Clock setup
Informative
How to bring the clock tree up and keep it supervised. Binding rules: CHI-MCU-MUST-04, CHI-MCU-MUST-05, CHI-MCU-MUST-06, CHI-MCU-MUST-07, and CHI-MCU-MUST-08 in Mcu — Requirements.
Apply a clock configuration
Std_ReturnType r = Mcu_InitClock(0u); /* apply clock configuration id 0 */
/* E_OK: accepted; E_NOT_OK: rejected */
Mcu_InitClock applies the clock setting identified by clockId (its index in the configured
clock_settings list) and returns immediately — it does not busy-wait for a PLL or oscillator
to stabilise.
Wait for distribution (non-blocking)
Because stabilisation is asynchronous, drive it from Mcu_PollFunction and check
Mcu_IsClockDistributed before relying on the clock:
while (Mcu_IsClockDistributed() == FALSE) {
Mcu_PollFunction(); /* polls stabilisation and distributes when ready */
}
Mcu_IsClockDistributed returns TRUE only once 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.
Runtime supervision
If clock supervision or a software FLL is configured, keep calling Mcu_PollFunction cyclically at
runtime. A detected clock failure is reported as a runtime error:
/* the driver reports, via LogM_Report, on a supervised clock failure: */
/* LogM_Report(LOGM_LOG_LEVEL_RTERR, moduleId, instanceId, apiId, MCU_RTERR_CLOCK); */
See LogM_Report in the general reference.