ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

Event Link Controller (ELC) software-event demo for the EK-RA8D2. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_elc.h"
#include "ra8_elc_regs.h"
#include "ra8_err.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  elc_demo_const_t : uint32_t {
  k_elc_demo_baud = 115200U ,
  k_elc_demo_period_ms = 1000U
}
 App-wide tunables. More...
enum  elc_demo_byte_t : uint8_t {
  k_elc_demo_slot = 0U ,
  k_elc_demo_sw_event_idx = 0U ,
  k_elc_demo_ascii_zero = '0' ,
  k_elc_demo_ascii_one = '1' ,
  k_elc_demo_dec_base = 10U ,
  k_elc_demo_uint_dec_max = 10U ,
  k_elc_demo_print_buf = 48U
}
 ELC slot / software-event indices used by the demo. More...

Functions

static void internal_panic_halt (void)
 Park forever after a fatal init failure.
static void internal_setup_or_halt (void)
 Bring CGC + SysTick + console + ELC up.
static uint8_t internal_uint_to_dec (uint8_t *buf, uint32_t v)
 Write a decimal uint32 into buf.
static uint32_t internal_format_line (uint8_t *out, bool enabled, uint32_t trig_count)
 Format the per-cycle "elc: en=N trig=NN\r\n" line.
void main (void)
 Application entry.

Detailed Description

Event Link Controller (ELC) software-event demo for the EK-RA8D2.

Tag
[Ring 6 / APP] {World: S}

Standalone EVM-tier app that exercises the libs/ra8_hal/inc/ra8_elc.h driver. The Event Link Controller lets one peripheral fire another peripheral's input without CPU involvement (HUM Ch 19, p 817..836). This demo:

  1. ra8_cgc_init – clocks up.
  2. ra8_mstp_init + ra8_board_uart_console_init (PD02 / PD03 SCI8).
  3. ra8_elc_init – powers on the controller and clears every ELSR slot.
  4. ra8_elc_link(0, k_ra8_elc_event_icu_irq0) – routes external IRQ0 into ELSR slot 0. The slot is wired to GPT input-capture in HUM Table 19.2; on a real EVM a button on IRQ0 would trigger a hardware capture without a single CPU instruction.
  5. Once a second the demo fires ra8_elc_software_trigger(0) (the 3-step ELSEGR unlock-arm-set sequence from HUM Ch 19.2.2) so the runtime never depends on the user pressing a button. ra8_elc_is_enabled is read back into a status byte and printed over SCI8.

SCI8 prints "elc: en=1 trig=NN\r\n" once a second; LED1 toggles per cycle; LED2 latches on if any ELC call hard-fails.

Bare EK-RA8D2 only – no external pins required because the software trigger replaces a real edge.

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ elc_demo_byte_t

enum elc_demo_byte_t : uint8_t

ELC slot / software-event indices used by the demo.

Enumerator
k_elc_demo_slot 

ELSR0 – arbitrary; HUM Tbl 19.2 maps to GPT capture.

k_elc_demo_sw_event_idx 

ELSEGR0 – software event 0.

k_elc_demo_ascii_zero 

Elc demo ascii zero.

k_elc_demo_ascii_one 

Elc demo ascii one.

k_elc_demo_dec_base 

Elc demo dec base.

k_elc_demo_uint_dec_max 

Max digits in a uint32 base-10.

k_elc_demo_print_buf 

Max bytes in one print line.

Definition at line 61 of file main.c.

◆ elc_demo_const_t

enum elc_demo_const_t : uint32_t

App-wide tunables.

Enumerator
k_elc_demo_baud 

Elc demo baud.

k_elc_demo_period_ms 

Elc demo period ms.

Definition at line 55 of file main.c.

Function Documentation

◆ internal_format_line()

uint32_t internal_format_line ( uint8_t * out,
bool enabled,
uint32_t trig_count )
static

Format the per-cycle "elc: en=N trig=NN\r\n" line.

Copies fixed prefix, separator, and line-ending fragments around one enabled digit and the decimal trigger count without using a NUL-terminated or variadic formatting API.

Parameters
[out]outDestination buffer.
[in]enabledELCR.ELCON state.
[in]trig_countSoftware-trigger count.
Returns
Bytes written into out.
Return values
18..27Complete line length, depending on trigger-count width.
Precondition
out is non-NULL with >= k_elc_demo_print_buf capacity.
enabled and trig_count are stable for the duration of the call.
Postcondition
No bytes beyond the returned length are touched.
The returned prefix contains exactly one complete CRLF-terminated line.
Note
Reentrant when callers provide distinct output buffers.
Since
0.1.0

Definition at line 204 of file main.c.

References internal_uint_to_dec(), k_elc_demo_ascii_one, k_elc_demo_ascii_zero, and RA8_INTERNAL.

Referenced by main().

◆ internal_panic_halt()

void internal_panic_halt ( void )
static

Park forever after a fatal init failure.

Repeatedly executes WFI so an attached debugger can inspect the failed bring-up state without further peripheral traffic.

Precondition
Called only after a fatal error in boot.
No caller requires recovery without an external reset.
Postcondition
CPU is parked; only a debugger or external reset wakes it.
No application state is modified after the first WFI.
Note
Not thread-safe; this is the terminal single-threaded boot path.
Since
0.1.0

Definition at line 84 of file main.c.

References RA8_INTERNAL.

◆ internal_setup_or_halt()

void internal_setup_or_halt ( void )
static

Bring CGC + SysTick + console + ELC up.

Panic-halts on any fail.

Initializes the clocks, timebase, polled console, ELC slot-zero route, and both status LEDs in dependency order. Any failed HAL call transfers control to the terminal panic helper.

Precondition
Reset startup has initialized static storage and the vector table.
This function is called exactly once before global IRQ enable.
Postcondition
On return, ELSR0 routes ICU IRQ0 and both LEDs are usable.
The console and delay service are ready for the foreground loop.
Note
Not thread-safe; it mutates global peripheral configuration.
Since
0.1.0

Definition at line 105 of file main.c.

References internal_panic_halt(), k_elc_demo_baud, k_elc_demo_slot, k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_elc_event_icu_irq0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_elc_init(), ra8_elc_link(), RA8_INTERNAL, ra8_mstp_init(), and ra8_time_init().

◆ internal_uint_to_dec()

uint8_t internal_uint_to_dec ( uint8_t * buf,
uint32_t v )
static

Write a decimal uint32 into buf.

Extracts digits into a fixed local reverse buffer, then copies them in display order. Zero takes the explicit single-digit path.

Parameters
[out]bufDestination buffer (must hold at least 10 chars).
[in]vValue to render.
Returns
Number of ASCII digits written.
Return values
1A zero or single-digit value was rendered.
2..10The exact number of digits in a larger value.
Precondition
buf is non-NULL with >= 10 bytes capacity.
The destination does not overlap this function's local storage.
Postcondition
No null terminator is written.
The returned prefix of buf is the base-10 representation of v.
Note
Reentrant when callers provide distinct destination buffers.
Since
0.1.0

Definition at line 162 of file main.c.

References k_elc_demo_ascii_zero, k_elc_demo_dec_base, k_elc_demo_uint_dec_max, and RA8_INTERNAL.

Referenced by internal_format_line().

◆ main()

void main ( void )

Application entry.

The application entry point Reset_Handler hands control to.

Fires ELC software events once a second.

Precondition
Reset_Handler has copied .data and zeroed .bss.
SystemInit has set VTOR, FPU, and priority grouping.
Postcondition
On clean entry the CPU stays in the trigger + blink loop.
On any HAL hard error LED2 latches ON.
Since
0.1.0

Definition at line 235 of file main.c.

References internal_format_line(), internal_panic_halt(), internal_setup_or_halt(), k_elc_demo_period_ms, k_elc_demo_print_buf, k_elc_demo_sw_event_idx, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_on(), ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_elc_is_enabled(), ra8_elc_software_trigger(), and ra8_isr_globals_enable().