|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Host-side console formatters + ra8_fs backend + pass ladder. More...
#include <stdint.h>#include <string.h>#include "usb_selftest_hs_host_steps.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_fs.h"#include "ra8_io_blockdev.h"#include "ra8_io_blockdev_usbmsc.h"#include "ra8_time.h"#include "ra8_usb_hmsc.h"Go to the source code of this file.
Functions | |
| static uint8_t | selftest_nibble_to_hex (uint32_t nibble) |
| Format one nibble (0..15) into an uppercase hex character. | |
| static uint32_t | selftest_str_len (const char *text) |
| Bounded ASCII string length (cap k_selftest_print_cap). | |
| static ra8_err_t | selftest_sci_write (const uint8_t *data, uint32_t len) |
| Push a literal block over SCI8 polled. | |
| static ra8_err_t | selftest_print (const char *text) |
| Print a NUL-terminated ASCII string over the console. | |
| static ra8_err_t | selftest_print_dec (uint32_t value) |
| Print a uint32_t as ASCII decimal. | |
| static ra8_err_t | selftest_print_hex (uint32_t value, uint8_t digits) |
| Print a value as fixed-width uppercase hex. | |
| static ra8_err_t | selftest_print_fail (const char *what, ra8_err_t err) |
| Print "FAIL <what> err=0xNNNNNNNN" on its own line. | |
| static const char * | selftest_fs_type_name (ra8_fs_type_t type) |
| Map a detected filesystem type to a printable name. | |
| static ra8_err_t | selftest_mount_volume (ra8_fs_mount_t **out_mount) |
| Mount the loop device's volume through the USB-MSC backend. | |
| static ra8_err_t | selftest_verify_mram_raw (void) |
| Raw multi-block READ(10) of the MRAM data region vs MRAM. | |
| static ra8_err_t | selftest_print_verify_verdict (void) |
| Print the verify verdict line (bytes + duration + rate). | |
| static ra8_err_t | selftest_write_protect_probe (void) |
| WRITE(10) into the read-only LUN must be rejected. | |
| static ra8_err_t | selftest_host_enumerate (ra8_usb_hmsc_device_t *out_device) |
| Bring the host controller up and enumerate the loop device. | |
| ra8_err_t | selftest_host_pass (void) |
| One full host-side pass: enumerate, mount, browse, verify, WP. | |
Variables | |
| static volatile uint32_t | s_dbg_phase |
| Host-ladder phase marker (selftest_phase_t). | |
| static volatile uint32_t | s_dbg_verified_bytes |
| Bytes content-verified so far this pass. | |
| static volatile uint32_t | s_dbg_mismatch_off = (uint32_t)k_selftest_no_mismatch |
| First mismatching MRAM offset (k_selftest_no_mismatch = none). | |
| static volatile uint32_t | s_dbg_verify_ms |
| Milliseconds the 1 MiB verify streamed for. | |
| static volatile uint32_t | s_dbg_pass_count |
| Completed full passes (sticky success counter). | |
| static ra8_io_blockdev_t | s_selftest_usb_dev |
| Block device fronting the hosted MSC volume for this ladder. | |
| static ra8_io_blockdev_usbmsc_state_t | s_selftest_usb_state |
| Caller-owned backend state for s_selftest_usb_dev. | |
Host-side console formatters + ra8_fs backend + pass ladder.
The host half of the USB self-loop config A app: the SCI8 -> J-Link OB CDC console formatters, the ra8_fs backend vtable over the polled host-MSC class, the raw multi-block READ(10) integrity sweep against the MRAM window, the write-protect rejection probe, and the full pass ladder (selftest_host_pass). main.c's selftest_host_worker drives selftest_host_pass; the J-Link phase / verify / pass probes that track its progress live in this translation unit.
Split out of main.c verbatim to keep every translation unit under the 1000-line file-size cap; see usb_selftest_hs_host_steps.h for the shared constants and the pass-ladder contract.
Definition in file usb_selftest_hs_host_host.c.
|
static |
Map a detected filesystem type to a printable name.
Total over the enum; unknown maps to "unknown".
| [in] | type | Mount-time detection result. |
| fat16 | For k_ra8_fs_type_fat16 (the expected verdict). |
type came from a populated mount struct. Definition at line 332 of file usb_selftest_hs_host_host.c.
References k_ra8_fs_type_exfat, k_ra8_fs_type_fat12, k_ra8_fs_type_fat16, k_ra8_fs_type_fat32, and k_ra8_fs_type_unknown.
Referenced by selftest_mount_volume().
|
staticnodiscard |
Bring the host controller up and enumerate the loop device.
Initializes the USBHS host, enumerates the downstream FS device over the cable, and prints its VID/PID. On any failure the host controller is closed so the caller's retry starts clean.
| [out] | out_device | Receives the enumerated device snapshot. |
| k_ra8_ok | Host up and device enumerated; identity printed. |
out_device is non-NULL. out_device filled. Definition at line 590 of file usb_selftest_hs_host_host.c.
References k_ra8_ok, k_ra8_usb_speed_hs, k_selftest_hex_chars_u16, k_selftest_phase_enum, k_selftest_phase_host_init, ra8_usb_hmsc_device_t::product_id, ra8_usb_hmsc_close(), ra8_usb_hmsc_enumerate(), ra8_usb_hmsc_init(), s_dbg_phase, selftest_print(), selftest_print_fail(), selftest_print_hex(), and ra8_usb_hmsc_device_t::vendor_id.
Referenced by selftest_host_pass().
|
nodiscard |
One full host-side pass: enumerate, mount, browse, verify, WP.
Run one full soak pass and print the verdict.
One full host-side pass: enumerate, mount, verify, WP.
Drives the host-side ladder over the self-loop cable: brings the USBHS host up and enumerates the FS device, mounts and parses the FAT16 volume, browses the root directory, raw-verifies the 1 MiB MRAM data region with multi-block READ(10) bursts, then probes the write-protect rejection. Phases are mirrored into the J-Link progress probe for readout. On any failure the host controller is closed so the next retry starts from a clean attach. The host worker thread (in main.c) loops this until it returns k_ra8_ok.
| k_ra8_ok | The pass printed the BROWSE PASS banner. |
One full host-side pass: enumerate, mount, browse, verify, WP.
Definition at line 628 of file usb_selftest_hs_host_host.c.
References k_ra8_board_led2, k_ra8_ok, k_selftest_phase_mount, k_selftest_phase_pass, k_selftest_phase_verify, k_selftest_phase_wp, ra8_board_led_on(), ra8_fs_unmount(), ra8_usb_hmsc_close(), s_dbg_pass_count, s_dbg_phase, selftest_host_enumerate(), selftest_mount_volume(), selftest_print(), selftest_print_verify_verdict(), selftest_verify_mram_raw(), and selftest_write_protect_probe().
|
staticnodiscard |
Mount the loop device's volume through the USB-MSC backend.
Binds the ra8_io USB-MSC block device over the polled host class, bridges it to an ra8_fs backend, and prints the detected filesystem type (must be fat16 for this device).
| [out] | out_mount | Receives the mount handle on success. |
| k_ra8_ok | Volume mounted; the type line was printed. |
out_mount is non-NULL. Definition at line 370 of file usb_selftest_hs_host_host.c.
References k_ra8_ok, k_selftest_target_lun, ra8_fs_mount(), ra8_io_blockdev_as_fs_backend(), ra8_io_blockdev_usbmsc_init(), s_selftest_usb_dev, s_selftest_usb_state, selftest_fs_type_name(), selftest_print(), and selftest_print_fail().
Referenced by selftest_host_pass().
|
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 79 of file usb_selftest_hs_host_host.c.
References k_selftest_hex_digit_split.
Referenced by selftest_print_hex().
|
staticnodiscard |
Print a NUL-terminated ASCII string over the console.
Length-bounded by selftest_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_selftest_print_cap bytes. Definition at line 159 of file usb_selftest_hs_host_host.c.
References selftest_sci_write(), and selftest_str_len().
Referenced by selftest_host_enumerate(), selftest_host_pass(), selftest_mount_volume(), selftest_print_fail(), selftest_print_verify_verdict(), and selftest_write_protect_probe().
|
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 182 of file usb_selftest_hs_host_host.c.
References k_selftest_dec_chars_u32, k_selftest_dec_radix, and selftest_sci_write().
Referenced by selftest_print_verify_verdict().
Print "FAIL <what> err=0xNNNNNNNN" on its own line.
One-line diagnostic; print errors inside are not recoverable anyway, so the first failing chunk's code is 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 259 of file usb_selftest_hs_host_host.c.
References k_ra8_ok, k_selftest_hex_chars_u32, selftest_print(), and selftest_print_hex().
Referenced by selftest_host_enumerate(), selftest_mount_volume(), selftest_verify_mram_raw(), and selftest_write_protect_probe().
|
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_selftest_hex_chars_u32. Definition at line 225 of file usb_selftest_hs_host_host.c.
References k_selftest_hex_chars_u32, k_selftest_nibble_bits, k_selftest_nibble_mask, selftest_nibble_to_hex(), and selftest_sci_write().
Referenced by selftest_host_enumerate(), selftest_print_fail(), and selftest_write_protect_probe().
|
staticnodiscard |
Print the verify verdict line (bytes + duration + rate).
"verified 1048576 bytes in N ms (M KiB/s)".
| k_ra8_ok | The verdict line is queued. |
Definition at line 478 of file usb_selftest_hs_host_host.c.
References k_ra8_ok, k_selftest_bytes_per_kib, k_selftest_ms_per_sec, s_dbg_verified_bytes, s_dbg_verify_ms, selftest_print(), and selftest_print_dec().
Referenced by selftest_host_pass().
|
staticnodiscard |
Push a literal block over 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 136 of file usb_selftest_hs_host_host.c.
References ra8_board_uart_console_write().
Referenced by selftest_print(), selftest_print_dec(), and selftest_print_hex().
|
static |
Bounded ASCII string length (cap k_selftest_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 returned length. Definition at line 105 of file usb_selftest_hs_host_host.c.
References k_selftest_print_cap.
Referenced by selftest_print().
|
staticnodiscard |
Raw multi-block READ(10) of the MRAM data region vs MRAM.
Streams the 1 MiB data region straight through the SCSI READ(10) entry point in 8-block (4 KiB) bursts – one CBW per burst, not per sector – and memcmp's each burst against the same offset of the real MRAM window at 0x02000000. This deliberately bypasses ra8_fs: the filesystem walk re-reads FAT/metadata sectors per cluster (a ~250x device-read amplification that throttled the loop to under 1 sector/s), whereas the raw path is the direct integrity proof – "the SCSI transport returns the chip's flash byte for byte" – and runs at the cable's real rate. The mount step (separate phase) already proved the host can PARSE the FAT16 volume over the loop.
Data region: FAT16 LBA k_fat_data_lba is cluster 2 = MRAM offset 0, so LBA (data_lba + b) holds MRAM[b * 512].
| k_ra8_ok | All 1 MiB matched byte for byte. |
| k_ra8_err_invalid_state | A byte differed from MRAM. |
Definition at line 431 of file usb_selftest_hs_host_host.c.
References k_fat_data_lba, k_fat_mram_clusters, k_mram_base_addr, k_ra8_err_invalid_state, k_ra8_ok, k_selftest_block_size, k_selftest_burst_blocks, k_selftest_burst_bytes, k_selftest_no_mismatch, k_selftest_target_lun, memcmp(), ra8_time_ms(), ra8_usb_hmsc_read10(), s_dbg_mismatch_off, s_dbg_verified_bytes, s_dbg_verify_ms, and selftest_print_fail().
Referenced by selftest_host_pass().
|
staticnodiscard |
WRITE(10) into the read-only LUN must be rejected.
Issues a 1-block WRITE(10) into the data region. The device LUN is write-protected (MODE SENSE WP bit + media_write returns DATA PROTECT), so the host's write entry point must surface an error rather than k_ra8_ok – the MRAM is never modified. This is the write-protection proof.
It deliberately stops there: terminating a data-out phase against a write-protected device STALLs the bulk-OUT endpoint, and recovering the BOT transport afterwards (Bulk-Only Mass Storage Reset + Clear Feature ENDPOINT_HALT on both bulk pipes) is not yet implemented in the host class. That STALL/ClearFeature recovery path is tracked as GitHub issue #92's robustness sweep; this pass parks on success, so the post-STALL desync does not affect the verdict.
| k_ra8_ok | The write was rejected (protection works). |
| k_ra8_err_invalid_state | The write was unexpectedly accepted. |
Definition at line 543 of file usb_selftest_hs_host_host.c.
References k_ra8_err_invalid_state, k_ra8_ok, k_selftest_block_size, k_selftest_hex_chars_u32, k_selftest_target_lun, k_selftest_wp_probe_lba, ra8_usb_hmsc_write10(), selftest_print(), selftest_print_fail(), and selftest_print_hex().
Referenced by selftest_host_pass().
|
static |
First mismatching MRAM offset (k_selftest_no_mismatch = none).
Definition at line 51 of file usb_selftest_hs_host_host.c.
|
static |
Completed full passes (sticky success counter).
Definition at line 55 of file usb_selftest_hs_host_host.c.
|
static |
Host-ladder phase marker (selftest_phase_t).
Definition at line 47 of file usb_selftest_hs_host_host.c.
|
static |
Bytes content-verified so far this pass.
Definition at line 49 of file usb_selftest_hs_host_host.c.
|
static |
Milliseconds the 1 MiB verify streamed for.
Definition at line 53 of file usb_selftest_hs_host_host.c.
|
static |
Block device fronting the hosted MSC volume for this ladder.
Bound once in selftest_mount_volume by ra8_io_blockdev_usbmsc_init, which wires the ra8_io USB-MSC backend over the polled host-MSC class. File scope because ra8_io_blockdev_as_fs_backend keeps a pointer to this handle for the whole life of the mount.
Definition at line 298 of file usb_selftest_hs_host_host.c.
|
static |
Caller-owned backend state for s_selftest_usb_dev.
Records the logical unit the backend addresses. Private to the ra8_io USB-MSC backend and must out-live every call made through the device.
Definition at line 312 of file usb_selftest_hs_host_host.c.