Skip to content
Snippets Groups Projects
Select Git revision
  • 26a99207354787cd010b833c6ea8ad348c793820
  • wip-bootstrap default
  • dualcore
  • ch3/leds
  • ch3/time
  • master
6 results

main.c

Blame
  • filesystem_fat.c 14.02 KiB
    /*
     * Implementation of efs_ API functions for a FatFS specific
     * EpicFileSystem
     */
    
    #include <errno.h>
    #include <stddef.h>
    #include <stdio.h>
    #include <stdbool.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    
    #include <ff.h>
    #include <diskio.h>
    
    #include <FreeRTOS.h>
    #include <semphr.h>
    #include <timers.h>
    
    #include "fs/internal.h"
    #include "modules/filesystem.h"
    #include "epicardium.h"
    #include "card10.h"
    #include "modules/log.h"
    #include "modules/modules.h"
    #include "api/common.h"
    #include "core_cmFunc.h" //__get_IPSR()
    
    #define SSLOG_DEBUG(...) LOG_DEBUG("fatfs", __VA_ARGS__)
    #define SSLOG_INFO(...) LOG_INFO("fatfs", __VA_ARGS__)
    #define SSLOG_ERR(...) LOG_ERR("fatfs", __VA_ARGS__)
    
    #ifndef EPIC_FAT_STATIC_SEMAPHORE
    #define EPIC_FAT_STATIC_SEMAPHORE 0
    #endif
    
    /* clang-format off */
    #define EPIC_FAT_MAX_OPENED           (1 << (EPIC_FAT_FD_INDEX_BITS))
    #define EPIC_FAT_FD_GENERATION_BITS   (31 - (EPIC_FAT_FD_INDEX_BITS))
    #define EPIC_FAT_FD_INDEX_MASK        (uint32_t)((1u << EPIC_FAT_FD_INDEX_BITS) - 1)
    #define EPIC_FAT_FD_INDEX(fd)         ((uint32_t)(fd)&EPIC_FAT_FD_INDEX_MASK)
    #define EPIC_FAT_FD_GENERATION(fd)    ((uint32_t)(fd) >> EPIC_FAT_FD_INDEX_BITS)
    #define EPIC_FAT_FD_MAX_GENERATION    (uint32_t)((1u << EPIC_FAT_FD_GENERATION_BITS) - 1)
    #define EPIC_FAT_FD(idx, gen)         (int)(((uint32_t)(gen) << EPIC_FAT_FD_INDEX_BITS) \
                                          | ((uint32_t)(idx)&EPIC_FAT_FD_INDEX_MASK))
    /* clang-format on */
    
    struct FatObject {
    	uint32_t generation;
    	int coreMask;
    	enum epic_stat_type type;
    	union {
    		FIL file;
    		DIR dir;
    	};
    };
    
    struct EpicFileSystem {
    	struct FatObject pool[EPIC_FAT_MAX_OPENED];
    	uint32_t generationCount;
    	bool attached;
    	FATFS FatFs;
    	int lockCoreMask;
    };
    
    // this table converts from FRESULT to POSIX errno
    static const int s_libffToErrno[20];
    
    static const char *f_get_rc_string(FRESULT rc);