Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TiSPIFFSImpl.hxx
1
34// #define LOGLEVEL INFO
35
36#include "utils/logging.h"
37
38#include "TiSPIFFS.hxx"
40#include "spiffs.h"
41
42
43
44//
45// TiSPIFFS::flash_read()
46//
47template<unsigned ERASE_PAGE_SIZE>
48int32_t TiSPIFFS<ERASE_PAGE_SIZE>::flash_read(uint32_t addr, uint32_t size, uint8_t *dst)
49{
50 HASSERT(addr >= fs_->cfg.phys_addr &&
51 (addr + size) <= (fs_->cfg.phys_addr + fs_->cfg.phys_size));
52
53 TiFlash<ERASE_PAGE_SIZE>::read(addr, dst, size);
54
55 return 0;
56}
57
58//
59// TiSPIFFS::flash_write()
60//
61template<unsigned ERASE_PAGE_SIZE>
62int32_t TiSPIFFS<ERASE_PAGE_SIZE>::flash_write(uint32_t addr, uint32_t size, uint8_t *src)
63{
64 LOG(INFO, "Write %x sz %d", (unsigned)addr, (unsigned)size);
65
66 TiFlash<ERASE_PAGE_SIZE>::write(addr, src, size);
67 return 0;
68}
69
70//
71// TiSPIFFS::flash_erase()
72//
73template<unsigned ERASE_PAGE_SIZE>
74int32_t TiSPIFFS<ERASE_PAGE_SIZE>::flash_erase(uint32_t addr, uint32_t size)
75{
76 LOG(INFO, "Erasing %x sz %d", (unsigned)addr, (unsigned)size);
77 HASSERT(addr >= fs_->cfg.phys_addr &&
78 (addr + size) <= (fs_->cfg.phys_addr + fs_->cfg.phys_size));
79 HASSERT((size % ERASE_PAGE_SIZE) == 0);
80
82
83 LOG(INFO, "Erasing %x done", (unsigned)addr);
84 return 0;
85}
86
static void read(uint32_t addr, void *buf, size_t len)
Reads data from the device.
Definition TiFlash.hxx:231
static void write(uint32_t addr, const void *buf, uint32_t len)
Performs write to the device.
Definition TiFlash.hxx:152
static void erase(uint32_t addr, size_t len)
Erases sector(s) of the device.
Definition TiFlash.hxx:249
int32_t flash_read(uint32_t addr, uint32_t size, uint8_t *dst) override
SPIFFS callback to read flash, in context.
int32_t flash_erase(uint32_t addr, uint32_t size) override
SPIFFS callback to erase flash, in context.
int32_t flash_write(uint32_t addr, uint32_t size, uint8_t *src) override
SPIFFS callback to write flash, in context.
#define LOG(level, message...)
Conditionally write a message to the logging output.
Definition logging.h:99
static const int INFO
Loglevel that is printed by default, reporting some status information.
Definition logging.h:57
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138