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

Independent Watchdog Timer driver implementation. More...

#include "ra8_iwdt.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_iwdt_regs.h"
#include "ra8_log.h"
Include dependency graph for ra8_iwdt.c:

Go to the source code of this file.

Data Structures

struct  ra8_iwdt_state_t
 Driver-wide runtime state. More...

Enumerations

enum  ra8_iwdt_mask_t : uint16_t { k_ra8_iwdt_status_all }
 Combined IWDTSR flag mask (UNDFF | REFEF). More...

Functions

ra8_err_t ra8_iwdt_init (void)
 Prepare the IWDT driver layer.
void ra8_iwdt_refresh_deferred (void)
 Refresh the IWDT counter.
ra8_err_t ra8_iwdt_get_status (uint16_t *out_mask)
 Read the IWDTSR status bits (UNDFF / REFEF only).
ra8_err_t ra8_iwdt_clear_status (void)
 Clear the underflow / refresh-error flags via IWDTSR write.
ra8_err_t ra8_iwdt_get_counter (uint16_t *out_counter)
 Read the live 14-bit IWDT down-counter (CNTVAL).
ra8_err_t ra8_iwdt_attach_handler (ra8_iwdt_event_fn_t fn, void *ctx)
 Attach a handler for the IWDT NMI event.
void ra8_iwdt_dispatch (void)
 Dispatch an IWDT NMI event – snapshot status + fire callback.

Variables

static const char * s_tag = "IWDT"
static ra8_iwdt_state_t s_iwdt_state

Detailed Description

Independent Watchdog Timer driver implementation.

Tag
[Ring 3 / HAL] {World: S}

The IWDT configuration (period, window, reset-vs-interrupt output) lives in the OFS0 option-setting register, which is programmed at flash time and locked once the boot ROM hands off. RA8D2 supports auto-start mode only (FSP IWDT_PRV_REGISTER_START_MODE is never set on this part), so this driver covers only the runtime surface: refresh, status read/clear, live counter readout, and NMI dispatch. Every register touch below carries a HUM Ch 28 citation.

Mapping to FSP r_iwdt API:

Definition in file ra8_iwdt.c.

Enumeration Type Documentation

◆ ra8_iwdt_mask_t

enum ra8_iwdt_mask_t : uint16_t

Combined IWDTSR flag mask (UNDFF | REFEF).

Enumerator
k_ra8_iwdt_status_all 

RA8 iwdt status all.

Definition at line 55 of file ra8_iwdt.c.

Function Documentation

◆ ra8_iwdt_attach_handler()

ra8_err_t ra8_iwdt_attach_handler ( ra8_iwdt_event_fn_t fn,
void * ctx )
nodiscard

Attach a handler for the IWDT NMI event.

Parameters
[in]fnCallback fired on dispatch.
[in]ctxContext forwarded to the callback.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 133 of file ra8_iwdt.c.

References k_ra8_ok, and s_iwdt_state.

◆ ra8_iwdt_clear_status()

ra8_err_t ra8_iwdt_clear_status ( void )
nodiscard

Clear the underflow / refresh-error flags via IWDTSR write.

Mirrors FSP R_IWDT_StatusClear – writes a 0 to the relevant bit and re-reads until the bit clears (the silicon takes one IWDTCLK cycle to drop the flag).

Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 110 of file ra8_iwdt.c.

References r_iwdt_regs_t::IWDTSR, k_ra8_iwdt_status_all, k_ra8_ok, and ra8_iwdt().

Referenced by main().

◆ ra8_iwdt_dispatch()

void ra8_iwdt_dispatch ( void )

Dispatch an IWDT NMI event – snapshot status + fire callback.

Since
0.1.0

See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.

Precondition
Driver state has been initialized by the matching *_init.
Caller has validated all pointer parameters.
Postcondition
Side effects are limited to those documented in the header.
No global state is modified on the error path.
Note
Thread safety: see the header declaration.

Definition at line 141 of file ra8_iwdt.c.

References r_iwdt_regs_t::IWDTSR, k_ra8_iwdt_status_all, ra8_iwdt(), and s_iwdt_state.

◆ ra8_iwdt_get_counter()

ra8_err_t ra8_iwdt_get_counter ( uint16_t * out_counter)
nodiscard

Read the live 14-bit IWDT down-counter (CNTVAL).

Mirrors FSP R_IWDT_CounterGet – reads IWDTSR & 0x3FFF.

Parameters
[out]out_counterReceives the 14-bit counter value (0..0x3FFF).
Returns
ra8_err_t error code.
Return values
k_ra8_ok*out_counter populated.
k_ra8_err_null_ptrout_counter == NULL.
Precondition
out_counter != NULL.
Postcondition
*out_counter <= 0x3FFF.
Note
Thread-safe (single 16-bit read).
Since
0.1.0

Definition at line 124 of file ra8_iwdt.c.

References k_ra8_iwdt_sr_cnt_mask, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_iwdt(), and s_tag.

Referenced by main().

◆ ra8_iwdt_get_status()

ra8_err_t ra8_iwdt_get_status ( uint16_t * out_mask)
nodiscard

Read the IWDTSR status bits (UNDFF / REFEF only).

Parameters
[out]out_maskReceives OR of k_ra8_iwdt_status_*.
Returns
ra8_err_t error code.
Since
0.1.0

Definition at line 100 of file ra8_iwdt.c.

References k_ra8_iwdt_status_all, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_iwdt(), and s_tag.

◆ ra8_iwdt_init()

ra8_err_t ra8_iwdt_init ( void )
nodiscard

Prepare the IWDT driver layer.

Initialise the IWDT driver layer.

No-op in v0.x: the IWDT is armed by OFS0 at reset, so there is nothing for the driver to programme. We just log that we are alive.

Returns
k_ra8_ok.

Definition at line 69 of file ra8_iwdt.c.

References k_ra8_ok, ra8_log_info, and s_tag.

Referenced by internal_wdt_demo_setup_or_halt(), and main().

◆ ra8_iwdt_refresh_deferred()

void ra8_iwdt_refresh_deferred ( void )

Refresh the IWDT counter.

Refresh the IWDT counter via a wrapper function.

Thin wrapper around the inline ra8_iwdt_refresh() helper in the register header. Provided as an extern so other compilation units do not have to pull in ra8_iwdt_regs.h. Mirrors FSP R_IWDT_Refresh (which writes 0x00 then 0xFF to IWDTRR).

Precondition
Driver state has been initialized by the matching *_init.
Caller has validated all pointer parameters.
Postcondition
Side effects are limited to those documented in the header.
No global state is modified on the error path.
Note
Thread safety: see the header declaration.
Since
0.1.0

Definition at line 94 of file ra8_iwdt.c.

References ra8_iwdt_refresh().

Referenced by main().

Variable Documentation

◆ s_iwdt_state

ra8_iwdt_state_t s_iwdt_state
static

Definition at line 49 of file ra8_iwdt.c.

Referenced by ra8_iwdt_attach_handler(), and ra8_iwdt_dispatch().

◆ s_tag

const char* s_tag = "IWDT"
static

Definition at line 38 of file ra8_iwdt.c.