/*------------------------------------------------------------------------*/\r
-/* Sample code of OS dependent controls for FatFs */\r
-/* (C)ChaN, 2014 */\r
+/* Sample Code of OS Dependent Functions for FatFs */\r
+/* (C)ChaN, 2017 */\r
/*------------------------------------------------------------------------*/\r
\r
\r
-#include "../ff.h"\r
+#include "ff.h"\r
\r
\r
-#if _FS_REENTRANT\r
+\r
+#if FF_USE_LFN == 3 /* Dynamic memory allocation */\r
+\r
/*------------------------------------------------------------------------*/\r
-/* Create a Synchronization Object\r
+/* Allocate a memory block */\r
/*------------------------------------------------------------------------*/\r
-/* This function is called in f_mount() function to create a new\r
-/ synchronization object, such as semaphore and mutex. When a 0 is returned,\r
-/ the f_mount() function fails with FR_INT_ERR.\r
-*/\r
\r
-int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */\r
- BYTE vol, /* Corresponding volume (logical drive number) */\r
- _SYNC_t *sobj /* Pointer to return the created sync object */\r
+void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */\r
+ UINT msize /* Number of bytes to allocate */\r
+)\r
+{\r
+ return malloc(msize); /* Allocate a new memory block with POSIX API */\r
+}\r
+\r
+\r
+/*------------------------------------------------------------------------*/\r
+/* Free a memory block */\r
+/*------------------------------------------------------------------------*/\r
+\r
+void ff_memfree (\r
+ void* mblock /* Pointer to the memory block to free (nothing to do for null) */\r
)\r
{\r
- int ret;\r
+ free(mblock); /* Free the memory block with POSIX API */\r
+}\r
+\r
+#endif\r
\r
\r
- *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */\r
- ret = (int)(*sobj != INVALID_HANDLE_VALUE);\r
\r
-// *sobj = SyncObjects[vol]; /* uITRON (give a static sync object) */\r
-// ret = 1; /* The initial value of the semaphore must be 1. */\r
+#if FF_FS_REENTRANT /* Mutal exclusion */\r
\r
-// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */\r
-// ret = (int)(err == OS_NO_ERR);\r
+/*------------------------------------------------------------------------*/\r
+/* Create a Synchronization Object */\r
+/*------------------------------------------------------------------------*/\r
+/* This function is called in f_mount() function to create a new\r
+/ synchronization object for the volume, such as semaphore and mutex.\r
+/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.\r
+*/\r
\r
-// *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */\r
-// ret = (int)(*sobj != NULL);\r
+//const osMutexDef_t Mutex[FF_VOLUMES]; /* CMSIS-RTOS */\r
\r
- return ret;\r
-}\r
\r
+int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */\r
+ BYTE vol, /* Corresponding volume (logical drive number) */\r
+ FF_SYNC_t* sobj /* Pointer to return the created sync object */\r
+)\r
+{\r
+ /* Win32 */\r
+ *sobj = CreateMutex(NULL, FALSE, NULL);\r
+ return (int)(*sobj != INVALID_HANDLE_VALUE);\r
+\r
+ /* uITRON */\r
+// T_CSEM csem = {TA_TPRI,1,1};\r
+// *sobj = acre_sem(&csem);\r
+// return (int)(*sobj > 0);\r
+\r
+ /* uC/OS-II */\r
+// OS_ERR err;\r
+// *sobj = OSMutexCreate(0, &err);\r
+// return (int)(err == OS_NO_ERR);\r
+\r
+ /* FreeRTOS */\r
+// *sobj = xSemaphoreCreateMutex();\r
+// return (int)(*sobj != NULL);\r
+\r
+ /* CMSIS-RTOS */\r
+// *sobj = osMutexCreate(Mutex + vol);\r
+// return (int)(*sobj != NULL);\r
+}\r
\r
\r
/*------------------------------------------------------------------------*/\r
/ the f_mount() function fails with FR_INT_ERR.\r
*/\r
\r
-int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */\r
- _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */\r
+int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */\r
+ FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */\r
)\r
{\r
- int ret;\r
-\r
+ /* Win32 */\r
+ return (int)CloseHandle(sobj);\r
\r
- ret = CloseHandle(sobj); /* Win32 */\r
+ /* uITRON */\r
+// return (int)(del_sem(sobj) == E_OK);\r
\r
-// ret = 1; /* uITRON (nothing to do) */\r
+ /* uC/OS-II */\r
+// OS_ERR err;\r
+// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);\r
+// return (int)(err == OS_NO_ERR);\r
\r
-// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */\r
-// ret = (int)(err == OS_NO_ERR);\r
+ /* FreeRTOS */\r
+// vSemaphoreDelete(sobj);\r
+// return 1;\r
\r
-// vSemaphoreDelete(sobj); /* FreeRTOS */\r
-// ret = 1;\r
-\r
- return ret;\r
+ /* CMSIS-RTOS */\r
+// return (int)(osMutexDelete(sobj) == osOK);\r
}\r
\r
\r
-\r
/*------------------------------------------------------------------------*/\r
/* Request Grant to Access the Volume */\r
/*------------------------------------------------------------------------*/\r
*/\r
\r
int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */\r
- _SYNC_t sobj /* Sync object to wait */\r
+ FF_SYNC_t sobj /* Sync object to wait */\r
)\r
{\r
- int ret;\r
+ /* Win32 */\r
+ return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);\r
\r
- ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */\r
+ /* uITRON */\r
+// return (int)(wai_sem(sobj) == E_OK);\r
\r
-// ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */\r
+ /* uC/OS-II */\r
+// OS_ERR err;\r
+// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));\r
+// return (int)(err == OS_NO_ERR);\r
\r
-// OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */\r
-// ret = (int)(err == OS_NO_ERR);\r
+ /* FreeRTOS */\r
+// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);\r
\r
-// ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */\r
-\r
- return ret;\r
+ /* CMSIS-RTOS */\r
+// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);\r
}\r
\r
\r
-\r
/*------------------------------------------------------------------------*/\r
/* Release Grant to Access the Volume */\r
/*------------------------------------------------------------------------*/\r
*/\r
\r
void ff_rel_grant (\r
- _SYNC_t sobj /* Sync object to be signaled */\r
+ FF_SYNC_t sobj /* Sync object to be signaled */\r
)\r
{\r
- ReleaseMutex(sobj); /* Win32 */\r
-\r
-// sig_sem(sobj); /* uITRON */\r
-\r
-// OSMutexPost(sobj); /* uC/OS-II */\r
-\r
-// xSemaphoreGive(sobj); /* FreeRTOS */\r
-}\r
-\r
-#endif\r
-\r
-\r
-\r
-\r
-#if _USE_LFN == 3 /* LFN with a working buffer on the heap */\r
-/*------------------------------------------------------------------------*/\r
-/* Allocate a memory block */\r
-/*------------------------------------------------------------------------*/\r
-/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.\r
-*/\r
+ /* Win32 */\r
+ ReleaseMutex(sobj);\r
\r
-void* ff_memalloc ( /* Returns pointer to the allocated memory block */\r
- UINT msize /* Number of bytes to allocate */\r
-)\r
-{\r
- return malloc(msize); /* Allocate a new memory block with POSIX API */\r
-}\r
+ /* uITRON */\r
+// sig_sem(sobj);\r
\r
+ /* uC/OS-II */\r
+// OSMutexPost(sobj);\r
\r
-/*------------------------------------------------------------------------*/\r
-/* Free a memory block */\r
-/*------------------------------------------------------------------------*/\r
+ /* FreeRTOS */\r
+// xSemaphoreGive(sobj);\r
\r
-void ff_memfree (\r
- void* mblock /* Pointer to the memory block to free */\r
-)\r
-{\r
- free(mblock); /* Discard the memory block with POSIX API */\r
+ /* CMSIS-RTOS */\r
+// osMutexRelease(sobj);\r
}\r
\r
#endif\r
+\r