|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Host-side step routines + console formatters for the writable-OSPI self-loop. More...
#include "usb_selftest_ospi_rw_steps.h"#include <stdint.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_err.h"#include "ra8_usb_hmsc.h"#include "tx_api.h"#include "ux_api.h"Go to the source code of this file.
Functions | |
| static void | ospirw_pattern_fill (uint32_t lun, uint32_t lba, UCHAR *out) |
| Fill one 512-byte sector with this LUN/LBA's deterministic bytes. | |
| static uint8_t | ospirw_nibble_to_hex (uint32_t nibble) |
| Format one nibble (0..15) into an uppercase hex character. | |
| static uint32_t | ospirw_str_len (const char *text) |
| Bounded ASCII string length (cap k_ospirw_print_cap). | |
| static ra8_err_t | ospirw_sci_write (const uint8_t *data, uint32_t len) |
| Push a literal block over the BSP UART console (SCI8) polled. | |
| static ra8_err_t | ospirw_print (const char *text) |
| Print a NUL-terminated ASCII string over the console. | |
| static ra8_err_t | ospirw_print_dec (uint32_t value) |
| Print a uint32_t as ASCII decimal. | |
| static ra8_err_t | ospirw_print_hex (uint32_t value, uint8_t digits) |
| Print a value as fixed-width uppercase hex. | |
| static ra8_err_t | ospirw_print_fail (const char *what, ra8_err_t err) |
| Print "FAIL <what> err=0xNNNNNNNN" on its own line. | |
| static ra8_err_t | ospirw_write_disk (uint32_t lun) |
| WRITE(10) the per-LBA pattern across the whole OSPI window. | |
| static ra8_err_t | ospirw_verify_one (uint32_t lun) |
| Read + verify one LUN's full sector range against its pattern. | |
| static ra8_err_t | ospirw_print_lun_ok (uint32_t lun) |
| Print "LUN n OK" for the verified writable unit. | |
| static ra8_err_t | ospirw_host_enumerate (ra8_usb_hmsc_device_t *device) |
| Enumerate the looped device and print its PID + GET_MAX_LUN. | |
| static ra8_err_t | ospirw_host_pass (void) |
| One full host-side pass: enumerate, WRITE(10) then verify. | |
| VOID | ospirw_host_worker (ULONG arg) |
| Host-side worker: retry the full pass until it succeeds. | |
Variables | |
| static volatile uint32_t | s_dbg_phase |
| Host-ladder phase marker (ospirw_phase_t). | |
| static volatile uint32_t | s_dbg_luns_ok |
| Sectors that read back correctly after the write pass. | |
| static volatile uint32_t | s_dbg_max_lun |
| Device-reported GET_MAX_LUN value (expect 0, single LUN). | |
| static volatile uint32_t | s_dbg_mismatch = (uint32_t)k_ospirw_no_mismatch |
| First mismatching sector, or k_ospirw_no_mismatch. | |
| static volatile uint32_t | s_dbg_pass_count |
| Completed full passes (sticky success counter). | |
Host-side step routines + console formatters for the writable-OSPI self-loop.
The host-side half of the usb_selftest_ospi_rw application, split out of main.c so each translation unit stays below the 1000-line file-size cap. It carries:
Only ospirw_host_worker is externally visible; tx_application_define in main.c spawns it. Everything else here is file-private. The J-Link debug probes touched solely by this side (s_dbg_phase ... s_dbg_pass_count) live here too; the device-side probes stay in main.c.
Definition in file usb_selftest_ospi_rw_steps.c.
|
staticnodiscard |
Enumerate the looped device and print its PID + GET_MAX_LUN.
Sets the enum phase, runs ra8_usb_hmsc_enumerate, records the reported max-LUN in s_dbg_max_lun, and streams the enumerated pid=... GET_MAX_LUN=... banner. On enumerate failure the host controller is closed so the next retry re-attaches clean.
| [out] | device | Receives the enumerated descriptor snapshot. |
| k_ra8_ok | Device enumerated and the banner printed. |
device is non-null. Definition at line 470 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_hex_chars_u16, k_ospirw_phase_enum, k_ra8_ok, ra8_usb_hmsc_device_t::max_lun, ospirw_print(), ospirw_print_dec(), ospirw_print_fail(), ospirw_print_hex(), ra8_usb_hmsc_device_t::product_id, ra8_usb_hmsc_close(), ra8_usb_hmsc_enumerate(), s_dbg_max_lun, and s_dbg_phase.
Referenced by ospirw_host_pass().
|
staticnodiscard |
One full host-side pass: enumerate, WRITE(10) then verify.
Phases mirror ospirw_phase_t. On any failure the host controller is closed so the next retry starts from a clean attach.
| k_ra8_ok | The pass printed WRITABLE-OSPI PASS. |
Definition at line 516 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_count, k_ospirw_phase_init, k_ospirw_phase_pass, k_ospirw_phase_verify, k_ra8_board_led2, k_ra8_ok, k_ra8_usb_speed_hs, ospirw_host_enumerate(), ospirw_print(), ospirw_print_fail(), ospirw_print_lun_ok(), ospirw_verify_one(), ospirw_write_disk(), ra8_board_led_on(), ra8_usb_hmsc_close(), ra8_usb_hmsc_init(), s_dbg_luns_ok, s_dbg_pass_count, and s_dbg_phase.
Referenced by ospirw_host_worker().
| VOID ospirw_host_worker | ( | ULONG | arg | ) |
Host-side worker: retry the full pass until it succeeds.
Waits for the device side to attach, then loops the full host pass (enumerate + WRITE(10) + read-verify) with a retry pause until the writable LUN verifies; afterwards parks so the verdict stays on the wire. Spawned by tx_application_define in main.c; the body and all of its helpers live in usb_selftest_ospi_rw_steps.c.
| [in] | arg | ThreadX entry argument (unused). |
Definition at line 565 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_boot_wait_ticks, k_ospirw_idle_ticks, k_ospirw_retry_ticks, k_ra8_ok, ospirw_host_pass(), and tx_thread_sleep.
Referenced by tx_application_define().
|
static |
Format one nibble (0..15) into an uppercase hex character.
Standard '0'-'9' then 'A'-'F' mapping.
| [in] | nibble | 4-bit value. |
| '0' | For a zero nibble. |
Definition at line 118 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_hex_digit_split.
Referenced by ospirw_print_hex().
|
static |
Fill one 512-byte sector with this LUN/LBA's deterministic bytes.
Byte i = (lun*97 + lba*7 + i + 0x5A) & 0xFF. Distinct per LUN and per LBA so the host can prove it addressed the right logical unit and sector. The device media-read and the host verifier compute it identically.
| [in] | lun | The logical unit (0..1). |
| [in] | lba | The logical block address within the LUN. |
| [out] | out | 512-byte destination buffer. |
out has k_ospirw_block_size writable bytes. lun and lba are within the exposed geometry. out holds the sector's pattern bytes. Definition at line 87 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_block_size, k_ospirw_byte_mask, k_ospirw_pat_bias, k_ospirw_pat_lba_mul, and k_ospirw_pat_lun_mul.
Referenced by ospirw_verify_one(), and ospirw_write_disk().
|
staticnodiscard |
Print a NUL-terminated ASCII string over the console.
Length-bounded by ospirw_str_len.
| [in] | text | String to print (CR/LF included by the caller). |
| k_ra8_ok | All bytes queued. |
text is non-NULL. text is NUL-terminated within k_ospirw_print_cap bytes. Definition at line 198 of file usb_selftest_ospi_rw_steps.c.
References ospirw_sci_write(), and ospirw_str_len().
Referenced by ospirw_host_enumerate(), ospirw_host_pass(), ospirw_print_fail(), and ospirw_print_lun_ok().
|
staticnodiscard |
Print a uint32_t as ASCII decimal.
Digit-reversal into a bounded scratch buffer.
| [in] | value | Value to print. |
| k_ra8_ok | All bytes queued. |
Definition at line 221 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_dec_chars_u32, k_ospirw_dec_radix, and ospirw_sci_write().
Referenced by ospirw_host_enumerate(), and ospirw_print_lun_ok().
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
One-line diagnostic; first failing chunk's code returned.
| [in] | what | Short description of the failed step. |
| [in] | err | Error code returned by the step. |
| k_ra8_ok | The diagnostic line is queued. |
what is NUL-terminated within the print cap. Definition at line 297 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_hex_chars_u32, k_ra8_ok, ospirw_print(), and ospirw_print_hex().
Referenced by ospirw_host_enumerate(), ospirw_host_pass(), ospirw_verify_one(), and ospirw_write_disk().
|
staticnodiscard |
Print a value as fixed-width uppercase hex.
Width is clamped to 8 hex digits.
| [in] | value | Value to print. |
| [in] | digits | Hex digit count (4 for u16, 8 for u32). |
| k_ra8_ok | All bytes queued. |
digits is at most k_ospirw_hex_chars_u32. Definition at line 264 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_hex_chars_u32, k_ospirw_nibble_bits, k_ospirw_nibble_mask, ospirw_nibble_to_hex(), and ospirw_sci_write().
Referenced by ospirw_host_enumerate(), and ospirw_print_fail().
|
staticnodiscard |
Print "LUN n OK" for the verified writable unit.
| [in] | lun | The LUN that just verified. |
| k_ra8_ok | The line is queued. |
lun. Definition at line 436 of file usb_selftest_ospi_rw_steps.c.
References k_ra8_ok, ospirw_print(), and ospirw_print_dec().
Referenced by ospirw_host_pass().
|
staticnodiscard |
Push a literal block over the BSP UART console (SCI8) polled.
Thin wrapper fixing the console channel.
| [in] | data | Buffer to send. |
| [in] | len | Byte count. |
| k_ra8_ok | All bytes queued. |
data is non-NULL; the BSP console init already ran. len excludes any NUL terminator. Definition at line 175 of file usb_selftest_ospi_rw_steps.c.
References ra8_board_uart_console_write().
Referenced by ospirw_print(), ospirw_print_dec(), and ospirw_print_hex().
|
static |
Bounded ASCII string length (cap k_ospirw_print_cap).
Linear scan with a hard upper bound.
| [in] | text | NUL-terminated string. |
| 0 | For an empty string. |
text is non-NULL. text points to readable storage of at least the length. Definition at line 144 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_print_cap.
Referenced by ospirw_print().
|
staticnodiscard |
Read + verify one LUN's full sector range against its pattern.
READ_CAPACITY (must report k_ospirw_sectors), then a raw multi-block READ(10) sweep in 8-block bursts, checking each sector against ospirw_pattern_fill for this lun.
| [in] | lun | Logical unit to verify (0..1). |
| k_ra8_ok | The whole LUN matched its pattern. |
| k_ra8_err_invalid_size | READ_CAPACITY reported wrong geometry. |
| k_ra8_err_invalid_state | A byte differed from the pattern. |
lun is below k_ospirw_count. Definition at line 384 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_block_size, k_ospirw_burst_blocks, k_ospirw_burst_bytes, k_ospirw_mismatch_lun_shift, k_ospirw_sectors, k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_ok, memcmp(), ospirw_pattern_fill(), ospirw_print_fail(), ra8_usb_hmsc_read10(), ra8_usb_hmsc_read_capacity(), and s_dbg_mismatch.
Referenced by ospirw_host_pass().
|
staticnodiscard |
WRITE(10) the per-LBA pattern across the whole OSPI window.
Fills an 8-block burst from ospirw_pattern_fill and pushes it with raw ra8_usb_hmsc_write10 until every sector is written. This is the host data-OUT phase that drives the device bulk-OUT receive path (the gating mechanism for every writable / repeated-bulk matrix item).
| [in] | lun | Logical unit to write (0). |
| k_ra8_ok | The whole window was written. |
| k_ra8_err_hw_timeout | A WRITE(10) data-OUT phase did not complete. |
Definition at line 344 of file usb_selftest_ospi_rw_steps.c.
References k_ospirw_block_size, k_ospirw_burst_blocks, k_ospirw_burst_bytes, k_ospirw_sectors, k_ra8_ok, ospirw_pattern_fill(), ospirw_print_fail(), and ra8_usb_hmsc_write10().
Referenced by ospirw_host_pass().
|
static |
Sectors that read back correctly after the write pass.
Definition at line 55 of file usb_selftest_ospi_rw_steps.c.
|
static |
Device-reported GET_MAX_LUN value (expect 0, single LUN).
Definition at line 57 of file usb_selftest_ospi_rw_steps.c.
|
static |
First mismatching sector, or k_ospirw_no_mismatch.
Definition at line 59 of file usb_selftest_ospi_rw_steps.c.
|
static |
Completed full passes (sticky success counter).
Definition at line 61 of file usb_selftest_ospi_rw_steps.c.
|
static |
Host-ladder phase marker (ospirw_phase_t).
Definition at line 53 of file usb_selftest_ospi_rw_steps.c.