CARME-M4 BSP  V1.5
sync.c
Go to the documentation of this file.
1 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif /* __cplusplus */
76 
77 /*----- Header-Files -------------------------------------------------------*/
78 #include <_ansi.h> /* support for ANSI environments */
79 #include <stm32f4xx.h> /* Processor STM32F407IG */
80 #include <stddef.h> /* Standard defines */
81 #include <ff.h> /* Fat file system */
82 
83 #if _FS_REENTRANT
84 
85 /*----- Macros -------------------------------------------------------------*/
86 
87 /*----- Data types ---------------------------------------------------------*/
88 
89 /*----- Function prototypes ------------------------------------------------*/
90 
91 /*----- Data ---------------------------------------------------------------*/
92 _VOLATILE static uint8_t sync[_VOLUMES];
93 
94 /*----- Implementation -----------------------------------------------------*/
95 __attribute__((naked)) static uint32_t DisableGlobalInterrupt(void) {
96  __asm volatile
97  (
98  " mrs r0, basepri \n"
99  " mov r1, %0 \n"
100  " msr basepri, r1 \n"
101  " bx lr \n"
102  :: "i" (255) : "r0", "r1"
103  );
104 
105  /* This return will not be reached but is necessary to prevent compiler
106  * warnings. */
107  return 0;
108 }
109 
110 __attribute__((naked)) static void EnableGlobalInterrupt(
111  uint32_t ulNewMaskValue) {
112  __asm volatile
113  (
114  " msr basepri, r0 \n"
115  " bx lr \n"
116  :::"r0"
117  );
118 
119  /* Just to avoid compiler warnings. */
120  (void) ulNewMaskValue;
121 }
122 
133 __attribute__((weak)) int ff_cre_syncobj(BYTE vol, _SYNC_t *mutex) {
134 
135  _VOLATILE uint8_t **value = (_VOLATILE uint8_t **)mutex;
136 
137  /* Check if the drive number is valid */
138  if (vol >= _VOLUMES) {
139  return FR_INVALID_DRIVE;
140  }
141 
142  /* Get current fs object */
143  *value = &sync[vol];
144 
145  return (*mutex != NULL);
146 }
147 
157 __attribute__((weak)) int ff_del_syncobj(_SYNC_t mutex) {
158 
159  uint8_t *value = (uint8_t *)mutex;
160  uint32_t interrupts;
161 
162  interrupts = DisableGlobalInterrupt();
163  *value = 0;
164  EnableGlobalInterrupt(interrupts);
165 
166  return !0;
167 }
168 
178 __attribute__((weak)) int ff_req_grant(_SYNC_t mutex) {
179 
180  uint8_t *value = (uint8_t *)mutex;
181  uint32_t interrupts;
182  uint8_t granted = 0;
183 
184  interrupts = DisableGlobalInterrupt();
185  if (!(*value)) {
186  *value = 1;
187  granted = 1;
188  }
189  EnableGlobalInterrupt(interrupts);
190 
191  return granted;
192 }
193 
201 __attribute__((weak)) void ff_rel_grant(_SYNC_t mutex) {
202 
203  uint8_t *value = (uint8_t *)mutex;
204  uint32_t interrupts;
205 
206  interrupts = DisableGlobalInterrupt();
207  *value = 0;
208  EnableGlobalInterrupt(interrupts);
209 }
210 
211 #endif /* _FS_REENTRANT */
212 
213 #ifdef __cplusplus
214 }
215 #endif /* __cplusplus */
216 
int ff_del_syncobj(_SYNC_t sobj)
#define NULL
SDIO Static flags, TimeOut, FIFO Address.
#define _SYNC_t
O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc..
Definition: ffconf.h:379
int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj)
void ff_rel_grant(_SYNC_t sobj)
int ff_req_grant(_SYNC_t sobj)
#define _VOLUMES
Number of volumes (logical drives) to be used.
Definition: ffconf.h:267