updated chan_fatfs
Fork of chan_fatfs by
Revision 4:f88948891a05, committed 2012-12-11
- Comitter:
- tylerjw
- Date:
- Tue Dec 11 23:49:02 2012 +0000
- Parent:
- 3:68eaafe726ac
- Child:
- 5:2f921c306d4f
- Commit message:
- added rtos functionality... syscall.cpp
Changed in this revision
--- a/diskio.cpp Tue Dec 11 23:02:31 2012 +0000 +++ b/diskio.cpp Tue Dec 11 23:49:02 2012 +0000 @@ -82,7 +82,7 @@ return res; } -DSTATUS disk_initialize(BYTE Drive) +DSTATUS card_initialize(BYTE Drive) { // Set to 100kHz for initialisation, and clock card with cs = 1 _spi.frequency(100000); @@ -130,6 +130,11 @@ debug("Not in idle state after sending CMD8 (not an SD card?)\n"); return STA_NOINIT; } +} + +DSTATUS disk_initialize(BYTE Drive) +{ + DSTATUS ret = card_initialize(Drive); _sectors = _sd_sectors(); @@ -140,7 +145,7 @@ } _spi.frequency(10000000); // Set to 10MHz for data transfer - return 0; + return ret; } DRESULT disk_write(BYTE Drive,const BYTE * Buffer, DWORD SectorNumber, BYTE SectorCount)
--- a/ff.h Tue Dec 11 23:02:31 2012 +0000 +++ b/ff.h Tue Dec 11 23:49:02 2012 +0000 @@ -18,6 +18,7 @@ #include "integer.h" /* Basic integer types */ #include "ffconf.h" /* FatFs configuration options */ +#include "rtos.h" #if _FATFS != _FFCONFIG #error Wrong configuration file (ffconf.h).
--- a/ffconf.h Tue Dec 11 23:02:31 2012 +0000 +++ b/ffconf.h Tue Dec 11 23:49:02 2012 +0000 @@ -86,7 +86,7 @@ */ -#define _USE_LFN 1 /* 0, 1 or 2 */ +#define _USE_LFN 0 /* 0, 1 or 2 */ #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ /* The _USE_LFN option switches the LFN support. / @@ -152,9 +152,9 @@ / performance and code size. */ -#define _FS_REENTRANT 0 /* 0 or 1 */ -#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ -#define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */ +#define _FS_REENTRANT 1 /* 0 or 1 */ +#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ +#define _SYNC_t Semaphore* /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */ /* The _FS_REENTRANT option switches the reentrancy of the FatFs module. / / 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/syscall.cpp Tue Dec 11 23:49:02 2012 +0000 @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------/ +// Sample code of OS dependent controls for FatFs / +// (C)ChaN, 2012 / +//------------------------------------------------------------------------/ + +#include "ff.h" +#include "rtos.h" + +#if _FS_REENTRANT +/*-----------------------------------------------------------------------/ +/ Create a Synchronization Object +/------------------------------------------------------------------------/ +/ This function is called in f_mount function to create a new +/ synchronization object, such as semaphore and mutex. When a FALSE is +/ returned, the f_mount function fails with FR_INT_ERR. +*/ + +bool ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any error */ + BYTE vol, /* Corresponding logical drive being processed */ + _SYNC_t *sobj /* Pointer to return the created sync object */ +) +{ + (*sobj) = new Semaphore(0); + + return 1; +} + + + +/*------------------------------------------------------------------------*/ +/* Delete a Synchronization Object */ +/*------------------------------------------------------------------------*/ +/* This function is called in f_mount function to delete a synchronization +/ object that created with ff_cre_syncobj function. When a FALSE is +/ returned, the f_mount function fails with FR_INT_ERR. +*/ + +bool ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */ + _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ +) +{ + delete sobj; + return true; +} + + + +/*------------------------------------------------------------------------*/ +/* Request Grant to Access the Volume */ +/*------------------------------------------------------------------------*/ +/* This function is called on entering file functions to lock the volume. +/ When a FALSE is returned, the file function fails with FR_TIMEOUT. +*/ + +bool ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */ + _SYNC_t sobj /* Sync object to wait */ +) +{ + bool ret; + + ret = (sobj->wait(_FS_TIMEOUT) > 0); + + return ret; +} + + + +/*------------------------------------------------------------------------*/ +/* Release Grant to Access the Volume */ +/*------------------------------------------------------------------------*/ +/* This function is called on leaving file functions to unlock the volume. +*/ + +void ff_rel_grant ( + _SYNC_t sobj /* Sync object to be signaled */ +) +{ + sobj->release(); +} + +#endif + + + + +#if _USE_LFN == 3 /* LFN with a working buffer on the heap */ +/*------------------------------------------------------------------------*/ +/* Allocate a memory block */ +/*------------------------------------------------------------------------*/ +/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. +*/ + +void* ff_memalloc ( /* Returns pointer to the allocated memory block */ + UINT size /* Number of bytes to allocate */ +) +{ + return malloc(size); +} + + +/*------------------------------------------------------------------------*/ +/* Free a memory block */ +/*------------------------------------------------------------------------*/ + +void ff_memfree ( + void* mblock /* Pointer to the memory block to free */ +) +{ + free(mblock); +} + +#endif