]>
cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/src/option/syscall.c
ccfd47e5e4319c1c2a458cb98ced4a9744353b44
1 /*------------------------------------------------------------------------*/
2 /* Sample code of OS dependent controls for FatFs */
4 /*------------------------------------------------------------------------*/
6 #include <stdlib.h> /* ANSI memory controls */
7 #include <malloc.h> /* ANSI memory controls */
13 /*------------------------------------------------------------------------*/
14 /* Create a Synchronization Object
15 /*------------------------------------------------------------------------*/
16 /* This function is called by f_mount() function to create a new
17 / synchronization object, such as semaphore and mutex. When a 0 is
18 / returned, the f_mount() function fails with FR_INT_ERR.
21 int ff_cre_syncobj ( /* 1:Function succeeded, 0: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 */
29 *sobj
= CreateMutex(NULL
, FALSE
, NULL
); /* Win32 */
30 ret
= (int)(*sobj
!= INVALID_HANDLE_VALUE
);
32 // *sobj = SyncObjects[vol]; /* uITRON (give a static created semaphore) */
35 // *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
36 // ret = (int)(err == OS_NO_ERR);
38 // *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
39 // ret = (int)(*sobj != NULL);
46 /*------------------------------------------------------------------------*/
47 /* Delete a Synchronization Object */
48 /*------------------------------------------------------------------------*/
49 /* This function is called in f_mount() function to delete a synchronization
50 / object that created with ff_cre_syncobj() function. When a 0 is
51 / returned, the f_mount() function fails with FR_INT_ERR.
54 int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */
55 _SYNC_t sobj
/* Sync object tied to the logical drive to be deleted */
61 ret
= CloseHandle(sobj
); /* Win32 */
63 // ret = 1; /* uITRON (nothing to do) */
65 // OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
66 // ret = (int)(err == OS_NO_ERR);
68 // xSemaphoreDelete(sobj); /* FreeRTOS */
76 /*------------------------------------------------------------------------*/
77 /* Request Grant to Access the Volume */
78 /*------------------------------------------------------------------------*/
79 /* This function is called on entering file functions to lock the volume.
80 / When a FALSE is returned, the file function fails with FR_TIMEOUT.
83 int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
84 _SYNC_t sobj
/* Sync object to wait */
89 ret
= (int)(WaitForSingleObject(sobj
, _FS_TIMEOUT
) == WAIT_OBJECT_0
); /* Win32 */
91 // ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */
93 // OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */
94 // ret = (int)(err == OS_NO_ERR);
96 // ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
103 /*------------------------------------------------------------------------*/
104 /* Release Grant to Access the Volume */
105 /*------------------------------------------------------------------------*/
106 /* This function is called on leaving file functions to unlock the volume.
110 _SYNC_t sobj
/* Sync object to be signaled */
113 ReleaseMutex(sobj
); /* Win32 */
115 // sig_sem(sobj); /* uITRON */
117 // OSMutexPost(sobj); /* uC/OS-II */
119 // xSemaphoreGive(sobj); /* FreeRTOS */
127 #if _USE_LFN == 3 /* LFN with a working buffer on the heap */
128 /*------------------------------------------------------------------------*/
129 /* Allocate a memory block */
130 /*------------------------------------------------------------------------*/
131 /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
134 void* ff_memalloc ( /* Returns pointer to the allocated memory block */
135 UINT msize
/* Number of bytes to allocate */
138 return malloc(msize
);
142 /*------------------------------------------------------------------------*/
143 /* Free a memory block */
144 /*------------------------------------------------------------------------*/
147 void* mblock
/* Pointer to the memory block to free */