79static const char*
s_tag =
"WDT";
104typedef enum : uint8_t {
144 if (out_word ==
nullptr) {
150 const volatile uint32_t* src = (
const volatile uint32_t*)ofs_addr;
165typedef enum : uint16_t {
409 const uint16_t write_val = (uint16_t)(reg->
WDTSR & (uint16_t)~mask);
410 reg->
WDTSR = write_val;
412#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
414 const bool cleared = ra8_fake_mmio_poll(®->
WDTSR, poll, ((uint16_t)reg->
WDTSR & mask) == 0U);
417 const bool cleared = ((uint16_t)reg->
WDTSR & mask) == 0U;
494 uint32_t* out_pclkb_cycles)
498 uint16_t cycles = 0U;
499 uint16_t divisor = 0U;
510 *out_pclkb_cycles = (uint32_t)cycles * (uint32_t)divisor;
539 if (out_slot !=
nullptr) {
582 reg->
WDTSR = (uint16_t)(reg->
WDTSR & (uint16_t)~mask);
684 const uint32_t field = (sel >> shift) & mask;
685 return (field == 0U) || (field == mask);
757 if (out_word !=
nullptr) {
760 uint32_t nonsec = 0U;
772 *out_word = (nonsec & mux) | (sec & ~mux);
809 const uint8_t rstirqs =
811 const uint8_t stpctl =
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Bounded wait-flag primitives for RA8D2 HAL drivers.
Interrupt Control Unit driver (IRQ pins, NMI).
ra8_err_t ra8_icu_nmi_enable(uint32_t mask)
Enable one or more NMI sources by OR'ing into NMIER.
ra8_err_t ra8_icu_nmi_clear(uint32_t mask)
Clear pending NMI status flags via NMICLR (HUM 14.2.15 p 544).
ra8_err_t ra8_icu_nmi_disable(uint32_t mask)
Disable NMI sources by clearing bits in NMIER.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
#define ra8_log_error(tag, message)
RA8 log error.
Option Function Select (OFS) boot-map inventory for the active RA8 device.
@ k_ra8_ofs0_addr
OFS0 – IWDT + WDT0 fields (Secure).
@ k_ra8_ofs3_sec_addr
OFS3_SEC – WDT1 fields (Secure).
@ k_ra8_ofs3_addr
OFS3 – WDT1 fields (Non-secure alias).
@ k_ra8_ofs3_sel_addr
OFS3_SEL – per-field S/NS selector.
ra8_err_t ra8_wdt_install_nmi(void)
Enable the WDT bit in NMIER so the NMI line fires on underflow.
ra8_err_t ra8_wdt_uninstall_nmi(void)
Disable the WDT bit in NMIER (counterpart to ra8_wdt_install_nmi).
void ra8_wdt_refresh_deferred(void)
Refresh the software WDT counter (WDT0).
ra8_wdt_status_combined_t
Union of the two WDTSR top-flag bits the driver cares about.
@ k_ra8_wdt_status_all
RA8 wdt status all.
static ra8_err_t internal_default_ofs_reader(uintptr_t ofs_addr, uint32_t *out_word)
Default OFSm reader: dereferences the address as a 32-bit word.
ra8_wdt_legacy_slot_t
Slot reserved for the legacy single-callback API.
@ k_ra8_wdt_legacy_slot
RA8 wdt legacy slot.
static uint16_t internal_pack_wdtcr(const ra8_wdt_cfg_t *cfg)
Pack a ra8_wdt_cfg_t into a 16-bit WDTCR word.
static bool internal_clock_div_is_valid(ra8_wdt_clock_div_t div)
Reject CKS encodings the silicon marks as "Setting prohibited".
ra8_err_t ra8_wdt_ofs_reader_set(ra8_wdt_ofs_reader_fn_t reader)
Override the OFSm reader hook used by ra8_wdt_ofs_get.
static void internal_subs_clear_all(void)
Clear every subscriber slot.
ra8_err_t ra8_wdt_refresh_for(ra8_wdt_instance_t which)
Refresh a specific WDT instance.
ra8_err_t ra8_wdt_exit_stop(void)
Disable counter halt on Sleep entry.
ra8_err_t ra8_wdt_timeout_cycles_get(ra8_wdt_timeout_sel_t sel, uint16_t *out_cycles)
Decode a ra8_wdt_timeout_sel_t into its cycle count.
static ra8_err_t internal_read_wdt1_word(uint32_t *out_word)
Resolve WDT1's effective option word from the OFS3 family.
static bool internal_timeout_sel_is_valid(ra8_wdt_timeout_sel_t sel)
Reject TOPS encodings outside the documented 2-bit range.
uint8_t ra8_wdt_subscriber_count(void)
Number of currently-installed subscribers.
ra8_err_t ra8_wdt_init(const ra8_wdt_cfg_t *cfg)
Initialise the WDT in register-start mode.
static ra8_wdt_ofs_reader_fn_t s_ofs_reader
Active OFSm reader hook (dependency-inverted for test isolation).
ra8_err_t ra8_wdt_unsubscribe(uint8_t slot)
Remove a previously-registered subscriber.
ra8_err_t ra8_wdt_subscribe(ra8_wdt_event_fn_t fn, void *ctx, uint8_t *out_slot)
Add a hot-pluggable subscriber to the WDT NMI dispatch list.
ra8_err_t ra8_wdt_get_status(uint16_t *out_mask)
Read the WDTSR status flag bits.
ra8_err_t ra8_wdt_ofs_get(ra8_wdt_instance_t which, ra8_wdt_ofs_decoded_t *out)
Decode an OFSm option-setting word into ra8_wdt_cfg_t.
static void internal_decode_ofs_word(uint32_t ofsm, ra8_wdt_ofs_decoded_t *out)
Decode the seven WDT fields out of a resolved OFSm word.
ra8_err_t ra8_wdt_clear_status(void)
Clear the WDTSR underflow / refresh-error flags.
static ra8_wdt_sub_t s_wdt_subs[k_ra8_wdt_max_subs]
Dispatch table of registered subscribers.
ra8_err_t ra8_wdt_deinit(void)
Quiesce the driver into a Sleep-stop posture.
ra8_err_t ra8_wdt_pclkb_divisor(ra8_wdt_clock_div_t div, uint16_t *out_divisor)
Decode a ra8_wdt_clock_div_t into its numeric divisor.
ra8_err_t ra8_wdt_total_pclkb_cycles(ra8_wdt_timeout_sel_t sel, ra8_wdt_clock_div_t div, uint32_t *out_pclkb_cycles)
Compute the effective timeout in PCLKB cycles.
ra8_err_t ra8_wdt_get_counter(uint16_t *out_count)
Read the live CNTVAL[13:0] down-counter value.
static bool internal_sel_field_uniform(uint32_t sel, uint32_t shift, uint32_t mask)
Report whether one multi-bit OFS3_SEL field holds a legal encoding.
ra8_err_t ra8_wdt_enter_stop(void)
Enable counter halt on Sleep entry.
ra8_err_t ra8_wdt_attach_handler(ra8_wdt_event_fn_t fn, void *ctx)
Register a callback invoked from the WDT NMI / underflow ISR.
void ra8_wdt_dispatch(void)
Dispatch a WDT event – snapshot WDTSR + fan-out to subscribers.
ra8_err_t ra8_wdt_clear_status_blocking(uint16_t mask)
Clear specific WDTSR flag bits and busy-wait until they read 0.
static bool internal_ofs3_sel_is_legal(uint32_t sel)
Report whether an OFS3_SEL word is legal in every multi-bit field.
Software Watchdog Timer (WDT) driver header.
ra8_wdt_timeout_sel_t
Legal TOPS[1:0] encodings for WDTCR.
@ k_ra8_wdt_timeout_16384
16384 cycles.
@ k_ra8_wdt_timeout_1024
1024 cycles.
@ k_ra8_wdt_timeout_8192
8192 cycles.
@ k_ra8_wdt_timeout_4096
4096 cycles.
ra8_wdt_clock_div_t
Legal CKS[3:0] encodings for WDTCR.
@ k_ra8_wdt_clkdiv_512
PCLKB / 512.
@ k_ra8_wdt_clkdiv_8192
PCLKB / 8192.
@ k_ra8_wdt_clkdiv_4
PCLKB / 4.
@ k_ra8_wdt_clkdiv_2048
PCLKB / 2048.
@ k_ra8_wdt_clkdiv_64
PCLKB / 64.
@ k_ra8_wdt_clkdiv_128
PCLKB / 128.
ra8_err_t(* ra8_wdt_ofs_reader_fn_t)(uintptr_t ofs_addr, uint32_t *out_word)
Hook used to fetch one OFSm option-setting word.
ra8_wdt_ofs_strt_t
OFSm.WDTnSTRT encoding – auto vs register start mode.
@ k_ra8_wdt_ofs_strt_auto
Auto-start (OFSm-driven).
ra8_wdt_window_start_t
Legal RPSS[1:0] encodings (refresh-permitted window start).
@ k_ra8_wdt_clear_max_polls
16384 reads – safely > 8193.
ra8_wdt_reset_ctrl_t
WDTRCR.RSTIRQS encoding – reset vs NMI on expiry.
@ k_ra8_wdt_on_expiry_reset
RSTIRQS=1 – internal reset.
@ k_ra8_wdt_status_underflow
UNDFF (bit 14).
@ k_ra8_wdt_status_none
No flag set.
@ k_ra8_wdt_status_refresh
REFEF (bit 15).
@ k_ra8_wdt_max_subs
Max simultaneous subscribers.
ra8_wdt_stop_ctrl_t
WDTCSTPR.SLCSTP encoding – counter behaviour in Sleep.
@ k_ra8_wdt_sleep_stop_count
SLCSTP=1 – counter halts in Sleep.
void(* ra8_wdt_event_fn_t)(void *ctx, uint16_t status_mask)
WDT NMI / underflow event callback.
ra8_wdt_window_end_t
Legal RPES[1:0] encodings (refresh-permitted window end).
Watchdog Timer (WDT) register layout for the RA8D2.
static void ra8_wdt_refresh(void)
Refresh the WDT0 instance using the two-byte unlock sequence.
static void ra8_wdt_refresh_instance(ra8_wdt_instance_t which)
Refresh a specific WDT instance.
@ k_ra8_wdt_cycles_1024
TOPS = 0b00.
@ k_ra8_wdt_cycles_8192
TOPS = 0b10.
@ k_ra8_wdt_cycles_16384
TOPS = 0b11.
@ k_ra8_wdt_cycles_4096
TOPS = 0b01.
@ k_ra8_wdt_sr_cnt_mask
CNTVAL[13:0] mask.
@ k_ra8_wdt_ofs_mask_rpss
2-bit field.
@ k_ra8_wdt_ofs_shift_rstirqs
OFSm.WDTRSTIRQS shift.
@ k_ra8_wdt_ofs_shift_tops
OFSm.WDTTOPS shift.
@ k_ra8_wdt_ofs_shift_rpss
OFSm.WDTRPSS shift.
@ k_ra8_wdt_ofs_mask_stpctl
1-bit field.
@ k_ra8_wdt_ofs_mask_tops
2-bit field.
@ k_ra8_wdt_ofs_shift_rpes
OFSm.WDTRPES shift.
@ k_ra8_wdt_ofs_shift_strt
OFSm.WDTSTRT shift.
@ k_ra8_wdt_ofs_shift_stpctl
OFSm.WDTSTPCTL shift.
@ k_ra8_wdt_ofs_mask_strt
1-bit field.
@ k_ra8_wdt_ofs_mask_rpes
2-bit field.
@ k_ra8_wdt_ofs_shift_cks
OFSm.WDTCKS shift.
@ k_ra8_wdt_ofs_mask_cks
4-bit field.
@ k_ra8_wdt_ofs_mask_rstirqs
1-bit field.
@ k_ra8_wdt_ofs_field_mask
Union of all seven fields.
@ k_ra8_wdt_nmier_wdten_mask
NMIER.WDTEN = bit 1.
ra8_wdt_instance_t
Hardware instance selector used by per-instance helpers.
@ k_ra8_wdt0
WDT0 – Cortex-M85 side.
@ k_ra8_wdt_instance_count
Number of WDT instances on RA8D2.
static volatile r_wdt_regs_t * ra8_wdt(void)
Get pointer to WDT0 (the default / M85-side instance).
@ k_ra8_wdt_rcr_rstirqs
RSTIRQS = bit 7 (1 = reset, 0 = NMI / IRQ).
@ k_ra8_wdt_div_value_128
RA8 wdt div value 128.
@ k_ra8_wdt_div_value_2048
RA8 wdt div value 2048.
@ k_ra8_wdt_div_value_8192
RA8 wdt div value 8192.
@ k_ra8_wdt_div_value_4
RA8 wdt div value 4.
@ k_ra8_wdt_div_value_64
RA8 wdt div value 64.
@ k_ra8_wdt_div_value_512
RA8 wdt div value 512.
@ k_ra8_wdt_mask_rpss
RPSS field width (2 bits).
@ k_ra8_wdt_shift_cks
CKS occupies bits 7:4.
@ k_ra8_wdt_mask_tops
TOPS field width (2 bits).
@ k_ra8_wdt_shift_rpss
RPSS occupies bits 13:12.
@ k_ra8_wdt_shift_rpes
RPES occupies bits 9:8.
@ k_ra8_wdt_mask_rpes
RPES field width (2 bits).
@ k_ra8_wdt_shift_tops
TOPS occupies bits 1:0.
@ k_ra8_wdt_mask_cks
CKS field width (4 bits).
@ k_ra8_wdt_cstpr_slcstp
SLCSTP = bit 7 (1 = halt counter in Sleep).
Memory-mapped layout of one WDT instance.
volatile uint16_t WDTCR
+0x02 Control register.
volatile uint8_t WDTCSTPR
+0x08 Count-stop control.
volatile uint16_t WDTSR
+0x04 Status register.
volatile uint8_t WDTRCR
+0x06 Reset control register.
Register-start-mode configuration block.
ra8_wdt_window_start_t window_start
WDTCR.RPSS[1:0] selection.
ra8_wdt_timeout_sel_t timeout
WDTCR.TOPS[1:0] selection.
ra8_wdt_stop_ctrl_t stop_in_sleep
WDTCSTPR.SLCSTP halt-on-Sleep.
ra8_wdt_clock_div_t clock_div
WDTCR.CKS[3:0] selection.
ra8_wdt_reset_ctrl_t on_expiry
WDTRCR.RSTIRQS reset vs IRQ.
ra8_wdt_window_end_t window_end
WDTCR.RPES[1:0] selection.
Decoded view of an OFSm option-setting word.
ra8_wdt_ofs_strt_t start_mode
OFSm.WDTnSTRT (auto vs register start).
ra8_wdt_cfg_t cfg
Decoded period / divider / window / etc.
bool auto_start
Convenience flag = (start_mode == auto).
One entry in the multi-subscriber dispatch table.
ra8_wdt_event_fn_t fn
Subscriber callback or nullptr if slot is free.
void * ctx
Opaque pointer forwarded to fn.