#include "distortos/devices/memory/SdCard.hpp"
SdCard class is a SD card.
This class supports SD version 2.0 cards only.
◆ SdCard()
constexpr distortos::devices::SdCard::SdCard |
( |
SdMmcCardLowLevel & |
sdMmcCard, |
|
|
const bool |
_4BitBusMode = true , |
|
|
const uint32_t |
maxClockFrequency = 25000000 |
|
) |
| |
|
inlineexplicit |
SdCard's constructor.
- Parameters
-
[in] | sdMmcCard | is a reference to low-level implementation of SdMmcCardLowLevel interface |
[in] | _4BitBusMode | selects whether 1-bit (false) or 4-bit (true) bus mode will be used, default - true |
[in] | maxClockFrequency | is 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.
◆ 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.
◆ deinitialize()
void distortos::devices::SdCard::deinitialize |
( |
| ) |
|
|
private |
◆ 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] | address | is the address of range that will be erased, must be a multiple of block size |
[in] | size | is the size of erased range, bytes, must be a multiple of block size |
- Returns
- 0 on success, error code otherwise:
Implements distortos::devices::BlockDevice.
◆ getBlockSize()
size_t distortos::devices::SdCard::getBlockSize |
( |
| ) |
const |
|
overridevirtual |
◆ getSize()
uint64_t distortos::devices::SdCard::getSize |
( |
| ) |
const |
|
overridevirtual |
◆ initialize()
int distortos::devices::SdCard::initialize |
( |
| ) |
|
|
private |
Initializes SD card.
- Returns
- 0 on success, error code otherwise:
◆ 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.
◆ 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.
◆ 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] | address | is the address of data that will be read, must be a multiple of block size |
[out] | buffer | is the buffer into which the data will be read, must be valid |
[in] | size | is the size of buffer, bytes, must be a multiple of block size |
- Returns
- 0 on success, error code otherwise:
Implements distortos::devices::BlockDevice.
◆ 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.
◆ 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.
◆ 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] | address | is the address of data that will be written, must be a multiple of block size |
[in] | buffer | is the buffer with data that will be written, must be valid |
[in] | size | is the size of buffer, bytes, must be a multiple of block size |
- Returns
- 0 on success, error code otherwise:
Implements distortos::devices::BlockDevice.
◆ _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 |
◆ 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 |
◆ busyDeadline_
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 |
◆ readTimeoutMs_
uint16_t distortos::devices::SdCard::readTimeoutMs_ |
|
private |
timeout of read operation, milliseconds
◆ sdCard_
◆ writeTimeoutMs_
uint16_t distortos::devices::SdCard::writeTimeoutMs_ |
|
private |
timeout of write operation, milliseconds
The documentation for this class was generated from the following files: