73 lines
1.4 KiB
C
73 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/time.h>
|
|
|
|
#include "osp.h"
|
|
|
|
|
|
|
|
/*
|
|
*osp_get_rtc_time - query RTC time
|
|
*input:
|
|
* pRtc pointer to RTC
|
|
*return
|
|
* OSP_OK
|
|
* OSP_ERROR(fail)
|
|
*/
|
|
|
|
OSP_STATUS osp_get_rtc_time(OSP_RTCTIME *pRtc)
|
|
{
|
|
#if 0
|
|
|
|
time_t sysTime;
|
|
struct tm *timeInfo = NULL;
|
|
|
|
if (pRtc == NULL)
|
|
return (OSP_ERROR);
|
|
gettimeofday
|
|
time(&sysTime);
|
|
timeInfo = localtime(&sysTime);
|
|
pRtc->year = timeInfo->tm_year+1900;
|
|
pRtc->month = timeInfo->tm_mon+1;
|
|
pRtc->day = timeInfo->tm_mday;
|
|
pRtc->hour = timeInfo->tm_hour;
|
|
pRtc->minute = timeInfo->tm_min;
|
|
pRtc->second = timeInfo->tm_sec;
|
|
#endif
|
|
struct timeval tv;
|
|
struct timezone tz;
|
|
|
|
struct tm *timeInfo = NULL;
|
|
|
|
if (pRtc == NULL)
|
|
return (OSP_ERROR);
|
|
|
|
gettimeofday(&tv, &tz);
|
|
timeInfo = localtime(&tv.tv_sec);
|
|
pRtc->year = timeInfo->tm_year + 1900;
|
|
pRtc->month = timeInfo->tm_mon + 1;
|
|
pRtc->day = timeInfo->tm_mday;
|
|
pRtc->hour = timeInfo->tm_hour;
|
|
pRtc->minute = timeInfo->tm_min;
|
|
pRtc->second = timeInfo->tm_sec;
|
|
pRtc->usecond = tv.tv_usec;
|
|
|
|
return (OSP_OK);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void osp_show_rtc_time(void)
|
|
{
|
|
OSP_RTCTIME Rtc;
|
|
osp_get_rtc_time(&Rtc);
|
|
|
|
osp_debug_out(CMD_DEBUG_LEVEL, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
|
|
Rtc.year, Rtc.month, Rtc.day,
|
|
Rtc.hour, Rtc.minute, Rtc.second);
|
|
|
|
}
|