Paparazzi UAS
v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
|
Interface for reading and writing blocks of data to and from an SD card directly over SPI. More...
Go to the source code of this file.
Data Structures | |
struct | SDCard |
Macros | |
#define | SD_BLOCK_SIZE 512 |
Typedefs | |
typedef void(* | SDCardCallback )(void) |
SDCard Callback function. More... | |
Functions | |
void | sdcard_spi_init (struct SDCard *sdcard, struct spi_periph *spi_p, const uint8_t slave_idx) |
Configure initial values for SDCard. More... | |
void | sdcard_spi_periodic (struct SDCard *sdcard) |
Periodic function of the SDCard. More... | |
void | sdcard_spi_write_block (struct SDCard *sdcard, uint32_t addr) |
Write a single block (512 bytes) to the SDCard at a given address. More... | |
void | sdcard_spi_read_block (struct SDCard *sdcard, uint32_t addr, SDCardCallback callback) |
Read a single block (512 bytes) from the SDCard at a given address. More... | |
void | sdcard_spi_multiwrite_start (struct SDCard *sdcard, uint32_t addr) |
Start writing multiple blocks of 512 bytes to the SDCard. More... | |
void | sdcard_spi_multiwrite_next (struct SDCard *sdcard, SDCardCallback callback) |
Write a(nother) data block (512 bytes) to the SDCard. More... | |
void | sdcard_spi_multiwrite_stop (struct SDCard *sdcard) |
Stop with multiwrite procedure. More... | |
Variables | |
struct SDCard | sdcard1 |
This is the definition of the SD card. More... | |
Interface for reading and writing blocks of data to and from an SD card directly over SPI.
Definition in file sdcard_spi.h.
struct SDCard |
Definition at line 109 of file sdcard_spi.h.
Data Fields | ||
---|---|---|
enum SDCardType | card_type | Type of SDCard. |
enum SDCardErrorStatus | error_status | Contains information on where the error has occured. |
SDCardCallback | external_callback | Callback to call when external operation finishes. |
uint8_t | input_buf[SD_BLOCK_SIZE+10] | The input buffer for the SPI transaction. |
uint8_t | output_buf[SD_BLOCK_SIZE+10] | The output buffer for the SPI transaction. |
uint8_t | response_counter | Response counter used at various locations. |
struct spi_periph * | spi_p | The SPI peripheral for the connection. |
struct spi_transaction | spi_t | The SPI transaction used for the writing and reading of registers. |
enum SDCardStatus | status | The status of the SD card. |
uint32_t | timeout_counter | Timeout counter used for initialization checks with ACMD41. |
#define SD_BLOCK_SIZE 512 |
Definition at line 38 of file sdcard_spi.h.
Referenced by sdcard_spi_multiwrite_start(), sdcard_spi_read_block(), sdcard_spi_spicallback(), sdcard_spi_write_block(), sdlogger_spi_direct_index_received(), and sdlogger_spi_direct_periodic().
typedef void(* SDCardCallback)(void) |
SDCard Callback function.
If not NULL (or 0), call function
Definition at line 36 of file sdcard_spi.h.
enum SDCardErrorStatus |
Definition at line 90 of file sdcard_spi.h.
enum SDCardStatus |
Enumerator | |
---|---|
SDCard_UnInit |
SDCard is not initialized. |
SDCard_Error |
An error has occured, sending debug message. |
SDCard_Idle |
Initialization sequence succesful. |
SDCard_Busy |
SDCard is busy with internal process. |
SDCard_BeforeDummyClock |
About to send dummy clock cycles to initialize spi mode. |
SDCard_SendingDummyClock |
Busy sending dummy clock cycles. |
SDCard_SendingCMD0 |
Busy sending CMD0. |
SDCard_ReadingCMD0Resp |
Reading R1 response to CMD0 byte by byte. |
SDCard_SendingCMD8 |
Busy sending CMD8. |
SDCard_ReadingCMD8Resp |
Reading R7 response to CMD8 byte by byte. |
SDCard_ReadingCMD8Parameter |
Reading the 32-bit parameter after receiving 0x01. |
SDCard_SendingACMD41v2 |
Busy sending ACMD41. |
SDCard_ReadingACMD41v2Resp |
Reading R1 response to ACMD41 byte by byte. |
SDCard_SendingCMD58 |
Busy sending CMD58. |
SDCard_ReadingCMD58Resp |
Reading R3 response to CMD58 byte by byte. |
SDCard_ReadingCMD58Parameter |
Reading the 32-bit parameter after receiving 0x00 from CMD58. |
SDCard_SendingCMD16 |
Busy sending CMD16. |
SDCard_ReadingCMD16Resp |
Reading R1 response to CMD16 byte by byte. |
SDCard_SendingCMD24 |
Busy sending CMD24. |
SDCard_ReadingCMD24Resp |
Reading R1 response to CMD24 byte by byte. |
SDCard_BeforeSendingDataBlock |
Start data block transfer. |
SDCard_SendingDataBlock |
Busy sending data block. |
SDCard_SendingCMD17 |
Busy sending CMD17 (block read request) |
SDCard_ReadingCMD17Resp |
Reading R1 response to CMD17 byte by byte. |
SDCard_WaitingForDataToken |
Reading a byte each period until there is a data token or error. |
SDCard_ReadingDataBlock |
Busy reading data block. |
SDCard_SendingCMD25 |
Busy sending CMD25 (multiwrite start command) |
SDCard_ReadingCMD25Resp |
Reading R1 response to CMD25 byte by byte. |
SDCard_MultiWriteIdle |
CMD25 complete, ready to sent blocks. |
SDCard_MultiWriteWriting |
Busy with the SPI transfer in multiwrite. |
SDCard_MultiWriteBusy |
Busy flag after sending data block in multiwrite. |
SDCard_MultiWriteStopping |
Busy sending the stop token. |
Definition at line 55 of file sdcard_spi.h.
enum SDCardType |
Enumerator | |
---|---|
SDCardType_Unknown | |
SDCardType_MmcV3 | |
SDCardType_SdV1 | |
SDCardType_SdV2byte | |
SDCardType_SdV2block |
Definition at line 47 of file sdcard_spi.h.
enum SdResponseType |
Enumerator | |
---|---|
SdResponseNone | |
SdResponseR1 | |
SdResponseR3 | |
SdResponseR7 |
Definition at line 40 of file sdcard_spi.h.
void sdcard_spi_init | ( | struct SDCard * | sdcard, |
struct spi_periph * | spi_p, | ||
const uint8_t | slave_idx | ||
) |
Configure initial values for SDCard.
Initialization of the card itself is done later in sdcard_spi_periodic().
sdcard | Pointer to the SDCard. |
spi_p | Pointer to the SPI Peripheral. |
slave_idx | SPI Slave index. |
Definition at line 74 of file sdcard_spi.c.
References spi_transaction::bitorder, SDCard::card_type, spi_transaction::cdiv, spi_transaction::cpha, spi_transaction::cpol, spi_transaction::dss, SDCard::error_status, SDCard::input_buf, spi_transaction::input_buf, spi_transaction::input_length, SDCard::output_buf, spi_transaction::output_buf, spi_transaction::output_length, SDCard_BeforeDummyClock, SDCardError_None, SDCardType_Unknown, spi_transaction::select, spi_transaction::slave_idx, SDCard::spi_p, SDCard::spi_t, SPICphaEdge1, SPICpolIdleLow, SPIDiv64, SPIDss8bit, SPIMSBFirst, SPISelectUnselect, SPITransDone, SDCard::status, and spi_transaction::status.
Referenced by sdlogger_spi_direct_init().
void sdcard_spi_multiwrite_next | ( | struct SDCard * | sdcard, |
SDCardCallback | callback | ||
) |
Write a(nother) data block (512 bytes) to the SDCard.
Use only after sdcard_spi_multiwrite_start().
sdcard | Pointer to the SDCard. |
Definition at line 638 of file sdcard_spi.c.
References spi_transaction::after_cb, spi_transaction::cdiv, SDCard::external_callback, spi_transaction::input_length, spi_transaction::output_buf, spi_transaction::output_length, SDCard_MultiWriteIdle, SDCard_MultiWriteWriting, sdcard_spi_spicallback(), SDCard::spi_p, spi_submit(), SDCard::spi_t, SPIDiv32, and SDCard::status.
Referenced by sdlogger_spi_direct_periodic(), and sdlogger_spi_direct_put_byte().
Start writing multiple blocks of 512 bytes to the SDCard.
This function notifies the SDCard to expect one or more data packets (which are sent by sdcard_spi_multiwrite_next()).
sdcard | Pointer to the SDCard. |
addr | Block address to start writing at. Addresses are consecutive numbers, regardless the SDCardType. |
Definition at line 616 of file sdcard_spi.c.
References SDCard::card_type, SD_BLOCK_SIZE, SDCard_Idle, SDCard_SendingCMD25, sdcard_spi_send_cmd(), SDCardType_SdV2block, and SDCard::status.
Referenced by sdlogger_spi_direct_periodic().
void sdcard_spi_multiwrite_stop | ( | struct SDCard * | sdcard | ) |
Stop with multiwrite procedure.
sdcard | Pointer to the SDCard. |
Definition at line 666 of file sdcard_spi.c.
References spi_transaction::after_cb, spi_transaction::cdiv, spi_transaction::input_length, SDCard::output_buf, spi_transaction::output_length, SDCard_MultiWriteIdle, SDCard_MultiWriteStopping, sdcard_spi_spicallback(), SDCard::spi_p, spi_submit(), SDCard::spi_t, SPIDiv32, and SDCard::status.
Referenced by sdlogger_spi_direct_periodic().
void sdcard_spi_periodic | ( | struct SDCard * | sdcard | ) |
Periodic function of the SDCard.
sdcard | Pointer to the SDCard. |
Definition at line 99 of file sdcard_spi.c.
References spi_transaction::after_cb, spi_transaction::input_length, SDCard::output_buf, spi_transaction::output_length, SDCard_BeforeDummyClock, SDCard_Busy, SDCard_MultiWriteBusy, SDCard_SendingACMD41v2, SDCard_SendingDummyClock, sdcard_spi_request_bytes(), sdcard_spi_send_app_cmd(), sdcard_spi_spicallback(), SDCard_WaitingForDataToken, spi_transaction::select, SDCard::spi_p, spi_submit(), SDCard::spi_t, SPINoSelect, SPITransPending, SPITransRunning, SDCard::status, spi_transaction::status, and SDCard::timeout_counter.
Referenced by sdlogger_spi_direct_periodic().
void sdcard_spi_read_block | ( | struct SDCard * | sdcard, |
uint32_t | addr, | ||
SDCardCallback | callback | ||
) |
Read a single block (512 bytes) from the SDCard at a given address.
When the block reading is finished, sdcard_spi_spicallback() is triggered which in turn calls the function from the callback parameter.
sdcard | Pointer to the SDCard. |
addr | Block address to read from. The addresses are consecutive numbers, regardless the SDCardType. |
callback | Function to call when block reading is finished. |
Definition at line 587 of file sdcard_spi.c.
References SDCard::card_type, spi_transaction::cdiv, SDCard::external_callback, SD_BLOCK_SIZE, SDCard_Idle, SDCard_SendingCMD17, sdcard_spi_send_cmd(), SDCardType_SdV2block, SDCard::spi_t, SPIDiv32, and SDCard::status.
Referenced by sdlogger_spi_direct_command(), sdlogger_spi_direct_index_received(), and sdlogger_spi_direct_periodic().
Write a single block (512 bytes) to the SDCard at a given address.
sdcard | Pointer to the SDCard. |
addr | Block address to write to. The addresses are consecutive numbers, regardless the SDCardType. |
Definition at line 560 of file sdcard_spi.c.
References SDCard::card_type, spi_transaction::cdiv, SD_BLOCK_SIZE, SDCard_Idle, SDCard_SendingCMD24, sdcard_spi_send_cmd(), SDCardType_SdV2block, SDCard::spi_t, SPIDiv64, and SDCard::status.
Referenced by sdlogger_spi_direct_index_received().
struct SDCard sdcard1 |
This is the definition of the SD card.
Currently, only one SD card can be used. Most of the functions are prepared for feature support of multiple SD cards, by taking a reference to the SDCard as parameter. Only the sdcard_spi_callback() function, which is called after a spi transaction is finished, does not provide a reference to the SDCard. Thereby sdcard_spi_callback() cannot know which SDCard is ready. However, the spi_transaction is given as a parameter, which is part of the SDCard. So thereby the SDCard might be identified.
Definition at line 56 of file sdcard_spi.c.
Referenced by sdcard_spi_spicallback(), sdlogger_spi_direct_command(), sdlogger_spi_direct_index_received(), sdlogger_spi_direct_init(), sdlogger_spi_direct_multiwrite_written(), sdlogger_spi_direct_periodic(), and sdlogger_spi_direct_put_byte().