64static const char*
s_tag =
"cac_demo";
67typedef enum : uint32_t {
80typedef enum : uint32_t {
98typedef enum : uint8_t {
152 __asm__
volatile(
"wfi");
188 uint32_t cpuclk0_hz = 0U;
239 const uint16_t upper = (uint16_t)(expected + tol);
240 const uint16_t lower = (uint16_t)(expected - tol);
285 const uint8_t meas_ok = (meas ==
k_ra8_ok) ? 1U : 0U;
298 *out_ok = (meas_ok != 0U && ferrf == 0U && ovff == 0U) ? 1U : 0U;
317 const uint8_t good = (err ==
k_ra8_ok && ok != 0U) ? 1U : 0U;
void main(void)
Secure fallback main entry point.
static void internal_setup_or_halt(void)
Bring up clocks, MSTP, delay timing, and the board console.
static void internal_panic_halt(void)
Park the core after an unrecoverable ADC demo failure.
cac_demo_calc_t
Clock-pair arithmetic for the expected count + window.
@ k_cac_demo_loco_hz
LOCO oscillator (CACLCLK).
@ k_cac_demo_ref_div
CACR2.RCDS = 00 -> reference /32.
@ k_cac_demo_main_hz
EK-RA8D2 main oscillator (CACMCLK).
@ k_cac_demo_tol_shift
Window half-width = expected >> 4.
volatile uint32_t g_cac_heartbeat
Bumps once per main-loop pass – liveness for headless probes.
volatile uint32_t g_cac_status
Last CASTR snapshot (FERRF | MENDF | OVFF bits).
static ra8_err_t internal_configure(void)
Programme CAC limits + the MAIN-vs-LOCO clock pair.
static uint32_t internal_expected(void)
Calculate the expected MAIN-vs-LOCO/32 edge count.
volatile uint32_t g_cac_ok
1 when the last measurement completed inside the window.
volatile uint32_t g_cac_count
Raw CACNTBR count captured on the last successful measurement.
static ra8_err_t internal_sample(uint8_t *out_ok)
Run one measurement and fold the result into the verdict.
cac_demo_config_t
Compile-time settings.
@ k_cac_demo_baud
SCI8 baud rate.
@ k_cac_demo_period_ms
Delay between measurements.
static const uint8_t s_cac_demo_bad_msg[]
cac_demo_cacr_t
Direct CACR1 / CACR2 values selecting the MAIN-vs-LOCO clock pair.
@ k_cac_demo_cacr1_main
Target = main osc, /1, rising.
@ k_cac_demo_cacr2_loco
Reference = LOCO /32, internal.
static const uint8_t s_cac_demo_ok_msg[]
Output line tags.
static const char * s_tag
Logging / check tag.
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).
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.
Clock Accuracy Check driver.
ra8_err_t ra8_cac_init(uint16_t upper, uint16_t lower)
Programme CAC with upper + lower bounds on measured cycles.
@ k_ra8_cac_status_ferrf
Frequency error (CASTR bit 0).
@ k_ra8_cac_status_ovff
Counter overflow (CASTR bit 2).
ra8_err_t ra8_cac_measure(uint16_t *out_count)
Kick off a CAC measurement and wait for completion.
ra8_err_t ra8_cac_get_status(uint8_t *out_mask)
Read the CASTR flag bits.
Clock Accuracy Check (CAC) register layout for the Renesas RA8D2.
static volatile r_cac_regs_t * ra8_cac(void)
Get pointer to the CAC block.
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.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
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.
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.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
volatile uint8_t CACR2
+0x02 Control 2.
volatile uint8_t CACR1
+0x01 Control 1.