diff options
Diffstat (limited to 'lib/chibios/os/various/fatfs_bindings/fatfs_syscall.c')
-rw-r--r-- | lib/chibios/os/various/fatfs_bindings/fatfs_syscall.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/chibios/os/various/fatfs_bindings/fatfs_syscall.c b/lib/chibios/os/various/fatfs_bindings/fatfs_syscall.c new file mode 100644 index 000000000..51bfec127 --- /dev/null +++ b/lib/chibios/os/various/fatfs_bindings/fatfs_syscall.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /*------------------------------------------------------------------------*/ | ||
18 | /* Sample code of OS dependent controls for FatFs */ | ||
19 | /* (C)ChaN, 2014 */ | ||
20 | /*------------------------------------------------------------------------*/ | ||
21 | |||
22 | #include "hal.h" | ||
23 | #include "ff.h" | ||
24 | |||
25 | #if FF_FS_REENTRANT | ||
26 | /*------------------------------------------------------------------------*/ | ||
27 | /* Static array of Synchronization Objects */ | ||
28 | /*------------------------------------------------------------------------*/ | ||
29 | static semaphore_t ff_sem[FF_VOLUMES]; | ||
30 | |||
31 | /*------------------------------------------------------------------------*/ | ||
32 | /* Create a Synchronization Object */ | ||
33 | /*------------------------------------------------------------------------*/ | ||
34 | int ff_cre_syncobj(BYTE vol, FF_SYNC_t *sobj) { | ||
35 | |||
36 | *sobj = &ff_sem[vol]; | ||
37 | chSemObjectInit(*sobj, 1); | ||
38 | return TRUE; | ||
39 | } | ||
40 | |||
41 | /*------------------------------------------------------------------------*/ | ||
42 | /* Delete a Synchronization Object */ | ||
43 | /*------------------------------------------------------------------------*/ | ||
44 | int ff_del_syncobj(FF_SYNC_t sobj) { | ||
45 | |||
46 | chSemReset(sobj, 0); | ||
47 | return TRUE; | ||
48 | } | ||
49 | |||
50 | /*------------------------------------------------------------------------*/ | ||
51 | /* Request Grant to Access the Volume */ | ||
52 | /*------------------------------------------------------------------------*/ | ||
53 | int ff_req_grant(FF_SYNC_t sobj) { | ||
54 | |||
55 | msg_t msg = chSemWaitTimeout(sobj, (systime_t)FF_FS_TIMEOUT); | ||
56 | return msg == MSG_OK; | ||
57 | } | ||
58 | |||
59 | /*------------------------------------------------------------------------*/ | ||
60 | /* Release Grant to Access the Volume */ | ||
61 | /*------------------------------------------------------------------------*/ | ||
62 | void ff_rel_grant(FF_SYNC_t sobj) { | ||
63 | |||
64 | chSemSignal(sobj); | ||
65 | } | ||
66 | #endif /* FF_FS_REENTRANT */ | ||
67 | |||
68 | #if FF_USE_LFN == 3 /* LFN with a working buffer on the heap */ | ||
69 | /*------------------------------------------------------------------------*/ | ||
70 | /* Allocate a memory block */ | ||
71 | /*------------------------------------------------------------------------*/ | ||
72 | void *ff_memalloc(UINT size) { | ||
73 | |||
74 | return chHeapAlloc(NULL, size); | ||
75 | } | ||
76 | |||
77 | /*------------------------------------------------------------------------*/ | ||
78 | /* Free a memory block */ | ||
79 | /*------------------------------------------------------------------------*/ | ||
80 | void ff_memfree(void *mblock) { | ||
81 | |||
82 | chHeapFree(mblock); | ||
83 | } | ||
84 | #endif /* FF_USE_LFN == 3 */ | ||