]>
cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/src/option/syscall.c
1 /*------------------------------------------------------------------------*/
2 /* Sample code of OS dependent controls for FatFs */
4 /*------------------------------------------------------------------------*/
11 /*------------------------------------------------------------------------*/
12 /* Create a Synchronization Object
13 /*------------------------------------------------------------------------*/
14 /* This function is called in f_mount() function to create a new
15 / synchronization object, such as semaphore and mutex. When a 0 is returned,
16 / the f_mount() function fails with FR_INT_ERR.
19 int ff_cre_syncobj ( /* !=0:Function succeeded, ==0:Could not create due to any error */
20 BYTE vol
, /* Corresponding logical drive being processed */
21 _SYNC_t
*sobj
/* Pointer to return the created sync object */
27 *sobj
= CreateMutex(NULL
, FALSE
, NULL
); /* Win32 */
28 ret
= (int)(*sobj
!= INVALID_HANDLE_VALUE
);
30 // *sobj = SyncObjects[vol]; /* uITRON (give a static created sync object) */
31 // ret = 1; /* The initial value of the semaphore must be 1. */
33 // *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
34 // ret = (int)(err == OS_NO_ERR);
36 // *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
37 // ret = (int)(*sobj != NULL);
44 /*------------------------------------------------------------------------*/
45 /* Delete a Synchronization Object */
46 /*------------------------------------------------------------------------*/
47 /* This function is called in f_mount() function to delete a synchronization
48 / object that created with ff_cre_syncobj function. When a 0 is returned,
49 / the f_mount() function fails with FR_INT_ERR.
52 int ff_del_syncobj ( /* !=0:Function succeeded, ==0:Could not delete due to any error */
53 _SYNC_t sobj
/* Sync object tied to the logical drive to be deleted */
59 ret
= CloseHandle(sobj
); /* Win32 */
61 // ret = 1; /* uITRON (nothing to do) */
63 // OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
64 // ret = (int)(err == OS_NO_ERR);
66 // vSemaphoreDelete(sobj); /* FreeRTOS */
74 /*------------------------------------------------------------------------*/
75 /* Request Grant to Access the Volume */
76 /*------------------------------------------------------------------------*/
77 /* This function is called on entering file functions to lock the volume.
78 / When a 0 is returned, the file function fails with FR_TIMEOUT.
81 int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
82 _SYNC_t sobj
/* Sync object to wait */
87 ret
= (int)(WaitForSingleObject(sobj
, _FS_TIMEOUT
) == WAIT_OBJECT_0
); /* Win32 */
89 // ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */
91 // OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */
92 // ret = (int)(err == OS_NO_ERR);
94 // ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
101 /*------------------------------------------------------------------------*/
102 /* Release Grant to Access the Volume */
103 /*------------------------------------------------------------------------*/
104 /* This function is called on leaving file functions to unlock the volume.
108 _SYNC_t sobj
/* Sync object to be signaled */
111 ReleaseMutex(sobj
); /* Win32 */
113 // sig_sem(sobj); /* uITRON */
115 // OSMutexPost(sobj); /* uC/OS-II */
117 // xSemaphoreGive(sobj); /* FreeRTOS */
125 #if _USE_LFN == 3 /* LFN with a working buffer on the heap */
126 /*------------------------------------------------------------------------*/
127 /* Allocate a memory block */
128 /*------------------------------------------------------------------------*/
129 /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
132 void* ff_memalloc ( /* Returns pointer to the allocated memory block */
133 UINT msize
/* Number of bytes to allocate */
136 return malloc(msize
); /* Allocate a new memory block with POSIX API */
140 /*------------------------------------------------------------------------*/
141 /* Free a memory block */
142 /*------------------------------------------------------------------------*/
145 void* mblock
/* Pointer to the memory block to free */
148 free(mblock
); /* Discard the memory block with POSIX API */