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
30
31#include <stdint.h>
32
33#include "ra8_attributes.h"
34#include "ra8_board_ek_ra8d2.h"
35#include "ra8_boot_entry.h"
36#include "ra8_cgc.h"
37#include "ra8_dmac.h"
38#include "ra8_dmac_regs.h"
39#include "ra8_err.h"
40#include "ra8_isr.h"
41#include "ra8_mstp.h"
42#include "ra8_time.h"
43
52
54typedef enum : uint8_t {
58
60static const uint8_t s_dma_demo_ok_msg[] = "dma: copied 1024B match=Y\r\n";
61static const uint8_t s_dma_demo_bad_msg[] = "dma: copied 1024B match=N\r\n";
62
64static uint32_t s_src[k_dma_demo_buf_words];
65static uint32_t s_dst[k_dma_demo_buf_words];
66
78{
79 while (1) {
80 __asm__ volatile("wfi");
81 }
82}
83
96{
97 uint32_t cpuclk0_hz = 0U;
98
99 if (ra8_cgc_init() != k_ra8_ok) {
101 }
104 }
105 if (ra8_mstp_init() != k_ra8_ok) {
107 }
108 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
110 }
113 }
116 }
119 }
120}
121
140{
141 for (uint32_t i = 0U; i < (uint32_t)k_dma_demo_buf_words; ++i) {
142 s_src[i] = i ^ (i >> (uint32_t)k_dma_demo_byte_sh);
143 s_dst[i] = 0U;
144 }
145}
146
169RA8_INTERNAL static uint8_t internal_verify(void)
170{
171 for (uint32_t i = 0U; i < (uint32_t)k_dma_demo_buf_words; ++i) {
172 if (s_dst[i] != s_src[i]) {
173 return 0U;
174 }
175 }
176 return 1U;
177}
178
208[[nodiscard]] RA8_INTERNAL static ra8_err_t internal_run_copy(void)
209{
210 const ra8_dmac_config_t cfg = {
211 .src = (uint32_t)(uintptr_t)s_src,
212 .dst = (uint32_t)(uintptr_t)s_dst,
213 .count = (uint16_t)k_dma_demo_buf_words,
214 .block_count = 1U,
215 .width = k_ra8_dmac_width_word,
216 .src_inc = true,
217 .dst_inc = true,
218 };
219 const ra8_err_t err = ra8_dmac_start_block((uint8_t)k_dma_demo_channel, &cfg);
220 if (err != k_ra8_ok) {
221 return err;
222 }
223
224 /* Software trigger: assert DMREQ.SWREQ on the channel.
225 * HUM Ch 17.2.15 p 744: write SWREQ=1 to request one block-mode
226 * transfer. SWREQ auto-clears when the controller accepts the
227 * request (CLRS=0 is the reset default). */
228 volatile r_dmac_channel_regs_t* reg = ra8_dmac((uint8_t)k_dma_demo_channel);
229 if (reg == nullptr) {
230 return k_ra8_err_hw_error;
231 }
232 reg->DMREQ = (uint8_t)k_ra8_dmreq_swreq_mask;
233
234 /* Poll DMSTS.ACT until the controller goes idle.
235 * HUM Ch 17.2.16 p 745: "When data transfer in response to one
236 * transfer request is completed" the ACT flag clears. */
237 for (uint32_t i = 0U; i < (uint32_t)k_dma_demo_poll_limit; ++i) {
238 if ((reg->DMSTS & (uint8_t)k_ra8_dmsts_act_mask) == 0U) {
239 return ra8_dmac_stop((uint8_t)k_dma_demo_channel);
240 }
241 }
242 (void)ra8_dmac_stop((uint8_t)k_dma_demo_channel);
244}
245
246void main(void)
247{
250
251 while (1) {
253 const ra8_err_t err = internal_run_copy();
254 const uint8_t ok = (err == k_ra8_ok && internal_verify() != 0U) ? 1U : 0U;
255 if (ok != 0U) {
257 (size_t)(sizeof(s_dma_demo_ok_msg) - 1U));
259 } else {
261 (size_t)(sizeof(s_dma_demo_bad_msg) - 1U));
263 }
265 }
267}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static uint32_t s_src[k_dtc_arm_buf_words]
Source / destination buffers (32-bit aligned by element type).
Definition main.c:181
static uint32_t s_dst[k_dtc_arm_buf_words]
Definition main.c:182
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_run_copy(void)
Clean src, run the DMAC block copy, then invalidate dst.
Definition main.c:277
static void internal_fill_buffers(void)
Fill s_src with a deterministic pattern; prime s_dst.
Definition main.c:201
static uint8_t internal_verify(void)
Verify s_dst matches s_src element-by-element.
Definition main.c:233
static const uint8_t s_dma_demo_ok_msg[]
Output line tags.
Definition main.c:60
static const uint8_t s_dma_demo_bad_msg[]
Definition main.c:61
dma_demo_byte_t
Single-byte constants.
Definition main.c:54
@ k_dma_demo_channel
DMA demo channel.
Definition main.c:55
@ k_dma_demo_byte_sh
DMA demo byte sh.
Definition main.c:56
dma_demo_config_t
Compile-time settings.
Definition main.c:45
@ k_dma_demo_period_ms
DMA demo period ms.
Definition main.c:47
@ k_dma_demo_baud
DMA demo baud.
Definition main.c:46
@ k_dma_demo_buf_words
DMA demo buffer words.
Definition main.c:49
@ k_dma_demo_poll_limit
DMA demo poll limit.
Definition main.c:50
@ k_dma_demo_buf_bytes
DMA demo buffer bytes.
Definition main.c:48
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_led2
LED2, GREEN, P303 (jumper E26).
@ 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
8-channel DMA controller (DMAC0) driver
@ k_ra8_dmac_width_word
32-bit transfers (DMTMD.SZ = 10b).
Definition ra8_dmac.h:53
ra8_err_t ra8_dmac_stop(uint8_t channel)
Disable a DMAC0 channel and drop its MSTP reference.
Definition ra8_dmac.c:432
ra8_err_t ra8_dmac_start_block(uint8_t channel, const ra8_dmac_config_t *cfg)
Programme a DMAC channel in block-transfer mode.
Definition ra8_dmac.c:483
DMAC (Direct Memory Access Controller) register layout for the RA8D2.
static volatile r_dmac_channel_regs_t * ra8_dmac(uint8_t channel)
Pointer to DMAC channel channel (0..7), or NULL on error.
@ k_ra8_dmreq_swreq_mask
RA8 dmreq swreq mask.
@ k_ra8_dmsts_act_mask
RA8 dmsts act mask.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
Definition ra8_err.h:304
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
Definition ra8_err.h:310
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
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Definition ra8_mstp.c:291
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
Per-channel DMAC register window.
volatile uint8_t DMSTS
+0x1E Status (ESIF/DTIF/ACT).
volatile uint8_t DMREQ
+0x1D Software Start (SWREQ/CLRS).
DMAC channel configuration.
Definition ra8_dmac.h:121