]> cloudbase.mooo.com Git - z180-stamp.git/blame - fatfs/src/option/syscall.c
Import fatfs R0.10b
[z180-stamp.git] / fatfs / src / option / syscall.c
CommitLineData
53668523
L
1/*------------------------------------------------------------------------*/\r
2/* Sample code of OS dependent controls for FatFs */\r
3/* (C)ChaN, 2012 */\r
4/*------------------------------------------------------------------------*/\r
5\r
6#include <stdlib.h> /* ANSI memory controls */\r
7#include <malloc.h> /* ANSI memory controls */\r
8\r
9#include "../ff.h"\r
10\r
11\r
12#if _FS_REENTRANT\r
13/*------------------------------------------------------------------------*/\r
14/* Create a Synchronization Object\r
15/*------------------------------------------------------------------------*/\r
16/* This function is called by f_mount() function to create a new\r
17/ synchronization object, such as semaphore and mutex. When a 0 is\r
18/ returned, the f_mount() function fails with FR_INT_ERR.\r
19*/\r
20\r
21int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any error */\r
22 BYTE vol, /* Corresponding logical drive being processed */\r
23 _SYNC_t* sobj /* Pointer to return the created sync object */\r
24)\r
25{\r
26 int ret;\r
27\r
28\r
29 *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */\r
30 ret = (int)(*sobj != INVALID_HANDLE_VALUE);\r
31\r
32// *sobj = SyncObjects[vol]; /* uITRON (give a static created semaphore) */\r
33// ret = 1;\r
34\r
35// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */\r
36// ret = (int)(err == OS_NO_ERR);\r
37\r
38// *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */\r
39// ret = (int)(*sobj != NULL);\r
40\r
41 return ret;\r
42}\r
43\r
44\r
45\r
46/*------------------------------------------------------------------------*/\r
47/* Delete a Synchronization Object */\r
48/*------------------------------------------------------------------------*/\r
49/* This function is called in f_mount() function to delete a synchronization\r
50/ object that created with ff_cre_syncobj() function. When a 0 is\r
51/ returned, the f_mount() function fails with FR_INT_ERR.\r
52*/\r
53\r
54int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */\r
55 _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */\r
56)\r
57{\r
58 int ret;\r
59\r
60\r
61 ret = CloseHandle(sobj); /* Win32 */\r
62\r
63// ret = 1; /* uITRON (nothing to do) */\r
64\r
65// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */\r
66// ret = (int)(err == OS_NO_ERR);\r
67\r
68// xSemaphoreDelete(sobj); /* FreeRTOS */\r
69// ret = 1;\r
70\r
71 return ret;\r
72}\r
73\r
74\r
75\r
76/*------------------------------------------------------------------------*/\r
77/* Request Grant to Access the Volume */\r
78/*------------------------------------------------------------------------*/\r
79/* This function is called on entering file functions to lock the volume.\r
80/ When a FALSE is returned, the file function fails with FR_TIMEOUT.\r
81*/\r
82\r
83int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */\r
84 _SYNC_t sobj /* Sync object to wait */\r
85)\r
86{\r
87 int ret;\r
88\r
89 ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */\r
90\r
91// ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */\r
92\r
93// OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */\r
94// ret = (int)(err == OS_NO_ERR);\r
95\r
96// ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */\r
97\r
98 return ret;\r
99}\r
100\r
101\r
102\r
103/*------------------------------------------------------------------------*/\r
104/* Release Grant to Access the Volume */\r
105/*------------------------------------------------------------------------*/\r
106/* This function is called on leaving file functions to unlock the volume.\r
107*/\r
108\r
109void ff_rel_grant (\r
110 _SYNC_t sobj /* Sync object to be signaled */\r
111)\r
112{\r
113 ReleaseMutex(sobj); /* Win32 */\r
114\r
115// sig_sem(sobj); /* uITRON */\r
116\r
117// OSMutexPost(sobj); /* uC/OS-II */\r
118\r
119// xSemaphoreGive(sobj); /* FreeRTOS */\r
120}\r
121\r
122#endif\r
123\r
124\r
125\r
126\r
127#if _USE_LFN == 3 /* LFN with a working buffer on the heap */\r
128/*------------------------------------------------------------------------*/\r
129/* Allocate a memory block */\r
130/*------------------------------------------------------------------------*/\r
131/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.\r
132*/\r
133\r
134void* ff_memalloc ( /* Returns pointer to the allocated memory block */\r
135 UINT msize /* Number of bytes to allocate */\r
136)\r
137{\r
138 return malloc(msize);\r
139}\r
140\r
141\r
142/*------------------------------------------------------------------------*/\r
143/* Free a memory block */\r
144/*------------------------------------------------------------------------*/\r
145\r
146void ff_memfree (\r
147 void* mblock /* Pointer to the memory block to free */\r
148)\r
149{\r
150 free(mblock);\r
151}\r
152\r
153#endif\r