distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::devices::SdCard Class Reference

#include "distortos/devices/memory/SdCard.hpp"

Inheritance diagram for distortos::devices::SdCard:
[legend]
Collaboration diagram for distortos::devices::SdCard:
[legend]

Public Member Functions

constexpr SdCard (SdMmcCardLowLevel &sdMmcCard, const bool _4BitBusMode=true, const uint32_t maxClockFrequency=25000000)
 SdCard's constructor. More...
 
 ~SdCard () override
 SdCard's destructor. More...
 
int close () override
 Closes SD card. More...
 
int erase (uint64_t address, uint64_t size) override
 Erases blocks on a SD card. More...
 
size_t getBlockSize () const override
 
uint64_t getSize () const override
 
void lock () override
 Locks the device for exclusive use by current thread. More...
 
int open () override
 Opens SD card. More...
 
int read (uint64_t address, void *buffer, size_t size) override
 Reads data from SD card. More...
 
int synchronize () override
 Synchronizes state of SD card, ensuring all cached writes are finished. More...
 
void unlock () override
 Unlocks the device which was previously locked by current thread. More...
 
int write (uint64_t address, const void *buffer, size_t size) override
 Writes data to SD card. More...
 
- Public Member Functions inherited from distortos::devices::BlockDevice
virtual ~BlockDevice ()=default
 BlockDevice's destructor. More...
 
 BlockDevice (const BlockDevice &)=delete
 
BlockDeviceoperator= (const BlockDevice &)=delete
 

Static Public Attributes

static constexpr size_t blockSize {512}
 size of block, bytes More...
 

Private Member Functions

void deinitialize ()
 Deinitializes SD card. More...
 
int initialize ()
 Initializes SD card. More...
 

Private Attributes

TickClock::time_point busyDeadline_
 current deadline of waiting while card is busy More...
 
Mutex mutex_
 mutex used to serialize access to this object More...
 
SynchronousSdMmcCardLowLevel sdCard_
 synchronous wrapper for low-level implementation of SdMmcCardLowLevel interface More...
 
uint32_t auSize_
 size of AU, bytes More...
 
size_t blocksCount_
 number of blocks available on SD card More...
 
uint32_t maxClockFrequency_
 max allowed clock frequency of SD card, Hz More...
 
uint16_t eraseTimeoutMs_
 timeout of erase operation of single AU, milliseconds More...
 
uint16_t rca_
 relative card address More...
 
uint16_t readTimeoutMs_
 timeout of read operation, milliseconds More...
 
uint16_t writeTimeoutMs_
 timeout of write operation, milliseconds More...
 
bool _4BitBusMode_
 selects whether 1-bit (false) or 4-bit (true) bus mode will be used More...
 
bool blockAddressing_
 selects whether card uses byte (false) or block (true) addressing More...
 
uint8_t openCount_
 number of times this device was opened but not yet closed More...
 

Detailed Description

SdCard class is a SD card.

This class supports SD version 2.0 cards only.

Constructor & Destructor Documentation

◆ SdCard()

constexpr distortos::devices::SdCard::SdCard ( SdMmcCardLowLevel sdMmcCard,
const bool  _4BitBusMode = true,
const uint32_t  maxClockFrequency = 25000000 
)
inlineexplicit

SdCard's constructor.

Parameters
[in]sdMmcCardis a reference to low-level implementation of SdMmcCardLowLevel interface
[in]_4BitBusModeselects whether 1-bit (false) or 4-bit (true) bus mode will be used, default - true
[in]maxClockFrequencyis the max allowed clock frequency of SD card, Hz, default - 25 MHz

◆ ~SdCard()

distortos::devices::SdCard::~SdCard ( )
override

SdCard's destructor.

Warning
This function must not be called from interrupt context!
Precondition
Device is closed.

Member Function Documentation

◆ close()

int distortos::devices::SdCard::close ( )
overridevirtual

Closes SD card.

Note
Even if error code is returned, the device must not be used from the context which opened it (until it is successfully opened again).
Warning
This function must not be called from interrupt context!
Precondition
Device is opened.
Returns
0 on success, error code otherwise:

Implements distortos::devices::BlockDevice.

Here is the call graph for this function:

◆ deinitialize()

void distortos::devices::SdCard::deinitialize ( )
private

Deinitializes SD card.

Here is the caller graph for this function:

◆ erase()

int distortos::devices::SdCard::erase ( uint64_t  address,
uint64_t  size 
)
overridevirtual

Erases blocks on a SD card.

Warning
This function must not be called from interrupt context!
Precondition
Device is opened.
address and size are valid.
Selected range is within address space of device.
Parameters
[in]addressis the address of range that will be erased, must be a multiple of block size
[in]sizeis the size of erased range, bytes, must be a multiple of block size
Returns
0 on success, error code otherwise:

Implements distortos::devices::BlockDevice.

Here is the call graph for this function:

◆ getBlockSize()

size_t distortos::devices::SdCard::getBlockSize ( ) const
overridevirtual
Returns
block size, bytes

Implements distortos::devices::BlockDevice.

◆ getSize()

uint64_t distortos::devices::SdCard::getSize ( ) const
overridevirtual
Returns
size of SD card, bytes

Implements distortos::devices::BlockDevice.

Here is the caller graph for this function:

◆ initialize()

int distortos::devices::SdCard::initialize ( )
private

Initializes SD card.

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

◆ lock()

void distortos::devices::SdCard::lock ( )
overridevirtual

Locks the device 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.

Note
Locks are recursive.
Warning
This function must not be called from interrupt context!
Precondition
The number of recursive locks of device is less than 65535.
Postcondition
Device is locked.

Implements distortos::devices::BlockDevice.

Here is the call graph for this function:

◆ open()

int distortos::devices::SdCard::open ( )
overridevirtual

Opens SD card.

Warning
This function must not be called from interrupt context!
Precondition
The number of times the device is opened is less than 255.
Returns
0 on success, error code otherwise:

Implements distortos::devices::BlockDevice.

Here is the call graph for this function:

◆ read()

int distortos::devices::SdCard::read ( uint64_t  address,
void *  buffer,
size_t  size 
)
overridevirtual

Reads data from SD card.

Warning
This function must not be called from interrupt context!
Precondition
Device is opened.
address and buffer and size are valid.
Selected range is within address space of device.
Parameters
[in]addressis the address of data that will be read, must be a multiple of block size
[out]bufferis the buffer into which the data will be read, must be valid
[in]sizeis the size of buffer, bytes, must be a multiple of block size
Returns
0 on success, error code otherwise:

Implements distortos::devices::BlockDevice.

Here is the call graph for this function:

◆ synchronize()

int distortos::devices::SdCard::synchronize ( )
overridevirtual

Synchronizes state of SD card, ensuring all cached writes are finished.

Precondition
Device is opened.
Returns
0 on success, error code otherwise:

Implements distortos::devices::BlockDevice.

Here is the call graph for this function:

◆ unlock()

void distortos::devices::SdCard::unlock ( )
overridevirtual

Unlocks the device which was previously locked by current thread.

Note
Locks are recursive.
Warning
This function must not be called from interrupt context!
Precondition
This function is called by the thread that locked the device.

Implements distortos::devices::BlockDevice.

Here is the call graph for this function:

◆ write()

int distortos::devices::SdCard::write ( uint64_t  address,
const void *  buffer,
size_t  size 
)
overridevirtual

Writes data to SD card.

Warning
This function must not be called from interrupt context!
Precondition
Device is opened.
address and buffer and size are valid.
Selected range is within address space of device.
Parameters
[in]addressis the address of data that will be written, must be a multiple of block size
[in]bufferis the buffer with data that will be written, must be valid
[in]sizeis the size of buffer, bytes, must be a multiple of block size
Returns
0 on success, error code otherwise:

Implements distortos::devices::BlockDevice.

Here is the call graph for this function:

Member Data Documentation

◆ _4BitBusMode_

bool distortos::devices::SdCard::_4BitBusMode_
private

selects whether 1-bit (false) or 4-bit (true) bus mode will be used

◆ auSize_

uint32_t distortos::devices::SdCard::auSize_
private

size of AU, bytes

◆ blockAddressing_

bool distortos::devices::SdCard::blockAddressing_
private

selects whether card uses byte (false) or block (true) addressing

◆ blocksCount_

size_t distortos::devices::SdCard::blocksCount_
private

number of blocks available on SD card

◆ blockSize

constexpr size_t distortos::devices::SdCard::blockSize {512}
static

size of block, bytes

◆ busyDeadline_

TickClock::time_point distortos::devices::SdCard::busyDeadline_
private

current deadline of waiting while card is busy

◆ eraseTimeoutMs_

uint16_t distortos::devices::SdCard::eraseTimeoutMs_
private

timeout of erase operation of single AU, milliseconds

◆ maxClockFrequency_

uint32_t distortos::devices::SdCard::maxClockFrequency_
private

max allowed clock frequency of SD card, Hz

◆ mutex_

Mutex distortos::devices::SdCard::mutex_
private

mutex used to serialize access to this object

◆ openCount_

uint8_t distortos::devices::SdCard::openCount_
private

number of times this device was opened but not yet closed

◆ rca_

uint16_t distortos::devices::SdCard::rca_
private

relative card address

◆ readTimeoutMs_

uint16_t distortos::devices::SdCard::readTimeoutMs_
private

timeout of read operation, milliseconds

◆ sdCard_

SynchronousSdMmcCardLowLevel distortos::devices::SdCard::sdCard_
private

synchronous wrapper for low-level implementation of SdMmcCardLowLevel interface

◆ writeTimeoutMs_

uint16_t distortos::devices::SdCard::writeTimeoutMs_
private

timeout of write operation, milliseconds


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