43typedef enum : uint32_t {
62typedef enum : uint8_t {
103 for (uint32_t i = 0U; i < len; i++) {
107 crc = (uint16_t)(crc << 1U);
143 const uint64_t available = c->
image_len - off;
144 const size_t count = (available < (uint64_t)
k_sd_block) ? (
size_t)available : (size_t)
k_sd_block;
211 const uint64_t off = (uint64_t)arg * (uint64_t)
k_sd_block;
314 (void)snprintf(ln,
sizeof(ln),
"SDSPI wr blk=%u", (
unsigned)arg);
479 memset(csd, 0,
sizeof(csd));
690 const bool was_app = c->
app_cmd;
747 const uint64_t off = (uint64_t)lba * (uint64_t)
k_sd_block;
755 (void)
memcpy(dst, block,
sizeof(block));
765 const uint64_t off = (uint64_t)lba * (uint64_t)
k_sd_block;
Multi-channel console log store backing the board view's tabbed console.
void board_console_push(board_console_ch_t ch, const char *line)
Append one completed line to a channel ring and the ALL ring.
@ k_board_console_ch_sd
SD (SDHI + SD-over-SPI) block summaries.
static bool internal_board_sd_fill_block(const board_sd_state_t *c, uint64_t off, uint8_t *blk)
Copy one 512-byte block out of the backing image (zero past the end).
static void internal_sd_write_crc(board_sd_state_t *c)
Swallow the two block-CRC bytes, then acknowledge the block.
static void internal_board_sd_cmd_erase(board_sd_state_t *c, uint8_t r1)
Zero the latched [start, end] block range – CMD38 (ERASE).
static void internal_board_sd_stop_read(board_sd_state_t *c, uint8_t r1)
Answer CMD12 STOP_TRANSMISSION and close any open CMD18 stream.
static void internal_board_sd_cmd_send_csd(board_sd_state_t *c)
Stage the 16-byte CSD v2.0 data block for a CMD9 (SEND_CSD) reply.
static void internal_board_sd_stage_block(board_sd_state_t *c, const uint8_t *payload, uint32_t len)
Stage the R1 + data-token + payload + CRC16 reply for a block read.
sd_console_t
Console-tap sizing for SD-over-SPI block summaries.
@ k_sd_console_rd_every
Push 1 read line per N blocks (anti-flood).
@ k_sd_console_line_cap
Max chars in an "SDSPI .. .." line.
static bool internal_board_sd_dispatch_ident(board_sd_state_t *c, uint8_t idx, uint8_t r1)
Handle the identification / configuration commands (CMD0/8/55/58/16).
static void internal_board_sd_begin_read(board_sd_state_t *c, uint8_t idx, uint32_t arg)
Accept a CMD17/CMD18 block-read command and stage the first block.
static void internal_sd_write_token(board_sd_state_t *c, uint8_t tx)
Handle a byte while the model waits for a write data token.
bool board_sd_read_block(uint32_t lba, uint8_t *dst)
Copy one 512-byte block straight out of the backing image.
static uint16_t internal_board_sd_crc16(const uint8_t *data, uint32_t len)
CRC16-CCITT (poly 0x1021, init 0) over a buffer.
static void internal_sd_write_data(board_sd_state_t *c, uint8_t tx)
Absorb one payload byte of a write block.
static uint8_t internal_board_sd_write_byte(board_sd_state_t *c, uint8_t tx)
Feed one host byte into an in-flight block write; return the CIPO byte.
uint8_t board_sd_exchange(uint8_t tx)
Exchange one full-duplex SPI byte with the modelled card.
static void internal_board_sd_read_stream_next(board_sd_state_t *c)
Stage the next block of an open CMD18 stream (token + payload + CRC).
static void internal_board_sd_process_cmd(board_sd_state_t *c)
Build the response for a completed 6-byte command frame.
bool board_sd_write_block(uint32_t lba, const uint8_t *src)
Copy one 512-byte block straight into the backing image.
static void internal_board_sd_dispatch_data(board_sd_state_t *c, uint8_t idx, uint32_t arg, uint8_t r1)
Handle the data-transfer and erase commands (CMD9/17/18/12/24/25/32/33/38).
static uint32_t s_sd_spi_block_reads
Count of SD-over-SPI data blocks staged for read this run.
void board_sd_reset(void)
Reset the card's command / response framing to power-on.
static void internal_board_sd_cmd_erase_bound(board_sd_state_t *c, uint32_t *bound, uint32_t arg, uint8_t r1)
Record one bound of the CMD32/CMD33 erase range and acknowledge it.
board_sd_cmd_idx_t
SD SPI command indices answered by the model (low 6 bits of byte 0).
@ k_sd_idx_cmd33
ERASE_WR_BLK_END.
@ k_sd_idx_cmd32
ERASE_WR_BLK_START.
@ k_sd_idx_cmd17
READ_SINGLE.
@ k_sd_idx_cmd18
READ_MULTIPLE.
@ k_sd_idx_acmd41
SD_SEND_OP_COND.
@ k_sd_idx_cmd8
SEND_IF_COND.
@ k_sd_idx_cmd12
STOP_TRANSMISSION.
@ k_sd_idx_cmd25
WRITE_MULTIPLE.
@ k_sd_idx_cmd16
SET_BLOCKLEN.
@ k_sd_idx_cmd0
GO_IDLE_STATE.
@ k_sd_idx_cmd24
WRITE_SINGLE.
@ k_sd_idx_cmd58
READ_OCR.
static void internal_board_sd_begin_write(board_sd_state_t *c, uint8_t idx, uint32_t arg, uint8_t r1)
Accept a CMD24/CMD25 block-write command and arm the data phase.
SD-card-over-SPI device model for ra8_emulator (attached to SPI_B).
Module-private FAT formatter shared by the board_periph_sd TUs.
bool priv_board_sd_storage_write(uint64_t offset, const void *src, size_t count)
Write exactly to the current sparse backend at a checked byte offset.
bool priv_board_sd_storage_zero(uint64_t offset, uint64_t count)
Make a checked byte range read as zero while preserving sparse storage.
board_sd_state_t g_board_sd
The single modelled SD card (defined in board_periph_sd.c).
@ k_sd_wr_idle
Not in a write transaction.
@ k_sd_wr_token
Awaiting the data-start (or stop-tran) token.
@ k_sd_wr_data
Collecting the 512 payload bytes.
@ k_sd_wr_crc
Collecting the trailing 2 CRC bytes.
@ k_sd_csd_unit
CSD v2.0 C_SIZE unit: 512 KiB.
bool priv_board_sd_storage_read(uint64_t offset, void *dst, size_t count)
Read exactly from the current sparse backend at a checked byte offset.
@ k_sd_csd_csize_b7
C_SIZE high byte offset in the CSD.
@ k_sd_tok_wmulti
Multi-block write data-start token.
@ k_sd_csd_v2
CSD_STRUCTURE = 01b (v2.0 / SDHC).
@ k_sd_r7_len
R1 + 4-byte tail.
@ k_sd_csd_csize
C_SIZE byte (=> 8 MiB modelled card).
@ k_sd_cmd_mask
Mask isolating the lead bits.
@ k_sd_crc_len
Trailing CRC16 bytes after a data block.
@ k_sd_data_error
Data-response token: backend write error.
@ k_sd_cmd_len
Command frame: opcode + 4 arg + crc.
@ k_sd_data_accept
Data-response token: block accepted.
@ k_sd_csd_off
C_SIZE LSB byte offset in the CSD.
@ k_sd_byte_bits
Bits per byte (shift amount).
@ k_sd_crc_poly
CRC16-CCITT polynomial.
@ k_sd_arg_sh1
Arg byte 1 shift.
@ k_sd_idle
Bus idle / CIPO-high byte.
@ k_sd_ocr_pwrccs
OCR byte 0: power-up done + CCS.
@ k_sd_r1_param_err
R1 parameter/backend range error.
@ k_sd_arg_sh0
Arg byte 0 (MSB) shift.
@ k_sd_idx_mask
Command index in the lead byte.
@ k_sd_ocr_volt
OCR byte 2: voltage window.
@ k_sd_block
Bytes per SD block.
@ k_sd_tok_stop
Multi-block write stop-tran token.
@ k_sd_cmd8_echo
CMD8 check pattern echo.
@ k_sd_r1_idle
R1 with IDLE set.
@ k_sd_read_error
Read data-error token: backend fault.
@ k_sd_tok_data
Single-block read / write data token.
@ k_sd_cmd_start
SPI command lead bits (01xxxxxx).
@ k_sd_csd_csize_b8
C_SIZE mid byte offset in the CSD.
@ k_sd_crc_msb
Top bit of the 16-bit CRC register.
@ k_sd_csize_b7_mask
C_SIZE field spans only 6 bits in b7.
@ k_sd_busy
CIPO held low while the card programs.
@ k_sd_csd_len
CSD register length.
@ k_sd_r1_ready
R1, card ready.
@ k_sd_byte_mask
Low-byte mask.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
The modelled card: backing image + command/response framing.
uint8_t cmd[k_sd_cmd_len]
Cmd.
uint32_t resp_pos
Resp pos.
bool ready
ACMD41 has completed.
uint32_t erase_start
CMD32 ERASE_WR_BLK_START block.
bool app_cmd
Previous command was CMD55 (APP_CMD).
uint64_t rd_off
Byte offset of the next streamed CMD18 block.
board_sd_wr_phase_t wr_phase
CMD24/CMD25 write sub-state.
bool wr_multi
Write is CMD25 (multi-block).
bool rd_multi
An open CMD18 read stream.
uint64_t image_len
Image size in bytes (64-bit: cards > 4 GB).
uint32_t resp_len
Resp length.
uint64_t wr_off
Byte offset of the current block.
uint32_t wr_cnt
Bytes seen in the data/CRC phase.
uint8_t resp[k_sd_resp_cap]
Resp.
uint8_t wr_block[k_sd_block]
Bounded block-write staging buffer.
uint32_t erase_end
CMD33 ERASE_WR_BLK_END block.