source: azure_iot_hub_f767zi/trunk/asp_baseplatform/files/ff/option/syncobj.c@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 3.7 KB
Line 
1/*------------------------------------------------------------------------*/
2/* Sample code of OS dependent synchronization object controls */
3/* for FatFs R0.07a (C)ChaN, 2009 */
4/*------------------------------------------------------------------------*/
5
6//#include <windows.h> // Win32
7#include <kernel.h>
8#include "kernel_cfg.h"
9//#include <ucos_ii.h> // uC/OS-II
10
11#include "../ff.h"
12
13#if _FS_REENTRANT
14
15static const ID VolumeSemId[4] = {
16 SEMID_FATFS1,
17 SEMID_FATFS2,
18 SEMID_FATFS3,
19 SEMID_FATFS4
20};
21
22/*------------------------------------------------------------------------*/
23/* Create a Synchronization Object for a Volume */
24/*------------------------------------------------------------------------*/
25/* This function is called in f_mount function to create a new
26/ synchronization object, such as semaphore and mutex. When a FALSE is
27/ returned, the f_mount function fails with FR_INT_ERR.
28*/
29
30BOOL ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */
31 BYTE vol, /* Corresponding logical drive being processed */
32 _SYNC_t *sobj /* Pointer to return the created sync object */
33)
34{
35 BOOL ret;
36
37// *sobj = CreateMutex(NULL, FALSE, NULL); // Win32
38// ret = (*sobj != INVALID_HANDLE_VALUE) ? TRUE : FALSE; //
39
40 *sobj = VolumeSemId[vol]; // uITRON (give a static created sync object)
41 ret = TRUE; // The initial value of the semaphore must be 1.
42
43// *sobj = OSMutexCreate(0, &err); // uC/OS-II
44// ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
45
46 return ret;
47}
48
49
50
51/*------------------------------------------------------------------------*/
52/* Delete a Synchronization Object */
53/*------------------------------------------------------------------------*/
54/* This function is called in f_mount function to delete a synchronization
55/ object that created with ff_cre_syncobj function. When a FALSE is
56/ returned, the f_mount function fails with FR_INT_ERR.
57*/
58
59BOOL ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */
60 _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
61)
62{
63 BOOL ret;
64
65// ret = CloseHandle(sobj); // Win32
66
67 ret = TRUE; // uITRON (nothing to do)
68
69// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); // uC/OS-II
70// ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
71
72 return ret;
73}
74
75
76
77/*------------------------------------------------------------------------*/
78/* Request Grant to Access the Volume */
79/*------------------------------------------------------------------------*/
80/* This function is called on entering file functions to lock the volume.
81/ When a FALSE is returned, the file function fails with FR_TIMEOUT.
82*/
83
84BOOL ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
85 _SYNC_t sobj /* Sync object to wait */
86)
87{
88 BOOL ret;
89
90// ret = (WaitForSingleObject(sobj, _TIMEOUT) == WAIT_OBJECT_0) ? TRUE : FALSE; // Win32
91
92 ret = (wai_sem(sobj) == E_OK) ? TRUE : FALSE; // uITRON
93
94// OSMutexPend(sobj, _TIMEOUT, &err)); // uC/OS-II
95// ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
96
97 return ret;
98}
99
100
101
102/*------------------------------------------------------------------------*/
103/* Release Grant to Access the Volume */
104/*------------------------------------------------------------------------*/
105/* This function is called on leaving file functions to unlock the volume.
106*/
107
108void ff_rel_grant (
109 _SYNC_t sobj /* Sync object to be signaled */
110)
111{
112// ReleaseMutex(sobj); // Win32
113
114 sig_sem(sobj); // uITRON
115
116// OSMutexPost(sobj); // uC/OS-II
117}
118
119
120#else
121
122#error This file is not needed in this configuration.
123
124#endif
Note: See TracBrowser for help on using the repository browser.