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
24
25#include <stdint.h>
26
27#include "ra8_attributes.h"
28#include "ra8_board_ek_ra8d2.h"
29#include "ra8_boot_entry.h"
30#include "ra8_cgc.h"
31#include "ra8_doc.h"
32#include "ra8_err.h"
33#include "ra8_isr.h"
34#include "ra8_time.h"
35
37typedef enum : uint32_t {
40
42typedef enum : uint8_t {
45
47static const uint16_t s_doc_demo_operands[k_doc_demo_table_len] = {
48 0x1111U,
49 0x2222U,
50 0x3333U,
51 0x0F0FU,
52 0xF0F0U,
53 0x00FFU,
54 0xFF00U,
55 0xDEADU,
56};
57
69{
70 while (1) {
71 __asm__ volatile("wfi");
72 }
73}
74
91volatile uint32_t g_doc_match = 0U;
92
108volatile uint32_t g_doc_mismatch = 0U;
109
130RA8_INTERNAL static uint16_t internal_sw_sum(void)
131{
132 uint16_t acc = 0U;
133 for (uint8_t i = 0U; i < (uint8_t)k_doc_demo_table_len; ++i) {
134 acc = (uint16_t)(acc + s_doc_demo_operands[i]);
135 }
136 return acc;
137}
138
163[[nodiscard]] RA8_INTERNAL static ra8_err_t internal_hw_sum(uint16_t* out_sum)
164{
165 uint16_t acc = s_doc_demo_operands[0];
166 for (uint8_t i = 1U; i < (uint8_t)k_doc_demo_table_len; ++i) {
167 uint16_t partial = 0U;
168 const ra8_err_t err = ra8_doc_add16(acc, s_doc_demo_operands[i], &partial);
169 if (err != k_ra8_ok) {
170 return err;
171 }
172 acc = partial;
173 }
174 *out_sum = acc;
175 return k_ra8_ok;
176}
177
190{
191 uint32_t cpuclk0_hz = 0U;
192 if (ra8_cgc_init() != k_ra8_ok) {
194 }
197 }
198 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
200 }
203 }
206 }
207 if (ra8_doc_init() != k_ra8_ok) {
209 }
210}
211
237[[nodiscard]] RA8_INTERNAL static ra8_err_t internal_one_iter(uint8_t* out_match)
238{
239 uint16_t hw = 0U;
240 const ra8_err_t err = internal_hw_sum(&hw);
241 if (err != k_ra8_ok) {
242 return err;
243 }
244 const uint16_t sw = internal_sw_sum();
245 *out_match = (hw == sw) ? 1U : 0U;
246 return k_ra8_ok;
247}
248
260void main(void)
261{
264
265 while (1) {
266 uint8_t match = 0U;
267 const ra8_err_t err = internal_one_iter(&match);
268 if (err != k_ra8_ok) {
269 g_doc_mismatch += 1U;
271 } else if (match != 0U) {
272 g_doc_match += 1U;
274 } else {
275 g_doc_mismatch += 1U;
277 }
279 }
281}
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 ra8_err_t internal_one_iter(uint8_t *out_match)
One iteration: HW sum + SW sum + compare.
Definition main.c:237
static ra8_err_t internal_hw_sum(uint16_t *out_sum)
Hardware DOC sum: chain seven add16 calls into the accumulator.
Definition main.c:163
volatile uint32_t g_doc_mismatch
HIL failure counter – incremented every time the hardware DOC sum disagreed with the software referen...
Definition main.c:108
volatile uint32_t g_doc_match
HIL liveness counter – incremented on every iteration where the hardware DOC sum matched the software...
Definition main.c:91
static uint16_t internal_sw_sum(void)
Software reference: sum every operand modulo 2^16.
Definition main.c:130
static const uint16_t s_doc_demo_operands[k_doc_demo_table_len]
Eight 16-bit operands chained through DOC.add.
Definition main.c:47
doc_demo_const_t
Demo tunables.
Definition main.c:37
@ k_doc_demo_period_ms
Doc demo period ms.
Definition main.c:38
doc_demo_layout_t
Operand-table layout.
Definition main.c:42
@ k_doc_demo_table_len
Doc demo table length.
Definition main.c:43
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).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
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
Data Operation Circuit (DOC) driver header.
ra8_err_t ra8_doc_add16(uint16_t a, uint16_t b, uint16_t *out_sum)
Perform a 16-bit hardware add.
Definition ra8_doc.c:127
ra8_err_t ra8_doc_init(void)
Reset the DOC control register to its reset state.
Definition ra8_doc.c:103
Error Code Definitions for ra8-firmware.
@ 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
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
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