|
Open Model Railroad Network (OpenMRN)
|
Shared implementation for operating spiflash devices. More...
#include <SPIFlash.hxx>
Public Member Functions | |
| SPIFlash (const SPIFlashConfig *cfg, OSMutex *lock) | |
| Constructor. | |
| const SPIFlashConfig & | cfg () |
| void | init (const char *dev_name) |
| Opens the SPI bus. | |
| void | write (uint32_t addr, const void *buf, size_t len) |
| Performs write to the device. | |
| void | read (uint32_t addr, void *buf, size_t len) |
| Reads data from the device. | |
| 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 | erase (uint32_t addr, size_t len) |
| Erases sector(s) of the device. | |
| void | chip_erase () |
| Erases the entire device. | |
| void | get_id (char id_out[3]) |
| Fetches the identification bytes form the SPIFlash. | |
Private Member Functions | |
| unsigned | wait_for_write () |
| Waits until write is complete. | |
Private Attributes | |
| const SPIFlashConfig * | cfg_ |
| Configuration. | |
| OSMutex * | lock_ |
| Lock that protects accesses to the flash chip. | |
| int | spiFd_ {-1} |
| File descriptor for the opened SPI bus. | |
| SPI * | spi_ |
| Direct access of the SPI device pointer. | |
Shared implementation for operating spiflash devices.
This class is intended to be used by other device drivers.
Definition at line 103 of file SPIFlash.hxx.
|
inline |
Constructor.
| cfg | static configuration for this SPI flash device. |
| lock | this lock will be taken before performing any operation on the chip. Can be null. |
This ensures that the sector size is a power of two.
Definition at line 110 of file SPIFlash.hxx.
|
inline |
Definition at line 119 of file SPIFlash.hxx.
| void SPIFlash::chip_erase | ( | ) |
Erases the entire device.
Definition at line 224 of file SPIFlash.cxx.
| void SPIFlash::erase | ( | uint32_t | addr, |
| size_t | len | ||
| ) |
Erases sector(s) of the device.
| addr | beginning of the sector to erase. Must be sector aligned. |
| len | how many bytes to erase (must be multiple of sector size). |
Definition at line 196 of file SPIFlash.cxx.
| void SPIFlash::get_id | ( | char | id_out[3] | ) |
Fetches the identification bytes form the SPIFlash.
| id_out | return parameter, will be filled with the received identification bytes. |
Definition at line 93 of file SPIFlash.cxx.
| void SPIFlash::init | ( | const char * | dev_name | ) |
Opens the SPI bus.
This is typically called in hw_postinit or main.
| dev_name | the name of the SPI device. |
Definition at line 78 of file SPIFlash.cxx.
|
inline |
Aligns an address to the next possible sector start (i.e., rounds up to sector boundary).
| addr | an address in the flash address space. |
Definition at line 146 of file SPIFlash.hxx.
| void SPIFlash::read | ( | uint32_t | addr, |
| void * | buf, | ||
| size_t | len | ||
| ) |
Reads data from the device.
| addr | where to read from |
| buf | points to where to put the data read |
| len | how many bytes to read |
Definition at line 105 of file SPIFlash.cxx.
|
private |
Waits until write is complete.
Definition at line 172 of file SPIFlash.cxx.
| void SPIFlash::write | ( | uint32_t | addr, |
| const void * | buf, | ||
| size_t | len | ||
| ) |
Performs write to the device.
Thiscall is synchronous; does not return until the write is complete.
| addr | where to write (0 = beginning of the device). |
| buf | data to write |
| len | how many bytes to write |
Definition at line 127 of file SPIFlash.cxx.
|
private |
Configuration.
Definition at line 170 of file SPIFlash.hxx.
|
private |
Lock that protects accesses to the flash chip.
Definition at line 173 of file SPIFlash.hxx.
|
private |
Direct access of the SPI device pointer.
Definition at line 179 of file SPIFlash.hxx.
|
private |
File descriptor for the opened SPI bus.
Definition at line 176 of file SPIFlash.hxx.