58typedef enum : uint32_t {
94static const uint8_t
k_msg_boot[] =
"battery-monitor: boot\r\n";
95static const uint8_t
k_msg_fail[] =
"battery-monitor: FAIL init\r\n";
96static const uint8_t
k_msg_open[] =
"battery: FAIL open\r\n";
97static const uint8_t
k_msg_nak[] =
"battery: NAK (no fuel gauge)\r\n";
138static void bm_print(
const uint8_t* msg, uint32_t len)
147 __asm__
volatile(
"bkpt #0");
149 __asm__
volatile(
"wfi");
163 buf[n] = (uint8_t)(
'0' + (value % (uint32_t)
k_bm_dec_ten));
167 for (uint32_t i = 0U; i < n; i++) {
198 uint32_t cpuclk0_hz = 0U;
237 uint8_t crate_hi = 0U;
243 *out_chg = ((crate_hi & (uint8_t)
k_bm_sign_mask) == 0U) ? 1U : 0U;
248 uint32_t pclka_hz = 0U;
258 .pclka_hz = pclka_hz};
290 bm_print((chg != 0U) ? (
const uint8_t*)
"Y" : (
const uint8_t*)
"N", 1U);
void main(void)
Secure fallback main entry point.
static const uint8_t k_msg_pre[]
static const uint8_t k_msg_ok[]
static const uint8_t k_msg_boot[]
static const uint8_t k_msg_open[]
static const uint8_t k_msg_fail[]
static void bm_print_nag(ra8_batt_nag_t nag, uint8_t soc)
Emit the low/critical battery nag line for nag at soc.
static void bm_setup_or_halt(uint32_t *out_pclka_hz)
Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
volatile uint32_t g_bat_chg
1 when the fuel gauge reports a positive (charging) rate.
volatile uint32_t g_bat_nag
Last raised nag level (ra8_batt_nag_t), 0 when none this poll.
static void bm_read_or_halt(uint8_t *out_soc, uint8_t *out_chg)
Read SOC + the CRATE-sign from the fuel gauge; halt on a bus NAK.
volatile uint32_t g_bat_heartbeat
Bumps once per poll – liveness for headless probes.
static const uint8_t k_msg_nak[]
static const uint8_t k_msg_nag_crit[]
static ra8_io_i2c_bus_t s_bm_bus
Bound I2C bus handle the SMBus layer's injected seam points at.
bm_consts_t
Console / bus / fuel-gauge knobs (no magic numbers).
@ k_bm_reg_crate
CRATE register (signed charge rate).
@ k_bm_bus_hz
IIC_B bit rate.
@ k_bm_period_ms
Poll period.
@ k_bm_dec_ten
Decimal base.
@ k_bm_uart_baud
Console baud.
@ k_bm_fg_addr
MAX17048 7-bit I2C address.
@ k_bm_iic_chan
IIC_B channel (0).
@ k_bm_dec_digits
Max decimal digits for a 0..100 value.
@ k_bm_sign_mask
High-byte sign bit (1 = negative).
@ k_bm_soc_max
SOC clamp for display.
@ k_bm_reg_soc
SOC register (high byte = integer percent).
static const uint8_t k_msg_nag_tail[]
volatile uint32_t g_bat_soc
Last read state-of-charge percent (0..100).
static const ra8_port_pin_t k_bm_pin_sda
MikroBUS SDA routed through the Pmod1 I2C side (SDA1).
static ra8_err_t bm_pins_init(void)
Route the MikroBUS IIC SCL/SDA via PFS.
static const uint8_t k_msg_nag_low[]
static void bm_panic_halt(const uint8_t *msg, uint32_t len)
Print the fail banner and trap (ra8_emulator halts on the BKPT).
static const uint8_t k_msg_pct[]
static const ra8_port_pin_t k_bm_pin_scl
MikroBUS SCL routed through the Pmod1 I2C side (SCL1).
static void bm_print_uint(uint32_t value)
Print a small unsigned integer (0..100) in decimal.
static void bm_print(const uint8_t *msg, uint32_t len)
Emit a byte run on the SCI8 console.
Bounded, allocation-free low-battery nag policy.
ra8_err_t ra8_batt_update(ra8_batt_monitor_t *mon, uint8_t soc_pct, bool charging, ra8_batt_nag_t *out_nag)
Fold one SOC reading into the monitor and report the nag to raise.
ra8_batt_nag_t
The low-battery warning a single ra8_batt_update step raises.
@ k_ra8_batt_nag_none
No new warning this step.
@ k_ra8_batt_nag_critical
SOC fell to the critical band (<=10%).
@ k_ra8_batt_nag_low
SOC fell to the low band (<=20%).
ra8_err_t ra8_batt_monitor_init(ra8_batt_monitor_t *mon)
Reset a nag monitor to the un-nagged, fully-armed state.
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
@ k_ra8_board_mikrobus_iic_b_channel
RA8 board mikrobus iic b channel.
@ k_ra8_board_mikrobus_i2c_scl
J22.5 SCL (SW4-5 OFF) -> P512 SCL1.
@ k_ra8_board_mikrobus_i2c_sda
J22.6 SDA (SW4-5 OFF) -> P511 SDA1.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
@ k_ra8_clock_id_pclka
PCLKA.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_init_failed
Hardware peripheral failed to initialise.
@ 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.
@ k_ra8_psel_iic
00111b: IIC / I3C controller-peripheral.
Injected I2C-bus seam consumed by Ring-3 I2C device drivers.
I3C Bus Interface driver – unified native-I3C + I2C-compat modes.
@ k_ra8_i3c_mode_i2c
Legacy I2C-compatibility controller.
ra8_err_t ra8_i3c_init(uint8_t channel, const ra8_i3c_cfg_t *cfg)
Initialise an I3C channel in the configured mode.
ra8_io I2C-bus facade – one controller-transfer vtable over thechip's two I2C implementations.
ra8_err_t ra8_io_i2c_bus_as_ops(const ra8_io_i2c_bus_t *bus, ra8_i2c_bus_ops_t *out)
Expose a bound bus through the Ring-3 seam ra8_i2c_bus_ops_t.
I3C I2C-compatibility backend binder for the ra8_io I2C-bus facade.
ra8_err_t ra8_io_i2c_bus_bind_i3c_compat(ra8_io_i2c_bus_t *bus, uint8_t channel)
Bind bus to I3C channel channel in I2C-compatibility mode.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
High-level GPIO helpers on top of the PORT + PFS register layer.
ra8_err_t ra8_pfs_route_peripheral(ra8_port_pin_t pin, ra8_psel_t psel, const char *owner)
Route a pin to a non-IRQ peripheral function via PFS.PSEL.
SMBus 3.2 protocol layer over an injected I2C bus seam.
ra8_err_t ra8_smbus_init(const ra8_smbus_cfg_t *cfg)
Initialise the SMBus layer over the injected bus seam.
ra8_err_t ra8_smbus_read_byte_data(uint8_t target_7b, uint8_t cmd, uint8_t *out_data)
Read Byte Data: register-indexed byte read (SMBus 3.2 sec 6.5.5).
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Caller-owned nag state carried across ra8_batt_update calls.
Caller-filled I2C controller-transfer seam (write / read / write-then-read).
Per-channel bring-up configuration for ra8_i3c_init.
Caller-allocated I2C-bus handle binding a backend to its context.
Configuration descriptor for ra8_smbus_init.