adding lfs
This commit is contained in:
1 parent
c2e1bf11ee
commit
4482a07bbf
5 files changed
+95
-7
No files matched your search
@@ -37,16 +37,79 @@
|
||||
#include <Arduino.h>
|
||||
#include "InternalFS.h"
|
||||
|
||||
extern "C"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
#define LFS_FLASH_ADDR 0xED000
|
||||
#else
|
||||
#define LFS_FLASH_ADDR 0x6D000
|
||||
#endif
|
||||
|
||||
#define LFS_FLASH_SIZE (4*4096) //(7*4096)
|
||||
#define LFS_BLOCK_SIZE 128
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
uint8_t ramdisk[LFS_FLASH_SIZE/LFS_BLOCK_SIZE][LFS_BLOCK_SIZE];
|
||||
|
||||
int _iflash_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
|
||||
{
|
||||
int nffs_init(void);
|
||||
(void) c;
|
||||
|
||||
memcpy(buffer, ramdisk[block] + off, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Program a region in a block. The block must have previously
|
||||
// been erased. Negative error codes are propogated to the user.
|
||||
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
||||
int _iflash_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
|
||||
{
|
||||
(void) c;
|
||||
|
||||
memcpy(ramdisk[block] + off, buffer, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Erase a block. A block must be erased before being programmed.
|
||||
// The state of an erased block is undefined. Negative error codes
|
||||
// are propogated to the user.
|
||||
// May return LFS_ERR_CORRUPT if the block should be considered bad.
|
||||
int _iflash_erase(const struct lfs_config *c, lfs_block_t block)
|
||||
{
|
||||
(void) c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Sync the state of the underlying block device. Negative error codes
|
||||
// are propogated to the user.
|
||||
int _iflash_sync(const struct lfs_config *c)
|
||||
{
|
||||
(void) c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
LittleFS InternalFS;
|
||||
|
||||
LittleFS::LittleFS (void)
|
||||
{
|
||||
_lfs_cfg = ((struct lfs_config) {
|
||||
.context = NULL,
|
||||
.read = _iflash_read,
|
||||
.prog = _iflash_prog,
|
||||
.erase = _iflash_erase,
|
||||
.sync = _iflash_sync,
|
||||
|
||||
.read_size = LFS_BLOCK_SIZE,
|
||||
.prog_size = LFS_BLOCK_SIZE,
|
||||
.block_size = LFS_BLOCK_SIZE,
|
||||
.block_count = LFS_FLASH_SIZE/LFS_BLOCK_SIZE,
|
||||
.lookahead = 128
|
||||
} );
|
||||
}
|
||||
|
||||
LittleFS::~LittleFS ()
|
||||
@@ -56,7 +119,20 @@ LittleFS::~LittleFS ()
|
||||
|
||||
bool LittleFS::begin (void)
|
||||
{
|
||||
int err = lfs_mount(&_lfs, &_lfs_cfg);
|
||||
PRINT_INT(err);
|
||||
|
||||
// reformat if we can't mount the filesystem
|
||||
// this should only happen on the first boot
|
||||
if (err) {
|
||||
err = lfs_format(&_lfs, &_lfs_cfg);
|
||||
PRINT_INT(err);
|
||||
err = lfs_mount(&_lfs, &_lfs_cfg);
|
||||
PRINT_INT(err);
|
||||
}
|
||||
PRINT_LOCATION();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BluefuritLib::File LittleFS::open (char const *filename, uint8_t mode)
|
||||
|
||||
Reference in new issue
Block a user