Concepts

Informative

The model behind the MCU driver: its driver state machine, the non-blocking clock-setup lifecycle, the reset-reason model, and the periodic poll. Non-binding; the normative rules live in Mcu — Requirements.

State machine

The McuDrv has a single driver-wide state — there are no channels and no de-init.

        stateDiagram-v2
   [*] --> MCU_DRV_STATE_UNINIT : Reset
   MCU_DRV_STATE_UNINIT --> MCU_DRV_STATE_INIT : Mcu_Init()
    

Driver state

Meaning

API calls accepted

MCU_DRV_STATE_UNINIT

Not initialized (state after reset/startup)

Only Mcu_Init() (plus Mcu_GetResetRawValue, which returns 0)

MCU_DRV_STATE_INIT

Initialized; all service APIs are accepted

All

Clock-setup lifecycle

Setting up the clock tree is a non-blocking sequence — a PLL or oscillator may need time to stabilise, and the driver never busy-waits for it:

        flowchart LR
   A["Mcu_InitClock(clockId)"]
   B["Mcu_PollFunction()<br/>(cyclically)"]
   C{"Mcu_IsClockDistributed?"}
   D["clocks distributed<br/>to the clock tree"]

   A --> B
   B --> C
   C -->|FALSE| B
   C -->|TRUE| D
    
  • Mcu_InitClock applies the clock configuration identified by clockId and returns immediately, without waiting for stabilisation.

  • Mcu_PollFunction — called cyclically — polls the stabilisation status and distributes the clock once it is stable. (A short fixed delay, e.g. 10 µs, may instead be handled inside Mcu_InitClock.)

  • Mcu_IsClockDistributed reports whether every clock set by Mcu_InitClock has stabilised and been distributed. Before Mcu_Init — or after a reset, before Mcu_InitClock — it returns TRUE (the reset-default clock is already running).

At runtime Mcu_PollFunction may also perform ongoing work such as clock supervision or a software-based FLL; a detected clock failure is reported through LogM_Report with MCU_RTERR_CLOCK (CHI-MCU-MUST-08).

Reset-reason model

The reset cause is captured once, at initialization. Mcu_Init reads the reason from the hardware, holds it in an internal variable, and clears it from the hardware (reset-cause registers often persist across resets and must be cleared by software). Mcu_GetResetRawValue then returns that captured value — a bitwise-ORed uint32 whose bit meanings are hardware-defined (MCU_RESET_POWER_ON, MCU_RESET_SW, MCU_RESET_WATCHDOG, MCU_RESET_EXT_PIN, plus any vendor-specific reasons).

  • Called before Mcu_Init, Mcu_GetResetRawValue returns 0.

  • Where the hardware has no reset-reason detection, it returns MCU_RESET_POWER_ON (CHI-MCU-SHOULD-01).

Boot sequence

The informative view of a typical boot: initialize, read the reset cause, set up and wait for the clock, then run (CHI-MCU-MUST-02, CHI-MCU-MUST-04CHI-MCU-MUST-07):

        sequenceDiagram
   participant IC as Integration code
   participant DRV as McuDrv
   participant HW as MCU HW

   Note over IC,HW: after reset
   IC->>DRV: Mcu_Init(NULL_PTR)
   activate DRV
   DRV->>HW: capture + clear reset cause, init mode/reset registers
   DRV-->>IC: return (state INIT)
   deactivate DRV

   IC->>DRV: Mcu_GetResetRawValue()
   DRV-->>IC: captured reset cause

   IC->>DRV: Mcu_InitClock(clockId)
   DRV->>HW: apply clock config (no busy wait)
   loop until Mcu_IsClockDistributed() == TRUE
      IC->>DRV: Mcu_PollFunction()
      DRV->>HW: poll stabilisation, distribute when stable
   end

   Note over IC,HW: runtime (periodic)
   opt clock supervision configured
      IC->>DRV: Mcu_PollFunction()
      opt clock failure
         DRV->>IC: LogM_Report(..., MCU_RTERR_CLOCK)
      end
   end
    

Key terms

For MCU terms — reset reason, clock distribution, clock supervision — see the glossary in the appendix and the shared foundation in General.