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_dma.h"
36#include "ra8_err.h"
37#include "ra8_gpt.h"
38#include "ra8_isr.h"
39#include "ra8_time.h"
40
47
49typedef enum : uint8_t {
52
63 0x00001000U,
64 0x00002000U,
65 0x00004000U,
66 0x0000FFFFU,
67};
68
77volatile uint32_t g_gpt_dma_match = 0U;
78
88volatile uint32_t g_gpt_dma_mismatch = 0U;
89
100static volatile uint8_t s_dma_done;
101
113{
114 while (1) {
115 __asm__ volatile("wfi");
116 }
117}
118
130{
131 uint32_t cpuclk0_hz = 0U;
132 if (ra8_cgc_init() != k_ra8_ok) {
134 }
137 }
138 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
140 }
143 }
144 if (ra8_dma_init() != k_ra8_ok) {
146 }
147}
148
164RA8_INTERNAL static void internal_on_complete(void* ctx)
165{
166 (void)ctx;
167 s_dma_done = 1U;
169}
170
188{
189 const ra8_gpt_cfg_t cfg = {
191 .prescaler = k_ra8_gpt_ps_div_4,
192 .period = (uint32_t)k_gpt_dma_demo_initial_period,
193 .duty_a = 0U,
194 .duty_b = 0U,
195 .auto_start = true,
196 };
197 return ra8_gpt_init((uint8_t)k_gpt_dma_demo_channel, &cfg);
198}
199
219{
220 s_dma_done = 0U;
221 uint8_t dma_chan = 0U;
222 /* ra8_gpt_write_dma succeeding proves: ra8_dma_init worked, a DMAC
223 * channel was allocated, the source / dest registers were
224 * programmed, the transfer was kicked. The completion-callback
225 * path additionally requires the per-app vector table to route
226 * the DMAC interrupt to ra8_dma's dispatcher (not wired in this
227 * app's boilerplate), so the IRQ-driven s_dma_done flag is a
228 * best-effort signal, not the gate. */
233 nullptr,
234 &dma_chan) != k_ra8_ok) {
235 return false;
236 }
237 /* Best-effort wait -- on real IRQ wiring the callback fires fast;
238 * without it the bounded wait simply elapses. */
239 enum : uint32_t { k_wait_iters = 5U };
240 for (uint32_t i = 0U; i < k_wait_iters; ++i) {
241 if (s_dma_done != 0U) {
242 break;
243 }
244 ra8_delay_ms(1U);
245 }
246 /* Manually release the channel because completion IRQ is not wired
247 * in this app's vector_table; without this each iteration leaks a
248 * channel and the 8-slot pool fills after 8 transfers. */
249 (void)ra8_dma_release(dma_chan);
250 return true;
251}
252
264void main(void)
265{
268
271 }
272
273 while (1) {
274 if (internal_run_one()) {
275 g_gpt_dma_match += 1U;
276 } else {
277 g_gpt_dma_mismatch += 1U;
278 }
280 }
282}
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_channel(void)
Init GPT0 as a saw-wave PWM with a stable initial period.
Definition main.c:187
static const uint32_t s_period_table[k_gpt_dma_demo_period_count]
Four 32-bit period values DMA streams into GPT0.GTPR.
Definition main.c:62
static bool internal_run_one(void)
Arm one DMA write of s_period_table into GPT0.GTPR.
Definition main.c:218
static void internal_on_complete(void *ctx)
DMA completion callback – raise the s_dma_done flag.
Definition main.c:164
volatile uint32_t g_gpt_dma_match
HIL liveness counter – bumped after each DMA-complete callback fires.
Definition main.c:77
volatile uint32_t g_gpt_dma_mismatch
HIL failure counter – bumped when ra8_gpt_write_dma returned non-ok or the completion callback never ...
Definition main.c:88
gpt_dma_demo_const_t
Demo tunables.
Definition main.c:42
@ k_gpt_dma_demo_initial_period
GPT DMA demo initial period.
Definition main.c:43
@ k_gpt_dma_demo_period_count
4 periods per DMA burst.
Definition main.c:44
@ k_gpt_dma_demo_rearm_delay_ms
GPT DMA demo rearm delay ms.
Definition main.c:45
gpt_dma_demo_chan_t
GPT channel.
Definition main.c:49
@ k_gpt_dma_demo_channel
GPT DMA demo channel.
Definition main.c:50
static volatile uint8_t s_dma_done
Set to 1 inside the DMA completion callback.
Definition main.c:100
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).
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
Generic DMA transfer substrate (DMAC engine).
ra8_err_t ra8_dma_init(void)
Initialise the DMA substrate.
Definition ra8_dma.c:215
ra8_err_t ra8_dma_release(uint8_t channel)
Stop a channel and return it to the free pool.
Definition ra8_dma.c:370
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.
ra8_err_t ra8_gpt_write_dma(uint8_t channel, const uint32_t *periods, uint16_t count, ra8_dma_complete_fn_t on_complete, void *ctx, uint8_t *out_dma_channel)
Stream a buffer of period values into GPT GTPR via DMA.
Definition ra8_gpt.c:463
@ 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
@ 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