ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_bkup.c
Go to the documentation of this file.
1
64
65#include "ra8_bkup.h"
66
67#include <stdint.h>
68
69#include "ra8_attributes.h"
70#include "ra8_bkup_internal.h"
71#include "ra8_bkup_regs.h"
72#include "ra8_check.h"
73#include "ra8_err.h"
74#include "ra8_log.h"
76
88const char* g_bkup_tag = "BKUP";
89
98
103static void* s_bkup_ctx;
104
121
136
137/* =============================================================================
138 * Internal helpers
139 * =============================================================================
140 */
141
165{
166 if ((uint16_t)cfg->vdet_level > k_ra8_bkup_max_vdet_level) {
168 }
169 return k_ra8_ok;
170}
171
172void priv_ra8_bkup_internal_rmw8(volatile uint8_t* reg,
173 uint8_t mask,
174 bool enable,
175 uint16_t unlock_val)
176{
177 const uint8_t live = *reg;
178 const uint8_t next = enable ? (uint8_t)(live | mask) : (uint8_t)(live & (uint8_t)~mask);
179 RA8_PROTECTED_WRITE(unlock_val)
180 {
181 *reg = next;
182 }
183}
184
211{
212 for (volatile uint32_t i = 0U; i < (uint32_t)k_ra8_bkup_vbae_settle_iters; ++i) {
213 __asm__ volatile("nop");
214 }
215}
216
217/* =============================================================================
218 * Lifecycle
219 * =============================================================================
220 */
221
223{
224 RA8_CHECK_NULL_PTR(cfg, g_bkup_tag, "cfg must not be nullptr");
225 const ra8_err_t v_err = internal_validate_cfg(cfg);
226 RA8_RETURN_ON_ERROR(v_err, g_bkup_tag, "bkup_init: cfg out of range");
227
228 /* All of VBTBPCR1 / VBTBPCR2 / VBTBER / VBTBPSR / VBTADSR sit behind PRC1
229 * (HUM Ch 13.1 Table 13.1 p 521); one window covers the whole bring-up. */
231 {
232 if (cfg->enable_switch) {
233 /* HUM Ch 12.2.11 "VBTBPCR1 : VBATT Battery Power Supply Control Register 1", p 507 */
234 *ra8_bkup_vbtbpcr1() = 0U;
235
236 /* HUM Ch 12.2.12 "VBTBPCR2 : VBATT Battery Power Supply Control Register 2", p 508 */
237 /* Program VDETLVL with VDETE = 0 first per the HUM stabilisation note. */
238 *ra8_bkup_vbtbpcr2() = (uint8_t)((uint8_t)cfg->vdet_level & k_ra8_bkup_vbtbpcr2_mask_lvl);
239
240 /* HUM Ch 12.2.12 "VBTBPCR2 : VBATT Battery Power Supply Control Register 2", p 508 */
241 /* Now set VDETE so VCC drop detection arms. */
242 *ra8_bkup_vbtbpcr2() = (uint8_t)(((uint8_t)cfg->vdet_level & k_ra8_bkup_vbtbpcr2_mask_lvl) |
244 } else {
245 /* HUM Ch 12.2.11 "VBTBPCR1 : VBATT Battery Power Supply Control Register 1", p 507 */
247 }
248
249 /* HUM Ch 12.2.6 "VBTBER : VBATT Backup Enable Register", p 504 */
250 if (cfg->enable_backup) {
251 /* HUM p 504: "You must write 1 to VBAE before accessing VBTBKR." */
253 /* HUM p 504: "wait for at least 500 ns after writing 1 to VBAE, and
254 * then access VBTBKR" -- arm the VBTBKRn window before it is used. */
256 } else {
257 *ra8_bkup_vbtber() = 0U;
258 }
259
260 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
262 (uint8_t)k_ra8_bkup_status_clear_keep_mask; /* W0C: clear VBPORF, leave others. */
263
264 /* HUM Ch 12.2.14 "VBTADSR : VBATT Tamper Detection Status Register", p 509 */
265 *ra8_bkup_vbtadsr() = 0U;
266 }
267
268 s_bkup_initialized = true;
269 ra8_log_info(g_bkup_tag, "bkup_init");
270 return k_ra8_ok;
271}
272
273[[nodiscard]] ra8_err_t ra8_bkup_deinit(void)
274{
275 /* VBTBER + VBTBPCR1 are PRC1-protected (HUM Ch 13.1 Table 13.1 p 521). */
277 {
278 /* HUM Ch 12.2.6 "VBTBER : VBATT Backup Enable Register", p 504 */
279 /* HUM warns: VBAE must be 0 before VBATT cutover or VBTBKRn is lost. */
280 *ra8_bkup_vbtber() = 0U;
281
282 /* HUM Ch 12.2.11 "VBTBPCR1 : VBATT Battery Power Supply Control Register 1", p 507 */
284 }
285
286 s_bkup_initialized = false;
287 ra8_log_info(g_bkup_tag, "bkup_deinit");
288 return k_ra8_ok;
289}
290
292 uint32_t timeout_iters)
293{
294 if ((uint16_t)level > k_ra8_bkup_max_vdet_level) {
296 }
297 if (timeout_iters == 0U) {
299 }
300
301 /* Cold-start step 1 (12.3.7.1 p 517): wait for VBPORM == 1. */
302 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
303 bool vbporm_ok = false;
304 for (uint32_t i = 0U; i < timeout_iters; ++i) {
306 vbporm_ok = true;
307 break;
308 }
309 }
310 if (!vbporm_ok) {
312 }
313
314 /* Steps 2-5 all target PRC1 registers (HUM Ch 13.1 Table 13.1 p 521). */
316 {
317 /* Cold-start step 2 (12.3.7.1 p 517): clear VBPORF. */
318 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
320
321 /* Cold-start step 3 (12.3.7.1 p 517): programme VDETLVL with VDETE still 0. */
322 /* HUM Ch 12.2.12 "VBTBPCR2 : VBATT Battery Power Supply Control Register 2", p 508 */
323 *ra8_bkup_vbtbpcr2() = (uint8_t)((uint8_t)level & k_ra8_bkup_vbtbpcr2_mask_lvl);
324
325 /* Cold-start step 4 (12.3.7.1 p 517): external tDETWT wait -- caller's job. */
326
327 /* Cold-start step 5 (12.3.7.1 p 517): arm VDETE. */
328 /* HUM Ch 12.2.12 "VBTBPCR2 : VBATT Battery Power Supply Control Register 2", p 508 */
330 (uint8_t)(((uint8_t)level & k_ra8_bkup_vbtbpcr2_mask_lvl) | k_ra8_bkup_vbtbpcr2_mask_vdete);
331
332 /* HUM Ch 12.2.11 "VBTBPCR1 : VBATT Battery Power Supply Control Register 1", p 507 */
333 *ra8_bkup_vbtbpcr1() = 0U; /* Switch enabled. */
334 }
335
336 s_bkup_initialized = true;
337 ra8_log_info(g_bkup_tag, "bkup_cold_start_init");
338 return k_ra8_ok;
339}
340
341[[nodiscard]] ra8_err_t ra8_bkup_warm_start_check(bool* needs_reinit, uint32_t timeout_iters)
342{
343 RA8_CHECK_NULL_PTR(needs_reinit, g_bkup_tag, "needs_reinit must not be nullptr");
344 if (timeout_iters == 0U) {
346 }
347
348 /* Warm-start step 1 (12.3.7.2 p 517): wait for VBPORM == 1. */
349 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
350 bool vbporm_ok = false;
351 for (uint32_t i = 0U; i < timeout_iters; ++i) {
353 vbporm_ok = true;
354 break;
355 }
356 }
357 if (!vbporm_ok) {
359 }
360
361 /* Warm-start step 2 (12.3.7.2 p 517): read VBPORF. */
362 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
363 *needs_reinit = ((*ra8_bkup_vbtbpsr() & k_ra8_bkup_vbtbpsr_mask_vbporf) != 0U);
364 return k_ra8_ok;
365}
366
367[[nodiscard]] ra8_err_t ra8_bkup_no_switch_init(uint32_t timeout_iters)
368{
369 if (timeout_iters == 0U) {
371 }
372
373 /* No-switch step 1 (12.3.7.3 p 518): stop the switch. */
375 {
376 /* HUM Ch 12.2.11 "VBTBPCR1 : VBATT Battery Power Supply Control Register 1", p 507 */
378 }
379
380 /* No-switch step 2 (12.3.7.3 p 518): wait for VBPORM == 0 (rail tied to VCC). */
381 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
382 bool vbporm_low = false;
383 for (uint32_t i = 0U; i < timeout_iters; ++i) {
385 vbporm_low = true;
386 break;
387 }
388 }
389 if (!vbporm_low) {
391 }
392
393 /* Steps 3-8 all target PRC1 registers (HUM Ch 13.1 Table 13.1 p 521). */
395 {
396 /* No-switch steps 3-4 (12.3.7.3 p 518): VDETE = 0, VDETLVL = 110b. */
397 /* HUM Ch 12.2.12 "VBTBPCR2 : VBATT Battery Power Supply Control Register 2", p 508 */
399
400 /* No-switch step 5 (12.3.7.3 p 518): W0C VBPORF. */
401 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
403
404 /* No-switch steps 7-8 (12.3.7.3 p 518): zero pad / tamper / backup-clear paths. */
405 /* HUM Ch 12.2.8 "VBTICTLR : VBATT Input Control Register", p 505 */
406 *ra8_bkup_vbtictlr() = 0U;
407 /* HUM Ch 12.2.9 "VBTICTLR2 : VBATT Input Control Register 2", p 506 */
408 *ra8_bkup_vbtictlr2() = 0U;
409 /* HUM Ch 12.2.14 "VBTADSR : VBATT Tamper Detection Status Register", p 509 */
410 *ra8_bkup_vbtadsr() = 0U;
411 /* HUM Ch 12.2.15 "VBTADCR1 : VBATT Tamper Detection Control Register 1", p 510 */
412 *ra8_bkup_vbtadcr1() = 0U;
413 /* HUM Ch 12.2.16 "VBTADCR2 : VBATT Tamper Detection Control Register 2", p 511 */
414 *ra8_bkup_vbtadcr2() = 0U;
415 }
416
417 s_bkup_initialized = true;
418 ra8_log_info(g_bkup_tag, "bkup_no_switch_init");
419 return k_ra8_ok;
420}
421
422/* =============================================================================
423 * Status
424 * =============================================================================
425 */
426
428{
429 RA8_CHECK_NULL_PTR(out, g_bkup_tag, "out must not be nullptr");
430
431 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
432 const uint8_t bpsr = *ra8_bkup_vbtbpsr();
433 /* HUM Ch 12.2.14 "VBTADSR : VBATT Tamper Detection Status Register", p 509 */
434 const uint8_t adsr = *ra8_bkup_vbtadsr();
435
436 out->raw_vbtbpsr = bpsr;
437 if ((bpsr & k_ra8_bkup_vbtbpsr_mask_swm) != 0U) {
439 } else {
441 }
442 out->vbatt_r_ok = ((bpsr & k_ra8_bkup_vbtbpsr_mask_vbporm) != 0U);
443 out->por_detected = ((bpsr & k_ra8_bkup_vbtbpsr_mask_vbporf) != 0U);
444 out->tamper_flags = (uint8_t)(adsr & k_ra8_bkup_vbtadsr_mask_all);
445 return k_ra8_ok;
446}
447
448[[nodiscard]] ra8_err_t ra8_bkup_clear_status(uint8_t mask)
449{
450 if ((mask & k_ra8_bkup_vbtbpsr_mask_vbporf) != 0U) {
451 /* HUM Ch 12.2.13 "VBTBPSR : VBATT Battery Power Supply Status Register", p 509 */
452 /* W0C: write 0 to bits we want cleared, 1 to bits to leave alone. */
455 false,
456 (uint16_t)k_ra8_prcr_unlock_lpm);
457 }
458 const uint8_t adf_bits = (uint8_t)(mask & k_ra8_bkup_vbtadsr_mask_all);
459 if (adf_bits != 0U) {
460 /* HUM Ch 12.2.14 "VBTADSR : VBATT Tamper Detection Status Register", p 509 */
462 adf_bits,
463 false,
464 (uint16_t)k_ra8_prcr_unlock_lpm);
465 }
466 return k_ra8_ok;
467}
468
469/* =============================================================================
470 * VBTBKRn access
471 * =============================================================================
472 */
473
474[[nodiscard]] ra8_err_t ra8_bkup_read_word(uint8_t word_index, uint32_t* out)
475{
476 RA8_CHECK_NULL_PTR(out, g_bkup_tag, "out must not be nullptr");
477 if ((uint16_t)word_index >= k_ra8_bkup_word_count) {
479 }
480 /* HUM Ch 12.2.7 "VBTBKRn : VBATT Backup Register", p 505 */
481 volatile uint32_t* slot = ra8_bkup_vbtbkr_word(word_index);
482 RA8_CHECK_NULL_PTR(slot, g_bkup_tag, "vbtbkr word slot mapping failed");
483 *out = *slot;
484 return k_ra8_ok;
485}
486
487[[nodiscard]] ra8_err_t ra8_bkup_write_word(uint8_t word_index, uint32_t value)
488{
489 if ((uint16_t)word_index >= k_ra8_bkup_word_count) {
491 }
492 /* HUM Ch 12.2.7 "VBTBKRn : VBATT Backup Register", p 505 */
493 volatile uint32_t* slot = ra8_bkup_vbtbkr_word(word_index);
494 RA8_CHECK_NULL_PTR(slot, g_bkup_tag, "vbtbkr word slot mapping failed");
495 /* VBTBKRn is PRC1-protected: unprotected stores are silently dropped
496 * (HUM Ch 13.1 Table 13.1 p 521). */
498 {
499 *slot = value;
500 }
501 return k_ra8_ok;
502}
503
504[[nodiscard]] ra8_err_t ra8_bkup_read_byte(uint16_t index, uint8_t* out)
505{
506 RA8_CHECK_NULL_PTR(out, g_bkup_tag, "out must not be nullptr");
507 if (index >= k_ra8_bkup_reg_count) {
509 }
510 /* HUM Ch 12.2.7 "VBTBKRn : VBATT Backup Register", p 505 */
511 volatile uint8_t* slot = ra8_bkup_vbtbkr(index);
512 RA8_CHECK_NULL_PTR(slot, g_bkup_tag, "vbtbkr byte slot mapping failed");
513 *out = *slot;
514 return k_ra8_ok;
515}
516
517[[nodiscard]] ra8_err_t ra8_bkup_write_byte(uint16_t index, uint8_t value)
518{
519 if (index >= k_ra8_bkup_reg_count) {
521 }
522 /* HUM Ch 12.2.7 "VBTBKRn : VBATT Backup Register", p 505 */
523 volatile uint8_t* slot = ra8_bkup_vbtbkr(index);
524 RA8_CHECK_NULL_PTR(slot, g_bkup_tag, "vbtbkr byte slot mapping failed");
525 /* VBTBKRn is PRC1-protected (HUM Ch 13.1 Table 13.1 p 521). */
527 {
528 *slot = value;
529 }
530 return k_ra8_ok;
531}
532
533[[nodiscard]] ra8_err_t ra8_bkup_zero_all(void)
534{
535 /* One PRC1 window spans the whole sweep (HUM Ch 13.1 Table 13.1 p 521)
536 * rather than 128 unlock/relock pairs. */
538 {
539 for (uint16_t i = 0U; i < k_ra8_bkup_reg_count; ++i) {
540 /* HUM Ch 12.2.7 "VBTBKRn : VBATT Backup Register", p 505 */
541 volatile uint8_t* slot = ra8_bkup_vbtbkr(i);
542 if (slot != nullptr) {
543 *slot = 0U;
544 }
545 }
546 }
547 return k_ra8_ok;
548}
549
550/* =============================================================================
551 * VBATT analog voltage monitor
552 * =============================================================================
553 */
554
555[[nodiscard]] ra8_err_t ra8_bkup_set_voltage_monitor(bool enable)
556{
557 /* HUM Ch 12.2.5 "VBATTMNSELR : Battery Backup Voltage Monitor Function Select Register", p 503 */
558 /* VBATTMNSELR is grouped with the PVD registers under PRC3, NOT PRC1
559 * (HUM Ch 13.1 Table 13.1 p 521). */
562 enable,
563 (uint16_t)k_ra8_prcr_unlock_pvd);
564 return k_ra8_ok;
565}
566
567[[nodiscard]] ra8_err_t ra8_bkup_get_voltage_monitor_enabled(bool* enabled_out)
568{
569 RA8_CHECK_NULL_PTR(enabled_out, g_bkup_tag, "enabled_out must not be nullptr");
570 /* HUM Ch 12.2.5 "VBATTMNSELR : Battery Backup Voltage Monitor Function Select Register", p 503 */
572 return k_ra8_ok;
573}
574
575/* =============================================================================
576 * IRQ path
577 * =============================================================================
578 */
579
581{
582 s_bkup_fn = fn;
583 s_bkup_ctx = ctx;
584 return k_ra8_ok;
585}
586
588{
589 if (!s_bkup_initialized) {
591 }
592
593 /* HUM Ch 12.4 "Interrupt Sources" Table 12.2 p 518: VBATTADI fires when
594 * any (VBTADFn AND VBTADIEn) is true. Read both, AND them, and
595 * dispatch the masked subset. */
596 /* HUM Ch 12.2.14 "VBTADSR : VBATT Tamper Detection Status Register", p 509 */
597 const uint8_t flags = (uint8_t)(*ra8_bkup_vbtadsr() & k_ra8_bkup_vbtadsr_mask_all);
598 /* HUM Ch 12.2.15 "VBTADCR1 : VBATT Tamper Detection Control Register 1", p 510 */
599 const uint8_t enables = (uint8_t)(*ra8_bkup_vbtadcr1() & k_ra8_bkup_vbtadcr1_mask_ie_all);
600 const uint8_t fired = (uint8_t)(flags & enables);
601
602 if (fired != 0U) {
603 /* HUM Ch 12.2.14 "VBTADSR : VBATT Tamper Detection Status Register", p 509 */
604 /* W0C: write 0 to the bits we are dispatching, leave others alone.
605 * VBTADSR is PRC1-protected (HUM Ch 13.1 Table 13.1 p 521); without the
606 * unlock the flag would never clear and the ISR would re-fire forever. */
608 ra8_bkup_dispatch(fired);
609 }
610 return k_ra8_ok;
611}
612
613void ra8_bkup_dispatch(uint8_t tamper_flags)
614{
616 void* const ctx = s_bkup_ctx;
617 if (fn != nullptr) {
618 fn(ctx, tamper_flags);
619 }
620}
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.
Definition ra8_bkup.c:448
ra8_err_t ra8_bkup_write_word(uint8_t word_index, uint32_t value)
Write one 32-bit word into the VBTBKRn array.
Definition ra8_bkup.c:487
const char * g_bkup_tag
Log tag used for this driver's diagnostics.
Definition ra8_bkup.c:88
ra8_err_t ra8_bkup_read_byte(uint16_t index, uint8_t *out)
Read one 8-bit byte from the VBTBKRn array.
Definition ra8_bkup.c:504
ra8_err_t ra8_bkup_init(const ra8_bkup_config_t *cfg)
Configure the battery-backup block from cfg.
Definition ra8_bkup.c:222
static ra8_bkup_event_fn_t s_bkup_fn
Currently attached low-battery / tamper callback or nullptr.
Definition ra8_bkup.c:97
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).
Definition ra8_bkup.c:341
static void * s_bkup_ctx
Opaque pointer forwarded to the s_bkup_fn callback.
Definition ra8_bkup.c:103
ra8_err_t ra8_bkup_attach_handler(ra8_bkup_event_fn_t fn, void *ctx)
Attach the shared low-battery / tamper event callback.
Definition ra8_bkup.c:580
bool s_bkup_initialized
true once any of the lifecycle init helpers have run.
Definition ra8_bkup.c:120
ra8_err_t ra8_bkup_get_voltage_monitor_enabled(bool *enabled_out)
Read the live VBATTMNSELR.VBTMNSEL bit.
Definition ra8_bkup.c:567
ra8_err_t ra8_bkup_get_status(ra8_bkup_status_t *out)
Read VBTBPSR + VBTADSR and decode into out.
Definition ra8_bkup.c:427
ra8_err_t ra8_bkup_set_voltage_monitor(bool enable)
Enable / disable the VBATT/6 analog tap to ADC16H.
Definition ra8_bkup.c:555
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.
Definition ra8_bkup.c:291
ra8_err_t ra8_bkup_deinit(void)
Disable the battery-backup switch and close the VBTBKRn window.
Definition ra8_bkup.c:273
ra8_err_t ra8_bkup_read_word(uint8_t word_index, uint32_t *out)
Read one 32-bit word from the VBTBKRn array.
Definition ra8_bkup.c:474
ra8_err_t ra8_bkup_write_byte(uint16_t index, uint8_t value)
Write one 8-bit byte into the VBTBKRn array.
Definition ra8_bkup.c:517
ra8_bkup_internal_t
Local numeric constants – avoid magic numbers per CLAUDE.md.
Definition ra8_bkup.c:126
@ k_ra8_bkup_no_switch_lvl_raw
110b sentinel for VDETLVL "initial value" (HUM 12.3.7.3).
Definition ra8_bkup.c:129
@ k_ra8_bkup_vbae_settle_iters
NOP-spin count: >= 500 ns at 1 GHz M85 (HUM Ch 12.2.6 p 504).
Definition ra8_bkup.c:133
@ k_ra8_bkup_status_clear_keep_mask
W0C base for VBPORF.
Definition ra8_bkup.c:131
@ k_ra8_bkup_max_vdet_level
Highest legal VDETLVL encoding.
Definition ra8_bkup.c:127
ra8_err_t ra8_bkup_zero_all(void)
Bulk-zeroise the entire 128-byte backup-register array.
Definition ra8_bkup.c:533
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.
Definition ra8_bkup.c:172
void ra8_bkup_dispatch(uint8_t tamper_flags)
Fire the registered callback (called from the ISR shim).
Definition ra8_bkup.c:613
static ra8_err_t internal_validate_cfg(const ra8_bkup_config_t *cfg)
Validate a ra8_bkup_config_t against HUM constraints.
Definition ra8_bkup.c:164
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).
Definition ra8_bkup.c:367
static void internal_vbae_access_settle(void)
Busy-wait the HUM-mandated VBTBKRn access settle after arming VBAE.
Definition ra8_bkup.c:210
ra8_err_t ra8_bkup_isr_handle(void)
ISR entry point that fires the registered callback.
Definition ra8_bkup.c:587
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.
Definition ra8_bkup.h:235
@ k_ra8_bkup_source_vbatt
BPWSWM=0: VCC < VDETBATT, on VBATT.
Definition ra8_bkup.h:79
@ k_ra8_bkup_source_vcc
BPWSWM=1: VCC > VDETBATT, on VCC.
Definition ra8_bkup.h:80
ra8_bkup_vdet_level_t
VDETBATT trip level (HUM Ch 12.2.12 p 508, VBTBPCR2.VDETLVL).
Definition ra8_bkup.h:65
@ k_ra8_bkup_vdet_1p75v
101b: 1.75 V.
Definition ra8_bkup.h:71
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.
Definition ra8_check.h:184
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
Definition ra8_err.h:304
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
Definition ra8_log.h:364
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.
Definition ra8_bkup.h:147
ra8_bkup_vdet_level_t vdet_level
VDETBATT trip threshold (VBTBPCR2.VDETLVL).
Definition ra8_bkup.h:148
bool enable_backup
true -> set VBTBER.VBAE so VBTBKRn is accessible.
Definition ra8_bkup.h:150
bool enable_switch
true -> clear BPWSWSTP, allow VCC->VBATT switching.
Definition ra8_bkup.h:149
Decoded snapshot of VBTBPSR.
Definition ra8_bkup.h:162
uint8_t tamper_flags
Raw VBTADSR.VBTADF[2:0] mask.
Definition ra8_bkup.h:166
bool por_detected
VBPORF: VBATT_POR reset latched (W0C).
Definition ra8_bkup.h:165
uint8_t raw_vbtbpsr
Unmodified VBTBPSR (debug aid).
Definition ra8_bkup.h:167
ra8_bkup_source_t source
Active power source right now.
Definition ra8_bkup.h:163
bool vbatt_r_ok
VBPORM: VBATT_R > VPORBATT (post-OK).
Definition ra8_bkup.h:164