|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
GPT hardware input-capture + external event/pulse counting demo. More...
#include <stdint.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_gpio_constants.h"#include "ra8_gpt.h"#include "ra8_gpt_capture.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_port_constants.h"#include "ra8_port_utils.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | gpt_ecc_period_const_t : uint32_t { k_gpt_ecc_period = 0xFFFFFFFFUL , k_gpt_ecc_min_valid_ticks = 0x00000064UL , k_gpt_ecc_max_valid_ticks = 0x7FFFFFFFUL } |
| 32-bit counter tunables (free-run period + capture window). More... | |
| enum | gpt_ecc_poll_const_t : uint16_t { k_gpt_ecc_poll_period_ms = 5U } |
| Main-loop poll cadence in milliseconds. More... | |
| enum | gpt_ecc_layout_t : uint8_t { k_gpt_ecc_capture_channel = 0U , k_gpt_ecc_count_channel = 1U } |
| GPT channel + LED selection for the demo. More... | |
Functions | |
| static void | gpt_ecc_panic_halt (void) |
| Park the CPU after a fatal init failure. | |
| static bool | gpt_ecc_period_valid (uint32_t delta_ticks) |
| Classify a captured delta as a genuine signal period. | |
| static void | gpt_ecc_clocks_or_halt (void) |
| Bring up the core clocks, SysTick, and LED1. | |
| static void | gpt_ecc_route_pins_or_halt (void) |
| Route the two GTIOCnA edge-input pins to the GPT peripheral. | |
| static void | gpt_ecc_timers_or_halt (void) |
| Configure the capture (GPT0) and count (GPT1) timer channels. | |
| static bool | gpt_ecc_service_capture (uint32_t *prev_latch) |
| Service one input-capture poll: latch delta -> globals. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const ra8_port_pin_t | k_gpt_ecc_pin_capture = ((ra8_port_pin_t)(((uint16_t)(k_ra8_port_4) << 8) | (uint16_t)(k_ra8_pin_8))) |
| GTIOC0A input pad for the capture channel (placeholder). | |
| static const ra8_port_pin_t | k_gpt_ecc_pin_count = ((ra8_port_pin_t)(((uint16_t)(k_ra8_port_4) << 8) | (uint16_t)(k_ra8_pin_9))) |
| GTIOC1A input pad for the event-count channel (placeholder). | |
| volatile uint32_t | g_gpt_ecc_last_period = 0U |
| Most recent valid input-capture delta, in GPT counter ticks. | |
| volatile uint32_t | g_gpt_ecc_capture_events = 0U |
| Count of valid input-capture edges observed so far. | |
| volatile uint32_t | g_gpt_ecc_pulse_count = 0U |
| Latest accumulated external pulse count (GPT1 GTCNT). | |
| volatile uint32_t | g_gpt_ecc_tick = 0U |
| Pin-independent liveness counter. | |
GPT hardware input-capture + external event/pulse counting demo.
Demonstrates the two GPT edge-driven driver features that gpt_capture_input only approximates in software:
The measured values are published in J-Link-readable globals so a future bench run can assert them against a known stimulus frequency.
Definition in file main.c.
| enum gpt_ecc_layout_t : uint8_t |
| enum gpt_ecc_period_const_t : uint32_t |
32-bit counter tunables (free-run period + capture window).
k_gpt_ecc_period is the full-scale GTPR so GTCNT behaves as a 32-bit free-running accumulator. A captured delta is treated as a genuine signal period only when it falls inside
lower bound rejects sub-microsecond noise / contact bounce, the upper bound rejects the first (uninitialised) latch and any counter-wrap artefact.
| Enumerator | |
|---|---|
| k_gpt_ecc_period | GTPR full-scale. |
| k_gpt_ecc_min_valid_ticks | 100: glitch-reject floor. |
| k_gpt_ecc_max_valid_ticks | Wrap / stale-latch ceiling. |
| enum gpt_ecc_poll_const_t : uint16_t |
|
static |
Bring up the core clocks, SysTick, and LED1.
CGC -> SysTick (from CPUCLK0) -> LED1 -> module-stop model. Any failure halts via gpt_ecc_panic_halt.
Definition at line 236 of file main.c.
References gpt_ecc_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_mstp_init(), and ra8_time_init().
Referenced by main().
|
static |
Park the CPU after a fatal init failure.
Spins in a low-power wait so a debugger can inspect state.
Definition at line 186 of file main.c.
Referenced by gpt_ecc_clocks_or_halt(), gpt_ecc_route_pins_or_halt(), gpt_ecc_timers_or_halt(), and main().
|
static |
Classify a captured delta as a genuine signal period.
Windows the delta to reject noise (too short) and the first / wrapped latch (too long). This is the demo's one compound decision.
| [in] | delta_ticks | Difference between two consecutive GTCCRA latches, in GPT counter ticks (0 .. UINT32_MAX). |
Definition at line 218 of file main.c.
References k_gpt_ecc_max_valid_ticks, and k_gpt_ecc_min_valid_ticks.
Referenced by gpt_ecc_service_capture().
|
static |
Route the two GTIOCnA edge-input pins to the GPT peripheral.
Uses ra8_pfs_route_peripheral with PSEL k_ra8_psel_gpt0 (GPT channels 0..3). Any failure halts.
Definition at line 268 of file main.c.
References gpt_ecc_panic_halt(), k_gpt_ecc_pin_capture, k_gpt_ecc_pin_count, k_ra8_ok, k_ra8_psel_gpt0, and ra8_pfs_route_peripheral().
Referenced by main().
|
static |
Service one input-capture poll: latch delta -> globals.
Checks GTST.TCFA; on a fresh latch reads GTCCRA, computes the delta from *prev_latch, and on a valid period updates the published globals and toggles LED1. Clears TCFA before returning.
| [in,out] | prev_latch | Previous GTCCRA latch value; updated to the current latch when a capture is serviced. |
Definition at line 345 of file main.c.
References g_gpt_ecc_capture_events, g_gpt_ecc_last_period, gpt_ecc_period_valid(), k_gpt_ecc_capture_channel, k_ra8_board_led1, k_ra8_gpt_ccr_a, k_ra8_gpt_status_ccra, k_ra8_ok, ra8_board_led_toggle(), ra8_gpt_capture_read(), ra8_gpt_clear_status(), and ra8_gpt_get_status().
Referenced by main().
|
static |
Configure the capture (GPT0) and count (GPT1) timer channels.
GPT0 starts free-running and GTICASR is armed for GTIOC0A rising-edge capture (#185). GPT1 starts and GTUPSR is armed for GTIOC1A rising-edge counting (#186). Any failure halts.
Definition at line 295 of file main.c.
References gpt_ecc_panic_halt(), k_gpt_ecc_capture_channel, k_gpt_ecc_count_channel, k_gpt_ecc_period, k_ra8_gpt_cap_src_ioca_rising, k_ra8_gpt_ccr_a, k_ra8_gpt_cnt_src_ioca_rising, k_ra8_gpt_cnt_src_none, k_ra8_gpt_mode_saw_pwm, k_ra8_gpt_ps_div_1, k_ra8_ok, ra8_gpt_capture_configure(), ra8_gpt_event_count_configure(), and ra8_gpt_init().
Referenced by main().
| void main | ( | void | ) |
The application entry point Reset_Handler hands control to.
Returns void, not int. This is a freestanding image: there is no hosted C environment, no process and nothing to report an exit status to. ISO C fixes main at int only for a hosted implementation; for a freestanding one (C23 5.1.2.1) the startup function's name and type are implementation-defined, and this is that definition. Reset_Handler discards no value because there is none to discard, and if main ever does return, startup halts the CPU rather than resuming anything.
The firmware lane is compiled -ffreestanding (see cmake/ra8_add_app.cmake) and the flag and this signature travel together: without it both GCC and clang reject a non-int main (-Wmain / -Wmain-return-type). Do not remove one without the other.
That coupling is why the declaration sits behind __STDC_HOSTED__ == 0, which -ffreestanding sets and a hosted build does not. The guard is not defensive dressing: this header is reachable from host builds (the unit tests compile ra8_core natively), and an unguarded void main(void); makes every hosted translation unit that includes it fail with conflicting types for 'main' against its own ISO int main. The declaration therefore exists exactly where its contract does.
Hosted first-party code – everything under tests/ and tools/ – uses the ISO int main(...) contract instead, because it genuinely does run under an OS that reads the exit status. scripts/checks/check_entry_points.py holds each domain to its own contract (#707).
Declared here, once, for the same reason SystemInit is: every vector_table.c used to restate it as a local extern int32_t main(void);, sixteen copies that no compiler ever compared against the definition – and roughly thirty of them had silently drifted out of agreement with the main they called.
The application entry point Reset_Handler hands control to.
Brings up CGC + BSP audio then plays blocks.
The application entry point Reset_Handler hands control to.
Brings up CGC + GPT triple, runs sweep.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART, then enters ThreadX.
The application entry point Reset_Handler hands control to.
Brings up LED, console, SDHI pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS + UAC1, then enters the iso-IN feed loop forever.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Profiles power modes once a second.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, SPI, and SD card, then runs the shared ra8_io VFS round-trip over the SD-over-SPI block device. On success it prints the exact PASS banner the HIL runner and ra8_emulator smoke gate scrape for; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
Initialises logging and the console, brings up the OSPI NOR volume, runs the erase-before-write round-trip, and prints a single PASS/FAIL verdict line over SCI8 before parking in an infinite loop.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Both USB controllers' clocks and pins come up before the kernel so the workers only deal with stack bring-up.
The application entry point Reset_Handler hands control to.
Brings up logging and the clock tree, releases the Cortex-M33 (which then blinks LED1 via ra8_pcntr_set_output()), and idles. See the file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the cacheable-SRAM round-trip with the D-cache that SystemInit() enabled through ra8_cache_dcache_enable(), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI. Every byte the self-test touches runs with the L1 caches + MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU + RA8_BOOT_CACHE_VIA_HAL).
The application entry point Reset_Handler hands control to.
Publishes the mailbox, releases the Cortex-M33 into the emitter, yields until it signals done, validates the blob the M33 built, then logs the PASS/FAIL verdict and the chapter count read back from the blob. See the file header for the offload narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Publishes the mailbox, arms the IPC0 wake and configures the LPM block, releases the Cortex-M33 into the reader, waits for the first held page, logs the page-0 verdict, then runs the #150 mode-switch cycle – parking in low-power WFI and waking on the M33's page-turn pokes – before logging the handoff verdict and parking for good. See the file header for the narrative.
The application entry point Reset_Handler hands control to.
Definition at line 369 of file main.c.
References g_gpt_ecc_pulse_count, g_gpt_ecc_tick, gpt_ecc_clocks_or_halt(), gpt_ecc_panic_halt(), gpt_ecc_route_pins_or_halt(), gpt_ecc_service_capture(), gpt_ecc_timers_or_halt(), k_gpt_ecc_capture_channel, k_gpt_ecc_count_channel, k_gpt_ecc_poll_period_ms, k_ra8_ok, ra8_delay_ms(), ra8_gpt_read(), and ra8_isr_globals_enable().
| volatile uint32_t g_gpt_ecc_capture_events = 0U |
Count of valid input-capture edges observed so far.
Definition at line 147 of file main.c.
Referenced by gpt_ecc_service_capture().
| volatile uint32_t g_gpt_ecc_last_period = 0U |
Most recent valid input-capture delta, in GPT counter ticks.
Updated only when a captured delta passes gpt_ecc_period_valid. Zero until the first valid capture.
Definition at line 137 of file main.c.
Referenced by gpt_ecc_service_capture().
| volatile uint32_t g_gpt_ecc_pulse_count = 0U |
Latest accumulated external pulse count (GPT1 GTCNT).
Reflects GTUPSR-driven event counting: the number of external rising edges the count channel has tallied.
Definition at line 159 of file main.c.
Referenced by main().
| volatile uint32_t g_gpt_ecc_tick = 0U |
Pin-independent liveness counter.
Bumped whenever the capture channel's free-running GTCNT advanced between two samples. Proves the GPT counter is alive even when no edge source is wired (the unattended-bench case), separately from the pin-driven capture / count signals above.
Definition at line 173 of file main.c.
Referenced by main().
|
static |
GTIOC0A input pad for the capture channel (placeholder).
TODO(board-rev): the EK-RA8D2 breaks out no conflict-free GTIOC0A pad – the candidate pins overlap the debug UART per HUM Ch 20.6 pin tables. This P408 assignment is illustrative so the app builds and the ra8_pfs_route_peripheral call is exercised; update it (or move to a carrier board) before bench validation.
Definition at line 113 of file main.c.
Referenced by gpt_ecc_route_pins_or_halt().
|
static |
GTIOC1A input pad for the event-count channel (placeholder).
TODO(board-rev): same EK-RA8D2 pad-availability caveat as k_gpt_ecc_pin_capture; P409 is illustrative.
Definition at line 125 of file main.c.
Referenced by gpt_ecc_route_pins_or_halt().