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
32
33#include <stdint.h>
34
35#include "ra8_board_ek_ra8d2.h"
36#include "ra8_boot_entry.h"
37#include "ra8_cgc.h"
38#include "ra8_err.h"
39#include "ra8_gpt.h"
40#include "ra8_isr.h"
41#include "ra8_mstp.h"
42#include "ra8_time.h"
43
52
60
62static const uint8_t k_timer_demo_prefix[] = "gpt: period=";
63static const uint8_t k_timer_demo_eol[] = "\r\n";
64
66static void timer_demo_panic_halt(void)
67{
68 while (1) {
69 __asm__ volatile("wfi");
70 }
71}
72
83static uint8_t timer_demo_nibble_to_hex(uint8_t nibble)
84{
85 uint8_t n = (uint8_t)(nibble & (uint8_t)k_timer_demo_nibble_mask);
86 if (n < (uint8_t)k_timer_demo_alpha_thresh) {
87 return (uint8_t)('0' + n);
88 }
89 return (uint8_t)('a' + (n - (uint8_t)k_timer_demo_alpha_thresh));
90}
91
102static void timer_demo_word_to_hex(uint32_t v, uint8_t* dst)
103{
104 for (uint8_t i = 0U; i < (uint8_t)k_timer_demo_hex_per_word; ++i) {
105 const uint8_t shift =
106 (uint8_t)(((uint8_t)k_timer_demo_hex_per_word - 1U - i) * (uint8_t)k_timer_demo_nibble_shift);
107 const uint8_t nibble = (uint8_t)((v >> shift) & (uint32_t)k_timer_demo_nibble_mask);
108 dst[i] = timer_demo_nibble_to_hex(nibble);
109 }
110}
111
128static uint32_t timer_demo_delta(uint32_t start, uint32_t stop)
129{
130 if (stop >= start) {
131 return stop - start;
132 }
133 return (uint32_t)k_timer_demo_gpt_period - start + stop + 1U;
134}
135
138{
139 uint32_t cpuclk0_hz = 0U;
140
141 if (ra8_cgc_init() != k_ra8_ok) {
143 }
146 }
147 if (ra8_mstp_init() != k_ra8_ok) {
149 }
150 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
152 }
155 }
158 }
160 (uint32_t)k_timer_demo_gpt_period) != k_ra8_ok) {
162 }
163}
164
181[[nodiscard]] static ra8_err_t timer_demo_one_capture(void)
182{
183 uint32_t start = 0U;
184 uint32_t stop = 0U;
185
186 if (ra8_gpt_read((uint8_t)k_timer_demo_gpt_channel, &start) != k_ra8_ok) {
187 return k_ra8_err_hw_error;
188 }
191 if (ra8_gpt_read((uint8_t)k_timer_demo_gpt_channel, &stop) != k_ra8_ok) {
192 return k_ra8_err_hw_error;
193 }
194
195 const uint32_t delta = timer_demo_delta(start, stop);
196 uint8_t hex[k_timer_demo_hex_per_word] = {};
197 timer_demo_word_to_hex(delta, hex);
198
200 (size_t)(sizeof(k_timer_demo_prefix) - 1U)) != k_ra8_ok) {
201 return k_ra8_err_hw_error;
202 }
204 return k_ra8_err_hw_error;
205 }
206 return ra8_board_uart_console_write(k_timer_demo_eol, (size_t)(sizeof(k_timer_demo_eol) - 1U));
207}
208
209void main(void)
210{
213
214 while (1) {
216 break;
217 }
219 }
221}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static const uint8_t k_timer_demo_prefix[]
Output line tags.
Definition main.c:62
static void timer_demo_panic_halt(void)
Park forever after a fatal init failure.
Definition main.c:66
static uint32_t timer_demo_delta(uint32_t start, uint32_t stop)
Compute stop - start modulo 2^32 (handles wrap).
Definition main.c:128
static void timer_demo_word_to_hex(uint32_t v, uint8_t *dst)
Render a 32-bit value as 8 ASCII hex chars (big-endian).
Definition main.c:102
static ra8_err_t timer_demo_one_capture(void)
One iteration: capture two counter snapshots and emit the delta.
Definition main.c:181
static uint8_t timer_demo_nibble_to_hex(uint8_t nibble)
Convert the low nibble of n to its ASCII hex char.
Definition main.c:83
timer_demo_config_t
Compile-time settings.
Definition main.c:45
@ k_timer_demo_capture_ms
Timer demo capture ms.
Definition main.c:48
@ k_timer_demo_gpt_channel
Timer demo GPT channel.
Definition main.c:49
@ k_timer_demo_period_ms
Timer demo period ms.
Definition main.c:47
@ k_timer_demo_gpt_period
Timer demo GPT period.
Definition main.c:50
@ k_timer_demo_baud
Timer demo baud.
Definition main.c:46
timer_demo_byte_t
Single-byte constants.
Definition main.c:54
@ k_timer_demo_hex_per_word
Timer demo hex per word.
Definition main.c:58
@ k_timer_demo_alpha_thresh
Timer demo alpha thresh.
Definition main.c:57
@ k_timer_demo_nibble_mask
Timer demo nibble mask.
Definition main.c:55
@ k_timer_demo_nibble_shift
Timer demo nibble shift.
Definition main.c:56
static const uint8_t k_timer_demo_eol[]
Definition main.c:63
static void timer_demo_setup_or_halt(void)
Bring CGC + SysTick + SCI8 + LED1 + MSTP + GPT0 up.
Definition main.c:137
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).
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
Error Code Definitions for ra8-firmware.
@ 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
Full-featured General PWM Timer (GPT) driver.
ra8_err_t ra8_gpt_start_free_run(uint8_t channel, uint32_t period)
Configure a GPT channel as a free-running up-counter.
Definition ra8_gpt.c:274
ra8_err_t ra8_gpt_read(uint8_t channel, uint32_t *out)
Read the current counter value.
Definition ra8_gpt.c:314
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