36#ifndef _FREERTOS_DRIVERS_COMMON_FLASHFILE_HXX_
37#define _FREERTOS_DRIVERS_COMMON_FLASHFILE_HXX_
83 int open(
File *file,
const char *path,
int flags,
int mode)
override
85 if ((flags & O_TRUNC) && ((flags & O_ACCMODE) != O_RDONLY))
107 ssize_t
write(
unsigned int index,
const void *buf,
size_t len)
override
113 if (len >
size_ - index)
118 size_t sec_addr =
flash_->next_sector_address(addr);
119 if (addr == sec_addr)
122 size_t next_sec =
flash_->next_sector_address(sec_addr + 1);
123 flash_->erase(sec_addr, next_sec - sec_addr);
126 if ((sec_addr - addr) < len)
128 len = sec_addr - addr;
130 flash_->write(addr, buf, len);
139 ssize_t
read(
unsigned int index,
void *buf,
size_t len)
override
145 if (len >
size_ - index)
150 flash_->read(addr, buf, len);
Base class for implementing block devices and other file drivers which can be seeked and addressed by...
int open(File *file, const char *path, int flags, int mode) OVERRIDE
Open a device.
static int fstat(struct _reent *reent, int fd, struct stat *stat)
Get the status information of a file or device.
const char * name
device name
FlashFile is a driver for a single file that is backed by flash.
size_t flashStart_
Offset where our file start on flash.
ssize_t write(unsigned int index, const void *buf, size_t len) override
Write to the flash.
ssize_t read(unsigned int index, void *buf, size_t len) override
Read from the flash.
int open(File *file, const char *path, int flags, int mode) override
Overrides behavior of open for O_TRUNC.
size_t size_
How many bytes our file is on flash.
int fstat(File *file, struct stat *stat) override
Implements querying the file size.
FLASH * flash_
Accessor to the flash device.
FlashFile(const char *name, FLASH *flash, size_t address, size_t size)
Constructor.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
static int stat(struct _reent *reent, const char *path, struct stat *stat)
Get the status information of a file or device.