From d57496b78cf3ffc5d56545149e0c749fe8f56b77 Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Sun, 21 Nov 2010 23:55:44 +0000 Subject: [PATCH] add time related function. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1082 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/libc/newlib/libc.c | 29 +++++++++++++++++++++++++++++ components/libc/newlib/libc.h | 1 + 2 files changed, 30 insertions(+) diff --git a/components/libc/newlib/libc.c b/components/libc/newlib/libc.c index 477ee4450..90b0b7f2e 100644 --- a/components/libc/newlib/libc.c +++ b/components/libc/newlib/libc.c @@ -2,6 +2,27 @@ #include #include #include +#include + +struct timeval _timevalue; +static void libc_system_time_init() +{ + rt_device_t device; + time_t time; + rt_tick_t tick; + + time = 0; tick = 0; + device = rt_device_find("rtc"); + if (device != RT_NULL) + { + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); + } + + tick = rt_tick_get(); + + _timevalue.tv_sec = time; + _timevalue.tv_usec = (1000000UL * tick)/RT_TICK_PER_SECOND; +} void libc_system_init(const char* tty_name) { @@ -20,3 +41,11 @@ void libc_system_init(const char* tty_name) putenv("HOME=/"); } +int libc_time_to_tick(const struct timespec *time) +{ + int tick; + + tick = RT_WAITING_FOREVER; + + return tick; +} diff --git a/components/libc/newlib/libc.h b/components/libc/newlib/libc.h index b21a7264b..60a86e49a 100644 --- a/components/libc/newlib/libc.h +++ b/components/libc/newlib/libc.h @@ -2,5 +2,6 @@ #define __RTT_LIBC_H__ void libc_system_init(const char* tty_name); +int libc_time_to_tick(const struct timespec *time); #endif