]> cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/src/option/syscall.c
ccfd47e5e4319c1c2a458cb98ced4a9744353b44
[z180-stamp.git] / fatfs / src / option / syscall.c
1 /*------------------------------------------------------------------------*/
2 /* Sample code of OS dependent controls for FatFs */
3 /* (C)ChaN, 2012 */
4 /*------------------------------------------------------------------------*/
5
6 #include <stdlib.h> /* ANSI memory controls */
7 #include <malloc.h> /* ANSI memory controls */
8
9 #include "../ff.h"
10
11
12 #if _FS_REENTRANT
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.
19 */
20
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 */
24 )
25 {
26 int ret;
27
28
29 *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */
30 ret = (int)(*sobj != INVALID_HANDLE_VALUE);
31
32 // *sobj = SyncObjects[vol]; /* uITRON (give a static created semaphore) */
33 // ret = 1;
34
35 // *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
36 // ret = (int)(err == OS_NO_ERR);
37
38 // *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
39 // ret = (int)(*sobj != NULL);
40
41 return ret;
42 }
43
44
45
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.
52 */
53
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 */
56 )
57 {
58 int ret;
59
60
61 ret = CloseHandle(sobj); /* Win32 */
62
63 // ret = 1; /* uITRON (nothing to do) */
64
65 // OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
66 // ret = (int)(err == OS_NO_ERR);
67
68 // xSemaphoreDelete(sobj); /* FreeRTOS */
69 // ret = 1;
70
71 return ret;
72 }
73
74
75
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.
81 */
82
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 */
85 )
86 {
87 int ret;
88
89 ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */
90
91 // ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */
92
93 // OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */
94 // ret = (int)(err == OS_NO_ERR);
95
96 // ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
97
98 return ret;
99 }
100
101
102
103 /*------------------------------------------------------------------------*/
104 /* Release Grant to Access the Volume */
105 /*------------------------------------------------------------------------*/
106 /* This function is called on leaving file functions to unlock the volume.
107 */
108
109 void ff_rel_grant (
110 _SYNC_t sobj /* Sync object to be signaled */
111 )
112 {
113 ReleaseMutex(sobj); /* Win32 */
114
115 // sig_sem(sobj); /* uITRON */
116
117 // OSMutexPost(sobj); /* uC/OS-II */
118
119 // xSemaphoreGive(sobj); /* FreeRTOS */
120 }
121
122 #endif
123
124
125
126
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.
132 */
133
134 void* ff_memalloc ( /* Returns pointer to the allocated memory block */
135 UINT msize /* Number of bytes to allocate */
136 )
137 {
138 return malloc(msize);
139 }
140
141
142 /*------------------------------------------------------------------------*/
143 /* Free a memory block */
144 /*------------------------------------------------------------------------*/
145
146 void ff_memfree (
147 void* mblock /* Pointer to the memory block to free */
148 )
149 {
150 free(mblock);
151 }
152
153 #endif