1 /*------------------------------------------------------------------------*/
2 /* Sample code of OS dependent synchronization object controls */
3 /* for FatFs R0.07a (C)ChaN, 2009 */
4 /*------------------------------------------------------------------------*/
6 #include <windows.h> // Win32
7 //#include <ucos_ii.h> // uC/OS-II
13 /*------------------------------------------------------------------------*/
14 /* Create a Synchronization Object for a Volume
15 /*------------------------------------------------------------------------*/
16 /* This function is called in f_mount function to create a new
17 / synchronization object, such as semaphore and mutex. When a FALSE is
18 / returned, the f_mount function fails with FR_INT_ERR.
21 BOOL ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */
22 BYTE vol, /* Corresponding logical drive being processed */
23 _SYNC_t *sobj /* Pointer to return the created sync object */
28 *sobj = CreateMutex(NULL, FALSE, NULL); // Win32
29 ret = (*sobj != INVALID_HANDLE_VALUE) ? TRUE : FALSE; //
31 // *sobj = VolumeSemId[vol]; // uITRON (give a static created sync object)
32 // ret = TRUE; // The initial value of the semaphore must be 1.
34 // *sobj = OSMutexCreate(0, &err); // uC/OS-II
35 // ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
42 /*------------------------------------------------------------------------*/
43 /* Delete a Synchronization Object */
44 /*------------------------------------------------------------------------*/
45 /* This function is called in f_mount function to delete a synchronization
46 / object that created with ff_cre_syncobj function. When a FALSE is
47 / returned, the f_mount function fails with FR_INT_ERR.
50 BOOL ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */
51 _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
56 ret = CloseHandle(sobj); // Win32
58 // ret = TRUE; // uITRON (nothing to do)
60 // OSMutexDel(sobj, OS_DEL_ALWAYS, &err); // uC/OS-II
61 // ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
68 /*------------------------------------------------------------------------*/
69 /* Request Grant to Access the Volume */
70 /*------------------------------------------------------------------------*/
71 /* This function is called on entering file functions to lock the volume.
72 / When a FALSE is returned, the file function fails with FR_TIMEOUT.
75 BOOL ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
76 _SYNC_t sobj /* Sync object to wait */
81 ret = (WaitForSingleObject(sobj, _TIMEOUT) == WAIT_OBJECT_0) ? TRUE : FALSE; // Win32
83 // ret = (wai_sem(sobj) == E_OK) ? TRUE : FALSE; // uITRON
85 // OSMutexPend(sobj, _TIMEOUT, &err)); // uC/OS-II
86 // ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
93 /*------------------------------------------------------------------------*/
94 /* Release Grant to Access the Volume */
95 /*------------------------------------------------------------------------*/
96 /* This function is called on leaving file functions to unlock the volume.
100 _SYNC_t sobj /* Sync object to be signaled */
103 ReleaseMutex(sobj); // Win32
105 // sig_sem(sobj); // uITRON
107 // OSMutexPost(sobj); // uC/OS-II
113 #error This file is not needed in this configuration.