I want to measure a FIRC & SIRC clock monitoring during runtime, if i use while(CMU.CSR.B.SFM == 1U){} my execution has to wait for sometime, to avoid that i am using a logic to come out of the loop if measurement not completed within the time period . so what is the expected time to complete the SIRC and FIRC measurement by considering ageing factor and lifespan of MCU. Herewith I have added my logic which runs every 10ms.
uint8 Clock_Monitor_Runtime(void)
{
static ClockMonitorState state = FIRC_MONITOR_INIT; /* State variable for both monitors */
static uint32 elapsed_time = 0U; /* Time tracker for timeout */
static uint32 MeasDur = 0U; /* Measurement duration */
static uint8 result = CLK_IN_RANGE; /* Default result to indicate progress */
switch (state)
{
case FIRC_MONITOR_INIT:
MeasDur = 0x8FFFU; /* Set FIRC measurement duration */
CMU.CSR.B.CKSEL1 = 0x00U; /* Select FIRC clock or CLKMT0_RMN */
CMU.MDR.B.MD = MeasDur; /* Set measurement duration */
CMU.CSR.B.SFM = 0x01U; /* Start FIRC measurement */
elapsed_time = 0U; /* Reset elapsed time */
state = FIRC_MONITOR_WAIT;
break;
case FIRC_MONITOR_WAIT:
if (CMU.CSR.B.SFM == 0U)
{
/* FIRC measurement completed */
FIRC_MeaFreq = CMU.FDR.B.FD;
Firc_MonitoredClk = ((float32)FXOC_CLK / (float32)FIRC_MeaFreq) * (float32)MeasDur;
if ((Firc_MonitoredClk >= (float32)Min_FIRC_Freq) &&
(Firc_MonitoredClk <= (float32)Max_FIRC_Freq))
{
result = CLK_IN_RANGE; /* FIRC clock is within range */
state = SIRC_MONITOR_INIT; /* Move to SIRC monitoring */
}
else
{
result = CLK_OUT_RANGE; /* FIRC clock is out of range */
state = FIRC_MONITOR_INIT; /* Move to FIRC monitoring again */
}
}
else
{
/* Increment elapsed time (10 ms per call) */
elapsed_time += 10U;
if (elapsed_time >= 100U) /* Timeout after 100 ms */
{
result = CLK_OUT_RANGE; /* Timeout occurred */
state = MONITOR_DONE; /* Skip to done */
}
}
break;
}