version 2.8
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.org/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 gfxSem 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, MAX_SEMAPHORE_COUNT);
32 
33  return 1;
34  }
35 
36  /*------------------------------------------------------------------------*/
37  /* Delete a Synchronization Object */
38  /*------------------------------------------------------------------------*/
39  int ff_del_syncobj(_SYNC_t sobj)
40  {
41  gfxSemDestroy( (gfxSem*)&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( (gfxSem*)&sobj, (delaytime_t)_FS_TIMEOUT) )
52  return TRUE;
53  return FALSE;
54  }
55 
56  /*------------------------------------------------------------------------*/
57  /* Release Grant to Access the Volume */
58  /*------------------------------------------------------------------------*/
59  void ff_rel_grant(_SYNC_t sobj)
60  {
61  gfxSemSignal( (gfxSem*)&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( (size_t)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 gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
Initialise a Counted Semaphore.
#define FALSE
Generic 'false' boolean constant.
Definition: gfx.h:31
void gfxSemDestroy(gfxSem *psem)
Destroy a Counted Semaphore.
void * gfxAlloc(size_t sz)
Allocate memory.
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
Wait on a semaphore.
A semaphore.
Definition: gos.h:105
void gfxFree(void *ptr)
Free memory.
void gfxSemSignal(gfxSem *psem)
Signal a semaphore.
#define TRUE
Generic 'true' boolean constant.
Definition: gfx.h:38