ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

Power-mode profiler smoke app for the EK-RA8D2. More...

#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_lpm.h"
#include "ra8_mstp.h"
#include "ra8_power_profile.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  pp_demo_const_t : uint32_t {
  k_pp_demo_baud = 115200U ,
  k_pp_demo_period_ms = 1000U ,
  k_pp_demo_busy_iters = 100000U ,
  k_pp_demo_us_per_ms = 1000U
}
 App-wide tunables. More...
enum  pp_demo_byte_t : uint8_t {
  k_pp_demo_ascii_zero = '0' ,
  k_pp_demo_dec_base = 10U ,
  k_pp_demo_uint_dec_max = 10U ,
  k_pp_demo_print_buf = 96U
}
 Single-byte ASCII conversion constants. More...

Functions

static void pp_demo_panic_halt (void)
 Park forever after a fatal init failure.
static uint64_t pp_demo_now_us (void *ctx)
 Time-base hook for the profiler – wraps ra8_time_ms to us.
static void pp_demo_clocks_or_halt (void)
 Bring CGC + SysTick + MSTP + UART console up.
static void pp_demo_modules_or_halt (void)
 Bring LPM + power profiler + LEDs up; panic-halts on fail.
static void pp_demo_setup_or_halt (void)
static bool pp_demo_cycle_modes (void)
 Cycle through ACTIVE -> SLEEP -> DEEP_SLEEP -> SOFTWARE_STANDBY, marking entry/exit on each.
static uint8_t pp_demo_uint_to_dec (uint8_t *buf, uint64_t v)
 Write a decimal uint64 (low 32 bits) into buf.
static uint32_t pp_demo_append (uint8_t *buf, uint32_t off, const char *tag, uint64_t val)
 Append tag then the decimal of val to buf at off.
static uint32_t pp_demo_format_line (uint8_t *out, const ra8_power_profile_stats_t *stats)
 Format the per-cycle stats line into out.
void main (void)
 Application entry.

Variables

static const uint8_t k_pp_demo_pass_msg [] = "pp: profile OK\r\n"
 Success verdict line emitted only when a full mode cycle and the stats read both returned k_ra8_ok (never on a "pp: FAIL" path); this is the success-only string the HIL scrape keys on.

Detailed Description

Power-mode profiler smoke app for the EK-RA8D2.

Tag
[Ring 6 / APP] {World: S}

Standalone EVM-tier app that drives the libs/ra8_power_profile/inc/ra8_power_profile.h accumulator across the four interesting RA8D2 low-power modes – ACTIVE, SLEEP, DEEP_SLEEP, and SOFTWARE_STANDBY – and reports the dwell time of each region over SCI8.

Each cycle:

  1. ra8_power_profile_mark_enter(ACTIVE) – spin a short busy-loop so the analyser sees a recognisable shape.
  2. ra8_power_profile_mark_enter(SLEEP) -> ra8_lpm_enter_sleep (k_ra8_sleep_mode_sleep). SysTick wakes the CPU within a millisecond.
  3. Same for DEEP_SLEEP and SOFTWARE_STANDBY (the latter is armed against the SysTick wake source so the demo does not require an external pin event on a bare EVM).
  4. After every region transition the profiler stats are printed as "pp: a=NN s=NN d=NN st=NN us\r\n". When the whole cycle and the stats read both succeed it also emits the success-only verdict line "pp: profile OK\r\n" that the HIL scrape keys on (never printed on a "pp: FAIL ..." path).

LED1 toggles per cycle. LED2 latches on if any HAL call hard-fails.

Bare EK-RA8D2 only – no extra pins required. The profiler hooks into ra8_time_ms for the timestamp source so accumulation works on the host test build under RA8_OFF_TARGET as well.

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ pp_demo_byte_t

enum pp_demo_byte_t : uint8_t

Single-byte ASCII conversion constants.

Enumerator
k_pp_demo_ascii_zero 

Pp demo ascii zero.

k_pp_demo_dec_base 

Pp demo dec base.

k_pp_demo_uint_dec_max 

Max digits in a uint32 base-10.

k_pp_demo_print_buf 

Max bytes in one print line.

Definition at line 64 of file main.c.

◆ pp_demo_const_t

enum pp_demo_const_t : uint32_t

App-wide tunables.

Enumerator
k_pp_demo_baud 

Pp demo baud.

k_pp_demo_period_ms 

Pp demo period ms.

k_pp_demo_busy_iters 

Pp demo busy iters.

k_pp_demo_us_per_ms 

Pp demo us per ms.

Definition at line 56 of file main.c.

Function Documentation

◆ main()

void main ( void )

Application entry.

The application entry point Reset_Handler hands control to.

Profiles power modes once a second.

Precondition
Reset_Handler has copied .data and zeroed .bss.
SystemInit has set VTOR, FPU, and priority grouping.
Postcondition
On clean entry the CPU stays in the profile + blink loop.
On any HAL hard error LED2 latches ON.
Since
0.1.0

Definition at line 313 of file main.c.

References k_pp_demo_pass_msg, k_pp_demo_period_ms, k_pp_demo_print_buf, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, pp_demo_cycle_modes(), pp_demo_format_line(), pp_demo_panic_halt(), pp_demo_setup_or_halt(), ra8_board_led_on(), ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_isr_globals_enable(), and ra8_power_profile_get_stats().

◆ pp_demo_append()

uint32_t pp_demo_append ( uint8_t * buf,
uint32_t off,
const char * tag,
uint64_t val )
static

Append tag then the decimal of val to buf at off.

Parameters
[in,out]bufDestination buffer.
[in]offCurrent offset (updated in-place).
[in]tagNUL-terminated label.
[in]val64-bit decimal value to append.
Returns
New offset after the append.
Precondition
buf and tag are non-NULL.
Postcondition
buf[off..] contains tag + decimal digits.
Since
0.1.0

Definition at line 255 of file main.c.

References pp_demo_uint_to_dec().

Referenced by pp_demo_format_line().

◆ pp_demo_clocks_or_halt()

void pp_demo_clocks_or_halt ( void )
static

◆ pp_demo_cycle_modes()

bool pp_demo_cycle_modes ( void )
static

Cycle through ACTIVE -> SLEEP -> DEEP_SLEEP -> SOFTWARE_STANDBY, marking entry/exit on each.

Each region is "open" for at least one millisecond so the profiler accumulator records a measurable delta. SOFTWARE_STANDBY is the deepest mode safely entered from this demo because deep- standby resets the CPU and would not return into this loop.

Returns
true when every enter/exit and ra8_lpm_enter_sleep call returns k_ra8_ok.
Precondition
ra8_lpm_init and ra8_power_profile_init succeeded.
Postcondition
All four region accumulators have one new closed pair.
Since
0.1.0

Definition at line 179 of file main.c.

References k_pp_demo_busy_iters, k_ra8_ok, k_ra8_power_profile_region_active, k_ra8_power_profile_region_sleep, k_ra8_sleep_mode_sleep, ra8_lpm_enter_sleep(), ra8_power_profile_mark_enter(), and ra8_power_profile_mark_exit().

Referenced by main().

◆ pp_demo_format_line()

uint32_t pp_demo_format_line ( uint8_t * out,
const ra8_power_profile_stats_t * stats )
static

Format the per-cycle stats line into out.

Parameters
[out]outDestination buffer (>= k_pp_demo_print_buf bytes).
[in]statsStats snapshot.
Returns
Number of bytes written.
Precondition
out is non-NULL with >= k_pp_demo_print_buf capacity.
Postcondition
No bytes beyond the returned length are touched.
Since
0.1.0

Definition at line 278 of file main.c.

References k_ra8_power_profile_region_active, k_ra8_power_profile_region_deep_standby, k_ra8_power_profile_region_sleep, k_ra8_power_profile_region_software_standby, pp_demo_append(), ra8_power_profile_stats_t::regions, and ra8_power_profile_region_stats_t::total_time_us.

Referenced by main().

◆ pp_demo_modules_or_halt()

void pp_demo_modules_or_halt ( void )
static

◆ pp_demo_now_us()

uint64_t pp_demo_now_us ( void * ctx)
static

Time-base hook for the profiler – wraps ra8_time_ms to us.

Parameters
[in]ctxUnused.
Returns
Microseconds (millisecond resolution).
Precondition
ra8_time_init succeeded.
Postcondition
No global state is modified.
Since
0.1.0

Definition at line 99 of file main.c.

References k_pp_demo_us_per_ms, and ra8_time_ms().

Referenced by pp_demo_modules_or_halt().

◆ pp_demo_panic_halt()

void pp_demo_panic_halt ( void )
static

Park forever after a fatal init failure.

Precondition
Called only after a fatal error in boot.
Postcondition
CPU is parked; only a debugger or external reset wakes it.
Since
0.1.0

Definition at line 82 of file main.c.

Referenced by main(), pp_demo_clocks_or_halt(), and pp_demo_modules_or_halt().

◆ pp_demo_setup_or_halt()

void pp_demo_setup_or_halt ( void )
static

Definition at line 156 of file main.c.

References pp_demo_clocks_or_halt(), and pp_demo_modules_or_halt().

Referenced by main().

◆ pp_demo_uint_to_dec()

uint8_t pp_demo_uint_to_dec ( uint8_t * buf,
uint64_t v )
static

Write a decimal uint64 (low 32 bits) into buf.

Parameters
[out]bufDestination (must hold at least 10 chars).
[in]vValue to render.
Returns
Number of ASCII digits written.
Precondition
buf is non-NULL with >= 10 bytes capacity.
Postcondition
No null terminator is written.
Since
0.1.0

Definition at line 221 of file main.c.

References k_pp_demo_ascii_zero, k_pp_demo_dec_base, and k_pp_demo_uint_dec_max.

Referenced by pp_demo_append().

Variable Documentation

◆ k_pp_demo_pass_msg

const uint8_t k_pp_demo_pass_msg[] = "pp: profile OK\r\n"
static

Success verdict line emitted only when a full mode cycle and the stats read both returned k_ra8_ok (never on a "pp: FAIL" path); this is the success-only string the HIL scrape keys on.

Definition at line 74 of file main.c.

Referenced by main().