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

GPT one-shot (saw-wave one-shot) HIL demo for 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_err.h"
#include "ra8_gpt.h"
#include "ra8_isr.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  gpt_os_demo_const_t : uint32_t {
  k_gpt_os_demo_period = 0x0000FFFFU ,
  k_gpt_os_demo_rearm_delay_ms = 50U
}
 Demo tunables. More...
enum  gpt_os_demo_chan_t : uint8_t { k_gpt_os_demo_channel = 0U }
 GPT channel. More...

Functions

static void internal_panic_halt (void)
 Park the core after an unrecoverable demo failure.
static void internal_setup_or_halt (void)
 Initialize clocks, the delay service, and LED1.
static ra8_err_t internal_arm (void)
 Init GPT0 in one-shot mode.
static bool internal_wait_ovf (void)
 Poll GTST.TCFPO for one overflow + clear, bounded.
void main (void)
 Repeatedly start and verify GPT0 one-shot intervals.

Variables

volatile uint32_t g_gpt_one_shot_match = 0U
 HIL liveness counter – bumped on every IRQ-observed one-shot completion.
volatile uint32_t g_gpt_one_shot_mismatch = 0U
 HIL failure counter – bumped when arm-or-start returns non-ok inside the loop.

Detailed Description

GPT one-shot (saw-wave one-shot) HIL demo for EK-RA8D2.

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

Exercises the GPT in saw-wave one-shot mode (HUM Ch 25.2.1 GTCR.MD = 001b) – the counter counts up from 0 to period once, fires an overflow IRQ, then stops on its own. The demo arms + starts + waits for IRQ + re-arms in a loop so the bench can scrape g_gpt_one_shot_match and confirm each one-shot completes.

Bring-up sequence:

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ gpt_os_demo_chan_t

enum gpt_os_demo_chan_t : uint8_t

GPT channel.

Enumerator
k_gpt_os_demo_channel 

GPT os demo channel.

Definition at line 45 of file main.c.

◆ gpt_os_demo_const_t

enum gpt_os_demo_const_t : uint32_t

Demo tunables.

Enumerator
k_gpt_os_demo_period 

16-bit period at div_4.

k_gpt_os_demo_rearm_delay_ms 

Sleep between one-shots.

Definition at line 39 of file main.c.

Function Documentation

◆ internal_arm()

ra8_err_t internal_arm ( void )
staticnodiscard

Init GPT0 in one-shot mode.

Programs channel zero for a PCLKD/4 saw-wave one-shot with manual start and the fixed demo period; no callback is required because completion is polled through the status register.

Returns
ra8_err_t from ra8_gpt_init.
Return values
k_ra8_okGPT0 accepted the one-shot configuration.
(other)The HAL rejected or could not apply the configuration.
Precondition
ra8_isr_globals_enable has been called.
GPT0 not yet initialised.
Postcondition
On k_ra8_ok the channel is armed (not yet running).
Note
Not thread-safe.
Since
0.1.0

Definition at line 144 of file main.c.

References k_gpt_os_demo_channel, k_gpt_os_demo_period, k_ra8_gpt_mode_saw_one_shot, k_ra8_gpt_ps_div_4, ra8_gpt_init(), and RA8_INTERNAL.

◆ internal_panic_halt()

void internal_panic_halt ( void )
static

Park the core after an unrecoverable demo failure.

Repeatedly executes WFI so a debugger can inspect the failed GPT or clock state without further peripheral accesses.

Precondition
Called only from boot failure or an unreachable terminal path.
The caller does not require recovery without an external reset.
Postcondition
The core remains in the WFI loop until reset or debug intervention.
No demo counters are modified after entry.
Note
Not thread-safe; this is a terminal single-threaded path.
Since
0.1.0

Definition at line 89 of file main.c.

References RA8_INTERNAL.

◆ internal_setup_or_halt()

void internal_setup_or_halt ( void )
static

Initialize clocks, the delay service, and LED1.

Brings dependencies up in order and parks immediately if any HAL operation fails, leaving GPT configuration to internal_arm.

Precondition
Reset startup initialized static storage and the vector table.
Called once before global interrupt enable.
Postcondition
On return, the delay service and LED1 are ready for the one-shot loop.
GPT0 remains unconfigured until internal_arm runs.
Note
Not thread-safe; it mutates global board and clock state.
Since
0.1.0

Definition at line 109 of file main.c.

References internal_panic_halt(), k_ra8_board_led1, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, and ra8_time_init().

◆ internal_wait_ovf()

bool internal_wait_ovf ( void )
static

Poll GTST.TCFPO for one overflow + clear, bounded.

Samples channel-zero status up to the fixed poll budget, clears the overflow flag on first observation, and treats a HAL read failure the same as exhaustion so the caller records a mismatch.

Returns
true if the overflow flag was observed.
Return values
trueTCFPO set + cleared within budget.
falsepoll budget elapsed.
Precondition
GPT0 is running (ra8_gpt_start_free_run was called).
IRQs are not required (poll-only path).
Postcondition
On true the GTST.TCFPO bit has been cleared.
Iteration count bounded.
Note
Not thread-safe.
Since
0.1.0

< Poll budget.

Definition at line 176 of file main.c.

References k_gpt_os_demo_channel, k_ra8_gpt_status_overflow, k_ra8_ok, ra8_gpt_clear_status(), ra8_gpt_get_status(), and RA8_INTERNAL.

Referenced by main().

◆ main()

void main ( void )

Repeatedly start and verify GPT0 one-shot intervals.

The application entry point Reset_Handler hands control to.

Initializes and arms GPT0 once, then starts, polls, records the exported pass/failure counters, toggles LED1 on completion, and delays before the next one-shot.

Precondition
Reset startup and SystemInit completed successfully.
GPT0 and LED1 are not owned by another execution context.
Postcondition
Each completed one-shot increments g_gpt_one_shot_match.
Each start or bounded-poll failure increments the mismatch counter.
Note
Does not return during normal operation.
Since
0.1.0

Definition at line 207 of file main.c.

References g_gpt_one_shot_match, g_gpt_one_shot_mismatch, internal_arm(), internal_panic_halt(), internal_setup_or_halt(), internal_wait_ovf(), k_gpt_os_demo_channel, k_gpt_os_demo_period, k_gpt_os_demo_rearm_delay_ms, k_ra8_board_led1, k_ra8_ok, ra8_board_led_toggle(), ra8_delay_ms(), ra8_gpt_start_free_run(), and ra8_isr_globals_enable().

Variable Documentation

◆ g_gpt_one_shot_match

volatile uint32_t g_gpt_one_shot_match = 0U

HIL liveness counter – bumped on every IRQ-observed one-shot completion.

Read externally by hil_jlink_memprobe.sh.

If the GPT clock is gated, GTCR.MD is wrong, or the IRQ is masked, the overflow callback never fires and this counter stops advancing.

Note
Read externally by J-Link only; firmware never reads back.
Since
0.1.0

Definition at line 61 of file main.c.

Referenced by main().

◆ g_gpt_one_shot_mismatch

volatile uint32_t g_gpt_one_shot_mismatch = 0U

HIL failure counter – bumped when arm-or-start returns non-ok inside the loop.

The memprobe asserts this stays at 0. Catches "clock gate closed silently" and "ra8_gpt_start_free_run rejected".

Note
Read externally by J-Link only.
Since
0.1.0

Definition at line 74 of file main.c.

Referenced by main().