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
41typedef enum : uint32_t {
42 k_gpt_pwm_demo_period = 0x0000FFFFU,
46
48typedef enum : uint8_t {
51
69volatile uint32_t g_gpt_pwm_match = 0U;
70
88volatile uint32_t g_gpt_pwm_mismatch = 0U;
89
107{
108 while (1) {
109 __asm__ volatile("wfi");
110 }
111}
112
131{
132 uint32_t cpuclk0_hz = 0U;
133 if (ra8_cgc_init() != k_ra8_ok) {
135 }
138 }
139 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
141 }
144 }
145}
146
170{
171 const ra8_gpt_cfg_t cfg = {
173 .prescaler = k_ra8_gpt_ps_div_4,
174 .period = (uint32_t)k_gpt_pwm_demo_period,
175 .duty_a = (uint32_t)0U,
176 .duty_b = (uint32_t)0U,
177 .auto_start = true,
178 };
179 return ra8_gpt_init((uint8_t)k_gpt_pwm_demo_channel, &cfg);
180}
181
182void main(void)
183{
186
189 }
190
191 uint32_t duty = 0U;
192 bool up = true;
193 uint32_t prev_count = 0U;
194 bool have_prev = false;
195 while (1) {
197 g_gpt_pwm_mismatch += 1U;
198 break;
199 }
200 uint32_t now_count = 0U;
201 if (ra8_gpt_read((uint8_t)k_gpt_pwm_demo_channel, &now_count) != k_ra8_ok) {
202 g_gpt_pwm_mismatch += 1U;
203 } else if (have_prev && (now_count == prev_count)) {
204 /* 20 ms passed but GTCNT did not move -- timer is wedged. */
205 g_gpt_pwm_mismatch += 1U;
206 prev_count = now_count;
207 } else {
208 g_gpt_pwm_match += 1U;
209 prev_count = now_count;
210 have_prev = true;
211 }
212 if (up) {
213 if (duty + (uint32_t)k_gpt_pwm_demo_step_pct >= (uint32_t)k_gpt_pwm_demo_period) {
214 duty = (uint32_t)k_gpt_pwm_demo_period;
215 up = false;
216 } else {
217 duty += (uint32_t)k_gpt_pwm_demo_step_pct;
218 }
219 } else {
220 if (duty <= (uint32_t)k_gpt_pwm_demo_step_pct) {
221 duty = 0U;
222 up = true;
223 } else {
224 duty -= (uint32_t)k_gpt_pwm_demo_step_pct;
225 }
226 }
228 }
230}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static void internal_gpt_pwm_demo_panic_halt(void)
Park the processor after an unrecoverable PWM demo failure.
Definition main.c:106
static void internal_gpt_pwm_demo_setup_or_halt(void)
Initialize clocks, timing, and the PWM demo status LED.
Definition main.c:130
gpt_pwm_demo_chan_t
GPT channel.
Definition main.c:48
@ k_gpt_pwm_demo_channel
GPT PWM demo channel.
Definition main.c:49
gpt_pwm_demo_const_t
Demo tunables.
Definition main.c:41
@ k_gpt_pwm_demo_step_pct
Duty step (>= 64 to stay in 16-bit range).
Definition main.c:44
@ k_gpt_pwm_demo_step_ms
Per-step delay -> ~1.3 s sweep.
Definition main.c:43
@ k_gpt_pwm_demo_period
16-bit period (~61 Hz at 4 MHz / 4).
Definition main.c:42
volatile uint32_t g_gpt_pwm_mismatch
HIL failure counter – incremented whenever a sub-step fails: ra8_gpt_set_duty returned non-ok,...
Definition main.c:88
volatile uint32_t g_gpt_pwm_match
HIL liveness counter – incremented every iteration in which GTCNT advanced relative to the previous s...
Definition main.c:69
static ra8_err_t internal_gpt_pwm_demo_arm(void)
Configure GPT0 for saw-wave PWM with auto_start = true.
Definition main.c:169
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_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).
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
Full-featured General PWM Timer (GPT) driver.
@ k_ra8_gpt_ccr_a
GTCCRA.
Definition ra8_gpt.h:114
ra8_err_t ra8_gpt_set_duty(uint8_t channel, ra8_gpt_ccr_sel_t which, uint32_t value)
Change one compare register (GTCCRA / GTCCRB) at runtime.
Definition ra8_gpt.c:394
@ 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_4
PCLKD / 4.
Definition ra8_gpt.h:67
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