|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
examples/ek_ra8d2/hw_validated/hil/usb_selftest_microsd/src/usb_selftest_microsd_steps.c More...
#include "usb_selftest_microsd_steps.h"#include <stdint.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_err.h"#include "ra8_usb.h"#include "ra8_usb_hmsc.h"#include "tx_api.h"#include "ux_api.h"#include "ux_dcd_ra8_usb.h"#include "ux_device_class_storage.h"#include "ux_device_stack.h"Go to the source code of this file.
Functions | |
| static UINT | microsd_msc_read (VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status) |
| Storage media-read callback: serve the boot-time SD snapshot. | |
| static UINT | microsd_msc_write (VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status) |
| Storage media-write callback: reject (all LUNs are read-only). | |
| static UINT | microsd_msc_status (VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status) |
| Storage media-status callback. | |
| static UINT | microsd_usbx_stack_up (void) |
| Bring USBX system + device stack up with the MSC framework. | |
| static void | microsd_fill_lun (UX_SLAVE_CLASS_STORAGE_PARAMETER *p, uint32_t idx) |
| Populate the LUN parameter slot with geometry + callbacks. | |
| static UINT | microsd_class_register (void) |
| Register the Mass-Storage class with one read-only LUN. | |
| VOID | microsd_device_worker (ULONG arg) |
| Device-side worker: bring the read-only SD FS device up, then park. | |
| static ra8_err_t | microsd_verify_one (uint32_t lun) |
| Read + verify the LUN's sectors against the SD snapshot. | |
| static ra8_err_t | microsd_print_lun_ok (uint32_t lun) |
| Print "LUN n OK (256 sectors)" for a verified logical unit. | |
| static ra8_err_t | microsd_host_enumerate (ra8_usb_hmsc_device_t *device) |
| Enumerate the looped device and print its PID + GET_MAX_LUN. | |
| static ra8_err_t | microsd_host_pass (void) |
| One full host-side pass: enumerate, verify the SD snapshot. | |
| VOID | microsd_host_worker (ULONG arg) |
| Host-side worker: retry the full pass until it succeeds. | |
Variables | |
| static UCHAR | s_usbx_pool [k_microsd_usbx_pool_bytes] |
| USBX memory pool (USBX uses tx_byte_pool internally). | |
| static UCHAR | s_msc_vendor_id [] = "RA8D2 " |
| static UCHAR | s_msc_product_id [] = "MICROSD CARD RO " |
| static UCHAR | s_msc_product_rev [] = "0001" |
| static volatile uint32_t | s_dbg_phase |
| Host-ladder phase marker (microsd_phase_t). | |
| static volatile uint32_t | s_dbg_luns_ok |
| Sectors that read back matching the SD snapshot this 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_microsd_no_mismatch |
| First mismatching sector, or k_microsd_no_mismatch. | |
| static volatile uint32_t | s_dbg_pass_count |
| Completed full passes (sticky success counter). | |
| static volatile uint32_t | s_dbg_read_calls |
| Device-side media_read invocations. | |
| static volatile uint32_t | s_dbg_dev_step |
| Device worker progress: 1 stack, 2 class, 3 dcd, 4 attach, 5 parked. | |
| static volatile uint32_t | s_dbg_dev_err |
| Device worker first failing return code (0 = none). | |
| static UCHAR | s_device_framework_fs [] |
| static UCHAR | s_string_framework [] |
| USBX string descriptor table (vendor / product / serial). | |
| static UCHAR | s_language_id_framework [] = {k_usb_langid_en_us_lo, k_usb_langid_en_us_hi} |
| USBX language-id table – US English. | |
examples/ek_ra8d2/hw_validated/hil/usb_selftest_microsd/src/usb_selftest_microsd_steps.c
USBX device worker, read-only MSC media callbacks, and host verify ladder
Split out of main.c to keep every translation unit under the line-count cap. Holds the device-side bring-up (USBX system + device stack
Definition in file usb_selftest_microsd_steps.c.
|
static |
Register the Mass-Storage class with one read-only LUN.
Sets number_lun = 1 and fills the single LUN slot via microsd_fill_lun, so the host's GET_MAX_LUN returns 0. One LUN is the minimal read-only microSD exposure.
| UX_SUCCESS | Class registered. |
Definition at line 439 of file usb_selftest_microsd_steps.c.
References k_microsd_count, memset(), microsd_fill_lun(), s_msc_product_id, s_msc_product_rev, and s_msc_vendor_id.
Referenced by microsd_device_worker().
| VOID microsd_device_worker | ( | ULONG | arg | ) |
Device-side worker: bring the read-only SD FS device up, then park.
USBX system + device stack + MSC class (1 LUN) + DCD bridge on the USBFS controller, then DPRPU attach. USBX runs the SCSI/BBB state machine on its own class threads after this.
| [in] | arg | ThreadX entry argument (unused). |
Definition at line 459 of file usb_selftest_microsd_steps.c.
References k_microsd_dev_step_attach, k_microsd_dev_step_class, k_microsd_dev_step_dcd, k_microsd_dev_step_parked, k_microsd_dev_step_stack, k_microsd_idle_ticks, k_ra8_ok, k_ra8_usb_speed_fs, microsd_class_register(), microsd_usbx_stack_up(), ra8_usb_device_attach(), s_dbg_dev_err, s_dbg_dev_step, tx_thread_sleep, and ux_dcd_ra8_usb_initialize().
Referenced by tx_application_define().
|
static |
Populate the LUN parameter slot with geometry + callbacks.
The single LUN is a read-only FAT-disk-typed, removable, 64-sector microSD-backed volume whose media callbacks serve the boot SD snapshot.
| [in,out] | p | The class parameter block. |
| [in] | idx | LUN slot index (0..1). |
p is zeroed and being filled before class register. idx is below k_microsd_count. idx carries the geometry + media callbacks. Definition at line 402 of file usb_selftest_microsd_steps.c.
References k_microsd_block_size, k_microsd_sectors, microsd_msc_read(), microsd_msc_status(), and microsd_msc_write().
Referenced by microsd_class_register().
|
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 608 of file usb_selftest_microsd_steps.c.
References k_microsd_hex_chars_u16, k_microsd_phase_enum, k_ra8_ok, ra8_usb_hmsc_device_t::max_lun, microsd_print(), microsd_print_dec(), microsd_print_fail(), microsd_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 microsd_host_pass().
|
staticnodiscard |
One full host-side pass: enumerate, verify the SD snapshot.
Phases mirror microsd_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 MICROSD PASS. |
Definition at line 654 of file usb_selftest_microsd_steps.c.
References k_microsd_count, k_microsd_phase_init, k_microsd_phase_pass, k_microsd_phase_verify, k_ra8_board_led2, k_ra8_ok, k_ra8_usb_speed_hs, microsd_host_enumerate(), microsd_print(), microsd_print_fail(), microsd_print_lun_ok(), microsd_verify_one(), 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 microsd_host_worker().
| VOID microsd_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 enumerate/verify pass with a retry pause until the SD LUN verifies; afterwards parks so the verdict stays on the wire.
| [in] | arg | ThreadX entry argument (unused). |
Definition at line 698 of file usb_selftest_microsd_steps.c.
References k_microsd_boot_wait_ticks, k_microsd_idle_ticks, k_microsd_retry_ticks, k_ra8_ok, microsd_host_pass(), and tx_thread_sleep.
Referenced by tx_application_define().
|
static |
Storage media-read callback: serve the boot-time SD snapshot.
Bound-checks the request against the exposed window, then copies the bytes straight out of s_usb_selftest_microsd_sd_snapshot (the read-only image of SD LBA 0..63 captured at boot). No live card access happens on the class thread. LED1 toggles per call so loop traffic is visible.
| [in,out] | storage | USBX storage class instance (unused). |
| [in] | lun | Logical unit number (unused; single LUN). |
| [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 from the snapshot. |
| UX_ERROR | Out-of-range LBA / count. |
Definition at line 251 of file usb_selftest_microsd_steps.c.
References k_microsd_block_size, k_microsd_sectors, k_ra8_board_led1, k_scsi_asc_lba_out_of_range, k_scsi_ascq_none, k_scsi_sense_illegal_request, memcpy(), ra8_board_led_toggle(), s_dbg_read_calls, and s_usb_selftest_microsd_sd_snapshot.
Referenced by microsd_fill_lun().
Storage media-status callback.
Always reports media-present.
Synthesized LUNs never go absent; 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 339 of file usb_selftest_microsd_steps.c.
Referenced by microsd_fill_lun().
|
static |
Storage media-write callback: reject (all LUNs are read-only).
The single microSD-backed volume is read-only; any WRITE(10) is refused with DATA PROTECT. Hosts honouring the MODE SENSE WP bit never call this.
| [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 300 of file usb_selftest_microsd_steps.c.
References k_scsi_asc_write_protected, k_scsi_ascq_none, and k_scsi_sense_data_protect.
Referenced by microsd_fill_lun().
|
staticnodiscard |
Print "LUN n OK (256 sectors)" for a verified logical unit.
| [in] | lun | The LUN that just verified. |
| k_ra8_ok | The line is queued. |
lun. Definition at line 574 of file usb_selftest_microsd_steps.c.
References k_ra8_ok, microsd_print(), and microsd_print_dec().
Referenced by microsd_host_pass().
|
static |
Bring USBX system + device stack up with the MSC framework.
One-shot USBX pool + device-stack init (FS-only framework).
| UX_SUCCESS | Stack ready. |
Definition at line 368 of file usb_selftest_microsd_steps.c.
References k_microsd_usbx_pool_bytes, s_device_framework_fs, s_language_id_framework, s_string_framework, and s_usbx_pool.
Referenced by microsd_device_worker().
|
staticnodiscard |
Read + verify the LUN's sectors against the SD snapshot.
READ_CAPACITY (must report k_microsd_sectors), confirm the SD boot signature, then a raw multi-block READ(10) sweep in 8-block against the boot-time SD snapshot (s_usb_selftest_microsd_sd_snapshot).
| [in] | lun | Logical unit to verify (0..1). |
| k_ra8_ok | Every sector matched the SD snapshot. |
| k_ra8_err_invalid_size | READ_CAPACITY reported wrong geometry. |
| k_ra8_err_invalid_state | A byte differed from the snapshot. |
lun is below k_microsd_count. Definition at line 521 of file usb_selftest_microsd_steps.c.
References k_microsd_block_size, k_microsd_burst_blocks, k_microsd_burst_bytes, k_microsd_sectors, k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_ok, memcmp(), microsd_print_fail(), ra8_usb_hmsc_read10(), ra8_usb_hmsc_read_capacity(), s_dbg_mismatch, s_usb_selftest_microsd_dbg_bootsig, and s_usb_selftest_microsd_sd_snapshot.
Referenced by microsd_host_pass().
|
static |
Device worker first failing return code (0 = none).
Definition at line 79 of file usb_selftest_microsd_steps.c.
|
static |
Device worker progress: 1 stack, 2 class, 3 dcd, 4 attach, 5 parked.
Definition at line 77 of file usb_selftest_microsd_steps.c.
|
static |
Sectors that read back matching the SD snapshot this pass.
Definition at line 67 of file usb_selftest_microsd_steps.c.
|
static |
Device-reported GET_MAX_LUN value (expect 0, single LUN).
Definition at line 69 of file usb_selftest_microsd_steps.c.
|
static |
First mismatching sector, or k_microsd_no_mismatch.
Definition at line 71 of file usb_selftest_microsd_steps.c.
|
static |
Completed full passes (sticky success counter).
Definition at line 73 of file usb_selftest_microsd_steps.c.
|
static |
Host-ladder phase marker (microsd_phase_t).
Definition at line 65 of file usb_selftest_microsd_steps.c.
|
static |
Device-side media_read invocations.
Definition at line 75 of file usb_selftest_microsd_steps.c.
|
static |
Definition at line 89 of file usb_selftest_microsd_steps.c.
|
static |
USBX language-id table – US English.
Definition at line 217 of file usb_selftest_microsd_steps.c.
|
static |
Definition at line 57 of file usb_selftest_microsd_steps.c.
|
static |
Definition at line 58 of file usb_selftest_microsd_steps.c.
|
static |
Definition at line 56 of file usb_selftest_microsd_steps.c.
|
static |
USBX string descriptor table (vendor / product / serial).
Each entry: 2 bytes lang-id, 1 byte string index, 1 byte length, then ASCII bytes.
Definition at line 154 of file usb_selftest_microsd_steps.c.
|
static |
USBX memory pool (USBX uses tx_byte_pool internally).
Definition at line 53 of file usb_selftest_microsd_steps.c.