36#ifndef _FREERTOS_DRIVERS_COMMON_SPIFLASH_HXX_
37#define _FREERTOS_DRIVERS_COMMON_SPIFLASH_HXX_
126 void init(
const char *dev_name);
133 void write(uint32_t addr,
const void *buf,
size_t len);
139 void read(uint32_t addr,
void *buf,
size_t len);
154 void erase(uint32_t addr,
size_t len);
162 void get_id(
char id_out[3]);
This class provides a mutex API.
Shared implementation for operating spiflash devices.
const SPIFlashConfig & cfg()
void write(uint32_t addr, const void *buf, size_t len)
Performs write to the device.
void init(const char *dev_name)
Opens the SPI bus.
void chip_erase()
Erases the entire device.
SPI * spi_
Direct access of the SPI device pointer.
uint32_t next_sector_address(uint32_t addr)
Aligns an address to the next possible sector start (i.e., rounds up to sector boundary).
void get_id(char id_out[3])
Fetches the identification bytes form the SPIFlash.
void read(uint32_t addr, void *buf, size_t len)
Reads data from the device.
void erase(uint32_t addr, size_t len)
Erases sector(s) of the device.
OSMutex * lock_
Lock that protects accesses to the flash chip.
SPIFlash(const SPIFlashConfig *cfg, OSMutex *lock)
Constructor.
int spiFd_
File descriptor for the opened SPI bus.
const SPIFlashConfig * cfg_
Configuration.
unsigned wait_for_write()
Waits until write is complete.
Private data for an SPI device.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Create a const structure like this to tell the spiflash driver how to talk to your spiflash device.
uint8_t statusReadCommand_
Command to use for status register read.
uint8_t chipEraseCommand_
Command to use for chip erase.
uint8_t spiMode_
SPI mode to use.
uint32_t pageSizeMask_
A page program operation might wrap around a page.
uint8_t readNeedsStuffing_
Set this to 1 if the read command needs a dummy byte after the address.
uint8_t statusWritePendingBit_
Which bit to check in the status register for write complete.
uint32_t speedHz_
Use this frequency to talk to SPI.
uint8_t writeCommand_
Command to use for writes.
uint32_t sectorSize_
How many bytes is an erase sector.
uint8_t idCommand_
Command to use for get identification bytes.
uint8_t readCommand_
Command to use for reads.
uint8_t writeEnableCommand_
Command sent out before each write/erase command.
uint8_t eraseCommand_
Command to use for sector erases.