ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
48
49#include <stdint.h>
50
51#include "c6_wifi.h"
52#include "esp_hosted_host_fw_ver.h"
53#include "esp_hosted_transport.h"
54#include "ra8_board_ek_ra8d2.h"
55#include "ra8_boot_entry.h"
56#include "ra8_c6link.h"
57#include "ra8_c6link_wifi.h"
58#include "ra8_cgc.h"
59#include "ra8_err.h"
61#include "ra8_esp_hosted_port.h"
62#include "ra8_isr.h"
63#include "ra8_mstp.h"
64#include "ra8_time.h"
65#include "transport_drv.h"
66#include "tx_api.h"
67
83typedef enum : uint32_t {
84 k_c6_wifi_expect_chip = (uint32_t)ESP_PRIV_FIRMWARE_CHIP_ESP32C6,
91
93static uint32_t s_c6_wifi_cpuclk_hz;
94
96static uint32_t s_c6_wifi_pclka_hz;
97
100
103
114static CHAR s_c6_wifi_worker_name[] = "c6_wifi_link";
115
118
131
134
145static uint32_t s_c6_wifi_events;
146
157static void c6_wifi_panic_halt(void)
158{
159 while (1) {
160 __asm__ volatile("wfi");
161 }
162}
163
197
211static void c6_wifi_on_event(void* ctx, const ra8_c6link_event_t* ev)
212{
213 (void)ctx;
215 c6_wifi_puts("c6_wifi: event kind=");
216 c6_wifi_put_u32((uint32_t)ev->kind);
217 c6_wifi_puts(" wifi_event_id=");
219 c6_wifi_puts(" reason=");
220 c6_wifi_put_u32((uint32_t)ev->reason);
221 c6_wifi_puts(" ssid=");
222 c6_wifi_put_text(ev->ssid, (size_t)ev->ssid_len);
223 c6_wifi_puts("\r\n");
224}
225
240static void c6_wifi_report_fault(const char* what, ra8_err_t err)
241{
242 ra8_c6link_fault_t fault = {};
244 c6_wifi_puts("c6_wifi: ");
245 c6_wifi_puts(what);
246 c6_wifi_puts(" failed err=");
248 c6_wifi_puts(" rpc_id=");
249 c6_wifi_put_u32(fault.rpc_id);
250 c6_wifi_puts(" coprocessor_resp=");
251 c6_wifi_put_i32(fault.resp);
252 c6_wifi_puts("\r\n");
253}
254
274{
275 if (fw_in == nullptr) {
276 c6_wifi_puts("c6_wifi: identity record missing\r\n");
277 return false;
278 }
279 const ra8_c6link_fw_version_t fw = *fw_in;
280
281 c6_wifi_puts("c6_wifi: coprocessor fw=");
283 c6_wifi_puts(".");
285 c6_wifi_puts(".");
287 c6_wifi_puts(" chip_id=0x");
289 c6_wifi_puts(" idf_target=");
290 c6_wifi_put_text(fw.target, (size_t)fw.target_len);
291 c6_wifi_puts(" expected=");
292 c6_wifi_put_u32((uint32_t)ESP_HOSTED_VERSION_MAJOR_1);
293 c6_wifi_puts(".");
294 c6_wifi_put_u32((uint32_t)ESP_HOSTED_VERSION_MINOR_1);
295 c6_wifi_puts(".");
296 c6_wifi_put_u32((uint32_t)ESP_HOSTED_VERSION_PATCH_1);
297 c6_wifi_puts("\r\n");
298
299 const bool matched = (fw.major == (uint32_t)ESP_HOSTED_VERSION_MAJOR_1) &&
300 (fw.minor == (uint32_t)ESP_HOSTED_VERSION_MINOR_1) &&
301 (fw.patch == (uint32_t)ESP_HOSTED_VERSION_PATCH_1) &&
302 (fw.chip_id == (uint32_t)k_c6_wifi_expect_chip);
303 if (!matched) {
304 c6_wifi_puts("c6_wifi: coprocessor identity is not the one this host was built against\r\n");
305 }
306 return matched;
307}
308
325static bool c6_wifi_phase_station(void)
326{
328 if (started != k_ra8_ok) {
329 c6_wifi_report_fault("wifi_start", started);
330 return false;
331 }
332 c6_wifi_puts("c6_wifi: station started (WifiInit + SetWifiMode + WifiStart accepted)\r\n");
333
334 ra8_c6link_stats_t drain = {};
335 (void)ra8_c6link_poll(&s_c6_wifi_link, (uint16_t)k_c6_wifi_drain_polls, &drain);
336 c6_wifi_print_stats("drain", &drain);
337
338 ra8_c6link_mac_t mac = {};
339 const ra8_err_t readen = ra8_c6link_wifi_mac(&s_c6_wifi_link, &mac);
340 if (readen != k_ra8_ok) {
341 c6_wifi_report_fault("wifi_mac", readen);
343 return false;
344 }
345 c6_wifi_puts("c6_wifi: station mac=");
346 c6_wifi_put_mac(&mac);
347 c6_wifi_puts("\r\n");
348
350 if (stopped != k_ra8_ok) {
351 c6_wifi_report_fault("wifi_stop", stopped);
352 return false;
353 }
354 c6_wifi_puts("c6_wifi: station stopped (WifiStop + WifiDeinit accepted)\r\n");
355 return true;
356}
357
373{
374 ra8_c6link_cfg_t cfg = {};
376 if (seam != k_ra8_ok) {
377 return seam;
378 }
380 cfg.arena_bytes = (uint32_t)sizeof(s_c6_wifi_arena);
382 cfg.cb_ctx = nullptr;
383 return ra8_c6link_open(&s_c6_wifi_link, &cfg);
384}
385
398static void c6_wifi_heartbeat(bool passed)
399{
400 uint32_t beat = 0U;
401 while (1) {
402 c6_wifi_puts("c6_wifi: heartbeat n=");
403 c6_wifi_put_u32(beat);
404 c6_wifi_puts(passed ? " verdict=PASS\r\n" : " verdict=FAIL\r\n");
405 beat++;
407 }
408}
409
432{
433 if (out == nullptr) {
434 c6_wifi_puts("c6_wifi: FAIL no identity record to fill\r\n");
435 return false;
436 }
437
438 const ra8_err_t opened = c6_wifi_open_link();
439 c6_wifi_puts("c6_wifi: link_open=");
441 c6_wifi_puts("\r\n");
442 if (opened != k_ra8_ok) {
443 c6_wifi_puts("c6_wifi: FAIL could not open the link\r\n");
444 return false;
445 }
446
447 const ra8_err_t ready =
449 c6_wifi_puts("c6_wifi: await_ready=");
451 c6_wifi_puts("\r\n");
452 if (ready != k_ra8_ok) {
453 c6_wifi_report_fault("await_ready", ready);
454 c6_wifi_puts("c6_wifi: FAIL the coprocessor did not answer the readiness probe\r\n");
455 return false;
456 }
457 return true;
458}
459
474static void c6_wifi_worker_entry(ULONG thread_input)
475{
476 (void)thread_input;
477
478 c6_wifi_puts("c6_wifi: port_init=");
480 c6_wifi_puts("\r\n");
482 c6_wifi_puts("c6_wifi: FAIL port init failed -- no transaction attempted\r\n");
483 c6_wifi_heartbeat(false);
484 return;
485 }
486
488
490 if (!c6_wifi_phase_ready(&fw)) {
491 c6_wifi_heartbeat(false);
492 return;
493 }
494
495 const bool identity = c6_wifi_phase_identity(&fw);
496 const bool station = identity && c6_wifi_phase_station();
497
498 c6_wifi_puts("c6_wifi: events_seen=");
500 c6_wifi_puts("\r\n");
501 if (station) {
502 c6_wifi_puts("c6_wifi: PASS ra8_c6link drove the coprocessor station up and read its "
503 "address\r\n");
504 } else {
505 c6_wifi_puts("c6_wifi: FAIL station bring-up through ra8_c6link did not complete\r\n");
506 }
507 ra8_esp_hosted_mem_dump("c6_wifi_link");
508 c6_wifi_heartbeat(station);
509}
510
525void tx_application_define(void* first_unused_memory)
526{
527 (void)first_unused_memory;
528
529 const ra8_esp_hosted_port_cfg_t cfg = {
530 .pclk_hz = s_c6_wifi_pclka_hz,
531 .sck_hz = (uint32_t)k_c6_wifi_sck_hz,
532 .edge_poll_ms = (uint16_t)k_c6_wifi_edge_poll_ms,
533 .sci_channel = (uint8_t)k_ra8_board_pmod1_sci_channel,
534 };
536
540 0U,
547 c6_wifi_puts("c6_wifi: worker thread creation failed\r\n");
548 }
549}
550
561void main(void)
562{
565
567 c6_wifi_puts("c6_wifi: entering ThreadX; port init runs from tx_application_define\r\n");
568
569 tx_kernel_enter();
570
572}
void main(void)
Secure fallback main entry point.
Definition main.c:37
Shared contract for the ra8_c6link facade bring-up application.
void c6_wifi_put_u32(uint32_t value)
Emit an unsigned 32-bit value in decimal.
void c6_wifi_print_stats(const char *label, const ra8_c6link_stats_t *stats)
Print what one facade poll did, as one console line.
@ k_c6_wifi_hex_byte
Hex digits printed for a byte-wide field.
Definition c6_wifi.h:98
void c6_wifi_put_i32(int32_t value)
Emit a signed 32-bit value in decimal.
void c6_wifi_put_hex(uint32_t value, uint8_t digits)
Emit a value as a fixed-width lower-case hexadecimal field.
void c6_wifi_puts(const char *text)
Write a NUL-terminated string to the board console.
void c6_wifi_put_text(const char *text, size_t len)
Emit a NUL-terminated co-processor string as printable text.
void c6_wifi_put_mac(const ra8_c6link_mac_t *mac)
Emit an IEEE 802 address as six colon-separated hexadecimal octets.
@ k_c6_wifi_sck_hz
SPI bit rate; the rate the RPC round-trip ran at on silicon.
Definition c6_wifi.h:60
@ k_c6_wifi_uart_baud
Console rate, 8N1, over the J-Link OB VCOM.
Definition c6_wifi.h:59
@ k_c6_wifi_boot_wait_ms
Settling delay before the first transaction.
Definition c6_wifi.h:64
@ k_c6_wifi_arena_bytes
Decode arena handed to the facade.
Definition c6_wifi.h:70
@ k_c6_wifi_worker_prio
Worker priority and preemption threshold.
Definition c6_wifi.h:69
@ k_c6_wifi_heartbeat_ms
Heartbeat gap after the verdict, in milliseconds and therefore in ThreadX ticks.
Definition c6_wifi.h:65
@ k_c6_wifi_edge_poll_ms
Poll period for a side-band pin with no ICU channel.
Definition c6_wifi.h:62
@ k_c6_wifi_worker_stack
Worker-thread stack, in bytes.
Definition c6_wifi.h:67
void c6_wifi_print_banner(uint32_t cpuclk_hz, uint32_t pclka_hz)
Print the banner: identity, clocks and link parameters.
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
Definition main.c:942
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
@ k_ra8_board_pmod1_sci_channel
Pmod1 (J26) Simple-SPI is SCI2.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
@ k_ra8_clock_id_pclka
PCLKA.
Definition ra8_cgc.h:73
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
const char * ra8_err_to_str(ra8_err_t err)
Human-readable string for an error code.
Definition ra8_log.c:737
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
struct ra8_esp_hosted_port_cfg ra8_esp_hosted_port_cfg_t
ra8_err_t ra8_esp_hosted_port_init(const ra8_esp_hosted_port_cfg_t *cfg)
Bring the esp-hosted port up and publish the OS-abstraction vtable.
void ra8_esp_hosted_mem_dump(const char *label)
Report transport pool occupancy at a named point.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Definition ra8_mstp.c:291
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
#define TX_SUCCESS
#define tx_thread_create
#define tx_thread_sleep
#define TX_NO_TIME_SLICE
char CHAR
ThreadX-compatible CHAR (host stub).
#define TX_AUTO_START
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Opaque thread stand-in for the host build.