126typedef enum : uint16_t {
177 const uint8_t live = *reg;
178 const uint8_t next = enable ? (uint8_t)(live | mask) : (uint8_t)(live & (uint8_t)~mask);
213 __asm__
volatile(
"nop");
292 uint32_t timeout_iters)
297 if (timeout_iters == 0U) {
303 bool vbporm_ok =
false;
304 for (uint32_t i = 0U; i < timeout_iters; ++i) {
344 if (timeout_iters == 0U) {
350 bool vbporm_ok =
false;
351 for (uint32_t i = 0U; i < timeout_iters; ++i) {
369 if (timeout_iters == 0U) {
382 bool vbporm_low =
false;
383 for (uint32_t i = 0U; i < timeout_iters; ++i) {
459 if (adf_bits != 0U) {
542 if (slot !=
nullptr) {
600 const uint8_t fired = (uint8_t)(flags & enables);
618 fn(ctx, tamper_flags);
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
ra8_err_t ra8_bkup_clear_status(uint8_t mask)
Clear latched VBPORF and tamper flags selected by mask.
ra8_err_t ra8_bkup_write_word(uint8_t word_index, uint32_t value)
Write one 32-bit word into the VBTBKRn array.
const char * g_bkup_tag
Log tag used for this driver's diagnostics.
ra8_err_t ra8_bkup_read_byte(uint16_t index, uint8_t *out)
Read one 8-bit byte from the VBTBKRn array.
ra8_err_t ra8_bkup_init(const ra8_bkup_config_t *cfg)
Configure the battery-backup block from cfg.
static ra8_bkup_event_fn_t s_bkup_fn
Currently attached low-battery / tamper callback or nullptr.
ra8_err_t ra8_bkup_warm_start_check(bool *needs_reinit, uint32_t timeout_iters)
Warm-start sanity check (HUM Ch 12.3.7.2 p 517).
static void * s_bkup_ctx
Opaque pointer forwarded to the s_bkup_fn callback.
ra8_err_t ra8_bkup_attach_handler(ra8_bkup_event_fn_t fn, void *ctx)
Attach the shared low-battery / tamper event callback.
bool s_bkup_initialized
true once any of the lifecycle init helpers have run.
ra8_err_t ra8_bkup_get_voltage_monitor_enabled(bool *enabled_out)
Read the live VBATTMNSELR.VBTMNSEL bit.
ra8_err_t ra8_bkup_get_status(ra8_bkup_status_t *out)
Read VBTBPSR + VBTADSR and decode into out.
ra8_err_t ra8_bkup_set_voltage_monitor(bool enable)
Enable / disable the VBATT/6 analog tap to ADC16H.
ra8_err_t ra8_bkup_cold_start_init(ra8_bkup_vdet_level_t level, uint32_t timeout_iters)
Drive the cold-start flow from HUM Ch 12.3.7.1 p 517.
ra8_err_t ra8_bkup_deinit(void)
Disable the battery-backup switch and close the VBTBKRn window.
ra8_err_t ra8_bkup_read_word(uint8_t word_index, uint32_t *out)
Read one 32-bit word from the VBTBKRn array.
ra8_err_t ra8_bkup_write_byte(uint16_t index, uint8_t value)
Write one 8-bit byte into the VBTBKRn array.
ra8_bkup_internal_t
Local numeric constants – avoid magic numbers per CLAUDE.md.
@ k_ra8_bkup_no_switch_lvl_raw
110b sentinel for VDETLVL "initial value" (HUM 12.3.7.3).
@ k_ra8_bkup_vbae_settle_iters
NOP-spin count: >= 500 ns at 1 GHz M85 (HUM Ch 12.2.6 p 504).
@ k_ra8_bkup_status_clear_keep_mask
W0C base for VBPORF.
@ k_ra8_bkup_max_vdet_level
Highest legal VDETLVL encoding.
ra8_err_t ra8_bkup_zero_all(void)
Bulk-zeroise the entire 128-byte backup-register array.
void priv_ra8_bkup_internal_rmw8(volatile uint8_t *reg, uint8_t mask, bool enable, uint16_t unlock_val)
Set or clear a bit in an 8-bit PRCR-protected RMW register.
void ra8_bkup_dispatch(uint8_t tamper_flags)
Fire the registered callback (called from the ISR shim).
static ra8_err_t internal_validate_cfg(const ra8_bkup_config_t *cfg)
Validate a ra8_bkup_config_t against HUM constraints.
ra8_err_t ra8_bkup_no_switch_init(uint32_t timeout_iters)
"Power-supply switch unused" init flow (HUM Ch 12.3.7.3 p 518).
static void internal_vbae_access_settle(void)
Busy-wait the HUM-mandated VBTBKRn access settle after arming VBAE.
ra8_err_t ra8_bkup_isr_handle(void)
ISR entry point that fires the registered callback.
Battery Backup Function (VBATT) HAL driver – public API.
void(* ra8_bkup_event_fn_t)(void *ctx, uint8_t tamper_flags)
Low-battery / tamper event callback signature.
@ k_ra8_bkup_source_vbatt
BPWSWM=0: VCC < VDETBATT, on VBATT.
@ k_ra8_bkup_source_vcc
BPWSWM=1: VCC > VDETBATT, on VCC.
ra8_bkup_vdet_level_t
VDETBATT trip level (HUM Ch 12.2.12 p 508, VBTBPCR2.VDETLVL).
@ k_ra8_bkup_vdet_1p75v
101b: 1.75 V.
Cross-TU shared surface for the ra8_bkup driver split.
Battery Backup Function (VBATT / BAT*) register layout for the RA8D2.
static volatile uint8_t * ra8_bkup_vbtbpcr2(void)
Pointer to 8-bit VBTBPCR2 (HUM Ch 12.2.12 p 508).
@ k_ra8_bkup_word_count
128 bytes / 4 = 32 uint32_t words.
@ k_ra8_bkup_reg_count
128 byte-wide VBTBKRn slots.
@ k_ra8_bkup_vbtbpcr1_mask_bpwswstp
BPWSWSTP @ bit 0.
static volatile uint8_t * ra8_bkup_vbtber(void)
Pointer to 8-bit VBTBER (HUM Ch 12.2.6 p 504).
static volatile uint8_t * ra8_bkup_vbtictlr2(void)
Pointer to 8-bit VBTICTLR2 (HUM Ch 12.2.9 p 506).
@ k_ra8_bkup_vbattmnselr_mask_vbtmnsel
VBTMNSEL @ bit 0.
static volatile uint8_t * ra8_bkup_vbattmnselr(void)
Pointer to 8-bit VBATTMNSELR (HUM Ch 12.2.5 p 503).
static volatile uint8_t * ra8_bkup_vbtbpsr(void)
Pointer to 8-bit VBTBPSR (HUM Ch 12.2.13 p 509).
@ k_ra8_bkup_vbtbpcr2_mask_vdete
VDETE @ bit 4.
@ k_ra8_bkup_vbtbpcr2_mask_lvl
VDETLVL[2:0].
static volatile uint8_t * ra8_bkup_vbtadcr2(void)
Pointer to 8-bit VBTADCR2 (HUM Ch 12.2.16 p 511).
static volatile uint8_t * ra8_bkup_vbtbkr(uint16_t index)
Pointer to one VBTBKRn byte (HUM Ch 12.2.7 p 505).
@ k_ra8_bkup_vbtber_mask_vbae
VBAE @ bit 3.
static volatile uint8_t * ra8_bkup_vbtadsr(void)
Pointer to 8-bit VBTADSR (HUM Ch 12.2.14 p 509).
static volatile uint8_t * ra8_bkup_vbtictlr(void)
Pointer to 8-bit VBTICTLR (HUM Ch 12.2.8 p 505).
static volatile uint8_t * ra8_bkup_vbtbpcr1(void)
Pointer to 8-bit VBTBPCR1 (HUM Ch 12.2.11 p 507).
static volatile uint8_t * ra8_bkup_vbtadcr1(void)
Pointer to 8-bit VBTADCR1 (HUM Ch 12.2.15 p 510).
@ k_ra8_bkup_vbtbpsr_mask_swm
Switch monitor.
@ k_ra8_bkup_vbtbpsr_mask_vbporm
VBATT_R OK.
@ k_ra8_bkup_vbtbpsr_mask_vbporf
VBATT_POR flag.
@ k_ra8_bkup_vbtadsr_mask_all
Combined VBTADF[2:0].
@ k_ra8_bkup_vbtadcr1_mask_ie_all
All IE bits.
static volatile uint32_t * ra8_bkup_vbtbkr_word(uint8_t word_index)
Pointer to one VBTBKR 32-bit word slot (4 bytes).
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_invalid_arg
Invalid function argument.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ 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(tag, message)
RA8 log info.
Scoped PRCR unlock helper.
#define RA8_PROTECTED_WRITE(unlock_val)
Scoped PRCR unlock block.
@ k_ra8_prcr_unlock_pvd
RA8 prcr unlock pvd.
@ k_ra8_prcr_unlock_lpm
RA8 prcr unlock lpm.
Configuration descriptor passed to ra8_bkup_init.
ra8_bkup_vdet_level_t vdet_level
VDETBATT trip threshold (VBTBPCR2.VDETLVL).
bool enable_backup
true -> set VBTBER.VBAE so VBTBKRn is accessible.
bool enable_switch
true -> clear BPWSWSTP, allow VCC->VBATT switching.
Decoded snapshot of VBTBPSR.
uint8_t tamper_flags
Raw VBTADSR.VBTADF[2:0] mask.
bool por_detected
VBPORF: VBATT_POR reset latched (W0C).
uint8_t raw_vbtbpsr
Unmodified VBTBPSR (debug aid).
ra8_bkup_source_t source
Active power source right now.
bool vbatt_r_ok
VBPORM: VBATT_R > VPORBATT (post-OK).