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
28
29#include <stdint.h>
30
31#include "ra8_attributes.h"
32#include "ra8_board_ek_ra8d2.h"
33#include "ra8_boot_entry.h"
34#include "ra8_cgc.h"
35#include "ra8_err.h"
36#include "ra8_gpt.h"
37#include "ra8_isr.h"
38#include "ra8_time.h"
39
46
61volatile uint32_t g_gpt_capture_tick = 0U;
62
64typedef enum : uint8_t {
67
82{
83 while (1) {
84 __asm__ volatile("wfi");
85 }
86}
87
103{
104 uint32_t cpuclk0_hz = 0U;
105 if (ra8_cgc_init() != k_ra8_ok) {
107 }
110 }
111 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
113 }
116 }
119 }
120 const ra8_gpt_cfg_t cfg = {
122 .prescaler = k_ra8_gpt_ps_div_64,
123 .period = (uint32_t)k_gpt_capture_period,
124 .duty_a = 0U,
125 .duty_b = 0U,
126 .auto_start = true,
127 };
128 if (ra8_gpt_init((uint8_t)k_gpt_capture_channel, &cfg) != k_ra8_ok) {
130 }
131}
132
150RA8_INTERNAL static uint32_t internal_read(void)
151{
152 uint32_t val = 0U;
153 if (ra8_gpt_read((uint8_t)k_gpt_capture_channel, &val) != k_ra8_ok) {
154 return UINT32_MAX;
155 }
156 return val;
157}
158
184{
187 return false;
188 }
189 bool fell = (*prev == k_ra8_board_sw_released) && (now == k_ra8_board_sw_pressed);
190 *prev = now;
191 return fell;
192}
193
208void main(void)
209{
212
214 uint32_t last_tick = 0U;
215 uint32_t prev_count = 0U;
216 bool have_prev = false;
217
218 while (1) {
219 if (internal_edge(&last_state)) {
220 const uint32_t now = internal_read();
221 const uint32_t last_delta = now - last_tick;
222 last_tick = now;
223 (void)last_delta;
225 }
226 /* Liveness check independent of SW1 -- proves GTCNT is counting
227 * even when the button isn't pressed (which it never is on the
228 * unattended HIL bench). */
229 const uint32_t now_count = internal_read();
230 if (now_count != UINT32_MAX) {
231 if (have_prev && (now_count != prev_count)) {
232 g_gpt_capture_tick += 1U;
233 }
234 prev_count = now_count;
235 have_prev = true;
236 }
238 }
240}
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_edge(ra8_board_sw_state_t *prev)
Detect a falling edge on SW1.
Definition main.c:183
static uint32_t internal_read(void)
Read current GPT counter ticks, or return UINT32_MAX on err.
Definition main.c:150
gpt_capture_layout_t
Channel + LED selection.
Definition main.c:64
@ k_gpt_capture_channel
GPT capture channel.
Definition main.c:65
volatile uint32_t g_gpt_capture_tick
HIL liveness counter – incremented every iteration where the GPT counter advanced relative to the pre...
Definition main.c:61
gpt_capture_const_t
Demo tunables.
Definition main.c:41
@ k_gpt_capture_min_delta_ms
GPT capture minimum delta ms.
Definition main.c:44
@ k_gpt_capture_poll_period_ms
GPT capture poll period ms.
Definition main.c:43
@ k_gpt_capture_period
GPT capture period.
Definition main.c:42
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_sw_read(ra8_board_sw_id_t sw, ra8_board_sw_state_t *out_pressed)
Sample the current state of sw.
ra8_err_t ra8_board_sw_init(ra8_board_sw_id_t sw)
Configure a switch pin as an input with internal pull-up.
@ k_ra8_board_sw1
SW1, P009, IRQ13-DS (jumper E31).
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
ra8_board_sw_state_t
Logical "pressed" / "released" state.
@ k_ra8_board_sw_released
RA8 board sw released.
@ k_ra8_board_sw_pressed
RA8 board sw pressed.
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
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
Full-featured General PWM Timer (GPT) driver.
@ k_ra8_gpt_mode_saw_pwm
Saw-wave PWM (up-count).
Definition ra8_gpt.h:54
ra8_err_t ra8_gpt_init(uint8_t channel, const ra8_gpt_cfg_t *cfg)
Initialise a GPT channel with a full config descriptor.
Definition ra8_gpt.c:329
ra8_err_t ra8_gpt_read(uint8_t channel, uint32_t *out)
Read the current counter value.
Definition ra8_gpt.c:314
@ k_ra8_gpt_ps_div_64
PCLKD / 64.
Definition ra8_gpt.h:69
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
Configuration descriptor for ra8_gpt_init.
Definition ra8_gpt.h:83