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
53
54#include <stdint.h>
55
56#include "c6_probe.h"
57#include "ra8_board_ek_ra8d2.h"
58#include "ra8_boot_entry.h"
59#include "ra8_cgc.h"
60#include "ra8_err.h"
61#include "ra8_isr.h"
62#include "ra8_mstp.h"
63#include "ra8_spi.h"
64#include "ra8_time.h"
65
77
86static uint32_t s_c6_pclka_hz;
87
105
115static void c6_probe_panic_halt(void)
116{
117 while (1) {
118 __asm__ volatile("wfi");
119 }
120}
121
133static void c6_probe_clocks_or_halt(void)
134{
135 uint32_t cpuclk0_hz = 0U;
136 if (ra8_cgc_init() != k_ra8_ok) {
138 }
141 }
144 }
145 if (ra8_mstp_init() != k_ra8_ok) {
147 }
148 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
150 }
151}
152
169static void c6_probe_setup_or_halt(void)
170{
174 }
176 c6_probe_puts("c6_probe: side-band pin init failed\r\n");
178 }
181 }
184 }
185}
186
202static void c6_probe_print_map(const c6_probe_stats_t* st, uint8_t hs_idx, uint8_t dr_idx)
203{
204 if (st == nullptr) {
205 return;
206 }
207 for (uint8_t i = 0U; i < (uint8_t)k_c6_sb_count; i++) {
208 c6_probe_puts("c6_probe: evidence ");
210 c6_probe_puts(" hs_vote=");
212 c6_probe_puts(" dr_vote=");
214 c6_probe_puts(" pull_low=");
215 c6_probe_put_u32((uint32_t)st->pull_low[i]);
216 c6_probe_puts("/");
217 c6_probe_put_u32((uint32_t)st->pull_samples);
218 c6_probe_puts(" high=");
219 c6_probe_put_u32((uint32_t)st->ever_high[i]);
220 c6_probe_puts(" low=");
221 c6_probe_put_u32((uint32_t)st->ever_low[i]);
222 c6_probe_puts("\r\n");
223 }
224 c6_probe_puts("c6_probe: map HANDSHAKE=");
226 c6_probe_puts(" DATA_READY=");
228 c6_probe_puts("\r\n");
229}
230
247static void c6_probe_print_verdict(const c6_probe_stats_t* st, ra8_spi_mode_t mode, bool link_live)
248{
249 if (st == nullptr) {
250 return;
251 }
252 c6_probe_puts(link_live ? "c6_probe: PASS esp-hosted link up mode="
253 : "c6_probe: FAIL no esp-hosted frame mode=");
254 c6_probe_put_u32((uint32_t)mode);
255 c6_probe_puts(" sck_hz=");
257 c6_probe_puts(" xfers=");
259 c6_probe_puts(" data=");
261 c6_probe_puts(" idle=");
263 c6_probe_puts(" badcsum=");
265 c6_probe_puts("\r\n");
266}
267
285static void c6_probe_run(void)
286{
287 uint8_t hs_idx =
288 c6_probe_best(s_c6_stats.hs_vote, (uint8_t)k_c6_sb_count, (uint32_t)k_c6_probe_min_votes);
289 bool link_live = false;
291
292 for (uint8_t m = 0U; m < (uint8_t)k_c6_probe_mode_count && !link_live; m++) {
293 used = k_c6_mode_order[m];
294 link_live = c6_probe_sweep_mode(used, s_c6_pclka_hz, &s_c6_stats, &hs_idx);
295 }
296
297 /* Here, and not before the sweep: a freshly-booted C6 has its INIT event
298 * queued and holds DATA_READY high until a transaction drains it, so an
299 * early contest would find nothing sunk. By now the queue is empty (or the
300 * link is dead and the contest is the only evidence there is) and the
301 * chip-select has been released, which is DATA_READY's true idle state. */
303 c6_probe_puts("c6_probe: pull-up contest failed; map falls back to votes\r\n");
304 }
305
306 uint8_t dr_idx = (uint8_t)k_c6_sb_count;
307 c6_probe_resolve_map(&s_c6_stats, &hs_idx, &dr_idx);
308 c6_probe_print_map(&s_c6_stats, hs_idx, dr_idx);
309 c6_probe_print_verdict(&s_c6_stats, used, link_live);
310 if (!link_live) {
312 }
313}
314
325void main(void)
326{
329
330 c6_probe_puts("\r\nc6_probe: EK-RA8D2 <-> ESP32-C6 esp-hosted SPI probe\r\n");
331 c6_probe_puts("c6_probe: pmod1 sci2 simple-spi controller, cs on P804\r\n");
333
334 c6_sideband_sample_t idle = {};
336 c6_probe_print_sideband("c6_probe: idle sideband", &idle);
337
340
342 c6_probe_puts("c6_probe: spi pin routing failed\r\n");
344 }
345 c6_probe_run();
346
347 while (1) {
350 }
351
353}
void main(void)
Secure fallback main entry point.
Definition main.c:37
Shared contract for the EK-RA8D2 <-> ESP32-C6 esp-hosted SPI probe.
@ k_c6_sb_count
Side-band pin count.
Definition c6_probe.h:177
ra8_err_t c6_probe_spi_pins_init(void)
Route the Pmod1 SPI pins to SCI2 and own the chip-select as GPIO.
Definition c6_xfer.c:322
const char * c6_probe_sideband_name(uint8_t idx)
Name a side-band pin for the console.
@ k_c6_probe_uart_baud
Console baud (J-Link OB VCOM).
Definition c6_probe.h:71
@ k_c6_probe_boot_wait_ms
Let the C6 finish booting.
Definition c6_probe.h:73
@ k_c6_probe_idle_ms
Background heartbeat period.
Definition c6_probe.h:77
@ k_c6_probe_sck_hz
Conservative first-light SCK rate.
Definition c6_probe.h:72
void c6_probe_puts(const char *text)
Emit a bounded, NUL-terminated ASCII literal on the console.
Definition c6_console.c:25
bool c6_probe_sweep_mode(ra8_spi_mode_t mode, uint32_t pclka_hz, c6_probe_stats_t *st, uint8_t *hs_idx)
Run the transaction burst for one SPI mode.
Definition c6_xfer.c:345
void c6_probe_put_u32(uint32_t value)
Emit an unsigned integer in decimal.
Definition c6_console.c:38
void c6_probe_sample_sideband(c6_sideband_sample_t *out)
Read every Pmod1 side-band pin into one sample.
void c6_probe_print_sideband(const char *label, const c6_sideband_sample_t *s)
Print a labelled side-band sample as label P006=1 P402=0 ....
ra8_err_t c6_probe_pull_contest(c6_probe_stats_t *st)
Find which side-band pins an external driver is holding low.
@ k_c6_probe_min_votes
Votes required to claim a mapping.
Definition c6_probe.h:114
@ k_c6_probe_mode_count
SPI modes swept.
Definition c6_probe.h:107
ra8_err_t c6_probe_sideband_init(void)
Claim the four Pmod1 side-band pins as no-pull digital inputs.
uint8_t c6_probe_best(const uint32_t *votes, uint8_t ignore, uint32_t min_votes)
Pick the side-band pin that won the vote outright, or report none.
void c6_probe_wire_test(void)
Run the drive-and-release test over every Pmod1 muxed net.
uint8_t c6_probe_cs_hunt(c6_probe_stats_t *st)
Find which MCU pin the board's Pmod1 mux has wired to the C6's chip-select, and identify HANDSHAKE at...
void c6_probe_resolve_map(const c6_probe_stats_t *st, uint8_t *hs_idx, uint8_t *dr_idx)
Resolve the HANDSHAKE and DATA_READY side-band map from the accumulated evidence.
static uint32_t s_c6_pclka_hz
Cached PCLKA rate, the SCI baud-clock source.
Definition main.c:86
static void c6_probe_setup_or_halt(void)
Bring clocks, console, LEDs and side-band inputs up.
Definition main.c:169
static void c6_probe_print_verdict(const c6_probe_stats_t *st, ra8_spi_mode_t mode, bool link_live)
Print the single-line PASS / FAIL verdict.
Definition main.c:247
static const ra8_spi_mode_t k_c6_mode_order[k_c6_probe_mode_count]
SPI modes tried, most likely first.
Definition main.c:99
static void c6_probe_clocks_or_halt(void)
Bring CGC, MSTP and SysTick up, caching PCLKA.
Definition main.c:133
static void c6_probe_run(void)
Sweep the SPI modes, resolve the side-band map, report the outcome.
Definition main.c:285
static c6_probe_stats_t s_c6_stats
Accumulated probe evidence for the final verdict and pin map.
Definition main.c:76
static void c6_probe_print_map(const c6_probe_stats_t *st, uint8_t hs_idx, uint8_t dr_idx)
Print the resolved DATA_READY / HANDSHAKE side-band map.
Definition main.c:202
static void c6_probe_panic_halt(void)
Park forever after a fatal initialisation failure.
Definition main.c:115
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
ra8_err_t ra8_board_led_on(ra8_board_led_id_t led)
Drive led HIGH (light it).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
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_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
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
SPI_B controller driver (RA8D2 Type-B SPI peripheral).
ra8_spi_mode_t
CPOL / CPHA combinations.
Definition ra8_spi.h:61
@ k_ra8_spi_mode_0
CPOL=0, CPHA=0.
Definition ra8_spi.h:62
@ k_ra8_spi_mode_3
CPOL=1, CPHA=1.
Definition ra8_spi.h:65
@ k_ra8_spi_mode_1
CPOL=0, CPHA=1.
Definition ra8_spi.h:63
@ k_ra8_spi_mode_2
CPOL=1, CPHA=0.
Definition ra8_spi.h:64
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
Running evidence gathered across every transaction.
Definition c6_probe.h:280
uint8_t pull_low[k_c6_sb_count]
Reads that lost to an external sink.
Definition c6_probe.h:289
uint8_t ever_high[k_c6_sb_count]
Pin was seen high at least once.
Definition c6_probe.h:287
uint32_t hs_vote[k_c6_sb_count]
Pin dropped while CS was asserted.
Definition c6_probe.h:285
uint32_t attempts
Transactions clocked.
Definition c6_probe.h:281
uint32_t idle_frames
Idle filler frames decoded.
Definition c6_probe.h:282
uint32_t dr_vote[k_c6_sb_count]
Pin dropped once the queue drained.
Definition c6_probe.h:286
uint32_t data_frames
Real frames with a good checksum.
Definition c6_probe.h:283
uint8_t pull_samples
Pull-up reads per pin; 0 = not run.
Definition c6_probe.h:290
uint8_t ever_low[k_c6_sb_count]
Pin was seen low at least once.
Definition c6_probe.h:288
uint32_t bad_csum_frames
Sane shape, checksum mismatched.
Definition c6_probe.h:284
One simultaneous reading of every side-band pin.
Definition c6_probe.h:194