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
44
45#include <stdint.h>
46
47#include "ra8_board_ek_ra8d2.h"
48#include "ra8_boot_entry.h"
49#include "ra8_cgc.h"
50#include "ra8_elc.h"
51#include "ra8_err.h"
52#include "ra8_gpio_constants.h"
53#include "ra8_isr.h"
54#include "ra8_port_constants.h"
55#include "ra8_port_utils.h"
56#include "ra8_sci.h"
57#include "ra8_time.h"
58
66
68typedef enum : uint16_t {
73
77
79static const uint8_t k_uart_irq_banner[] = "uart_irq_echo ready\r\n";
80
94volatile uint32_t g_uart_irq_echoes = 0U;
95
97static uint8_t s_uart_irq_rx_byte;
98
106static void uart_irq_panic_halt(void)
107{
108 while (1) {
109 __asm__ volatile("wfi");
110 }
111}
112
113/* ---- Interrupt service routines (registered via ra8_isr_register) ---------- */
114
124static void uart_irq_rxi_isr(void* ctx)
125{
126 (void)ctx;
128}
129
139static void uart_irq_txi_isr(void* ctx)
140{
141 (void)ctx;
143}
144
154static void uart_irq_tei_isr(void* ctx)
155{
156 (void)ctx;
158}
159
174static void uart_irq_rx_cb(void* ctx, uint8_t byte)
175{
176 (void)ctx;
177 g_uart_irq_echoes += 1U;
179 s_uart_irq_rx_byte = byte;
182}
183
184/* ---- Bring-up ------------------------------------------------------------- */
185
195[[nodiscard]] static ra8_err_t uart_irq_pins_init(void)
196{
197 ra8_err_t err =
199 if (err != k_ra8_ok) {
200 return err;
201 }
203}
204
213[[nodiscard]] static ra8_err_t uart_irq_register_isrs(void)
214{
217 nullptr,
218 (uint8_t)k_uart_irq_isr_prio,
219 nullptr);
220 if (err != k_ra8_ok) {
221 return err;
222 }
225 nullptr,
226 (uint8_t)k_uart_irq_isr_prio,
227 nullptr);
228 if (err != k_ra8_ok) {
229 return err;
230 }
233 nullptr,
234 (uint8_t)k_uart_irq_isr_prio,
235 nullptr);
236}
237
244static void uart_irq_setup_or_halt(void)
245{
246 uint32_t cpuclk0_hz = 0U;
247 uint32_t pclka_hz = 0U;
248
249 if (ra8_cgc_init() != k_ra8_ok) {
251 }
254 }
257 }
258 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
260 }
261 if (uart_irq_pins_init() != k_ra8_ok) {
263 }
264
265 const ra8_sci_cfg_t sci_cfg = {
266 .baud = k_uart_irq_baud,
267 .data_bits = k_ra8_sci_data_8,
268 .parity = k_ra8_sci_parity_none,
269 .stop_bits = k_ra8_sci_stop_1,
270 .pclk_hz = pclka_hz,
271 };
272 if (ra8_sci_init((uint8_t)k_uart_irq_sci_chan, &sci_cfg) != k_ra8_ok) {
274 }
277 }
278 if (ra8_isr_init() != k_ra8_ok) {
280 }
283 }
284}
285
294void main(void)
295{
297
299
300 /* Polled path: announce readiness (also exercises ra8_sci_write_polling). */
303 (uint32_t)(sizeof(k_uart_irq_banner) - 1U));
304
305 /* Attach the echo callback and arm the first interrupt-driven receive. */
308
309 while (1) {
310 /* All echo work happens in the SCI ISRs; the loop only idles. */
312 }
313
315}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static const ra8_port_pin_t k_uart_irq_pin_txd
Pinout for the on-board J-Link OB CDC channel (SCI8 / PD02 + PD03).
Definition main.c:75
static ra8_err_t uart_irq_pins_init(void)
Route PD02 / PD03 to SCI8 TXD / RXD via the PFS PSEL field.
Definition main.c:195
static const ra8_port_pin_t k_uart_irq_pin_rxd
Definition main.c:76
static void uart_irq_rx_cb(void *ctx, uint8_t byte)
RX byte callback: echo the byte and re-arm the next receive.
Definition main.c:174
volatile uint32_t g_uart_irq_echoes
Count of bytes echoed from interrupt context.
Definition main.c:94
uart_irq_event_t
SCI8 ELC event numbers (FSP ra8d2 bsp_elc: RXI/TXI/TEI).
Definition main.c:68
@ k_uart_irq_event_txi
SCI8 TXI transmit-data-empty event.
Definition main.c:70
@ k_uart_irq_event_rxi
SCI8 RXI receive-data-full event.
Definition main.c:69
@ k_uart_irq_event_tei
SCI8 TEI transmit-end event.
Definition main.c:71
static void uart_irq_setup_or_halt(void)
Bring CGC + SysTick + SCI8 + LED1 + the SCI ISRs up, or panic-halt.
Definition main.c:244
static void uart_irq_txi_isr(void *ctx)
SCI8 TXI ISR: push the next byte of an in-flight interrupt TX.
Definition main.c:139
static uint8_t s_uart_irq_rx_byte
One-byte RX landing pad re-armed by every receive callback.
Definition main.c:97
static ra8_err_t uart_irq_register_isrs(void)
Register the SCI8 RXI / TXI / TEI events with the NVIC.
Definition main.c:213
uart_irq_config_t
Compile-time settings for the echo demo.
Definition main.c:60
@ k_uart_irq_baud
UART IRQ baud.
Definition main.c:61
@ k_uart_irq_sci_chan
Console channel: SCI8 (PD02/PD03).
Definition main.c:63
@ k_uart_irq_isr_prio
NVIC priority for the SCI events.
Definition main.c:64
@ k_uart_irq_loop_ms
UART IRQ loop ms.
Definition main.c:62
static const uint8_t k_uart_irq_banner[]
Banner printed once over the polled path so the host sees a prompt.
Definition main.c:79
static void uart_irq_rxi_isr(void *ctx)
SCI8 RXI ISR: drive the driver's receive state machine.
Definition main.c:124
static void uart_irq_panic_halt(void)
Halt forever in WFI – panic stop on any init failure.
Definition main.c:106
static void uart_irq_tei_isr(void *ctx)
SCI8 TEI ISR: end-of-transmission housekeeping.
Definition main.c:154
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).
@ k_ra8_board_uart_console_pin_txd
PD02 TXD.
@ k_ra8_board_uart_console_pin_rxd
PD03 RXD.
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
@ k_ra8_clock_id_pclka
PCLKA.
Definition ra8_cgc.h:73
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Event Link Controller driver.
ra8_elc_event_t
Partial list of ELC events (populate as drivers need them).
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
PSEL codes for peripheral pin routing on the RA8D2.
@ k_ra8_psel_sci_async
00100b: SCI async serial (UART).
NVIC + ICU IELSR allocator.
ra8_err_t ra8_isr_init(void)
Initialise the ra8_isr table.
Definition ra8_isr.c:229
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
ra8_err_t ra8_isr_register(ra8_elc_event_t event, ra8_isr_handler_t handler, void *ctx, uint8_t priority, uint16_t *out_slot)
Allocate an IELSR slot for an ELC event + handler.
Definition ra8_isr.c:296
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
High-level GPIO helpers on top of the PORT + PFS register layer.
ra8_err_t ra8_pfs_route_peripheral(ra8_port_pin_t pin, ra8_psel_t psel, const char *owner)
Route a pin to a non-IRQ peripheral function via PFS.PSEL.
Definition gpio.c:238
Full-featured Serial Communications Interface driver.
ra8_err_t ra8_sci_write_polling(uint8_t channel, const uint8_t *data, uint32_t len)
Send len bytes by polling (convenience wrapper).
Definition ra8_sci.c:516
ra8_err_t ra8_sci_attach_rx_handler(uint8_t channel, ra8_sci_rx_fn_t fn, void *ctx)
Install the RX interrupt callback + context.
Definition ra8_sci.c:558
@ k_ra8_sci_stop_1
RA8 SCI stop 1.
Definition ra8_sci.h:81
void ra8_sci_dispatch_eri(uint8_t channel)
ERI dispatch – clear SSR error flags, invoke optional error callback (none in reserved for 3....
ra8_err_t ra8_sci_read(uint8_t channel, uint8_t *buf, uint32_t len)
Arm an interrupt-driven RX of len bytes into buf.
Definition ra8_sci.c:781
@ k_ra8_sci_parity_none
RA8 SCI parity none.
Definition ra8_sci.h:71
ra8_err_t ra8_sci_init(uint8_t channel, const ra8_sci_cfg_t *cfg)
Initialise an SCI channel using the descriptor.
Definition ra8_sci.c:410
@ k_ra8_sci_data_8
RA8 SCI data 8.
Definition ra8_sci.h:91
void ra8_sci_dispatch_rxi(uint8_t channel)
RXI dispatch – hand a received byte to the RX callback.
ra8_err_t ra8_sci_write(uint8_t channel, const uint8_t *data, uint32_t len)
Arm an interrupt-driven TX of len bytes from data.
Definition ra8_sci.c:747
void ra8_sci_dispatch_txi(uint8_t channel)
TXI dispatch – advance the TX callback.
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_sci_init.
Definition ra8_sci.h:103