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
29
30#include <stdint.h>
31
32#include "ra8_attributes.h"
33#include "ra8_board_ek_ra8d2.h"
34#include "ra8_boot_entry.h"
35#include "ra8_cgc.h"
36#include "ra8_err.h"
37#include "ra8_isr.h"
38#include "ra8_iwdt.h"
39#include "ra8_time.h"
40
42typedef enum : uint32_t {
43 k_iwdt_demo_baud = 115200U,
46
48typedef enum : uint16_t {
52
53static const uint8_t s_iwdt_demo_msg_refresh[] = "iwdt: refresh in window\r\n";
54static const uint8_t s_iwdt_demo_msg_boot[] = "iwdt: poll counter\r\n";
55
70{
71 while (1) {
72 __asm__ volatile("wfi");
73 }
74}
75
90{
91 uint32_t cpuclk0_hz = 0U;
92 if (ra8_cgc_init() != k_ra8_ok) {
94 }
97 }
98 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
100 }
103 }
106 }
107}
108
132RA8_INTERNAL static bool internal_in_window(uint16_t counter)
133{
134 return (counter >= (uint16_t)k_iwdt_demo_window_low) &&
135 (counter <= (uint16_t)k_iwdt_demo_window_high);
136}
137
152void main(void)
153{
156
157 /* Boot banner -- emit immediately after setup so the HIL host can
158 * confirm the firmware booted regardless of OFS0 / IWDT state. */
160 (size_t)(sizeof(s_iwdt_demo_msg_boot) - 1U));
161
162 if (ra8_iwdt_init() != k_ra8_ok) {
164 }
165
166 while (1) {
167 uint16_t counter = 0U;
168 if (ra8_iwdt_get_counter(&counter) != k_ra8_ok) {
169 break;
170 }
171 if (internal_in_window(counter)) {
174 break;
175 }
177 break;
178 }
180 (size_t)(sizeof(s_iwdt_demo_msg_refresh) - 1U)) !=
181 k_ra8_ok) {
182 break;
183 }
184 }
186 }
188}
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 bool internal_in_window(uint16_t counter)
Decide whether the live counter sits inside the legal window.
Definition main.c:132
iwdt_demo_window_t
Window bounds in 14-bit IWDTSR.CNTVAL units (HUM 28.2.2).
Definition main.c:48
@ k_iwdt_demo_window_low
Refresh-permitted lower bound.
Definition main.c:49
@ k_iwdt_demo_window_high
Refresh-permitted upper bound.
Definition main.c:50
static const uint8_t s_iwdt_demo_msg_refresh[]
Definition main.c:53
iwdt_demo_const_t
Demo tunables.
Definition main.c:42
@ k_iwdt_demo_poll_ms
Iwdt demo poll ms.
Definition main.c:44
@ k_iwdt_demo_baud
Iwdt demo baud.
Definition main.c:43
static const uint8_t s_iwdt_demo_msg_boot[]
Definition main.c:54
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_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
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
Independent Watchdog driver header.
ra8_err_t ra8_iwdt_init(void)
Initialise the IWDT driver layer.
Definition ra8_iwdt.c:69
ra8_err_t ra8_iwdt_get_counter(uint16_t *out_counter)
Read the live 14-bit IWDT down-counter (CNTVAL).
Definition ra8_iwdt.c:124
void ra8_iwdt_refresh_deferred(void)
Refresh the IWDT counter via a wrapper function.
Definition ra8_iwdt.c:94
ra8_err_t ra8_iwdt_clear_status(void)
Clear the underflow / refresh-error flags via IWDTSR write.
Definition ra8_iwdt.c:110
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