distortos
v0.7.0
object-oriented C++ RTOS for microcontrollers
|
#include "distortos/devices/memory/SpiEeprom.hpp"
Public Types | |
enum | Type : uint8_t { Type::_128Bytes8BytesPerPage = 0 << sizeShift_ | 0 << pageSizeShift_, Type::_128Bytes16BytesPerPage = 0 << sizeShift_ | 1 << pageSizeShift_, Type::_256Bytes8BytesPerPage = 1 << sizeShift_ | 0 << pageSizeShift_, Type::_256Bytes16BytesPerPage = 1 << sizeShift_ | 1 << pageSizeShift_, Type::_512Bytes8BytesPerPage = 2 << sizeShift_ | 0 << pageSizeShift_, Type::_512Bytes16BytesPerPage = 2 << sizeShift_ | 1 << pageSizeShift_, Type::_1KBytes16BytesPerPage = 3 << sizeShift_ | 1 << pageSizeShift_, Type::_1KBytes32BytesPerPage = 3 << sizeShift_ | 2 << pageSizeShift_, Type::_2KBytes16BytesPerPage = 4 << sizeShift_ | 1 << pageSizeShift_, Type::_2KBytes32BytesPerPage = 4 << sizeShift_ | 2 << pageSizeShift_, Type::_4KBytes32BytesPerPage = 5 << sizeShift_ | 2 << pageSizeShift_, Type::_8KBytes32BytesPerPage = 6 << sizeShift_ | 2 << pageSizeShift_, Type::_8KBytes64BytesPerPage = 6 << sizeShift_ | 3 << pageSizeShift_, Type::_16KBytes64BytesPerPage = 7 << sizeShift_ | 3 << pageSizeShift_, Type::_32KBytes64BytesPerPage = 8 << sizeShift_ | 3 << pageSizeShift_, Type::_64KBytes128BytesPerPage = 9 << sizeShift_ | 4 << pageSizeShift_, Type::_128KBytes256BytesPerPage = 10 << sizeShift_ | 5 << pageSizeShift_, Type::_256KBytes256BytesPerPage = 11 << sizeShift_ | 5 << pageSizeShift_, Type::at25010 = _128Bytes8BytesPerPage, Type::at25020 = _256Bytes8BytesPerPage, Type::at25040 = _512Bytes8BytesPerPage, Type::at25080 = _1KBytes32BytesPerPage, Type::at25160 = _2KBytes32BytesPerPage, Type::at25320 = _4KBytes32BytesPerPage, Type::at25640 = _8KBytes32BytesPerPage, Type::at25128 = _16KBytes64BytesPerPage, Type::at25256 = _32KBytes64BytesPerPage, Type::at25512 = _64KBytes128BytesPerPage, Type::at25m01 = _128KBytes256BytesPerPage, Type::at25m02 = _256KBytes256BytesPerPage, Type::cat25010 = _128Bytes16BytesPerPage, Type::cat25020 = _256Bytes16BytesPerPage, Type::cat25040 = _512Bytes16BytesPerPage, Type::cat25080 = _1KBytes32BytesPerPage, Type::cat25160 = _2KBytes32BytesPerPage, Type::cat25320 = _4KBytes32BytesPerPage, Type::cat25640 = _8KBytes64BytesPerPage, Type::cat25128 = _16KBytes64BytesPerPage, Type::cat25256 = _32KBytes64BytesPerPage, Type::cat25512 = _64KBytes128BytesPerPage, Type::cat25m01 = _128KBytes256BytesPerPage, Type::cat25m02 = _256KBytes256BytesPerPage, Type::m95010 = _128Bytes16BytesPerPage, Type::m95020 = _256Bytes16BytesPerPage, Type::m95040 = _512Bytes16BytesPerPage, Type::m95080 = _1KBytes32BytesPerPage, Type::m95160 = _2KBytes32BytesPerPage, Type::m95320 = _4KBytes32BytesPerPage, Type::m95640 = _8KBytes32BytesPerPage, Type::m95128 = _16KBytes64BytesPerPage, Type::m95256 = _32KBytes64BytesPerPage, Type::m95512 = _64KBytes128BytesPerPage, Type::m95m01 = _128KBytes256BytesPerPage, Type::m95m02 = _256KBytes256BytesPerPage, Type::_25xx010 = _128Bytes16BytesPerPage, Type::_25xx020 = _256Bytes16BytesPerPage, Type::_25xx040 = _512Bytes16BytesPerPage, Type::_25xx080 = _1KBytes16BytesPerPage, Type::_25xx080a = _25xx080, Type::_25xx080b = _1KBytes32BytesPerPage, Type::_25xx080c = _25xx080, Type::_25xx080d = _25xx080b, Type::_25xx160 = _2KBytes16BytesPerPage, Type::_25xx160a = _25xx160, Type::_25xx160b = _2KBytes32BytesPerPage, Type::_25xx160c = _25xx160, Type::_25xx160d = _25xx160b, Type::_25xx320 = _4KBytes32BytesPerPage, Type::_25xx640 = _8KBytes32BytesPerPage, Type::_25xx128 = _16KBytes64BytesPerPage, Type::_25xx256 = _32KBytes64BytesPerPage, Type::_25xx512 = _64KBytes128BytesPerPage, Type::_25xx1024 = _128KBytes256BytesPerPage } |
type of device - determines size and page size More... | |
Public Member Functions | |
constexpr | SpiEeprom (SpiMaster &spiMaster, OutputPin &slaveSelectPin, const Type type, const bool mode3={}, const uint32_t clockFrequency=1000000) |
SpiEeprom's constructor. More... | |
~SpiEeprom () override | |
SpiEeprom's destructor. More... | |
int | close () override |
Closes SPI EEPROM. More... | |
int | erase (uint64_t address, uint64_t size) override |
Erases blocks on SPI EEPROM. More... | |
size_t | getBlockSize () const override |
uint64_t | getSize () const override |
void | lock () override |
Locks SPI EEPROM for exclusive use by current thread. More... | |
int | open () override |
Opens SPI EEPROM. More... | |
int | read (uint64_t address, void *buffer, size_t size) override |
Reads data from SPI EEPROM. More... | |
int | synchronize () override |
Synchronizes state of SPI EEPROM, ensuring all cached writes are finished. More... | |
void | unlock () override |
Unlocks SPI EEPROM which was previously locked by current thread. More... | |
int | write (uint64_t address, const void *buffer, size_t size) override |
Writes data to SPI EEPROM. More... | |
![]() | |
virtual | ~BlockDevice ()=default |
BlockDevice's destructor. More... | |
BlockDevice (const BlockDevice &)=delete | |
BlockDevice & | operator= (const BlockDevice &)=delete |
Private Member Functions | |
int | eraseOrWrite (uint64_t address, const void *buffer, uint64_t size) |
Implementation of erase() and write() More... | |
std::pair< int, size_t > | eraseOrWritePage (uint32_t address, const void *buffer, size_t size) |
Erases or writes single page. More... | |
int | executeTransaction (SpiMasterTransfersRange transfersRange) const |
Executes series of transfers as a single atomic transaction. More... | |
size_t | getPageSize () const |
std::pair< int, bool > | isWriteInProgress () |
Checks whether any write operation is currently in progress. More... | |
std::pair< int, uint8_t > | readStatusRegister () const |
Reads value of status register of SPI EEPROM. More... | |
int | waitWhileWriteInProgress () |
Waits while any write operation is currently in progress. More... | |
int | writeEnable () const |
Enables writes in SPI EEPROM. More... | |
Private Attributes | |
Mutex | mutex_ |
mutex used to serialize access to this object More... | |
uint32_t | clockFrequency_ |
desired clock frequency of SPI EEPROM, Hz More... | |
OutputPin & | slaveSelectPin_ |
reference to slave select pin of this SPI EEPROM More... | |
SpiMaster & | spiMaster_ |
reference to SPI master to which this SPI EEPROM is connected More... | |
SpiMode | mode_ |
SPI mode used by SPI EEPROM. More... | |
uint8_t | openCount_ |
number of times this device was opened but not yet closed More... | |
Type | type_ |
type of SPI EEPROM More... | |
Static Private Attributes | |
static constexpr size_t | pageSizeShift_ {0} |
bit shift of field with page size encoded in device's type More... | |
static constexpr size_t | pageSizeWidth_ {3} |
bit width of field with page size encoded in device's type More... | |
static constexpr size_t | pageSizeMask_ {((1 << pageSizeWidth_) - 1) << pageSizeShift_} |
bit mask of field with page size encoded in device's type More... | |
static constexpr size_t | sizeShift_ {pageSizeWidth_} |
bit shift of field with size encoded in device's type More... | |
static constexpr size_t | sizeWidth_ {8 - pageSizeWidth_} |
bit width of field with size encoded in device's type More... | |
static constexpr size_t | sizeMask_ {((1 << sizeWidth_) - 1) << sizeShift_} |
bit mask of field with size encoded in device's type More... | |
SpiEeprom class is a SPI EEPROM memory: Atmel AT25xxx, ON Semiconductor CAT25xxx, ST M95xxx, Microchip 25xxxxx or similar.
|
strong |
type of device - determines size and page size
|
inline |
SpiEeprom's constructor.
[in] | spiMaster | is a reference to SPI master to which this SPI EEPROM is connected |
[in] | slaveSelectPin | is a reference to slave select pin of this SPI EEPROM |
[in] | type | is the type of SPI EEPROM |
[in] | mode3 | selects whether SPI mode 0 - CPOL == 0, CPHA == 0 - (false) or SPI mode 3 - CPOL == 1, CPHA == 1 - (true) will be used, default - SPI mode 0 (false) |
[in] | clockFrequency | is the desired clock frequency of SPI EEPROM, Hz, default - 1 MHz |
|
override |
SpiEeprom's destructor.
|
overridevirtual |
Closes SPI EEPROM.
Implements distortos::devices::BlockDevice.
|
overridevirtual |
Erases blocks on SPI EEPROM.
[in] | address | is the address of range that will be erased |
[in] | size | is the size of erased range, bytes |
Implements distortos::devices::BlockDevice.
|
private |
Implementation of erase() and write()
[in] | address | is the address of data that will be erased or written |
[in] | buffer | is the buffer with data that will be written, nullptr to erase |
[in] | size | is the size of erase (buffer == nullptr ) or size of buffer (buffer != nullptr ), bytes |
|
private |
Erases or writes single page.
[in] | address | is the address of data that will be erased or written, must be valid! |
[in] | buffer | is the buffer with data that will be written, nullptr to erase |
[in] | size | is the size of erase (buffer == nullptr ) or size of buffer (buffer != nullptr ), bytes |
|
private |
Executes series of transfers as a single atomic transaction.
[in] | transfersRange | is the range of transfers that will be executed |
|
overridevirtual |
Implements distortos::devices::BlockDevice.
|
inlineprivate |
|
overridevirtual |
Implements distortos::devices::BlockDevice.
|
private |
Checks whether any write operation is currently in progress.
|
overridevirtual |
Locks SPI EEPROM for exclusive use by current thread.
When the object is locked, any call to any member function from other thread will be blocked until the object is unlocked. Locking is optional, but may be useful when more than one transaction must be done atomically.
Implements distortos::devices::BlockDevice.
|
overridevirtual |
Opens SPI EEPROM.
Implements distortos::devices::BlockDevice.
|
overridevirtual |
Reads data from SPI EEPROM.
[in] | address | is the address of data that will be read |
[out] | buffer | is the buffer into which the data will be read, must be valid |
[in] | size | is the size of buffer, bytes |
Implements distortos::devices::BlockDevice.
|
private |
Reads value of status register of SPI EEPROM.
|
overridevirtual |
Synchronizes state of SPI EEPROM, ensuring all cached writes are finished.
Implements distortos::devices::BlockDevice.
|
overridevirtual |
Unlocks SPI EEPROM which was previously locked by current thread.
Implements distortos::devices::BlockDevice.
|
private |
Waits while any write operation is currently in progress.
|
overridevirtual |
Writes data to SPI EEPROM.
[in] | address | is the address of data that will be written |
[in] | buffer | is the buffer with data that will be written, must be valid |
[in] | size | is the size of buffer, bytes |
Implements distortos::devices::BlockDevice.
|
private |
Enables writes in SPI EEPROM.
|
private |
desired clock frequency of SPI EEPROM, Hz
|
private |
SPI mode used by SPI EEPROM.
|
private |
mutex used to serialize access to this object
|
private |
number of times this device was opened but not yet closed
|
staticprivate |
bit mask of field with page size encoded in device's type
|
staticprivate |
bit shift of field with page size encoded in device's type
|
staticprivate |
bit width of field with page size encoded in device's type
|
staticprivate |
bit mask of field with size encoded in device's type
|
staticprivate |
bit shift of field with size encoded in device's type
|
staticprivate |
bit width of field with size encoded in device's type
|
private |
reference to slave select pin of this SPI EEPROM
|
private |
reference to SPI master to which this SPI EEPROM is connected
|
private |
type of SPI EEPROM