Ejemplo n.º 1
0
/*!
 * @brief RTC setting up alarm.
 * @param uint32_t instance     : RTC instance
 * @param uint8_t offsetSec     : offset in seconds to call interrupt.
 */
void rtcSetAlarm(uint32_t instance, uint8_t offsetSec)
{
    uint32_t seconds;
    rtc_datetime_t date;

    if ((offsetSec < 1) || (offsetSec > 60))
    {
        offsetSec = 5;
    }
    // get date time and convert to seconds
    RTC_DRV_GetDatetime(instance, &date);
    // convert to sec and add offset
    RTC_HAL_ConvertDatetimeToSecs(&date, &seconds);
    seconds += offsetSec;
    RTC_HAL_ConvertSecsToDatetime(&seconds, &date);

    // set the date time for alarm
    if (RTC_DRV_SetAlarm(instance, &date, true))
    {
    }
    else
    {
        printf("Failed to set alarm. Alarm time is not in the future\r\n");
        return;
    }
}
Ejemplo n.º 2
0
bool RTC_DRV_SetAlarmRepeat(uint32_t instance, rtc_datetime_t *alarmTime, rtc_datetime_t *alarmRepInterval)
{
    assert(s_rtcRepeatAlarmState);
    assert(alarmRepInterval);

    if (!(RTC_DRV_SetAlarm(instance, alarmTime, true)))
    {
        return false;
    }

    memcpy(&s_rtcRepeatAlarmState->alarmTime, alarmTime, sizeof(*alarmTime));
    memcpy(&s_rtcRepeatAlarmState->alarmRepTime, alarmRepInterval, sizeof(*alarmRepInterval));

    return true;
}
Ejemplo n.º 3
0
void RTC_DRV_AlarmIntAction(uint32_t instance)
{
    uint32_t rtcBaseAddr = g_rtcBaseAddr[instance];

    if (s_rtcRepeatAlarmState != NULL)
    {
        s_rtcRepeatAlarmState->alarmTime.year += s_rtcRepeatAlarmState->alarmRepTime.year;
        s_rtcRepeatAlarmState->alarmTime.month += s_rtcRepeatAlarmState->alarmRepTime.month;
        s_rtcRepeatAlarmState->alarmTime.day += s_rtcRepeatAlarmState->alarmRepTime.day;
        s_rtcRepeatAlarmState->alarmTime.hour += s_rtcRepeatAlarmState->alarmRepTime.hour;
        s_rtcRepeatAlarmState->alarmTime.minute += s_rtcRepeatAlarmState->alarmRepTime.minute;
        RTC_DRV_SetAlarm(instance, &s_rtcRepeatAlarmState->alarmTime, true);
    }
    else
    {
        /* Writing to the alarm register clears the TAF flag in the Status register */
        RTC_HAL_SetAlarmReg(rtcBaseAddr, 0x0);
        RTC_HAL_SetAlarmIntCmd(rtcBaseAddr, false);
    }
}
/*!
* @brief RTC in alarm mode.
*
* This function demostrates how to use RTC as an alarm clock.
*/
int main(void)
{
    uint32_t sec;
    uint32_t currSeconds;
    rtc_datetime_t date;

    // Init hardware.
    hardware_init();

    PRINTF("RTC example: set up time to wake up an alarm\r\n");

    // Init RTC
    RTC_DRV_Init(RTC_INSTANCE);

    /* Need to check this here as the RTC_DRV_Init() may have issued a software reset on the
     * module clearing all prior RTC OSC related setup */
    BOARD_InitRtcOsc();

    // Set a start date time and start RT.
    date.year   = 2014U;
    date.month  = 12U;
    date.day    = 25U;
    date.hour   = 19U;
    date.minute = 0;
    date.second = 0;

    // Set RTC time to default
    RTC_DRV_SetDatetime(RTC_INSTANCE, &date);

    while (1)
    {
        busyWait = true;
        // Get date time.
        RTC_DRV_GetDatetime(RTC_INSTANCE, &date);

        // print default time
        PRINTF("Current datetime: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n",
                        date.year, date.month, date.day,
                        date.hour, date.minute, date.second);

        // Get alarm time from user
        sec = 0;
        PRINTF("Please input the number of second to wait for alarm \r\n");
        PRINTF("The second must be positive value\r\n");
        while (sec < 1)
        {
            SCANF("%d",&sec);
        }

        // Get current date time.
        RTC_DRV_GetDatetime(RTC_INSTANCE, &date);
        // Convert current date time to seconds
        RTC_HAL_ConvertDatetimeToSecs(&date, &currSeconds);

        // Add sec to currSeconds
        currSeconds += sec;
        // Convert sec to date type
        RTC_HAL_ConvertSecsToDatetime(&currSeconds, &date);

        // Set alarm time
        if(!RTC_DRV_SetAlarm(RTC_INSTANCE, &date, true))
        {
            PRINTF("Failed to set alarm. \r\n");
            continue;
        }
        // Print alarm time
        PRINTF("Alarm will be occured at: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n",
                        date.year, date.month, date.day,
                        date.hour, date.minute, date.second);

        // Wait until alarm occures
        while(busyWait)
        {}

        PRINTF("\r\n Alarm occured !!!! ");
    }

}
Ejemplo n.º 5
0
/*!
* @brief RTC in alarm mode.
*
* This function demostrates how to use RTC as an alarm clock.
*/
void main(void)
{
    uint32_t sec;
    uint32_t currSeconds;
    rtc_datetime_t date;

    // Init hardware.
    hardware_init();

    // Call this function to initialize the console UART.  This function
    // enables the use of STDIO functions (printf, scanf, etc.)
    dbg_uart_init();

    printf("RTC example: set up time to wake up an alarm\r\n");

    // Init RTC
    RTC_DRV_Init(RTC_INSTANCE);
    // Set a start date time and start RT.
    date.year   = 2014U;
    date.month  = 12U;
    date.day    = 25U;
    date.hour   = 19U;
    date.minute = 0;
    date.second = 0;

    // Set RTC time to default
    RTC_DRV_SetDatetime(RTC_INSTANCE, &date);

    while (1)
    {
        // Get date time.
        RTC_DRV_GetDatetime(RTC_INSTANCE, &date);

        // print default time
        printf("Current datetime: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n",
                        date.year, date.month, date.day,
                        date.hour, date.minute, date.second);

        // Convert current date time to seconds
        RTC_HAL_ConvertDatetimeToSecs(&date, &currSeconds);

        // Get alarm time from user
        sec = 0;
        printf("Please input the number of second to wait for alarm \r\n");
        printf("The second must be positive value\r\n");
        while (sec < 1)
        {
            scanf("%d",&sec);
        }

        // Add curr_seconds
        sec += currSeconds;
        // Convert sec to date type
        RTC_HAL_ConvertSecsToDatetime(&sec, &date);

        // Set alarm time
        if(!RTC_DRV_SetAlarm(RTC_INSTANCE, &date, true))
        {
            printf("Failed to set alarm. \r\n");
            continue;
        }

        // Print alarm time
        printf("Alarm will be occured at: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n",
                        date.year, date.month, date.day,
                        date.hour, date.minute, date.second);

        // Wait until alarm occures
        while(busyWait)
        {}

        printf("\r\n Alarm occured !!!! ");
    }

}