Exemplo n.º 1
0
/*!
 * @brief set alarm command.
 *
 * This function set the alarm which will be
 * trigerred x secs later. The alarm trigger
 * will print a notification on the console.
 */
static void cmd_alarm(uint8_t offsetSec)
{
    uint32_t seconds = 0;
    if ((offsetSec < 1) || (offsetSec > 60))
    {
        offsetSec = DEFAULT_ALARM_SECONDS;
    }

    RTC_HAL_GetDatetimeInSecs(RTC_BASE_PTR, &seconds);

    seconds += offsetSec;

    // set the datetime for alarm
    // set alarm in seconds
    RTC_HAL_SetAlarmReg(RTC_BASE_PTR, seconds);

    // Activate or deactivate the Alarm interrupt based on user choice
    RTC_HAL_SetAlarmIntCmd(RTC_BASE_PTR, true);

}
Exemplo n.º 2
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);
}