fs.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <generated/csr.h>
  2. #include <liblitesdcard/sdcard.h>
  3. #ifndef CSR_SDCORE_BASE
  4. #error CSR_SDCORE_BASE not defined
  5. #else
  6. #include <libfatfs/diskio.h>
  7. DISKOPS *FfDiskOps; //this is needed only for fatfs, but required to compile
  8. #include "fat_io_lib/src/fat_access.c"
  9. #include "fat_io_lib/src/fat_cache.c"
  10. #include "fat_io_lib/src/fat_filelib.c"
  11. #include "fat_io_lib/src/fat_format.c"
  12. #include "fat_io_lib/src/fat_misc.c"
  13. #include "fat_io_lib/src/fat_string.c"
  14. #include "fat_io_lib/src/fat_table.c"
  15. #include "fat_io_lib/src/fat_write.c"
  16. static int sd_readsector(uint32_t start_block, uint8_t *buffer, uint32_t sector_count)
  17. {
  18. sdcard_read(start_block, sector_count, buffer);
  19. return sector_count;
  20. }
  21. static int sd_writesector(uint32_t start_block, uint8_t *buffer, uint32_t sector_count)
  22. {
  23. sdcard_write(start_block, sector_count, buffer);
  24. return sector_count;
  25. }
  26. DISKOPS *FfDiskOps; //this is needed to allow litex's library to compile
  27. int fat_io_init(void)
  28. {
  29. sdcard_init();
  30. fl_init();
  31. return fl_attach_media(sd_readsector, sd_writesector);
  32. }
  33. #endif