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

Shared tunables + host-side worker seam for the writable-OSPI self-loop. More...

#include <stdint.h>
#include "ra8_err.h"
#include "tx_api.h"
Include dependency graph for usb_selftest_ospi_rw_steps.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  ospirw_config_t : uint32_t {
  k_ospirw_thread_stack = 4096U ,
  k_ospirw_host_stack = 8192U ,
  k_ospirw_usbx_pool_bytes = 32768U ,
  k_ospirw_idle_ticks = 50U ,
  k_ospirw_boot_wait_ticks = 500U ,
  k_ospirw_retry_ticks = 3000U ,
  k_ospirw_baud = 115200U ,
  k_ospirw_print_cap = 160U ,
  k_ospirw_dev_priority = 8U ,
  k_ospirw_host_priority = 24U
}
 Compile-time settings: threads, pool, console, cadence. More...
enum  ospirw_hex_t : uint8_t {
  k_ospirw_hex_chars_u16 = 4U ,
  k_ospirw_hex_chars_u32 = 8U ,
  k_ospirw_dec_chars_u32 = 10U ,
  k_ospirw_nibble_bits = 4U ,
  k_ospirw_hex_digit_split = 10U
}
 Hex/decimal text-formatter sizing constants. More...
enum  ospirw_mask_t : uint32_t {
  k_ospirw_nibble_mask = 0xFU ,
  k_ospirw_dec_radix = 10U
}
 Bit-mask constants used by the text formatters. More...
enum  ospirw_geom_t : uint32_t {
  k_ospirw_count = 1U ,
  k_ospirw_sectors = 64U ,
  k_ospirw_block_size = 512U ,
  k_ospirw_burst_blocks = 8U ,
  k_ospirw_burst_bytes = 4096U ,
  k_ospirw_target_lun0 = 0U ,
  k_ospirw_no_mismatch = 0xFFFFFFFFU ,
  k_ospirw_pat_lun_mul = 97U ,
  k_ospirw_pat_lba_mul = 7U ,
  k_ospirw_pat_bias = 0x5AU ,
  k_ospirw_byte_mask = 0xFFU ,
  k_ospirw_mismatch_lun_shift = 24U ,
  k_ospirw_instance = 0U ,
  k_ospirw_offset = 0x00200000U ,
  k_ospirw_erase_sector = 0x00001000U
}
 LUN geometry + verification constants. More...
enum  ospirw_phase_t : uint32_t {
  k_ospirw_phase_boot = 0U ,
  k_ospirw_phase_init = 1U ,
  k_ospirw_phase_enum = 2U ,
  k_ospirw_phase_verify = 3U ,
  k_ospirw_phase_pass = 4U
}
 J-Link probe values marking host-ladder progress. More...

Functions

ra8_err_t ospirw_ospi_provision (void)
 Bring the OSPI flash up and erase the writable window.
VOID ospirw_host_worker (ULONG arg)
 Host-side worker: retry the full pass until it succeeds.

Detailed Description

Shared tunables + host-side worker seam for the writable-OSPI self-loop.

Tag
[Ring 6 / APP] {World: S}

Splits the usb_selftest_ospi_rw application across two translation units to keep each below the 1000-line file-size cap. This header carries the compile-time tunables (threads, pool, console cadence, LUN geometry, text-formatter sizing, host-ladder phase markers) that BOTH main.c (device + board bring-up side) and the host-side step routines in usb_selftest_ospi_rw_steps.c reference, plus the prototype for the single host worker that tx_application_define (in main.c) spawns.

The enums are defined here – not duplicated – so the two TUs share one authoritative definition. The console formatters, the per-(LUN,LBA) pattern generator, and the host READ/WRITE verifier all live in the sibling and are file-private there; only ospirw_host_worker crosses the TU boundary, so it is the only function prototype exported here.

Author
Brighton Sikarskie
Date
2026-06-13
Since
0.1.0

Definition in file usb_selftest_ospi_rw_steps.h.

Enumeration Type Documentation

◆ ospirw_config_t

enum ospirw_config_t : uint32_t

Compile-time settings: threads, pool, console, cadence.

Enumerator
k_ospirw_thread_stack 

Device worker stack (bytes).

k_ospirw_host_stack 

Host worker stack (bytes).

k_ospirw_usbx_pool_bytes 

USBX memory pool (bytes).

k_ospirw_idle_ticks 

Parked-loop back-off (ticks).

k_ospirw_boot_wait_ticks 

Host start delay (1 ms ticks).

k_ospirw_retry_ticks 

Pause between ladder retries.

k_ospirw_baud 

J-Link OB CDC log baud.

k_ospirw_print_cap 

Bound for console-string scans.

k_ospirw_dev_priority 

Device bring-up worker priority.

k_ospirw_host_priority 

Host worker priority (below USBX).

Definition at line 48 of file usb_selftest_ospi_rw_steps.h.

◆ ospirw_geom_t

enum ospirw_geom_t : uint32_t

LUN geometry + verification constants.

Enumerator
k_ospirw_count 

Logical units exposed (single writable).

k_ospirw_sectors 

512-byte sectors (OSPI window = 32 KiB).

k_ospirw_block_size 

SCSI logical block size.

k_ospirw_burst_blocks 

Blocks per READ(10) burst.

k_ospirw_burst_bytes 

8 x 512 B burst buffer.

k_ospirw_target_lun0 

First LUN index.

k_ospirw_no_mismatch 

Probe: no mismatch.

k_ospirw_pat_lun_mul 

Per-LUN pattern multiplier.

k_ospirw_pat_lba_mul 

Per-LBA pattern multiplier.

k_ospirw_pat_bias 

Pattern constant bias.

k_ospirw_byte_mask 

Byte mask.

k_ospirw_mismatch_lun_shift 

s_dbg_mismatch: LUN in bits 31:24.

k_ospirw_instance 

xSPI controller instance.

k_ospirw_offset 

2 MiB into the chip (scratch).

k_ospirw_erase_sector 

IS25LX512M 4 KiB erase sector.

Definition at line 86 of file usb_selftest_ospi_rw_steps.h.

◆ ospirw_hex_t

enum ospirw_hex_t : uint8_t

Hex/decimal text-formatter sizing constants.

Enumerator
k_ospirw_hex_chars_u16 

16-bit value -> "ABCD".

k_ospirw_hex_chars_u32 

32-bit value -> "ABCDEF01".

k_ospirw_dec_chars_u32 

Max digits for a 32-bit count.

k_ospirw_nibble_bits 

Bits per hex nibble.

k_ospirw_hex_digit_split 

Threshold between '0-9'/'A-F'.

Definition at line 65 of file usb_selftest_ospi_rw_steps.h.

◆ ospirw_mask_t

enum ospirw_mask_t : uint32_t

Bit-mask constants used by the text formatters.

Enumerator
k_ospirw_nibble_mask 

4-bit nibble mask.

k_ospirw_dec_radix 

Base for decimal conversion.

Definition at line 77 of file usb_selftest_ospi_rw_steps.h.

◆ ospirw_phase_t

enum ospirw_phase_t : uint32_t

J-Link probe values marking host-ladder progress.

Enumerator
k_ospirw_phase_boot 

Host thread not started.

k_ospirw_phase_init 

ra8_usb_hmsc_init issued.

k_ospirw_phase_enum 

Enumerating.

k_ospirw_phase_verify 

Reading + checking LUNs.

k_ospirw_phase_pass 

All LUNs verified.

Definition at line 108 of file usb_selftest_ospi_rw_steps.h.

Function Documentation

◆ 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.

Parameters
[in]argThreadX entry argument (unused).
Precondition
tx_application_define created this thread.
The HS host pins, expander switch, and PLL are up (main).
Postcondition
On success the pass counter and LED2 are latched.
Retries forever otherwise; each failure prints its step.
Note
Blocking calls; ms timeouts via ra8_time.
Since
0.1.0

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().

◆ ospirw_ospi_provision()

ra8_err_t ospirw_ospi_provision ( void )
nodiscard

Bring the OSPI flash up and erase the writable window.

Mirrors the read-only OSPI self-loop's bring-up: U15 expander courtesy write, ra8_board_xspi_pins_init (OCTA pins + RESET pulse), ra8_xspi_init 1S-1S-1S, JEDEC-id readback, then a one-shot erase of the k_ospirw_sectors window at k_ospirw_offset so the per-write path is fast program-only. The host owns the data. The body lives in usb_selftest_ospi_rw_device.c; ospirw_device_worker in main.c calls it once before USB attach.

Returns
First failing step's error, or k_ra8_ok.
Return values
k_ra8_okOSPI is up and the write window is erased.
(other)A pins / init / erase step failed.
Precondition
CGC is initialized (main ran ra8_cgc_init).
Single caller (the device worker, before USB attach).
Postcondition
The OSPI bring-up / id J-Link probes reflect the outcome.
The 32 KiB OSPI window is erased (0xFF) on success.
Note
Blocking; runs once at boot before USB attach.
Since
0.1.0

Definition at line 45 of file usb_selftest_ospi_rw_device.c.

References k_ospirw_block_size, k_ospirw_erase_sector, k_ospirw_instance, k_ospirw_offset, k_ospirw_sectors, k_ra8_ok, k_ra8_xspi_lio_1s1s1s, ra8_board_io_expander_set_octospi_active(), ra8_board_xspi_pins_init(), ra8_xspi_flash_erase_sector(), ra8_xspi_flash_read_id(), ra8_xspi_init(), s_dbg_ospi_id, and s_dbg_ospi_prov.

Referenced by ospirw_device_worker().