예제 #1
0
파일: krtc.c 프로젝트: jewlenchow/MQX_3.8.1
_mqx_int _rtc_sync_with_mqx
(
    /* [IN] whether to update MQX time (source is RTC) or RTC time (source is MQX) */
    boolean update_mqx
)
{
    RTC_TIME_STRUCT rtc_time;
    DATE_STRUCT     mqx_date;
    TIME_STRUCT     mqx_time;

    if (update_mqx == TRUE)
    {
        _rtc_get_time(&rtc_time);
        _rtc_time_to_mqx_date(&rtc_time, &mqx_date);
        _time_from_date(&mqx_date, &mqx_time);
        _time_set(&mqx_time);
    }
    else
    {
        _time_get(&mqx_time);
        _time_to_date(&mqx_time, &mqx_date);
        _rtc_time_from_mqx_date (&mqx_date, &rtc_time);
        _rtc_set_time (&rtc_time);
    }
    return MQX_OK;
}
예제 #2
0
파일: main.c 프로젝트: BillyZhangZ/wifi
void lcd_task
(
        uint32_t initial_data
)
{
    DATE_STRUCT      time_rtc;
    uint32_t         time;
    TIME_STRUCT      ts;
    eLCD_Symbols     spec_sym;
    char             time[5];
    char             state = 0;

    puts("\n\n");
    if (_lcd_init() == IO_ERROR)
    {
        puts("_lcd_init() function returned IO_ERROR\n");
        puts("lcd_task blocked\n\n");
        _task_block();
    }

    puts("TWRPI-SLCD display is connected and lcd_task is running\n");

    _lcd_segments( FALSE );
    while(1)
    {
        _rtc_get_time(&time);
        ts.SECONDS = time;
        ts.MILLISECONDS = 0;
        _time_to_date(&ts, &time_rtc);

        /* post meridiem */
        if( time_rtc.HOUR > 12 )
        {
            time_rtc.HOUR -= 12;
            spec_sym = LCD_AM;
            _lcd_symbol( spec_sym, FALSE );
            spec_sym = LCD_PM;
            _lcd_symbol( spec_sym, TRUE);
        }
        else
        {
            spec_sym = LCD_PM;
            _lcd_symbol( spec_sym, FALSE);
            spec_sym = LCD_AM;
            _lcd_symbol( spec_sym, TRUE);
        }
        sprintf( time, "%2d%2d", time_rtc.HOUR, time_rtc.MINUTE);
        if( time_rtc.MINUTE < 10 )
        {
            time[2] = '0';
        }
        _lcd_puts( time );
        spec_sym = LCD_COL1;
        state = (state + 1) & 1;
        _lcd_symbol( spec_sym, (bool)state );
        _time_delay(1000);
    } /* Endwhile */
} /* Endbody */
예제 #3
0
파일: main.c 프로젝트: BillyZhangZ/wifi
void main_task
(
    uint32_t initial_data
)
{ /* Body */
    uint32_t        rtc_time;
    uint32_t        rtc_time_default;
    TIME_STRUCT     mqx_time;
    DATE_STRUCT     date_time;

    if (_lwevent_create(&lwevent,0) != MQX_OK)
    {
        printf("\nMake event failed");
        _task_block();
    }
    printf ("\f RTC Demo :\n\n");
    _rtc_get_time(&rtc_time);
    print_rtc_time(rtc_time);

    /* initialize time */
    date_time.YEAR     = RTC_TIME_INIT_TM_YEAR;
    date_time.MONTH    = RTC_TIME_INIT_TM_MON;
    date_time.DAY      = RTC_TIME_INIT_TM_MDAY;
    date_time.HOUR     = RTC_TIME_INIT_TM_HOUR;
    date_time.MINUTE   = RTC_TIME_INIT_TM_MIN;
    date_time.SECOND   = RTC_TIME_INIT_TM_SEC;
    date_time.MILLISEC = 0;

    /* Convert date time to time struct */
    if ( _time_from_date(&date_time, &mqx_time) == FALSE)
    {
        printf("\n Cannot convert date_time ");
        _task_block();
    }

    /* Convert rtc time to TIME_STRUCT */
    rtc_time = mqx_time.SECONDS;

    printf(" Set RTC time is: %s %s %3d %.2d:%.2d:%.2d %d\n",
            _days_abbrev[date_time.WDAY],
            _months_abbrev[date_time.MONTH - 1],
            date_time.DAY,
            date_time.HOUR,
            date_time.MINUTE,
            date_time.SECOND,
            date_time.YEAR);
    /* Set MQX time*/
    _time_set(&mqx_time);
    /* Set RTC time*/
    _rtc_set_time(rtc_time);
    printf("\n MQX time: %d SECONDS, %d MILISECOND ", mqx_time.SECONDS, mqx_time.MILLISECONDS);

    /*
     * set-up alarm
     */

    /* install callback */
    _rtc_callback_reg((INT_ISR_FPTR)rtc_callback, (void*)NULL);
    /* Set alarm to maximum time to avoid unexpected interrupt in next running */
    _rtc_set_alarm(MAXIMUM_SECONDS_IN_TIME,(uint32_t)0);
    _lwevent_clear(&lwevent,LWE_ALARM);
    
    /* Get current time */
    _rtc_get_time(&rtc_time);

    /* setup alarm in next 10 seconds & period 4 seconds*/
    rtc_time += (uint32_t)ALARM_NEXT_TIME; /* Alarm occurs in next 10 seconds */
    printf("\n Setup to occur alarm in next %d seconds & with period: %d seconds",ALARM_NEXT_TIME, ALARM_PERIOD);
    _rtc_set_alarm(rtc_time,(uint32_t)ALARM_PERIOD);
    printf("\n Wait %d seconds ....",ALARM_NEXT_TIME);
    /* Wait to clear LWE_ALARM event */
    _lwevent_wait_ticks(&lwevent,LWE_ALARM,FALSE,0);
    _lwevent_clear(&lwevent,LWE_ALARM);
    printf ("\nALARM! ALARM! ALARM!\n");
    /* Print current time */
    _rtc_get_time(&rtc_time);
    print_rtc_time(rtc_time);

    printf("\n Wait next alarm in %d seconds....",ALARM_PERIOD);
    _lwevent_wait_ticks(&lwevent,LWE_ALARM,FALSE,0);
    _lwevent_clear(&lwevent,LWE_ALARM);
    printf ("\nALARM! ALARM! ALARM!\n");
    _rtc_get_time(&rtc_time);
    print_rtc_time(rtc_time);

    printf ("\nClearing RTC:\n");
    _rtc_set_time(0);
    _rtc_get_time(&rtc_time_default);
    print_rtc_time(rtc_time_default);
    /* Wait 2 seconds after resynchronize rtc time with mqx time*/
    do{
       _rtc_get_time(&rtc_time);
    } while ((rtc_time - rtc_time_default) < 2);

    /* Get current time & display on terminal */
    _rtc_get_time(&rtc_time);
    print_rtc_time(rtc_time);

    printf ("Synchronize RTC to MQX time again:\n");
    _time_get(&mqx_time);
    rtc_time = mqx_time.SECONDS;
    _rtc_set_time(rtc_time);
    
    _rtc_get_time(&rtc_time);
    print_rtc_time(rtc_time);
    
#if PSP_HAS_IRTC == 1
    irtc_test();
#endif /* PSP_HAS_IRTC == 1 */

    printf ("Finish, press/hold reset to repeat.\n");
    _task_block() ;
} /* Endbody */