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
40
41#include <stdint.h>
42
43#include "ra8_attributes.h"
44#include "ra8_board_ek_ra8d2.h"
45#include "ra8_boot_entry.h"
46#include "ra8_cgc.h"
47#include "ra8_elc.h"
48#include "ra8_elc_regs.h"
49#include "ra8_err.h"
50#include "ra8_isr.h"
51#include "ra8_mstp.h"
52#include "ra8_time.h"
53
55typedef enum : uint32_t {
56 k_elc_demo_baud = 115200U,
59
70
85{
86 while (1) {
87 __asm__ volatile("wfi");
88 }
89}
90
106{
107 uint32_t cpuclk0_hz = 0U;
108
109 if (ra8_cgc_init() != k_ra8_ok) {
111 }
114 }
115 if (ra8_mstp_init() != k_ra8_ok) {
117 }
118 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
120 }
123 }
124
125 if (ra8_elc_init() != k_ra8_ok) {
127 }
128 /* Route IRQ0 -> ELSR0 so a real button press would chain a GPT
129 * capture without CPU intervention; the software trigger below
130 * keeps the demo self-contained. */
133 }
134
137 }
140 }
141}
142
162RA8_INTERNAL static uint8_t internal_uint_to_dec(uint8_t* buf, uint32_t v)
163{
164 uint8_t tmp[k_elc_demo_uint_dec_max];
165 uint8_t n = 0U;
166 uint32_t r = v;
167 if (r == 0U) {
168 buf[0] = (uint8_t)k_elc_demo_ascii_zero;
169 return 1U;
170 }
171 while ((r > 0U) && (n < (uint8_t)k_elc_demo_uint_dec_max)) {
172 tmp[n] =
173 (uint8_t)((uint8_t)k_elc_demo_ascii_zero + (uint8_t)(r % (uint32_t)k_elc_demo_dec_base));
174 r = r / (uint32_t)k_elc_demo_dec_base;
175 n++;
176 }
177 for (uint8_t i = 0U; i < n; i++) {
178 buf[i] = tmp[(uint8_t)(n - 1U - i)];
179 }
180 return n;
181}
182
204RA8_INTERNAL static uint32_t internal_format_line(uint8_t* out, bool enabled, uint32_t trig_count)
205{
206 uint32_t off = 0U;
207 const uint8_t prefix[] = "elc: en=";
208 const uint8_t mid[] = " trig=";
209 const uint8_t suffix[] = "\r\n";
210 for (uint32_t i = 0U; i < sizeof(prefix) - 1U; i++) {
211 out[off++] = prefix[i];
212 }
213 out[off++] = enabled ? (uint8_t)k_elc_demo_ascii_one : (uint8_t)k_elc_demo_ascii_zero;
214 for (uint32_t i = 0U; i < sizeof(mid) - 1U; i++) {
215 out[off++] = mid[i];
216 }
217 off += internal_uint_to_dec(&out[off], trig_count);
218 for (uint32_t i = 0U; i < sizeof(suffix) - 1U; i++) {
219 out[off++] = suffix[i];
220 }
221 return off;
222}
223
235void main(void)
236{
239
240 uint32_t trig_count = 0U;
241 while (1) {
244 /* Emit FAIL banner so the HIL negative regex catches a silently
245 * broken SW-trigger path; without this the t=N counter would
246 * stop advancing but the demo would keep emitting "elc: en=1
247 * t=0" indefinitely and the probe would pass. */
248 const uint8_t trig_fail[] = "elc: FAIL trigger\r\n";
249 (void)ra8_board_uart_console_write(trig_fail, (size_t)(sizeof(trig_fail) - 1U));
250 } else {
251 trig_count++;
252 }
253 bool enabled = false;
254 if (ra8_elc_is_enabled(&enabled) != k_ra8_ok) {
256 const uint8_t enabled_fail[] = "elc: FAIL is_enabled\r\n";
257 (void)ra8_board_uart_console_write(enabled_fail, (size_t)(sizeof(enabled_fail) - 1U));
258 }
259 uint8_t out[k_elc_demo_print_buf] = {};
260 const uint32_t off = internal_format_line(out, enabled, trig_count);
261 if (ra8_board_uart_console_write(out, (size_t)off) != k_ra8_ok) {
262 break;
263 }
265 break;
266 }
268 }
269
271}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static void internal_setup_or_halt(void)
Bring up clocks, MSTP, delay timing, and the board console.
Definition main.c:211
static void internal_panic_halt(void)
Park the core after an unrecoverable ADC demo failure.
Definition main.c:123
static uint8_t internal_uint_to_dec(uint8_t *buf, uint32_t v)
Write a decimal uint32 into buf.
Definition main.c:162
elc_demo_byte_t
ELC slot / software-event indices used by the demo.
Definition main.c:61
@ k_elc_demo_uint_dec_max
Max digits in a uint32 base-10.
Definition main.c:67
@ k_elc_demo_dec_base
Elc demo dec base.
Definition main.c:66
@ k_elc_demo_print_buf
Max bytes in one print line.
Definition main.c:68
@ k_elc_demo_ascii_one
Elc demo ascii one.
Definition main.c:65
@ k_elc_demo_slot
ELSR0 – arbitrary; HUM Tbl 19.2 maps to GPT capture.
Definition main.c:62
@ k_elc_demo_ascii_zero
Elc demo ascii zero.
Definition main.c:64
@ k_elc_demo_sw_event_idx
ELSEGR0 – software event 0.
Definition main.c:63
static uint32_t internal_format_line(uint8_t *out, bool enabled, uint32_t trig_count)
Format the per-cycle "elc: en=N trig=NN\r\n" line.
Definition main.c:204
elc_demo_const_t
App-wide tunables.
Definition main.c:55
@ k_elc_demo_period_ms
Elc demo period ms.
Definition main.c:57
@ k_elc_demo_baud
Elc demo baud.
Definition main.c:56
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
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
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Event Link Controller driver.
ra8_err_t ra8_elc_link(uint8_t elsr_index, ra8_elc_event_t event)
Route an ELC event to an ELSR slot so the destination peripheral triggers on it.
Definition ra8_elc.c:127
ra8_err_t ra8_elc_is_enabled(bool *out_enabled)
Read ELCR.ELCON to verify the global enable state.
Definition ra8_elc.c:164
ra8_err_t ra8_elc_init(void)
Reset the ELC register block and enable the controller.
Definition ra8_elc.c:91
ra8_err_t ra8_elc_software_trigger(uint8_t event_index)
Fire a software event via one of the ELSEGRn registers.
Definition ra8_elc.c:147
Event Link Controller (ELC) register layout for the Renesas RA8D2.
@ k_ra8_elc_event_icu_irq0
External pin interrupt 0.
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
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