updated chan_fatfs

Dependents:   HARP2 HARP3

Fork of chan_fatfs by Eli Hughes

Committer:
tylerjw
Date:
Tue Dec 11 23:49:02 2012 +0000
Revision:
4:f88948891a05
Child:
6:d770e6821de6
added rtos functionality... syscall.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 4:f88948891a05 1 //------------------------------------------------------------------------/
tylerjw 4:f88948891a05 2 // Sample code of OS dependent controls for FatFs /
tylerjw 4:f88948891a05 3 // (C)ChaN, 2012 /
tylerjw 4:f88948891a05 4 //------------------------------------------------------------------------/
tylerjw 4:f88948891a05 5
tylerjw 4:f88948891a05 6 #include "ff.h"
tylerjw 4:f88948891a05 7 #include "rtos.h"
tylerjw 4:f88948891a05 8
tylerjw 4:f88948891a05 9 #if _FS_REENTRANT
tylerjw 4:f88948891a05 10 /*-----------------------------------------------------------------------/
tylerjw 4:f88948891a05 11 / Create a Synchronization Object
tylerjw 4:f88948891a05 12 /------------------------------------------------------------------------/
tylerjw 4:f88948891a05 13 / This function is called in f_mount function to create a new
tylerjw 4:f88948891a05 14 / synchronization object, such as semaphore and mutex. When a FALSE is
tylerjw 4:f88948891a05 15 / returned, the f_mount function fails with FR_INT_ERR.
tylerjw 4:f88948891a05 16 */
tylerjw 4:f88948891a05 17
tylerjw 4:f88948891a05 18 bool ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any error */
tylerjw 4:f88948891a05 19 BYTE vol, /* Corresponding logical drive being processed */
tylerjw 4:f88948891a05 20 _SYNC_t *sobj /* Pointer to return the created sync object */
tylerjw 4:f88948891a05 21 )
tylerjw 4:f88948891a05 22 {
tylerjw 4:f88948891a05 23 (*sobj) = new Semaphore(0);
tylerjw 4:f88948891a05 24
tylerjw 4:f88948891a05 25 return 1;
tylerjw 4:f88948891a05 26 }
tylerjw 4:f88948891a05 27
tylerjw 4:f88948891a05 28
tylerjw 4:f88948891a05 29
tylerjw 4:f88948891a05 30 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 31 /* Delete a Synchronization Object */
tylerjw 4:f88948891a05 32 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 33 /* This function is called in f_mount function to delete a synchronization
tylerjw 4:f88948891a05 34 / object that created with ff_cre_syncobj function. When a FALSE is
tylerjw 4:f88948891a05 35 / returned, the f_mount function fails with FR_INT_ERR.
tylerjw 4:f88948891a05 36 */
tylerjw 4:f88948891a05 37
tylerjw 4:f88948891a05 38 bool ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */
tylerjw 4:f88948891a05 39 _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
tylerjw 4:f88948891a05 40 )
tylerjw 4:f88948891a05 41 {
tylerjw 4:f88948891a05 42 delete sobj;
tylerjw 4:f88948891a05 43 return true;
tylerjw 4:f88948891a05 44 }
tylerjw 4:f88948891a05 45
tylerjw 4:f88948891a05 46
tylerjw 4:f88948891a05 47
tylerjw 4:f88948891a05 48 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 49 /* Request Grant to Access the Volume */
tylerjw 4:f88948891a05 50 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 51 /* This function is called on entering file functions to lock the volume.
tylerjw 4:f88948891a05 52 / When a FALSE is returned, the file function fails with FR_TIMEOUT.
tylerjw 4:f88948891a05 53 */
tylerjw 4:f88948891a05 54
tylerjw 4:f88948891a05 55 bool ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
tylerjw 4:f88948891a05 56 _SYNC_t sobj /* Sync object to wait */
tylerjw 4:f88948891a05 57 )
tylerjw 4:f88948891a05 58 {
tylerjw 4:f88948891a05 59 bool ret;
tylerjw 4:f88948891a05 60
tylerjw 4:f88948891a05 61 ret = (sobj->wait(_FS_TIMEOUT) > 0);
tylerjw 4:f88948891a05 62
tylerjw 4:f88948891a05 63 return ret;
tylerjw 4:f88948891a05 64 }
tylerjw 4:f88948891a05 65
tylerjw 4:f88948891a05 66
tylerjw 4:f88948891a05 67
tylerjw 4:f88948891a05 68 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 69 /* Release Grant to Access the Volume */
tylerjw 4:f88948891a05 70 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 71 /* This function is called on leaving file functions to unlock the volume.
tylerjw 4:f88948891a05 72 */
tylerjw 4:f88948891a05 73
tylerjw 4:f88948891a05 74 void ff_rel_grant (
tylerjw 4:f88948891a05 75 _SYNC_t sobj /* Sync object to be signaled */
tylerjw 4:f88948891a05 76 )
tylerjw 4:f88948891a05 77 {
tylerjw 4:f88948891a05 78 sobj->release();
tylerjw 4:f88948891a05 79 }
tylerjw 4:f88948891a05 80
tylerjw 4:f88948891a05 81 #endif
tylerjw 4:f88948891a05 82
tylerjw 4:f88948891a05 83
tylerjw 4:f88948891a05 84
tylerjw 4:f88948891a05 85
tylerjw 4:f88948891a05 86 #if _USE_LFN == 3 /* LFN with a working buffer on the heap */
tylerjw 4:f88948891a05 87 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 88 /* Allocate a memory block */
tylerjw 4:f88948891a05 89 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 90 /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
tylerjw 4:f88948891a05 91 */
tylerjw 4:f88948891a05 92
tylerjw 4:f88948891a05 93 void* ff_memalloc ( /* Returns pointer to the allocated memory block */
tylerjw 4:f88948891a05 94 UINT size /* Number of bytes to allocate */
tylerjw 4:f88948891a05 95 )
tylerjw 4:f88948891a05 96 {
tylerjw 4:f88948891a05 97 return malloc(size);
tylerjw 4:f88948891a05 98 }
tylerjw 4:f88948891a05 99
tylerjw 4:f88948891a05 100
tylerjw 4:f88948891a05 101 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 102 /* Free a memory block */
tylerjw 4:f88948891a05 103 /*------------------------------------------------------------------------*/
tylerjw 4:f88948891a05 104
tylerjw 4:f88948891a05 105 void ff_memfree (
tylerjw 4:f88948891a05 106 void* mblock /* Pointer to the memory block to free */
tylerjw 4:f88948891a05 107 )
tylerjw 4:f88948891a05 108 {
tylerjw 4:f88948891a05 109 free(mblock);
tylerjw 4:f88948891a05 110 }
tylerjw 4:f88948891a05 111
tylerjw 4:f88948891a05 112 #endif