|
GPS Device
|
SD card driver implementation file. More...
#include <stdbool.h>#include <string.h>#include "sd.h"#include "common.h"#include "err.h"#include "init.h"#include "io.h"#include "log.h"#include "modules.h"#include "cmd.h"#include "configuration.h"#include "stm32f401re.h"#include "stm32f401re_gpio.h"#include "stm32f401re_rcc.h"#include "stm32f401re_spi.h"#include "arm_cortex_m4_systick.h"
Go to the source code of this file.
Classes | |
| struct | CMD_RESPONSE_ts |
| Holds the R1, R3, and R7 response bytes returned by the SD card after a command. More... | |
| struct | SD_CSD_INFO_ts |
| Decoded contents of the SD card CSD register. More... | |
| struct | sd_handle_s |
| Internal structure representing a single SD card handle instance. More... | |
| struct | internal_state_s |
| Internal state of the SysTick driver. More... | |
Functions | |
| static ERR_te | sd_go_idle_state (SD_HANDLE_ts *sd_handle) |
| Issues CMD0 to reset the SD card into idle (SPI) mode. | |
| static ERR_te | sd_send_if_cond (SD_HANDLE_ts *sd_handle, bool *match_o, bool *no_resp_o) |
| Issues CMD8 to determine whether the card is SD Ver.2 or older. | |
| static ERR_te | sd_app_send_op_cond (SD_HANDLE_ts *sd_handle, uint32_t arg) |
| Issues ACMD41 to initiate SD card initialization (SD Ver.2 and Ver.1). | |
| static ERR_te | sd_read_ocr (SD_HANDLE_ts *sd_handle) |
| Reads the OCR register via CMD58 and stores power-up status, addressing mode, and voltage range. | |
| static ERR_te | sd_send_op_cond (SD_HANDLE_ts *sd_handle) |
| Issues CMD1 to initiate MMC Ver.3 card initialization. | |
| static ERR_te | sd_set_blocklen (SD_HANDLE_ts *sd_handle) |
| Issues CMD16 to set the block length to 512 bytes for byte-addressed cards. | |
| static ERR_te | sd_read_csd (SD_HANDLE_ts *sd_handle) |
| Issues CMD9 to read the CSD register and stores capacity information in the handle. | |
| static ERR_te | decode_csd_v1 (const uint8_t *csd_raw, SD_CSD_INFO_ts *csd_info_o) |
| Decodes a CSD v1.0 register (SDSC cards) into a SD_CSD_INFO_ts structure. | |
| static ERR_te | decode_csd_v2 (const uint8_t *csd_raw, SD_CSD_INFO_ts *csd_info_o) |
| Decodes a CSD v2.0 register (SDHC/SDXC cards) into a SD_CSD_INFO_ts structure. | |
| static ERR_te | sd_send_cmd (SPI_REGDEF_ts *spi_instance, uint8_t index, uint32_t arg, bool acmd, CMD_RESPONSE_ts *cmd_response_o) |
| Transmits a single SPI-mode SD command and receives the response. | |
| static ERR_te | sd_cease_comms (SD_HANDLE_ts *sd_handle, bool deinit) |
| Raises CS, sends two dummy bytes, and disables SPI. Optionally deinitializes the handle. | |
| static ERR_te | sd_cmd_list_handler (uint32_t argc, char **argv) |
| CLI handler for the "list" command. Logs the names of all active SD card handles. | |
| static ERR_te | sd_cmd_info_handler (uint32_t argc, char **argv) |
| CLI handler for the "info" command. Logs detailed information about a named SD card handle. | |
| ERR_te | sd_init_subsys (void) |
| Initializes the SD card subsystem. | |
| ERR_te | sd_deinit_subsys (void) |
| Deinitializes the SD card subsystem. | |
| ERR_te | sd_start_subsys (void) |
| Starts the SD card subsystem. | |
| ERR_te | sd_stop_subsys (void) |
| Stops the SD card subsystem. | |
| ERR_te | sd_init_handle (SD_CFG_ts *sd_cfg, SD_HANDLE_ts **sd_handle_o) |
| Initializes an SD card handle and performs the full SPI-mode power-up sequence. | |
| ERR_te | sd_deinit_handle (SD_HANDLE_ts *sd_handle) |
| Deinitializes an SD card handle and resets the SPI peripheral. | |
| ERR_te | sd_get_handle_init (SD_HANDLE_ts *sd_handle, bool *handle_init_o) |
| Retrieves the initialization state of an SD card handle. | |
| ERR_te | sd_get_sector_count (SD_HANDLE_ts *sd_handle, uint32_t *sector_count_o) |
| Retrieves the total sector (block) count of the SD card. | |
| ERR_te | sd_get_sector_size (SD_HANDLE_ts *sd_handle, uint32_t *sector_size_o) |
| Retrieves the sector (block) size of the SD card in bytes. | |
| ERR_te | sd_read (SD_HANDLE_ts *sd_handle, uint8_t *read_buf, uint32_t start_sector, uint32_t num_sectors) |
| Reads one or more sectors from the SD card. | |
| ERR_te | sd_write (SD_HANDLE_ts *sd_handle, uint8_t *write_buf, uint32_t start_sector, uint32_t num_sectors) |
| Writes one or more sectors to the SD card. | |
Variables | |
| struct internal_state_s | internal_state |
| Singleton instance of the SD card subsystem internal state. | |
| CMD_INFO_ts | sd_cmds [] |
| Table of CLI commands registered by the SD card subsystem. | |
| CMD_CLIENT_INFO_ts | sd_cmd_client_info |
| Registration descriptor passed to the command subsystem. | |
SD card driver implementation file.
Definition in file sd.c.
| enum OCR_te |
Bit positions within the 32-bit OCR register.
Used to extract individual fields from the OCR value reconstructed from the R3 response of CMD58. Voltage range bits 4–23 each represent a 100 mV window; bit 30 is the Card Capacity Status (0 = SDSC, 1 = SDHC); bit 31 is the power-up completion flag.
Definition at line 54 of file sd.c.
Minimum allowed operating voltage of the SD card, decoded from the OCR register.
Definition at line 82 of file sd.c.
Maximum allowed operating voltage of the SD card, decoded from the OCR register.
Definition at line 108 of file sd.c.
| enum SD_ADDR_MODE_te |
Addressing mode used by the SD card for read/write sector addresses.
| Enumerator | |
|---|---|
| SD_ADDR_MODE_BYTE | Byte addressing (SDSC cards). Address = sector × block length. |
| SD_ADDR_MODE_BLOCK | Block addressing (SDHC/SDXC cards). Address = sector number directly. |
Definition at line 134 of file sd.c.
| enum SD_PWRUP_STATUS_te |
Power-up completion status decoded from the OCR register.
| Enumerator | |
|---|---|
| SD_PWRUP_STATUS_BUSY | Card is still completing its power-up sequence. |
| SD_PWRUP_STATUS_READY | Card has completed power-up and is ready for commands. |
Definition at line 142 of file sd.c.
| enum SD_TYPE_te |
Card type decoded from the OCR Capacity Status bit.
| Enumerator | |
|---|---|
| SDSC | Standard Capacity SD card (byte addressing, ≤ 2 GB). |
| SDHC | High Capacity SD card (block addressing, > 2 GB). |
| struct internal_state_s internal_state |
| CMD_INFO_ts sd_cmds[] |
Table of CLI commands registered by the SD card subsystem.
Registered with the command subsystem via sd_cmd_client_info during sd_init_subsys.
Definition at line 292 of file sd.c.
| CMD_CLIENT_INFO_ts sd_cmd_client_info |
Registration descriptor passed to the command subsystem.
Bundles the command table, its size, the subsystem name prefix used on the CLI, and a pointer to the runtime log-level variable.
Definition at line 312 of file sd.c.