|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
GPT input-capture-style demo: measure SW1 press period. 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"Go to the source code of this file.
Enumerations | |
| enum | gpt_capture_const_t : uint32_t { k_gpt_capture_period = 0xFFFFFFFFUL , k_gpt_capture_poll_period_ms = 10U , k_gpt_capture_min_delta_ms = 50U } |
| Demo tunables. More... | |
| enum | gpt_capture_layout_t : uint8_t { k_gpt_capture_channel = 0U } |
| Channel + LED selection. More... | |
Functions | |
| static void | internal_panic_halt (void) |
| Park the CPU after a fatal initialization failure. | |
| static void | internal_setup_or_halt (void) |
| Bring CGC + SysTick + LEDs + SW1 + GPT0 up. | |
| static uint32_t | internal_read (void) |
| Read current GPT counter ticks, or return UINT32_MAX on err. | |
| static bool | internal_edge (ra8_board_sw_state_t *prev) |
| Detect a falling edge on SW1. | |
| void | main (void) |
| Run the software input-capture and GPT liveness loop. | |
Variables | |
| volatile uint32_t | g_gpt_capture_tick = 0U |
| HIL liveness counter – incremented every iteration where the GPT counter advanced relative to the previous sample (proves GTCNT is actually counting). | |
GPT input-capture-style demo: measure SW1 press period.
Programs GPT0 as a free-running 32-bit up-counter with prescaler PCLKD/64. On each falling edge of SW1 (active-low) the application latches the current GPT counter value and computes the delta from the previous press: that delta is the measured "input capture period" in GPT counter ticks. The lowest LED is toggled on every captured edge so a human can see live activity.
Note: the RA8D2 GPT supports hardware GTIOC pin capture, and the HAL now exposes it via ra8_gpt_capture_configure / ra8_gpt_capture_read. This demo deliberately stays on the free-run + counter-read primitives and approximates input capture in software via SW1 polling, so it needs no external signal source and stays HIL-able on a bare EVM. The real hardware-capture + external-event-count path is demonstrated by the gpt_edge_capture_count hw_pending app.
Definition in file main.c.
| enum gpt_capture_const_t : uint32_t |
| enum gpt_capture_layout_t : uint8_t |
|
static |
Detect a falling edge on SW1.
Samples SW1 once, compares released-to-pressed state, and updates the caller-owned prior sample only when the board read succeeds.
| [in,out] | prev | Last sampled state (updated on return). |
| true | The sample changed from released to pressed. |
| false | No falling edge was observed or the board read failed. |
Definition at line 183 of file main.c.
References k_ra8_board_sw1, k_ra8_board_sw_pressed, k_ra8_board_sw_released, k_ra8_ok, ra8_board_sw_read(), and RA8_INTERNAL.
Referenced by main().
|
static |
Park the CPU after a fatal initialization failure.
Repeatedly executes WFI, preserving the failed peripheral state for an attached debugger until reset.
Definition at line 81 of file main.c.
References RA8_INTERNAL.
|
static |
Read current GPT counter ticks, or return UINT32_MAX on err.
Delegates to the channel-zero HAL accessor and maps any HAL error onto a sentinel that the foreground liveness probe can ignore.
| UINT32_MAX | The counter read failed. |
| 0..UINT32_MAX-1 | A sampled counter value. |
Definition at line 150 of file main.c.
References k_gpt_capture_channel, k_ra8_ok, ra8_gpt_read(), and RA8_INTERNAL.
Referenced by main().
|
static |
Bring CGC + SysTick + LEDs + SW1 + GPT0 up.
Initializes the clock tree and delay service, configures LED1 and SW1, then starts GPT0 as a PCLKD/64 free-running counter. A failed prerequisite transfers control to the panic helper.
Definition at line 102 of file main.c.
References internal_panic_halt(), k_gpt_capture_channel, k_gpt_capture_period, k_ra8_board_led1, k_ra8_board_sw1, k_ra8_clock_id_cpuclk0, k_ra8_gpt_mode_saw_pwm, k_ra8_gpt_ps_div_64, k_ra8_ok, ra8_board_led_init(), ra8_board_sw_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_gpt_init(), RA8_INTERNAL, and ra8_time_init().
| void main | ( | void | ) |
Run the software input-capture and GPT liveness loop.
The application entry point Reset_Handler hands control to.
Initializes the demo, tracks falling SW1 edges as counter deltas, and independently increments the exported liveness counter whenever successive GPT samples advance.
Definition at line 208 of file main.c.
References g_gpt_capture_tick, internal_edge(), internal_panic_halt(), internal_read(), internal_setup_or_halt(), k_gpt_capture_poll_period_ms, k_ra8_board_led1, k_ra8_board_sw_released, ra8_board_led_toggle(), ra8_delay_ms(), and ra8_isr_globals_enable().
| volatile uint32_t g_gpt_capture_tick = 0U |
HIL liveness counter – incremented every iteration where the GPT counter advanced relative to the previous sample (proves GTCNT is actually counting).
Read by hil_jlink_memprobe.sh. SW1-button-driven input capture is out-of-scope for automated HIL (would need a wire loopback), so the gate just confirms the free-running counter the demo uses for delta measurement is alive.
Definition at line 61 of file main.c.
Referenced by main().