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

IWDT window-mode refresh 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_iwdt.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  iwdt_demo_const_t : uint32_t {
  k_iwdt_demo_baud = 115200U ,
  k_iwdt_demo_poll_ms = 50U
}
 Demo tunables. More...
enum  iwdt_demo_window_t : uint16_t {
  k_iwdt_demo_window_low = 0x0400U ,
  k_iwdt_demo_window_high = 0x0C00U
}
 Window bounds in 14-bit IWDTSR.CNTVAL units (HUM 28.2.2). More...

Functions

static void internal_panic_halt (void)
 Park the core after an unrecoverable IWDT demo failure.
static void internal_setup_or_halt (void)
 Initialize clocks, SysTick, SCI8, and LED1.
static bool internal_in_window (uint16_t counter)
 Decide whether the live counter sits inside the legal window.
void main (void)
 Poll and refresh the IWDT only inside its legal window.

Variables

static const uint8_t s_iwdt_demo_msg_refresh [] = "iwdt: refresh in window\r\n"
static const uint8_t s_iwdt_demo_msg_boot [] = "iwdt: poll counter\r\n"

Detailed Description

IWDT window-mode refresh demo for EK-RA8D2.

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

Demonstrates the IWDT in window mode, distinct from the existing watchdog_demo which simply refreshes until it stops. The IWDT period and window-start / window-end positions are programmed in the OFS0 option-setting register at flash time – the chip cannot reconfigure them at runtime. This demo refreshes the counter only inside the legal window (between IWDTRPES and IWDTRPSS) via ra8_iwdt_refresh_deferred, observes the live counter via ra8_iwdt_get_counter, and reads the IWDTSR underflow / refresh- error status via ra8_iwdt_get_status to detect window violations.

Bring-up sequence:

  1. CGC + SysTick + UART (SCI8) + LED1.
  2. ra8_iwdt_init (no-op on RA8D2 – OFS0 owns the period).
  3. Loop: poll counter; refresh only when the counter is inside the legal window; clear status; toggle LED1 each refresh.
Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ iwdt_demo_const_t

enum iwdt_demo_const_t : uint32_t

Demo tunables.

Enumerator
k_iwdt_demo_baud 

Iwdt demo baud.

k_iwdt_demo_poll_ms 

Iwdt demo poll ms.

Definition at line 42 of file main.c.

◆ iwdt_demo_window_t

enum iwdt_demo_window_t : uint16_t

Window bounds in 14-bit IWDTSR.CNTVAL units (HUM 28.2.2).

Enumerator
k_iwdt_demo_window_low 

Refresh-permitted lower bound.

k_iwdt_demo_window_high 

Refresh-permitted upper bound.

Definition at line 48 of file main.c.

Function Documentation

◆ internal_in_window()

bool internal_in_window ( uint16_t counter)
static

Decide whether the live counter sits inside the legal window.

Applies the inclusive lower and upper OFS0-derived bounds used by the foreground loop before requesting a deferred refresh.

MC/DC:
Compound decision: counter >= low && counter <= high. Two atomic conditions x 3 vectors – both true (golden), low fail, high fail (test_app_iwdt_demo.c).
Parameters
[in]counterCurrent 14-bit IWDT counter sample.
Returns
Whether refreshing at this sample is permitted.
Return values
truecounter lies within both inclusive bounds.
falsecounter is below the lower or above the upper bound.
Precondition
counter was sampled from the active IWDT instance.
The compiled window constants match the programmed OFS0 policy.
Postcondition
No hardware or application state is modified.
The result depends only on counter and the fixed bounds.
Note
Pure and reentrant.
Since
0.1.0

Definition at line 132 of file main.c.

References k_iwdt_demo_window_high, k_iwdt_demo_window_low, and RA8_INTERNAL.

Referenced by main().

◆ internal_panic_halt()

void internal_panic_halt ( void )
static

Park the core after an unrecoverable IWDT demo failure.

Repeatedly executes WFI, retaining live IWDT and status-register state for an attached debugger until reset.

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 external intervention.
No further explicit IWDT refresh is issued.
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 LED1.

Brings the foreground loop's dependencies up in order and transfers to the panic helper if any clock, console, or LED operation fails.

Precondition
Reset startup initialized static storage and the vector table.
Called once before global interrupt enable.
Postcondition
On return, SCI8 and LED1 are ready and delays use the CPU clock.
IWDT option-register configuration remains unchanged.
Note
Not thread-safe; it mutates global board and clock state.
Since
0.1.0

Definition at line 89 of file main.c.

References internal_panic_halt(), k_iwdt_demo_baud, k_ra8_board_led1, 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, and ra8_time_init().

◆ main()

void main ( void )

Poll and refresh the IWDT only inside its legal window.

The application entry point Reset_Handler hands control to.

Emits the boot banner, initializes the option-controlled IWDT, samples its counter, and on legal samples queues a refresh, clears status, toggles LED1, and emits the refresh banner.

Precondition
Reset startup and SystemInit completed successfully.
OFS0 contains the window policy represented by the demo constants.
Postcondition
Each reported refresh was requested only within the inclusive window.
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 152 of file main.c.

References internal_in_window(), internal_panic_halt(), internal_setup_or_halt(), k_iwdt_demo_poll_ms, k_ra8_board_led1, k_ra8_ok, ra8_board_led_toggle(), ra8_board_uart_console_write(), ra8_delay_ms(), ra8_isr_globals_enable(), ra8_iwdt_clear_status(), ra8_iwdt_get_counter(), ra8_iwdt_init(), ra8_iwdt_refresh_deferred(), s_iwdt_demo_msg_boot, and s_iwdt_demo_msg_refresh.

Variable Documentation

◆ s_iwdt_demo_msg_boot

const uint8_t s_iwdt_demo_msg_boot[] = "iwdt: poll counter\r\n"
static

Definition at line 54 of file main.c.

Referenced by main().

◆ s_iwdt_demo_msg_refresh

const uint8_t s_iwdt_demo_msg_refresh[] = "iwdt: refresh in window\r\n"
static

Definition at line 53 of file main.c.

Referenced by main().