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
27
28#include <stdint.h>
29
30#include "ra8_attributes.h"
31#include "ra8_board_ek_ra8d2.h"
32#include "ra8_boot_entry.h"
33#include "ra8_cgc.h"
34#include "ra8_err.h"
35#include "ra8_isr.h"
36#include "ra8_time.h"
37#include "ra8_ulpt.h"
38
40typedef enum : uint32_t {
41 k_ulpt_demo_baud = 115200U,
43 /* 32 768 LOCO ticks ~= 1 s (chosen so the period fits in the
44 * 32-bit reload field while still being legible at host-test scale). */
47
49typedef enum : uint8_t {
53
54static const uint8_t s_ulpt_demo_log_msg[] = "ulpt: wake ok\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 }
104 if (ra8_ulpt_init() != k_ra8_ok) {
106 }
107}
108
131[[nodiscard]] RA8_INTERNAL static ra8_err_t internal_arm(void)
132{
134}
135
150void main(void)
151{
154
155 if (internal_arm() != k_ra8_ok) {
157 }
158
159 while (1) {
160 uint8_t status = 0U;
161 if (ra8_ulpt_get_status((uint8_t)k_ulpt_demo_channel, &status) != k_ra8_ok) {
162 break;
163 }
164 if ((status & (uint8_t)k_ulpt_demo_undf_bit) != 0U) {
166 (size_t)(sizeof(s_ulpt_demo_log_msg) - 1U)) != k_ra8_ok) {
167 break;
168 }
169 if (ra8_ulpt_stop((uint8_t)k_ulpt_demo_channel) != k_ra8_ok) {
170 break;
171 }
172 if (internal_arm() != k_ra8_ok) {
173 break;
174 }
175 }
177 }
179}
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_arm(void)
Configure ADC_B in 12-bit software-trigger mode.
Definition main.c:179
static const uint8_t s_ulpt_demo_log_msg[]
Definition main.c:54
ulpt_demo_const_t
Demo tunables.
Definition main.c:40
@ k_ulpt_demo_period_ticks
Ulpt demo period ticks.
Definition main.c:45
@ k_ulpt_demo_poll_ms
Ulpt demo poll ms.
Definition main.c:42
@ k_ulpt_demo_baud
Ulpt demo baud.
Definition main.c:41
ulpt_demo_chan_t
ULPT channel + status.
Definition main.c:49
@ k_ulpt_demo_undf_bit
ULPTCR.TUNDF – mirrors AGTCR layout.
Definition main.c:51
@ k_ulpt_demo_channel
Ulpt demo channel.
Definition main.c:50
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_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
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
Ultra-Low-Power Timer (ULPT) driver header.
ra8_err_t ra8_ulpt_get_status(uint8_t channel, uint8_t *out_mask)
Read ULPTCR status bits.
Definition ra8_ulpt.c:249
ra8_err_t ra8_ulpt_stop(uint8_t channel)
Stop a ULPT channel and confirm the counter has halted.
Definition ra8_ulpt.c:121
ra8_err_t ra8_ulpt_init(void)
Reset both ULPT channels to their power-on state.
Definition ra8_ulpt.c:64
ra8_err_t ra8_ulpt_start(uint8_t channel, uint32_t period)
Start a ULPT channel counting down from period.
Definition ra8_ulpt.c:93