|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
POEG (Port Output Enable for GPT) safe-shutoff demo for the EK-RA8D2. More...
#include <stddef.h>#include <stdint.h>#include "ra8_attributes.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_gpt.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_poeg.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | poeg_demo_config_t : uint32_t { k_poeg_demo_baud = 115200U , k_poeg_demo_period_ms = 1000U , k_poeg_demo_settle_ms = 2U , k_poeg_demo_gpt_prd = 0x0000FFFFU , k_poeg_demo_gpt_duty = 0x00008000U } |
| Compile-time settings. More... | |
| enum | poeg_demo_unit_t : uint8_t { k_poeg_demo_gpt_channel = 0U , k_poeg_demo_group = 0U } |
| GPT channel + POEG group the demo pairs. More... | |
Functions | |
| static void | internal_poeg_demo_panic_halt (void) |
| Park forever after a fatal initialization failure. | |
| static void | internal_poeg_demo_setup_or_halt (void) |
| Bring CGC + SysTick + MSTP + SCI console + LEDs up. | |
| static ra8_err_t | internal_poeg_demo_arm_gpt (void) |
| Configure GPT0 for saw-wave PWM with auto_start = true. | |
| static ra8_err_t | internal_poeg_demo_arm_poeg (void) |
| Arm POEG group 0 to accept an output-disable request. | |
| static ra8_err_t | internal_poeg_demo_cycle (uint8_t *out_ok) |
| Run one safe-shutoff cycle and fold the result into the verdict. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const char * | s_tag = "poeg_demo" |
| Diagnostic / log tag. | |
| static const uint8_t | s_poeg_demo_ok_msg [] = "poeg: pwm=run shutoff=highZ reenable=on ok=Y\r\n" |
| Success banner for a complete safe-shutoff and re-enable cycle. | |
| static const uint8_t | s_poeg_demo_bad_msg [] = "poeg: pwm=? shutoff=? reenable=? ok=N\r\n" |
| Failure banner for an incomplete POEG safety cycle. | |
| volatile uint32_t | g_poeg_shutoffs = 0U |
| Count of healthy safe-shutoff cycles completed (assert + re-enable). | |
| volatile uint32_t | g_poeg_last_status = 0U |
| Last POEGG snapshot latched immediately after the shutoff assert. | |
| volatile uint32_t | g_poeg_heartbeat = 0U |
| Bumps once per main-loop pass – liveness for headless probes. | |
| volatile uint32_t | g_poeg_mismatch = 0U |
| Latches the count of cycles whose verdict was not healthy. | |
POEG (Port Output Enable for GPT) safe-shutoff demo for the EK-RA8D2.
POEG forces the outputs of a GPT channel into a safe (high-impedance) state WITHOUT CPU involvement the moment a fault is detected – the mechanism a motor-control H-bridge relies on so an over-current trip kills the PWM in a single cycle. This demo drives a GPT PWM output, then exercises the full safe-shutoff cycle every second:
The GPT COUNTER keeps advancing across the shutoff (POEG gates the output pins, not the counter), so the demo also samples GTCNT before and after the hold to prove the timer is really running.
Bring-up: CGC + SysTick + MSTP + SCI console + LEDs, then GPT0 (saw PWM, auto-start) and POEG group 0. Each pass reports "poeg: pwm=run shutoff=highZ reenable=on ok=Y\r\n" on the J-Link OB CDC channel; LED1 toggles on a healthy cycle, LED2 on a fault.
On silicon the external fault input (GTETRG pin) additionally routes to the POEG group when enable_pin is set and the GPT output-disable request is wired to the group; this demo proves the request / STATE / clear path plus a live PWM using the deterministic software trigger, which is what the headless ra8_emulator gate can verify with no physical pin to scope.
Definition in file main.c.
| enum poeg_demo_config_t : uint32_t |
| enum poeg_demo_unit_t : uint8_t |
|
staticnodiscard |
Configure GPT0 for saw-wave PWM with auto_start = true.
Uses the same full-descriptor path the gpt_pwm_demo uses so the GPT counter advances immediately and drives a mid-scale PWM the POEG group can gate.
| k_ra8_ok | GPT0 armed and counting. |
Definition at line 209 of file main.c.
References k_poeg_demo_gpt_channel, k_poeg_demo_gpt_duty, k_poeg_demo_gpt_prd, k_ra8_gpt_mode_saw_pwm, k_ra8_gpt_ps_div_4, ra8_gpt_init(), and RA8_INTERNAL.
Referenced by main().
|
staticnodiscard |
Arm POEG group 0 to accept an output-disable request.
Enables the external GTETRG fault-input path (enable_pin) so a real over- current comparator wired to the POEG pin would trip the shutoff on silicon; the demo itself drives the deterministic software trigger. No output-short / oscillation-stop sources are armed.
| k_ra8_ok | POEG group 0 powered and armed. |
Definition at line 245 of file main.c.
References k_poeg_demo_group, RA8_INTERNAL, and ra8_poeg_init().
Referenced by main().
|
staticnodiscard |
Run one safe-shutoff cycle and fold the result into the verdict.
| [out] | out_ok | 1 when the whole assert -> high-Z -> clear -> re-enable cycle behaved AND the PWM counter advanced. |
Samples GTCNT, asserts the POEG software stop (SSF), confirms the derived output-disable STATE flag (POEGG.ST) latched high (outputs high-impedance), holds the shutoff for k_poeg_demo_settle_ms while the counter keeps running, clears the request, confirms ST returned to 0 (outputs re-enabled), then re-samples GTCNT. Healthy iff the shutoff latched, the re-enable cleared it, AND GTCNT advanced across the hold.
| k_ra8_ok | Cycle ran; *out_ok is 0 or 1. |
| k_ra8_err_null_ptr | out_ok was NULL. |
Definition at line 286 of file main.c.
References g_poeg_last_status, k_poeg_demo_gpt_channel, k_poeg_demo_group, k_poeg_demo_settle_ms, k_ra8_ok, k_ra8_poeg_status_ssf, k_ra8_poeg_status_st, RA8_CHECK_NULL_PTR, ra8_delay_ms(), ra8_gpt_read(), RA8_INTERNAL, ra8_poeg_clear_status(), ra8_poeg_get_status(), ra8_poeg_trigger_stop(), and s_tag.
Referenced by main().
|
static |
Park forever after a fatal initialization failure.
Retains GPT, POEG, and setup state for inspection in a permanent WFI loop.
Definition at line 143 of file main.c.
References RA8_INTERNAL.
Referenced by internal_poeg_demo_setup_or_halt(), and main().
|
static |
Bring CGC + SysTick + MSTP + SCI console + LEDs up.
Initializes every dependency required to configure and observe the GPT/POEG cycle, stopping terminally on the first failure.
Definition at line 161 of file main.c.
References internal_poeg_demo_panic_halt(), k_poeg_demo_baud, k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_mstp_init(), and ra8_time_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.
Definition at line 339 of file main.c.
References g_poeg_heartbeat, g_poeg_mismatch, g_poeg_shutoffs, internal_poeg_demo_arm_gpt(), internal_poeg_demo_arm_poeg(), internal_poeg_demo_cycle(), internal_poeg_demo_panic_halt(), internal_poeg_demo_setup_or_halt(), k_poeg_demo_period_ms, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_isr_globals_enable(), s_poeg_demo_bad_msg, and s_poeg_demo_ok_msg.
| volatile uint32_t g_poeg_heartbeat = 0U |
| volatile uint32_t g_poeg_last_status = 0U |
Last POEGG snapshot latched immediately after the shutoff assert.
Definition at line 115 of file main.c.
Referenced by internal_poeg_demo_cycle().
| volatile uint32_t g_poeg_mismatch = 0U |
| volatile uint32_t g_poeg_shutoffs = 0U |
|
static |
|
static |