|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
HAL SysTick + DWT timebase demo for EK-RA8D2 (SCI8 @ 115200). 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_isr.h"#include "ra8_systick.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | hal_timebase_config_t : uint32_t { k_demo_baud = 115200U , k_demo_period_ms = 1000U , k_demo_tick_hz = 1000U , k_demo_u32_digits = 10U , k_demo_hz_per_mhz = 1000000U , k_demo_dec_base = 10U } |
| Compile-time settings for the demo. More... | |
Functions | |
| static void | demo_panic_halt (void) |
| Halt forever in WFI – used as a panic stop on init failure. | |
| static void | demo_emit (const uint8_t *data, size_t len) |
| Write a byte span to the SCI8 console, ignoring flow-control errors. | |
| static void | demo_emit_u32 (uint32_t value) |
| Emit a uint32_t as decimal ASCII over the console. | |
| static ra8_err_t | demo_setup_or_halt (uint32_t *out_cpuclk_hz) |
| Bring up CGC + raw ra8_time + console + LED + the HAL timebase. | |
| static void | demo_emit_measurement (uint32_t cpuclk_hz) |
| Emit one measurement line: DWT-timed length of a 1 s delay. | |
| void | main (void) |
| Application entry. | |
Variables | |
| static const uint8_t | k_demo_lbl_reload [] = "reload=" |
| Label emitted once with the HAL-computed SysTick reload. | |
| static const uint8_t | k_demo_lbl_ms [] = "hal timebase ms=" |
| Label opening each per-second measurement line. | |
| static const uint8_t | k_demo_lbl_cycles [] = " cycles=" |
| Field separator before the DWT cycle count. | |
| static const uint8_t | k_demo_lbl_us [] = " us=" |
| Field separator before the derived microseconds. | |
| static const uint8_t | k_demo_crlf [] = "\r\n" |
| Line terminator. | |
HAL SysTick + DWT timebase demo for EK-RA8D2 (SCI8 @ 115200).
Exercises the ra8_core SysTick / DWT timebase primitive (ra8_systick_reload_for, ra8_systick_configure, ra8_systick_current_value, ra8_dwt_cyccnt_enable / ra8_dwt_cyccnt_reset / ra8_dwt_cyccnt_read) on real silicon, ALONGSIDE the existing raw-poke ra8_time path, so the two can be diffed on the bench (issue #582). Both program the same architectural SysTick registers; this app shows the HAL primitive producing the identical reload the raw path uses, and uses the DWT cycle counter to measure the wall-clock length of an ra8_delay_ms() produced by the raw path.
Sequence:
Verification: open the J-Link OB CDC port at 115200 8N1. You should see a reload=999999 line once, then a hal timebase ms=1000 cycles=<n> us=<n> line per second with LED1 toggling in lock-step. On a 1 GHz core the measured microseconds land near 1000000 for a 1000 ms delay.
Definition in file main.c.
| enum hal_timebase_config_t : uint32_t |
Compile-time settings for the demo.
|
static |
Write a byte span to the SCI8 console, ignoring flow-control errors.
Thin wrapper over the board console so the callers below read as a sequence of field emissions. A transient console error is non-fatal for a demo, so the return is intentionally discarded.
| [in] | data | Pointer to the bytes to emit. Must be non-NULL. |
| [in] | len | Number of bytes to emit. Zero is a no-op. |
Definition at line 118 of file main.c.
References ra8_board_uart_console_write().
Referenced by demo_emit_measurement(), demo_emit_u32(), and demo_setup_or_halt().
|
static |
Emit one measurement line: DWT-timed length of a 1 s delay.
Zeroes the DWT counter, runs ra8_delay_ms(k_demo_period_ms) (the raw path), samples the elapsed cycles, and derives microseconds as cycles / (cpuclk_hz / 1e6). The divisor is floored at one so a sub-MHz clock cannot divide by zero.
| [in] | cpuclk_hz | Live CPUCLK0 in Hz, used to convert cycles to us. |
Definition at line 249 of file main.c.
References demo_emit(), demo_emit_u32(), k_demo_crlf, k_demo_hz_per_mhz, k_demo_lbl_cycles, k_demo_lbl_ms, k_demo_lbl_us, k_demo_period_ms, ra8_delay_ms(), ra8_dwt_cyccnt_read(), and ra8_dwt_cyccnt_reset().
Referenced by main().
|
static |
Emit a uint32_t as decimal ASCII over the console.
Formats value into a fixed 10-byte scratch buffer from the least significant digit up, then emits the significant span. Uses only single-condition, statically bounded loops (at most 10 iterations) so it carries no compound decision and no unbounded loop.
| [in] | value | Value to print in base ten. |
value has been queued to the console. Definition at line 141 of file main.c.
References demo_emit(), k_demo_dec_base, and k_demo_u32_digits.
Referenced by demo_emit_measurement(), and demo_setup_or_halt().
|
static |
Halt forever in WFI – used as a panic stop on init failure.
Parks the core so a boot failure is a visible dead LED / silent console rather than undefined execution. Only a debugger or an external reset resumes it.
Definition at line 93 of file main.c.
Referenced by demo_fs_format_or_panic(), demo_lx_format_or_panic(), demo_lx_open_or_panic(), demo_setup_or_halt(), demo_setup_or_halt(), and main().
|
static |
Bring up CGC + raw ra8_time + console + LED + the HAL timebase.
Runs the raw ra8_time_init() path first (it arms SysTick + DWT and backs ra8_delay_ms()), then re-arms the SAME SysTick through the HAL primitive with the reload the HAL arithmetic derives – demonstrating the primitive substitutes for the raw poke with no timing change. Panic-halts on any failure. On success the HAL-computed reload has been emitted once.
| [out] | out_cpuclk_hz | Receives the live CPUCLK0 frequency in Hz. |
| k_ra8_ok | Everything up; *out_cpuclk_hz is valid. |
| k_ra8_err_invalid_arg | out_cpuclk_hz is NULL. |
Definition at line 187 of file main.c.
References demo_emit(), demo_emit_u32(), demo_panic_halt(), k_demo_baud, k_demo_crlf, k_demo_lbl_reload, k_demo_tick_hz, k_ra8_board_led1, k_ra8_clock_id_cpuclk0, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_systick_clk_cpu, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_dwt_cyccnt_enable(), ra8_systick_configure(), ra8_systick_reload_for(), and ra8_time_init().
| void main | ( | void | ) |
Application entry.
The application entry point Reset_Handler hands control to.
Brings up the timebase then measures forever.
Definition at line 281 of file main.c.
References demo_emit_measurement(), demo_panic_halt(), demo_setup_or_halt(), k_ra8_board_led1, k_ra8_ok, ra8_board_led_toggle(), and ra8_isr_globals_enable().
|
static |
Line terminator.
Definition at line 76 of file main.c.
Referenced by demo_emit_measurement(), and demo_setup_or_halt().
|
static |
Field separator before the DWT cycle count.
Definition at line 72 of file main.c.
Referenced by demo_emit_measurement().
|
static |
Label opening each per-second measurement line.
Definition at line 70 of file main.c.
Referenced by demo_emit_measurement().
|
static |
Label emitted once with the HAL-computed SysTick reload.
Definition at line 68 of file main.c.
Referenced by demo_setup_or_halt().
|
static |
Field separator before the derived microseconds.
Definition at line 74 of file main.c.
Referenced by demo_emit_measurement().