Included spi driver.
This commit is contained in:
parent
1c02765920
commit
eb1a572eff
2 changed files with 38 additions and 2 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,6 +1,6 @@
|
|||
*.o
|
||||
*.bin
|
||||
test/test
|
||||
test/test.bin
|
||||
image.elf
|
||||
image.map
|
||||
tags
|
||||
core
|
||||
|
|
36
usecfs_dev_spi.c
Normal file
36
usecfs_dev_spi.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <stdint.h>
|
||||
#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;
|
||||
}
|
Loading…
Reference in a new issue