]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/Driver/src/Flash_Demo.c
Updated CMSIS-Driver table
[cmsis] / CMSIS / DoxyGen / Driver / src / Flash_Demo.c
1 #include "Driver_Flash.h"
2 #include "cmsis_os2.h"                  // ARM::CMSIS:RTOS2:Keil RTX5
3    
4 /* Flash driver instance */
5 extern ARM_DRIVER_FLASH Driver_Flash0;
6 static ARM_DRIVER_FLASH * flashDev = &Driver_Flash0;
7  
8 /* CMSIS-RTOS2 Thread Id */
9 osThreadId_t Flash_Thread_Id;
10  
11 /* Flash signal event */
12 void Flash_Callback(uint32_t event)
13 {
14   if (event & ARM_FLASH_EVENT_READY) {
15     /* The read/program/erase operation is completed */
16     osThreadFlagsSet(Flash_Thread_Id, 1U);
17   }
18   if (event & ARM_FLASH_EVENT_ERROR) {
19     /* The read/program/erase operation is completed with errors */
20     /* Call debugger or replace with custom error handling */
21     __breakpoint(0);  
22   }
23
24  
25 /* CMSIS-RTOS2 Thread */ 
26 void Flash_Thread (void *argument)
27 {
28   /* Query drivers capabilities */
29   const ARM_FLASH_CAPABILITIES capabilities = flashDev->GetCapabilities();
30  
31   /* Initialize Flash device */
32   if (capabilities.event_ready) {
33     flashDev->Initialize (&Flash_Callback);
34   } else {
35     flashDev->Initialize (NULL);
36   }
37   
38   /* Power-on Flash device */
39   flashDev->PowerControl (ARM_POWER_FULL);
40   
41   /* Read data taking data_width into account */
42   uint8_t buf[256U];
43   flashDev->ReadData (0x1000U, buf, sizeof(buf)>>capabilities.data_width);
44   
45   /* Wait operation to be completed */
46   if (capabilities.event_ready) {
47     osThreadFlagsWait (1U, osFlagsWaitAny, 100U);
48   } else {
49     osDelay(100U);
50   }
51   
52   /* Switch off gracefully */
53   flashDev->PowerControl (ARM_POWER_OFF);
54   flashDev->Uninitialize ();
55 }