Tyler Weaver / chan_fatfs_sd

Dependents:   HARP2 HARP3

Fork of chan_fatfs by Eli Hughes

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers syscall.cpp Source File

syscall.cpp

00001 //------------------------------------------------------------------------/
00002 // Sample code of OS dependent controls for FatFs                         /
00003 // (C)ChaN, 2012                                                          /
00004 //------------------------------------------------------------------------/
00005 
00006 #include "ff.h"
00007 #include "rtos.h"
00008 
00009 #if _FS_REENTRANT
00010 /*-----------------------------------------------------------------------/
00011 / Create a Synchronization Object
00012 /------------------------------------------------------------------------/
00013 / This function is called in f_mount function to create a new
00014 /  synchronization object, such as semaphore and mutex. When a FALSE is
00015 /  returned, the f_mount function fails with FR_INT_ERR.
00016 */
00017 
00018 bool ff_cre_syncobj (    /* 1:Function succeeded, 0:Could not create due to any error */
00019     BYTE vol,           /* Corresponding logical drive being processed */
00020     _SYNC_t *sobj       /* Pointer to return the created sync object */
00021 )
00022 {
00023     (*sobj) = new Semaphore(1);
00024 
00025     return 1;
00026 }
00027 
00028 
00029 
00030 /*------------------------------------------------------------------------*/
00031 /* Delete a Synchronization Object                                        */
00032 /*------------------------------------------------------------------------*/
00033 /* This function is called in f_mount function to delete a synchronization
00034 /  object that created with ff_cre_syncobj function. When a FALSE is
00035 /  returned, the f_mount function fails with FR_INT_ERR.
00036 */
00037 
00038 bool ff_del_syncobj (    /* 1:Function succeeded, 0:Could not delete due to any error */
00039     _SYNC_t sobj        /* Sync object tied to the logical drive to be deleted */
00040 )
00041 {
00042     delete sobj;
00043     return true;
00044 }
00045 
00046 
00047 
00048 /*------------------------------------------------------------------------*/
00049 /* Request Grant to Access the Volume                                     */
00050 /*------------------------------------------------------------------------*/
00051 /* This function is called on entering file functions to lock the volume.
00052 /  When a FALSE is returned, the file function fails with FR_TIMEOUT.
00053 */
00054 
00055 bool ff_req_grant (  /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
00056     _SYNC_t sobj    /* Sync object to wait */
00057 )
00058 {
00059     bool ret;
00060 
00061     ret = (sobj->wait(_FS_TIMEOUT) > 0);
00062 
00063     return ret;
00064 }
00065 
00066 
00067 
00068 /*------------------------------------------------------------------------*/
00069 /* Release Grant to Access the Volume                                     */
00070 /*------------------------------------------------------------------------*/
00071 /* This function is called on leaving file functions to unlock the volume.
00072 */
00073 
00074 void ff_rel_grant (
00075     _SYNC_t sobj    /* Sync object to be signaled */
00076 )
00077 {
00078     sobj->release();
00079 }
00080 
00081 #endif
00082 
00083 
00084 
00085 
00086 #if _USE_LFN == 3   /* LFN with a working buffer on the heap */
00087 /*------------------------------------------------------------------------*/
00088 /* Allocate a memory block                                                */
00089 /*------------------------------------------------------------------------*/
00090 /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
00091 */
00092 
00093 void* ff_memalloc ( /* Returns pointer to the allocated memory block */
00094     UINT size       /* Number of bytes to allocate */
00095 )
00096 {
00097     return malloc(size);
00098 }
00099 
00100 
00101 /*------------------------------------------------------------------------*/
00102 /* Free a memory block                                                    */
00103 /*------------------------------------------------------------------------*/
00104 
00105 void ff_memfree (
00106     void* mblock    /* Pointer to the memory block to free */
00107 )
00108 {
00109     free(mblock);
00110 }
00111 
00112 #endif