From eb1a572eff56445bfee94b3aa945887ba9da6a6f Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Sat, 2 Nov 2019 14:45:27 +0100 Subject: [PATCH] Included spi driver. --- .gitignore | 4 ++-- usecfs_dev_spi.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 usecfs_dev_spi.c 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; +}