diff --git a/.gitignore b/.gitignore index 0202824..5bb9810 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.o *.bin -test/test -test/test.bin +image.elf +image.map tags core diff --git a/usecfs_dev_spi.c b/usecfs_dev_spi.c new file mode 100644 index 0000000..fbd8a10 --- /dev/null +++ b/usecfs_dev_spi.c @@ -0,0 +1,36 @@ +#include +#include "usecfs_dev.h" +#include "spi_flash.h" + +static uint32_t part_base = 0xFFFFFFFF; +static uint32_t part_size = 0; + +void *block_open(void *args_ptr) +{ + uint32_t *args = (uint32_t *)args_ptr; + part_base = args[0]; + part_size = args[1]; + return &part_base; +} + +int block_read(void *dev, void *_buf, uint32_t lba) +{ + if (part_size == 0) + return -1; + return spi_flash_read(part_base + (lba * BLOCK_SIZE), _buf, BLOCK_SIZE); +} + +int block_write(void *dev, const void *_buf, uint32_t lba) +{ + if (part_size == 0) + return -1; + spi_flash_sector_erase(part_base + lba * BLOCK_SIZE); + return spi_flash_write(part_base + lba * BLOCK_SIZE, _buf, BLOCK_SIZE); +} + +void block_close(void *dev) +{ + (void)dev; + part_base = 0xFFFFFFFF; + part_size = 0; +}