HP85 GPIB Disk Emulator  1.0
HP85GPIBDiskEmulator
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ffsystem.c
Go to the documentation of this file.
1 /*------------------------------------------------------------------------*/
2 /* Sample Code of OS Dependent Functions for FatFs */
3 /* (C)ChaN, 2018 */
4 /*------------------------------------------------------------------------*/
5 
6 
7 #include "user_config.h"
8 #include "fatfs.h"
9 
10 #ifdef AVR
11 #include <stdlib.h>
12 #endif
13 
14 #include "ff.h"
15 
16 
17 #if FF_USE_LFN == 3 /* Dynamic memory allocation */
18 
19 /*------------------------------------------------------------------------*/
20 /* Allocate a memory block */
21 /*------------------------------------------------------------------------*/
22 
23 void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
24  UINT msize /* Number of bytes to allocate */
25 )
26 {
27  return safemalloc(msize); /* Allocate a new memory block with POSIX API */
28 }
29 
30 
31 /*------------------------------------------------------------------------*/
32 /* Free a memory block */
33 /*------------------------------------------------------------------------*/
34 
35 void ff_memfree (
36  void* mblock /* Pointer to the memory block to free (nothing to do if null) */
37 )
38 {
39  safefree(mblock); /* Free the memory block with POSIX API */
40 }
41 
42 #endif
43 
44 
45 
46 //NOT USED in the hp85disk project
47 #if FF_FS_REENTRANT /* Mutal exclusion */
48 
49 /*------------------------------------------------------------------------*/
50 /* Create a Synchronization Object */
51 /*------------------------------------------------------------------------*/
52 /* This function is called in f_mount() function to create a new
53 / synchronization object for the volume, such as semaphore and mutex.
54 / When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
55 */
56 
57 //const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */
58 
59 
60 int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
61  BYTE vol, /* Corresponding volume (logical drive number) */
62  FF_SYNC_t* sobj /* Pointer to return the created sync object */
63 )
64 {
65  /* Win32 */
66  *sobj = CreateMutex(NULL, FALSE, NULL);
67  return (int)(*sobj != INVALID_HANDLE_VALUE);
68 
69  /* uITRON */
70 // T_CSEM csem = {TA_TPRI,1,1};
71 // *sobj = acre_sem(&csem);
72 // return (int)(*sobj > 0);
73 
74  /* uC/OS-II */
75 // OS_ERR err;
76 // *sobj = OSMutexCreate(0, &err);
77 // return (int)(err == OS_NO_ERR);
78 
79  /* FreeRTOS */
80 // *sobj = xSemaphoreCreateMutex();
81 // return (int)(*sobj != NULL);
82 
83  /* CMSIS-RTOS */
84 // *sobj = osMutexCreate(&Mutex[vol]);
85 // return (int)(*sobj != NULL);
86 }
87 
88 
89 /*------------------------------------------------------------------------*/
90 /* Delete a Synchronization Object */
91 /*------------------------------------------------------------------------*/
92 /* This function is called in f_mount() function to delete a synchronization
93 / object that created with ff_cre_syncobj() function. When a 0 is returned,
94 / the f_mount() function fails with FR_INT_ERR.
95 */
96 
97 int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
98  FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
99 )
100 {
101  /* Win32 */
102  return (int)CloseHandle(sobj);
103 
104  /* uITRON */
105 // return (int)(del_sem(sobj) == E_OK);
106 
107  /* uC/OS-II */
108 // OS_ERR err;
109 // OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
110 // return (int)(err == OS_NO_ERR);
111 
112  /* FreeRTOS */
113 // vSemaphoreDelete(sobj);
114 // return 1;
115 
116  /* CMSIS-RTOS */
117 // return (int)(osMutexDelete(sobj) == osOK);
118 }
119 
120 
121 /*------------------------------------------------------------------------*/
122 /* Request Grant to Access the Volume */
123 /*------------------------------------------------------------------------*/
124 /* This function is called on entering file functions to lock the volume.
125 / When a 0 is returned, the file function fails with FR_TIMEOUT.
126 */
127 
128 int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
129  FF_SYNC_t sobj /* Sync object to wait */
130 )
131 {
132  /* Win32 */
133  return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
134 
135  /* uITRON */
136 // return (int)(wai_sem(sobj) == E_OK);
137 
138  /* uC/OS-II */
139 // OS_ERR err;
140 // OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
141 // return (int)(err == OS_NO_ERR);
142 
143  /* FreeRTOS */
144 // return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
145 
146  /* CMSIS-RTOS */
147 // return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
148 }
149 
150 
151 /*------------------------------------------------------------------------*/
152 /* Release Grant to Access the Volume */
153 /*------------------------------------------------------------------------*/
154 /* This function is called on leaving file functions to unlock the volume.
155 */
156 
157 void ff_rel_grant (
158  FF_SYNC_t sobj /* Sync object to be signaled */
159 )
160 {
161  /* Win32 */
162  ReleaseMutex(sobj);
163 
164  /* uITRON */
165 // sig_sem(sobj);
166 
167  /* uC/OS-II */
168 // OSMutexPost(sobj);
169 
170  /* FreeRTOS */
171 // xSemaphoreGive(sobj);
172 
173  /* CMSIS-RTOS */
174 // osMutexRelease(sobj);
175 }
176 
177 #endif
178 
fatfs.h
BYTE
unsigned char BYTE
Definition: ff.h:54
ff_memalloc
void * ff_memalloc(UINT msize)
Definition: ffsystem.c:23
safefree
void safefree(void *p)
Safe free - Only free a pointer if it is in malloc memory range.
Definition: ram.c:158
UINT
unsigned int UINT
Definition: ff.h:53
safemalloc
void * safemalloc(size_t size)
Safe Malloc - Display Error message if Malloc fails.
Definition: ram.c:139
NULL
#define NULL
Definition: user_config.h:85
ff.h
ff_memfree
void ff_memfree(void *mblock)
Definition: ffsystem.c:35
FF_SYNC_t
#define FF_SYNC_t
Definition: ffconf.h:281
FF_FS_TIMEOUT
#define FF_FS_TIMEOUT
Definition: ffconf.h:280