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

Independent Watchdog driver header. More...

#include <stdint.h>
#include "ra8_err.h"
Include dependency graph for ra8_iwdt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* ra8_iwdt_event_fn_t) (void *ctx, uint16_t status_mask)
 IWDT NMI underflow event callback.

Enumerations

enum  ra8_iwdt_status_mask_t : uint16_t {
  k_ra8_iwdt_status_none = 0x0000U ,
  k_ra8_iwdt_status_underflow = 0x4000U ,
  k_ra8_iwdt_status_refresh = 0x8000U
}
 IWDTSR status bits exposed to callers. More...

Functions

ra8_err_t ra8_iwdt_init (void)
 Initialise the IWDT driver layer.
void ra8_iwdt_refresh_deferred (void)
 Refresh the IWDT counter via a wrapper function.
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.

Detailed Description

Independent Watchdog driver header.

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

Extends the refresh stub with: status reporting, live counter read, and NMI underflow attach / dispatch. Period + window + reset-vs-NMI choice still come from the OFS0 option-setting register at flash- write time; the IWDT cannot be reconfigured at runtime on the RA8D2 (auto-start only – the FSP IWDT_PRV_REGISTER_START_MODE path is not supported on this part).

The driver mirrors the runtime surface of the FSP r_iwdt driver:

Definition in file ra8_iwdt.h.

Typedef Documentation

◆ ra8_iwdt_event_fn_t

typedef void(* ra8_iwdt_event_fn_t) (void *ctx, uint16_t status_mask)

IWDT NMI underflow event callback.

Parameters
[in]ctxCaller context.
[in]status_maskLatched IWDTSR bits (UNDFF / REFEF).

Definition at line 59 of file ra8_iwdt.h.

Enumeration Type Documentation

◆ ra8_iwdt_status_mask_t

enum ra8_iwdt_status_mask_t : uint16_t

IWDTSR status bits exposed to callers.

Mirrors HUM Ch 28.2.2 "IWDTSR" bit layout (UNDFF bit 14, REFEF bit 15) and FSP IWDT_PRV_STATUS_START_BIT semantics. The CNTVAL counter occupies the lower 14 bits and is exposed through ra8_iwdt_get_counter instead.

Enumerator
k_ra8_iwdt_status_none 

RA8 iwdt status none.

k_ra8_iwdt_status_underflow 

IWDTSR.UNDFF bit 14.

k_ra8_iwdt_status_refresh 

IWDTSR.REFEF bit 15.

Definition at line 47 of file ra8_iwdt.h.

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

Initialise the IWDT driver layer.

Returns
k_ra8_ok – stub; OFS0 controls the actual period.
Since
0.1.0

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 via a wrapper function.

Equivalent to FSP R_IWDT_Refresh: writes the mandatory 0x00 then 0xFF sequence to IWDTRR. A single write does NOT refresh – both bytes are required.

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

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().