Exemplo n.º 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);
    RTC_Type *rtcBase = g_rtcBase[instance];
    uint32_t srcClock = 0;
    uint32_t seconds = 0;
    uint16_t preScaler = 0;
    uint64_t tmp = 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_GetRtcFreq(0U)) != 32768U)
    {
        /* As the seconds register will not increment every second, we need to adjust the value
         * programmed to the seconds register */
        tmp = (uint64_t)seconds * (uint64_t)srcClock;
        preScaler = (uint32_t)(tmp & 0x7FFFU);
        seconds = (uint32_t)(tmp >> 15U);
    }
Exemplo n.º 2
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;
}
Exemplo n.º 3
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);

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

    RTC_HAL_SetDatetime(g_rtcBaseAddr[instance], datetime);

    return true;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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);

    bool ret = false;
    uint32_t rtcBaseAddr = g_rtcBaseAddr[instance];

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

    ret = RTC_HAL_SetAlarm(rtcBaseAddr, alarmTime);

    if (ret)
    {
        /* Activate the Alarm interrupt if user wishes to use interrupts */
        RTC_HAL_SetAlarmIntCmd(rtcBaseAddr, enableAlarmInterrupt);
    }

    return ret;
}