|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
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"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). | |
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:
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.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).
Definition in file board_periph_sdhi.c.
| enum sdhi_cmd_idx_t : uint32_t |
SD command indices the model decodes (index = SD_CMD & 0x3F).
Definition at line 88 of file board_periph_sdhi.c.
| 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.
| enum sdhi_geom_t : uint32_t |
Geometry / sizing constants (no magic numbers).
Definition at line 120 of file board_periph_sdhi.c.
| enum sdhi_option_bits_t : uint32_t |
SD_OPTION bus-width selector bits + decoded lane counts.
Definition at line 79 of file board_periph_sdhi.c.
| 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.
| enum sdhi_reg_map_t : uint64_t |
SDHI0 register-window geometry + the offsets the model owns.
Definition at line 53 of file board_periph_sdhi.c.
| enum sdhi_resp_const_t : uint32_t |
Canned response field values the firmware accepts.
Definition at line 106 of file board_periph_sdhi.c.
| 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.
| 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.
|
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.
| [in] | multi | Multi input used by the operation. |
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().
|
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.
| [in] | multi | Multi input used by the operation. |
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().
|
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.
|
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.
| value | The operation-specific SDHI buf read value. |
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().
|
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.
| [in] | word | Instruction or register word processed by the operation. |
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().
|
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.
| value | The operation-specific SDHI bus lanes value. |
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().
|
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.
| [in] | cmd | Cmd input used by the operation. |
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().
|
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.
| [in] | idx | Bounded index of the selected entry. |
| [in] | arg | Arg input used by the operation. |
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().
|
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.
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().
|
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.
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().
|
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.
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().
|
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.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | addr | Guest address involved in the operation. |
| [in] | size | Size of the requested region or access in bytes. |
| value | The operation-specific SDHI read value. |
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.
|
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.
Definition at line 572 of file board_periph_sdhi.c.
References internal_sdhi_bus_lanes(), priv_emu_io_errf(), RA8_INTERNAL, and s_sdhi.
|
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.
Definition at line 537 of file board_periph_sdhi.c.
References memset(), RA8_INTERNAL, and s_sdhi.
|
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.
| [in] | off | Register or byte offset addressed by the operation. |
| value | The operation-specific SDHI word value. |
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().
|
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.
| [in,out] | uc | Unicorn engine whose emulated state is read or updated. |
| [in] | addr | Guest address involved in the operation. |
| [in] | size | Size of the requested region or access in bytes. |
| [in] | value | Register or payload value involved in the operation. |
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.
|
static |
SDHI0 block descriptor (self-registered with the core).
Definition at line 584 of file board_periph_sdhi.c.
Referenced by internal_sdhi_block_register().
|
static |
Definition at line 156 of file board_periph_sdhi.c.
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_exec_ident(), internal_sdhi_load_block(), internal_sdhi_make_csd(), internal_sdhi_publish_response(), internal_sdhi_read(), internal_sdhi_report(), internal_sdhi_reset(), and internal_sdhi_write().