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 "ra8_attributes.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_isr.h"
57#include "ra8_port_constants.h"
58#include "ra8_port_utils.h"
59#include "ra8_time.h"
60#include "ra8_time_constants.h"
61
63typedef enum : uint32_t {
66
85volatile uint32_t g_clock_check_match = 0U;
86
104volatile uint32_t g_clock_check_mismatch = 0U;
105
123
124/* Forward declarations -- definitions appear after main() so the
125 * audit_init_order linter sees the canonical CGC -> TIME -> peripheral
126 * sequence in source order. */
127[[nodiscard]] RA8_INTERNAL static ra8_err_t internal_clock_check_pins_init(void);
129[[nodiscard]] RA8_INTERNAL static bool internal_clock_check_verify_all(void);
130
149{
150 while (1) {
151 __asm__ volatile("wfi");
152 }
153}
154
166void main(void)
167{
168 if (ra8_cgc_init() != k_ra8_ok) {
170 }
171
172 uint32_t cpuclk0_hz = 0U;
175 }
176
177 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
179 }
180
183 }
184
186
187 while (1) {
190 break;
191 }
194 } else {
196 }
198 }
199
201}
202
220{
222 if (err != k_ra8_ok) {
223 return err;
224 }
226 if (err != k_ra8_ok) {
227 return err;
228 }
230}
231
247{
249 if (err != k_ra8_ok) {
250 return err;
251 }
253 if (err != k_ra8_ok) {
254 return err;
255 }
257}
258
281[[nodiscard]] RA8_INTERNAL static bool internal_clock_check_verify_all(void)
282{
283 const clock_check_expected_t kExpected[] = {
294 };
295 const uint32_t kExpectedCount = (uint32_t)(sizeof(kExpected) / sizeof(kExpected[0]));
296 for (uint32_t i = 0U; i < kExpectedCount; ++i) {
297 uint32_t hz = 0U;
298 if (ra8_cgc_get_clock_hz(kExpected[i].id, &hz) != k_ra8_ok) {
299 return false;
300 }
301 if (hz != kExpected[i].expected_hz) {
302 return false;
303 }
304 }
305 return true;
306}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static ra8_err_t internal_clock_check_pins_init(void)
Configure all three EK-RA8D2 user LEDs as outputs (low).
Definition main.c:219
volatile uint32_t g_clock_check_mismatch
HIL failure counter – incremented whenever any clock-tree readback disagrees with its expected target...
Definition main.c:104
clock_check_period_t
Half-period of the visible blink, in milliseconds.
Definition main.c:63
@ k_clock_check_half_period_ms
Clock check half period ms.
Definition main.c:64
static bool internal_clock_check_verify_all(void)
Verify every clock-tree readback equals its post-PLL target.
Definition main.c:281
static void internal_clock_check_panic_halt(void)
Halt forever in WFI – used as a panic stop on init failure.
Definition main.c:148
volatile uint32_t g_clock_check_match
HIL liveness counter – incremented once per blink iteration when every queried clock-tree domain (CPU...
Definition main.c:85
static ra8_err_t internal_clock_check_pins_toggle_all(void)
Toggle all three LED pins (one HAL call each).
Definition main.c:246
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).
@ k_ra8_board_led3
LED3, RED, PA07 (jumper E28).
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
ra8_clock_id_t
Identifiers for the clock-tree frequencies queryable at runtime.
Definition ra8_cgc.h:69
@ k_ra8_clock_id_pclkc
PCLKC.
Definition ra8_cgc.h:75
@ k_ra8_clock_id_fclk
Flash/MRAM interface clock.
Definition ra8_cgc.h:78
@ k_ra8_clock_id_cpuclk1
Cortex-M33 CPUCLK1.
Definition ra8_cgc.h:71
@ k_ra8_clock_id_pclkd
PCLKD.
Definition ra8_cgc.h:76
@ k_ra8_clock_id_pclkb
PCLKB.
Definition ra8_cgc.h:74
@ k_ra8_clock_id_pclke
PCLKE.
Definition ra8_cgc.h:77
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
@ k_ra8_clock_id_mriclk
MRAM bus clock.
Definition ra8_cgc.h:79
@ k_ra8_clock_id_pclka
PCLKA.
Definition ra8_cgc.h:73
@ k_ra8_clock_id_iclk
System ICLK.
Definition ra8_cgc.h:72
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
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
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
High-level GPIO helpers on top of the PORT + PFS register layer.
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
Named Time Unit Constants for Delay / Timeout / Tick Math.
@ k_ra8_mriclk_hz
MRICLK = PLL1P/4 = 250 MHz (MRAM I/F).
@ k_ra8_pclka_hz
PCLKA = PLL1P/8 = 125 MHz.
@ k_ra8_cpuclk1_hz
CPUCLK1 = PLL1P/4 = 250 MHz.
@ k_ra8_cpuclk0_hz
CPUCLK0 = PLL1P/1 = 1 GHz.
@ k_ra8_pclkb_hz
PCLKB = PLL1P/16 = 62.5 MHz.
@ k_ra8_fclk_hz
FCK (MRPCLK) = PLL1P/8 = 125 MHz.
@ k_ra8_pclkd_hz
PCLKD = PLL1P/4 = 250 MHz.
@ k_ra8_pclke_hz
PCLKE = PLL1P/4 = 250 MHz.
@ k_ra8_pclkc_hz
PCLKC = PLL1P/8 = 125 MHz.
@ k_ra8_iclk_hz
ICLK = PLL1P/4 = 250 MHz.
Pair of (clock id, expected post-PLL frequency in Hz).
Definition main.c:119
uint32_t expected_hz
Target frequency after PLL bring-up.
Definition main.c:121
ra8_clock_id_t id
Clock-tree domain identifier.
Definition main.c:120