]>
Commit | Line | Data |
---|---|---|
1 | /*------------------------------------------------------------------------*/\r | |
2 | /* Sample Code of OS Dependent Functions for FatFs */\r | |
3 | /* (C)ChaN, 2017 */\r | |
4 | /*------------------------------------------------------------------------*/\r | |
5 | \r | |
6 | \r | |
7 | #include "ff.h"\r | |
8 | \r | |
9 | \r | |
10 | \r | |
11 | #if FF_USE_LFN == 3 /* Dynamic memory allocation */\r | |
12 | \r | |
13 | /*------------------------------------------------------------------------*/\r | |
14 | /* Allocate a memory block */\r | |
15 | /*------------------------------------------------------------------------*/\r | |
16 | \r | |
17 | void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */\r | |
18 | UINT msize /* Number of bytes to allocate */\r | |
19 | )\r | |
20 | {\r | |
21 | return malloc(msize); /* Allocate a new memory block with POSIX API */\r | |
22 | }\r | |
23 | \r | |
24 | \r | |
25 | /*------------------------------------------------------------------------*/\r | |
26 | /* Free a memory block */\r | |
27 | /*------------------------------------------------------------------------*/\r | |
28 | \r | |
29 | void ff_memfree (\r | |
30 | void* mblock /* Pointer to the memory block to free (nothing to do for null) */\r | |
31 | )\r | |
32 | {\r | |
33 | free(mblock); /* Free the memory block with POSIX API */\r | |
34 | }\r | |
35 | \r | |
36 | #endif\r | |
37 | \r | |
38 | \r | |
39 | \r | |
40 | #if FF_FS_REENTRANT /* Mutal exclusion */\r | |
41 | \r | |
42 | /*------------------------------------------------------------------------*/\r | |
43 | /* Create a Synchronization Object */\r | |
44 | /*------------------------------------------------------------------------*/\r | |
45 | /* This function is called in f_mount() function to create a new\r | |
46 | / synchronization object for the volume, such as semaphore and mutex.\r | |
47 | / When a 0 is returned, the f_mount() function fails with FR_INT_ERR.\r | |
48 | */\r | |
49 | \r | |
50 | //const osMutexDef_t Mutex[FF_VOLUMES]; /* CMSIS-RTOS */\r | |
51 | \r | |
52 | \r | |
53 | int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */\r | |
54 | BYTE vol, /* Corresponding volume (logical drive number) */\r | |
55 | FF_SYNC_t* sobj /* Pointer to return the created sync object */\r | |
56 | )\r | |
57 | {\r | |
58 | /* Win32 */\r | |
59 | *sobj = CreateMutex(NULL, FALSE, NULL);\r | |
60 | return (int)(*sobj != INVALID_HANDLE_VALUE);\r | |
61 | \r | |
62 | /* uITRON */\r | |
63 | // T_CSEM csem = {TA_TPRI,1,1};\r | |
64 | // *sobj = acre_sem(&csem);\r | |
65 | // return (int)(*sobj > 0);\r | |
66 | \r | |
67 | /* uC/OS-II */\r | |
68 | // OS_ERR err;\r | |
69 | // *sobj = OSMutexCreate(0, &err);\r | |
70 | // return (int)(err == OS_NO_ERR);\r | |
71 | \r | |
72 | /* FreeRTOS */\r | |
73 | // *sobj = xSemaphoreCreateMutex();\r | |
74 | // return (int)(*sobj != NULL);\r | |
75 | \r | |
76 | /* CMSIS-RTOS */\r | |
77 | // *sobj = osMutexCreate(Mutex + vol);\r | |
78 | // return (int)(*sobj != NULL);\r | |
79 | }\r | |
80 | \r | |
81 | \r | |
82 | /*------------------------------------------------------------------------*/\r | |
83 | /* Delete a Synchronization Object */\r | |
84 | /*------------------------------------------------------------------------*/\r | |
85 | /* This function is called in f_mount() function to delete a synchronization\r | |
86 | / object that created with ff_cre_syncobj() function. When a 0 is returned,\r | |
87 | / the f_mount() function fails with FR_INT_ERR.\r | |
88 | */\r | |
89 | \r | |
90 | int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */\r | |
91 | FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */\r | |
92 | )\r | |
93 | {\r | |
94 | /* Win32 */\r | |
95 | return (int)CloseHandle(sobj);\r | |
96 | \r | |
97 | /* uITRON */\r | |
98 | // return (int)(del_sem(sobj) == E_OK);\r | |
99 | \r | |
100 | /* uC/OS-II */\r | |
101 | // OS_ERR err;\r | |
102 | // OSMutexDel(sobj, OS_DEL_ALWAYS, &err);\r | |
103 | // return (int)(err == OS_NO_ERR);\r | |
104 | \r | |
105 | /* FreeRTOS */\r | |
106 | // vSemaphoreDelete(sobj);\r | |
107 | // return 1;\r | |
108 | \r | |
109 | /* CMSIS-RTOS */\r | |
110 | // return (int)(osMutexDelete(sobj) == osOK);\r | |
111 | }\r | |
112 | \r | |
113 | \r | |
114 | /*------------------------------------------------------------------------*/\r | |
115 | /* Request Grant to Access the Volume */\r | |
116 | /*------------------------------------------------------------------------*/\r | |
117 | /* This function is called on entering file functions to lock the volume.\r | |
118 | / When a 0 is returned, the file function fails with FR_TIMEOUT.\r | |
119 | */\r | |
120 | \r | |
121 | int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */\r | |
122 | FF_SYNC_t sobj /* Sync object to wait */\r | |
123 | )\r | |
124 | {\r | |
125 | /* Win32 */\r | |
126 | return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);\r | |
127 | \r | |
128 | /* uITRON */\r | |
129 | // return (int)(wai_sem(sobj) == E_OK);\r | |
130 | \r | |
131 | /* uC/OS-II */\r | |
132 | // OS_ERR err;\r | |
133 | // OSMutexPend(sobj, FF_FS_TIMEOUT, &err));\r | |
134 | // return (int)(err == OS_NO_ERR);\r | |
135 | \r | |
136 | /* FreeRTOS */\r | |
137 | // return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);\r | |
138 | \r | |
139 | /* CMSIS-RTOS */\r | |
140 | // return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);\r | |
141 | }\r | |
142 | \r | |
143 | \r | |
144 | /*------------------------------------------------------------------------*/\r | |
145 | /* Release Grant to Access the Volume */\r | |
146 | /*------------------------------------------------------------------------*/\r | |
147 | /* This function is called on leaving file functions to unlock the volume.\r | |
148 | */\r | |
149 | \r | |
150 | void ff_rel_grant (\r | |
151 | FF_SYNC_t sobj /* Sync object to be signaled */\r | |
152 | )\r | |
153 | {\r | |
154 | /* Win32 */\r | |
155 | ReleaseMutex(sobj);\r | |
156 | \r | |
157 | /* uITRON */\r | |
158 | // sig_sem(sobj);\r | |
159 | \r | |
160 | /* uC/OS-II */\r | |
161 | // OSMutexPost(sobj);\r | |
162 | \r | |
163 | /* FreeRTOS */\r | |
164 | // xSemaphoreGive(sobj);\r | |
165 | \r | |
166 | /* CMSIS-RTOS */\r | |
167 | // osMutexRelease(sobj);\r | |
168 | }\r | |
169 | \r | |
170 | #endif\r | |
171 | \r |