-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathff_iso.c
340 lines (337 loc) · 9.65 KB
/
ff_iso.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#include "ff_iso.h"
#if (osCMSIS < 0x20000U)
osMutexId ffMutexID;
#else
osMutexId_t ffMutexID;
#endif
ff_iso_t ff_iso;
//##############################################################################################################
FRESULT ff_mount(FATFS *fs, const TCHAR *path, BYTE opt)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.fs = fs;
ff_iso.path = (TCHAR*) path;
ff_iso.opt = opt;
ff_iso.func = FF_ISO_MOUNT;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_open(FIL *fp, const TCHAR *path, BYTE mode)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.fp = fp;
ff_iso.path = (TCHAR*) path;
ff_iso.mode = mode;
ff_iso.func = FF_ISO_OPEN;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_close(FIL *fp)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.func = FF_ISO_CLOSE;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_read(FIL *fp, void *buff, UINT btr, UINT *br)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.fp = fp;
ff_iso.buff = buff;
ff_iso.len = btr;
ff_iso.ptr = br;
ff_iso.func = FF_ISO_READ;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_write(FIL *fp, const void *buff, UINT btw, UINT *bw)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.fp = fp;
ff_iso.buff = (void*) buff;
ff_iso.len = btw;
ff_iso.ptr = bw;
ff_iso.func = FF_ISO_WRITE;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
int ff_puts(const TCHAR *str, FIL *cp)
{
int res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.fp = cp;
ff_iso.tbuff = (TCHAR*) str;
ff_iso.func = FF_ISO_PUTS;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.int32;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
TCHAR* ff_gets (TCHAR* buff, int len, FIL* fp)
{
int res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.fp = fp;
ff_iso.int32 = len;
ff_iso.buff = buff;
ff_iso.func = FF_ISO_GETS;
while (ff_iso.end == 0)
osDelay(1);
osMutexRelease(ffMutexID);
return ff_iso.tbuff;
}
//##############################################################################################################
FRESULT ff_opendir(DIR *dp, const TCHAR *path)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.dp = dp;
ff_iso.path = (TCHAR*) path;
ff_iso.func = FF_ISO_OPENDIR;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_closedir(DIR *dp)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.dp = dp;
ff_iso.func = FF_ISO_CLOSEDIR;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_readdir(DIR *dp, FILINFO *fno)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.dp = dp;
ff_iso.fno = fno;
ff_iso.func = FF_ISO_READDIR;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_findfirst(DIR *dp, FILINFO *fno, const TCHAR *path, const TCHAR *pattern)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.dp = dp;
ff_iso.fno = fno;
ff_iso.path = (TCHAR*) path;
ff_iso.tbuff = (TCHAR*) pattern;
ff_iso.func = FF_ISO_FINDFIRST;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_findnext(DIR *dp, FILINFO *fno)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.dp = dp;
ff_iso.fno = fno;
ff_iso.func = FF_ISO_FINDNEXT;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_mkdir(const TCHAR *path)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.path = (TCHAR*) path;
ff_iso.func = FF_ISO_MKDIR;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_unlink(const TCHAR *path)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.path = (TCHAR*) path;
ff_iso.func = FF_ISO_UNLINK;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
FRESULT ff_rename(const TCHAR *path_old, const TCHAR *path_new)
{
FRESULT res;
osMutexWait(ffMutexID, portMAX_DELAY);
ff_iso.end = 0;
ff_iso.path = (TCHAR*) path_old;
ff_iso.tbuff = (TCHAR*) path_new;
ff_iso.func = FF_ISO_RENAME;
while (ff_iso.end == 0)
osDelay(1);
res = ff_iso.res;
osMutexRelease(ffMutexID);
return res;
}
//##############################################################################################################
//##############################################################################################################
//##############################################################################################################
void ff_loop(void)
{
switch (ff_iso.func)
{
case FF_ISO_IDLE:
break;
case FF_ISO_MOUNT:
ff_iso.res = f_mount(ff_iso.fs, ff_iso.path, ff_iso.opt);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_OPEN:
ff_iso.res = f_open(ff_iso.fp, ff_iso.path, ff_iso.mode);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_CLOSE:
ff_iso.res = f_close(ff_iso.fp);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_READ:
ff_iso.res = f_read(ff_iso.fp, ff_iso.buff, ff_iso.len, ff_iso.ptr);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_WRITE:
ff_iso.res = f_write(ff_iso.fp, ff_iso.buff, ff_iso.len, ff_iso.ptr);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_PUTS:
ff_iso.int32 = f_puts(ff_iso.tbuff, ff_iso.fp);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_GETS:
ff_iso.tbuff = f_gets(ff_iso.buff, ff_iso.int32, ff_iso.fp);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_OPENDIR:
ff_iso.res = f_opendir(ff_iso.dp, ff_iso.path);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_CLOSEDIR:
ff_iso.res = f_closedir(ff_iso.dp);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_READDIR:
ff_iso.res = f_readdir(ff_iso.dp, ff_iso.fno);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_FINDFIRST:
ff_iso.res = f_findfirst(ff_iso.dp, ff_iso.fno, ff_iso.path, ff_iso.tbuff);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_FINDNEXT:
ff_iso.res = f_findnext(ff_iso.dp, ff_iso.fno);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_MKDIR:
ff_iso.res = f_mkdir(ff_iso.path);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_UNLINK:
ff_iso.res = f_unlink(ff_iso.path);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
case FF_ISO_RENAME:
ff_iso.res = f_rename(ff_iso.path, ff_iso.tbuff);
ff_iso.end = 1;
ff_iso.func = FF_ISO_IDLE;
break;
}
osDelay(1);
}
//##############################################################################################################
FRESULT ff_init(void)
{
osMutexDef(ffMutex);
#if (osCMSIS < 0x20000U)
ffMutexID = osMutexCreate(osMutex(ffMutex));
#else
ffMutexID = osMutexNew(osMutex(ffMutex));
#endif
if (ffMutexID != NULL)
return FR_OK;
else
return FR_NOT_ENABLED;
}
//##############################################################################################################