Пример #1
0
/*FUNCTION**********************************************************************
 *
 * Function Name : RTC_DRV_SetDatetime
 * Description   : sets the RTC date and time according to the given time struct.
 * This function will set the RTC date and time according to the given time
 * struct, if start_after_set is true, the RTC oscillator will be enabled and
 * the counter will start.
 *
 *END**************************************************************************/
bool RTC_DRV_SetDatetime(uint32_t instance, rtc_datetime_t *datetime)
{
    assert(datetime);
    uint32_t rtcBaseAddr = g_rtcBaseAddr[instance];
    uint32_t srcClock = 0;
    uint32_t seconds = 0;

    /* Return error if the time provided is not valid */
    if (!(RTC_HAL_IsDatetimeCorrectFormat(datetime)))
    {
        return false;
    }

    RTC_HAL_ConvertDatetimeToSecs(datetime, &seconds);

    if ((srcClock = CLOCK_SYS_GetExternalRefClock32kFreq()) != 32768U)
    {
        /* As the seconds register will not increment every second, we need to adjust the value
         * programmed to the seconds register */
        seconds = seconds / (32768U / srcClock);
    }
    /* Set time in seconds */
    RTC_HAL_SetDatetimeInsecs(rtcBaseAddr, seconds);

    return true;
}
Пример #2
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_GetLptmrFreq
 * Description   : Gets LPTMRx pre-scaler/glitch filter clock frequency.
 * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
 *
 *END**************************************************************************/
uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
{
    uint32_t freq;

    switch (lptmrSrc)
    {
        case kClockLptmrSrcMcgIrClk:            /* MCG out clock  */
            freq = CLOCK_HAL_GetInternalRefClk(MCG);
            break;
        case kClockLptmrSrcLpoClk:              /* LPO clock     */
            freq = CLOCK_SYS_GetLpoClockFreq();
            break;
        case kClockLptmrSrcEr32kClk:            /* ERCLK32K clock */
            freq = CLOCK_SYS_GetExternalRefClock32kFreq();
            break;
        case kClockLptmrSrcOsc0erClkUndiv:      /* OSC0ERCLKUDIV clock */
            freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
            break;
        default:
            freq = 0U;
            break;
    }

    return freq;
}
clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
                                                 uint32_t *frequency)
{
    clock_manager_error_code_t returnCode = kClockManagerSuccess;

    switch (clockName)
    {
        case kCoreClock:
        case kSystemClock:
            *frequency = CLOCK_SYS_GetCoreClockFreq();
            break;
        case kPlatformClock:
            *frequency = CLOCK_SYS_GetSystemClockFreq();
            break;
        case kBusClock:
            *frequency = CLOCK_SYS_GetBusClockFreq();
            break;
        case kFlexBusClock:
            *frequency = CLOCK_SYS_GetFlexbusFreq();
            break;
        case kFlashClock:
            *frequency = CLOCK_SYS_GetFlashClockFreq();
            break;
        case kOsc32kClock:
            *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
            break;
        case kOsc0ErClock:
            *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
            break;
        case kRtcoutClock:
            *frequency = CLOCK_SYS_GetRtcOutFreq();
            break;
        case kMcgFfClock:
            *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
            break;
        case kMcgFllClock:
            *frequency = CLOCK_HAL_GetFllClk(MCG_BASE);
            break;
        case kMcgPll0Clock:
            *frequency = CLOCK_HAL_GetPll0Clk(MCG_BASE);
            break;
        case kMcgOutClock:
            *frequency = CLOCK_HAL_GetOutClk(MCG_BASE);
            break;
        case kMcgIrClock:
            *frequency = CLOCK_HAL_GetInternalRefClk(MCG_BASE);
            break;
        case kLpoClock:
            *frequency = CLOCK_SYS_GetLpoClockFreq();
            break;
        default:
            *frequency = 0U;
            returnCode = kClockManagerNoSuchClockName;
            break;
    }

    return returnCode;
}
Пример #4
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_GetRtcOutFreq
 * Description   : Gets the RTC_CLKOUT frequency.
 * This function gets RTC_CLKOUT  clock frequency.
 *
 *END**************************************************************************/
uint32_t CLOCK_SYS_GetRtcOutFreq(void)
{
    if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
    {
        return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
    }
    else
    {
        return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
Пример #5
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_GetRtcOutFreq
 * Description   : Gets the RTC_CLKOUT frequency.
 * This function gets RTC_CLKOUT  clock frequency.
 *
 *END**************************************************************************/
uint32_t CLOCK_SYS_GetRtcOutFreq(void)
{
#if FSL_FEATURE_SIM_OPT_HAS_RTC_CLOCK_OUT_SELECTION
    if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
    {
        return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
    }
    else
    {
#endif
        return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
Пример #6
0
/*FUNCTION**********************************************************************
 *
 * Function Name : rtc_get_alarm
 * Description   : returns the RTC alarm time.
 * This function will first get alarm time in seconds, then convert the seconds to
 * date time.
 *
 *END**************************************************************************/
void RTC_DRV_GetAlarm(uint32_t instance, rtc_datetime_t *date)
{
    assert(date);

    uint32_t alrmSeconds = 0;
    uint32_t srcClock = 0;

    /* Get alarm in seconds  */
    alrmSeconds = RTC_HAL_GetAlarmReg(g_rtcBaseAddr[instance]);

    if ((srcClock = CLOCK_SYS_GetExternalRefClock32kFreq()) != 32768U)
    {
        /* Re-adjust the alarm value to match the method used to program it */
        alrmSeconds = (alrmSeconds * (32768U / srcClock));
    }

    RTC_HAL_ConvertSecsToDatetime(&alrmSeconds, date);
}
Пример #7
0
/*FUNCTION**********************************************************************
 *
 * Function Name : RTC_DRV_GetDatetime
 * Description   : gets the actual RTC time and stores it in the given time struct.
 * This function will get the actual RTC time and stores it in the given time
 * struct.
 *
 *END**************************************************************************/
void RTC_DRV_GetDatetime(uint32_t instance, rtc_datetime_t *datetime)
{
    assert(datetime);

    uint32_t rtcBaseAddr = g_rtcBaseAddr[instance];
    uint32_t seconds = 0;
    uint32_t srcClock = 0;

    RTC_HAL_GetDatetimeInSecs(rtcBaseAddr, &seconds);

    if ((srcClock = CLOCK_SYS_GetExternalRefClock32kFreq()) != 32768U)
    {
        /* In case the input clock to the RTC counter is not 32KHz, the seconds register will not
         * increment every second, therefore the seconds register value needs to be adjusted.
         * to get actual seconds. We then add the prescaler register value to the seconds.
         */
        seconds = (seconds * (32768U / srcClock)) + (RTC_HAL_GetPrescaler(rtcBaseAddr) / srcClock);
    }
    RTC_HAL_ConvertSecsToDatetime(&seconds, datetime);
}
Пример #8
0
/*FUNCTION**********************************************************************
 *
 * Function Name : RTC_DRV_SetAlarm
 * Description   : sets the RTC alarm.
 * This function will first check if the date time has correct format. If yes,
 * convert the date time to seconds, and set the alarm in seconds.
 *
 *END**************************************************************************/
bool RTC_DRV_SetAlarm(uint32_t instance, rtc_datetime_t *alarmTime, bool enableAlarmInterrupt)
{
    assert(alarmTime);

    uint32_t rtcBaseAddr = g_rtcBaseAddr[instance];
    uint32_t srcClock = 0;
    uint32_t alrmSeconds = 0;
    uint32_t currSeconds = 0;

    /* Return error if the alarm time provided is not valid */
    if (!(RTC_HAL_IsDatetimeCorrectFormat(alarmTime)))
    {
        return false;
    }

    RTC_HAL_ConvertDatetimeToSecs(alarmTime, &alrmSeconds);

    /* Get the current time */
    currSeconds = RTC_HAL_GetSecsReg(rtcBaseAddr);

    if ((srcClock = CLOCK_SYS_GetExternalRefClock32kFreq()) != 32768U)
    {
        /* As the seconds register will not increment every second, we need to adjust the value
         * programmed to the alarm register */
        alrmSeconds = alrmSeconds / (32768U / srcClock);
    }

    /* Make sure the alarm is for a future time */
    if (alrmSeconds < currSeconds)
    {
        return false;
    }

    /* set alarm in seconds*/
    RTC_HAL_SetAlarmReg(rtcBaseAddr, alrmSeconds);

    /* Activate or deactivate the Alarm interrupt based on user choice */
    RTC_HAL_SetAlarmIntCmd(rtcBaseAddr, enableAlarmInterrupt);

    return true;
}