|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Module-private cross-TU surface for the SPI-mode SD card driver. More...
Go to the source code of this file.
Data Structures | |
| struct | sd_state_t |
| Cached protocol state held across the driver public API. More... | |
Functions | |
| ra8_err_t | priv_sdmmc_spi_xfer_one (uint8_t tx, uint8_t *rx) |
| Shift out one byte and capture the response over the transport. | |
| ra8_err_t | priv_sdmmc_spi_send_idle (uint32_t n) |
Shift n idle bytes (0xFF) and discard the response. | |
| ra8_err_t | priv_sdmmc_spi_cs_assert (void) |
| Drive CS low and clock a single idle byte so CIPO is sampled. | |
| ra8_err_t | priv_sdmmc_spi_cs_release (void) |
| Drive CS high after clocking one idle byte (SD spec section 7.2.4). | |
| ra8_err_t | priv_sdmmc_spi_send_command (sd_cmd_t cmd, uint32_t arg, uint8_t *out_r1) |
| Send a command frame and capture the R1 response byte. | |
| ra8_err_t | priv_sdmmc_spi_send_acmd (sd_cmd_t acmd, uint32_t arg, uint8_t *out_r1) |
| Send an ACMD by prefixing it with CMD55 (APP_CMD). | |
| ra8_err_t | priv_sdmmc_spi_send_stop_transmission (uint8_t *out_r1) |
| Send CMD12 (STOP_TRANSMISSION) and capture its R1 response byte. | |
| ra8_err_t | priv_sdmmc_spi_wait_data_token (void) |
| Poll for the data-start token (0xFE), bounded by a retry budget. | |
| ra8_err_t | priv_sdmmc_spi_wait_not_busy_bounded (uint32_t max_polls) |
Wait for the card to release busy (CIPO -> 0xFF), bounded by max_polls. | |
| ra8_err_t | priv_sdmmc_spi_wait_not_busy (void) |
| Wait for the card to release the busy token (CIPO returns to 0xFF). | |
| ra8_err_t | priv_sdmmc_spi_validate_transport (const ra8_sdmmc_spi_transport_t *transport) |
| Validate the transport descriptor: every callback non-NULL. | |
| ra8_err_t | priv_sdmmc_spi_run_init_sequence (void) |
| Walk the full SD identification sequence and learn capacity / type. | |
Variables | |
| sd_state_t | g_sdmmc_spi_state |
| Single driver instance (the module's one external definition). | |
Module-private cross-TU surface for the SPI-mode SD card driver.
Shared between the core/init translation unit (ra8_sdmmc_spi.c) and the block-I/O translation unit (ra8_sdmmc_spi_io.c) of the ra8_sdmmc_spi library. It carries the protocol enums both units use, the single mutable driver-state definition, and the prototypes of the low-level transport / framing helpers that the block-I/O unit calls.
This header is private to the ra8_sdmmc_spi module; no other library includes it. All enum values and helper contracts mirror SD Specification Part 1 Physical Layer Simplified Specification v9.10 section 7 ("SPI Mode") – the same references documented inline at each symbol's original definition site.
Definition in file ra8_sdmmc_spi_internal.h.
| enum sd_bit_shift_t : uint8_t |
Bit-shift constants reused across byte packing.
| Enumerator | |
|---|---|
| k_sd_bit_byte | SD bit byte. |
| k_sd_bit_two_byte | SD bit two byte. |
| k_sd_bit_three_byte | SD bit three byte. |
Definition at line 133 of file ra8_sdmmc_spi_internal.h.
| enum sd_byte_mask_t : uint32_t |
Generic byte-extraction masks used across argument packing.
k_sd_mask_byte isolates the low 8 bits when packing a 32-bit command argument into the 4 big-endian frame bytes (SD spec PHY v9 section 7.3.1.1 "Command Format") or splitting a 16-bit CRC16 into its two on-wire bytes. k_sd_mask_12bit is the CMD8 echo-check mask (SD spec PHY v9 section 7.3.2.6: bits [11:0] of the R7 echo carry the voltage-range code (bits 11:8) and the host check pattern (bits 7:0)).
| Enumerator | |
|---|---|
| k_sd_mask_byte | Low 8 bits of a wider value. |
| k_sd_mask_12bit | CMD8 R7 echo voltage-range + check pattern. |
Definition at line 152 of file ra8_sdmmc_spi_internal.h.
| enum sd_cmd_t : uint8_t |
Wire-byte for every command used by this driver.
The wire byte is 0x40 | cmd_index per SD spec PHY v9 section 7.3.1.1 "Command Format" (bit 7 = 0, bit 6 = 1, bits 5..0 = command index).
Definition at line 52 of file ra8_sdmmc_spi_internal.h.
| enum sd_data_response_t : uint8_t |
Data-response token bit layout (SD spec PHY v9 section 7.3.3.1).
Wire layout xxx0sss1 where sss = 010 "accepted", 101 "CRC error", 110 "write error". Mask with k_sd_data_response_mask first.
Definition at line 91 of file ra8_sdmmc_spi_internal.h.
| enum sd_data_token_t : uint8_t |
Data tokens used for block I/O (SD spec PHY v9 section 7.3.3).
| Enumerator | |
|---|---|
| k_sd_token_data_start_single | Single-block start. |
| k_sd_token_data_start_multi | Multi-block start. |
| k_sd_token_stop_multi | Multi-block stop. |
| k_sd_token_idle | Idle bus. |
Definition at line 76 of file ra8_sdmmc_spi_internal.h.
| enum sd_protocol_const_t : uint32_t |
Magic argument values and retry budgets.
Definition at line 102 of file ra8_sdmmc_spi_internal.h.
| ra8_err_t priv_sdmmc_spi_cs_assert | ( | void | ) |
Drive CS low and clock a single idle byte so CIPO is sampled.
Selects the card and emits one idle byte to align framing.
| k_ra8_ok | CS asserted and one idle byte clocked. |
| other | Propagated from the transport cs / xfer callbacks. |
Definition at line 249 of file ra8_sdmmc_spi.c.
References g_sdmmc_spi_state, k_ra8_ok, priv_sdmmc_spi_send_idle(), and RA8_PRIV.
Referenced by internal_acmd41_loop(), internal_cmd_require_ready(), internal_erase_range(), internal_read_csd(), internal_read_ocr(), internal_send_cmd0(), internal_send_cmd8(), internal_set_block_len(), ra8_sdmmc_spi_read_block(), ra8_sdmmc_spi_read_blocks(), ra8_sdmmc_spi_write_block(), and ra8_sdmmc_spi_write_blocks().
| ra8_err_t priv_sdmmc_spi_cs_release | ( | void | ) |
Drive CS high after clocking one idle byte (SD spec section 7.2.4).
Releases the card and emits trailing idle clocks so the card can finish any pending internal state transition.
| k_ra8_ok | CS released and one idle byte clocked. |
| other | Propagated from the transport cs / xfer callbacks. |
Definition at line 260 of file ra8_sdmmc_spi.c.
References g_sdmmc_spi_state, k_ra8_ok, priv_sdmmc_spi_send_idle(), and RA8_PRIV.
Referenced by internal_acmd41_loop(), internal_cmd_require_ready(), internal_erase_range(), internal_read_csd(), internal_read_ocr(), internal_send_cmd0(), internal_send_cmd8(), internal_set_block_len(), ra8_sdmmc_spi_read_block(), ra8_sdmmc_spi_read_blocks(), ra8_sdmmc_spi_write_block(), and ra8_sdmmc_spi_write_blocks().
| ra8_err_t priv_sdmmc_spi_run_init_sequence | ( | void | ) |
Walk the full SD identification sequence and learn capacity / type.
Runs the CMD0/CMD8/ACMD41/CMD58/CMD9/CMD16 probe and records the card type and capacity into g_sdmmc_spi_state.
| k_ra8_ok | Card identified; type and capacity cached. |
| k_ra8_err_protocol_error | A response was malformed. |
| other | Propagated from the probe steps. |
Definition at line 777 of file ra8_sdmmc_spi.c.
References g_sdmmc_spi_state, internal_classify_card(), internal_probe_card(), internal_read_csd(), internal_set_block_len(), k_ra8_ok, RA8_PRIV, RA8_RETURN_ON_ERROR, and s_tag.
Referenced by ra8_sdmmc_spi_init().
Send an ACMD by prefixing it with CMD55 (APP_CMD).
Issues CMD55 then the application command, returning the application command's R1.
| [in] | acmd | Application command wire byte. |
| [in] | arg | 32-bit command argument. |
| [out] | out_r1 | Captured R1 response byte of the application command. |
| k_ra8_ok | Both commands sent and R1 captured. |
| other | Propagated from the transport callbacks. |
out_r1 is non-NULL. out_r1 holds the application command R1. out_r1 is modified. Definition at line 333 of file ra8_sdmmc_spi.c.
References k_ra8_ok, k_sd_cmd_app_cmd, priv_sdmmc_spi_send_command(), and RA8_PRIV.
Referenced by internal_acmd41_loop(), and ra8_sdmmc_spi_write_blocks().
Send a command frame and capture the R1 response byte.
Builds the 6-byte frame (CRC7 included), clocks it out, then polls for the R1 token.
| [in] | cmd | Command wire byte. |
| [in] | arg | 32-bit command argument. |
| [out] | out_r1 | Captured R1 response byte. |
| k_ra8_ok | Command sent and R1 captured. |
| k_ra8_err_hw_timeout | R1 did not appear within budget. |
| other | Propagated from the transport callbacks. |
out_r1 is non-NULL. out_r1 holds the R1 byte. out_r1 is modified. Definition at line 316 of file ra8_sdmmc_spi.c.
References g_sdmmc_spi_state, internal_build_frame(), internal_read_r1(), k_ra8_ok, k_ra8_sdmmc_spi_cmd_frame_bytes, and RA8_PRIV.
Referenced by internal_cmd_require_ready(), internal_erase_range(), internal_read_csd(), internal_read_data_phase(), internal_read_ocr(), internal_recover_stuck_card(), internal_send_cmd0(), internal_send_cmd8(), internal_set_block_len(), priv_sdmmc_spi_send_acmd(), ra8_sdmmc_spi_read_blocks(), ra8_sdmmc_spi_write_block(), and ra8_sdmmc_spi_write_blocks().
| ra8_err_t priv_sdmmc_spi_send_idle | ( | uint32_t | n | ) |
Shift n idle bytes (0xFF) and discard the response.
Bounded by n; clocks the bus idle to advance card timers.
| [in] | n | Number of idle bytes to clock. |
| k_ra8_ok | All n bytes clocked. |
| other | Propagated from the transport xfer callback. |
n idle bytes were clocked on success. Definition at line 235 of file ra8_sdmmc_spi.c.
References k_ra8_ok, k_sd_token_idle, priv_sdmmc_spi_xfer_one(), and RA8_PRIV.
Referenced by internal_recover_stuck_card(), internal_wake_card(), internal_write_data_block(), internal_write_multi_stream(), priv_sdmmc_spi_cs_assert(), priv_sdmmc_spi_cs_release(), and priv_sdmmc_spi_send_stop_transmission().
| ra8_err_t priv_sdmmc_spi_send_stop_transmission | ( | uint8_t * | out_r1 | ) |
Send CMD12 (STOP_TRANSMISSION) and capture its R1 response byte.
Builds and clocks the 6-byte CMD12 frame, discards the one stuff byte that follows it (the tail of the interrupted read stream – its value is undefined, and a bit7-clear garbage byte would be misread as R1), then polls for the R1 token. Terminates a CMD18 READ_MULTIPLE_BLOCK stream; the plain priv_sdmmc_spi_send_command cannot be used because it polls for R1 straight after the frame.
| [out] | out_r1 | Captured R1 response byte. |
| k_ra8_ok | CMD12 sent and R1 captured. |
| k_ra8_err_hw_timeout | R1 did not appear within budget. |
| other | Propagated from the transport callbacks. |
out_r1 is non-NULL. out_r1 holds the CMD12 R1 byte. out_r1 is modified. Definition at line 346 of file ra8_sdmmc_spi.c.
References g_sdmmc_spi_state, internal_build_frame(), internal_read_r1(), k_ra8_ok, k_ra8_sdmmc_spi_cmd_frame_bytes, k_sd_cmd_stop_transmission, priv_sdmmc_spi_send_idle(), and RA8_PRIV.
Referenced by internal_read_multi_stop().
| ra8_err_t priv_sdmmc_spi_validate_transport | ( | const ra8_sdmmc_spi_transport_t * | transport | ) |
Validate the transport descriptor: every callback non-NULL.
Rejects a NULL descriptor or any NULL callback before bind.
| [in] | transport | Transport descriptor to check. |
| k_ra8_ok | Descriptor and all callbacks are non-NULL. |
| k_ra8_err_null_ptr | transport is NULL. |
| k_ra8_err_invalid_arg | A callback is NULL. |
Definition at line 488 of file ra8_sdmmc_spi.c.
References k_ra8_err_invalid_arg, k_ra8_err_null_ptr, k_ra8_ok, and RA8_PRIV.
Referenced by ra8_sdmmc_spi_init().
| ra8_err_t priv_sdmmc_spi_wait_data_token | ( | void | ) |
Poll for the data-start token (0xFE), bounded by a retry budget.
Clocks idle bytes until the single-block data-start token appears or the poll budget is exhausted.
| k_ra8_ok | Data-start token observed. |
| k_ra8_err_hw_timeout | Token did not appear within budget. |
| other | Propagated from the transport callbacks. |
Definition at line 404 of file ra8_sdmmc_spi.c.
References k_ra8_err_hw_timeout, k_ra8_ok, k_sd_max_data_token_polls, k_sd_token_data_start_single, k_sd_token_idle, priv_sdmmc_spi_xfer_one(), and RA8_PRIV.
Referenced by internal_read_csd(), internal_read_data_phase(), and internal_read_multi_stream().
| ra8_err_t priv_sdmmc_spi_wait_not_busy | ( | void | ) |
Wait for the card to release the busy token (CIPO returns to 0xFF).
Convenience wrapper over priv_sdmmc_spi_wait_not_busy_bounded with the default worst-case write timeout.
| k_ra8_ok | Card released busy. |
| k_ra8_err_hw_timeout | Card stayed busy beyond the default budget. |
| other | Propagated from the transport callbacks. |
Definition at line 438 of file ra8_sdmmc_spi.c.
References k_sd_max_busy_poll_bytes, priv_sdmmc_spi_wait_not_busy_bounded(), and RA8_PRIV.
Referenced by internal_read_multi_stop(), internal_recover_stuck_card(), internal_write_data_block(), and internal_write_multi_stream().
| ra8_err_t priv_sdmmc_spi_wait_not_busy_bounded | ( | uint32_t | max_polls | ) |
Wait for the card to release busy (CIPO -> 0xFF), bounded by max_polls.
Clocks idle bytes until the card stops holding CIPO low or the poll budget is exhausted.
| [in] | max_polls | Maximum idle bytes to clock before timing out. |
| k_ra8_ok | Card released busy. |
| k_ra8_err_hw_timeout | Card stayed busy beyond max_polls. |
| other | Propagated from the transport callbacks. |
Definition at line 421 of file ra8_sdmmc_spi.c.
References k_ra8_err_hw_timeout, k_ra8_ok, k_sd_token_idle, priv_sdmmc_spi_xfer_one(), and RA8_PRIV.
Referenced by internal_erase_range(), and priv_sdmmc_spi_wait_not_busy().
| ra8_err_t priv_sdmmc_spi_xfer_one | ( | uint8_t | tx, |
| uint8_t * | rx ) |
Shift out one byte and capture the response over the transport.
Wraps a single-byte full-duplex transfer through the bound g_sdmmc_spi_state.transport so callers need not stage 1-byte buffers themselves.
| [in] | tx | Byte to clock out. |
| [out] | rx | Received byte, or NULL to discard. |
| k_ra8_ok | Byte exchanged. |
| other | Propagated from the transport xfer callback. |
rx holds the received byte when non-NULL. rx is modified. Definition at line 218 of file ra8_sdmmc_spi.c.
References g_sdmmc_spi_state, k_ra8_ok, and RA8_PRIV.
Referenced by internal_read_block_crc_check(), internal_read_block_payload(), internal_read_csd(), internal_read_r1(), internal_read_r3_or_r7_tail(), internal_recover_stuck_card(), internal_write_data_block(), internal_write_multi_stream(), priv_sdmmc_spi_send_idle(), priv_sdmmc_spi_wait_data_token(), and priv_sdmmc_spi_wait_not_busy_bounded().
|
extern |
Single driver instance (the module's one external definition).
Single driver instance, defined in ra8_sdmmc_spi.c.
Shared with the block-I/O TU through ra8_sdmmc_spi_internal.h; this file owns the sole definition.
Mutable protocol state shared between the core/init TU and the block-I/O TU. Renamed with the module infix so it is link-unique.
Definition at line 164 of file ra8_sdmmc_spi.c.
Referenced by internal_finalize_init(), internal_fs_get_capacity(), internal_lba_to_arg(), internal_prepare_init(), internal_read_r3_or_r7_tail(), internal_recover_stuck_card(), internal_wake_card(), internal_write_data_block(), priv_sdmmc_spi_cs_assert(), priv_sdmmc_spi_cs_release(), priv_sdmmc_spi_run_init_sequence(), priv_sdmmc_spi_send_command(), priv_sdmmc_spi_send_stop_transmission(), priv_sdmmc_spi_xfer_one(), ra8_sdmmc_spi_bind_fs_backend(), ra8_sdmmc_spi_deinit(), ra8_sdmmc_spi_erase_blocks(), ra8_sdmmc_spi_get_capacity(), ra8_sdmmc_spi_get_card_type(), ra8_sdmmc_spi_read_block(), ra8_sdmmc_spi_read_blocks(), ra8_sdmmc_spi_write_block(), and ra8_sdmmc_spi_write_blocks().