/* Glue functions to bind FatFS to rest of the system. */ #include "fatfs/ff.h" #include "FreeRTOS.h" #include "semphr.h" #include static FATFS fs; xSemaphoreHandle mmc_dma_semaphore; void fatfs_init() { // Initialize filesystem structure FRESULT status = f_mount(0, &fs); if (status != FR_OK) { fprintf(stderr, "f_mount: %d\n", status); } // Semaphore to communicate between ISR and main thread in mmc.c vSemaphoreCreateBinary(mmc_dma_semaphore); xSemaphoreTake(mmc_dma_semaphore, 0); // Clear semaphore } DWORD get_fattime (void) { /* Pack date and time into a DWORD variable */ return ((DWORD)(2000 - 1980) << 25) | ((DWORD)1 << 21) | ((DWORD)1 << 16) | ((DWORD)13 << 11) | ((DWORD)37 << 5) | ((DWORD)0 >> 1); } /* Create a sync object */ int ff_cre_syncobj (BYTE volume, _SYNC_t* dest) { *dest = xSemaphoreCreateMutex(); return *dest != NULL; } /* Lock sync object */ int ff_req_grant (_SYNC_t mutex) { return xSemaphoreTake(mutex, _FS_TIMEOUT); } /* Unlock sync object */ void ff_rel_grant (_SYNC_t mutex) { xSemaphoreGive(mutex); } /* Delete a sync object */ int ff_del_syncobj (_SYNC_t mutex) { vQueueDelete(mutex); return 1; }