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

The same Wi-Fi join as c6_wifi_join, the HAL way, through ra8_wifi. More...

#include <stdint.h>
#include "nx_ether_driver_c6.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_c6link.h"
#include "ra8_cgc.h"
#include "ra8_err.h"
#include "ra8_esp_hosted_c6link.h"
#include "ra8_esp_hosted_port.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_net_provision.h"
#include "ra8_time.h"
#include "ra8_wifi.h"
#include "ra8_wifi_c6link.h"
#include "tx_api.h"
#include "wifi_hal_join.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

static void wifi_hal_panic_halt (void)
 Halt the processor after an unrecoverable start-up failure.
static void wifi_hal_setup_or_halt (void)
 Initialize platform services required by the HAL join application.
static ra8_err_t wifi_hal_make_cfg (ra8_wifi_cfg_t *out)
 Build the C6-backed Wi-Fi and NetX DHCP configuration.
static void wifi_hal_print_lease (const ra8_wifi_lease_t *lease)
 Print the non-secret fields of one DHCP lease.
static bool wifi_hal_report (const wifi_hal_result_t *res, bool joined)
 Report one completed HAL journey and derive its terminal verdict.
static bool wifi_hal_run (const ra8_net_credentials_t *credentials)
 Execute the HAL network journey with runtime credentials.
static void wifi_hal_heartbeat (bool passed)
 Preserve the terminal verdict as a periodic console heartbeat.
static void wifi_hal_worker_entry (ULONG thread_input)
 Run runtime provisioning, the HAL journey, erasure, and heartbeat.
void tx_application_define (void *first_unused_memory)
 ThreadX define hook: bring the port up and start the worker.
void main (void)
 Application entry: clocks, console, banner, then ThreadX.

Variables

static uint32_t s_cpuclk_hz
 Cached CPUCLK0 rate.
static uint32_t s_pclka_hz
 Cached PCLKA rate.
static ra8_err_t s_init_err = k_ra8_err_not_initialized
 Port-init result from tx_application_define.
static TX_THREAD s_worker
 Application worker thread.
static CHAR s_worker_name [] = "wifi_hal_join"
 Worker thread name.
static UCHAR s_worker_stack [k_wifi_hal_worker_stack]
 Worker thread stack.
static uint8_t s_arena [k_wifi_hal_arena_bytes]
 Decode arena handed to the backend.
static ra8_c6link_t s_link
 The one C6 link handle this app owns.
static ra8_wifi_c6link_t s_c6
 The ESP32-C6 ra8_wifi backend context.
static ra8_wifi_t s_wifi
 The Wi-Fi handle every operation goes through.
static const ra8_net_provision_uart_t s_provision_uart
 Board-console binding for the shared runtime provisioner.

Detailed Description

The same Wi-Fi join as c6_wifi_join, the HAL way, through ra8_wifi.

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

A deliberate side-by-side with c6_wifi_join (kept unchanged next door): both associate the ESP32-C6 station with the bench access point and obtain a DHCP lease, but this one does it through the ra8_wifi facade. The whole network journey is six calls – ra8_wifi_c6link_setup, ra8_wifi_init, ra8_wifi_connect, ra8_wifi_wait_ip, plus ra8_wifi_get_mac and ra8_wifi_get_ap for the printout – with no ra8_c6link handle poked, no RPC sequence, no event callback and no station config struct in sight. The one thing the facade cannot own, obtaining an IP, is a caller-supplied provider: wifi_hal_ip_bind wraps NetX Duo's DHCP client.

The credential-free image accepts one bounded runtime provisioning record over the board console and erases it after the synchronous network journey.

Since
0.1.0

Definition in file main.c.

Function Documentation

◆ main()

void main ( void )

Application entry: clocks, console, banner, then ThreadX.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler has copied .data and zeroed .bss.
SystemInit has set VTOR, the FPU and the priority grouping.
Postcondition
The banner was printed exactly once.
Control passed to ThreadX and never came back.
Note
Everything after tx_kernel_enter runs on ThreadX; the panic-halt below is reached only if the kernel refuses to start.
Since
0.1.0

Definition at line 396 of file main.c.

References ra8_isr_globals_enable(), s_cpuclk_hz, s_pclka_hz, wifi_hal_panic_halt(), wifi_hal_print_banner(), wifi_hal_puts(), and wifi_hal_setup_or_halt().

◆ tx_application_define()

void tx_application_define ( void * first_unused_memory)

ThreadX define hook: bring the port up and start the worker.

Parameters
[in]first_unused_memoryFree RAM from the ThreadX port; unused, every object here is static.
Returns
Nothing.
Precondition
tx_kernel_enter has been called and the clock cache is valid.
No vendored esp-hosted entry point has been called yet.
Postcondition
s_init_err holds the exact port-init result.
Exactly one worker thread was created.
Note
The port creates ThreadX objects, so its init must run where ThreadX permits object creation – here, not from main.
Since
0.1.0

Definition at line 360 of file main.c.

References k_ra8_board_pmod1_sci_channel, k_wifi_hal_edge_poll_ms, k_wifi_hal_sck_hz, k_wifi_hal_worker_prio, ra8_esp_hosted_port_init(), s_init_err, s_pclka_hz, s_worker, s_worker_name, s_worker_stack, TX_AUTO_START, TX_NO_TIME_SLICE, TX_SUCCESS, tx_thread_create, wifi_hal_puts(), and wifi_hal_worker_entry().

◆ wifi_hal_heartbeat()

void wifi_hal_heartbeat ( bool passed)
static

Preserve the terminal verdict as a periodic console heartbeat.

Emits the immutable pass or fail line and sleeps for the fixed heartbeat period forever after the Wi-Fi journey completes.

Parameters
[in]passedFinal application verdict.
Returns
Never returns.
Precondition
The console and ThreadX scheduler are operational.
No further network setup step is required.
Postcondition
The selected verdict is never changed.
Each loop iteration yields through tx_thread_sleep.
Note
Not thread-safe; this consumes the worker thread permanently.
Since
0.1.0

Definition at line 291 of file main.c.

References k_wifi_hal_heartbeat_ms, tx_thread_sleep, and wifi_hal_puts().

Referenced by wifi_hal_worker_entry().

◆ wifi_hal_make_cfg()

ra8_err_t wifi_hal_make_cfg ( ra8_wifi_cfg_t * out)
static

Build the C6-backed Wi-Fi and NetX DHCP configuration.

Binds ESP-hosted transport into the fixed-arena C6 backend, connects that backend to the facade configuration, and installs DHCP binding.

Parameters
[out]outWi-Fi facade configuration destination.
Returns
Repository error code.
Return values
k_ra8_okThe complete configuration was bound.
otherTransport binding or backend setup error propagated unchanged.
Precondition
out is non-null and writable.
ESP-hosted platform initialization completed successfully.
Postcondition
Success initializes the backend, DHCP callback, and callback context.
Failure leaves no active Wi-Fi journey.
Note
Not thread-safe; called once by the worker.
Since
0.1.0

Definition at line 142 of file main.c.

References ra8_wifi_c6link_cfg::arena, ra8_wifi_c6link_cfg::arena_bytes, ra8_wifi_cfg::ip_bind, ra8_wifi_cfg::ip_ctx, k_ra8_ok, ra8_wifi_c6link_cfg::link, nx_ether_driver_c6_rx(), ra8_esp_hosted_c6link_bind(), ra8_wifi_c6link_setup(), ra8_wifi_c6link_cfg::rx_cb, s_arena, s_c6, s_link, ra8_wifi_c6link_cfg::transport, and wifi_hal_ip_bind().

Referenced by wifi_hal_run().

◆ wifi_hal_panic_halt()

void wifi_hal_panic_halt ( void )
static

Halt the processor after an unrecoverable start-up failure.

Executes wait-for-interrupt forever so failed platform or kernel initialization cannot fall through into a partial network journey.

Returns
Never returns.
Precondition
A terminal start-up failure was detected.
Interrupt state is safe for an indefinite wait.
Postcondition
No application operation executes after entry.
The processor remains in the bounded halt loop.
Note
Not thread-safe; this is a terminal single-context path.
Since
0.1.0

Definition at line 86 of file main.c.

Referenced by main(), and wifi_hal_setup_or_halt().

◆ wifi_hal_print_lease()

void wifi_hal_print_lease ( const ra8_wifi_lease_t * lease)
static

Print the non-secret fields of one DHCP lease.

Emits address, mask, gateway, and DHCP server in dotted-quad form through bounded console helpers.

Parameters
[in]leaseBound lease record to print.
Returns
Nothing.
Precondition
lease is non-null and initialized.
The board console is initialized.
Postcondition
Every lease address field is emitted once.
No credential-bearing data is emitted.
Note
Not thread-safe; the worker is the sole caller.
Since
0.1.0

Definition at line 175 of file main.c.

References ra8_wifi_lease::dhcp_server, ra8_wifi_lease::gateway, ra8_wifi_lease::ip, ra8_wifi_lease::mask, wifi_hal_put_ip(), and wifi_hal_puts().

Referenced by wifi_hal_report().

◆ wifi_hal_report()

bool wifi_hal_report ( const wifi_hal_result_t * res,
bool joined )
static

Report one completed HAL journey and derive its terminal verdict.

Emits each non-secret stage result and lease while requiring the aggregate result to agree with its recorded successful stages.

Parameters
[in]resCompleted join result record.
[in]joinedAggregate verdict returned by wifi_hal_join_run.
Returns
Final reported verdict.
Return values
trueEvery stage and the aggregate verdict succeeded.
falseInitialization, association, DHCP, or aggregate verdict failed.
Precondition
res is non-null and initialized by wifi_hal_join_run.
The console is initialized.
Postcondition
A failed stage emits one non-secret failure line.
Success emits association and lease information without SSID or PSK.
Note
Not thread-safe; the worker is the sole caller.
Since
0.1.0

Definition at line 244 of file main.c.

References wifi_hal_result::ap, wifi_hal_result::associated, ra8_wifi_ap::channel, wifi_hal_result::connect_err, wifi_hal_result::init_err, wifi_hal_result::init_ok, wifi_hal_result::ip_bound, wifi_hal_result::ip_err, wifi_hal_result::lease, wifi_hal_result::mac, ra8_err_to_str(), wifi_hal_print_lease(), wifi_hal_put_mac(), wifi_hal_put_u32(), and wifi_hal_puts().

Referenced by wifi_hal_run().

◆ wifi_hal_run()

bool wifi_hal_run ( const ra8_net_credentials_t * credentials)
static

Execute the HAL network journey with runtime credentials.

Builds the hardware configuration, passes the caller-owned runtime strings into the host-tested orchestration, and reports its result.

Parameters
[in]credentialsValidated runtime SSID and PSK record.
Returns
Journey outcome.
Return values
trueAssociation and DHCP completed.
falseHardware binding, initialization, association, or DHCP failed.
Precondition
credentials is non-null and contains validated fields.
ESP-hosted initialization completed successfully.
Postcondition
The shared journey has synchronously consumed the credential strings.
No credential-bearing field is written to the console.
Note
Not thread-safe; called once by the worker.
Since
0.1.0

Definition at line 205 of file main.c.

References k_ra8_ok, k_wifi_hal_assoc_polls, ra8_net_credentials::psk, ra8_err_to_str(), s_wifi, ra8_net_credentials::ssid, wifi_hal_join_run(), wifi_hal_make_cfg(), wifi_hal_puts(), and wifi_hal_report().

Referenced by wifi_hal_worker_entry().

◆ wifi_hal_setup_or_halt()

void wifi_hal_setup_or_halt ( void )
static

Initialize platform services required by the HAL join application.

Brings up clocks, caches live rates, enables module-stop control, initializes delay timing, and opens the console in dependency order.

Returns
Nothing after successful initialization; failures halt permanently.
Precondition
Reset-time clock and board state is available.
No worker or Wi-Fi operation has started.
Postcondition
Live CPUCLK0 and PCLKA rates are cached.
Timing and board-console services are initialized on return.
Note
Not thread-safe; call exactly once during boot.
Since
0.1.0

Definition at line 105 of file main.c.

References k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, k_wifi_hal_uart_baud, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), ra8_time_init(), s_cpuclk_hz, s_pclka_hz, and wifi_hal_panic_halt().

Referenced by main().

◆ wifi_hal_worker_entry()

void wifi_hal_worker_entry ( ULONG thread_input)
static

Run runtime provisioning, the HAL journey, erasure, and heartbeat.

Refuses a failed port, receives one bounded record, passes it through the synchronous HAL journey, erases it, and enters terminal heartbeat.

Parameters
[in]thread_inputUnused ThreadX entry argument.
Returns
Nothing on provisioning failure; successful receives enter heartbeat.
Precondition
ThreadX started this worker after tx_application_define.
s_init_err contains the ESP-hosted initialization result.
Postcondition
The credential record is erased before return or heartbeat.
No credential-bearing field is written to the console.
Note
Not thread-safe; this is the application's sole worker thread.
Since
0.1.0

Definition at line 312 of file main.c.

References k_ra8_net_provision_timeout_ms, k_ra8_ok, k_wifi_hal_boot_wait_ms, k_wifi_hal_fail_line, k_wifi_hal_pass_line, ra8_delay_ms(), ra8_err_to_str(), ra8_net_provision_clear(), ra8_net_provision_receive(), s_init_err, s_provision_uart, wifi_hal_heartbeat(), wifi_hal_puts(), and wifi_hal_run().

Referenced by tx_application_define().

Variable Documentation

◆ s_arena

uint8_t s_arena[k_wifi_hal_arena_bytes]
static

Decode arena handed to the backend.

Since
0.1.0

Definition at line 60 of file main.c.

◆ s_c6

ra8_wifi_c6link_t s_c6
static

The ESP32-C6 ra8_wifi backend context.

Since
0.1.0

Definition at line 64 of file main.c.

Referenced by wifi_hal_make_cfg().

◆ s_cpuclk_hz

uint32_t s_cpuclk_hz
static

Cached CPUCLK0 rate.

Since
0.1.0

Definition at line 48 of file main.c.

◆ s_init_err

ra8_err_t s_init_err = k_ra8_err_not_initialized
static

Port-init result from tx_application_define.

Since
0.1.0

Definition at line 52 of file main.c.

◆ s_link

ra8_c6link_t s_link
static

The one C6 link handle this app owns.

Since
0.1.0

Definition at line 62 of file main.c.

◆ s_pclka_hz

uint32_t s_pclka_hz
static

Cached PCLKA rate.

Since
0.1.0

Definition at line 50 of file main.c.

◆ s_provision_uart

const ra8_net_provision_uart_t s_provision_uart
static
Initial value:
= {
.wait_ms = ra8_delay_ms,
}
ra8_err_t ra8_board_uart_console_read(uint8_t *out, size_t cap, size_t *out_len)
Polled non-blocking read from the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129

Board-console binding for the shared runtime provisioner.

Since
0.1.0

Definition at line 68 of file main.c.

◆ s_wifi

ra8_wifi_t s_wifi
static

The Wi-Fi handle every operation goes through.

Since
0.1.0

Definition at line 66 of file main.c.

Referenced by wifi_hal_run().

◆ s_worker

TX_THREAD s_worker
static

Application worker thread.

Since
0.1.0

Definition at line 54 of file main.c.

◆ s_worker_name

CHAR s_worker_name[] = "wifi_hal_join"
static

Worker thread name.

Since
0.1.0

Definition at line 56 of file main.c.

◆ s_worker_stack

UCHAR s_worker_stack[k_wifi_hal_worker_stack]
static

Worker thread stack.

Since
0.1.0

Definition at line 58 of file main.c.