--- /dev/null
+/*------------------------------------------------------------------------*/\r
+/* Sample code of OS dependent controls for FatFs */\r
+/* (C)ChaN, 2012 */\r
+/*------------------------------------------------------------------------*/\r
+\r
+#include <stdlib.h> /* ANSI memory controls */\r
+#include <malloc.h> /* ANSI memory controls */\r
+\r
+#include "../ff.h"\r
+\r
+\r
+#if _FS_REENTRANT\r
+/*------------------------------------------------------------------------*/\r
+/* Create a Synchronization Object\r
+/*------------------------------------------------------------------------*/\r
+/* This function is called by f_mount() function to create a new\r
+/ synchronization object, such as semaphore and mutex. When a 0 is\r
+/ returned, the f_mount() function fails with FR_INT_ERR.\r
+*/\r
+\r
+int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any error */\r
+ BYTE vol, /* Corresponding logical drive being processed */\r
+ _SYNC_t* sobj /* Pointer to return the created sync object */\r
+)\r
+{\r
+ int ret;\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 created semaphore) */\r
+// ret = 1;\r
+\r
+// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */\r
+// ret = (int)(err == OS_NO_ERR);\r
+\r
+// *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */\r
+// ret = (int)(*sobj != NULL);\r
+\r
+ return ret;\r
+}\r
+\r
+\r
+\r
+/*------------------------------------------------------------------------*/\r
+/* Delete a Synchronization Object */\r
+/*------------------------------------------------------------------------*/\r
+/* This function is called in f_mount() function to delete a synchronization\r
+/ object that created with ff_cre_syncobj() function. When a 0 is\r
+/ returned, 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
+)\r
+{\r
+ int ret;\r
+\r
+\r
+ ret = CloseHandle(sobj); /* Win32 */\r
+\r
+// ret = 1; /* uITRON (nothing to do) */\r
+\r
+// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */\r
+// ret = (int)(err == OS_NO_ERR);\r
+\r
+// xSemaphoreDelete(sobj); /* FreeRTOS */\r
+// ret = 1;\r
+\r
+ return ret;\r
+}\r
+\r
+\r
+\r
+/*------------------------------------------------------------------------*/\r
+/* Request Grant to Access the Volume */\r
+/*------------------------------------------------------------------------*/\r
+/* This function is called on entering file functions to lock the volume.\r
+/ When a FALSE is returned, the file function fails with FR_TIMEOUT.\r
+*/\r
+\r
+int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */\r
+ _SYNC_t sobj /* Sync object to wait */\r
+)\r
+{\r
+ int ret;\r
+\r
+ ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */\r
+\r
+// ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */\r
+\r
+// OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */\r
+// ret = (int)(err == OS_NO_ERR);\r
+\r
+// ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */\r
+\r
+ return ret;\r
+}\r
+\r
+\r
+\r
+/*------------------------------------------------------------------------*/\r
+/* Release Grant to Access the Volume */\r
+/*------------------------------------------------------------------------*/\r
+/* This function is called on leaving file functions to unlock the volume.\r
+*/\r
+\r
+void ff_rel_grant (\r
+ _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
+\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);\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 */\r
+)\r
+{\r
+ free(mblock);\r
+}\r
+\r
+#endif\r