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
40
41#include <stdint.h>
42
43#include "ra8_attributes.h"
44#include "ra8_board_ek_ra8d2.h"
45#include "ra8_boot_entry.h"
46#include "ra8_cgc.h"
47#include "ra8_dmac.h"
48#include "ra8_err.h"
49#include "ra8_isr.h"
50#include "ra8_mstp.h"
51#include "ra8_time.h"
52
54typedef enum : uint32_t {
55 k_dma_hal_baud = 115200U,
61
63typedef enum : uint8_t {
67
69static const uint8_t s_dma_hal_ok_msg[] = "dmahal: copied 1024B match=Y\r\n";
70static const uint8_t s_dma_hal_bad_msg[] = "dmahal: copied 1024B match=N\r\n";
71
73static uint32_t s_src[k_dma_hal_buf_words];
74static uint32_t s_dst[k_dma_hal_buf_words];
75
87{
88 while (1) {
89 __asm__ volatile("wfi");
90 }
91}
92
105{
106 uint32_t cpuclk0_hz = 0U;
107
108 if (ra8_cgc_init() != k_ra8_ok) {
110 }
113 }
114 if (ra8_mstp_init() != k_ra8_ok) {
116 }
117 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
119 }
122 }
125 }
128 }
129}
130
149{
150 for (uint32_t i = 0U; i < (uint32_t)k_dma_hal_buf_words; ++i) {
151 s_src[i] = i ^ (i >> (uint32_t)k_dma_hal_byte_sh);
152 s_dst[i] = 0U;
153 }
154}
155
178RA8_INTERNAL static uint8_t internal_verify(void)
179{
180 for (uint32_t i = 0U; i < (uint32_t)k_dma_hal_buf_words; ++i) {
181 if (s_dst[i] != s_src[i]) {
182 return 0U;
183 }
184 }
185 return 1U;
186}
187
215[[nodiscard]] RA8_INTERNAL static ra8_err_t internal_run_copy(void)
216{
217 const ra8_dmac_config_t cfg = {
218 .src = (uint32_t)(uintptr_t)s_src,
219 .dst = (uint32_t)(uintptr_t)s_dst,
220 .count = (uint16_t)k_dma_hal_buf_words,
221 .block_count = 1U,
222 .width = k_ra8_dmac_width_word,
223 .src_inc = true,
224 .dst_inc = true,
225 };
227 if (err != k_ra8_ok) {
228 return err;
229 }
230
232 if (err != k_ra8_ok) {
233 (void)ra8_dmac_stop((uint8_t)k_dma_hal_channel);
234 return err;
235 }
236
238 const ra8_err_t stop_err = ra8_dmac_stop((uint8_t)k_dma_hal_channel);
239 if (err != k_ra8_ok) {
240 return err;
241 }
242 return stop_err;
243}
244
245void main(void)
246{
249
250 while (1) {
252 const ra8_err_t err = internal_run_copy();
253 uint8_t ok = 0U;
254 if (err == k_ra8_ok) {
255 if (internal_verify() != 0U) {
256 ok = 1U;
257 }
258 }
259 if (ok != 0U) {
262 } else {
264 (size_t)(sizeof(s_dma_hal_bad_msg) - 1U));
266 }
268 }
270}
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
dma_hal_byte_t
Single-byte constants.
Definition main.c:63
@ k_dma_hal_byte_sh
DMA HAL demo byte sh.
Definition main.c:65
@ k_dma_hal_channel
DMA HAL demo channel.
Definition main.c:64
dma_hal_config_t
Compile-time settings.
Definition main.c:54
@ k_dma_hal_buf_bytes
DMA HAL demo buffer bytes.
Definition main.c:57
@ k_dma_hal_period_ms
DMA HAL demo period ms.
Definition main.c:56
@ k_dma_hal_baud
DMA HAL demo baud.
Definition main.c:55
@ k_dma_hal_buf_words
DMA HAL demo buffer words.
Definition main.c:58
@ k_dma_hal_poll_limit
DMSTS.ACT poll bound.
Definition main.c:59
static const uint8_t s_dma_hal_bad_msg[]
Definition main.c:70
static const uint8_t s_dma_hal_ok_msg[]
Output line tags.
Definition main.c:69
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
ra8_err_t ra8_dmac_wait_idle(uint8_t channel, uint32_t poll_limit)
Spin until a DMAC0 channel goes idle or a poll bound expires.
Definition ra8_dmac.c:588
ra8_err_t ra8_dmac_software_trigger(uint8_t channel)
Software-trigger one transfer request on a DMAC0 channel.
Definition ra8_dmac.c:565
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
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
DMAC channel configuration.
Definition ra8_dmac.h:121