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
47
48#include <stdint.h>
49
50#include "c6_fwver.h"
51#include "esp_hosted_interface.h"
52#include "ra8_board_ek_ra8d2.h"
53#include "ra8_boot_entry.h"
54#include "ra8_cgc.h"
55#include "ra8_err.h"
56#include "ra8_esp_hosted_port.h"
57#include "ra8_isr.h"
58#include "ra8_mstp.h"
59#include "ra8_time.h"
60#include "tx_api.h"
61
79typedef enum : uint16_t {
82
91static uint32_t s_c6_fwver_cpuclk_hz;
92
103static uint32_t s_c6_fwver_pclka_hz;
104
116
127
138static CHAR s_c6_fwver_worker_name[] = "c6_fw_version";
139
150
162
173static void c6_fwver_panic_halt(void)
174{
175 while (1) {
176 __asm__ volatile("wfi");
177 }
178}
179
214
228static void c6_fwver_phase_caps(void)
229{
230 uint16_t len = 0U;
231 const ra8_err_t err =
233 c6_fwver_puts("c6_fwver: host caps build=");
235 c6_fwver_puts(" bytes=");
236 c6_fwver_put_u32((uint32_t)len);
237 c6_fwver_puts("\r\n");
238 if (err != k_ra8_ok) {
239 return;
240 }
241
242 c6_fwver_pump_stats_t stats = {};
243 const ra8_err_t ran = c6_fwver_link_pump((uint8_t)ESP_PRIV_IF,
244 0U,
246 len,
249 &stats);
250 c6_fwver_print_pump("caps", &stats);
251 if (ran != k_ra8_ok) {
252 c6_fwver_puts("c6_fwver: caps pump=");
254 c6_fwver_puts("\r\n");
255 }
256}
257
270static void c6_fwver_phase_request(void)
271{
272 uint16_t len = 0U;
274 c6_fwver_puts("c6_fwver: request build=");
276 c6_fwver_puts(" bytes=");
277 c6_fwver_put_u32((uint32_t)len);
278 c6_fwver_puts("\r\n");
279 if (err != k_ra8_ok) {
280 return;
281 }
282
283 c6_fwver_pump_stats_t stats = {};
284 const ra8_err_t ran = c6_fwver_link_pump((uint8_t)ESP_SERIAL_IF,
285 0U,
287 len,
288 (uint16_t)k_c6_fwver_max_transfers,
290 &stats);
291 c6_fwver_print_pump("rpc", &stats);
292 if (ran != k_ra8_ok) {
293 c6_fwver_puts("c6_fwver: rpc pump=");
295 c6_fwver_puts("\r\n");
296 }
297}
298
311static void c6_fwver_heartbeat(bool passed)
312{
313 uint32_t beat = 0U;
314 while (1) {
315 c6_fwver_puts("c6_fwver: heartbeat n=");
316 c6_fwver_put_u32(beat);
317 c6_fwver_puts(passed ? " verdict=PASS\r\n" : " verdict=FAIL\r\n");
318 beat++;
320 }
321}
322
338static void c6_fwver_worker_entry(ULONG thread_input)
339{
340 (void)thread_input;
341
342 c6_fwver_puts("c6_fwver: port_init=");
344 c6_fwver_puts("\r\n");
345
347 c6_fwver_puts("c6_fwver: FAIL port init failed -- no transaction attempted\r\n");
348 c6_fwver_heartbeat(false);
349 return;
350 }
351
355 const bool passed = c6_fwver_rpc_report();
356 ra8_esp_hosted_mem_dump("c6_fw_version");
357 c6_fwver_heartbeat(passed);
358}
359
374void tx_application_define(void* first_unused_memory)
375{
376 (void)first_unused_memory;
377
378 const ra8_esp_hosted_port_cfg_t cfg = {
379 .pclk_hz = s_c6_fwver_pclka_hz,
380 .sck_hz = (uint32_t)k_c6_fwver_sck_hz,
381 .edge_poll_ms = (uint16_t)k_c6_fwver_edge_poll_ms,
382 .sci_channel = (uint8_t)k_ra8_board_pmod1_sci_channel,
383 };
385
389 0U,
396 c6_fwver_puts("c6_fwver: worker thread creation failed\r\n");
397 }
398}
399
410void main(void)
411{
414
416 c6_fwver_puts("c6_fwver: entering ThreadX; port init runs from tx_application_define\r\n");
417
418 tx_kernel_enter();
419
421}
void main(void)
Secure fallback main entry point.
Definition main.c:37
Shared contract for the esp-hosted RPC round-trip application.
ra8_err_t c6_fwver_link_pump(uint8_t if_type, uint8_t if_num, const uint8_t *payload, uint16_t payload_len, uint16_t max_transfers, c6_fwver_sink_t sink, c6_fwver_pump_stats_t *stats)
Clock full-duplex transactions until the sink is satisfied.
@ k_c6_fwver_worker_prio
Worker priority and preemption threshold.
Definition c6_fwver.h:83
@ k_c6_fwver_edge_poll_ms
Poll period for a side-band pin with no ICU channel.
Definition c6_fwver.h:74
@ k_c6_fwver_heartbeat_ms
Heartbeat gap after the verdict, in milliseconds and therefore in ThreadX ticks.
Definition c6_fwver.h:77
@ k_c6_fwver_boot_wait_ms
Settling delay before the first transaction.
Definition c6_fwver.h:76
@ k_c6_fwver_uart_baud
Console rate, 8N1, over the J-Link OB VCOM.
Definition c6_fwver.h:71
@ k_c6_fwver_worker_stack
Worker-thread stack, in bytes.
Definition c6_fwver.h:80
@ k_c6_fwver_sck_hz
SPI bit rate; the rate the port ran at on silicon in the c6_hosted_init bring-up.
Definition c6_fwver.h:72
bool c6_fwver_dispatch(uint8_t if_type, uint8_t if_num, const uint8_t *payload, uint16_t len)
Route a received frame to the module that understands it.
void c6_fwver_print_banner(uint32_t cpuclk_hz, uint32_t pclka_hz)
Print the banner: identity, clocks and SPI parameters.
ra8_err_t c6_fwver_priv_host_caps(uint8_t *out, uint16_t cap, uint16_t *out_len)
Build the host-capabilities frame the reference host sends first.
void c6_fwver_print_pump(const char *label, const c6_fwver_pump_stats_t *stats)
Print what one pump did, as one console line.
@ k_c6_fwver_max_transfers
Transactions one pump may clock before giving up.
Definition c6_fwver.h:141
@ k_c6_fwver_tx_max
Bound on any payload this application transmits: the packed RPC request and its TLV envelope are two ...
Definition c6_fwver.h:156
struct c6_fwver_pump_stats c6_fwver_pump_stats_t
ra8_err_t c6_fwver_rpc_request(uint8_t *out, uint16_t cap, uint16_t *out_len)
Build the TLV-wrapped RPC firmware-version request.
bool c6_fwver_rpc_report(void)
Print the recorded response and decide the run's verdict.
void c6_fwver_put_u32(uint32_t value)
Emit an unsigned 32-bit value in decimal.
void c6_fwver_puts(const char *text)
Write a NUL-terminated string to the board console.
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
Definition main.c:942
static void c6_fwver_worker_entry(ULONG thread_input)
Worker thread: report the init, run both phases, judge, heartbeat.
Definition main.c:338
static void c6_fwver_phase_request(void)
Send the firmware-version request and pump until it is answered.
Definition main.c:270
static ra8_err_t s_c6_fwver_init_err
Exact result of ra8_esp_hosted_port_init.
Definition main.c:115
static void c6_fwver_phase_caps(void)
Send the host-capabilities event and drain the co-processor's.
Definition main.c:228
static void c6_fwver_setup_or_halt(void)
Bring clocks, module-stop state, SysTick and the console up.
Definition main.c:193
static void c6_fwver_heartbeat(bool passed)
Print a liveness line forever, never returning.
Definition main.c:311
static CHAR s_c6_fwver_worker_name[]
Thread name handed to ThreadX.
Definition main.c:138
static uint32_t s_c6_fwver_pclka_hz
Cached PCLKA rate, the SCI baud-clock source the port divides.
Definition main.c:103
c6_fwver_pump_budget_t
Per-phase transaction budgets, so each phase bounds its own wait.
Definition main.c:79
@ k_c6_fwver_caps_transfers
Transactions the capabilities phase clocks.
Definition main.c:80
static TX_THREAD s_c6_fwver_worker
Control block of the single application thread.
Definition main.c:126
static uint32_t s_c6_fwver_cpuclk_hz
Cached CPUCLK0 rate, used to programme SysTick.
Definition main.c:91
static UCHAR s_c6_fwver_worker_stack[k_c6_fwver_worker_stack]
Stack backing s_c6_fwver_worker.
Definition main.c:149
static void c6_fwver_panic_halt(void)
Park the CPU forever after an unrecoverable bring-up failure.
Definition main.c:173
static uint8_t s_c6_fwver_txbuf[k_c6_fwver_tx_max]
Staging buffer for the one payload each phase transmits.
Definition main.c:161
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.