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

ULPT 1 Hz wake-from-software-standby demo for 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_err.h"
#include "ra8_isr.h"
#include "ra8_time.h"
#include "ra8_ulpt.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  ulpt_demo_const_t : uint32_t {
  k_ulpt_demo_baud = 115200U ,
  k_ulpt_demo_poll_ms = 50U ,
  k_ulpt_demo_period_ticks = 0x8000U
}
 Demo tunables. More...
enum  ulpt_demo_chan_t : uint8_t {
  k_ulpt_demo_channel = 0U ,
  k_ulpt_demo_undf_bit = 0x20U
}
 ULPT channel + status. More...

Functions

static void internal_panic_halt (void)
 Park the core after an unrecoverable ULPT demo failure.
static void internal_setup_or_halt (void)
 Initialize clocks, SysTick, SCI8, and the ULPT block.
static ra8_err_t internal_arm (void)
 Arm ULPT0 with the demo period.
void main (void)
 Report and re-arm each observed ULPT0 underflow.

Variables

static const uint8_t s_ulpt_demo_log_msg [] = "ulpt: wake ok\r\n"

Detailed Description

ULPT 1 Hz wake-from-software-standby demo for EK-RA8D2.

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

Brings up the on-chip Ultra-Low-Power Timer (ULPT0) in 1 Hz mode and uses its underflow event as a wake source through software-standby cycles. Each underflow:

  1. Increments a wake counter.
  2. Logs "ulpt: wake ok\r\n" over the J-Link OB CDC console.
  3. Stops the timer to clear ULPTCR.TUNDF.
  4. Re-arms the timer with the same period.

The demo deliberately keeps the wake-source path inside the ULPT driver and polls ULPTCR via ra8_ulpt_get_status: this matches the host unit-test path (no NVIC needed) and exercises the same register sequence on the EK-RA8D2 silicon.

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ ulpt_demo_chan_t

enum ulpt_demo_chan_t : uint8_t

ULPT channel + status.

Enumerator
k_ulpt_demo_channel 

Ulpt demo channel.

k_ulpt_demo_undf_bit 

ULPTCR.TUNDF – mirrors AGTCR layout.

Definition at line 49 of file main.c.

◆ ulpt_demo_const_t

enum ulpt_demo_const_t : uint32_t

Demo tunables.

Enumerator
k_ulpt_demo_baud 

Ulpt demo baud.

k_ulpt_demo_poll_ms 

Ulpt demo poll ms.

k_ulpt_demo_period_ticks 

Ulpt demo period ticks.

Definition at line 40 of file main.c.

Function Documentation

◆ internal_arm()

ra8_err_t internal_arm ( void )
staticnodiscard

Arm ULPT0 with the demo period.

Delegates the fixed channel and approximately one-second reload to the ULPT HAL without changing any other timer channel.

MC/DC:
Compound decision: ra8_ulpt_start != ok. One atomic condition x 2 vectors – ok (golden) and bad-channel reject (covered in test_app_ulpt_demo.c).
Returns
ULPT start status from the HAL.
Return values
k_ra8_okULPT0 accepted the channel and reload configuration.
(other)The HAL rejected or could not start the timer.
Precondition
internal_setup_or_halt initialized the ULPT driver.
ULPT0 is stopped or ready to be re-armed after an underflow.
Postcondition
On success, ULPT0 counts toward the fixed reload underflow.
On failure, the caller receives the HAL error unchanged.
Note
Not thread-safe with concurrent ULPT0 control.
Since
0.1.0

Definition at line 131 of file main.c.

References k_ulpt_demo_channel, k_ulpt_demo_period_ticks, RA8_INTERNAL, and ra8_ulpt_start().

◆ internal_panic_halt()

void internal_panic_halt ( void )
static

Park the core after an unrecoverable ULPT demo failure.

Repeatedly executes WFI so an attached debugger can inspect the timer and clock state without additional foreground traffic.

Precondition
Called only from the boot or terminal foreground path.
The caller does not require this function to return.
Postcondition
The core remains in the WFI loop until reset or debug intervention.
No further timer or console operation is requested.
Note
Not thread-safe; this is the terminal single-threaded path.
Since
0.1.0

Definition at line 69 of file main.c.

References RA8_INTERNAL.

◆ internal_setup_or_halt()

void internal_setup_or_halt ( void )
static

Initialize clocks, SysTick, SCI8, and the ULPT block.

Brings all foreground-loop dependencies up in order and transfers control to the terminal panic helper on the first HAL error.

Precondition
Reset startup initialized static storage and the vector table.
Called once before global interrupt enable.
Postcondition
On return, the delay service, console, and ULPT driver are ready.
ULPT0 remains stopped until internal_arm runs.
Note
Not thread-safe; it mutates global peripheral configuration.
Since
0.1.0

Definition at line 89 of file main.c.

References internal_panic_halt(), k_ra8_clock_id_cpuclk0, k_ra8_ok, k_ulpt_demo_baud, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), RA8_INTERNAL, ra8_time_init(), and ra8_ulpt_init().

◆ main()

void main ( void )

Report and re-arm each observed ULPT0 underflow.

The application entry point Reset_Handler hands control to.

Initializes and arms ULPT0, then polls its underflow bit. Each event emits the fixed wake banner, stops the channel to clear status, and starts the next interval with the same reload.

Precondition
Reset startup and SystemInit completed successfully.
The EK-RA8D2 console wiring matches the board definition.
Postcondition
Every reported wake corresponds to an observed underflow status bit.
Any HAL or output error leads to the terminal panic helper.
Note
Does not return during normal operation.
Since
0.1.0

Definition at line 150 of file main.c.

References internal_arm(), internal_panic_halt(), internal_setup_or_halt(), k_ra8_ok, k_ulpt_demo_channel, k_ulpt_demo_poll_ms, k_ulpt_demo_undf_bit, ra8_board_uart_console_write(), ra8_delay_ms(), ra8_isr_globals_enable(), ra8_ulpt_get_status(), ra8_ulpt_stop(), and s_ulpt_demo_log_msg.

Variable Documentation

◆ s_ulpt_demo_log_msg

const uint8_t s_ulpt_demo_log_msg[] = "ulpt: wake ok\r\n"
static

Definition at line 54 of file main.c.

Referenced by main().