ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
syscall.c
Go to the documentation of this file.
1 /*------------------------------------------------------------------------*/
2 /* Sample code of OS dependent controls for FatFs */
3 /* (C)ChaN, 2014 */
4 /*------------------------------------------------------------------------*/
5 
6 
7 
8 #include "user_config.h"
9 #include "fatfs.h"
10 
11 #ifdef AVR
12 #include <stdlib.h>
13 #endif
14 
15 #include "fatfs/ff.h" /* Declarations of FatFs API */
16 
17 
18 
19 #if _FS_REENTRANT
20 /*------------------------------------------------------------------------*/
21 /* Create a Synchronization Object
22 /*------------------------------------------------------------------------*/
23 /* This function is called in f_mount() function to create a new
24 / synchronization object, such as semaphore and mutex. When a 0 is returned,
25 / the f_mount() function fails with FR_INT_ERR.
26 */
27 
28 
30 int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
31  BYTE vol, /* Corresponding volume (logical drive number) */
32  _SYNC_t *sobj /* Pointer to return the created sync object */
33 )
34 {
35  int ret;
36 
37 
38  *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */
39  ret = (int)(*sobj != INVALID_HANDLE_VALUE);
40 
41 // *sobj = SyncObjects[vol]; /* uITRON (give a static sync object) */
42 // ret = 1; /* The initial value of the semaphore must be 1. */
43 
44 // *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
45 // ret = (int)(err == OS_NO_ERR);
46 
47 // *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
48 // ret = (int)(*sobj != NULL);
49 
50  return ret;
51 }
52 
53 
54 
55 /*------------------------------------------------------------------------*/
56 /* Delete a Synchronization Object */
57 /*------------------------------------------------------------------------*/
58 /* This function is called in f_mount() function to delete a synchronization
59 / object that created with ff_cre_syncobj() function. When a 0 is returned,
60 / the f_mount() function fails with FR_INT_ERR.
61 */
62 
64 int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */
65  _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
66 )
67 {
68  int ret;
69 
70 
71  ret = CloseHandle(sobj); /* Win32 */
72 
73 // ret = 1; /* uITRON (nothing to do) */
74 
75 // OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
76 // ret = (int)(err == OS_NO_ERR);
77 
78 // vSemaphoreDelete(sobj); /* FreeRTOS */
79 // ret = 1;
80 
81  return ret;
82 }
83 
84 
85 
86 /*------------------------------------------------------------------------*/
87 /* Request Grant to Access the Volume */
88 /*------------------------------------------------------------------------*/
89 /* This function is called on entering file functions to lock the volume.
90 / When a 0 is returned, the file function fails with FR_TIMEOUT.
91 */
92 
94 int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
95  _SYNC_t sobj /* Sync object to wait */
96 )
97 {
98  int ret;
99 
100  ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */
101 
102 // ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */
103 
104 // OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */
105 // ret = (int)(err == OS_NO_ERR);
106 
107 // ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
108 
109  return ret;
110 }
111 
112 
113 
114 /*------------------------------------------------------------------------*/
115 /* Release Grant to Access the Volume */
116 /*------------------------------------------------------------------------*/
117 /* This function is called on leaving file functions to unlock the volume.
118 */
119 
120 MEMSPACE
121 void ff_rel_grant (
122  _SYNC_t sobj /* Sync object to be signaled */
123 )
124 {
125  ReleaseMutex(sobj); /* Win32 */
126 
127 // sig_sem(sobj); /* uITRON */
128 
129 // OSMutexPost(sobj); /* uC/OS-II */
130 
131 // xSemaphoreGive(sobj); /* FreeRTOS */
132 }
133 
134 #endif
135 
136 
137 
138 
139 #if _USE_LFN == 3 /* LFN with a working buffer on the heap */
140 /*------------------------------------------------------------------------*/
141 /* Allocate a memory block */
142 /*------------------------------------------------------------------------*/
143 /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
144 */
145 
146 MEMSPACE
147 void* ff_memalloc ( /* Returns pointer to the allocated memory block */
148  UINT msize /* Number of bytes to allocate */
149 )
150 {
151  return safemalloc(msize); /* Allocate a new memory block with POSIX API */
152 }
153 
154 
155 /*------------------------------------------------------------------------*/
156 /* Free a memory block */
157 /*------------------------------------------------------------------------*/
158 
159 MEMSPACE
160 void ff_memfree (
161  void* mblock /* Pointer to the memory block to free */
162 )
163 {
164  safefree(mblock); /* Discard the memory block with POSIX API */
165 }
166 
167 #endif
Master include file for project Includes all project includes and defines here.
#define _FS_TIMEOUT
Definition: ffconf.h:256
unsigned char BYTE
Definition: integer.h:22
#define NULL
Definition: cpu.h:55
MEMSPACE void * safemalloc(size_t size)
Safe Malloc - Display Error message if Malloc fails.
Definition: system.c:146
void * ff_memalloc(UINT msize)
#define MEMSPACE
Definition: cpu.h:25
unsigned int UINT
Definition: integer.h:19
#define _SYNC_t
Definition: ffconf.h:257
void ff_memfree(void *mblock)
MEMSPACE void safefree(void *p)
Safe free - Only free a pointer if it is in malloc memory range. We want to try to catch frees of sta...
Definition: system.c:165