[mini2440]fix list_date problem
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@535 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
31561ae50a
commit
7606f6d952
|
@ -21,8 +21,8 @@
|
||||||
|
|
||||||
#define RTC_DEBUG
|
#define RTC_DEBUG
|
||||||
|
|
||||||
#define RTC_ENABLE (RTCCON |= 0x01); /*RTC read and write enable */
|
#define RTC_ENABLE RTCCON |= 0x01; /*RTC read and write enable */
|
||||||
#define RTC_DISABLE (RTCCON &= ~0x01); /* RTC read and write disable */
|
#define RTC_DISABLE RTCCON &= ~0x01; /* RTC read and write disable */
|
||||||
#define BCD2BIN(n) (((((n) >> 4) & 0x0F) * 10) + ((n) & 0x0F))
|
#define BCD2BIN(n) (((((n) >> 4) & 0x0F) * 10) + ((n) & 0x0F))
|
||||||
#define BIN2BCD(n) ((((n) / 10) << 4) | ((n) % 10))
|
#define BIN2BCD(n) ((((n) / 10) << 4) | ((n) % 10))
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ void rt_hw_rtc_get(struct tm *ti)
|
||||||
rt_uint8_t sec, min, hour, mday, wday, mon, year;
|
rt_uint8_t sec, min, hour, mday, wday, mon, year;
|
||||||
|
|
||||||
/* enable access to RTC registers */
|
/* enable access to RTC registers */
|
||||||
RTC_ENABLE
|
RTCCON |= RTC_ENABLE;
|
||||||
|
|
||||||
/* read RTC registers */
|
/* read RTC registers */
|
||||||
do
|
do
|
||||||
|
@ -46,7 +46,12 @@ void rt_hw_rtc_get(struct tm *ti)
|
||||||
wday = BCDDAY;
|
wday = BCDDAY;
|
||||||
mon = BCDMON;
|
mon = BCDMON;
|
||||||
year = BCDYEAR;
|
year = BCDYEAR;
|
||||||
} while (sec != BCDSEC);
|
} while (sec != BCDSEC);
|
||||||
|
|
||||||
|
/*
|
||||||
|
rt_kprintf("sec:%x min:%x hour:%x mday:%x wday:%x mon:%x year:%x\n",
|
||||||
|
sec, min, hour, mday, wday, mon, year);
|
||||||
|
*/
|
||||||
|
|
||||||
/* disable access to RTC registers */
|
/* disable access to RTC registers */
|
||||||
RTC_DISABLE
|
RTC_DISABLE
|
||||||
|
@ -80,15 +85,17 @@ void rt_hw_rtc_set(struct tm *ti)
|
||||||
/* enable access to RTC registers */
|
/* enable access to RTC registers */
|
||||||
RTC_ENABLE
|
RTC_ENABLE
|
||||||
|
|
||||||
/* write RTC registers */
|
do{
|
||||||
BCDSEC = sec;
|
/* write RTC registers */
|
||||||
BCDMIN = min;
|
BCDSEC = sec;
|
||||||
BCDHOUR = hour;
|
BCDMIN = min;
|
||||||
BCDDATE = mday;
|
BCDHOUR = hour;
|
||||||
BCDDAY = wday;
|
BCDDATE = mday;
|
||||||
BCDMON = mon;
|
BCDDAY = wday;
|
||||||
BCDYEAR = year;
|
BCDMON = mon;
|
||||||
|
BCDYEAR = year;
|
||||||
|
}while (sec != BCDSEC);
|
||||||
|
|
||||||
/* disable access to RTC registers */
|
/* disable access to RTC registers */
|
||||||
RTC_DISABLE
|
RTC_DISABLE
|
||||||
}
|
}
|
||||||
|
@ -162,23 +169,9 @@ void rt_hw_rtc_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t time(time_t* t)
|
time_t time(time_t* t)
|
||||||
{
|
{
|
||||||
rt_device_t device;
|
rt_kprintf("not implement yet\n");
|
||||||
struct tm ti;
|
return 0;
|
||||||
time_t time;
|
|
||||||
|
|
||||||
device = rt_device_find("rtc");
|
|
||||||
if (device != RT_NULL)
|
|
||||||
{
|
|
||||||
rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &ti);
|
|
||||||
if (t != RT_NULL)
|
|
||||||
{
|
|
||||||
time = mktime(&ti);
|
|
||||||
*t = time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
|
@ -219,10 +212,18 @@ FINSH_FUNCTION_EXPORT(set_time, set time(hour, minute, second))
|
||||||
|
|
||||||
void list_date(void)
|
void list_date(void)
|
||||||
{
|
{
|
||||||
time_t now;
|
struct tm ti;
|
||||||
|
rt_device_t device;
|
||||||
time(&now);
|
|
||||||
rt_kprintf("%s\n", ctime(&now));
|
device = rt_device_find("rtc");
|
||||||
|
if (device != RT_NULL)
|
||||||
|
{
|
||||||
|
rt_rtc_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &ti);
|
||||||
|
|
||||||
|
rt_kprintf("%04d-%02d-%02d %02d-%02d-%02d\n",
|
||||||
|
ti.tm_year + 1900, ti.tm_mon+1, ti.tm_mday,
|
||||||
|
ti.tm_hour, ti.tm_min, ti.tm_sec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FINSH_FUNCTION_EXPORT(list_date, list date)
|
FINSH_FUNCTION_EXPORT(list_date, list date)
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue