]>
cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/source/ffsystem.c
1 /*------------------------------------------------------------------------*/
2 /* Sample Code of OS Dependent Functions for FatFs */
4 /*------------------------------------------------------------------------*/
11 #if FF_USE_LFN == 3 /* Dynamic memory allocation */
13 /*------------------------------------------------------------------------*/
14 /* Allocate a memory block */
15 /*------------------------------------------------------------------------*/
17 void* ff_memalloc ( /* Returns pointer to the allocated memory block (null on not enough core) */
18 UINT msize
/* Number of bytes to allocate */
21 return malloc(msize
); /* Allocate a new memory block with POSIX API */
25 /*------------------------------------------------------------------------*/
26 /* Free a memory block */
27 /*------------------------------------------------------------------------*/
30 void* mblock
/* Pointer to the memory block to free (nothing to do for null) */
33 free(mblock
); /* Free the memory block with POSIX API */
40 #if FF_FS_REENTRANT /* Mutal exclusion */
42 /*------------------------------------------------------------------------*/
43 /* Create a Synchronization Object */
44 /*------------------------------------------------------------------------*/
45 /* This function is called in f_mount() function to create a new
46 / synchronization object for the volume, such as semaphore and mutex.
47 / When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
50 //const osMutexDef_t Mutex[FF_VOLUMES]; /* CMSIS-RTOS */
53 int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
54 BYTE vol
, /* Corresponding volume (logical drive number) */
55 FF_SYNC_t
* sobj
/* Pointer to return the created sync object */
59 *sobj
= CreateMutex(NULL
, FALSE
, NULL
);
60 return (int)(*sobj
!= INVALID_HANDLE_VALUE
);
63 // T_CSEM csem = {TA_TPRI,1,1};
64 // *sobj = acre_sem(&csem);
65 // return (int)(*sobj > 0);
69 // *sobj = OSMutexCreate(0, &err);
70 // return (int)(err == OS_NO_ERR);
73 // *sobj = xSemaphoreCreateMutex();
74 // return (int)(*sobj != NULL);
77 // *sobj = osMutexCreate(Mutex + vol);
78 // return (int)(*sobj != NULL);
82 /*------------------------------------------------------------------------*/
83 /* Delete a Synchronization Object */
84 /*------------------------------------------------------------------------*/
85 /* This function is called in f_mount() function to delete a synchronization
86 / object that created with ff_cre_syncobj() function. When a 0 is returned,
87 / the f_mount() function fails with FR_INT_ERR.
90 int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
91 FF_SYNC_t sobj
/* Sync object tied to the logical drive to be deleted */
95 return (int)CloseHandle(sobj
);
98 // return (int)(del_sem(sobj) == E_OK);
102 // OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
103 // return (int)(err == OS_NO_ERR);
106 // vSemaphoreDelete(sobj);
110 // return (int)(osMutexDelete(sobj) == osOK);
114 /*------------------------------------------------------------------------*/
115 /* Request Grant to Access the Volume */
116 /*------------------------------------------------------------------------*/
117 /* This function is called on entering file functions to lock the volume.
118 / When a 0 is returned, the file function fails with FR_TIMEOUT.
121 int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
122 FF_SYNC_t sobj
/* Sync object to wait */
126 return (int)(WaitForSingleObject(sobj
, FF_FS_TIMEOUT
) == WAIT_OBJECT_0
);
129 // return (int)(wai_sem(sobj) == E_OK);
133 // OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
134 // return (int)(err == OS_NO_ERR);
137 // return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
140 // return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
144 /*------------------------------------------------------------------------*/
145 /* Release Grant to Access the Volume */
146 /*------------------------------------------------------------------------*/
147 /* This function is called on leaving file functions to unlock the volume.
151 FF_SYNC_t sobj
/* Sync object to be signaled */
161 // OSMutexPost(sobj);
164 // xSemaphoreGive(sobj);
167 // osMutexRelease(sobj);