From a281ee98745f4bdf6b4b1b1d202f9450430d074e Mon Sep 17 00:00:00 2001 From: iysheng Date: Fri, 5 Feb 2021 11:46:44 +0800 Subject: code format --- components/drivers/include/drivers/hwtimer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/drivers/include/drivers/hwtimer.h b/components/drivers/include/drivers/hwtimer.h index cbfeec2bf8..d00dbd8a13 100644 --- a/components/drivers/include/drivers/hwtimer.h +++ b/components/drivers/include/drivers/hwtimer.h @@ -70,7 +70,7 @@ typedef struct rt_hwtimer_device rt_int32_t freq; /* counting frequency set by the user */ rt_int32_t overflow; /* timer overflows */ - float period_sec; + float period_sec; rt_int32_t cycles; /* how many times will generate a timeout event after overflow */ rt_int32_t reload; /* reload cycles(using in period mode) */ rt_hwtimer_mode_t mode; /* timing mode(oneshot/period) */ -- cgit v1.3.1 From 23304a77d9c2d0f06fc7fc412afd4d9a74dcfff3 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 6 Feb 2021 02:27:18 +0800 Subject: [bug][pin] 修复错误码没有为负的错误 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/misc/pin.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'components') diff --git a/components/drivers/misc/pin.c b/components/drivers/misc/pin.c index 2750f5105a..6f27fe516d 100644 --- a/components/drivers/misc/pin.c +++ b/components/drivers/misc/pin.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2015-01-20 Bernard the first version + * 2021-02-06 Meco Man fix RT_ENOSYS code in negative */ #include @@ -108,7 +109,7 @@ rt_err_t rt_pin_attach_irq(rt_int32_t pin, rt_uint32_t mode, { return _hw_pin.ops->pin_attach_irq(&_hw_pin.parent, pin, mode, hdr, args); } - return RT_ENOSYS; + return -RT_ENOSYS; } rt_err_t rt_pin_detach_irq(rt_int32_t pin) { @@ -117,7 +118,7 @@ rt_err_t rt_pin_detach_irq(rt_int32_t pin) { return _hw_pin.ops->pin_detach_irq(&_hw_pin.parent, pin); } - return RT_ENOSYS; + return -RT_ENOSYS; } rt_err_t rt_pin_irq_enable(rt_base_t pin, rt_uint32_t enabled) @@ -127,7 +128,7 @@ rt_err_t rt_pin_irq_enable(rt_base_t pin, rt_uint32_t enabled) { return _hw_pin.ops->pin_irq_enable(&_hw_pin.parent, pin, enabled); } - return RT_ENOSYS; + return -RT_ENOSYS; } /* RT-Thread Hardware PIN APIs */ -- cgit v1.3.1 From 0d30632de6864a7cfaaa3a1de78ff7ef8f77539a Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 7 Feb 2021 22:09:22 +0800 Subject: fix #3976 --- components/libc/compilers/common/time.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index e2dae1feaf..ad167a85c7 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -213,22 +213,12 @@ RT_WEAK clock_t clock(void) /* TODO: timezone */ int gettimeofday(struct timeval *tp, struct timezone *tz) { - time_t time = 0; -#ifdef RT_USING_DEVICE - rt_device_t device; - device = rt_device_find("rtc"); - RT_ASSERT(device != RT_NULL); - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); + time_t time = time(NULL); if (tp != RT_NULL) { tp->tv_sec = time; tp->tv_usec = 0; } -#else - tv->tv_sec = 0; - tv->tv_usec = 0; -#endif - return time; } -- cgit v1.3.1 From d92f8a53da900f4c03dd8c5c0b8163a03a72a9df Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 7 Feb 2021 22:25:30 +0800 Subject: update --- components/libc/compilers/common/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index ad167a85c7..d7f239bea1 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -213,13 +213,13 @@ RT_WEAK clock_t clock(void) /* TODO: timezone */ int gettimeofday(struct timeval *tp, struct timezone *tz) { - time_t time = time(NULL); + time_t t = time(RT_NULL); if (tp != RT_NULL) { - tp->tv_sec = time; + tp->tv_sec = t; tp->tv_usec = 0; } - return time; + return 0; } time_t timegm(struct tm * const t) -- cgit v1.3.1 From 4c6962436ae8a89252c397dffac4b865f5cb663f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 7 Feb 2021 22:33:37 +0800 Subject: update --- components/libc/compilers/common/time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index d7f239bea1..bdbb27bce4 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -213,10 +213,9 @@ RT_WEAK clock_t clock(void) /* TODO: timezone */ int gettimeofday(struct timeval *tp, struct timezone *tz) { - time_t t = time(RT_NULL); if (tp != RT_NULL) { - tp->tv_sec = t; + tp->tv_sec = time(RT_NULL); tp->tv_usec = 0; } return 0; -- cgit v1.3.1 From 6c7dd305329602611aba93772357aa5a394a3a6e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 00:56:31 +0800 Subject: add function settimeofday & stime --- components/libc/compilers/common/sys/time.h | 4 +- components/libc/compilers/common/time.c | 71 +++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 20 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index e99fd7d54f..599b8b5262 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -48,8 +48,10 @@ struct timezone { int tz_dsttime; /* type of dst correction */ }; -int gettimeofday(struct timeval *tp, struct timezone *tz); +int stime(const time_t *t); time_t timegm(struct tm * const t); +int gettimeofday(struct timeval *tv, struct timezone *tz); +int settimeofday(const struct timeval *tv, const struct timezone *tz); #ifdef __cplusplus } diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index bdbb27bce4..155a04f92f 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -8,6 +8,8 @@ * 2019-08-21 zhangjun copy from minilibc * 2020-09-07 Meco Man combine gcc armcc iccarm * 2021-02-05 Meco Man add timegm() + * 2021-02-07 Meco Man fixed gettimeofday() time() + * 2021-02-08 Meco Man add settimeofday() stime() */ #include @@ -175,24 +177,15 @@ time_t time(time_t *t) #endif { time_t time_now = 0; - #ifdef RT_USING_RTC - static rt_device_t device = RT_NULL; - - /* optimization: find rtc device only first. */ - if (device == RT_NULL) - { - device = rt_device_find("rtc"); - } + rt_device_t device; /* read timestamp from RTC device. */ - if (device != RT_NULL) + device = rt_device_find("rtc"); + if (rt_device_open(device, 0) == RT_EOK) { - if (rt_device_open(device, 0) == RT_EOK) - { - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); - rt_device_close(device); - } + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); + rt_device_close(device); } #endif /* RT_USING_RTC */ @@ -210,15 +203,27 @@ RT_WEAK clock_t clock(void) return rt_tick_get(); } -/* TODO: timezone */ -int gettimeofday(struct timeval *tp, struct timezone *tz) +int stime(const time_t *t) { - if (tp != RT_NULL) +#ifdef RT_USING_RTC + rt_device_t device; + + /* read timestamp from RTC device. */ + device = rt_device_find("rtc"); + if (rt_device_open(device, 0) == RT_EOK) + { + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, (void*)t); + rt_device_close(device); + } + else { - tp->tv_sec = time(RT_NULL); - tp->tv_usec = 0; + return -1; } return 0; + +#else + return -1; +#endif /* RT_USING_RTC */ } time_t timegm(struct tm * const t) @@ -294,3 +299,31 @@ time_t timegm(struct tm * const t) i = 60; return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; } + +/* TODO: timezone */ +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + if (tv != RT_NULL) + { + tv->tv_sec = time(RT_NULL); + tv->tv_usec = 0; + return 0; + } + else + { + return -1; + } +} + +/* TODO: timezone */ +int settimeofday(const struct timeval *tv, const struct timezone *tz) +{ + if (tv != RT_NULL) + { + return stime(&tv->tv_sec); + } + else + { + return -1; + } +} -- cgit v1.3.1 From d0c2631b1215af38eb07b24cd25a751640e9c07c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 10:33:12 +0800 Subject: revert time() --- components/libc/compilers/common/time.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 155a04f92f..a67c0497af 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -8,7 +8,7 @@ * 2019-08-21 zhangjun copy from minilibc * 2020-09-07 Meco Man combine gcc armcc iccarm * 2021-02-05 Meco Man add timegm() - * 2021-02-07 Meco Man fixed gettimeofday() time() + * 2021-02-07 Meco Man fixed gettimeofday() * 2021-02-08 Meco Man add settimeofday() stime() */ @@ -177,15 +177,24 @@ time_t time(time_t *t) #endif { time_t time_now = 0; + #ifdef RT_USING_RTC - rt_device_t device; + static rt_device_t device = RT_NULL; + + /* optimization: find rtc device only first. */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } /* read timestamp from RTC device. */ - device = rt_device_find("rtc"); - if (rt_device_open(device, 0) == RT_EOK) + if (device != RT_NULL) { - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); - rt_device_close(device); + if (rt_device_open(device, 0) == RT_EOK) + { + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); + rt_device_close(device); + } } #endif /* RT_USING_RTC */ -- cgit v1.3.1 From 9b428e519fc91204f4be5e91f1436ba6fd63119b Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 10:42:50 +0800 Subject: avoid warning --- components/libc/compilers/common/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index a67c0497af..bd251d99bf 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -329,7 +329,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) { if (tv != RT_NULL) { - return stime(&tv->tv_sec); + return stime((const time_t *)&tv->tv_sec); } else { -- cgit v1.3.1 From 3e9c77efd5aac880e2f5d5db895d50c227dda663 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 10:55:08 +0800 Subject: 优化IAR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index bd251d99bf..bc77aee510 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -18,9 +18,6 @@ #include #endif - -#if !defined (__IAR_SYSTEMS_ICC__) - /* seconds per day */ #define SPD 24*60*60 @@ -155,8 +152,6 @@ char* ctime(const time_t *timep) return asctime(localtime(timep)); } -#endif /* __IAR_SYSTEMS_ICC__ */ - /** * Returns the current time. * -- cgit v1.3.1 From 2645aec2e3b5b805d697b2ec546faeb5157e8d81 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 11:30:49 +0800 Subject: 删除没有用的预编译,在新版的IAR中此已经不需要了 对time函数增加RT_WEAK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index bc77aee510..7e4a98f923 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -160,16 +160,7 @@ char* ctime(const time_t *timep) * @return time_t return timestamp current. * */ -#if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000 /* for IAR 6.2 later Compiler */ -#pragma module_name = "?time" -#if _DLIB_TIME_USES_64 -time_t __time64(time_t *t) -#else -time_t __time32(time_t *t) -#endif -#else /* Keil & GCC */ -time_t time(time_t *t) -#endif +RT_WEAK time_t time(time_t *t) { time_t time_now = 0; -- cgit v1.3.1 From 39ff4b5a97accf4a0c2134b8b7b395482fc785fb Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 11:37:24 +0800 Subject: 修改时区计算公式的错误 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 7e4a98f923..2cea9b75ce 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -101,10 +101,10 @@ struct tm* gmtime(const time_t* t) struct tm* localtime_r(const time_t* t, struct tm* r) { time_t local_tz; - int timezone; + int utc; - timezone = 0 * 3600 * 8; /* GTM: UTC+0 */ - local_tz = *t + timezone; + utc = 3600 * 0; /* GTM: UTC+0 */ + local_tz = *t + utc; return gmtime_r(&local_tz, r); } -- cgit v1.3.1 From 66e2a9424b6d4a46be1bb697fa5acbec46a287a8 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 10 Feb 2021 21:01:16 +0800 Subject: update --- components/libc/compilers/common/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 2cea9b75ce..dc33e0b9e5 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -101,10 +101,10 @@ struct tm* gmtime(const time_t* t) struct tm* localtime_r(const time_t* t, struct tm* r) { time_t local_tz; - int utc; + int utc_plus; - utc = 3600 * 0; /* GTM: UTC+0 */ - local_tz = *t + utc; + utc_plus = 3600 * 0; /* GTM: UTC+0 */ + local_tz = *t + utc_plus; return gmtime_r(&local_tz, r); } -- cgit v1.3.1 From 072dbe57c6da6bafb90128720462dd16e92741cd Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:31:53 +0800 Subject: format & add clear tm_isdst --- components/libc/compilers/common/time.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index dc33e0b9e5..081e27de74 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -88,6 +88,8 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r) ; r->tm_mon = i; r->tm_mday += work - __spm[i]; + + r->tm_isdst = 0; return r; } @@ -103,8 +105,8 @@ struct tm* localtime_r(const time_t* t, struct tm* r) time_t local_tz; int utc_plus; - utc_plus = 3600 * 0; /* GTM: UTC+0 */ - local_tz = *t + utc_plus; + utc_plus = 0; /* GTM: UTC+0 */ + local_tz = *t + utc_plus * 3600; return gmtime_r(&local_tz, r); } -- cgit v1.3.1 From 5e5ceabfdce8638c5ec8b78d4a53aa2ed0046b82 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:32:47 +0800 Subject: add ctime_r() and re-implement ctime() --- components/libc/compilers/common/time.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 081e27de74..ff76fae453 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -10,6 +10,7 @@ * 2021-02-05 Meco Man add timegm() * 2021-02-07 Meco Man fixed gettimeofday() * 2021-02-08 Meco Man add settimeofday() stime() + * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() */ #include @@ -149,9 +150,15 @@ char* asctime(const struct tm *timeptr) return asctime_r(timeptr, buf); } -char* ctime(const time_t *timep) +char *ctime_r (const time_t * tim_p, char * result) { - return asctime(localtime(timep)); + struct tm tm; + return asctime_r (localtime_r (tim_p, &tm), result); +} + +char* ctime(const time_t *tim_p) +{ + return asctime (localtime (tim_p)); } /** -- cgit v1.3.1 From 51cb109cf8386088368469769d14b1d039551dd1 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:33:45 +0800 Subject: fix bug #3183 - align days[] and months[] to 4 bytes --- components/libc/compilers/common/time.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index ff76fae453..68cd7f0837 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -11,6 +11,7 @@ * 2021-02-07 Meco Man fixed gettimeofday() * 2021-02-08 Meco Man add settimeofday() stime() * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() + * 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes */ #include @@ -39,8 +40,9 @@ const short __spm[13] = (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30), (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), }; -static const char days[] = "Sun Mon Tue Wed Thu Fri Sat "; -static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec "; + +ALIGN(4) static const char days[] = "Sun Mon Tue Wed Thu Fri Sat "; +ALIGN(4) static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec "; static int __isleap(int year) { -- cgit v1.3.1 From d67d4d3fd0ae292677cee9cf9a4d2bb5b5eefb1a Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:34:38 +0800 Subject: add difftime() --- components/libc/compilers/common/time.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 68cd7f0837..366bc28bd1 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -12,6 +12,7 @@ * 2021-02-08 Meco Man add settimeofday() stime() * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() * 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes + * add difftime() */ #include @@ -163,6 +164,11 @@ char* ctime(const time_t *tim_p) return asctime (localtime (tim_p)); } +double difftime (time_t tim1, time_t tim2) +{ + return (double)(tim1 - tim2); +} + /** * Returns the current time. * -- cgit v1.3.1 From e3fee1ca77104bbc6d8e5e964b5f44fca7456c49 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:46:23 +0800 Subject: 2 spaces -> 4 spaces --- components/libc/compilers/common/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 366bc28bd1..e1c9340e69 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -155,8 +155,8 @@ char* asctime(const struct tm *timeptr) char *ctime_r (const time_t * tim_p, char * result) { - struct tm tm; - return asctime_r (localtime_r (tim_p, &tm), result); + struct tm tm; + return asctime_r (localtime_r (tim_p, &tm), result); } char* ctime(const time_t *tim_p) -- cgit v1.3.1 From a400991ee9f8edf87a618d621129890a583d8c53 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:58:19 +0800 Subject: remove _gettimeofday_r() and _times_r() --- components/libc/compilers/newlib/syscalls.c | 121 ++-------------------------- 1 file changed, 8 insertions(+), 113 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index 228fa0d140..ad56078367 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -5,7 +5,9 @@ * * Change Logs: * Date Author Notes + * 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r() */ + #include #include #include @@ -190,14 +192,6 @@ _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) #endif } -_CLOCK_T_ -_times_r(struct _reent *ptr, struct tms *ptms) -{ - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - int _unlink_r(struct _reent *ptr, const char *file) { @@ -243,111 +237,6 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) } #endif -#ifdef RT_USING_PTHREADS - -#include -/* POSIX timer provides clock_gettime function */ -#include -int -_gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp) -{ - struct timespec tp; - - if (clock_gettime(CLOCK_REALTIME, &tp) == 0) - { - if (__tp != RT_NULL) - { - __tp->tv_sec = tp.tv_sec; - __tp->tv_usec = tp.tv_nsec / 1000UL; - } - - return tp.tv_sec; - } - - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} - -#else - -#define MILLISECOND_PER_SECOND 1000UL -#define MICROSECOND_PER_SECOND 1000000UL -#define NANOSECOND_PER_SECOND 1000000000UL - -#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND) -#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND) -#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND) - -struct timeval _timevalue = {0}; -#ifdef RT_USING_DEVICE -static void libc_system_time_init(void) -{ - time_t time; - rt_tick_t tick; - rt_device_t device; - - time = 0; - device = rt_device_find("rtc"); - if (device != RT_NULL) - { - /* get realtime seconds */ - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); - } - - /* get tick */ - tick = rt_tick_get(); - - _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; -} -#endif - -int libc_get_time(struct timespec *time) -{ - rt_tick_t tick; - static rt_bool_t inited = 0; - - RT_ASSERT(time != RT_NULL); - - /* initialize system time */ - if (inited == 0) - { - libc_system_time_init(); - inited = 1; - } - - /* get tick */ - tick = rt_tick_get(); - - time->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; - time->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; - - return 0; -} - -int -_gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp) -{ - struct timespec tp; - - if (libc_get_time(&tp) == 0) - { - if (__tp != RT_NULL) - { - __tp->tv_sec = tp.tv_sec; - __tp->tv_usec = tp.tv_nsec / 1000UL; - } - - return tp.tv_sec; - } - - /* return "not supported" */ - ptr->_errno = ENOTSUP; - return -1; -} -#endif - /* Memory routine */ void * _malloc_r (struct _reent *ptr, size_t size) @@ -453,3 +342,9 @@ int flock(int fd, int operation) { return 0; } + +/* +These function will be implemented in the 'common/time.c' file +int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); +_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); +*/ -- cgit v1.3.1 From b4c8cb1445ad2e249473a101133d06478e8c1170 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 03:02:32 +0800 Subject: remove declare --- components/libc/compilers/newlib/libc.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/newlib/libc.h b/components/libc/compilers/newlib/libc.h index fdf2ab4f60..b4f28e44cc 100644 --- a/components/libc/compilers/newlib/libc.h +++ b/components/libc/compilers/newlib/libc.h @@ -34,10 +34,6 @@ int libc_system_init(void); int libc_stdio_set_console(const char* device_name, int mode); int libc_stdio_get_console(void); -/* some time related function */ -int libc_set_time(const struct timespec* time); -int libc_get_time(struct timespec* time); -int libc_time_to_tick(const struct timespec* time); #ifdef __cplusplus } #endif -- cgit v1.3.1 From e904f9bf27d0056ffc53f47e91f39ed9a0b1f11e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 03:03:59 +0800 Subject: update common --- components/libc/compilers/newlib/syscalls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index ad56078367..193080c926 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -344,7 +344,7 @@ int flock(int fd, int operation) } /* -These function will be implemented in the 'common/time.c' file +These functions will be implemented and replaced by the 'common/time.c' file int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); _CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); */ -- cgit v1.3.1 From dd147925e52aa205a09d631984c545f9c99c52c2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 13:41:24 +0800 Subject: fix time() return value --- components/libc/compilers/common/time.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index e1c9340e69..fecae28f9f 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -174,23 +174,24 @@ double difftime (time_t tim1, time_t tim2) * * @param time_t * t the timestamp pointer, if not used, keep NULL. * - * @return time_t return timestamp current. + * @return The value ((time_t)-1) is returned if the calendar time is not available. + * If timer is not a NULL pointer, the return value is also stored in timer. * */ RT_WEAK time_t time(time_t *t) { - time_t time_now = 0; + time_t time_now = ((time_t)-1); /* default is not available */ #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; - /* optimization: find rtc device only first. */ + /* optimization: find rtc device only first */ if (device == RT_NULL) { device = rt_device_find("rtc"); } - /* read timestamp from RTC device. */ + /* read timestamp from RTC device */ if (device != RT_NULL) { if (rt_device_open(device, 0) == RT_EOK) -- cgit v1.3.1 From dbe1a9c2dcc517e0d99ad5cfdfab12a4ebe357d7 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 16:29:14 +0800 Subject: 移除无用的代码 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/newlib/libc.h | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/newlib/libc.h b/components/libc/compilers/newlib/libc.h index b4f28e44cc..9a76ffb79f 100644 --- a/components/libc/compilers/newlib/libc.h +++ b/components/libc/compilers/newlib/libc.h @@ -10,23 +10,10 @@ #ifndef __RTT_LIBC_H__ #define __RTT_LIBC_H__ -#include -#include -#include -#include - #ifndef _EXFUN -#define _EXFUN(name, proto) name proto +#define _EXFUN(name, proto) name proto #endif -#define MILLISECOND_PER_SECOND 1000UL -#define MICROSECOND_PER_SECOND 1000000UL -#define NANOSECOND_PER_SECOND 1000000000UL - -#define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND) -#define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND) -#define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND) - #ifdef __cplusplus extern "C" { #endif -- cgit v1.3.1 From ce4fabe158a9b0367712a4afe904b5d6d7da9f78 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 20:48:30 +0800 Subject: add errno --- components/libc/compilers/common/time.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index fecae28f9f..a980f742fb 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -13,6 +13,7 @@ * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() * 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes * add difftime() + * 2021-02-12 Meco Man add errno */ #include @@ -208,6 +209,11 @@ RT_WEAK time_t time(time_t *t) *t = time_now; } + if(time_now == (time_t)-1) + { + errno = ENOSYS; + } + return time_now; } @@ -230,11 +236,13 @@ int stime(const time_t *t) } else { + errno = ENOSYS; return -1; } return 0; #else + errno = ENOSYS; return -1; #endif /* RT_USING_RTC */ } @@ -316,14 +324,17 @@ time_t timegm(struct tm * const t) /* TODO: timezone */ int gettimeofday(struct timeval *tv, struct timezone *tz) { - if (tv != RT_NULL) + time_t t = time(RT_NULL); + + if (tv != RT_NULL && t != (time_t)-1) { - tv->tv_sec = time(RT_NULL); + tv->tv_sec = t; tv->tv_usec = 0; return 0; } else { + errno = ENOSYS; return -1; } } @@ -337,6 +348,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) } else { + errno = ENOSYS; return -1; } } -- cgit v1.3.1