Application Note
69 of 80
002-26071 Rev. *B
2021-09-07
Clock configuration setup in TRAVEO™ T2G family CYT4D series MCUs
Supplementary information
Code Listing 59
GetILOClockFreq() function
uint32_t GetILOClockFreq(void)
{
uint32_t counter1 = 40000ul;
if((SRSS->unCLK_ECO_STATUS.stcField.u1ECO_OK == 0ul) || (SRSS->unCLK_ECO_STATUS.stcField.u1ECO_READY == 0ul))
{
while(1);
}
cy_en_sysclk_status_t status;
status = Cy_SysClk_StartClkMeasurementCounters(CY_SYSCLK_MEAS_CLK_ECO, counter1, clockMeasuredInfo[0].name);
CY_ASSERT(status == CY_SYSCLK_SUCCESS);
while(Cy_SysClk_ClkMeasurementCountersDone() == false);
status = Cy_SysClk_ClkMeasurementCountersGetFreq(&clockMeasuredInfo[0].measuredFreq, CLK_FREQ_ECO);
CY_ASSERT(status == CY_SYSCLK_SUCCESS);
:
uint32_t Frequency = clockMeasuredInfo[0].measuredFreq;
return (Frequency);
}
Code Listing 60
Cy_SysClk_StartClkMeasurementCounters() function
cy_en_sysclk_status_t Cy_SysClk_StartClkMeasurementCounters(cy_en_meas_clks_t clock1, uint32_t count1,
cy_en_meas_clks_t clock2)
{
cy_en_sysclk_status_t rtnval = CY_SYSCLK_INVALID_STATE;
:
if (!preventCounting
/* don't start a measurement if about to enter DeepSleep mode */
||
SRSS->unCLK_CAL_CNT1.stcField.u1CAL_COUNTER_DONE != 0ul
/*1 = done*/
)
{
:
SRSS->unCLK_OUTPUT_FAST.stcField.u4FAST_SEL0 = (uint32_t)clock1;
:
SRSS->unCLK_OUTPUT_SLOW.stcField.u4SLOW_SEL1 = (uint32_t)clock2;
SRSS->unCLK_OUTPUT_FAST.stcField.u4FAST_SEL1 = 7ul; /*slow_sel1 output*/;
:
rtnval = CY_SYSCLK_SUCCESS;
/* Save this input parameter for use later, in other functions.
No error checking is done on this parameter.*/
clk1Count1 = count1;
/* Counting starts when counter1 is written with a nonzero
value. */
SRSS->unCLK_CAL_CNT1.stcField.u24CAL_COUNTER1 = clk1Count1;
:
return (rtnval);
}
Code Listing 61
Cy_SysClk_ClkMeasurementCountersDone() function
__STATIC_INLINE bool Cy_SysClk_ClkMeasurementCountersDone(void)
{
return (bool)(SRSS->unCLK_CAL_CNT1.stcField.u1CAL_COUNTER_DONE);
/* 1 = done */
}
Code Listing 62
Cy_SysClk_ClkMeasurementCountersGetFreq() function
cy_en_sysclk_status_t Cy_SysClk_ClkMeasurementCountersGetFreq(uint32_t *measuredFreq, uint32_t refClkFreq)
{
if(SRSS->unCLK_CAL_CNT1.stcField.u1CAL_COUNTER_DONE != 1ul)
{
return(CY_SYSCLK_INVALID_STATE);
}
Check the ECO status.
Start the clock measurement counter. See
Check if counter measurement is done. See
Get the ILO frequency. See
(2) Setting the reference clock (ECO)
(3) Setting the measurement clock
(ILO0)
(4) Set the count value and start the counter.
(5) Check the completion of lock
calibration counter operation.