|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Shared constants + step prototypes for the OSPI USB self-loop app. More...
#include <stdint.h>#include "ra8_err.h"#include "ra8_fs.h"#include "ra8_usb_hmsc.h"#include "tx_api.h"Go to the source code of this file.
Functions | |
| void | selftest_pattern_fill (uint32_t win_sector, UCHAR *out) |
| Compute the deterministic pattern for one window data sector. | |
| UINT | selftest_msc_read (VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status) |
| Storage media-read callback: synthesize sectors over MRAM. | |
| UINT | selftest_msc_write (VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status) |
| Storage media-write callback: always rejects (write-protected). | |
| UINT | selftest_msc_status (VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status) |
| Storage media-status callback. | |
| ra8_err_t | selftest_print (const char *text) |
| Print a NUL-terminated ASCII string over the console. | |
| ra8_err_t | selftest_print_dec (uint32_t value) |
| Print a uint32_t as ASCII decimal. | |
| ra8_err_t | selftest_print_hex (uint32_t value, uint8_t digits) |
| Print a value as fixed-width uppercase hex. | |
| ra8_err_t | selftest_print_fail (const char *what, ra8_err_t err) |
| Print "FAIL <what> err=0xNNNNNNNN" on its own line. | |
| ra8_err_t | selftest_host_pass (void) |
| One full host-side pass: enumerate, mount, verify, WP. | |
Shared constants + step prototypes for the OSPI USB self-loop app.
Self-contained contract surface shared between the app's translation units. main.c owns boot, the ThreadX workers, and tx_application_ define; the FAT16-synthesis / console / Mass-Storage-media callbacks live in usb_selftest_ospi_format.c; the polled host-side pass ladder (enumerate -> mount -> verify -> write-protect) lives in usb_selftest_ospi_host.c. This header carries every app-local enum (volume geometry, OSPI pattern coefficients, SCSI sense triples, console sizing, J-Link phase markers) plus the cross-TU function prototypes so no symbol is defined in one TU and referenced from another without going through this header.
The USBX-typed entry points (UCHAR* / UINT / VOID* / ULONG) are only declared when ThreadX/USBX is in the build, i.e. outside RA8_OFF_TARGET; the plain console helpers are likewise gated since their definitions are.
Definition in file usb_selftest_ospi_steps.h.
| enum scsi_sense_code_t : uint8_t |
SCSI sense triple for an unsupported / out-of-range request.
| Enumerator | |
|---|---|
| k_scsi_sense_illegal_request | Sense key: ILLEGAL REQUEST. |
| k_scsi_asc_lba_out_of_range | ASC: LBA out of range. |
| k_scsi_ascq_none | ASCQ: none. |
Definition at line 152 of file usb_selftest_ospi_steps.h.
| enum scsi_wp_sense_t : uint8_t |
SCSI sense triple for a write to the protected medium.
| Enumerator | |
|---|---|
| k_scsi_sense_data_protect | Sense key: DATA PROTECT. |
| k_scsi_asc_write_protected | ASC: WRITE PROTECTED. |
Definition at line 159 of file usb_selftest_ospi_steps.h.
| enum selftest_config_t : uint32_t |
Compile-time settings: threads, pool, console, retry cadence.
Definition at line 46 of file usb_selftest_ospi_steps.h.
| enum selftest_fat_boot_t : uint32_t |
Boot-sector field values (MS FAT spec 1.03 sec 3.1).
Definition at line 195 of file usb_selftest_ospi_steps.h.
| enum selftest_fat_geom_t : uint32_t |
Synthesized FAT16 volume geometry (MS FAT spec 1.03).
Identical to usb_msc_mram: one 512-byte sector per cluster, data region padded to 4096 clusters to cross the FAT16 threshold, MRAM.BIN occupying clusters 2..2049.
Definition at line 172 of file usb_selftest_ospi_steps.h.
| enum selftest_fat_off_t : uint8_t |
Byte offsets inside the boot sector and directory entries.
Definition at line 215 of file usb_selftest_ospi_steps.h.
| enum selftest_hex_t : uint8_t |
Hex/decimal text-formatter sizing constants.
Definition at line 73 of file usb_selftest_ospi_steps.h.
| enum selftest_mask_t : uint32_t |
Bit-mask constants used by the text formatters.
| Enumerator | |
|---|---|
| k_selftest_nibble_mask | 4-bit nibble mask. |
| k_selftest_dec_radix | Base for decimal conversion. |
Definition at line 85 of file usb_selftest_ospi_steps.h.
| enum selftest_ospi_t : uint32_t |
OSPI flash geometry the device-side volume is backed by.
The 1 MiB window the device programs + exposes lives at offset 0x100000 in the IS25LX512M (clear of flash_journal's offset-0 record). ra8_xspi addresses the chip 0-based. Erase granularity is the IS25LX512M 4 KiB sector.
Definition at line 127 of file usb_selftest_ospi_steps.h.
| enum selftest_pattern_t : uint32_t |
Deterministic sector-pattern coefficients (device + host agree).
Sector s, byte i holds (s * smul + i * imul + bias) & 0xFF. Both the boot programmer and the host verifier compute this identically, so the host never has to read the OSPI (single-controller contention-free).
| Enumerator | |
|---|---|
| k_ospi_pat_smul | Per-sector multiplier. |
| k_ospi_pat_imul | Per-byte multiplier. |
| k_ospi_pat_bias | Constant bias. |
| k_ospi_pat_mask | Byte mask. |
Definition at line 144 of file usb_selftest_ospi_steps.h.
| enum selftest_phase_t : uint32_t |
J-Link probe values marking host-ladder progress.
Definition at line 108 of file usb_selftest_ospi_steps.h.
| enum selftest_verify_t : uint32_t |
Content-verification geometry over the device's FAT16 volume.
Definition at line 94 of file usb_selftest_ospi_steps.h.
| enum selftest_word_pack_t : uint32_t |
32-bit little-endian split constants.
| Enumerator | |
|---|---|
| k_word_shift | Bits per half-word. |
| k_word_mask | Low half-word mask. |
Definition at line 248 of file usb_selftest_ospi_steps.h.
|
nodiscard |
One full host-side pass: enumerate, mount, verify, WP.
Phases mirror selftest_phase_t and are mirrored into the J-Link phase probe for readout. On any failure the host controller is closed so the next retry starts from a clean attach.
| k_ra8_ok | The pass printed OSPI PASS. |
One full host-side pass: enumerate, mount, verify, WP.
One full host-side pass: enumerate, mount, browse, verify, WP.
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.
One full host-side pass: enumerate, mount, verify, WP.
One full host-side pass: enumerate, mount, browse, verify, WP.
Enumerates and mounts to prove FAT parse, then runs selftest_verify_mram_raw k_selftest_soak_iters times back to back – every burst is still memcmp'd vs MRAM, so a single corrupted transfer anywhere in the soak fails the run. Aggregates volume + time for a stable throughput benchmark, then confirms the RO write rejection once. s_dbg_pass_count mirrors the completed-iteration count for J-Link.
| k_ra8_ok | All iterations matched; SOAK PASS printed. |
Definition at line 738 of file usb_host_msc_browse_host.c.
| UINT selftest_msc_read | ( | VOID * | storage, |
| ULONG | lun, | ||
| UCHAR * | data_pointer, | ||
| ULONG | number_blocks, | ||
| ULONG | lba, | ||
| ULONG * | media_status ) |
Storage media-read callback: synthesize sectors over MRAM.
Bound checks the request against the volume, then fills each block via the FAT16 sector synthesizer. LED1 toggles per call so the self-loop traffic is visible on the board.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (must be 0). |
| [out] | data_pointer | USBX-owned destination buffer. |
| [in] | number_blocks | Number of 512-byte blocks to produce. |
| [in] | lba | Starting LBA. |
| [out] | media_status | Filled with sense status word. |
| UX_SUCCESS | Read completed. |
| UX_ERROR | Out-of-range LBA / count. |
Bound checks the request against the volume, then fills each block via the FAT16 synthesizer. LED1 toggles per call so the self-loop traffic is visible on the board.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (must be 0). |
| [out] | data_pointer | USBX-owned destination buffer. |
| [in] | number_blocks | Number of 512-byte blocks to produce. |
| [in] | lba | Starting LBA. |
| [out] | media_status | Filled with sense status word. |
| UX_SUCCESS | Read completed. |
| UX_ERROR | Out-of-range LBA / count. |
Bound checks the request against the volume, then fills each block via selftest_fat_fill_sector. LED1 toggles per call so the self-loop traffic is visible on the board.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (must be 0). |
| [out] | data_pointer | USBX-owned destination buffer. |
| [in] | number_blocks | Number of 512-byte blocks to produce. |
| [in] | lba | Starting LBA. |
| [out] | media_status | Filled with sense status word. |
| UX_SUCCESS | Read completed. |
| UX_ERROR | Out-of-range LBA / count. |
Bound checks the request against the volume, then fills each block via the FAT16 synthesizer. LED1 toggles per call so the self-loop traffic is visible on the board.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (must be 0). |
| [out] | data_pointer | USBX-owned destination buffer. |
| [in] | number_blocks | Number of 512-byte blocks to produce. |
| [in] | lba | Starting LBA. |
| [out] | media_status | Filled with sense status word. |
| UX_SUCCESS | Read completed. |
| UX_ERROR | Out-of-range LBA / count. |
Bound checks the request against the volume, then fills each block via selftest_fat_fill_sector. LED1 toggles per call so the self-loop traffic is visible on the board.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (must be 0). |
| [out] | data_pointer | USBX-owned destination buffer. |
| [in] | number_blocks | Number of 512-byte blocks to produce. |
| [in] | lba | Starting LBA. |
| [out] | media_status | Filled with sense status word. |
| UX_SUCCESS | Read completed. |
| UX_ERROR | Out-of-range LBA / count. |
Definition at line 304 of file usb_host_msc_browse_steps.c.
References k_fat_total_sectors, k_ra8_board_led1, k_scsi_asc_lba_out_of_range, k_scsi_ascq_none, k_scsi_sense_illegal_request, k_selftest_block_size, ra8_board_led_toggle(), s_dbg_read_calls, selftest_fat_fill_sector(), selftest_fat_fill_sector(), and selftest_fat_fill_sector().
Storage media-status callback.
Always reports media-present.
The synthesized volume cannot go away; status is constant 0.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (unused). |
| [in] | media_id | Media id (unused). |
| [out] | media_status | Filled with 0 (no fault). |
| UX_SUCCESS | Media is present and ready. |
Definition at line 347 of file usb_host_msc_browse_steps.c.
| UINT selftest_msc_write | ( | VOID * | storage, |
| ULONG | lun, | ||
| UCHAR * | data_pointer, | ||
| ULONG | number_blocks, | ||
| ULONG | lba, | ||
| ULONG * | media_status ) |
Storage media-write callback: always rejects (write-protected).
The host side of this very app probes exactly this rejection (WRITE(10) must fail with DATA PROTECT and the transport must keep working afterwards).
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (unused). |
| [in] | data_pointer | USBX-owned source buffer (unused). |
| [in] | number_blocks | Number of blocks the host tried (unused). |
| [in] | lba | Starting LBA (unused). |
| [out] | media_status | Filled with DATA PROTECT sense. |
| UX_ERROR | The medium is write-protected. |
Definition at line 328 of file usb_host_msc_browse_steps.c.
References k_scsi_asc_write_protected, k_scsi_ascq_none, and k_scsi_sense_data_protect.
| void selftest_pattern_fill | ( | uint32_t | win_sector, |
| UCHAR * | out ) |
Compute the deterministic pattern for one window data sector.
Fills out with (win_sector * smul + i * imul + bias) per byte (see selftest_pattern_t). This is the single source of truth: the boot programmer writes it into OSPI and the host verifier recomputes it – so the host never reads the flash and there is no single-controller contention.
| [in] | win_sector | 0-based sector index within the OSPI window. |
| [out] | out | 512-byte destination buffer. |
out has 512 writable bytes. out holds the sector's pattern bytes. Definition at line 227 of file usb_selftest_ospi_format.c.
References k_ospi_pat_bias, k_ospi_pat_imul, k_ospi_pat_mask, k_ospi_pat_smul, and k_selftest_block_size.
Referenced by selftest_ospi_write_pattern(), and selftest_verify_ospi_raw().
|
nodiscard |
Print a NUL-terminated ASCII string over the console.
Length-bounded by the bounded string-length scan.
| [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. 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 423 of file usb_selftest_ospi_format.c.
References selftest_sci_write(), and selftest_str_len().
|
nodiscard |
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 428 of file usb_selftest_ospi_format.c.
References k_selftest_dec_chars_u32, k_selftest_dec_radix, and selftest_sci_write().
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 466 of file usb_selftest_ospi_format.c.
References k_ra8_ok, k_selftest_hex_chars_u32, selftest_print(), and selftest_print_hex().
|
nodiscard |
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 452 of file usb_selftest_ospi_format.c.
References k_selftest_hex_chars_u32, k_selftest_nibble_bits, k_selftest_nibble_mask, selftest_nibble_to_hex(), and selftest_sci_write().