12 #ifndef INCLUDE_DISTORTOS_DEVICES_MEMORY_SPIEEPROM_HPP_ 13 #define INCLUDE_DISTORTOS_DEVICES_MEMORY_SPIEEPROM_HPP_ 227 const uint32_t clockFrequency = 1000000) :
228 mutex_{Mutex::Type::recursive, Mutex::Protocol::priorityInheritance},
260 int close()
override;
278 int erase(uint64_t address, uint64_t size)
override;
290 uint64_t
getSize()
const override;
307 void lock()
override;
340 int read(uint64_t address,
void* buffer,
size_t size)
override;
384 int write(uint64_t address,
const void* buffer,
size_t size)
override;
402 int eraseOrWrite(uint64_t address,
const void* buffer, uint64_t size);
418 std::pair<int, size_t>
eraseOrWritePage(uint32_t address,
const void* buffer,
size_t size);
505 #endif // INCLUDE_DISTORTOS_DEVICES_MEMORY_SPIEEPROM_HPP_
constexpr SpiEeprom(SpiMaster &spiMaster, OutputPin &slaveSelectPin, const Type type, const bool mode3={}, const uint32_t clockFrequency=1000000)
SpiEeprom's constructor.
Definition: SpiEeprom.hpp:226
128 kB (1 Mb) size, 256 bytes per page
ON Semiconductor CAT25256.
Definition: SpiEeprom.hpp:38
int writeEnable() const
Enables writes in SPI EEPROM.
Definition: SpiEeprom.cpp:312
ON Semiconductor CAT25128.
int eraseOrWrite(uint64_t address, const void *buffer, uint64_t size)
Implementation of erase() and write()
Definition: SpiEeprom.cpp:217
512 B (4 kb) size, 8 bytes per page
void lock() override
Locks SPI EEPROM for exclusive use by current thread.
Definition: SpiEeprom.cpp:137
static constexpr size_t pageSizeMask_
bit mask of field with page size encoded in device's type
Definition: SpiEeprom.hpp:47
std::pair< int, bool > isWriteInProgress()
Checks whether any write operation is currently in progress.
Definition: SpiEeprom.cpp:284
static constexpr size_t sizeWidth_
bit width of field with size encoded in device's type
Definition: SpiEeprom.hpp:53
SpiMode enum class header.
uint8_t openCount_
number of times this device was opened but not yet closed
Definition: SpiEeprom.hpp:495
void unlock() override
Unlocks SPI EEPROM which was previously locked by current thread.
Definition: SpiEeprom.cpp:198
int waitWhileWriteInProgress()
Waits while any write operation is currently in progress.
Definition: SpiEeprom.cpp:298
BlockDevice class header.
static constexpr size_t sizeShift_
bit shift of field with size encoded in device's type
Definition: SpiEeprom.hpp:50
Definition: OutputPin.hpp:29
std::pair< int, uint8_t > readStatusRegister() const
Reads value of status register of SPI EEPROM.
Definition: SpiEeprom.cpp:290
SpiMode
Definition: SpiMode.hpp:29
size_t getBlockSize() const override
Definition: SpiEeprom.cpp:127
OutputPin & slaveSelectPin_
reference to slave select pin of this SPI EEPROM
Definition: SpiEeprom.hpp:486
ON Semiconductor CAT25320.
256 B (2 kb) size, 16 bytes per page
estd::ContiguousRange< const SpiMasterTransfer > SpiMasterTransfersRange
Definition: SpiMasterTransfersRange.hpp:31
1 kB (8 kb) size, 16 bytes per page
static constexpr size_t sizeMask_
bit mask of field with size encoded in device's type
Definition: SpiEeprom.hpp:56
ON Semiconductor CAT25512.
~SpiEeprom() override
SpiEeprom's destructor.
Definition: SpiEeprom.cpp:102
SpiMaster & spiMaster_
reference to SPI master to which this SPI EEPROM is connected
Definition: SpiEeprom.hpp:489
std::pair< int, size_t > eraseOrWritePage(uint32_t address, const void *buffer, size_t size)
Erases or writes single page.
Definition: SpiEeprom.cpp:243
Mutex mutex_
mutex used to serialize access to this object
Definition: SpiEeprom.hpp:480
static constexpr size_t pageSizeWidth_
bit width of field with page size encoded in device's type
Definition: SpiEeprom.hpp:44
256 B (2 kb) size, 8 bytes per page
int synchronize() override
Synchronizes state of SPI EEPROM, ensuring all cached writes are finished.
Definition: SpiEeprom.cpp:189
Type type_
type of SPI EEPROM
Definition: SpiEeprom.hpp:498
int write(uint64_t address, const void *buffer, size_t size) override
Writes data to SPI EEPROM.
Definition: SpiEeprom.cpp:204
Top-level namespace of distortos project.
Definition: buttons.hpp:33
Mutex is the basic synchronization primitive.
Definition: Mutex.hpp:30
32 kB (256 kb) size, 64 bytes per page
256 kB (2 Mb) size, 256 bytes per page
ON Semiconductor CAT25160.
int close() override
Closes SPI EEPROM.
Definition: SpiEeprom.cpp:107
int executeTransaction(SpiMasterTransfersRange transfersRange) const
Executes series of transfers as a single atomic transaction.
Definition: SpiEeprom.cpp:273
ON Semiconductor CAT25640.
16 kB (128 kb) size, 64 bytes per page
Definition: BlockDevice.hpp:30
ON Semiconductor CAT25040.
ON Semiconductor CAT25M01.
ON Semiconductor CAT25080.
ON Semiconductor CAT25020.
mode 0 - CPOL == 0, CPHA == 0
uint32_t clockFrequency_
desired clock frequency of SPI EEPROM, Hz
Definition: SpiEeprom.hpp:483
128 B (1 kb) size, 8 bytes per page
Definition: SpiMaster.hpp:37
2 kB (16 kb) size, 16 bytes per page
uint64_t getSize() const override
Definition: SpiEeprom.cpp:132
int erase(uint64_t address, uint64_t size) override
Erases blocks on SPI EEPROM.
Definition: SpiEeprom.cpp:120
64 kB (512 kb) size, 128 bytes per page
1 kB (8 kb) size, 32 bytes per page
SpiMasterTransfersRange type alias header.
ON Semiconductor CAT25M02.
SpiMode mode_
SPI mode used by SPI EEPROM.
Definition: SpiEeprom.hpp:492
128 B (1 kb) size, 16 bytes per page
8 kB (64 kb) size, 64 bytes per page
mode 3 - CPOL == 1, CPHA == 1
8 kB (64 kb) size, 32 bytes per page
4 kB (32 kb) size, 32 bytes per page
ON Semiconductor CAT25010.
2 kB (16 kb) size, 32 bytes per page
static constexpr size_t pageSizeShift_
bit shift of field with page size encoded in device's type
Definition: SpiEeprom.hpp:41
int read(uint64_t address, void *buffer, size_t size) override
Reads data from SPI EEPROM.
Definition: SpiEeprom.cpp:161
int open() override
Opens SPI EEPROM.
Definition: SpiEeprom.cpp:143
Type
type of device - determines size and page size
Definition: SpiEeprom.hpp:61
512 B (4 kb) size, 16 bytes per page
size_t getPageSize() const
Definition: SpiEeprom.hpp:435