BeRTOS
syncobj.c
00001 /*------------------------------------------------------------------------*/
00002 /* Sample code of OS dependent synchronization object controls            */
00003 /* for FatFs R0.07a  (C)ChaN, 2009                                        */
00004 /*------------------------------------------------------------------------*/
00005 
00006 #include <windows.h>    // Win32
00007 //#include <ucos_ii.h>  // uC/OS-II
00008 
00009 #include "../ff.h"
00010 
00011 #if _FS_REENTRANT
00012 
00013 /*------------------------------------------------------------------------*/
00014 /* Create a Synchronization Object for a Volume
00015 /*------------------------------------------------------------------------*/
00016 /* This function is called in f_mount function to create a new
00017 /  synchronization object, such as semaphore and mutex. When a FALSE is
00018 /  returned, the f_mount function fails with FR_INT_ERR.
00019 */
00020 
00021 BOOL ff_cre_syncobj (   /* TRUE:Function succeeded, FALSE:Could not create due to any error */
00022     BYTE vol,           /* Corresponding logical drive being processed */
00023     _SYNC_t *sobj       /* Pointer to return the created sync object */
00024 )
00025 {
00026     BOOL ret;
00027 
00028     *sobj = CreateMutex(NULL, FALSE, NULL);                 // Win32
00029     ret = (*sobj != INVALID_HANDLE_VALUE) ? TRUE : FALSE;   //
00030 
00031 //  *sobj = VolumeSemId[vol];   // uITRON (give a static created sync object)
00032 //  ret = TRUE;                 // The initial value of the semaphore must be 1.
00033 
00034 //  *sobj = OSMutexCreate(0, &err);             // uC/OS-II
00035 //  ret = (err == OS_NO_ERR) ? TRUE : FALSE;    //
00036 
00037     return ret;
00038 }
00039 
00040 
00041 
00042 /*------------------------------------------------------------------------*/
00043 /* Delete a Synchronization Object                                        */
00044 /*------------------------------------------------------------------------*/
00045 /* This function is called in f_mount function to delete a synchronization
00046 /  object that created with ff_cre_syncobj function. When a FALSE is
00047 /  returned, the f_mount function fails with FR_INT_ERR.
00048 */
00049 
00050 BOOL ff_del_syncobj (   /* TRUE:Function succeeded, FALSE:Could not delete due to any error */
00051     _SYNC_t sobj        /* Sync object tied to the logical drive to be deleted */
00052 )
00053 {
00054     BOOL ret;
00055 
00056     ret = CloseHandle(sobj);    // Win32
00057 
00058 //  ret = TRUE;                 // uITRON (nothing to do)
00059 
00060 //  OSMutexDel(sobj, OS_DEL_ALWAYS, &err);      // uC/OS-II
00061 //  ret = (err == OS_NO_ERR) ? TRUE : FALSE;    //
00062 
00063     return ret;
00064 }
00065 
00066 
00067 
00068 /*------------------------------------------------------------------------*/
00069 /* Request Grant to Access the Volume                                     */
00070 /*------------------------------------------------------------------------*/
00071 /* This function is called on entering file functions to lock the volume.
00072 /  When a FALSE is returned, the file function fails with FR_TIMEOUT.
00073 */
00074 
00075 BOOL ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
00076     _SYNC_t sobj    /* Sync object to wait */
00077 )
00078 {
00079     BOOL ret;
00080 
00081     ret = (WaitForSingleObject(sobj, _TIMEOUT) == WAIT_OBJECT_0) ? TRUE : FALSE;    // Win32
00082 
00083 //  ret = (wai_sem(sobj) == E_OK) ? TRUE : FALSE;   // uITRON
00084 
00085 //  OSMutexPend(sobj, _TIMEOUT, &err));             // uC/OS-II
00086 //  ret = (err == OS_NO_ERR) ? TRUE : FALSE;        //
00087 
00088     return ret;
00089 }
00090 
00091 
00092 
00093 /*------------------------------------------------------------------------*/
00094 /* Release Grant to Access the Volume                                     */
00095 /*------------------------------------------------------------------------*/
00096 /* This function is called on leaving file functions to unlock the volume.
00097 */
00098 
00099 void ff_rel_grant (
00100     _SYNC_t sobj    /* Sync object to be signaled */
00101 )
00102 {
00103     ReleaseMutex(sobj); // Win32
00104 
00105 //  sig_sem(sobj);      // uITRON
00106 
00107 //  OSMutexPost(sobj);  // uC/OS-II
00108 }
00109 
00110 
00111 #else
00112 
00113 #error This file is not needed in this configuration.
00114 
00115 #endif