Reset handling
Informative
How to read why the MCU last reset, and how to issue a reset. Binding rules: CHI-MCU-MUST-03, CHI-MCU-MUST-09, CHI-MCU-MUST-10, and CHI-MCU-SHOULD-01 in Mcu — Requirements.
Read the reset reason
Mcu_Init captures the reset cause at startup; read it afterwards:
uint32 cause = Mcu_GetResetRawValue();
if ((cause & MCU_RESET_WATCHDOG) != 0u) {
/* recovered from a watchdog reset — take the appropriate action */
}
The return value is a bitwise-ORed uint32; the standard bits are MCU_RESET_POWER_ON,
MCU_RESET_SW, MCU_RESET_WATCHDOG, and MCU_RESET_EXT_PIN (a vendor may add more, and omit
any the hardware does not support). Notable edge cases:
Called before
Mcu_Init, it returns0.On hardware without reset-reason detection, it returns
MCU_RESET_POWER_ON.
Issue a reset
/* ensure no preemption first — e.g. disable interrupts */
Mcu_PerformReset(); /* does not return under normal operation */
Mcu_PerformReset issues a hardware reset of the microcontroller. The caller must guarantee no
preemption during the call (typically by disabling all interrupts beforehand), because the driver
sets up reset-related HW state, issues the reset, and waits for it to take effect.
Note
Mcu_PerformReset and Mcu_GetResetRawValue require the driver to be in
MCU_DRV_STATE_INIT; calling them earlier is a development error (except
Mcu_GetResetRawValue before Mcu_Init, which simply returns 0).