|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
GPTP hardware-timer demo – proves the HUM Ch 35 counter really runs. More...
#include <stddef.h>#include <stdint.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_eth_gptp.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | gptp_const_t : uint32_t { k_gptp_baud = 115200U , k_gptp_period_ms = 1000U , k_gptp_window_ms = 500U , k_gptp_base_sec = 1000000000U } |
| Demo tunables. More... | |
| enum | gptp_flatten_limit_t : uint64_t { k_gptp_sec_flatten_max = 18446744073ULL } |
| Largest seconds value that can be flattened to nanoseconds. More... | |
| enum | gptp_fmt_t : uint32_t { k_gptp_radix = 10U , k_gptp_dec_u64_max = 20U , k_gptp_ns_per_ms = 1000000U , k_gptp_ns_per_sec = 1000000000U } |
| Formatting and arithmetic constants. More... | |
| enum | gptp_band_t : uint8_t { k_gptp_tolerance_pct = 10U , k_gptp_pct_full = 100U } |
| Accuracy band the measured advance must fall inside. More... | |
Functions | |
| static void | gptp_panic_halt (void) |
| Park forever after a fatal init error. | |
| static void | gptp_write (const uint8_t *data, uint32_t len) |
| Write a byte span to the SCI8 console, discarding the status. | |
| static void | gptp_write_u64 (uint64_t val) |
| Log one unsigned 64-bit value as decimal ASCII. | |
| static void | gptp_log_time (uint64_t sec, uint32_t nsec) |
| Log one gptp: t= line – seconds, a dot, then nanoseconds. | |
| static uint64_t | gptp_flatten_ns (uint64_t sec, uint32_t nsec) |
| Flatten a GPTP sample to nanoseconds. | |
| static bool | gptp_probe_presence (void) |
| Read the IP-version word and require it to be nonzero. | |
| static bool | gptp_advance_ok (uint64_t advance_ns, uint32_t elapsed_ms) |
| Decide whether a measured advance matches the SysTick window. | |
| static bool | gptp_measure (void) |
| Sample the counter twice around a SysTick-timed window. | |
| static bool | gptp_run_cycle (void) |
| Run one cycle: presence probe plus one advance measurement. | |
| static void | gptp_setup_or_halt (void) |
| Core bring-up: CGC -> ESWCLK -> MSTP -> TIME -> console + LED. | |
| static ra8_err_t | gptp_arm (void) |
| Programme the GPTP timer from the live ESWCLK and start it. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const uint8_t | k_gptp_ipv_prefix [] = "gptp: ipv=" |
| static const uint8_t | k_gptp_time_prefix [] = "gptp: t=" |
| static const uint8_t | k_gptp_time_dot [] = "." |
| static const uint8_t | k_gptp_adv_prefix [] = "gptp: adv_ns=" |
| static const uint8_t | k_gptp_sys_prefix [] = " sys_ms=" |
| static const uint8_t | k_gptp_crlf [] = "\r\n" |
| static const uint8_t | k_gptp_verdict_pass [] = "gptp: clock PASS\r\n" |
| static const uint8_t | k_gptp_verdict_fail [] = "gptp: clock FAIL\r\n" |
GPTP hardware-timer demo – proves the HUM Ch 35 counter really runs.
Exercises the only PTP-related hardware the RA8D2 actually has: the Ethernet Generic PTP Timer of HUM Ch 35 p 1925-1964. That block is a timer – it has no Sync / Announce generator, no domain, no clockIdentity and no BMCA – so this app makes no claim to be an IEEE 1588 or 802.1AS node. It brings the counter up and then measures it.
Bring-up (CGC -> ESWCLK -> MSTP -> TIME -> peripheral):
Per cycle the app:
The verdict "gptp: clock PASS" therefore means the counter advanced one second per second against an independent time base – not merely that a driver call returned k_ra8_ok.
hw_pending: this stays under hw_pending because the full IEEE-1588 / 802.1AS claim (a bounded sync offset against the bench's gPTP peer) can only be made on the bench. Its counter-advance verdict, however, is now gated in the emulator: tools/ra8_emulator models the HUM Ch 35 GPTP timer (board_periph_gptp.c), whose free-running counter really advances one second per second against the emulator's SysTick, so gptp: clock PASS is asserted on every CI run through the emulator-smoke gate as well as on the bench.
Definition in file main.c.
| enum gptp_band_t : uint8_t |
| enum gptp_const_t : uint32_t |
| enum gptp_flatten_limit_t : uint64_t |
| enum gptp_fmt_t : uint32_t |
|
static |
Decide whether a measured advance matches the SysTick window.
| [in] | advance_ns | Nanoseconds the GPTP counter moved. |
| [in] | elapsed_ms | Milliseconds SysTick measured over the same window. |
The band is a percentage of the SysTick-measured interval, so it scales with the window and needs no absolute tolerance constant. band_ns can never exceed expected_ns, so the lower comparison cannot underflow.
| true | The advance is inside the band. |
| false | The advance is outside the band, or no time elapsed. |
Definition at line 306 of file main.c.
References k_gptp_ns_per_ms, k_gptp_pct_full, and k_gptp_tolerance_pct.
Referenced by gptp_measure().
|
staticnodiscard |
Programme the GPTP timer from the live ESWCLK and start it.
Reads the ESWCLK frequency published by ra8_cgc_eswclk_init, hands it to ra8_eth_gptp_init (which derives PTPTIVCt), loads k_gptp_base_sec into the 78-bit offset and enables the timer unit.
| k_ra8_ok | The counter is programmed and running. |
| Other | Forwarded from the failing driver call. |
Definition at line 465 of file main.c.
References k_gptp_base_sec, k_ra8_gptp_timer_0, k_ra8_ok, ra8_cgc_eswclk_hz(), ra8_eth_gptp_init(), ra8_eth_gptp_set_offset(), and ra8_eth_gptp_timer_enable().
Referenced by main().
|
static |
Flatten a GPTP sample to nanoseconds.
The seconds field is 48 bits wide, so sec * 1e9 would wrap a uint64_t above sec ~= 1.8e10. That is far beyond any epoch this demo loads, but it is a value read straight off a hardware register, so an implausible reading is clamped to UINT64_MAX rather than silently wrapped into a small number that could look like a healthy advance.
| [in] | sec | Seconds field. |
| [in] | nsec | Nanoseconds field. |
Definition at line 242 of file main.c.
References k_gptp_ns_per_sec, and k_gptp_sec_flatten_max.
Referenced by gptp_measure().
|
static |
Log one gptp: t= line – seconds, a dot, then nanoseconds.
Prints the two fields verbatim rather than converting to a single nanosecond count, so a bench operator sees exactly what the registers held.
| [in] | sec | Seconds field of a GPTP sample. |
| [in] | nsec | Nanoseconds field of the same sample. |
Definition at line 209 of file main.c.
References gptp_write(), gptp_write_u64(), k_gptp_crlf, k_gptp_time_dot, and k_gptp_time_prefix.
Referenced by gptp_measure().
|
static |
Sample the counter twice around a SysTick-timed window.
| true | The counter advanced by the measured interval. |
| false | A read failed, or the counter did not track SysTick. |
Definition at line 335 of file main.c.
References gptp_advance_ok(), gptp_flatten_ns(), gptp_log_time(), gptp_write(), gptp_write_u64(), k_gptp_adv_prefix, k_gptp_crlf, k_gptp_sys_prefix, k_gptp_window_ms, k_ra8_gptp_timer_0, k_ra8_ok, ra8_delay_ms(), ra8_eth_gptp_get_time(), and ra8_time_ms().
Referenced by gptp_run_cycle().
|
static |
Park forever after a fatal init error.
wfi in a bare loop rather than a spin so the part idles cold while a bench operator attaches a debugger.
Definition at line 120 of file main.c.
Referenced by gptp_setup_or_halt(), and main().
|
static |
Read the IP-version word and require it to be nonzero.
A reserved aperture either reads 0 or echoes the last write; PTPIPV is read-only with a nonzero reset value (HUM 35.3.1.1 p 1927), so a nonzero read is evidence the GPTP block is really mapped here.
| true | PTPIPV read back a nonzero version word. |
| false | The read failed, or the aperture returned 0. |
Definition at line 270 of file main.c.
References gptp_write(), gptp_write_u64(), k_gptp_crlf, k_gptp_ipv_prefix, k_ra8_ok, and ra8_eth_gptp_ip_version().
Referenced by gptp_run_cycle().
|
static |
Run one cycle: presence probe plus one advance measurement.
Both halves run unconditionally so one log block always appears, even when the first check has already failed – a bench operator needs the numbers from the failing cycle, not just the verdict.
| true | Presence probe and advance measurement both held. |
| false | At least one of them did not. |
Definition at line 392 of file main.c.
References gptp_measure(), and gptp_probe_presence().
Referenced by main().
|
static |
Core bring-up: CGC -> ESWCLK -> MSTP -> TIME -> console + LED.
ESWCLK comes last because ra8_cgc_eswclk_init powers the ESWM domain and needs HOCO and the PLL already stable.
Definition at line 419 of file main.c.
References gptp_panic_halt(), k_gptp_baud, k_ra8_board_led1, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_eswclk_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), and ra8_time_init().
Referenced by main().
|
static |
Write a byte span to the SCI8 console, discarding the status.
| [in] | data | Non-NULL byte span to transmit. |
| [in] | len | Byte count (0 is a no-op). |
The console status is discarded deliberately: this app's verdict is about the GPTP counter, and a UART hiccup must not be reported as a clock fault.
Definition at line 145 of file main.c.
References ra8_board_uart_console_write().
Referenced by gptp_log_time(), gptp_measure(), gptp_probe_presence(), gptp_write_u64(), and main().
|
static |
Log one unsigned 64-bit value as decimal ASCII.
| [in] | val | Value to print. |
Digits are generated least-significant first into a scratch buffer and reversed, so no division-by-power-of-ten table is needed. Both buffers are k_gptp_dec_u64_max bytes, the exact width of UINT64_MAX at k_gptp_radix, which is what bounds the generate loop.
Definition at line 169 of file main.c.
References gptp_write(), k_gptp_dec_u64_max, and k_gptp_radix.
Referenced by gptp_log_time(), gptp_measure(), and gptp_probe_presence().
| 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 485 of file main.c.
References gptp_arm(), gptp_panic_halt(), gptp_run_cycle(), gptp_setup_or_halt(), gptp_write(), k_gptp_period_ms, k_gptp_verdict_fail, k_gptp_verdict_pass, k_ra8_board_led1, k_ra8_ok, ra8_board_led_toggle(), ra8_delay_ms(), and ra8_isr_globals_enable().
|
static |
Definition at line 99 of file main.c.
Referenced by gptp_measure().
|
static |
Definition at line 101 of file main.c.
Referenced by gptp_log_time(), gptp_measure(), and gptp_probe_presence().
|
static |
Definition at line 96 of file main.c.
Referenced by gptp_probe_presence().
|
static |
Definition at line 100 of file main.c.
Referenced by gptp_measure().
|
static |
Definition at line 98 of file main.c.
Referenced by gptp_log_time().
|
static |
Definition at line 97 of file main.c.
Referenced by gptp_log_time().
|
static |