1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
49
50
51
52
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
78
79
80
85
110
111
116
137
138
143
147
148
151
152
/* ... */
#include "k_storage.h"
/* ... */
/* ... */
Includes
FATFS mSDDISK_FatFs;
char mSDDISK_Drive[4];
osMessageQId StorageEvent;
DIR dir;
extern uint32_t UserButton_press;
extern uint32_t calibration_data[3*2];
static uint32_t StorageStatus[NUM_DISK_UNITS];Private variables
static void StorageThread(void const * argument);
Private function prototypes
/* ... */
void k_StorageInit(void)
{
FATFS_LinkDriver(&SD_Driver, mSDDISK_Drive);
osThreadDef(STORAGE_Thread, StorageThread, osPriorityLow, 0, 512);
osThreadCreate (osThread(STORAGE_Thread), NULL);
osMessageQDef(osqueue, 10, uint16_t);
StorageEvent = osMessageCreate (osMessageQ(osqueue), NULL);
BSP_SD_Init();
BSP_SD_ITConfig();
if(BSP_SD_IsDetected())
{
osMessagePut ( StorageEvent, MSDDISK_CONNECTION_EVENT, 0);
}if (BSP_SD_IsDetected()) { ... }
}{ ... }
/* ... */
static void StorageThread(void const * argument)
{
osEvent event;
for( ;; )
{
event = osMessageGet( StorageEvent, osWaitForever );
if( event.status == osEventMessage )
{
switch(event.value.v)
{
case MSDDISK_CONNECTION_EVENT:
f_mount(&mSDDISK_FatFs, mSDDISK_Drive, 0);
StorageStatus[MSD_DISK_UNIT] = 1;
break;
case MSDDISK_CONNECTION_EVENT:
case MSDDISK_DISCONNECTION_EVENT:
f_mount(0, mSDDISK_Drive, 0);
StorageStatus[MSD_DISK_UNIT] = 0;
break; case MSDDISK_DISCONNECTION_EVENT:
}switch (event.value.v) { ... }
}if (event.status == osEventMessage) { ... }
}for (;;) { ... }
}{ ... }
/* ... */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == TS_INT_PIN)
{
k_TouchUpdate();
}if (GPIO_Pin == TS_INT_PIN) { ... }
else if(GPIO_Pin == SD_DETECT_PIN)
{
if((BSP_SD_IsDetected()))
{
BSP_SD_Init();
osMessagePut ( StorageEvent, MSDDISK_CONNECTION_EVENT, 0);
}if ((BSP_SD_IsDetected())) { ... }
else
{
osMessagePut ( StorageEvent, MSDDISK_DISCONNECTION_EVENT, 0);
}else { ... }
}else if (GPIO_Pin == SD_DETECT_PIN) { ... }
}{ ... }
/* ... */
uint8_t k_StorageGetStatus (uint8_t unit)
{
return StorageStatus[unit];
}{ ... }
/* ... */
/* ... */