|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Non-Secure USBHS polled HOST ladder: enumerate + bulk echo (#96). More...
#include <stdint.h>#include <string.h>#include "ns_usb_internal.h"#include "ra8_usb.h"#include "tx_api.h"Go to the source code of this file.
Functions | |
| static void | ns_host_pattern_fill (uint32_t round, uint8_t *out, uint32_t len) |
| Fill an echo payload with this round's deterministic bytes. | |
| static ra8_err_t | ns_host_get_dev_desc (uint8_t *desc) |
| GET_DESCRIPTOR(DEVICE) over the polled host control engine. | |
| static ra8_err_t | ns_host_enum_hunt (uint8_t *desc) |
| Wait for attach, then bus-reset + read the device descriptor. | |
| static ra8_err_t | ns_host_set_address (void) |
| SET_ADDRESS to k_ns_dev_addr, then retarget the DCP. | |
| static ra8_err_t | ns_host_set_config (void) |
| SET_CONFIGURATION(::k_ns_config_value) on the addressed device. | |
| static ra8_err_t | ns_host_open_pipes (void) |
| Open the host bulk pipes for the device's CDC data endpoints. | |
| static ra8_err_t | ns_host_enumerate (uint32_t *out_pid) |
| Full enumeration ladder: hunt, SET_ADDRESS, SET_CONFIG, open pipes. | |
| static ra8_err_t | ns_host_echo_round (uint32_t round) |
| One echo round: bulk-OUT a pattern, bulk-IN the echo, compare. | |
| VOID | ns_host_worker (ULONG arg) |
| HS host worker – enumerate the looped FS device, then echo forever. | |
Variables | |
| volatile uint32_t | g_tz_usb_host_phase |
| HS-host ladder phase: 0 boot, 1 host-init, 2 enumerating, 3 echoing, 4 first full pass done. | |
| volatile uint32_t | g_tz_usb_host_pid |
| idProduct the HS host read from the looped FS device (expect 0x000A). | |
| volatile uint32_t | g_tz_usb_host_rounds_ok |
| Bulk echo rounds the HS host has verified byte-equal (advances forever once the loop is healthy – the HIL gate probes this). | |
| volatile uint32_t | g_tz_usb_host_err |
| First non-OK ra8_err_t from the host ladder (0 = none yet). | |
| TX_THREAD | s_ns_host_thread |
| ThreadX TCB for the HS host worker (defined in ns_usb_host.c). | |
| UCHAR | s_ns_host_stack [k_ns_host_stack_bytes] |
| Stack backing storage for s_ns_host_thread (defined in ns_usb_host.c). | |
| CHAR | s_ns_host_thread_name [] = "ns_usb_host" |
| HS host worker thread name (defined in ns_usb_host.c; ThreadX CHAR*). | |
Non-Secure USBHS polled HOST ladder: enumerate + bulk echo (#96).
Split out of ns_usb.c for the 1000-line file-size cap. This TU owns the J7 USBHS HOST side of the self-loop: USBHS (J7) is wired host-side by the Secure boot (PSARB12, host-mode expander, J7 VBUS, UTMI PLL). The ns_host_worker enumerates the FS CDC device over the loop cable using the first-party ra8_usb_host_* polled primitives – no IRQ – and then bulk round-trips a deterministic pattern through the device's auto-echo. It runs at the SAME ThreadX priority as the device dispatch worker (defined in ns_usb.c) with time-slicing, so each thread yields the CPU each tick; the device's chapter-9
The single tx_application_define that spawns this worker lives in ns_usb.c and reaches ns_host_worker plus this TU's thread storage through ns_usb_internal.h. The ThreadX-backed ra8_delay_ms / ra8_time_ms this ladder uses are likewise defined in ns_usb.c (ra8_time.c is intentionally not linked).
Definition in file ns_usb_host.c.
| enum ns_host_req_t : uint16_t |
Chapter-9 standard request / descriptor constants for the host.
Definition at line 105 of file ns_usb_host.c.
| enum ns_host_tune_t : uint32_t |
Host enumeration timing / retry / geometry tunables.
Definition at line 119 of file ns_usb_host.c.
|
staticnodiscard |
One echo round: bulk-OUT a pattern, bulk-IN the echo, compare.
| [in] | round | The echo round index (pattern key). |
| k_ra8_ok | The echo matched the sent payload. |
| k_ra8_err_invalid_size | The echo length differed. |
| k_ra8_err_invalid_state | The echo bytes differed. |
Definition at line 368 of file ns_usb_host.c.
References k_ns_echo_buf, k_ns_host_pipe_in, k_ns_host_pipe_out, k_ns_payload, k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_ok, k_ra8_usb_speed_hs, memcmp(), ns_host_pattern_fill(), ra8_usb_host_bulk_in(), and ra8_usb_host_bulk_out().
Referenced by ns_host_worker().
|
staticnodiscard |
Wait for attach, then bus-reset + read the device descriptor.
| [out] | desc | Receives the winning 18-byte device descriptor. |
| k_ra8_ok | The device answered at address 0. |
| k_ra8_err_hw_timeout | Nothing attached / nothing answered. |
Definition at line 212 of file ns_usb_host.c.
References k_ns_attach_spin, k_ns_attach_to_ms, k_ns_debounce_ms, k_ns_enum_tries, k_ns_recovery_ms, k_ns_reset_hold_ms, k_ns_vbus_settle_ms, k_ra8_err_hw_timeout, k_ra8_ok, k_ra8_usb_speed_hs, ns_host_get_dev_desc(), ra8_delay_ms(), ra8_time_ms(), ra8_usb_host_bus_reset(), ra8_usb_host_line_state(), ra8_usb_host_set_target(), and ra8_usb_host_set_uact().
Referenced by ns_host_enumerate().
|
staticnodiscard |
Full enumeration ladder: hunt, SET_ADDRESS, SET_CONFIG, open pipes.
| [out] | out_pid | Receives the device idProduct on success. |
| k_ra8_ok | Device enumerated; bulk pipes open. |
out_pid is non-NULL. out_pid holds the device idProduct on success. Definition at line 334 of file ns_usb_host.c.
References k_ns_byte_bits, k_ns_dev_desc_len, k_ns_off_dev_pid, k_ra8_ok, ns_host_enum_hunt(), ns_host_open_pipes(), ns_host_set_address(), and ns_host_set_config().
Referenced by ns_host_worker().
|
staticnodiscard |
GET_DESCRIPTOR(DEVICE) over the polled host control engine.
| [out] | desc | Receives the 18-byte device descriptor. |
| k_ra8_ok | All 18 bytes arrived. |
| k_ra8_err_hw_error | A short descriptor came back. |
desc holds at least k_ns_dev_desc_len bytes. desc carries the device descriptor on success. Definition at line 181 of file ns_usb_host.c.
References k_ns_bm_std_dev_in, k_ns_breq_get_desc, k_ns_byte_bits, k_ns_desc_device, k_ns_dev_desc_len, k_ra8_err_hw_error, k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().
Referenced by ns_host_enum_hunt().
|
staticnodiscard |
Open the host bulk pipes for the device's CDC data endpoints.
| k_ra8_ok | Both bulk pipes configured. |
Definition at line 303 of file ns_usb_host.c.
References k_ns_dev_addr, k_ns_ep_in_num, k_ns_ep_out_num, k_ns_host_pipe_in, k_ns_host_pipe_out, k_ns_mps, k_ra8_ok, k_ra8_usb_speed_hs, and ra8_usb_host_pipe_setup().
Referenced by ns_host_enumerate().
|
static |
Fill an echo payload with this round's deterministic bytes.
Byte i = (round*97 + i*7 + 0x5A) & 0xFF – distinct per round so the host proves it read back what it sent for that round.
| [in] | round | The echo round index. |
| [out] | out | Destination buffer. |
| [in] | len | Bytes to fill. |
out has len writable bytes. len is at most k_ns_payload. out[0..len-1] hold the round's pattern bytes. Definition at line 159 of file ns_usb_host.c.
References k_ns_byte_mask, k_ns_pat_bias, k_ns_pat_idx_mul, and k_ns_pat_round_mul.
Referenced by ns_host_echo_round().
|
staticnodiscard |
SET_ADDRESS to k_ns_dev_addr, then retarget the DCP.
| k_ra8_ok | The DCP now targets the operating address. |
Definition at line 252 of file ns_usb_host.c.
References k_ns_addr_settle_ms, k_ns_bm_std_dev_out, k_ns_breq_set_addr, k_ns_dev_addr, k_ra8_ok, k_ra8_usb_speed_hs, ra8_delay_ms(), ra8_usb_host_control_xfer(), and ra8_usb_host_set_target().
Referenced by ns_host_enumerate().
|
staticnodiscard |
SET_CONFIGURATION(::k_ns_config_value) on the addressed device.
| k_ra8_ok | The device entered the Configured state. |
Definition at line 280 of file ns_usb_host.c.
References k_ns_bm_std_dev_out, k_ns_breq_set_config, k_ns_config_value, k_ra8_usb_speed_hs, and ra8_usb_host_control_xfer().
Referenced by ns_host_enumerate().
| VOID ns_host_worker | ( | ULONG | arg | ) |
HS host worker – enumerate the looped FS device, then echo forever.
Defined in ns_usb_host.c; forwarded here so the single tx_application_define in ns_usb.c can pass it to tx_thread_create. Enumerates the FS CDC device over the J7 loop cable (GET_DESCRIPTOR / SET_ADDRESS / SET_CONFIGURATION), opens the bulk pipes, then bulk round-trips a deterministic pattern forever, advancing g_tz_usb_host_rounds_ok (the HIL gate).
| [in] | arg | Unused (ThreadX entry signature). |
Definition at line 398 of file ns_usb_host.c.
References g_tz_usb_host_err, g_tz_usb_host_phase, g_tz_usb_host_pid, g_tz_usb_host_rounds_ok, k_ns_boot_wait_tk, k_ns_retry_tk, k_ra8_ok, k_ra8_usb_speed_hs, ns_host_echo_round(), ns_host_enumerate(), ra8_usb_host_deinit(), ra8_usb_host_init(), and tx_thread_sleep.
Referenced by tx_application_define().
| volatile uint32_t g_tz_usb_host_err |
First non-OK ra8_err_t from the host ladder (0 = none yet).
Definition at line 75 of file ns_usb_host.c.
Referenced by ns_host_worker().
| volatile uint32_t g_tz_usb_host_phase |
HS-host ladder phase: 0 boot, 1 host-init, 2 enumerating, 3 echoing, 4 first full pass done.
Definition at line 50 of file ns_usb_host.c.
Referenced by ns_host_worker().
| volatile uint32_t g_tz_usb_host_pid |
idProduct the HS host read from the looped FS device (expect 0x000A).
Definition at line 58 of file ns_usb_host.c.
Referenced by ns_host_worker().
| volatile uint32_t g_tz_usb_host_rounds_ok |
Bulk echo rounds the HS host has verified byte-equal (advances forever once the loop is healthy – the HIL gate probes this).
Definition at line 67 of file ns_usb_host.c.
Referenced by ns_host_worker().
| UCHAR s_ns_host_stack[k_ns_host_stack_bytes] |
Stack backing storage for s_ns_host_thread (defined in ns_usb_host.c).
Stack backing storage for s_ns_host_thread.
Sized by k_ns_host_stack_bytes; passed verbatim by the spawner.
Definition at line 95 of file ns_usb_host.c.
Referenced by tx_application_define().
| TX_THREAD s_ns_host_thread |
ThreadX TCB for the HS host worker (defined in ns_usb_host.c).
ThreadX TCB for the HS host worker.
Spawned by tx_application_define in ns_usb.c; the host worker itself runs from ns_usb_host.c. Declared here so the spawner TU can reference the storage.
Definition at line 88 of file ns_usb_host.c.
Referenced by tx_application_define().
| CHAR s_ns_host_thread_name[] = "ns_usb_host" |
HS host worker thread name (defined in ns_usb_host.c; ThreadX CHAR*).
HS host worker thread name (writable NS data; ThreadX name is CHAR*).
Writable NS data because ThreadX's name_ptr field is CHAR*.
Definition at line 102 of file ns_usb_host.c.
Referenced by tx_application_define().