]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/FileSystem/FatFs-0.7e/src/option/syncobj.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / Common / FileSystem / FatFs-0.7e / src / option / syncobj.c
1 /*------------------------------------------------------------------------*/\r
2 /* Sample code of OS dependent synchronization object controls            */\r
3 /* for FatFs R0.07d  (C)ChaN, 2009                                        */\r
4 /*------------------------------------------------------------------------*/\r
5 \r
6 #include <FreeRTOS.h>\r
7 #include <semphr.h>\r
8 \r
9 #include "../ff.h"\r
10 \r
11 #if _FS_REENTRANT\r
12 \r
13 /*------------------------------------------------------------------------*/\r
14 /* Create a Synchronization Object for a Volume                           */\r
15 /*------------------------------------------------------------------------*/\r
16 /* This function is called in f_mount function to create a new\r
17 /  synchronization object, such as semaphore and mutex. When a FALSE is\r
18 /  returned, the f_mount function fails with FR_INT_ERR.\r
19 */\r
20 \r
21 BOOL ff_cre_syncobj (   /* TRUE:Function succeeded, FALSE:Could not create due to any error */\r
22         BYTE vol,                       /* Corresponding logical drive being processed */\r
23         _SYNC_t *sobj           /* Pointer to return the created sync object */\r
24 )\r
25 {\r
26         BOOL ret;\r
27 \r
28         *sobj = xSemaphoreCreateMutex();\r
29         \r
30         if( *sobj == NULL )\r
31         {\r
32                 ret = FALSE;\r
33         }\r
34         else\r
35         {\r
36                 ret = TRUE;\r
37         }\r
38 \r
39         return ret;\r
40 }\r
41 \r
42 \r
43 \r
44 /*------------------------------------------------------------------------*/\r
45 /* Delete a Synchronization Object                                        */\r
46 /*------------------------------------------------------------------------*/\r
47 /* This function is called in f_mount function to delete a synchronization\r
48 /  object that created with ff_cre_syncobj function. When a FALSE is\r
49 /  returned, the f_mount function fails with FR_INT_ERR.\r
50 */\r
51 \r
52 BOOL ff_del_syncobj (   /* TRUE:Function succeeded, FALSE:Could not delete due to any error */\r
53         _SYNC_t sobj            /* Sync object tied to the logical drive to be deleted */\r
54 )\r
55 {\r
56         BOOL ret;\r
57 \r
58         if( sobj != NULL )\r
59         {\r
60                 vQueueDelete( sobj );\r
61                 ret = TRUE;\r
62         }\r
63         else\r
64         {\r
65                 ret = FALSE;\r
66         }\r
67         \r
68         return ret;\r
69 }\r
70 \r
71 \r
72 \r
73 /*------------------------------------------------------------------------*/\r
74 /* Request Grant to Access the Volume                                     */\r
75 /*------------------------------------------------------------------------*/\r
76 /* This function is called on entering file functions to lock the volume.\r
77 /  When a FALSE is returned, the file function fails with FR_TIMEOUT.\r
78 */\r
79 \r
80 BOOL ff_req_grant (     /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */\r
81         _SYNC_t sobj    /* Sync object to wait */\r
82 )\r
83 {\r
84         BOOL ret;\r
85 \r
86         ret = xSemaphoreTake( sobj, _FS_TIMEOUT );\r
87         \r
88         return ret;\r
89 }\r
90 \r
91 \r
92 \r
93 /*------------------------------------------------------------------------*/\r
94 /* Release Grant to Access the Volume                                     */\r
95 /*------------------------------------------------------------------------*/\r
96 /* This function is called on leaving file functions to unlock the volume.\r
97 */\r
98 \r
99 void ff_rel_grant (\r
100         _SYNC_t sobj    /* Sync object to be signaled */\r
101 )\r
102 {\r
103         xSemaphoreGive( sobj );\r
104 }\r
105 \r
106 \r
107 #else\r
108 \r
109 #error This file is not needed in this configuration.\r
110 \r
111 #endif\r