|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
PWM Delay Generation (PDG) bring-up + delay-program demo (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_check.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_pdg.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | pdg_demo_config_t : uint32_t { k_pdg_demo_baud = 115200U , k_pdg_demo_period_ms = 1000U } |
| Compile-time settings. More... | |
| enum | pdg_demo_chan_t : uint8_t { k_pdg_demo_channel = 0U , k_pdg_demo_chan_mask = 0x01U , k_pdg_demo_delay_code = 0x40U } |
| PDG channel + delay programmed by this demo. More... | |
Functions | |
| static void | internal_pdg_demo_panic_halt (void) |
| Park the processor after a fatal initialization failure. | |
| static void | internal_pdg_demo_setup_or_halt (void) |
| Bring CGC, SysTick, SCI8, LEDs, and MSTP support up. | |
| static ra8_err_t | internal_pdg_demo_configure (void) |
| Bring up the PDG DLL on channel 0 and programme a delay code. | |
| static ra8_err_t | internal_pdg_demo_sample (uint8_t *out_ok) |
| Read the PDG status and fold the bring-up into the verdict. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const char * | s_tag = "pdg_demo" |
| Diagnostic / log tag. | |
| static const uint8_t | s_pdg_demo_ok_msg [] = "pdg: dll=on ch0=on delay=0x40 cfg=ok\r\n" |
| Output line tags. | |
| static const uint8_t | s_pdg_demo_bad_msg [] = "pdg: cfg=BAD\r\n" |
| volatile uint32_t | g_pdg_cfg_ok = 0U |
| 1 when the DLL + channel + delay read back as configured. | |
| volatile uint32_t | g_pdg_delay_readback = 0U |
| Last delay code read back from the PDG temporary register. | |
| volatile uint32_t | g_pdg_dll = 0U |
| 1 when GTDLYCR.DLLEN reads back enabled. | |
| volatile uint32_t | g_pdg_heartbeat = 0U |
| Bumps once per main-loop pass – liveness for headless probes. | |
PWM Delay Generation (PDG) bring-up + delay-program demo (EK-RA8D2).
The PDG block adds a fine, DLL-derived delay (DLY[6:0], 1/128 of the GPT core-clock period per step in the 80..160 MHz band) to the rising and falling edges of a GPT32 channel's GTIOCnA / GTIOCnB outputs, so a PWM edge can be nudged with sub-nanosecond resolution. This demo brings the PDG DLL up on channel 0, programs a mid-range delay code (0x40) on the GTIOC0A rising edge, and reports the configured bring-up state.
Bring-up: CGC + SysTick + SCI8 + LEDs + MSTP. Once a second the loop reads the PDG status and reports "pdg: dll=on ch0=on delay=0x40 cfg=ok\r\n" on the J-Link OB CDC channel. LED1 toggles while the configuration reads back clean; LED2 toggles otherwise.
Bare EK-RA8D2 only – no shields or external transceivers.
Definition in file main.c.
| enum pdg_demo_chan_t : uint8_t |
| enum pdg_demo_config_t : uint32_t |
|
staticnodiscard |
Bring up the PDG DLL on channel 0 and programme a delay code.
Configures the 80..160 MHz FRANGE band, enables PDG channel 0, then writes a mid-range delay (0x40) onto the GTIOC0A rising edge. The code lands in the PDG temporary register and would propagate to the live delay on the next GPT overflow/underflow once a GPT32_0 PWM source is running (out of scope here – see the bench plan).
| k_ra8_ok | The DLL and channel accepted the requested delay setup. |
Definition at line 188 of file main.c.
References k_pdg_demo_chan_mask, k_pdg_demo_channel, k_pdg_demo_delay_code, k_ra8_ok, k_ra8_pdg_edge_rising, k_ra8_pdg_frange_80_160_mhz, k_ra8_pdg_pin_a, RA8_INTERNAL, ra8_pdg_init(), and ra8_pdg_set_delay().
Referenced by main().
|
static |
Park the processor after a fatal initialization failure.
Executes wait-for-interrupt indefinitely to prevent application progress with incomplete clock, timing, console, LED, or MSTP setup.
Definition at line 119 of file main.c.
References RA8_INTERNAL.
Referenced by internal_pdg_demo_setup_or_halt(), and main().
|
staticnodiscard |
Read the PDG status and fold the bring-up into the verdict.
Reads the staged delay for emulator visibility and the full PDG status for the silicon-observable DLL, power, and bypass verdict.
| [out] | out_ok | 1 when the DLL is enabled and channel 0 is powered and un-bypassed (the software-observable bring-up). The delay code is staged by internal_pdg_demo_configure but is not read-exposed on silicon, so it is not part of the verdict. |
| k_ra8_ok | Both status reads completed and out_ok was populated. |
| k_ra8_err_null_ptr | out_ok was NULL. |
out_ok addresses writable storage for one verdict byte. out_ok contains exactly zero or one. Definition at line 231 of file main.c.
References ra8_pdg_status_full_t::dll_enabled, g_pdg_delay_readback, g_pdg_dll, k_pdg_demo_channel, k_ra8_ok, k_ra8_pdg_edge_rising, k_ra8_pdg_pin_a, ra8_pdg_status_full_t::per_channel_bypass_off, ra8_pdg_status_full_t::per_channel_powered, RA8_CHECK_NULL_PTR, RA8_INTERNAL, ra8_pdg_get_delay(), ra8_pdg_get_status_full(), and s_tag.
Referenced by main().
|
static |
Bring CGC, SysTick, SCI8, LEDs, and MSTP support up.
Initializes all PDG-demo prerequisites in dependency order and transfers to internal_pdg_demo_panic_halt on the first failure.
Definition at line 139 of file main.c.
References internal_pdg_demo_panic_halt(), k_pdg_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 262 of file main.c.
References g_pdg_cfg_ok, g_pdg_heartbeat, internal_pdg_demo_configure(), internal_pdg_demo_panic_halt(), internal_pdg_demo_sample(), internal_pdg_demo_setup_or_halt(), k_pdg_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_pdg_demo_bad_msg, and s_pdg_demo_ok_msg.
| volatile uint32_t g_pdg_cfg_ok = 0U |
| volatile uint32_t g_pdg_delay_readback = 0U |
Last delay code read back from the PDG temporary register.
Definition at line 88 of file main.c.
Referenced by internal_pdg_demo_sample().
| volatile uint32_t g_pdg_dll = 0U |
1 when GTDLYCR.DLLEN reads back enabled.
Definition at line 96 of file main.c.
Referenced by internal_pdg_demo_sample().
| volatile uint32_t g_pdg_heartbeat = 0U |
|
static |
|
static |