ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
board_periph_sdhi.c File Reference

Native 4-bit SDHI host-controller model for ra8_emulator (SDHI0). More...

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "board_console.h"
#include "board_periph_block.h"
#include "board_periph_sd.h"
#include "emu_host_io_internal.h"
Include dependency graph for board_periph_sdhi.c:

Go to the source code of this file.

Data Structures

struct  sdhi_state_t
 SDHI model state: register shadow + command + data-phase engine. More...

Enumerations

enum  sdhi_console_t : uint32_t { k_sdhi_console_line_cap = 48U }
 Console-tap line buffer capacity for an SDHI block summary. More...
enum  sdhi_reg_map_t : uint64_t {
  k_sdhi_base = 0x40252000UL ,
  k_sdhi_span = 0x200UL ,
  k_sdhi_off_sd_cmd = 0x000UL ,
  k_sdhi_off_sd_arg = 0x008UL ,
  k_sdhi_off_sd_stop = 0x010UL ,
  k_sdhi_off_sd_seccnt = 0x014UL ,
  k_sdhi_off_sd_rsp10 = 0x018UL ,
  k_sdhi_off_sd_rsp32 = 0x020UL ,
  k_sdhi_off_sd_rsp54 = 0x028UL ,
  k_sdhi_off_sd_rsp76 = 0x030UL ,
  k_sdhi_off_sd_info1 = 0x038UL ,
  k_sdhi_off_sd_info2 = 0x03CUL ,
  k_sdhi_off_sd_option = 0x050UL ,
  k_sdhi_off_sd_buf0 = 0x060UL ,
  k_sdhi_off_soft_rst = 0x1C0UL
}
 SDHI0 register-window geometry + the offsets the model owns. More...
enum  sdhi_status_t : uint32_t {
  k_sdhi_info1_rspend = 0x00000001U ,
  k_sdhi_info2_bre = 0x00000100U ,
  k_sdhi_info2_bwe = 0x00000200U
}
 SD_INFO1 / SD_INFO2 status bits the firmware polls. More...
enum  sdhi_option_bits_t : uint32_t {
  k_sdhi_option_width_bit = 0x00008000U ,
  k_sdhi_option_width8_bit = 0x00002000U ,
  k_sdhi_lanes_1bit = 1U ,
  k_sdhi_lanes_4bit = 4U ,
  k_sdhi_lanes_8bit = 8U
}
 SD_OPTION bus-width selector bits + decoded lane counts. More...
enum  sdhi_cmd_idx_t : uint32_t {
  k_sdhi_cmd0_go_idle = 0U ,
  k_sdhi_cmd2_send_cid = 2U ,
  k_sdhi_cmd3_send_rca = 3U ,
  k_sdhi_cmd7_select = 7U ,
  k_sdhi_cmd8_if_cond = 8U ,
  k_sdhi_cmd9_send_csd = 9U ,
  k_sdhi_cmd12_stop = 12U ,
  k_sdhi_cmd16_blocklen = 16U ,
  k_sdhi_cmd17_read1 = 17U ,
  k_sdhi_cmd18_readm = 18U ,
  k_sdhi_cmd24_write1 = 24U ,
  k_sdhi_cmd25_writem = 25U ,
  k_sdhi_acmd41_op_cond = 41U ,
  k_sdhi_cmd55_app_cmd = 55U
}
 SD command indices the model decodes (index = SD_CMD & 0x3F). More...
enum  sdhi_resp_const_t : uint32_t {
  k_sdhi_cmd_index_mask = 0x0000003FU ,
  k_sdhi_r1_app_cmd = 0x00000020U ,
  k_sdhi_r1_ready = 0x00000900U ,
  k_sdhi_r7_if_cond = 0x000001AAU ,
  k_sdhi_ocr_ready = 0xC0FF8000U ,
  k_sdhi_cid_word = 0x52413844U ,
  k_sdhi_rca_value = 0x00010000U ,
  k_sdhi_csd_v2_struct = 0x40000000U ,
  k_sdhi_csize_lo_mask = 0x0000003FU ,
  k_sdhi_csize_mid_mask = 0x0000FFFFU
}
 Canned response field values the firmware accepts. More...
enum  sdhi_geom_t : uint32_t {
  k_sdhi_words = 128U ,
  k_sdhi_block_bytes = 512U ,
  k_sdhi_words_per_blk = 128U ,
  k_sdhi_byte_bits = 8U ,
  k_sdhi_byte_mask = 0xFFU ,
  k_sdhi_csize_unit = 1024U ,
  k_sdhi_csize_shift = 16U
}
 Geometry / sizing constants (no magic numbers). More...
enum  sdhi_order_t : uint32_t { k_sdhi_block_order = 96U }
 End-of-run report-order slot (after the XSPI block at 95). More...
enum  sdhi_xfer_t : uint8_t {
  k_sdhi_xfer_none = 0U ,
  k_sdhi_xfer_read = 1U ,
  k_sdhi_xfer_write = 2U
}
 Block-transfer phase the model is mid-way through. More...

Functions

static RA8_INTERNAL uint32_t internal_sdhi_word (uint64_t off)
 Word index of register at byte offset off inside the shadow.
static RA8_INTERNAL void internal_sdhi_publish_response (void)
 Copy the latched response words into the SD_RSP* shadow registers.
static RA8_INTERNAL void internal_sdhi_make_csd (void)
 Encode the attached card's capacity into a CSD v2 response (CMD9).
static RA8_INTERNAL void internal_sdhi_load_block (void)
 Load the block at the current LBA into the staging buffer (read phase).
static RA8_INTERNAL void internal_sdhi_begin_read (bool multi)
 Arm a read data phase for CMD17 (single) or CMD18 (multi).
static RA8_INTERNAL void internal_sdhi_begin_write (bool multi)
 Arm a write data phase for CMD24 (single) or CMD25 (multi).
static RA8_INTERNAL void internal_sdhi_exec_ident (uint32_t idx, uint32_t arg)
 Decode the identification + addressing commands into a response.
static RA8_INTERNAL void internal_sdhi_exec_command (uint32_t cmd)
 Execute the latched command, build its response, raise RSPEND.
static RA8_INTERNAL uint32_t internal_sdhi_buf_read (void)
 Serve one 32-bit FIFO word from the staging buffer (read phase).
static RA8_INTERNAL void internal_sdhi_buf_write (uint32_t word)
 Capture one 32-bit FIFO word into the staging buffer (write phase).
static RA8_INTERNAL uint64_t internal_sdhi_read (uc_engine *uc, uint64_t addr, unsigned size)
 MMIO read inside the SDHI window (SD_BUF0 is a live FIFO).
static RA8_INTERNAL void internal_sdhi_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
 MMIO write inside the SDHI window (SD_CMD issues; SD_BUF0 captures).
static RA8_INTERNAL void internal_sdhi_reset (void)
 Reset the SDHI model: zero the shadow + command/data-phase engine.
static RA8_INTERNAL uint32_t internal_sdhi_bus_lanes (void)
 Decode the SD_OPTION shadow into the host bus-width lane count.
static RA8_INTERNAL void internal_sdhi_report (void)
 End-of-run SDHI section: block I/O counts (only if the bus was used).
static RA8_INTERNAL void internal_sdhi_block_register (void)
 Register the SDHI block before main (host constructor).

Variables

static sdhi_state_t s_sdhi
static const board_periph_block_t s_k_sdhi_block
 SDHI0 block descriptor (self-registered with the core).

Detailed Description

Native 4-bit SDHI host-controller model for ra8_emulator (SDHI0).

Models the RA8D2 SDHI0 host controller (ra8_sdhi_regs.h, ra8_sdhi.c, ra8_sdcard.c) at 0x40252000 just enough that the firmware's real native-SD path runs headless: the SD Physical Layer identification (CMD0 -> CMD8 -> ACMD41 -> CMD2 -> CMD3 -> CMD9 -> CMD7) plus the polled 512-byte block read / write over the SD_BUF0 FIFO. Without it the identification sequence times out (no SD_INFO1.RSPEND) so any native-SDHI app parks at "card init".

The model keeps a register shadow (read returns the shadow except for the live RSPEND / BRE / BWE status bits it computes) plus a tiny command engine:

  • A SD_CMD write latches the command (index = SD_CMD & 0x3F) and the pending SD_ARG, executes it, drops a response into SD_RSP10/32/54/76, and SETS SD_INFO1.RSPEND (bit 0) so ra8_sdhi_send_command's poll exits.
  • CMD17/18 arm a read data phase; CMD24/25 arm a write data phase. Each SD_BUF0 access serves / captures one 32-bit word of a 512-byte block; after 128 words a multi-block transfer advances to the next LBA and keeps the BRE / BWE flag set, else clears it.

The SD image is shared with board_periph_sd.c (the same --sd / --sd-new card): block I/O calls board_sd_read_block / board_sd_write_block, and the CMD9 CSD encodes the card's real capacity via board_sd_info.

Window geometry is deliberately narrow – only SDHI0's own 0x200-byte register page is claimed (SDHI registers are SDHI-only, so no clock-setup register that ra8_cgc_init polls is intercepted).

Since
0.1.0

Definition in file board_periph_sdhi.c.

Enumeration Type Documentation

◆ sdhi_cmd_idx_t

enum sdhi_cmd_idx_t : uint32_t

SD command indices the model decodes (index = SD_CMD & 0x3F).

Enumerator
k_sdhi_cmd0_go_idle 

CMD0 GO_IDLE_STATE.

k_sdhi_cmd2_send_cid 

CMD2 ALL_SEND_CID (R2).

k_sdhi_cmd3_send_rca 

CMD3 SEND_RELATIVE_ADDR.

k_sdhi_cmd7_select 

CMD7 SELECT_CARD.

k_sdhi_cmd8_if_cond 

CMD8 SEND_IF_COND (R7).

k_sdhi_cmd9_send_csd 

CMD9 SEND_CSD (R2).

k_sdhi_cmd12_stop 

CMD12 STOP_TRANSMISSION.

k_sdhi_cmd16_blocklen 

CMD16 SET_BLOCKLEN.

k_sdhi_cmd17_read1 

CMD17 READ_SINGLE_BLOCK.

k_sdhi_cmd18_readm 

CMD18 READ_MULTIPLE_BLOCK.

k_sdhi_cmd24_write1 

CMD24 WRITE_SINGLE_BLOCK.

k_sdhi_cmd25_writem 

CMD25 WRITE_MULTIPLE_BLOCK.

k_sdhi_acmd41_op_cond 

ACMD41 SD_SEND_OP_COND.

k_sdhi_cmd55_app_cmd 

CMD55 APP_CMD prefix.

Definition at line 88 of file board_periph_sdhi.c.

◆ sdhi_console_t

enum sdhi_console_t : uint32_t

Console-tap line buffer capacity for an SDHI block summary.

Enumerator
k_sdhi_console_line_cap 

Max chars in an "SD rd lba=.." line.

Definition at line 48 of file board_periph_sdhi.c.

◆ sdhi_geom_t

enum sdhi_geom_t : uint32_t

Geometry / sizing constants (no magic numbers).

Enumerator
k_sdhi_words 

0x200-byte window as 32-bit words.

k_sdhi_block_bytes 

SD block size in bytes.

k_sdhi_words_per_blk 

512 / 4 = 128 FIFO words per block.

k_sdhi_byte_bits 

Bits per byte.

k_sdhi_byte_mask 

One byte.

k_sdhi_csize_unit 

CSD v2: blocks per (C_SIZE+1) unit.

k_sdhi_csize_shift 

C_SIZE high-half shift.

Definition at line 120 of file board_periph_sdhi.c.

◆ sdhi_option_bits_t

enum sdhi_option_bits_t : uint32_t

SD_OPTION bus-width selector bits + decoded lane counts.

Enumerator
k_sdhi_option_width_bit 

SD_OPTION.WIDTH bit 15: 1 -> 1-bit.

k_sdhi_option_width8_bit 

SD_OPTION.WIDTH8 bit 13: 1 -> 8-bit.

k_sdhi_lanes_1bit 

Single data lane.

k_sdhi_lanes_4bit 

Four data lanes.

k_sdhi_lanes_8bit 

Eight data lanes.

Definition at line 79 of file board_periph_sdhi.c.

◆ sdhi_order_t

enum sdhi_order_t : uint32_t

End-of-run report-order slot (after the XSPI block at 95).

Enumerator
k_sdhi_block_order 

Report ordering only.

Definition at line 131 of file board_periph_sdhi.c.

◆ sdhi_reg_map_t

enum sdhi_reg_map_t : uint64_t

SDHI0 register-window geometry + the offsets the model owns.

Enumerator
k_sdhi_base 

SDHI0 register window base.

k_sdhi_span 

Narrow window: SD_CMD..SOFT_RST.

k_sdhi_off_sd_cmd 

SD_CMD : command type / issue.

k_sdhi_off_sd_arg 

SD_ARG : command argument.

k_sdhi_off_sd_stop 

SD_STOP : data stop.

k_sdhi_off_sd_seccnt 

SD_SECCNT : multi-block count.

k_sdhi_off_sd_rsp10 

SD_RSP10 : response word 0.

k_sdhi_off_sd_rsp32 

SD_RSP32 : response word 1.

k_sdhi_off_sd_rsp54 

SD_RSP54 : response word 2.

k_sdhi_off_sd_rsp76 

SD_RSP76 : response word 3.

k_sdhi_off_sd_info1 

SD_INFO1 : interrupt flag 1.

k_sdhi_off_sd_info2 

SD_INFO2 : interrupt flag 2.

k_sdhi_off_sd_option 

SD_OPTION : bus width + timeout.

k_sdhi_off_sd_buf0 

SD_BUF0 : 32-bit FIFO word.

k_sdhi_off_soft_rst 

SOFT_RST : software reset.

Definition at line 53 of file board_periph_sdhi.c.

◆ sdhi_resp_const_t

enum sdhi_resp_const_t : uint32_t

Canned response field values the firmware accepts.

Enumerator
k_sdhi_cmd_index_mask 

Low 6 bits of SD_CMD = index.

k_sdhi_r1_app_cmd 

R1 bit 5 APP_CMD (CMD55 ack).

k_sdhi_r1_ready 

R1: TRAN state + ready-for-data.

k_sdhi_r7_if_cond 

CMD8 R7: voltage 0x1 + echo 0xAA.

k_sdhi_ocr_ready 

ACMD41 R3: busy=1, CCS=1, volt win.

k_sdhi_cid_word 

Dummy CID fill ("RA8D" packed).

k_sdhi_rca_value 

CMD3 R6: RCA = 1 in bits [31:16].

k_sdhi_csd_v2_struct 

CSD v2 structure tag in rsp[3].

k_sdhi_csize_lo_mask 

C_SIZE[21:16] field width.

k_sdhi_csize_mid_mask 

C_SIZE[15:0] field width.

Definition at line 106 of file board_periph_sdhi.c.

◆ sdhi_status_t

enum sdhi_status_t : uint32_t

SD_INFO1 / SD_INFO2 status bits the firmware polls.

Enumerator
k_sdhi_info1_rspend 

SD_INFO1.RSPEND (response received).

k_sdhi_info2_bre 

SD_INFO2.BRE (read buffer ready).

k_sdhi_info2_bwe 

SD_INFO2.BWE (write buffer space).

Definition at line 72 of file board_periph_sdhi.c.

◆ sdhi_xfer_t

enum sdhi_xfer_t : uint8_t

Block-transfer phase the model is mid-way through.

Enumerator
k_sdhi_xfer_none 

No data phase in flight.

k_sdhi_xfer_read 

CMD17/18 read data phase.

k_sdhi_xfer_write 

CMD24/25 write data phase.

Definition at line 136 of file board_periph_sdhi.c.

Function Documentation

◆ internal_sdhi_begin_read()

RA8_INTERNAL void internal_sdhi_begin_read ( bool multi)
static

Arm a read data phase for CMD17 (single) or CMD18 (multi).

Arm a read data phase for cmd17 (single) or cmd18 (multi); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Parameters
[in]multiMulti input used by the operation.
Precondition
Arguments satisfy the ranges documented for SDHI begin read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 238 of file board_periph_sdhi.c.

References board_console_push(), internal_sdhi_load_block(), internal_sdhi_word(), k_board_console_ch_sd, k_sdhi_console_line_cap, k_sdhi_off_sd_seccnt, k_sdhi_xfer_read, RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_exec_command().

◆ internal_sdhi_begin_write()

RA8_INTERNAL void internal_sdhi_begin_write ( bool multi)
static

Arm a write data phase for CMD24 (single) or CMD25 (multi).

Arm a write data phase for cmd24 (single) or cmd25 (multi); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Parameters
[in]multiMulti input used by the operation.
Precondition
Arguments satisfy the ranges documented for SDHI begin write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 265 of file board_periph_sdhi.c.

References board_console_push(), internal_sdhi_word(), k_board_console_ch_sd, k_sdhi_console_line_cap, k_sdhi_info2_bwe, k_sdhi_off_sd_info2, k_sdhi_off_sd_seccnt, k_sdhi_xfer_write, memset(), RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_exec_command().

◆ internal_sdhi_block_register()

RA8_INTERNAL void internal_sdhi_block_register ( void )
static

Register the SDHI block before main (host constructor).

Definition at line 597 of file board_periph_sdhi.c.

References board_periph_register_block(), RA8_INTERNAL, and s_k_sdhi_block.

◆ internal_sdhi_buf_read()

RA8_INTERNAL uint32_t internal_sdhi_buf_read ( void )
static

Serve one 32-bit FIFO word from the staging buffer (read phase).

Serve one 32-bit fifo word from the staging buffer (read phase); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Returns
The SDHI buf read result produced by the board periph SDHI model.
Return values
valueThe operation-specific SDHI buf read value.
Precondition
Arguments satisfy the ranges documented for SDHI buf read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 391 of file board_periph_sdhi.c.

References internal_sdhi_load_block(), internal_sdhi_word(), k_sdhi_byte_bits, k_sdhi_info2_bre, k_sdhi_off_sd_info2, k_sdhi_words_per_blk, k_sdhi_xfer_none, k_sdhi_xfer_read, RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_read().

◆ internal_sdhi_buf_write()

RA8_INTERNAL void internal_sdhi_buf_write ( uint32_t word)
static

Capture one 32-bit FIFO word into the staging buffer (write phase).

Capture one 32-bit fifo word into the staging buffer (write phase); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Parameters
[in]wordInstruction or register word processed by the operation.
Precondition
Arguments satisfy the ranges documented for SDHI buf write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 429 of file board_periph_sdhi.c.

References board_sd_write_block(), internal_sdhi_word(), k_sdhi_byte_bits, k_sdhi_byte_mask, k_sdhi_info2_bwe, k_sdhi_off_sd_info2, k_sdhi_words_per_blk, k_sdhi_xfer_none, k_sdhi_xfer_write, RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_write().

◆ internal_sdhi_bus_lanes()

RA8_INTERNAL uint32_t internal_sdhi_bus_lanes ( void )
static

Decode the SD_OPTION shadow into the host bus-width lane count.

Decode the sd_option shadow into the host bus-width lane count; this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Returns
The SDHI bus lanes result produced by the board periph SDHI model.
Return values
valueThe operation-specific SDHI bus lanes value.
Precondition
Arguments satisfy the ranges documented for SDHI bus lanes.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 552 of file board_periph_sdhi.c.

References internal_sdhi_word(), k_sdhi_lanes_1bit, k_sdhi_lanes_4bit, k_sdhi_lanes_8bit, k_sdhi_off_sd_option, k_sdhi_option_width8_bit, k_sdhi_option_width_bit, RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_report().

◆ internal_sdhi_exec_command()

RA8_INTERNAL void internal_sdhi_exec_command ( uint32_t cmd)
static

Execute the latched command, build its response, raise RSPEND.

Execute the latched command, build its response, raise rspend; this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Parameters
[in]cmdCmd input used by the operation.
Precondition
Arguments satisfy the ranges documented for SDHI exec command.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 339 of file board_periph_sdhi.c.

References internal_sdhi_begin_read(), internal_sdhi_begin_write(), internal_sdhi_exec_ident(), internal_sdhi_publish_response(), internal_sdhi_word(), k_sdhi_cmd12_stop, k_sdhi_cmd17_read1, k_sdhi_cmd18_readm, k_sdhi_cmd24_write1, k_sdhi_cmd25_writem, k_sdhi_cmd55_app_cmd, k_sdhi_cmd_index_mask, k_sdhi_info1_rspend, k_sdhi_off_sd_arg, k_sdhi_off_sd_info1, k_sdhi_r1_ready, k_sdhi_xfer_none, RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_write().

◆ internal_sdhi_exec_ident()

RA8_INTERNAL void internal_sdhi_exec_ident ( uint32_t idx,
uint32_t arg )
static

Decode the identification + addressing commands into a response.

Decode the identification + addressing commands into a response; this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Parameters
[in]idxBounded index of the selected entry.
[in]argArg input used by the operation.
Precondition
Arguments satisfy the ranges documented for SDHI exec ident.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 295 of file board_periph_sdhi.c.

References internal_sdhi_make_csd(), k_sdhi_acmd41_op_cond, k_sdhi_cid_word, k_sdhi_cmd2_send_cid, k_sdhi_cmd3_send_rca, k_sdhi_cmd55_app_cmd, k_sdhi_cmd8_if_cond, k_sdhi_cmd9_send_csd, k_sdhi_ocr_ready, k_sdhi_r1_app_cmd, k_sdhi_r1_ready, k_sdhi_r7_if_cond, k_sdhi_rca_value, RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_exec_command().

◆ internal_sdhi_load_block()

RA8_INTERNAL void internal_sdhi_load_block ( void )
static

Load the block at the current LBA into the staging buffer (read phase).

Load the block at the current lba into the staging buffer (read phase); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for SDHI load block.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 221 of file board_periph_sdhi.c.

References board_sd_read_block(), internal_sdhi_word(), k_sdhi_info2_bre, k_sdhi_off_sd_info2, memset(), RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_begin_read(), and internal_sdhi_buf_read().

◆ internal_sdhi_make_csd()

RA8_INTERNAL void internal_sdhi_make_csd ( void )
static

Encode the attached card's capacity into a CSD v2 response (CMD9).

Encode the attached card's capacity into a csd v2 response (cmd9); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for SDHI make csd.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 198 of file board_periph_sdhi.c.

References board_sd_info(), k_sdhi_block_bytes, k_sdhi_csd_v2_struct, k_sdhi_csize_lo_mask, k_sdhi_csize_mid_mask, k_sdhi_csize_shift, k_sdhi_csize_unit, RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_exec_ident().

◆ internal_sdhi_publish_response()

RA8_INTERNAL void internal_sdhi_publish_response ( void )
static

Copy the latched response words into the SD_RSP* shadow registers.

Copy the latched response words into the sd_rsp; this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for SDHI publish response.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 182 of file board_periph_sdhi.c.

References internal_sdhi_word(), k_sdhi_off_sd_rsp10, k_sdhi_off_sd_rsp32, k_sdhi_off_sd_rsp54, k_sdhi_off_sd_rsp76, RA8_INTERNAL, and s_sdhi.

Referenced by internal_sdhi_exec_command().

◆ internal_sdhi_read()

RA8_INTERNAL uint64_t internal_sdhi_read ( uc_engine * uc,
uint64_t addr,
unsigned size )
static

MMIO read inside the SDHI window (SD_BUF0 is a live FIFO).

MMIO read inside the sdhi window (sd_buf0 is a live fifo); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
Returns
The SDHI read result produced by the board periph SDHI model.
Return values
valueThe operation-specific SDHI read value.
Precondition
Arguments satisfy the ranges documented for SDHI read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 474 of file board_periph_sdhi.c.

References internal_sdhi_buf_read(), internal_sdhi_word(), k_sdhi_base, k_sdhi_off_sd_buf0, k_sdhi_words, RA8_INTERNAL, and s_sdhi.

◆ internal_sdhi_report()

RA8_INTERNAL void internal_sdhi_report ( void )
static

End-of-run SDHI section: block I/O counts (only if the bus was used).

End-of-run sdhi section: block i/o counts (only if the bus was used); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for SDHI report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 572 of file board_periph_sdhi.c.

References internal_sdhi_bus_lanes(), priv_emu_io_errf(), RA8_INTERNAL, and s_sdhi.

◆ internal_sdhi_reset()

RA8_INTERNAL void internal_sdhi_reset ( void )
static

Reset the SDHI model: zero the shadow + command/data-phase engine.

Reset the sdhi model: zero the shadow + command/data-phase engine; this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for SDHI reset.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 537 of file board_periph_sdhi.c.

References memset(), RA8_INTERNAL, and s_sdhi.

◆ internal_sdhi_word()

RA8_INTERNAL uint32_t internal_sdhi_word ( uint64_t off)
static

Word index of register at byte offset off inside the shadow.

Word index of register at byte offset off inside the shadow; this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Parameters
[in]offRegister or byte offset addressed by the operation.
Returns
The SDHI word result produced by the board periph SDHI model.
Return values
valueThe operation-specific SDHI word value.
Precondition
Arguments satisfy the ranges documented for SDHI word.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 169 of file board_periph_sdhi.c.

References RA8_INTERNAL.

Referenced by internal_sdhi_begin_read(), internal_sdhi_begin_write(), internal_sdhi_buf_read(), internal_sdhi_buf_write(), internal_sdhi_bus_lanes(), internal_sdhi_exec_command(), internal_sdhi_load_block(), internal_sdhi_publish_response(), internal_sdhi_read(), and internal_sdhi_write().

◆ internal_sdhi_write()

RA8_INTERNAL void internal_sdhi_write ( uc_engine * uc,
uint64_t addr,
unsigned size,
uint64_t value )
static

MMIO write inside the SDHI window (SD_CMD issues; SD_BUF0 captures).

MMIO write inside the sdhi window (sd_cmd issues; sd_buf0 captures); this step is contained within the board periph SDHI model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
[in]valueRegister or payload value involved in the operation.
Precondition
Arguments satisfy the ranges documented for SDHI write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph SDHI model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 501 of file board_periph_sdhi.c.

References internal_sdhi_buf_write(), internal_sdhi_exec_command(), internal_sdhi_word(), k_sdhi_base, k_sdhi_off_sd_buf0, k_sdhi_off_sd_cmd, k_sdhi_off_sd_info1, k_sdhi_off_sd_info2, k_sdhi_off_soft_rst, k_sdhi_words, k_sdhi_xfer_none, and s_sdhi.

Variable Documentation

◆ s_k_sdhi_block

const board_periph_block_t s_k_sdhi_block
static
Initial value:
= {
.base = (uint32_t)k_sdhi_base,
.span = (uint32_t)k_sdhi_span,
.order = (uint32_t)k_sdhi_block_order,
.tick = nullptr,
.name = "SDHI",
}
@ k_sdhi_block_order
Report ordering only.
@ k_sdhi_span
Narrow window: SD_CMD..SOFT_RST.
@ k_sdhi_base
SDHI0 register window base.
static RA8_INTERNAL void internal_sdhi_reset(void)
Reset the SDHI model: zero the shadow + command/data-phase engine.
static RA8_INTERNAL void internal_sdhi_report(void)
End-of-run SDHI section: block I/O counts (only if the bus was used).
-proof
static ra8_err_t internal_sdhi_write(void *ctx, uint32_t lba, uint32_t count, const uint8_t *buf)
Native-SDHI backend: write count blocks from buf at lba.
static ra8_err_t internal_sdhi_read(void *ctx, uint32_t lba, uint32_t count, uint8_t *buf)
Native-SDHI backend: read count blocks at lba into buf.

SDHI0 block descriptor (self-registered with the core).

Definition at line 584 of file board_periph_sdhi.c.

Referenced by internal_sdhi_block_register().

◆ s_sdhi