STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
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 #include <stdlib.h> /* ANSI memory controls */
7 #include "../ff.h"
8 
9 #if _FS_REENTRANT
10 /*-----------------------------------------------------------------------
11  Create a Synchronization Object
12 ------------------------------------------------------------------------
13  This function is called in f_mount function to create a new
14  synchronization object, such as semaphore and mutex. When a zero is
15  returned, the f_mount function fails with FR_INT_ERR.
16 */
17 
18 int ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */
19  BYTE vol, /* Corresponding logical drive being processed */
20  _SYNC_t *sobj /* Pointer to return the created sync object */
21 )
22 {
23  int ret;
24 
25  osSemaphoreDef(SEM);
26  *sobj = osSemaphoreCreate(osSemaphore(SEM), 1);
27  ret = (*sobj != NULL);
28 
29  return ret;
30 }
31 
32 
33 
34 /*------------------------------------------------------------------------*/
35 /* Delete a Synchronization Object */
36 /*------------------------------------------------------------------------*/
37 /* This function is called in f_mount function to delete a synchronization
38 / object that created with ff_cre_syncobj function. When a zero is
39 / returned, the f_mount function fails with FR_INT_ERR.
40 */
41 
42 int ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */
43  _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
44 )
45 {
46  osSemaphoreDelete (sobj);
47  return 1;
48 }
49 
50 
51 
52 /*------------------------------------------------------------------------*/
53 /* Request Grant to Access the Volume */
54 /*------------------------------------------------------------------------*/
55 /* This function is called on entering file functions to lock the volume.
56 / When a zero is returned, the file function fails with FR_TIMEOUT.
57 */
58 
59 int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
60  _SYNC_t sobj /* Sync object to wait */
61 )
62 {
63  int ret = 0;
64 
65  if(osSemaphoreWait(sobj, _FS_TIMEOUT) == osOK)
66  {
67  ret = 1;
68  }
69 
70  return ret;
71 }
72 
73 
74 
75 /*------------------------------------------------------------------------*/
76 /* Release Grant to Access the Volume */
77 /*------------------------------------------------------------------------*/
78 /* This function is called on leaving file functions to unlock the volume.
79 */
80 
81 void ff_rel_grant (
82  _SYNC_t sobj /* Sync object to be signaled */
83 )
84 {
85  osSemaphoreRelease(sobj);
86 }
87 
88 #endif
89 
90 
91 
92 
93 #if _USE_LFN == 3 /* LFN with a working buffer on the heap */
94 /*------------------------------------------------------------------------*/
95 /* Allocate a memory block */
96 /*------------------------------------------------------------------------*/
97 /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
98 */
99 
100 void* ff_memalloc ( /* Returns pointer to the allocated memory block */
101  UINT msize /* Number of bytes to allocate */
102 )
103 {
104  return malloc(msize); /* Allocate a new memory block with POSIX API */
105 }
106 
107 
108 /*------------------------------------------------------------------------*/
109 /* Free a memory block */
110 /*------------------------------------------------------------------------*/
111 
112 void ff_memfree (
113  void* mblock /* Pointer to the memory block to free */
114 )
115 {
116  free(mblock); /* Discard the memory block with POSIX API */
117 }
118 
119 #endif
osStatus osSemaphoreDelete(osSemaphoreId semaphore_id)
Delete a Semaphore.
Definition: cmsis_os.c:747
osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def, int32_t count)
Create and Initialize a Semaphore object used for managing resources.
Definition: cmsis_os.c:656
function completed; no error or event occurred.
Definition: cmsis_os.h:253
#define osSemaphore(name)
Definition: cmsis_os.h:653
#define NULL
Definition: usbd_def.h:53
unsigned char BYTE
Definition: integer.h:16
osStatus osSemaphoreRelease(osSemaphoreId semaphore_id)
Release a Semaphore token.
Definition: cmsis_os.c:720
unsigned int UINT
Definition: integer.h:25
int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec)
Wait until a Semaphore token becomes available.
Definition: cmsis_os.c:680
#define osSemaphoreDef(name)
Definition: cmsis_os.h:645