distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::devices::anonymous_namespace{SdCardSpiBased.cpp} Namespace Reference

Classes

struct  Csd
 CSD. More...
 
struct  CsdV1
 fields unique to CSD version 1.0 More...
 
struct  CsdV2
 fields unique to CSD version 2.0 More...
 
struct  R2Response
 R2 response. More...
 
struct  R3Response
 R3 response. More...
 
struct  R7Response
 R7 response. More...
 
struct  SdStatus
 SD Status. More...
 
class  SelectGuard
 select guard for SD card connected via SPI More...
 

Typedefs

using Uint8Range = estd::ContiguousRange< uint8_t >
 range of uint8_t elements More...
 
using ConstUint8Range = estd::ContiguousRange< const uint8_t >
 range of const uint8_t elements More...
 

Functions

uint32_t extractBits (const ConstUint8Range range, const size_t index, const size_t size)
 Extracts up to 32 bits from data range. More...
 
Csd decodeCsd (const std::array< uint8_t, 16 > &buffer)
 Decodes raw data into CSD. More...
 
SdStatus decodeSdStatus (const std::array< uint8_t, 64 > &buffer)
 Decodes raw data into SD Status. More...
 
template<typename Functor >
std::pair< int, uint8_t > waitWhile (const SpiMasterHandle &spiMasterHandle, const distortos::TickClock::duration duration, Functor functor)
 Waits while byte received via SPI satisfies predicate. More...
 
int waitWhileBusy (const SpiMasterHandle &spiMasterHandle, const distortos::TickClock::duration duration)
 Waits while SD card connected via SPI is busy. More...
 
int readDataBlock (const SpiMasterHandle &spiMasterHandle, void *const buffer, const size_t size, const distortos::TickClock::duration duration)
 Reads data block from SD card connected via SPI. More...
 
int writeDataBlock (const SpiMasterHandle &spiMasterHandle, const uint8_t token, const void *const buffer, const size_t size, const distortos::TickClock::duration duration)
 Writes data block to SD card connected via SPI. More...
 
int readResponse (const SpiMasterHandle &spiMasterHandle, const Uint8Range buffer)
 Reads response from SD card connected via SPI. More...
 
std::pair< int, uint8_t > readR1 (const SpiMasterHandle &spiMasterHandle)
 Reads R1 response from SD card connected via SPI. More...
 
std::pair< int, R2ResponsereadR2 (const SpiMasterHandle &spiMasterHandle)
 Reads R2 response from SD card connected via SPI. More...
 
std::pair< int, R3ResponsereadR3 (const SpiMasterHandle &spiMasterHandle)
 Reads R3 response from SD card connected via SPI. More...
 
std::pair< int, R7ResponsereadR7 (const SpiMasterHandle &spiMasterHandle)
 Reads R7 response from SD card connected via SPI. More...
 
int writeCmd (const SpiMasterHandle &spiMasterHandle, const uint8_t command, const uint32_t argument={}, const uint8_t crc7={}, const bool stuffByte={})
 Writes regular (CMD) command to SD card connected via SPI. More...
 
std::pair< int, uint8_t > writeCmdReadR1 (const SpiMasterHandle &spiMasterHandle, const uint8_t command, const uint32_t argument={}, const uint8_t crc7={}, const bool stuffByte={})
 Writes regular (CMD) command and reads R1 response to/from SD card connected via SPI. More...
 
std::pair< int, R3ResponsewriteCmdReadR3 (const SpiMasterHandle &spiMasterHandle, const uint8_t command, const uint32_t argument={}, const uint8_t crc7={}, const bool stuffByte={})
 Writes regular (CMD) command and reads R3 response to/from SD card connected via SPI. More...
 
std::pair< int, R7ResponsewriteCmdReadR7 (const SpiMasterHandle &spiMasterHandle, const uint8_t command, const uint32_t argument={}, const uint8_t crc7={}, const bool stuffByte={})
 Writes regular (CMD) command and reads R7 response to/from SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd0 (const SpiMasterHandle &spiMasterHandle)
 Executes CMD0 command on SD card connected via SPI. More...
 
std::tuple< int, uint8_t, bool > executeCmd8 (const SpiMasterHandle &spiMasterHandle)
 Executes CMD8 command on SD card connected via SPI. More...
 
std::tuple< int, uint8_t, std::array< uint8_t, 16 > > executeCmd9 (const SpiMasterHandle &spiMasterHandle)
 Executes CMD9 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd12 (const SpiMasterHandle &spiMasterHandle, const distortos::TickClock::duration duration)
 Executes CMD12 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd16 (const SpiMasterHandle &spiMasterHandle, const uint32_t blockLength)
 Executes CMD16 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd17 (const SpiMasterHandle &spiMasterHandle, const uint32_t address)
 Executes CMD17 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd18 (const SpiMasterHandle &spiMasterHandle, const uint32_t address)
 Executes CMD18 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd24 (const SpiMasterHandle &spiMasterHandle, const uint32_t address)
 Executes CMD24 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd25 (const SpiMasterHandle &spiMasterHandle, const uint32_t address)
 Executes CMD25 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd32 (const SpiMasterHandle &spiMasterHandle, const uint32_t address)
 Executes CMD32 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd33 (const SpiMasterHandle &spiMasterHandle, const uint32_t address)
 Executes CMD33 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd38 (const SpiMasterHandle &spiMasterHandle, const distortos::TickClock::duration duration)
 Executes CMD38 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeCmd55 (const SpiMasterHandle &spiMasterHandle)
 Executes CMD55 command on SD card connected via SPI. More...
 
std::pair< int, R3ResponseexecuteCmd58 (const SpiMasterHandle &spiMasterHandle)
 Executes CMD58 command on SD card connected via SPI. More...
 
int writeAcmd (const SpiMasterHandle &spiMasterHandle, const uint8_t command, const uint32_t argument={}, const uint8_t crc7={}, const bool stuffByte={})
 Writes application (ACMD) command to SD card connected via SPI. More...
 
std::pair< int, uint8_t > writeAcmdReadR1 (const SpiMasterHandle &spiMasterHandle, const uint8_t command, const uint32_t argument={}, const uint8_t crc7={}, const bool stuffByte={})
 Writes application (ACMD) command and reads R1 response to/from SD card connected via SPI. More...
 
std::pair< int, R2ResponsewriteAcmdReadR2 (const SpiMasterHandle &spiMasterHandle, const uint8_t command, const uint32_t argument={}, const uint8_t crc7={}, const bool stuffByte={})
 Writes application (ACMD) command and reads R2 response to/from SD card connected via SPI. More...
 
std::tuple< int, R2Response, std::array< uint8_t, 64 > > executeAcmd13 (const SpiMasterHandle &spiMasterHandle, const distortos::TickClock::duration duration)
 Executes ACMD13 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeAcmd23 (const SpiMasterHandle &spiMasterHandle, const uint32_t blocksCount)
 Executes ACMD23 command on SD card connected via SPI. More...
 
std::pair< int, uint8_t > executeAcmd41 (const SpiMasterHandle &spiMasterHandle, const bool hcs)
 Executes ACMD41 command on SD card connected via SPI. More...
 

Variables

constexpr uint8_t dataResponseTokenMask {0b00011111}
 mask for data response token More...
 
constexpr uint8_t dataResponseTokenDataAccepted {0b010 << 1 | 1}
 data response token - data accepted More...
 
constexpr uint8_t startBlockToken {0b11111110}
 control token - start block More...
 
constexpr uint8_t startBlockWriteToken {0b11111100}
 control token - start block for CMD25 More...
 
constexpr uint8_t stopTranToken {0b11111101}
 control token - stop tran More...
 
constexpr uint8_t r1InIdleStateMask {1 << 0}
 R1 - in idle state. More...
 
constexpr uint32_t ocrCcsMask {1 << 30}
 OCR - CCS bit mask. More...
 
constexpr uint8_t acmd41HcsPosition {30}
 ACMD41 argument - HCS bit position. More...
 

Typedef Documentation

◆ ConstUint8Range

using distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::ConstUint8Range = typedef estd::ContiguousRange<const uint8_t>

range of const uint8_t elements

◆ Uint8Range

using distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::Uint8Range = typedef estd::ContiguousRange<uint8_t>

range of uint8_t elements

Function Documentation

◆ decodeCsd()

Csd distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::decodeCsd ( const std::array< uint8_t, 16 > &  buffer)

Decodes raw data into CSD.

Parameters
[in]bufferis a reference to array with raw data containing CSD
Returns
decoded CSD
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeSdStatus()

SdStatus distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::decodeSdStatus ( const std::array< uint8_t, 64 > &  buffer)

Decodes raw data into SD Status.

Parameters
[in]bufferis a reference to array with raw data containing SD Status
Returns
decoded SD Status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeAcmd13()

std::tuple<int, R2Response, std::array<uint8_t, 64> > distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeAcmd13 ( const SpiMasterHandle spiMasterHandle,
const distortos::TickClock::duration  duration 
)

Executes ACMD13 command on SD card connected via SPI.

This is SD_STATUS command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]durationis the duration of wait before giving up
Returns
tuple with return code (0 on success, error code otherwise), R2 response and array with raw data containing SD Status register; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeAcmd23()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeAcmd23 ( const SpiMasterHandle spiMasterHandle,
const uint32_t  blocksCount 
)

Executes ACMD23 command on SD card connected via SPI.

This is SET_WR_BLK_ERASE_COUNT command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]blocksCountis the number of blocks to pre-erase with next multi-block write command
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeAcmd41()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeAcmd41 ( const SpiMasterHandle spiMasterHandle,
const bool  hcs 
)

Executes ACMD41 command on SD card connected via SPI.

This is SD_SEND_OP_COND command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]hcsis the value of HCS (Host Capacity Support) bit sent to the SD card, which selects whether host supports SDHC or SDXC cards
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd0()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd0 ( const SpiMasterHandle spiMasterHandle)

Executes CMD0 command on SD card connected via SPI.

This is GO_IDLE_STATE command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd12()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd12 ( const SpiMasterHandle spiMasterHandle,
const distortos::TickClock::duration  duration 
)

Executes CMD12 command on SD card connected via SPI.

This is STOP_TRANSMISSION command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]durationis the duration of wait before giving up
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd16()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd16 ( const SpiMasterHandle spiMasterHandle,
const uint32_t  blockLength 
)

Executes CMD16 command on SD card connected via SPI.

This is SET_BLOCKLEN command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]blockLengthis the length of read/write block, bytes
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd17()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd17 ( const SpiMasterHandle spiMasterHandle,
const uint32_t  address 
)

Executes CMD17 command on SD card connected via SPI.

This is READ_SINGLE_BLOCK command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]addressis the address from which data will be read, bytes or blocks
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd18()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd18 ( const SpiMasterHandle spiMasterHandle,
const uint32_t  address 
)

Executes CMD18 command on SD card connected via SPI.

This is READ_MULTIPLE_BLOCK command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]addressis the address from which data will be read, bytes or blocks
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd24()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd24 ( const SpiMasterHandle spiMasterHandle,
const uint32_t  address 
)

Executes CMD24 command on SD card connected via SPI.

This is WRITE_BLOCK command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]addressis the address to which data will be written, bytes or blocks
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd25()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd25 ( const SpiMasterHandle spiMasterHandle,
const uint32_t  address 
)

Executes CMD25 command on SD card connected via SPI.

This is WRITE_MULTIPLE_BLOCK command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]addressis the address to which data will be written, bytes or blocks
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd32()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd32 ( const SpiMasterHandle spiMasterHandle,
const uint32_t  address 
)

Executes CMD32 command on SD card connected via SPI.

This is ERASE_WR_BLK_START_ADDR command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]addressis the address of first block marked for erase, bytes or blocks
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd33()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd33 ( const SpiMasterHandle spiMasterHandle,
const uint32_t  address 
)

Executes CMD33 command on SD card connected via SPI.

This is ERASE_WR_BLK_END_ADDR command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]addressis the address of last block marked for erase, bytes or blocks
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd38()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd38 ( const SpiMasterHandle spiMasterHandle,
const distortos::TickClock::duration  duration 
)

Executes CMD38 command on SD card connected via SPI.

This is ERASE command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]durationis the duration of wait before giving up
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd55()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd55 ( const SpiMasterHandle spiMasterHandle)

Executes CMD55 command on SD card connected via SPI.

This is APP_CMD command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:

◆ executeCmd58()

std::pair<int, R3Response> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd58 ( const SpiMasterHandle spiMasterHandle)

Executes CMD58 command on SD card connected via SPI.

This is READ_OCR command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
pair with return code (0 on success, error code otherwise) and R3 response; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd8()

std::tuple<int, uint8_t, bool> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd8 ( const SpiMasterHandle spiMasterHandle)

Executes CMD8 command on SD card connected via SPI.

This is SEND_IF_COND command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
tuple with return code (0 on success, error code otherwise), R1 response and a boolean value which tells whether pattern was matched; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeCmd9()

std::tuple<int, uint8_t, std::array<uint8_t, 16> > distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::executeCmd9 ( const SpiMasterHandle spiMasterHandle)

Executes CMD9 command on SD card connected via SPI.

This is SEND_CSD command.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
tuple with return code (0 on success, error code otherwise), R1 response and array with raw data containing CSD; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extractBits()

uint32_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::extractBits ( const ConstUint8Range  range,
const size_t  index,
const size_t  size 
)

Extracts up to 32 bits from data range.

Bits are numbered just like in the CSD.

Parameters
[in]rangeis the data range from which bits will be extracted
[in]indexis the index of starting bit, 0 - LSB of last element in data range
[in]sizeis the number of bits to extract
Returns
bits extracted from data range
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readDataBlock()

int distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::readDataBlock ( const SpiMasterHandle spiMasterHandle,
void *const  buffer,
const size_t  size,
const distortos::TickClock::duration  duration 
)

Reads data block from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[out]bufferis a pointer to buffer for received data
[in]sizeis the size of data block that should be read, bytes
[in]durationis the duration of wait before giving up
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ readR1()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::readR1 ( const SpiMasterHandle spiMasterHandle)

Reads R1 response from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the call graph for this function:

◆ readR2()

std::pair<int, R2Response> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::readR2 ( const SpiMasterHandle spiMasterHandle)

Reads R2 response from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
pair with return code (0 on success, error code otherwise) and R2 response; error codes:
Here is the call graph for this function:

◆ readR3()

std::pair<int, R3Response> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::readR3 ( const SpiMasterHandle spiMasterHandle)

Reads R3 response from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
pair with return code (0 on success, error code otherwise) and R3 response; error codes:
Here is the call graph for this function:

◆ readR7()

std::pair<int, R7Response> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::readR7 ( const SpiMasterHandle spiMasterHandle)

Reads R7 response from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
Returns
pair with return code (0 on success, error code otherwise) and R7 response; error codes:
Here is the call graph for this function:

◆ readResponse()

int distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::readResponse ( const SpiMasterHandle spiMasterHandle,
const Uint8Range  buffer 
)

Reads response from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]bufferis a buffer for received response
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitWhile()

template<typename Functor >
std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::waitWhile ( const SpiMasterHandle spiMasterHandle,
const distortos::TickClock::duration  duration,
Functor  functor 
)

Waits while byte received via SPI satisfies predicate.

Template Parameters
Functoris the type of functor, should be callable as bool(const uint8_t&)
Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]durationis the duration of wait before giving up
[in]functoris the functor used to check predicate
Returns
pair with return code (0 on success, error code otherwise) and last byte that was received; error codes:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitWhileBusy()

int distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::waitWhileBusy ( const SpiMasterHandle spiMasterHandle,
const distortos::TickClock::duration  duration 
)

Waits while SD card connected via SPI is busy.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]durationis the duration of wait before giving up
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeAcmd()

int distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::writeAcmd ( const SpiMasterHandle spiMasterHandle,
const uint8_t  command,
const uint32_t  argument = {},
const uint8_t  crc7 = {},
const bool  stuffByte = {} 
)

Writes application (ACMD) command to SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]commandis the command that will be written
[in]argumentis the argument for command, default - 0
[in]crc7is the value of CRC-7 appended to the transferred block, default - 0
[in]stuffByteselects whether stuff byte will be appended to the transferred block, default - false
Returns
0 on success, error code otherwise:
  • EIO - unexpected R1 response for CMD55 was read;
  • error codes returned by executeCmd55();
  • error codes returned by writeCmd();

◆ writeAcmdReadR1()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::writeAcmdReadR1 ( const SpiMasterHandle spiMasterHandle,
const uint8_t  command,
const uint32_t  argument = {},
const uint8_t  crc7 = {},
const bool  stuffByte = {} 
)

Writes application (ACMD) command and reads R1 response to/from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]commandis the command that will be written
[in]argumentis the argument for command, default - 0
[in]crc7is the value of CRC-7 appended to the transferred block, default - 0
[in]stuffByteselects whether stuff byte will be appended to the transferred block, default - false
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the caller graph for this function:

◆ writeAcmdReadR2()

std::pair<int, R2Response> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::writeAcmdReadR2 ( const SpiMasterHandle spiMasterHandle,
const uint8_t  command,
const uint32_t  argument = {},
const uint8_t  crc7 = {},
const bool  stuffByte = {} 
)

Writes application (ACMD) command and reads R2 response to/from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]commandis the command that will be written
[in]argumentis the argument for command, default - 0
[in]crc7is the value of CRC-7 appended to the transferred block, default - 0
[in]stuffByteselects whether stuff byte will be appended to the transferred block, default - false
Returns
pair with return code (0 on success, error code otherwise) and R2 response; error codes:
Here is the caller graph for this function:

◆ writeCmd()

int distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::writeCmd ( const SpiMasterHandle spiMasterHandle,
const uint8_t  command,
const uint32_t  argument = {},
const uint8_t  crc7 = {},
const bool  stuffByte = {} 
)

Writes regular (CMD) command to SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]commandis the command that will be written
[in]argumentis the argument for command, default - 0
[in]crc7is the value of CRC-7 appended to the transferred block, default - 0
[in]stuffByteselects whether stuff byte will be appended to the transferred block, default - false
Returns
0 on success, error code otherwise:

◆ writeCmdReadR1()

std::pair<int, uint8_t> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::writeCmdReadR1 ( const SpiMasterHandle spiMasterHandle,
const uint8_t  command,
const uint32_t  argument = {},
const uint8_t  crc7 = {},
const bool  stuffByte = {} 
)

Writes regular (CMD) command and reads R1 response to/from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]commandis the command that will be written
[in]argumentis the argument for command, default - 0
[in]crc7is the value of CRC-7 appended to the transferred block, default - 0
[in]stuffByteselects whether stuff byte will be appended to the transferred block, default - false
Returns
pair with return code (0 on success, error code otherwise) and R1 response; error codes:
Here is the caller graph for this function:

◆ writeCmdReadR3()

std::pair<int, R3Response> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::writeCmdReadR3 ( const SpiMasterHandle spiMasterHandle,
const uint8_t  command,
const uint32_t  argument = {},
const uint8_t  crc7 = {},
const bool  stuffByte = {} 
)

Writes regular (CMD) command and reads R3 response to/from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]commandis the command that will be written
[in]argumentis the argument for command, default - 0
[in]crc7is the value of CRC-7 appended to the transferred block, default - 0
[in]stuffByteselects whether stuff byte will be appended to the transferred block, default - false
Returns
pair with return code (0 on success, error code otherwise) and R3 response; error codes:
Here is the caller graph for this function:

◆ writeCmdReadR7()

std::pair<int, R7Response> distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::writeCmdReadR7 ( const SpiMasterHandle spiMasterHandle,
const uint8_t  command,
const uint32_t  argument = {},
const uint8_t  crc7 = {},
const bool  stuffByte = {} 
)

Writes regular (CMD) command and reads R7 response to/from SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]commandis the command that will be written
[in]argumentis the argument for command, default - 0
[in]crc7is the value of CRC-7 appended to the transferred block, default - 0
[in]stuffByteselects whether stuff byte will be appended to the transferred block, default - false
Returns
pair with return code (0 on success, error code otherwise) and R7 response; error codes:
Here is the caller graph for this function:

◆ writeDataBlock()

int distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::writeDataBlock ( const SpiMasterHandle spiMasterHandle,
const uint8_t  token,
const void *const  buffer,
const size_t  size,
const distortos::TickClock::duration  duration 
)

Writes data block to SD card connected via SPI.

Parameters
[in]spiMasterHandleis a reference to SpiMasterHandle object used for communication
[in]tokenis the token which will be used to start data block
[in]bufferis a pointer to buffer with written data
[in]sizeis the size of data block that should be written, bytes
[in]durationis the duration of wait before giving up
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ acmd41HcsPosition

constexpr uint8_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::acmd41HcsPosition {30}

ACMD41 argument - HCS bit position.

◆ dataResponseTokenDataAccepted

constexpr uint8_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::dataResponseTokenDataAccepted {0b010 << 1 | 1}

data response token - data accepted

◆ dataResponseTokenMask

constexpr uint8_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::dataResponseTokenMask {0b00011111}

mask for data response token

◆ ocrCcsMask

constexpr uint32_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::ocrCcsMask {1 << 30}

OCR - CCS bit mask.

◆ r1InIdleStateMask

constexpr uint8_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::r1InIdleStateMask {1 << 0}

R1 - in idle state.

◆ startBlockToken

constexpr uint8_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::startBlockToken {0b11111110}

control token - start block

◆ startBlockWriteToken

constexpr uint8_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::startBlockWriteToken {0b11111100}

control token - start block for CMD25

◆ stopTranToken

constexpr uint8_t distortos::devices::anonymous_namespace{SdCardSpiBased.cpp}::stopTranToken {0b11111101}

control token - stop tran