distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::devices::SpiEeprom Class Reference

#include <SpiEeprom.hpp>

Collaboration diagram for distortos::devices::SpiEeprom:
[legend]

Public Types

enum  Type : uint8_t {
  Type::_128Bytes8BytesPerPage = 0 << capacityShift_ | 0 << pageSizeShift_, Type::_128Bytes16BytesPerPage = 0 << capacityShift_ | 1 << pageSizeShift_, Type::_256Bytes8BytesPerPage = 1 << capacityShift_ | 0 << pageSizeShift_, Type::_256Bytes16BytesPerPage = 1 << capacityShift_ | 1 << pageSizeShift_,
  Type::_512Bytes8BytesPerPage = 2 << capacityShift_ | 0 << pageSizeShift_, Type::_512Bytes16BytesPerPage = 2 << capacityShift_ | 1 << pageSizeShift_, Type::_1KBytes16BytesPerPage = 3 << capacityShift_ | 1 << pageSizeShift_, Type::_1KBytes32BytesPerPage = 3 << capacityShift_ | 2 << pageSizeShift_,
  Type::_2KBytes16BytesPerPage = 4 << capacityShift_ | 1 << pageSizeShift_, Type::_2KBytes32BytesPerPage = 4 << capacityShift_ | 2 << pageSizeShift_, Type::_4KBytes32BytesPerPage = 5 << capacityShift_ | 2 << pageSizeShift_, Type::_8KBytes32BytesPerPage = 6 << capacityShift_ | 2 << pageSizeShift_,
  Type::_8KBytes64BytesPerPage = 6 << capacityShift_ | 3 << pageSizeShift_, Type::_16KBytes64BytesPerPage = 7 << capacityShift_ | 3 << pageSizeShift_, Type::_32KBytes64BytesPerPage = 8 << capacityShift_ | 3 << pageSizeShift_, Type::_64KBytes128BytesPerPage = 9 << capacityShift_ | 4 << pageSizeShift_,
  Type::_128KBytes256BytesPerPage = 10 << capacityShift_ | 5 << pageSizeShift_, Type::_256KBytes256BytesPerPage = 11 << capacityShift_ | 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 capacity and page size More...
 

Public Member Functions

constexpr SpiEeprom (SpiMaster &spiMaster, OutputPin &slaveSelectPin, const Type type, const bool mode3={}, const uint32_t maxClockFrequency=1000000)
 SpiEeprom's constructor. More...
 
int close ()
 Closes SPI EEPROM. More...
 
size_t getCapacity () const
 
size_t getPageSize () const
 
std::pair< int, bool > isWriteInProgress ()
 Checks whether any write operation is currently in progress. More...
 
bool lock ()
 Wrapper for SpiDevice::lock() More...
 
int open ()
 Opens SPI EEPROM. More...
 
std::pair< int, size_t > read (uint32_t address, void *buffer, size_t size)
 Reads data from SPI EEPROM. More...
 
void unlock (bool previousLockState)
 Wrapper for SpiDevice::unlock() More...
 
int waitWhileWriteInProgress ()
 Waits while any write operation is currently in progress. More...
 
std::pair< int, size_t > write (uint32_t address, const void *buffer, size_t size)
 Writes data to SPI EEPROM. More...
 

Private Member Functions

std::pair< int, uint8_t > readStatusRegister ()
 Reads value of status register of SPI EEPROM. More...
 
int writeEnable ()
 Enables writes in SPI EEPROM. More...
 
std::pair< int, size_t > writePage (uint32_t address, const void *buffer, size_t size)
 Writes single page. More...
 

Private Attributes

SpiDevice spiDevice_
 internal SPI slave device 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 capacityShift_ {pageSizeWidth_}
 bit shift of field with capacity encoded in device's type More...
 
static constexpr size_t capacityWidth_ {8 - pageSizeWidth_}
 bit width of field with capacity encoded in device's type More...
 
static constexpr size_t capacityMask_ {((1 << capacityWidth_) - 1) << capacityShift_}
 bit mask of field with capacity encoded in device's type More...
 

Detailed Description

SpiEeprom class is a SPI EEPROM memory: Atmel AT25xxx, ON Semiconductor CAT25xxx, ST M95xxx, Microchip 25xxxxx or similar.

Member Enumeration Documentation

◆ Type

enum distortos::devices::SpiEeprom::Type : uint8_t
strong

type of device - determines capacity and page size

Enumerator
_128Bytes8BytesPerPage 

128B (1kb) capacity, 8 bytes per page

_128Bytes16BytesPerPage 

128B (1kb) capacity, 16 bytes per page

_256Bytes8BytesPerPage 

256B (2kb) capacity, 8 bytes per page

_256Bytes16BytesPerPage 

256B (2kb) capacity, 16 bytes per page

_512Bytes8BytesPerPage 

512B (4kb) capacity, 8 bytes per page

_512Bytes16BytesPerPage 

512B (4kb) capacity, 16 bytes per page

_1KBytes16BytesPerPage 

1kB (8kb) capacity, 16 bytes per page

_1KBytes32BytesPerPage 

1kB (8kb) capacity, 32 bytes per page

_2KBytes16BytesPerPage 

2kB (16kb) capacity, 16 bytes per page

_2KBytes32BytesPerPage 

2kB (16kb) capacity, 32 bytes per page

_4KBytes32BytesPerPage 

4kB (32kb) capacity, 32 bytes per page

_8KBytes32BytesPerPage 

8kB (64kb) capacity, 32 bytes per page

_8KBytes64BytesPerPage 

8kB (64kb) capacity, 64 bytes per page

_16KBytes64BytesPerPage 

16kB (128kb) capacity, 64 bytes per page

_32KBytes64BytesPerPage 

32kB (256kb) capacity, 64 bytes per page

_64KBytes128BytesPerPage 

64kB (512kb) capacity, 128 bytes per page

_128KBytes256BytesPerPage 

128kB (1Mb) capacity, 256 bytes per page

_256KBytes256BytesPerPage 

256kB (2Mb) capacity, 256 bytes per page

at25010 

Atmel AT25010.

at25020 

Atmel AT25020.

at25040 

Atmel AT25040.

at25080 

Atmel AT25080.

at25160 

Atmel AT25160.

at25320 

Atmel AT25320.

at25640 

Atmel AT25640.

at25128 

Atmel AT25128.

at25256 

Atmel AT25256.

at25512 

Atmel AT25512.

at25m01 

Atmel AT25M01.

at25m02 

Atmel AT25M02.

cat25010 

ON Semiconductor CAT25010.

cat25020 

ON Semiconductor CAT25020.

cat25040 

ON Semiconductor CAT25040.

cat25080 

ON Semiconductor CAT25080.

cat25160 

ON Semiconductor CAT25160.

cat25320 

ON Semiconductor CAT25320.

cat25640 

ON Semiconductor CAT25640.

cat25128 

ON Semiconductor CAT25128.

cat25256 

ON Semiconductor CAT25256.

cat25512 

ON Semiconductor CAT25512.

cat25m01 

ON Semiconductor CAT25M01.

cat25m02 

ON Semiconductor CAT25M02.

m95010 

ST M95010.

m95020 

ST M95020.

m95040 

ST M95040.

m95080 

ST M95080.

m95160 

ST M95160.

m95320 

ST M95320.

m95640 

ST M95640.

m95128 

ST M95128.

m95256 

ST M95256.

m95512 

ST M95512.

m95m01 

ST M95M01.

m95m02 

ST M95M02.

_25xx010 

Microchip 25xx010.

_25xx020 

Microchip 25xx020.

_25xx040 

Microchip 25xx040.

_25xx080 

Microchip 25xx080.

_25xx080a 

Microchip 25xx080A.

_25xx080b 

Microchip 25xx080B.

_25xx080c 

Microchip 25xx080C.

_25xx080d 

Microchip 25xx080D.

_25xx160 

Microchip 25xx160.

_25xx160a 

Microchip 25xx160A.

_25xx160b 

Microchip 25xx160B.

_25xx160c 

Microchip 25xx160C.

_25xx160d 

Microchip 25xx160D.

_25xx320 

Microchip 25xx320.

_25xx640 

Microchip 25xx640.

_25xx128 

Microchip 25xx128.

_25xx256 

Microchip 25xx256.

_25xx512 

Microchip 25xx512.

_25xx1024 

Microchip 25xx1024.

Constructor & Destructor Documentation

◆ SpiEeprom()

constexpr distortos::devices::SpiEeprom::SpiEeprom ( SpiMaster spiMaster,
OutputPin slaveSelectPin,
const Type  type,
const bool  mode3 = {},
const uint32_t  maxClockFrequency = 1000000 
)
inline

SpiEeprom's constructor.

Parameters
[in]spiMasteris a reference to SPI master to which this SPI EEPROM is connected
[in]slaveSelectPinis a reference to slave select pin of this SPI EEPROM
[in]typeis the type of SPI EEPROM
[in]mode3selects 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]maxClockFrequencyis the max clock frequency supported by SPI EEPROM, Hz, default - 1MHz
Here is the call graph for this function:

Member Function Documentation

◆ close()

int distortos::devices::SpiEeprom::close ( )

Closes SPI EEPROM.

Wrapper for SpiDevice::close().

Warning
This function must not be called from interrupt context!
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCapacity()

size_t distortos::devices::SpiEeprom::getCapacity ( ) const
inline
Returns
total capacity of the device, bytes
Here is the caller graph for this function:

◆ getPageSize()

size_t distortos::devices::SpiEeprom::getPageSize ( ) const
inline
Returns
size of single page, bytes
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isWriteInProgress()

std::pair< int, bool > distortos::devices::SpiEeprom::isWriteInProgress ( )

Checks whether any write operation is currently in progress.

Warning
This function must not be called from interrupt context!
Returns
pair with return code (0 on success, error code otherwise) and current status of device: false - device is idle, true - write operation is in progress; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lock()

bool distortos::devices::SpiEeprom::lock ( )

Wrapper for SpiDevice::lock()

Note
Locks may be nested.
Warning
This function must not be called from interrupt context!
Returns
previous state of lock: false if this SPI EEPROM was unlocked before this call, true if it was already locked by current thread
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open()

int distortos::devices::SpiEeprom::open ( )

Opens SPI EEPROM.

Wrapper for SpiDevice::open().

Warning
This function must not be called from interrupt context!
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read()

std::pair< int, size_t > distortos::devices::SpiEeprom::read ( uint32_t  address,
void *  buffer,
size_t  size 
)

Reads data from SPI EEPROM.

Warning
This function must not be called from interrupt context!
Parameters
[in]addressis the address of data that will be read
[out]bufferis the buffer to which the data will be written
[in]sizeis the size of buffer, bytes
Returns
pair with return code (0 on success, error code otherwise) and number of read bytes (valid even when error code is returned); error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readStatusRegister()

std::pair< int, uint8_t > distortos::devices::SpiEeprom::readStatusRegister ( )
private

Reads value of status register of SPI EEPROM.

Returns
pair with return code (0 on success, error code otherwise) and value of status register of SPI EEPROM; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unlock()

void distortos::devices::SpiEeprom::unlock ( bool  previousLockState)

Wrapper for SpiDevice::unlock()

Does nothing if SPI EEPROM is not locked by current thread.

Note
Locks may be nested.
Warning
This function must not be called from interrupt context!
Parameters
previousLockStateis the value returned by matching call to lock()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitWhileWriteInProgress()

int distortos::devices::SpiEeprom::waitWhileWriteInProgress ( )

Waits while any write operation is currently in progress.

Warning
This function must not be called from interrupt context!
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

std::pair< int, size_t > distortos::devices::SpiEeprom::write ( uint32_t  address,
const void *  buffer,
size_t  size 
)

Writes data to SPI EEPROM.

Warning
This function must not be called from interrupt context!
Parameters
[in]addressis the address of data that will be written
[in]bufferis the buffer with data that will be written
[in]sizeis the size of buffer, bytes
Returns
pair with return code (0 on success, error code otherwise) and number of written bytes (valid even when error code is returned); error codes:
  • EINVAL - address and/or buffer and/or size are not valid;
  • error codes returned by writePage();
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeEnable()

int distortos::devices::SpiEeprom::writeEnable ( )
private

Enables writes in SPI EEPROM.

Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writePage()

std::pair< int, size_t > distortos::devices::SpiEeprom::writePage ( uint32_t  address,
const void *  buffer,
size_t  size 
)
private

Writes single page.

Parameters
[in]addressis the address of data that will be written, must be valid!
[in]bufferis the buffer with data that will be written
[in]sizeis the size of buffer, bytes
Returns
pair with return code (0 on success, error code otherwise) and number of written bytes (valid even when error code is returned); error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ capacityMask_

constexpr size_t distortos::devices::SpiEeprom::capacityMask_ {((1 << capacityWidth_) - 1) << capacityShift_}
staticprivate

bit mask of field with capacity encoded in device's type

◆ capacityShift_

constexpr size_t distortos::devices::SpiEeprom::capacityShift_ {pageSizeWidth_}
staticprivate

bit shift of field with capacity encoded in device's type

◆ capacityWidth_

constexpr size_t distortos::devices::SpiEeprom::capacityWidth_ {8 - pageSizeWidth_}
staticprivate

bit width of field with capacity encoded in device's type

◆ pageSizeMask_

constexpr size_t distortos::devices::SpiEeprom::pageSizeMask_ {((1 << pageSizeWidth_) - 1) << pageSizeShift_}
staticprivate

bit mask of field with page size encoded in device's type

◆ pageSizeShift_

constexpr size_t distortos::devices::SpiEeprom::pageSizeShift_ {0}
staticprivate

bit shift of field with page size encoded in device's type

◆ pageSizeWidth_

constexpr size_t distortos::devices::SpiEeprom::pageSizeWidth_ {3}
staticprivate

bit width of field with page size encoded in device's type

◆ spiDevice_

SpiDevice distortos::devices::SpiEeprom::spiDevice_
private

internal SPI slave device

◆ type_

Type distortos::devices::SpiEeprom::type_
private

type of SPI EEPROM


The documentation for this class was generated from the following files: