µGFX  2.9
version 2.9
gfile_fatfs_wrapper.c
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 #include "../../gfx.h"
9 
10 #if GFX_USE_GFILE && GFILE_NEED_FATFS && !GFILE_FATFS_EXTERNAL_LIB
11 
12 #include "gfile_fatfs_wrapper.h"
13 
14 // Include the source we want
15 #include "../../3rdparty/fatfs-0.13/source/ff.c"
16 #include "../../3rdparty/fatfs-0.13/source/ffunicode.c"
17 
18 // Extra operating system support
19 #if _FS_REENTRANT
20  /*------------------------------------------------------------------------*/
21  /* Static array of Synchronization Objects */
22  /*------------------------------------------------------------------------*/
23  static gSem ff_sem[_VOLUMES];
24 
25  /*------------------------------------------------------------------------*/
26  /* Create a Synchronization Object */
27  /*------------------------------------------------------------------------*/
28  int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj)
29  {
30  *sobj = ff_sem[vol];
31  gfxSemInit(sobj, 1, gSemMaxCount);
32 
33  return 1;
34  }
35 
36  /*------------------------------------------------------------------------*/
37  /* Delete a Synchronization Object */
38  /*------------------------------------------------------------------------*/
39  int ff_del_syncobj(_SYNC_t sobj)
40  {
41  gfxSemDestroy( (gSem*)&sobj );
42 
43  return 1;
44  }
45 
46  /*------------------------------------------------------------------------*/
47  /* Request Grant to Access the Volume */
48  /*------------------------------------------------------------------------*/
49  int ff_req_grant(_SYNC_t sobj)
50  {
51  if (gfxSemWait( (gSem*)&sobj, (gDelay)_FS_TIMEOUT) )
52  return gTrue;
53  return gFalse;
54  }
55 
56  /*------------------------------------------------------------------------*/
57  /* Release Grant to Access the Volume */
58  /*------------------------------------------------------------------------*/
59  void ff_rel_grant(_SYNC_t sobj)
60  {
61  gfxSemSignal( (gSem*)&sobj );
62  }
63 #endif /* _FS_REENTRANT */
64 
65 #if _USE_LFN == 3 /* LFN with a working buffer on the heap */
66  /*------------------------------------------------------------------------*/
67  /* Allocate a memory block */
68  /*------------------------------------------------------------------------*/
69  void *ff_memalloc(UINT size)
70  {
71  return gfxAlloc( (gMemSize)size );
72  }
73 
74  /*------------------------------------------------------------------------*/
75  /* Free a memory block */
76  /*------------------------------------------------------------------------*/
77  void ff_memfree(void *mblock)
78  {
79  gfxFree(mblock);
80  }
81 #endif /* _USE_LFN == 3 */
82 
83 #endif // GFX_USE_GFILE && GFILE_NEED_FATFS && !GFILE_FATFS_EXTERNAL_LIB
GFILE FATFS wrapper.
void gfxSemSignal(gSem *psem)
Signal a semaphore.
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void * gfxAlloc(gMemSize sz)
Allocate memory.
void gfxSemDestroy(gSem *psem)
Destroy a Counted Semaphore.
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
Initialise a Counted Semaphore.
void gfxFree(void *ptr)
Free memory.
A semaphore.
Definition: gos.h:104