52 uint32_t after_assert_val,
56 return (hysteresis == hvd_val) && (negate == after_assert_val);
76 uint32_t reset_on_rise_val,
79 return (response == reset_val) || (response == reset_on_rise_val);
87static const char*
s_tag =
"LVD";
332 const uint8_t base = (uint8_t)((prev & (uint8_t)~clear_mask) | set_bits);
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#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_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
bool priv_ra8_lvd_internal_reject_hvd_after(uint32_t hvd_val, uint32_t after_assert_val, uint32_t hysteresis, uint32_t negate)
Pure RN+RHSEL reject predicate – see header for full contract.
static ra8_err_t internal_validate_cfg(const ra8_lvd_channel_map_t *map, const ra8_lvd_cfg_t *cfg)
Validate the cfg fields that the per-channel init reads.
const ra8_lvd_channel_map_t g_lvd_map[k_ra8_lvd_map_idx_count]
Lookup table from ra8_lvd_map_idx_t to register offsets.
ra8_err_t ra8_lvd_channel_deinit(ra8_lvd_channel_t channel)
Tear down one PVD channel per HUM Ch 12 Table 12.5 / 12.7.
ra8_err_t priv_ra8_lvd_internal_channel_to_idx(ra8_lvd_channel_t channel, uint8_t *out_idx)
Implementation of priv_ra8_lvd_internal_channel_to_idx() – switch on PVD id.
ra8_err_t ra8_lvd_set_irq_edge(ra8_lvd_channel_t channel, ra8_lvd_edge_t edge)
Update CR1.IDTSEL for an IRQ-capable PVDm channel.
ra8_err_t priv_ra8_lvd_internal_validate_div(ra8_lvd_loco_div_t div)
Implementation of priv_ra8_lvd_internal_validate_div() – upper-bound check.
uint8_t priv_ra8_lvd_internal_read_ri(const ra8_lvd_channel_map_t *map)
Implementation of priv_ra8_lvd_internal_read_ri() – masked CR0 read.
static ra8_err_t internal_validate_edge(ra8_lvd_edge_t edge)
Validate IDTSEL[1:0] candidate (0..2).
static uint8_t internal_m_cr0_with_reserved(uint8_t base)
Build a PVDmCR0 byte with bit3 forced to 1 (HUM-mandated).
ra8_err_t ra8_lvd_set_threshold(ra8_lvd_channel_t channel, ra8_lvd_pvdlvl_t threshold)
Update PVDLVL for an already-armed channel.
static uint8_t internal_n_cr0_with_reserved(uint8_t base)
Build a PVDnCR0 byte with the chip-mandated bit-6 = 1 / bit-7 = 0 reserved values.
bool priv_ra8_lvd_internal_set_ri_bit(uint32_t reset_val, uint32_t reset_on_rise_val, uint32_t response)
Pure RI-bit predicate – see header for full contract.
ra8_err_t ra8_lvd_set_irq_kind(ra8_lvd_channel_t channel, ra8_lvd_irq_type_t kind)
Update CR1.IRQSEL (maskable IRQ vs NMI) for a PVDm channel.
static uint8_t internal_cr0_apply_reserved(const ra8_lvd_channel_map_t *map, uint8_t base)
Apply the chip-specific reserved-bit pattern to a CR0 value.
static uint8_t internal_compose_cr0(const ra8_lvd_channel_map_t *map, const ra8_lvd_cfg_t *cfg)
Compute the initial CR0 value for ra8_lvd_channel_init.
static void internal_program_cr1(const ra8_lvd_channel_map_t *map, const ra8_lvd_cfg_t *cfg)
Program CR1 + status-clear for the m-only steps 9-11.
ra8_err_t ra8_lvd_channel_init(ra8_lvd_channel_t channel, const ra8_lvd_cfg_t *cfg)
Bring up one PVD channel per HUM Ch 12 Table 12.4 / 12.6.
static void internal_lvd_program_cmpcr(const ra8_lvd_channel_map_t *map, const ra8_lvd_cfg_t *cfg)
Run HUM Table 8.4 / 8.6 steps 1-4 (CMPCR programming).
static ra8_err_t internal_validate_threshold(ra8_lvd_pvdlvl_t threshold)
Reject PVDLVL encodings outside the HUM-allowed range.
static void internal_lvd_program_cr0_chain(const ra8_lvd_channel_map_t *map, const ra8_lvd_cfg_t *cfg)
Run HUM Table 8.4 / 8.6 steps 6-13 (CR0 / CR1 / status).
void priv_ra8_lvd_internal_cr0_rmw(const ra8_lvd_channel_map_t *map, uint8_t clear_mask, uint8_t set_bits)
Implementation of priv_ra8_lvd_internal_cr0_rmw() – RMW with reserved-bit refold.
Programmable Voltage Detection (PVD / LVD) HAL driver.
Test-access surface for ra8_lvd internal helpers (MC/DC).
@ k_ra8_lvd_map_idx_ch5
PVD5.
@ k_ra8_lvd_map_idx_ch4
PVD4.
@ k_ra8_lvd_map_idx_count
Sentinel.
@ k_ra8_lvd_map_idx_ch2
PVD2.
@ k_ra8_lvd_map_idx_ch1
PVD1.
Programmable Voltage Detection (PVD / LVD) register layout for the RA8D2.
@ k_ra8_lvd_cr0_mask_re
RE (n) – reset-only enable.
@ k_ra8_lvd_cr0_mask_rn
RN reset-negate timing (m).
@ k_ra8_lvd_cr0_mask_n_bit6
Reserved bit6 – write-1 (n).
@ k_ra8_lvd_cr0_mask_cmpe
CMPE comparator-output enable.
@ k_ra8_lvd_cr0_mask_ri
RI reset-on-cross select (m).
@ k_ra8_lvd_cr0_mask_rie
RIE (m) – IRQ/reset enable.
@ k_ra8_lvd_cr0_mask_bit3
Reserved bit3 – write-1 (m).
@ k_ra8_lvd_cr0_mask_dfdis
DFDIS digital-filter disable.
@ k_ra8_lvd_cr0_mask_fsamp
FSAMP[1:0] divider field.
@ k_ra8_lvd_cr1_mask_irqsel
IRQSEL maskable / NMI selector.
@ k_ra8_lvd_cr1_mask_idtsel
IDTSEL[1:0] edge-select field.
static volatile uint8_t * ra8_lvd_reg8(ra8_lvd_off_t off)
Get a volatile uint8_t* to a PVD 8-bit register.
@ k_ra8_lvd_pvd5_cmpcr_off
PVD5CMPCR.
@ k_ra8_lvd_pvd1_cr1_off
PVD1CR1.
@ k_ra8_lvd_pvd1_fcr_off
PVD1FCR.
@ k_ra8_lvd_pvd1_sr_off
PVD1SR.
@ k_ra8_lvd_pvd5_fcr_off
PVD5FCR.
@ k_ra8_lvd_pvd2_cr1_off
PVD2CR1.
@ k_ra8_lvd_pvd1_cr0_off
PVD1CR0.
@ k_ra8_lvd_pvd4_fcr_off
PVD4FCR.
@ k_ra8_lvd_pvd5_cr0_off
PVD5CR0.
@ k_ra8_lvd_pvd2_cmpcr_off
PVD2CMPCR.
@ k_ra8_lvd_pvd1_cmpcr_off
PVD1CMPCR.
@ k_ra8_lvd_pvd2_sr_off
PVD2SR.
@ k_ra8_lvd_pvd2_cr0_off
PVD2CR0.
@ k_ra8_lvd_pvd2_fcr_off
PVD2FCR.
@ k_ra8_lvd_pvd4_cmpcr_off
PVD4CMPCR.
@ k_ra8_lvd_pvd4_cr0_off
PVD4CR0.
@ k_ra8_lvd_cmpcr_mask_pvdlvl
PVDLVL[4:0] threshold field.
@ k_ra8_lvd_cmpcr_mask_pvde
PVDE detector enable.
@ k_ra8_lvd_fcr_mask_rhsel
RHSEL hysteresis-band selector.
@ k_ra8_lvd_cr0_shift_fsamp
FSAMP[1:0] starts at bit 4.
ra8_lvd_loco_div_t
PVDmCR0.FSAMP[1:0] / PVDnCR0.FSAMP[1:0] sampling-clock divider.
@ k_ra8_lvd_loco_div_max
Highest legal value (sentinel).
@ k_ra8_lvd_negate_after_assert
Negate after reset asserts.
@ k_ra8_lvd_hysteresis_hvd
RHSEL = 1 (rise detect).
ra8_lvd_irq_type_t
PVDmCR1.IRQSEL value – NMI vs maskable interrupt.
@ k_ra8_lvd_irq_maskable
Maskable interrupt via ICU.
ra8_lvd_pvdlvl_t
PVDLVL[4:0] threshold encoding for PVDmCMPCR / PVDnCMPCR.
@ k_ra8_lvd_pvdlvl_max
Highest legal threshold encoding.
@ k_ra8_lvd_pvdlvl_min
Lowest legal threshold encoding.
ra8_lvd_edge_t
PVDmCR1.IDTSEL[1:0] edge selector for monitor m channels.
@ k_ra8_lvd_edge_both
Detect either crossing.
ra8_lvd_channel_t
Voltage-monitor channel selector.
@ k_ra8_lvd_ch5
PVD5 (n series, reset-only).
@ k_ra8_lvd_ch2
PVD2 (m series, NMI-capable).
@ k_ra8_lvd_ch1
PVD1 (m series, NMI-capable).
@ k_ra8_lvd_ch4
PVD4 (n series, reset-only).
@ k_ra8_lvd_response_reset_on_rise
HVD reset (any).
@ k_ra8_lvd_response_interrupt
Maskable IRQ (m only).
@ k_ra8_lvd_response_reset
LVD reset (any).
@ k_ra8_lvd_response_nmi
NMI (m only).
@ k_ra8_lvd_response_none
Flags / ELC only.
Configuration descriptor for ra8_lvd_channel_init.
ra8_lvd_edge_t edge
IDTSEL setting (m channels only).
bool clear_status
true -> write 0 to PVDmSR.DET on init.
ra8_lvd_pvdlvl_t threshold
PVDLVL[4:0] encoding (see enum).
ra8_lvd_irq_type_t irq_type
IRQSEL setting (m channels only).
ra8_lvd_loco_div_t filter_div
FSAMP[1:0] sampling-clock divider.
ra8_lvd_negate_t negate
PVDmCR0.RN (m chan, ignored on n).
ra8_lvd_hysteresis_t hysteresis
PVDmFCR.RHSEL / PVDnFCR.RHSEL.
bool filter_en
true -> clear DFDIS (digital filter on).
ra8_lvd_response_t response
Interrupt / reset / NMI / none.
bool irq_enable
true -> set RIE on init (IRQ + reset).
Per-channel register-offset bundle.
ra8_lvd_off_t fcr
PVDxFCR (RHSEL).
ra8_lvd_off_t cmpcr
PVDxCMPCR offset.
ra8_lvd_off_t cr0
PVDxCR0 offset.
ra8_lvd_off_t cr1
PVDxCR1 (m only; n: same as cr0 stub).
ra8_lvd_off_t sr
PVDxSR (m only; n: same as cr0 stub).
bool has_irq
true for monitor m channels (1, 2).