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
36
37#include <stdint.h>
38
39#include "ra8_attributes.h"
40#include "ra8_board_ek_ra8d2.h"
41#include "ra8_boot_entry.h"
42#include "ra8_cgc.h"
43#include "ra8_err.h"
44#include "ra8_isr.h"
45#include "ra8_iwdt.h"
46#include "ra8_reset.h"
47#include "ra8_time.h"
48
50typedef enum : uint32_t {
51 k_ms_per_sec = 1000U,
53
54typedef enum : uint32_t {
55 k_wdt_demo_baud = 115200U,
59
61static const uint8_t s_wdt_demo_msg_pwr[] = "wdt: boot reason=power_on\r\n";
63static const uint8_t s_wdt_demo_msg_wdt[] = "wdt: boot reason=iwdt\r\n";
65static const uint8_t s_wdt_demo_msg_other[] = "wdt: boot reason=other\r\n";
67static const uint8_t s_wdt_demo_msg_stop[] = "wdt: stopping refresh, expect reset\r\n";
68
86{
87 while (1) {
88 __asm__ volatile("wfi");
89 }
90}
91
117 uint32_t* out_len)
118{
119 if (cause == k_ra8_reset_cause_power_on) {
120 *out_len = (uint32_t)(sizeof(s_wdt_demo_msg_pwr) - 1U);
121 return s_wdt_demo_msg_pwr;
122 }
123 if (cause == k_ra8_reset_cause_iwdt) {
124 *out_len = (uint32_t)(sizeof(s_wdt_demo_msg_wdt) - 1U);
125 return s_wdt_demo_msg_wdt;
126 }
127 *out_len = (uint32_t)(sizeof(s_wdt_demo_msg_other) - 1U);
129}
130
149{
150 uint32_t cpuclk0_hz = 0U;
151 if (ra8_cgc_init() != k_ra8_ok) {
153 }
156 }
157 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
159 }
160 if (ra8_reset_init() != k_ra8_ok) {
162 }
165 }
168 }
169 if (ra8_iwdt_init() != k_ra8_ok) {
171 }
172}
173
174void main(void)
175{
178
180 (void)ra8_reset_get_cause(&cause);
181 uint32_t msg_len = 0U;
182 const uint8_t* msg = internal_wdt_demo_banner_for(cause, &msg_len);
183 (void)ra8_board_uart_console_write(msg, (size_t)msg_len);
184
185 /* Stage 1: refresh for ``alive_seconds`` seconds. */
186 const uint32_t refreshes_per_sec = k_ms_per_sec / (uint32_t)k_wdt_demo_refresh_ms;
187 const uint32_t total_refreshes = (uint32_t)k_wdt_demo_alive_seconds * refreshes_per_sec;
188 for (uint32_t i = 0U; i < total_refreshes; ++i) {
192 }
193
194 /* Stage 2: stop refreshing and let the IWDT underflow reset us. */
196 (size_t)(sizeof(s_wdt_demo_msg_stop) - 1U));
197 while (1) {
198 __asm__ volatile("wfi");
199 }
200}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static const uint8_t s_wdt_demo_msg_wdt[]
Banner emitted when the cause is iwdt (we tripped).
Definition main.c:63
static const uint8_t s_wdt_demo_msg_pwr[]
Banner emitted when the cause is power_on.
Definition main.c:61
static const uint8_t s_wdt_demo_msg_stop[]
Logged just before the demo stops feeding the IWDT.
Definition main.c:67
static const uint8_t * internal_wdt_demo_banner_for(ra8_reset_cause_t cause, uint32_t *out_len)
Pick the right banner string for cause.
Definition main.c:116
wdt_demo_time_unit_t
Time-unit conversion.
Definition main.c:50
@ k_ms_per_sec
Milliseconds per second.
Definition main.c:51
static void internal_wdt_demo_panic_halt(void)
Park the processor after an unrecoverable watchdog demo failure.
Definition main.c:85
wdt_demo_const_t
Definition main.c:54
@ k_wdt_demo_baud
Wdt demo baud.
Definition main.c:55
@ k_wdt_demo_refresh_ms
Wdt demo refresh ms.
Definition main.c:56
@ k_wdt_demo_alive_seconds
Wdt demo alive seconds.
Definition main.c:57
static void internal_wdt_demo_setup_or_halt(void)
Initialize clocks, reset-cause decoding, console, and status LED.
Definition main.c:148
static const uint8_t s_wdt_demo_msg_other[]
Banner emitted for any other cause.
Definition main.c:65
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
void ra8_iwdt_refresh_deferred(void)
Refresh the IWDT counter via a wrapper function.
Definition ra8_iwdt.c:94
Reset cause introspection + software reset trigger.
ra8_err_t ra8_reset_get_cause(ra8_reset_cause_t *out)
Decode the latched RSTSRn flags into a single primary cause.
Definition ra8_reset.c:326
ra8_err_t ra8_reset_init(void)
Snapshot the reset cause at boot.
Definition ra8_reset.c:310
ra8_reset_cause_t
Decoded reset-cause taxonomy.
Definition ra8_reset.h:93
@ k_ra8_reset_cause_power_on
RSTSR0.PORF.
Definition ra8_reset.h:95
@ k_ra8_reset_cause_unknown
No flag latched.
Definition ra8_reset.h:94
@ k_ra8_reset_cause_iwdt
RSTSR1.IWDTRF.
Definition ra8_reset.h:105
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