From cc1277d491979d01cd47072f2ceb099636ca2254 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 15 Mar 2021 11:29:42 +0800 Subject: [libc][time] 修复没有末尾\0的bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index ed72cc1f3f..3ffc6381fc 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -16,6 +16,7 @@ * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, * which found by Rob * 2021-02-12 Meco Man move all of the functions located in to this file + * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html */ #include @@ -152,13 +153,14 @@ char* asctime_r(const struct tm *t, char *buf) num2str(buf + 20, (t->tm_year + 1900) / 100); num2str(buf + 22, (t->tm_year + 1900) % 100); buf[24] = '\n'; + buf[25] = '\0'; return buf; } RTM_EXPORT(asctime_r); char* asctime(const struct tm *timeptr) { - static char buf[25]; + static char buf[26]; return asctime_r(timeptr, buf); } RTM_EXPORT(asctime); -- cgit v1.3.1 From 1b68098f0830ac8c0ebbf69c71e07f12c49ec03a Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Tue, 16 Mar 2021 14:07:36 +0800 Subject: [libc] Fix Win32 compilation errors --- components/libc/compilers/common/sys/time.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 67ef1d2faa..2a40b7b805 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -32,13 +32,15 @@ extern "C" { * Structure returned by gettimeofday(2) system call, * and used in other calls. */ +#if !(defined(_WIN32)) struct timeval { long tv_sec; /* seconds */ long tv_usec; /* and microseconds */ }; +#endif #endif /* _TIMEVAL_DEFINED */ -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)) && !defined (__ICCARM__) +#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)) && !defined (__ICCARM__) && !defined (_WIN32) struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ -- cgit v1.3.1 From 9d17aa7ce5a5c110ba7fdcd8f02ebfc34c021ce1 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 17 Mar 2021 02:37:42 +0800 Subject: [libc][ioctl] 将sys/ioctl.h移至common文件夹 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/sys/ioctl.h | 15 --------------- components/libc/compilers/common/sys/ioctl.h | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) delete mode 100644 components/libc/compilers/armlibc/sys/ioctl.h create mode 100644 components/libc/compilers/common/sys/ioctl.h (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/armlibc/sys/ioctl.h b/components/libc/compilers/armlibc/sys/ioctl.h deleted file mode 100644 index df17b19a61..0000000000 --- a/components/libc/compilers/armlibc/sys/ioctl.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-01 Meco Man First Version - */ -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H - - - -#endif diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h new file mode 100644 index 0000000000..df17b19a61 --- /dev/null +++ b/components/libc/compilers/common/sys/ioctl.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-01 Meco Man First Version + */ +#ifndef _SYS_IOCTL_H +#define _SYS_IOCTL_H + + + +#endif -- cgit v1.3.1 From 0ec2a5f78222a22a242f730ad9b45b763604bae4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 26 Mar 2021 17:36:43 +0800 Subject: [libc][time] add LOG_W to give a warning when RTC device is not used --- components/libc/compilers/common/time.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 083ae9be6c..286a173347 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -21,6 +21,7 @@ #include #include +#include #ifdef RT_USING_DEVICE #include #endif @@ -219,6 +220,7 @@ RT_WEAK time_t time(time_t *t) if(time_now == (time_t)-1) { + LOG_W("Cannot find a RTC device to provide time!"); errno = ENOSYS; } @@ -246,12 +248,13 @@ int stime(const time_t *t) } else { + LOG_W("Cannot find a RTC device to provide time!"); errno = ENOSYS; return -1; } return 0; - #else + LOG_W("Cannot find a RTC device to provide time!"); errno = ENOSYS; return -1; #endif /* RT_USING_RTC */ -- cgit v1.3.1 From a584b8ba6b6f137480e47eead44d40938e8e6774 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 28 Mar 2021 10:32:20 +0800 Subject: [libc][time] add debug tag --- components/libc/compilers/common/time.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 286a173347..83b6ed5672 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -21,11 +21,15 @@ #include #include -#include + #ifdef RT_USING_DEVICE #include #endif +#define DBG_TAG "TIME" +#define DBG_LVL DBG_INFO +#include + /* seconds per day */ #define SPD 24*60*60 -- cgit v1.3.1 From b4040df9dca12574c7cc8fd37a655e811d1337da Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 11 Apr 2021 13:31:11 +0800 Subject: [libc][time][bug] LOG_W will cause a recursive printing if ulog timestamp function is turned on --- components/libc/compilers/common/time.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 83b6ed5672..72aa8a42f4 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -224,7 +224,8 @@ RT_WEAK time_t time(time_t *t) if(time_now == (time_t)-1) { - LOG_W("Cannot find a RTC device to provide time!"); + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); errno = ENOSYS; } -- cgit v1.3.1 From 76be91c7dec45bd33e149bb059880caf2f838934 Mon Sep 17 00:00:00 2001 From: armink Date: Wed, 14 Apr 2021 20:10:47 +0800 Subject: [libc/time] Add microseconds time get feature in gettimeofday. --- components/libc/compilers/common/time.c | 59 +++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 25 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 72aa8a42f4..dcfc4b9776 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -120,7 +120,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r) time_t local_tz; int utc_plus; - utc_plus = 0; /* GTM: UTC+0 */ + utc_plus = 8; /* GMT: UTC+8 */ local_tz = *t + utc_plus * 3600; return gmtime_r(&local_tz, r); } @@ -183,18 +183,14 @@ char* ctime(const time_t *tim_p) } RTM_EXPORT(ctime); -/** - * Returns the current time. - * - * @param time_t * t the timestamp pointer, if not used, keep NULL. - * - * @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) +static void get_timeval(struct timeval *tv) { - time_t time_now = ((time_t)-1); /* default is not available */ + if (tv == RT_NULL) + return; + /* default is not available */ + tv->tv_sec = -1; + /* default is 0 */ + tv->tv_usec = 0; #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; @@ -210,26 +206,41 @@ RT_WEAK time_t time(time_t *t) { if (rt_device_open(device, 0) == RT_EOK) { - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); rt_device_close(device); } } #endif /* RT_USING_RTC */ - /* if t is not NULL, write timestamp to *t */ - if (t != RT_NULL) - { - *t = time_now; - } - - if(time_now == (time_t)-1) + if (tv->tv_sec == (time_t) -1) { /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ rt_kprintf("Cannot find a RTC device to provide time!\r\n"); errno = ENOSYS; } +} - return time_now; +/** + * Returns the current time. + * + * @param time_t * t the timestamp pointer, if not used, keep NULL. + * + * @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) +{ + struct timeval now; + + get_timeval(&now); + + if (t) + { + *t = now.tv_sec; + } + return now.tv_sec; } RTM_EXPORT(time); @@ -344,12 +355,10 @@ RTM_EXPORT(timegm); /* TODO: timezone */ int gettimeofday(struct timeval *tv, struct timezone *tz) { - time_t t = time(RT_NULL); + get_timeval(tv); - if (tv != RT_NULL && t != (time_t)-1) + if (tv != RT_NULL && tv->tv_sec != (time_t) -1) { - tv->tv_sec = t; - tv->tv_usec = 0; return 0; } else -- cgit v1.3.1 From 4accfc410c34147f48e9d8cca486c8b0a2f51aeb Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 15 Apr 2021 00:57:01 +0800 Subject: 修改get_timeval的错误返回形式 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 49 ++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index dcfc4b9776..c2a3c8fcbf 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -183,10 +183,12 @@ char* ctime(const time_t *tim_p) } RTM_EXPORT(ctime); -static void get_timeval(struct timeval *tv) +/*-1 failure; 1 success*/ +static int get_timeval(struct timeval *tv) { if (tv == RT_NULL) - return; + return -1; + /* default is not available */ tv->tv_sec = -1; /* default is 0 */ @@ -217,8 +219,11 @@ static void get_timeval(struct timeval *tv) { /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - errno = ENOSYS; + tv->tv_sec = 0; + return -1; } + + return 1; } /** @@ -234,13 +239,19 @@ RT_WEAK time_t time(time_t *t) { struct timeval now; - get_timeval(&now); - - if (t) + if(get_timeval(&now)>0) { - *t = now.tv_sec; + if (t) + { + *t = now.tv_sec; + } + return now.tv_sec; + } + else + { + errno = EFAULT; + return -1; } - return now.tv_sec; } RTM_EXPORT(time); @@ -265,13 +276,13 @@ int stime(const time_t *t) else { LOG_W("Cannot find a RTC device to provide time!"); - errno = ENOSYS; + errno = EFAULT; return -1; } return 0; #else LOG_W("Cannot find a RTC device to provide time!"); - errno = ENOSYS; + errno = EFAULT; return -1; #endif /* RT_USING_RTC */ } @@ -355,15 +366,13 @@ RTM_EXPORT(timegm); /* TODO: timezone */ int gettimeofday(struct timeval *tv, struct timezone *tz) { - get_timeval(tv); - - if (tv != RT_NULL && tv->tv_sec != (time_t) -1) + if (tv != RT_NULL && get_timeval(tv)>0) { return 0; } else { - errno = ENOSYS; + errno = EFAULT; return -1; } } @@ -374,11 +383,19 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) { if (tv != RT_NULL) { - return stime((const time_t *)&tv->tv_sec); + if(tv->tv_sec >= 0 && tv->tv_usec >= 0) + { + return stime((const time_t *)&tv->tv_sec); + } + else + { + errno = EINVAL; + return -1; + } } else { - errno = ENOSYS; + errno = EFAULT; return -1; } } -- cgit v1.3.1 From 8e2a456d7a1ffff4a35ba9f4c5a199eac14e132e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 15 Apr 2021 14:01:55 +0800 Subject: implement set_timeval --- components/libc/compilers/common/sys/time.h | 5 +- components/libc/compilers/common/time.c | 179 ++++++++++++++++++---------- include/rtdef.h | 8 +- 3 files changed, 127 insertions(+), 65 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 2a40b7b805..ef1c810608 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -40,7 +40,7 @@ struct timeval { #endif #endif /* _TIMEVAL_DEFINED */ -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)) && !defined (__ICCARM__) && !defined (_WIN32) +#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !defined (__ICCARM__) && !defined (_WIN32) struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ @@ -56,6 +56,9 @@ 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); +#if defined(__ARMCC_VERSION) || defined (__ICCARM__) +struct tm *gmtime_r(const time_t *timep, struct tm *r); +#endif #ifdef RT_USING_POSIX #include diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index c2a3c8fcbf..75adb817da 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -68,6 +68,104 @@ static void num2str(char *c, int i) c[1] = i % 10 + '0'; } +/** + * Get time from RTC device (without timezone) + * @param tv: struct timeval + * @return -1 failure; 1 success + */ +static int get_timeval(struct timeval *tv) +{ +#ifdef RT_USING_RTC + static rt_device_t device = RT_NULL; +#endif + rt_err_t rst = -RT_ERROR; + + if (tv == RT_NULL) + return -1; + + /* default is 0 */ + tv->tv_sec = 0; + tv->tv_usec = 0; + +#ifdef RT_USING_RTC + /* optimization: find rtc device only first */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } + + /* read timestamp from RTC device */ + if (device != RT_NULL) + { + if (rt_device_open(device, 0) == RT_EOK) + { + rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); + rt_device_close(device); + } + } + else + { + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + return -1; + } + + return (rst < 0) ? -1 : 1; + +#else + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + return -1; +#endif /* RT_USING_RTC */ +} + +/** + * Set time to RTC device (without timezone) + * @param tv: struct timeval + * @return -1 failure; 1 success + */ +static int set_timeval(struct timeval *tv) +{ + rt_err_t rst = -RT_ERROR; +#ifdef RT_USING_RTC + static rt_device_t device = RT_NULL; +#endif + + if (tv == RT_NULL) + return -1; + +#ifdef RT_USING_RTC + /* optimization: find rtc device only first */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } + + /* read timestamp from RTC device */ + if (device != RT_NULL) + { + if (rt_device_open(device, 0) == RT_EOK) + { + rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec); + rt_device_close(device); + } + } + else + { + LOG_W("Cannot find a RTC device to provide time!"); + return -1; + } + + return (rst < 0) ? -1 : 1; + +#else + LOG_W("Cannot find a RTC device to provide time!"); + return -1; +#endif /* RT_USING_RTC */ +} + struct tm *gmtime_r(const time_t *timep, struct tm *r) { time_t i; @@ -183,49 +281,6 @@ char* ctime(const time_t *tim_p) } RTM_EXPORT(ctime); -/*-1 failure; 1 success*/ -static int get_timeval(struct timeval *tv) -{ - if (tv == RT_NULL) - return -1; - - /* default is not available */ - tv->tv_sec = -1; - /* default is 0 */ - tv->tv_usec = 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"); - } - - /* read timestamp from RTC device */ - if (device != RT_NULL) - { - if (rt_device_open(device, 0) == RT_EOK) - { - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); - rt_device_close(device); - } - } -#endif /* RT_USING_RTC */ - - if (tv->tv_sec == (time_t) -1) - { - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - tv->tv_sec = 0; - return -1; - } - - return 1; -} - /** * Returns the current time. * @@ -239,7 +294,7 @@ RT_WEAK time_t time(time_t *t) { struct timeval now; - if(get_timeval(&now)>0) + if(get_timeval(&now) > 0) { if (t) { @@ -263,28 +318,24 @@ RTM_EXPORT(clock); int stime(const time_t *t) { -#ifdef RT_USING_RTC - rt_device_t device; + struct timeval tv; - /* read timestamp from RTC device. */ - device = rt_device_find("rtc"); - if (rt_device_open(device, 0) == RT_EOK) + if (!t) + { + errno = EFAULT; + return -1; + } + + tv.tv_sec = *t; + if (set_timeval(&tv) > 0) { - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, (void*)t); - rt_device_close(device); + return 0; } else { - LOG_W("Cannot find a RTC device to provide time!"); errno = EFAULT; return -1; } - return 0; -#else - LOG_W("Cannot find a RTC device to provide time!"); - errno = EFAULT; - return -1; -#endif /* RT_USING_RTC */ } RTM_EXPORT(stime); @@ -366,7 +417,7 @@ RTM_EXPORT(timegm); /* TODO: timezone */ int gettimeofday(struct timeval *tv, struct timezone *tz) { - if (tv != RT_NULL && get_timeval(tv)>0) + if (tv != RT_NULL && get_timeval(tv) > 0) { return 0; } @@ -385,7 +436,15 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) { if(tv->tv_sec >= 0 && tv->tv_usec >= 0) { - return stime((const time_t *)&tv->tv_sec); + if(set_timeval((struct timeval *)tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } } else { diff --git a/include/rtdef.h b/include/rtdef.h index aba8a6f12d..111ac4a12c 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -964,10 +964,10 @@ enum rt_device_class_type #define RT_DEVICE_CTRL_MTD_FORMAT 0x10 /**< format a MTD device */ #define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get second time */ #define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set second time */ -#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x12 /**< get alarm */ -#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x13 /**< set alarm */ -#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x14 /**< get microsecond time */ -#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x15 /**< set microsecond time */ +#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x12 /**< get microsecond time */ +#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x13 /**< set microsecond time */ +#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x14 /**< get alarm */ +#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x15 /**< set alarm */ typedef struct rt_device *rt_device_t; -- cgit v1.3.1 From b74022e2c4274698aa26a18cbd6df72842f8ac38 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 15 Apr 2021 14:31:23 +0800 Subject: mktime support fixed timezone --- components/libc/compilers/common/time.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 75adb817da..638735b77c 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -234,7 +234,13 @@ RTM_EXPORT(localtime); /* TODO: timezone */ time_t mktime(struct tm * const t) { - return timegm(t); + time_t timestamp; + int utc_plus; + + utc_plus = 8; /* GMT: UTC+8 */ + timestamp = timegm(t); + timestamp = timestamp - 3600 * utc_plus; + return timestamp; } RTM_EXPORT(mktime); -- cgit v1.3.1 From 46d51a99f1b92738a2955245527ad8e18bcf96a5 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 15 Apr 2021 16:34:09 +0800 Subject: 优化get_timeval set_timeval 条件编译代码结构 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 638735b77c..33d8907165 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -77,7 +77,6 @@ static int get_timeval(struct timeval *tv) { #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; -#endif rt_err_t rst = -RT_ERROR; if (tv == RT_NULL) @@ -87,7 +86,6 @@ static int get_timeval(struct timeval *tv) tv->tv_sec = 0; tv->tv_usec = 0; -#ifdef RT_USING_RTC /* optimization: find rtc device only first */ if (device == RT_NULL) { @@ -127,15 +125,13 @@ static int get_timeval(struct timeval *tv) */ static int set_timeval(struct timeval *tv) { - rt_err_t rst = -RT_ERROR; #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; -#endif + rt_err_t rst = -RT_ERROR; if (tv == RT_NULL) return -1; -#ifdef RT_USING_RTC /* optimization: find rtc device only first */ if (device == RT_NULL) { @@ -311,7 +307,7 @@ RT_WEAK time_t time(time_t *t) else { errno = EFAULT; - return -1; + return ((time_t)-1); } } RTM_EXPORT(time); -- cgit v1.3.1 From 9d401ea8b06518a49b59b6d246325afa5902e3f4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 18 Apr 2021 00:51:07 +0800 Subject: 重新整理libc重复共用文件,创建common_for_all 和 common_for_keiliar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/dirent.h | 62 -- components/libc/compilers/armlibc/fcntl.h | 18 - components/libc/compilers/armlibc/sys/mman.h | 58 -- components/libc/compilers/armlibc/sys/stat.h | 8 - components/libc/compilers/armlibc/sys/types.h | 34 -- components/libc/compilers/armlibc/sys/unistd.h | 83 --- components/libc/compilers/armlibc/unistd.h | 10 - components/libc/compilers/common/SConscript | 27 - components/libc/compilers/common/readme.md | 10 - components/libc/compilers/common/stdlib.c | 28 - components/libc/compilers/common/sys/ioctl.h | 15 - components/libc/compilers/common/sys/time.h | 101 ---- components/libc/compilers/common/termios.h | 19 - components/libc/compilers/common/time.c | 643 --------------------- components/libc/compilers/common/unistd.c | 88 --- components/libc/compilers/common_all/SConscript | 27 + components/libc/compilers/common_all/dirent.h | 65 +++ components/libc/compilers/common_all/readme.md | 10 + components/libc/compilers/common_all/stdlib.c | 28 + components/libc/compilers/common_all/sys/ioctl.h | 18 + components/libc/compilers/common_all/sys/mman.h | 60 ++ components/libc/compilers/common_all/sys/statfs.h | 21 + components/libc/compilers/common_all/sys/termios.h | 8 + components/libc/compilers/common_all/sys/time.h | 101 ++++ components/libc/compilers/common_all/termios.h | 19 + components/libc/compilers/common_all/time.c | 643 +++++++++++++++++++++ components/libc/compilers/common_all/unistd.c | 88 +++ .../libc/compilers/common_except_gcc/SConscript | 13 + .../libc/compilers/common_except_gcc/fcntl.h | 18 + .../libc/compilers/common_except_gcc/sys/stat.h | 8 + .../libc/compilers/common_except_gcc/sys/types.h | 36 ++ .../libc/compilers/common_except_gcc/sys/unistd.h | 83 +++ .../libc/compilers/common_except_gcc/unistd.h | 10 + components/libc/compilers/dlib/dirent.h | 62 -- components/libc/compilers/dlib/fcntl.h | 8 - components/libc/compilers/dlib/sys/mman.h | 58 -- components/libc/compilers/dlib/sys/stat.h | 8 - components/libc/compilers/dlib/sys/types.h | 33 -- components/libc/compilers/dlib/sys/unistd.h | 57 -- components/libc/compilers/dlib/unistd.h | 14 - components/libc/compilers/newlib/sys/dirent.h | 65 --- components/libc/compilers/newlib/sys/mman.h | 58 -- components/libc/compilers/newlib/sys/statfs.h | 21 - components/libc/compilers/newlib/sys/termios.h | 8 - include/rtlibc.h | 5 - 45 files changed, 1256 insertions(+), 1601 deletions(-) delete mode 100644 components/libc/compilers/armlibc/dirent.h delete mode 100644 components/libc/compilers/armlibc/fcntl.h delete mode 100644 components/libc/compilers/armlibc/sys/mman.h delete mode 100644 components/libc/compilers/armlibc/sys/stat.h delete mode 100644 components/libc/compilers/armlibc/sys/types.h delete mode 100644 components/libc/compilers/armlibc/sys/unistd.h delete mode 100644 components/libc/compilers/armlibc/unistd.h delete mode 100644 components/libc/compilers/common/SConscript delete mode 100644 components/libc/compilers/common/readme.md delete mode 100644 components/libc/compilers/common/stdlib.c delete mode 100644 components/libc/compilers/common/sys/ioctl.h delete mode 100644 components/libc/compilers/common/sys/time.h delete mode 100644 components/libc/compilers/common/termios.h delete mode 100644 components/libc/compilers/common/time.c delete mode 100644 components/libc/compilers/common/unistd.c create mode 100644 components/libc/compilers/common_all/SConscript create mode 100644 components/libc/compilers/common_all/dirent.h create mode 100644 components/libc/compilers/common_all/readme.md create mode 100644 components/libc/compilers/common_all/stdlib.c create mode 100644 components/libc/compilers/common_all/sys/ioctl.h create mode 100644 components/libc/compilers/common_all/sys/mman.h create mode 100644 components/libc/compilers/common_all/sys/statfs.h create mode 100644 components/libc/compilers/common_all/sys/termios.h create mode 100644 components/libc/compilers/common_all/sys/time.h create mode 100644 components/libc/compilers/common_all/termios.h create mode 100644 components/libc/compilers/common_all/time.c create mode 100644 components/libc/compilers/common_all/unistd.c create mode 100644 components/libc/compilers/common_except_gcc/SConscript create mode 100644 components/libc/compilers/common_except_gcc/fcntl.h create mode 100644 components/libc/compilers/common_except_gcc/sys/stat.h create mode 100644 components/libc/compilers/common_except_gcc/sys/types.h create mode 100644 components/libc/compilers/common_except_gcc/sys/unistd.h create mode 100644 components/libc/compilers/common_except_gcc/unistd.h delete mode 100644 components/libc/compilers/dlib/dirent.h delete mode 100644 components/libc/compilers/dlib/fcntl.h delete mode 100644 components/libc/compilers/dlib/sys/mman.h delete mode 100644 components/libc/compilers/dlib/sys/stat.h delete mode 100644 components/libc/compilers/dlib/sys/types.h delete mode 100644 components/libc/compilers/dlib/sys/unistd.h delete mode 100644 components/libc/compilers/dlib/unistd.h delete mode 100644 components/libc/compilers/newlib/sys/dirent.h delete mode 100644 components/libc/compilers/newlib/sys/mman.h delete mode 100644 components/libc/compilers/newlib/sys/statfs.h delete mode 100644 components/libc/compilers/newlib/sys/termios.h (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/armlibc/dirent.h b/components/libc/compilers/armlibc/dirent.h deleted file mode 100644 index 2c0521d2e3..0000000000 --- a/components/libc/compilers/armlibc/dirent.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __RTT_DIRENT_H__ -#define __RTT_DIRENT_H__ - -#include -#include - -/* -* dirent.h - format of directory entries - * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html - */ - -/* File types */ -#define FT_REGULAR 0 /* regular file */ -#define FT_SOCKET 1 /* socket file */ -#define FT_DIRECTORY 2 /* directory */ -#define FT_USER 3 /* user defined */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef HAVE_DIR_STRUCTURE -typedef struct -{ - int fd; /* directory file */ - char buf[512]; - int num; - int cur; -} DIR; -#endif - -#ifndef HAVE_DIRENT_STRUCTURE -struct dirent -{ - rt_uint8_t d_type; /* The type of the file */ - rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ - rt_uint16_t d_reclen; /* length of this record */ - char d_name[256]; /* The null-terminated file name */ -}; -#endif - -int closedir(DIR *); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); -void rewinddir(DIR *); -void seekdir(DIR *, long int); -long telldir(DIR *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/armlibc/fcntl.h b/components/libc/compilers/armlibc/fcntl.h deleted file mode 100644 index f247b926e9..0000000000 --- a/components/libc/compilers/armlibc/fcntl.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef FCNTL_H__ -#define FCNTL_H__ - -#include - -#ifdef RT_USING_DFS -#include -#endif - -#endif diff --git a/components/libc/compilers/armlibc/sys/mman.h b/components/libc/compilers/armlibc/sys/mman.h deleted file mode 100644 index 6a260ccd70..0000000000 --- a/components/libc/compilers/armlibc/sys/mman.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/11/30 Bernard The first version. - */ - -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAP_FAILED ((void *) -1) - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_TYPE 0x0f -#define MAP_FIXED 0x10 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_NORESERVE 0x4000 -#define MAP_GROWSDOWN 0x0100 -#define MAP_DENYWRITE 0x0800 -#define MAP_EXECUTABLE 0x1000 -#define MAP_LOCKED 0x2000 -#define MAP_POPULATE 0x8000 -#define MAP_NONBLOCK 0x10000 -#define MAP_STACK 0x20000 -#define MAP_HUGETLB 0x40000 -#define MAP_FILE 0 - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 -#define MCL_ONFAULT 4 - -void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off); -int munmap (void *start, size_t len); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/components/libc/compilers/armlibc/sys/stat.h b/components/libc/compilers/armlibc/sys/stat.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/armlibc/sys/stat.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/components/libc/compilers/armlibc/sys/types.h b/components/libc/compilers/armlibc/sys/types.h deleted file mode 100644 index a6b245b81c..0000000000 --- a/components/libc/compilers/armlibc/sys/types.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-05 Meco Man fix bugs - * 2020-12-16 Meco Man add useconds_t - */ -#ifndef __TYPES_H__ -#define __TYPES_H__ - -#include - -typedef int32_t clockid_t; -typedef int32_t key_t; /* Used for interprocess communication. */ -typedef int pid_t; /* Used for process IDs and process group IDs. */ -typedef unsigned short uid_t; -typedef unsigned short gid_t; -#ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#endif -typedef unsigned long useconds_t; /* microseconds (unsigned) */ - -typedef unsigned long dev_t; - -typedef unsigned int u_int; -typedef unsigned char u_char; -typedef unsigned long u_long; - -#endif diff --git a/components/libc/compilers/armlibc/sys/unistd.h b/components/libc/compilers/armlibc/sys/unistd.h deleted file mode 100644 index 7752a1caf7..0000000000 --- a/components/libc/compilers/armlibc/sys/unistd.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-12-16 Meco Man add usleep - */ -#ifndef _SYS_UNISTD_H -#define _SYS_UNISTD_H - -#include -#include "types.h" - -#ifdef RT_USING_DFS - -#define STDIN_FILENO 0 /* standard input file descriptor */ -#define STDOUT_FILENO 1 /* standard output file descriptor */ -#define STDERR_FILENO 2 /* standard error file descriptor */ - -#include -#else -#define _FREAD 0x0001 /* read enabled */ -#define _FWRITE 0x0002 /* write enabled */ -#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ -#define _FMARK 0x0010 /* internal; mark during gc() */ -#define _FDEFER 0x0020 /* internal; defer for next gc pass */ -#define _FASYNC 0x0040 /* signal pgrp when data ready */ -#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ -#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ -#define _FCREAT 0x0200 /* open with file create */ -#define _FTRUNC 0x0400 /* open with truncation */ -#define _FEXCL 0x0800 /* error on open if file exists */ -#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ -#define _FSYNC 0x2000 /* do all writes synchronously */ -#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ -#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ -#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ - - -#ifndef O_RDONLY -#define O_RDONLY 0 /* +1 == FREAD */ -#endif -#ifndef O_WRONLY -#define O_WRONLY 1 /* +1 == FWRITE */ -#endif -#ifndef O_RDWR -#define O_RDWR 2 /* +1 == FREAD|FWRITE */ -#endif -#ifndef O_APPEND -#define O_APPEND _FAPPEND -#endif -#ifndef O_CREAT -#define O_CREAT _FCREAT -#endif -#ifndef O_TRUNC -#define O_TRUNC _FTRUNC -#endif -#ifndef O_EXCL -#define O_EXCL _FEXCL -#endif -#ifndef O_SYNC -#define O_SYNC _FSYNC -#endif - -#endif - - -int isatty (int fd); -char * ttyname (int desc); - -unsigned int sleep(unsigned int seconds); -int usleep(useconds_t usec); - -pid_t getpid(void); -pid_t getppid(void); -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); - -#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/armlibc/unistd.h b/components/libc/compilers/armlibc/unistd.h deleted file mode 100644 index cd77a12e3b..0000000000 --- a/components/libc/compilers/armlibc/unistd.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#include "sys/unistd.h" - diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript deleted file mode 100644 index 319e1a3555..0000000000 --- a/components/libc/compilers/common/SConscript +++ /dev/null @@ -1,27 +0,0 @@ -from building import * - -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -group = [] -CPPPATH = [cwd] - -if GetDepend('RT_USING_LIBC'): - src += Glob('*.c') -else: - if GetDepend('RT_LIBC_USING_TIME'): - src += ['time.c'] - -if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) - -if rtconfig.CROSS_TOOL == 'keil': - CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND'] -else: - CPPDEFINES = [] - -if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): - group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) - -Return('group') diff --git a/components/libc/compilers/common/readme.md b/components/libc/compilers/common/readme.md deleted file mode 100644 index 81bb005d0a..0000000000 --- a/components/libc/compilers/common/readme.md +++ /dev/null @@ -1,10 +0,0 @@ -## Attentions - -1. This folder is "common" for armlibc newlibc and dlib. - -2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg: - -```python -if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) -``` \ No newline at end of file diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c deleted file mode 100644 index 9d8952e99e..0000000000 --- a/components/libc/compilers/common/stdlib.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-02-15 Meco Man first version - */ - -#include - -void __rt_libc_exit(int status) -{ - rt_thread_t self = rt_thread_self(); - - if (self != RT_NULL) - { - rt_kprintf("thread:%s exit:%d!\n", self->name, status); - rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL); - } -} - -int __rt_libc_system(const char *string) -{ - /* TODO */ - return 0; -} diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h deleted file mode 100644 index df17b19a61..0000000000 --- a/components/libc/compilers/common/sys/ioctl.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-01 Meco Man First Version - */ -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H - - - -#endif diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h deleted file mode 100644 index ef1c810608..0000000000 --- a/components/libc/compilers/common/sys/time.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-07 Meco Man combine gcc armcc iccarm - * 2021-02-12 Meco Man move all definitions located in to this file - */ -#ifndef _SYS_TIME_H_ -#define _SYS_TIME_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001. - */ -#if defined ( __ICCARM__ ) && (__VER__ >= 8010001) -#define _TIMESPEC_DEFINED -#endif - - -#ifndef _TIMEVAL_DEFINED -#define _TIMEVAL_DEFINED -/* - * Structure returned by gettimeofday(2) system call, - * and used in other calls. - */ -#if !(defined(_WIN32)) -struct timeval { - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; -#endif -#endif /* _TIMEVAL_DEFINED */ - -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !defined (__ICCARM__) && !defined (_WIN32) -struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* and nanoseconds */ -}; -#endif - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - -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); -#if defined(__ARMCC_VERSION) || defined (__ICCARM__) -struct tm *gmtime_r(const time_t *timep, struct tm *r); -#endif - -#ifdef RT_USING_POSIX -#include -/* posix clock and timer */ -#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) - -#ifndef CLOCK_REALTIME -#define CLOCK_REALTIME 1 -#endif - -#define CLOCK_CPUTIME_ID 2 - -#ifndef CLOCK_PROCESS_CPUTIME_ID -#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID -#endif -#ifndef CLOCK_THREAD_CPUTIME_ID -#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID -#endif - -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC 4 -#endif - -int clock_getres (clockid_t clockid, struct timespec *res); -int clock_gettime (clockid_t clockid, struct timespec *tp); -int clock_settime (clockid_t clockid, const struct timespec *tp); -int clock_time_to_tick(const struct timespec *time); -#endif /* RT_USING_POSIX */ - -#ifdef __cplusplus -} -#endif - -#endif /* _SYS_TIME_H_ */ diff --git a/components/libc/compilers/common/termios.h b/components/libc/compilers/common/termios.h deleted file mode 100644 index 2960d52c58..0000000000 --- a/components/libc/compilers/common/termios.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef _TERMIOS_H__ -#define _TERMIOS_H__ - -#include - -#ifdef RT_USING_POSIX_TERMIOS -#include -#include -#endif - -#endif diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c deleted file mode 100644 index 33d8907165..0000000000 --- a/components/libc/compilers/common/time.c +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 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() - * 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 - * 2021-02-12 Meco Man add errno - * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, - * which found by Rob - * 2021-02-12 Meco Man move all of the functions located in to this file - * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html - */ - -#include -#include - -#ifdef RT_USING_DEVICE -#include -#endif - -#define DBG_TAG "TIME" -#define DBG_LVL DBG_INFO -#include - -/* seconds per day */ -#define SPD 24*60*60 - -/* days per month -- nonleap! */ -static const short __spm[13] = -{ - 0, - (31), - (31 + 28), - (31 + 28 + 31), - (31 + 28 + 31 + 30), - (31 + 28 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), -}; - -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) -{ - /* every fourth year is a leap year except for century years that are - * not divisible by 400. */ - /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */ - return (!(year % 4) && ((year % 100) || !(year % 400))); -} - -static void num2str(char *c, int i) -{ - c[0] = i / 10 + '0'; - c[1] = i % 10 + '0'; -} - -/** - * Get time from RTC device (without timezone) - * @param tv: struct timeval - * @return -1 failure; 1 success - */ -static int get_timeval(struct timeval *tv) -{ -#ifdef RT_USING_RTC - static rt_device_t device = RT_NULL; - rt_err_t rst = -RT_ERROR; - - if (tv == RT_NULL) - return -1; - - /* default is 0 */ - tv->tv_sec = 0; - tv->tv_usec = 0; - - /* optimization: find rtc device only first */ - if (device == RT_NULL) - { - device = rt_device_find("rtc"); - } - - /* read timestamp from RTC device */ - if (device != RT_NULL) - { - if (rt_device_open(device, 0) == RT_EOK) - { - rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); - rt_device_close(device); - } - } - else - { - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - return -1; - } - - return (rst < 0) ? -1 : 1; - -#else - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - return -1; -#endif /* RT_USING_RTC */ -} - -/** - * Set time to RTC device (without timezone) - * @param tv: struct timeval - * @return -1 failure; 1 success - */ -static int set_timeval(struct timeval *tv) -{ -#ifdef RT_USING_RTC - static rt_device_t device = RT_NULL; - rt_err_t rst = -RT_ERROR; - - if (tv == RT_NULL) - return -1; - - /* optimization: find rtc device only first */ - if (device == RT_NULL) - { - device = rt_device_find("rtc"); - } - - /* read timestamp from RTC device */ - if (device != RT_NULL) - { - if (rt_device_open(device, 0) == RT_EOK) - { - rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec); - rt_device_close(device); - } - } - else - { - LOG_W("Cannot find a RTC device to provide time!"); - return -1; - } - - return (rst < 0) ? -1 : 1; - -#else - LOG_W("Cannot find a RTC device to provide time!"); - return -1; -#endif /* RT_USING_RTC */ -} - -struct tm *gmtime_r(const time_t *timep, struct tm *r) -{ - time_t i; - register time_t work = *timep % (SPD); - r->tm_sec = work % 60; - work /= 60; - r->tm_min = work % 60; - r->tm_hour = work / 60; - work = *timep / (SPD); - r->tm_wday = (4 + work) % 7; - for (i = 1970;; ++i) - { - register time_t k = __isleap(i) ? 366 : 365; - if (work >= k) - work -= k; - else - break; - } - r->tm_year = i - 1900; - r->tm_yday = work; - - r->tm_mday = 1; - if (__isleap(i) && (work > 58)) - { - if (work == 59) - r->tm_mday = 2; /* 29.2. */ - work -= 1; - } - - for (i = 11; i && (__spm[i] > work); --i) - ; - r->tm_mon = i; - r->tm_mday += work - __spm[i]; - - r->tm_isdst = 0; - return r; -} -RTM_EXPORT(gmtime_r); - -struct tm* gmtime(const time_t* t) -{ - static struct tm tmp; - return gmtime_r(t, &tmp); -} -RTM_EXPORT(gmtime); - -/*TODO: timezone */ -struct tm* localtime_r(const time_t* t, struct tm* r) -{ - time_t local_tz; - int utc_plus; - - utc_plus = 8; /* GMT: UTC+8 */ - local_tz = *t + utc_plus * 3600; - return gmtime_r(&local_tz, r); -} -RTM_EXPORT(localtime_r); - -struct tm* localtime(const time_t* t) -{ - static struct tm tmp; - return localtime_r(t, &tmp); -} -RTM_EXPORT(localtime); - -/* TODO: timezone */ -time_t mktime(struct tm * const t) -{ - time_t timestamp; - int utc_plus; - - utc_plus = 8; /* GMT: UTC+8 */ - timestamp = timegm(t); - timestamp = timestamp - 3600 * utc_plus; - return timestamp; -} -RTM_EXPORT(mktime); - -char* asctime_r(const struct tm *t, char *buf) -{ - /* "Wed Jun 30 21:49:08 1993\n" */ - *(int*) buf = *(int*) (days + (t->tm_wday << 2)); - *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); - num2str(buf + 8, t->tm_mday); - if (buf[8] == '0') - buf[8] = ' '; - buf[10] = ' '; - num2str(buf + 11, t->tm_hour); - buf[13] = ':'; - num2str(buf + 14, t->tm_min); - buf[16] = ':'; - num2str(buf + 17, t->tm_sec); - buf[19] = ' '; - num2str(buf + 20, (t->tm_year + 1900) / 100); - num2str(buf + 22, (t->tm_year + 1900) % 100); - buf[24] = '\n'; - buf[25] = '\0'; - return buf; -} -RTM_EXPORT(asctime_r); - -char* asctime(const struct tm *timeptr) -{ - static char buf[26]; - return asctime_r(timeptr, buf); -} -RTM_EXPORT(asctime); - -char *ctime_r (const time_t * tim_p, char * result) -{ - struct tm tm; - return asctime_r (localtime_r (tim_p, &tm), result); -} -RTM_EXPORT(ctime_r); - -char* ctime(const time_t *tim_p) -{ - return asctime (localtime (tim_p)); -} -RTM_EXPORT(ctime); - -/** - * Returns the current time. - * - * @param time_t * t the timestamp pointer, if not used, keep NULL. - * - * @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) -{ - struct timeval now; - - if(get_timeval(&now) > 0) - { - if (t) - { - *t = now.tv_sec; - } - return now.tv_sec; - } - else - { - errno = EFAULT; - return ((time_t)-1); - } -} -RTM_EXPORT(time); - -RT_WEAK clock_t clock(void) -{ - return rt_tick_get(); -} -RTM_EXPORT(clock); - -int stime(const time_t *t) -{ - struct timeval tv; - - if (!t) - { - errno = EFAULT; - return -1; - } - - tv.tv_sec = *t; - if (set_timeval(&tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(stime); - -time_t timegm(struct tm * const t) -{ - register time_t day; - register time_t i; - register time_t years = t->tm_year - 70; - - if (t->tm_sec > 60) - { - t->tm_min += t->tm_sec / 60; - t->tm_sec %= 60; - } - if (t->tm_min > 60) - { - t->tm_hour += t->tm_min / 60; - t->tm_min %= 60; - } - if (t->tm_hour > 24) - { - t->tm_mday += t->tm_hour / 24; - t->tm_hour %= 24; - } - if (t->tm_mon > 12) - { - t->tm_year += t->tm_mon / 12; - t->tm_mon %= 12; - } - while (t->tm_mday > __spm[1 + t->tm_mon]) - { - if (t->tm_mon == 1 && __isleap(t->tm_year + 1900)) - { - --t->tm_mday; - } - t->tm_mday -= __spm[t->tm_mon]; - ++t->tm_mon; - if (t->tm_mon > 11) - { - t->tm_mon = 0; - ++t->tm_year; - } - } - - if (t->tm_year < 70) - return (time_t) - 1; - - /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ - day = years * 365 + (years + 1) / 4; - - /* After 2100 we have to substract 3 leap years for every 400 years - This is not intuitive. Most mktime implementations do not support - dates after 2059, anyway, so we might leave this out for it's - bloat. */ - if (years >= 131) - { - years -= 131; - years /= 100; - day -= (years >> 2) * 3 + 1; - if ((years &= 3) == 3) - years--; - day -= years; - } - - day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 + - (__isleap(t->tm_year + 1900) & (t->tm_mon > 1)); - - /* day is now the number of days since 'Jan 1 1970' */ - i = 7; - t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ - - i = 24; - day *= i; - i = 60; - return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; -} -RTM_EXPORT(timegm); - -/* TODO: timezone */ -int gettimeofday(struct timeval *tv, struct timezone *tz) -{ - if (tv != RT_NULL && get_timeval(tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(gettimeofday); - -/* TODO: timezone */ -int settimeofday(const struct timeval *tv, const struct timezone *tz) -{ - if (tv != RT_NULL) - { - if(tv->tv_sec >= 0 && tv->tv_usec >= 0) - { - if(set_timeval((struct timeval *)tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } - } - else - { - errno = EINVAL; - return -1; - } - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(settimeofday); - -/* inherent in the toolchain */ -RTM_EXPORT(difftime); -RTM_EXPORT(strftime); - -#ifdef RT_USING_POSIX -static struct timeval _timevalue; -static int clock_time_system_init() -{ - 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 = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; - - return 0; -} -INIT_COMPONENT_EXPORT(clock_time_system_init); - -int clock_getres(clockid_t clockid, struct timespec *res) -{ - int ret = 0; - - if (res == RT_NULL) - { - rt_set_errno(EINVAL); - return -1; - } - - switch (clockid) - { - case CLOCK_REALTIME: - res->tv_sec = 0; - res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND; - break; - -#ifdef RT_USING_CPUTIME - case CLOCK_CPUTIME_ID: - res->tv_sec = 0; - res->tv_nsec = clock_cpu_getres(); - break; -#endif - - default: - ret = -1; - rt_set_errno(EINVAL); - break; - } - - return ret; -} -RTM_EXPORT(clock_getres); - -int clock_gettime(clockid_t clockid, struct timespec *tp) -{ - int ret = 0; - - if (tp == RT_NULL) - { - rt_set_errno(EINVAL); - return -1; - } - - switch (clockid) - { - case CLOCK_REALTIME: - { - /* get tick */ - int tick = rt_tick_get(); - - tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; - tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; - } - break; - -#ifdef RT_USING_CPUTIME - case CLOCK_CPUTIME_ID: - { - float unit = 0; - long long cpu_tick; - - unit = clock_cpu_getres(); - cpu_tick = clock_cpu_gettime(); - - tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND; - tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND; - } - break; -#endif - default: - rt_set_errno(EINVAL); - ret = -1; - } - - return ret; -} -RTM_EXPORT(clock_gettime); - -int clock_settime(clockid_t clockid, const struct timespec *tp) -{ - int second; - rt_tick_t tick; - rt_device_t device; - - if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) - { - rt_set_errno(EINVAL); - - return -1; - } - - /* get second */ - second = tp->tv_sec; - /* get tick */ - tick = rt_tick_get(); - - /* update timevalue */ - _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; - - /* update for RTC device */ - device = rt_device_find("rtc"); - if (device != RT_NULL) - { - /* set realtime seconds */ - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); - } - else - return -1; - - return 0; -} -RTM_EXPORT(clock_settime); - -int clock_time_to_tick(const struct timespec *time) -{ - int tick; - int nsecond, second; - struct timespec tp; - - RT_ASSERT(time != RT_NULL); - - tick = RT_WAITING_FOREVER; - if (time != NULL) - { - /* get current tp */ - clock_gettime(CLOCK_REALTIME, &tp); - - if ((time->tv_nsec - tp.tv_nsec) < 0) - { - nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec); - second = time->tv_sec - tp.tv_sec - 1; - } - else - { - nsecond = time->tv_nsec - tp.tv_nsec; - second = time->tv_sec - tp.tv_sec; - } - - tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND; - if (tick < 0) tick = 0; - } - - return tick; -} -RTM_EXPORT(clock_time_to_tick); - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c deleted file mode 100644 index 20130cbb8a..0000000000 --- a/components/libc/compilers/common/unistd.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-01 Meco Man first Version - * 2021-02-12 Meco Man move all functions located in to this file - */ - -#include -#include -#include - -#ifdef RT_USING_POSIX_TERMIOS -#include "termios.h" - -int isatty(int fd) -{ - struct termios ts; - return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/ -} -RTM_EXPORT(isatty); -#endif - -char *ttyname(int fd) -{ - return "/dev/tty0"; /*TODO: need to add more specific*/ -} -RTM_EXPORT(ttyname); - -unsigned int sleep(unsigned int seconds) -{ - rt_tick_t delta_tick; - - delta_tick = rt_tick_get(); - rt_thread_delay(seconds * RT_TICK_PER_SECOND); - delta_tick = rt_tick_get() - delta_tick; - - return seconds - delta_tick/RT_TICK_PER_SECOND; -} -RTM_EXPORT(sleep); - -int usleep(useconds_t usec) -{ - rt_thread_mdelay(usec / 1000u); - rt_hw_us_delay(usec % 1000u); - return 0; -} -RTM_EXPORT(usleep); - -pid_t getpid(void) -{ - /*TODO*/ - return 0; -} -RTM_EXPORT(getpid); - -pid_t getppid(void) -{ - return 0; -} -RTM_EXPORT(getppid); - -uid_t getuid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getuid); - -uid_t geteuid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(geteuid); - -gid_t getgid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getgid); - -gid_t getegid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getegid); diff --git a/components/libc/compilers/common_all/SConscript b/components/libc/compilers/common_all/SConscript new file mode 100644 index 0000000000..319e1a3555 --- /dev/null +++ b/components/libc/compilers/common_all/SConscript @@ -0,0 +1,27 @@ +from building import * + +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +group = [] +CPPPATH = [cwd] + +if GetDepend('RT_USING_LIBC'): + src += Glob('*.c') +else: + if GetDepend('RT_LIBC_USING_TIME'): + src += ['time.c'] + +if GetDepend('RT_USING_POSIX') == False: + SrcRemove(src, ['unistd.c']) + +if rtconfig.CROSS_TOOL == 'keil': + CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND'] +else: + CPPDEFINES = [] + +if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): + group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) + +Return('group') diff --git a/components/libc/compilers/common_all/dirent.h b/components/libc/compilers/common_all/dirent.h new file mode 100644 index 0000000000..bfba586093 --- /dev/null +++ b/components/libc/compilers/common_all/dirent.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef __RTT_DIRENT_H__ +#define __RTT_DIRENT_H__ + +#include + +/* +* dirent.h - format of directory entries + * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html + */ + +/* File types */ +#define FT_REGULAR 0 /* regular file */ +#define FT_SOCKET 1 /* socket file */ +#define FT_DIRECTORY 2 /* directory */ +#define FT_USER 3 /* user defined */ + +#define DT_UNKNOWN 0x00 +#define DT_REG 0x01 +#define DT_DIR 0x02 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef HAVE_DIR_STRUCTURE +typedef struct +{ + int fd; /* directory file */ + char buf[512]; + int num; + int cur; +} DIR; +#endif + +#ifndef HAVE_DIRENT_STRUCTURE +struct dirent +{ + rt_uint8_t d_type; /* The type of the file */ + rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ + rt_uint16_t d_reclen; /* length of this record */ + char d_name[256]; /* The null-terminated file name */ +}; +#endif + +int closedir(DIR *); +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +int readdir_r(DIR *, struct dirent *, struct dirent **); +void rewinddir(DIR *); +void seekdir(DIR *, long int); +long telldir(DIR *); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/libc/compilers/common_all/readme.md b/components/libc/compilers/common_all/readme.md new file mode 100644 index 0000000000..81bb005d0a --- /dev/null +++ b/components/libc/compilers/common_all/readme.md @@ -0,0 +1,10 @@ +## Attentions + +1. This folder is "common" for armlibc newlibc and dlib. + +2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg: + +```python +if GetDepend('RT_USING_POSIX') == False: + SrcRemove(src, ['unistd.c']) +``` \ No newline at end of file diff --git a/components/libc/compilers/common_all/stdlib.c b/components/libc/compilers/common_all/stdlib.c new file mode 100644 index 0000000000..9d8952e99e --- /dev/null +++ b/components/libc/compilers/common_all/stdlib.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-02-15 Meco Man first version + */ + +#include + +void __rt_libc_exit(int status) +{ + rt_thread_t self = rt_thread_self(); + + if (self != RT_NULL) + { + rt_kprintf("thread:%s exit:%d!\n", self->name, status); + rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL); + } +} + +int __rt_libc_system(const char *string) +{ + /* TODO */ + return 0; +} diff --git a/components/libc/compilers/common_all/sys/ioctl.h b/components/libc/compilers/common_all/sys/ioctl.h new file mode 100644 index 0000000000..648d90230d --- /dev/null +++ b/components/libc/compilers/common_all/sys/ioctl.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-01 Meco Man First Version + */ +#ifndef _SYS_IOCTL_H +#define _SYS_IOCTL_H + +#include +#ifdef RT_USING_POSIX +#include +#endif + +#endif diff --git a/components/libc/compilers/common_all/sys/mman.h b/components/libc/compilers/common_all/sys/mman.h new file mode 100644 index 0000000000..a9235d61f0 --- /dev/null +++ b/components/libc/compilers/common_all/sys/mman.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/11/30 Bernard The first version. + */ + +#ifndef _SYS_MMAN_H +#define _SYS_MMAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define MAP_FAILED ((void *) -1) + +#define MAP_SHARED 0x01 +#define MAP_PRIVATE 0x02 +#define MAP_TYPE 0x0f +#define MAP_FIXED 0x10 +#define MAP_ANON 0x20 +#define MAP_ANONYMOUS MAP_ANON +#define MAP_NORESERVE 0x4000 +#define MAP_GROWSDOWN 0x0100 +#define MAP_DENYWRITE 0x0800 +#define MAP_EXECUTABLE 0x1000 +#define MAP_LOCKED 0x2000 +#define MAP_POPULATE 0x8000 +#define MAP_NONBLOCK 0x10000 +#define MAP_STACK 0x20000 +#define MAP_HUGETLB 0x40000 +#define MAP_FILE 0 + +#define PROT_NONE 0 +#define PROT_READ 1 +#define PROT_WRITE 2 +#define PROT_EXEC 4 +#define PROT_GROWSDOWN 0x01000000 +#define PROT_GROWSUP 0x02000000 + +#define MS_ASYNC 1 +#define MS_INVALIDATE 2 +#define MS_SYNC 4 + +#define MCL_CURRENT 1 +#define MCL_FUTURE 2 +#define MCL_ONFAULT 4 + +void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off); +int munmap (void *start, size_t len); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/components/libc/compilers/common_all/sys/statfs.h b/components/libc/compilers/common_all/sys/statfs.h new file mode 100644 index 0000000000..0996af9a18 --- /dev/null +++ b/components/libc/compilers/common_all/sys/statfs.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef __RTT_STATFS_H__ +#define __RTT_STATFS_H__ + +#include + +struct statfs +{ + rt_size_t f_bsize; /* block size */ + rt_size_t f_blocks; /* total data blocks in file system */ + rt_size_t f_bfree; /* free blocks in file system */ +}; + +#endif diff --git a/components/libc/compilers/common_all/sys/termios.h b/components/libc/compilers/common_all/sys/termios.h new file mode 100644 index 0000000000..c4b42083c4 --- /dev/null +++ b/components/libc/compilers/common_all/sys/termios.h @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ diff --git a/components/libc/compilers/common_all/sys/time.h b/components/libc/compilers/common_all/sys/time.h new file mode 100644 index 0000000000..ef1c810608 --- /dev/null +++ b/components/libc/compilers/common_all/sys/time.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-07 Meco Man combine gcc armcc iccarm + * 2021-02-12 Meco Man move all definitions located in to this file + */ +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001. + */ +#if defined ( __ICCARM__ ) && (__VER__ >= 8010001) +#define _TIMESPEC_DEFINED +#endif + + +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED +/* + * Structure returned by gettimeofday(2) system call, + * and used in other calls. + */ +#if !(defined(_WIN32)) +struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ +}; +#endif +#endif /* _TIMEVAL_DEFINED */ + +#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !defined (__ICCARM__) && !defined (_WIN32) +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +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); +#if defined(__ARMCC_VERSION) || defined (__ICCARM__) +struct tm *gmtime_r(const time_t *timep, struct tm *r); +#endif + +#ifdef RT_USING_POSIX +#include +/* posix clock and timer */ +#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) + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 1 +#endif + +#define CLOCK_CPUTIME_ID 2 + +#ifndef CLOCK_PROCESS_CPUTIME_ID +#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID +#endif +#ifndef CLOCK_THREAD_CPUTIME_ID +#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID +#endif + +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 4 +#endif + +int clock_getres (clockid_t clockid, struct timespec *res); +int clock_gettime (clockid_t clockid, struct timespec *tp); +int clock_settime (clockid_t clockid, const struct timespec *tp); +int clock_time_to_tick(const struct timespec *time); +#endif /* RT_USING_POSIX */ + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS_TIME_H_ */ diff --git a/components/libc/compilers/common_all/termios.h b/components/libc/compilers/common_all/termios.h new file mode 100644 index 0000000000..2960d52c58 --- /dev/null +++ b/components/libc/compilers/common_all/termios.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef _TERMIOS_H__ +#define _TERMIOS_H__ + +#include + +#ifdef RT_USING_POSIX_TERMIOS +#include +#include +#endif + +#endif diff --git a/components/libc/compilers/common_all/time.c b/components/libc/compilers/common_all/time.c new file mode 100644 index 0000000000..33d8907165 --- /dev/null +++ b/components/libc/compilers/common_all/time.c @@ -0,0 +1,643 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 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() + * 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 + * 2021-02-12 Meco Man add errno + * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, + * which found by Rob + * 2021-02-12 Meco Man move all of the functions located in to this file + * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html + */ + +#include +#include + +#ifdef RT_USING_DEVICE +#include +#endif + +#define DBG_TAG "TIME" +#define DBG_LVL DBG_INFO +#include + +/* seconds per day */ +#define SPD 24*60*60 + +/* days per month -- nonleap! */ +static const short __spm[13] = +{ + 0, + (31), + (31 + 28), + (31 + 28 + 31), + (31 + 28 + 31 + 30), + (31 + 28 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), +}; + +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) +{ + /* every fourth year is a leap year except for century years that are + * not divisible by 400. */ + /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */ + return (!(year % 4) && ((year % 100) || !(year % 400))); +} + +static void num2str(char *c, int i) +{ + c[0] = i / 10 + '0'; + c[1] = i % 10 + '0'; +} + +/** + * Get time from RTC device (without timezone) + * @param tv: struct timeval + * @return -1 failure; 1 success + */ +static int get_timeval(struct timeval *tv) +{ +#ifdef RT_USING_RTC + static rt_device_t device = RT_NULL; + rt_err_t rst = -RT_ERROR; + + if (tv == RT_NULL) + return -1; + + /* default is 0 */ + tv->tv_sec = 0; + tv->tv_usec = 0; + + /* optimization: find rtc device only first */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } + + /* read timestamp from RTC device */ + if (device != RT_NULL) + { + if (rt_device_open(device, 0) == RT_EOK) + { + rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); + rt_device_close(device); + } + } + else + { + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + return -1; + } + + return (rst < 0) ? -1 : 1; + +#else + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + return -1; +#endif /* RT_USING_RTC */ +} + +/** + * Set time to RTC device (without timezone) + * @param tv: struct timeval + * @return -1 failure; 1 success + */ +static int set_timeval(struct timeval *tv) +{ +#ifdef RT_USING_RTC + static rt_device_t device = RT_NULL; + rt_err_t rst = -RT_ERROR; + + if (tv == RT_NULL) + return -1; + + /* optimization: find rtc device only first */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } + + /* read timestamp from RTC device */ + if (device != RT_NULL) + { + if (rt_device_open(device, 0) == RT_EOK) + { + rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec); + rt_device_close(device); + } + } + else + { + LOG_W("Cannot find a RTC device to provide time!"); + return -1; + } + + return (rst < 0) ? -1 : 1; + +#else + LOG_W("Cannot find a RTC device to provide time!"); + return -1; +#endif /* RT_USING_RTC */ +} + +struct tm *gmtime_r(const time_t *timep, struct tm *r) +{ + time_t i; + register time_t work = *timep % (SPD); + r->tm_sec = work % 60; + work /= 60; + r->tm_min = work % 60; + r->tm_hour = work / 60; + work = *timep / (SPD); + r->tm_wday = (4 + work) % 7; + for (i = 1970;; ++i) + { + register time_t k = __isleap(i) ? 366 : 365; + if (work >= k) + work -= k; + else + break; + } + r->tm_year = i - 1900; + r->tm_yday = work; + + r->tm_mday = 1; + if (__isleap(i) && (work > 58)) + { + if (work == 59) + r->tm_mday = 2; /* 29.2. */ + work -= 1; + } + + for (i = 11; i && (__spm[i] > work); --i) + ; + r->tm_mon = i; + r->tm_mday += work - __spm[i]; + + r->tm_isdst = 0; + return r; +} +RTM_EXPORT(gmtime_r); + +struct tm* gmtime(const time_t* t) +{ + static struct tm tmp; + return gmtime_r(t, &tmp); +} +RTM_EXPORT(gmtime); + +/*TODO: timezone */ +struct tm* localtime_r(const time_t* t, struct tm* r) +{ + time_t local_tz; + int utc_plus; + + utc_plus = 8; /* GMT: UTC+8 */ + local_tz = *t + utc_plus * 3600; + return gmtime_r(&local_tz, r); +} +RTM_EXPORT(localtime_r); + +struct tm* localtime(const time_t* t) +{ + static struct tm tmp; + return localtime_r(t, &tmp); +} +RTM_EXPORT(localtime); + +/* TODO: timezone */ +time_t mktime(struct tm * const t) +{ + time_t timestamp; + int utc_plus; + + utc_plus = 8; /* GMT: UTC+8 */ + timestamp = timegm(t); + timestamp = timestamp - 3600 * utc_plus; + return timestamp; +} +RTM_EXPORT(mktime); + +char* asctime_r(const struct tm *t, char *buf) +{ + /* "Wed Jun 30 21:49:08 1993\n" */ + *(int*) buf = *(int*) (days + (t->tm_wday << 2)); + *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); + num2str(buf + 8, t->tm_mday); + if (buf[8] == '0') + buf[8] = ' '; + buf[10] = ' '; + num2str(buf + 11, t->tm_hour); + buf[13] = ':'; + num2str(buf + 14, t->tm_min); + buf[16] = ':'; + num2str(buf + 17, t->tm_sec); + buf[19] = ' '; + num2str(buf + 20, (t->tm_year + 1900) / 100); + num2str(buf + 22, (t->tm_year + 1900) % 100); + buf[24] = '\n'; + buf[25] = '\0'; + return buf; +} +RTM_EXPORT(asctime_r); + +char* asctime(const struct tm *timeptr) +{ + static char buf[26]; + return asctime_r(timeptr, buf); +} +RTM_EXPORT(asctime); + +char *ctime_r (const time_t * tim_p, char * result) +{ + struct tm tm; + return asctime_r (localtime_r (tim_p, &tm), result); +} +RTM_EXPORT(ctime_r); + +char* ctime(const time_t *tim_p) +{ + return asctime (localtime (tim_p)); +} +RTM_EXPORT(ctime); + +/** + * Returns the current time. + * + * @param time_t * t the timestamp pointer, if not used, keep NULL. + * + * @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) +{ + struct timeval now; + + if(get_timeval(&now) > 0) + { + if (t) + { + *t = now.tv_sec; + } + return now.tv_sec; + } + else + { + errno = EFAULT; + return ((time_t)-1); + } +} +RTM_EXPORT(time); + +RT_WEAK clock_t clock(void) +{ + return rt_tick_get(); +} +RTM_EXPORT(clock); + +int stime(const time_t *t) +{ + struct timeval tv; + + if (!t) + { + errno = EFAULT; + return -1; + } + + tv.tv_sec = *t; + if (set_timeval(&tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(stime); + +time_t timegm(struct tm * const t) +{ + register time_t day; + register time_t i; + register time_t years = t->tm_year - 70; + + if (t->tm_sec > 60) + { + t->tm_min += t->tm_sec / 60; + t->tm_sec %= 60; + } + if (t->tm_min > 60) + { + t->tm_hour += t->tm_min / 60; + t->tm_min %= 60; + } + if (t->tm_hour > 24) + { + t->tm_mday += t->tm_hour / 24; + t->tm_hour %= 24; + } + if (t->tm_mon > 12) + { + t->tm_year += t->tm_mon / 12; + t->tm_mon %= 12; + } + while (t->tm_mday > __spm[1 + t->tm_mon]) + { + if (t->tm_mon == 1 && __isleap(t->tm_year + 1900)) + { + --t->tm_mday; + } + t->tm_mday -= __spm[t->tm_mon]; + ++t->tm_mon; + if (t->tm_mon > 11) + { + t->tm_mon = 0; + ++t->tm_year; + } + } + + if (t->tm_year < 70) + return (time_t) - 1; + + /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ + day = years * 365 + (years + 1) / 4; + + /* After 2100 we have to substract 3 leap years for every 400 years + This is not intuitive. Most mktime implementations do not support + dates after 2059, anyway, so we might leave this out for it's + bloat. */ + if (years >= 131) + { + years -= 131; + years /= 100; + day -= (years >> 2) * 3 + 1; + if ((years &= 3) == 3) + years--; + day -= years; + } + + day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 + + (__isleap(t->tm_year + 1900) & (t->tm_mon > 1)); + + /* day is now the number of days since 'Jan 1 1970' */ + i = 7; + t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ + + i = 24; + day *= i; + i = 60; + return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; +} +RTM_EXPORT(timegm); + +/* TODO: timezone */ +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + if (tv != RT_NULL && get_timeval(tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(gettimeofday); + +/* TODO: timezone */ +int settimeofday(const struct timeval *tv, const struct timezone *tz) +{ + if (tv != RT_NULL) + { + if(tv->tv_sec >= 0 && tv->tv_usec >= 0) + { + if(set_timeval((struct timeval *)tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } + } + else + { + errno = EINVAL; + return -1; + } + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(settimeofday); + +/* inherent in the toolchain */ +RTM_EXPORT(difftime); +RTM_EXPORT(strftime); + +#ifdef RT_USING_POSIX +static struct timeval _timevalue; +static int clock_time_system_init() +{ + 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 = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; + _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; + + return 0; +} +INIT_COMPONENT_EXPORT(clock_time_system_init); + +int clock_getres(clockid_t clockid, struct timespec *res) +{ + int ret = 0; + + if (res == RT_NULL) + { + rt_set_errno(EINVAL); + return -1; + } + + switch (clockid) + { + case CLOCK_REALTIME: + res->tv_sec = 0; + res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND; + break; + +#ifdef RT_USING_CPUTIME + case CLOCK_CPUTIME_ID: + res->tv_sec = 0; + res->tv_nsec = clock_cpu_getres(); + break; +#endif + + default: + ret = -1; + rt_set_errno(EINVAL); + break; + } + + return ret; +} +RTM_EXPORT(clock_getres); + +int clock_gettime(clockid_t clockid, struct timespec *tp) +{ + int ret = 0; + + if (tp == RT_NULL) + { + rt_set_errno(EINVAL); + return -1; + } + + switch (clockid) + { + case CLOCK_REALTIME: + { + /* get tick */ + int tick = rt_tick_get(); + + tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; + tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; + } + break; + +#ifdef RT_USING_CPUTIME + case CLOCK_CPUTIME_ID: + { + float unit = 0; + long long cpu_tick; + + unit = clock_cpu_getres(); + cpu_tick = clock_cpu_gettime(); + + tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND; + tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND; + } + break; +#endif + default: + rt_set_errno(EINVAL); + ret = -1; + } + + return ret; +} +RTM_EXPORT(clock_gettime); + +int clock_settime(clockid_t clockid, const struct timespec *tp) +{ + int second; + rt_tick_t tick; + rt_device_t device; + + if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) + { + rt_set_errno(EINVAL); + + return -1; + } + + /* get second */ + second = tp->tv_sec; + /* get tick */ + tick = rt_tick_get(); + + /* update timevalue */ + _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; + _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; + + /* update for RTC device */ + device = rt_device_find("rtc"); + if (device != RT_NULL) + { + /* set realtime seconds */ + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); + } + else + return -1; + + return 0; +} +RTM_EXPORT(clock_settime); + +int clock_time_to_tick(const struct timespec *time) +{ + int tick; + int nsecond, second; + struct timespec tp; + + RT_ASSERT(time != RT_NULL); + + tick = RT_WAITING_FOREVER; + if (time != NULL) + { + /* get current tp */ + clock_gettime(CLOCK_REALTIME, &tp); + + if ((time->tv_nsec - tp.tv_nsec) < 0) + { + nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec); + second = time->tv_sec - tp.tv_sec - 1; + } + else + { + nsecond = time->tv_nsec - tp.tv_nsec; + second = time->tv_sec - tp.tv_sec; + } + + tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND; + if (tick < 0) tick = 0; + } + + return tick; +} +RTM_EXPORT(clock_time_to_tick); + +#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/common_all/unistd.c b/components/libc/compilers/common_all/unistd.c new file mode 100644 index 0000000000..20130cbb8a --- /dev/null +++ b/components/libc/compilers/common_all/unistd.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-01 Meco Man first Version + * 2021-02-12 Meco Man move all functions located in to this file + */ + +#include +#include +#include + +#ifdef RT_USING_POSIX_TERMIOS +#include "termios.h" + +int isatty(int fd) +{ + struct termios ts; + return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/ +} +RTM_EXPORT(isatty); +#endif + +char *ttyname(int fd) +{ + return "/dev/tty0"; /*TODO: need to add more specific*/ +} +RTM_EXPORT(ttyname); + +unsigned int sleep(unsigned int seconds) +{ + rt_tick_t delta_tick; + + delta_tick = rt_tick_get(); + rt_thread_delay(seconds * RT_TICK_PER_SECOND); + delta_tick = rt_tick_get() - delta_tick; + + return seconds - delta_tick/RT_TICK_PER_SECOND; +} +RTM_EXPORT(sleep); + +int usleep(useconds_t usec) +{ + rt_thread_mdelay(usec / 1000u); + rt_hw_us_delay(usec % 1000u); + return 0; +} +RTM_EXPORT(usleep); + +pid_t getpid(void) +{ + /*TODO*/ + return 0; +} +RTM_EXPORT(getpid); + +pid_t getppid(void) +{ + return 0; +} +RTM_EXPORT(getppid); + +uid_t getuid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getuid); + +uid_t geteuid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(geteuid); + +gid_t getgid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getgid); + +gid_t getegid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getegid); diff --git a/components/libc/compilers/common_except_gcc/SConscript b/components/libc/compilers/common_except_gcc/SConscript new file mode 100644 index 0000000000..bda0d5610f --- /dev/null +++ b/components/libc/compilers/common_except_gcc/SConscript @@ -0,0 +1,13 @@ +from building import * + +Import('rtconfig') + +if rtconfig.PLATFORM == 'iar' or rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang': + src = [] + cwd = GetCurrentDir() + CPPPATH = [cwd] + group = [] + src += Glob('*.c') + + group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH) + Return('group') diff --git a/components/libc/compilers/common_except_gcc/fcntl.h b/components/libc/compilers/common_except_gcc/fcntl.h new file mode 100644 index 0000000000..f247b926e9 --- /dev/null +++ b/components/libc/compilers/common_except_gcc/fcntl.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef FCNTL_H__ +#define FCNTL_H__ + +#include + +#ifdef RT_USING_DFS +#include +#endif + +#endif diff --git a/components/libc/compilers/common_except_gcc/sys/stat.h b/components/libc/compilers/common_except_gcc/sys/stat.h new file mode 100644 index 0000000000..c4b42083c4 --- /dev/null +++ b/components/libc/compilers/common_except_gcc/sys/stat.h @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ diff --git a/components/libc/compilers/common_except_gcc/sys/types.h b/components/libc/compilers/common_except_gcc/sys/types.h new file mode 100644 index 0000000000..7222326a2a --- /dev/null +++ b/components/libc/compilers/common_except_gcc/sys/types.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-05 Meco Man fix bugs + * 2020-12-16 Meco Man add useconds_t + */ +#ifndef __TYPES_H__ +#define __TYPES_H__ + +#include + +typedef int32_t clockid_t; +typedef int32_t key_t; /* Used for interprocess communication. */ +typedef int pid_t; /* Used for process IDs and process group IDs. */ +typedef unsigned short uid_t; +typedef unsigned short gid_t; +typedef signed long off_t; +typedef int mode_t; +#ifndef ARCH_CPU_64BIT +typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ +#else +typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ +#endif +typedef unsigned long useconds_t; /* microseconds (unsigned) */ + +typedef unsigned long dev_t; + +typedef unsigned int u_int; +typedef unsigned char u_char; +typedef unsigned long u_long; + +#endif diff --git a/components/libc/compilers/common_except_gcc/sys/unistd.h b/components/libc/compilers/common_except_gcc/sys/unistd.h new file mode 100644 index 0000000000..7752a1caf7 --- /dev/null +++ b/components/libc/compilers/common_except_gcc/sys/unistd.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-12-16 Meco Man add usleep + */ +#ifndef _SYS_UNISTD_H +#define _SYS_UNISTD_H + +#include +#include "types.h" + +#ifdef RT_USING_DFS + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +#include +#else +#define _FREAD 0x0001 /* read enabled */ +#define _FWRITE 0x0002 /* write enabled */ +#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ +#define _FMARK 0x0010 /* internal; mark during gc() */ +#define _FDEFER 0x0020 /* internal; defer for next gc pass */ +#define _FASYNC 0x0040 /* signal pgrp when data ready */ +#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ +#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ +#define _FCREAT 0x0200 /* open with file create */ +#define _FTRUNC 0x0400 /* open with truncation */ +#define _FEXCL 0x0800 /* error on open if file exists */ +#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ +#define _FSYNC 0x2000 /* do all writes synchronously */ +#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ +#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ +#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ + + +#ifndef O_RDONLY +#define O_RDONLY 0 /* +1 == FREAD */ +#endif +#ifndef O_WRONLY +#define O_WRONLY 1 /* +1 == FWRITE */ +#endif +#ifndef O_RDWR +#define O_RDWR 2 /* +1 == FREAD|FWRITE */ +#endif +#ifndef O_APPEND +#define O_APPEND _FAPPEND +#endif +#ifndef O_CREAT +#define O_CREAT _FCREAT +#endif +#ifndef O_TRUNC +#define O_TRUNC _FTRUNC +#endif +#ifndef O_EXCL +#define O_EXCL _FEXCL +#endif +#ifndef O_SYNC +#define O_SYNC _FSYNC +#endif + +#endif + + +int isatty (int fd); +char * ttyname (int desc); + +unsigned int sleep(unsigned int seconds); +int usleep(useconds_t usec); + +pid_t getpid(void); +pid_t getppid(void); +uid_t getuid(void); +uid_t geteuid(void); +gid_t getgid(void); +gid_t getegid(void); + +#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common_except_gcc/unistd.h b/components/libc/compilers/common_except_gcc/unistd.h new file mode 100644 index 0000000000..cd77a12e3b --- /dev/null +++ b/components/libc/compilers/common_except_gcc/unistd.h @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#include "sys/unistd.h" + diff --git a/components/libc/compilers/dlib/dirent.h b/components/libc/compilers/dlib/dirent.h deleted file mode 100644 index 2c0521d2e3..0000000000 --- a/components/libc/compilers/dlib/dirent.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __RTT_DIRENT_H__ -#define __RTT_DIRENT_H__ - -#include -#include - -/* -* dirent.h - format of directory entries - * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html - */ - -/* File types */ -#define FT_REGULAR 0 /* regular file */ -#define FT_SOCKET 1 /* socket file */ -#define FT_DIRECTORY 2 /* directory */ -#define FT_USER 3 /* user defined */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef HAVE_DIR_STRUCTURE -typedef struct -{ - int fd; /* directory file */ - char buf[512]; - int num; - int cur; -} DIR; -#endif - -#ifndef HAVE_DIRENT_STRUCTURE -struct dirent -{ - rt_uint8_t d_type; /* The type of the file */ - rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ - rt_uint16_t d_reclen; /* length of this record */ - char d_name[256]; /* The null-terminated file name */ -}; -#endif - -int closedir(DIR *); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); -void rewinddir(DIR *); -void seekdir(DIR *, long int); -long telldir(DIR *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/dlib/fcntl.h b/components/libc/compilers/dlib/fcntl.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/dlib/fcntl.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/components/libc/compilers/dlib/sys/mman.h b/components/libc/compilers/dlib/sys/mman.h deleted file mode 100644 index 6a260ccd70..0000000000 --- a/components/libc/compilers/dlib/sys/mman.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/11/30 Bernard The first version. - */ - -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAP_FAILED ((void *) -1) - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_TYPE 0x0f -#define MAP_FIXED 0x10 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_NORESERVE 0x4000 -#define MAP_GROWSDOWN 0x0100 -#define MAP_DENYWRITE 0x0800 -#define MAP_EXECUTABLE 0x1000 -#define MAP_LOCKED 0x2000 -#define MAP_POPULATE 0x8000 -#define MAP_NONBLOCK 0x10000 -#define MAP_STACK 0x20000 -#define MAP_HUGETLB 0x40000 -#define MAP_FILE 0 - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 -#define MCL_ONFAULT 4 - -void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off); -int munmap (void *start, size_t len); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/components/libc/compilers/dlib/sys/stat.h b/components/libc/compilers/dlib/sys/stat.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/dlib/sys/stat.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/components/libc/compilers/dlib/sys/types.h b/components/libc/compilers/dlib/sys/types.h deleted file mode 100644 index 6e2d1ce839..0000000000 --- a/components/libc/compilers/dlib/sys/types.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-12-16 Meco Man add useconds_t - */ -#ifndef __TYPES_H__ -#define __TYPES_H__ - -#include - -typedef int32_t clockid_t; -typedef int32_t key_t; /* Used for interprocess communication. */ -typedef int pid_t; /* Used for process IDs and process group IDs. */ -typedef unsigned short uid_t; -typedef unsigned short gid_t; -#ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#endif -typedef unsigned long useconds_t; /* microseconds (unsigned) */ - -typedef unsigned long dev_t; - -typedef unsigned int u_int; -typedef unsigned char u_char; -typedef unsigned long u_long; - -#endif diff --git a/components/libc/compilers/dlib/sys/unistd.h b/components/libc/compilers/dlib/sys/unistd.h deleted file mode 100644 index 14966a2bad..0000000000 --- a/components/libc/compilers/dlib/sys/unistd.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-12-16 Meco Man add usleep - */ -#ifndef _SYS_UNISTD_H -#define _SYS_UNISTD_H - -#include -#include "types.h" - -#ifdef RT_USING_DFS - -#define STDIN_FILENO 0 /* standard input file descriptor */ -#define STDOUT_FILENO 1 /* standard output file descriptor */ -#define STDERR_FILENO 2 /* standard error file descriptor */ - -#include -#else -#define _FREAD 0x0001 /* read enabled */ -#define _FWRITE 0x0002 /* write enabled */ -#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ -#define _FMARK 0x0010 /* internal; mark during gc() */ -#define _FDEFER 0x0020 /* internal; defer for next gc pass */ -#define _FASYNC 0x0040 /* signal pgrp when data ready */ -#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ -#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ -#define _FCREAT 0x0200 /* open with file create */ -#define _FTRUNC 0x0400 /* open with truncation */ -#define _FEXCL 0x0800 /* error on open if file exists */ -#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ -#define _FSYNC 0x2000 /* do all writes synchronously */ -#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ -#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ -#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ - -#endif - - -int isatty (int fd); -char * ttyname (int desc); - -unsigned int sleep(unsigned int seconds); -int usleep(useconds_t usec); - -pid_t getpid(void); -pid_t getppid(void); -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); - -#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/dlib/unistd.h b/components/libc/compilers/dlib/unistd.h deleted file mode 100644 index 72b9d538ec..0000000000 --- a/components/libc/compilers/dlib/unistd.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef _UNISTD_H_ -#define _UNISTD_H_ - -# include "sys/unistd.h" - -#endif /* _UNISTD_H_ */ diff --git a/components/libc/compilers/newlib/sys/dirent.h b/components/libc/compilers/newlib/sys/dirent.h deleted file mode 100644 index bfba586093..0000000000 --- a/components/libc/compilers/newlib/sys/dirent.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __RTT_DIRENT_H__ -#define __RTT_DIRENT_H__ - -#include - -/* -* dirent.h - format of directory entries - * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html - */ - -/* File types */ -#define FT_REGULAR 0 /* regular file */ -#define FT_SOCKET 1 /* socket file */ -#define FT_DIRECTORY 2 /* directory */ -#define FT_USER 3 /* user defined */ - -#define DT_UNKNOWN 0x00 -#define DT_REG 0x01 -#define DT_DIR 0x02 - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef HAVE_DIR_STRUCTURE -typedef struct -{ - int fd; /* directory file */ - char buf[512]; - int num; - int cur; -} DIR; -#endif - -#ifndef HAVE_DIRENT_STRUCTURE -struct dirent -{ - rt_uint8_t d_type; /* The type of the file */ - rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ - rt_uint16_t d_reclen; /* length of this record */ - char d_name[256]; /* The null-terminated file name */ -}; -#endif - -int closedir(DIR *); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); -void rewinddir(DIR *); -void seekdir(DIR *, long int); -long telldir(DIR *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/newlib/sys/mman.h b/components/libc/compilers/newlib/sys/mman.h deleted file mode 100644 index 6a260ccd70..0000000000 --- a/components/libc/compilers/newlib/sys/mman.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/11/30 Bernard The first version. - */ - -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAP_FAILED ((void *) -1) - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_TYPE 0x0f -#define MAP_FIXED 0x10 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_NORESERVE 0x4000 -#define MAP_GROWSDOWN 0x0100 -#define MAP_DENYWRITE 0x0800 -#define MAP_EXECUTABLE 0x1000 -#define MAP_LOCKED 0x2000 -#define MAP_POPULATE 0x8000 -#define MAP_NONBLOCK 0x10000 -#define MAP_STACK 0x20000 -#define MAP_HUGETLB 0x40000 -#define MAP_FILE 0 - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 -#define MCL_ONFAULT 4 - -void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off); -int munmap (void *start, size_t len); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/components/libc/compilers/newlib/sys/statfs.h b/components/libc/compilers/newlib/sys/statfs.h deleted file mode 100644 index 0996af9a18..0000000000 --- a/components/libc/compilers/newlib/sys/statfs.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __RTT_STATFS_H__ -#define __RTT_STATFS_H__ - -#include - -struct statfs -{ - rt_size_t f_bsize; /* block size */ - rt_size_t f_blocks; /* total data blocks in file system */ - rt_size_t f_bfree; /* free blocks in file system */ -}; - -#endif diff --git a/components/libc/compilers/newlib/sys/termios.h b/components/libc/compilers/newlib/sys/termios.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/newlib/sys/termios.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/include/rtlibc.h b/include/rtlibc.h index 5a260d250d..6f6777a2f3 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -23,11 +23,6 @@ #include "libc/libc_limits.h" #include "libc/libc_stdio.h" -#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) -typedef signed long off_t; -typedef int mode_t; -#endif - #if defined(__MINGW32__) || defined(_WIN32) typedef signed long off_t; typedef int mode_t; -- cgit v1.3.1 From bc25c8a6e87e0f070152985eda47a3648390881f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 18 Apr 2021 00:55:32 +0800 Subject: update sconscript --- components/libc/compilers/common_except_gcc/SConscript | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common_except_gcc/SConscript b/components/libc/compilers/common_except_gcc/SConscript index bda0d5610f..346e69b478 100644 --- a/components/libc/compilers/common_except_gcc/SConscript +++ b/components/libc/compilers/common_except_gcc/SConscript @@ -2,12 +2,12 @@ from building import * Import('rtconfig') -if rtconfig.PLATFORM == 'iar' or rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang': - src = [] - cwd = GetCurrentDir() - CPPPATH = [cwd] - group = [] - src += Glob('*.c') +src = [] +cwd = GetCurrentDir() +CPPPATH = [cwd] +group = [] +src += Glob('*.c') +if rtconfig.PLATFORM != 'gcc': group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH) - Return('group') +Return('group') -- cgit v1.3.1 From 926cd865892cfbb9b474d36cfd046688d92ecc37 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 18 Apr 2021 01:36:35 +0800 Subject: remove dlib and armlibc sys folder --- components/libc/compilers/armlibc/sys/README.md | 1 - components/libc/compilers/armlibc/sys/errno.h | 14 -------------- components/libc/compilers/common_except_gcc/readme.md | 3 +++ components/libc/compilers/dlib/sys/README.md | 1 - components/libc/compilers/dlib/sys/errno.h | 16 ---------------- components/libc/compilers/dlib/sys/signal.h | 16 ---------------- 6 files changed, 3 insertions(+), 48 deletions(-) delete mode 100644 components/libc/compilers/armlibc/sys/README.md delete mode 100644 components/libc/compilers/armlibc/sys/errno.h create mode 100644 components/libc/compilers/common_except_gcc/readme.md delete mode 100644 components/libc/compilers/dlib/sys/README.md delete mode 100644 components/libc/compilers/dlib/sys/errno.h delete mode 100644 components/libc/compilers/dlib/sys/signal.h (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/armlibc/sys/README.md b/components/libc/compilers/armlibc/sys/README.md deleted file mode 100644 index 7ad10a7d43..0000000000 --- a/components/libc/compilers/armlibc/sys/README.md +++ /dev/null @@ -1 +0,0 @@ -Because Keil MDK leaks some system header file, we put them in here. \ No newline at end of file diff --git a/components/libc/compilers/armlibc/sys/errno.h b/components/libc/compilers/armlibc/sys/errno.h deleted file mode 100644 index 74cc986f7c..0000000000 --- a/components/libc/compilers/armlibc/sys/errno.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef SYS_ERRNO_H__ -#define SYS_ERRNO_H__ - -#include - -#endif diff --git a/components/libc/compilers/common_except_gcc/readme.md b/components/libc/compilers/common_except_gcc/readme.md new file mode 100644 index 0000000000..15f8e60d59 --- /dev/null +++ b/components/libc/compilers/common_except_gcc/readme.md @@ -0,0 +1,3 @@ +## Attentions + +This folder is "common" for armlibc and dlib. \ No newline at end of file diff --git a/components/libc/compilers/dlib/sys/README.md b/components/libc/compilers/dlib/sys/README.md deleted file mode 100644 index 4f0d203180..0000000000 --- a/components/libc/compilers/dlib/sys/README.md +++ /dev/null @@ -1 +0,0 @@ -Because IAR leaks some system header file, we put them in here. \ No newline at end of file diff --git a/components/libc/compilers/dlib/sys/errno.h b/components/libc/compilers/dlib/sys/errno.h deleted file mode 100644 index 54a1d33cd0..0000000000 --- a/components/libc/compilers/dlib/sys/errno.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2019-07-08 Bernard The first version - */ - -#ifndef SYS_ERRNO_H__ -#define SYS_ERRNO_H__ - -#include - -#endif diff --git a/components/libc/compilers/dlib/sys/signal.h b/components/libc/compilers/dlib/sys/signal.h deleted file mode 100644 index a30235f2b2..0000000000 --- a/components/libc/compilers/dlib/sys/signal.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2019-07-08 Bernard The first version - */ - -#ifndef SYS_SIGNAL_H__ -#define SYS_SIGNAL_H__ - -#include - -#endif -- cgit v1.3.1 From 40c09fc1e088e1f7a9eb91c85bd30119d4a38822 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 21 Apr 2021 00:56:36 +0800 Subject: 重新分类为common文件夹下属all文件夹和excgcc文件夹 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/include/dfs_fs.h | 2 + components/libc/compilers/common/SConscript | 15 + components/libc/compilers/common/all/SConscript | 27 + components/libc/compilers/common/all/dirent.h | 65 +++ components/libc/compilers/common/all/readme.md | 10 + components/libc/compilers/common/all/stdlib.c | 28 + components/libc/compilers/common/all/sys/ioctl.h | 18 + components/libc/compilers/common/all/sys/mman.h | 60 ++ components/libc/compilers/common/all/sys/statfs.h | 21 + components/libc/compilers/common/all/sys/termios.h | 8 + components/libc/compilers/common/all/sys/time.h | 101 ++++ components/libc/compilers/common/all/termios.h | 19 + components/libc/compilers/common/all/time.c | 643 +++++++++++++++++++++ components/libc/compilers/common/all/unistd.c | 88 +++ components/libc/compilers/common/excgcc/SConscript | 13 + components/libc/compilers/common/excgcc/fcntl.h | 18 + components/libc/compilers/common/excgcc/readme.md | 3 + components/libc/compilers/common/excgcc/sys/stat.h | 8 + .../libc/compilers/common/excgcc/sys/types.h | 36 ++ .../libc/compilers/common/excgcc/sys/unistd.h | 83 +++ components/libc/compilers/common/excgcc/unistd.h | 10 + components/libc/compilers/common_all/SConscript | 27 - components/libc/compilers/common_all/dirent.h | 65 --- components/libc/compilers/common_all/readme.md | 10 - components/libc/compilers/common_all/stdlib.c | 28 - components/libc/compilers/common_all/sys/ioctl.h | 18 - components/libc/compilers/common_all/sys/mman.h | 60 -- components/libc/compilers/common_all/sys/statfs.h | 21 - components/libc/compilers/common_all/sys/termios.h | 8 - components/libc/compilers/common_all/sys/time.h | 101 ---- components/libc/compilers/common_all/termios.h | 19 - components/libc/compilers/common_all/time.c | 643 --------------------- components/libc/compilers/common_all/unistd.c | 88 --- .../libc/compilers/common_except_gcc/SConscript | 13 - .../libc/compilers/common_except_gcc/fcntl.h | 18 - .../libc/compilers/common_except_gcc/readme.md | 3 - .../libc/compilers/common_except_gcc/sys/stat.h | 8 - .../libc/compilers/common_except_gcc/sys/types.h | 36 -- .../libc/compilers/common_except_gcc/sys/unistd.h | 83 --- .../libc/compilers/common_except_gcc/unistd.h | 10 - include/rtlibc.h | 7 + 41 files changed, 1283 insertions(+), 1259 deletions(-) create mode 100644 components/libc/compilers/common/SConscript create mode 100644 components/libc/compilers/common/all/SConscript create mode 100644 components/libc/compilers/common/all/dirent.h create mode 100644 components/libc/compilers/common/all/readme.md create mode 100644 components/libc/compilers/common/all/stdlib.c create mode 100644 components/libc/compilers/common/all/sys/ioctl.h create mode 100644 components/libc/compilers/common/all/sys/mman.h create mode 100644 components/libc/compilers/common/all/sys/statfs.h create mode 100644 components/libc/compilers/common/all/sys/termios.h create mode 100644 components/libc/compilers/common/all/sys/time.h create mode 100644 components/libc/compilers/common/all/termios.h create mode 100644 components/libc/compilers/common/all/time.c create mode 100644 components/libc/compilers/common/all/unistd.c create mode 100644 components/libc/compilers/common/excgcc/SConscript create mode 100644 components/libc/compilers/common/excgcc/fcntl.h create mode 100644 components/libc/compilers/common/excgcc/readme.md create mode 100644 components/libc/compilers/common/excgcc/sys/stat.h create mode 100644 components/libc/compilers/common/excgcc/sys/types.h create mode 100644 components/libc/compilers/common/excgcc/sys/unistd.h create mode 100644 components/libc/compilers/common/excgcc/unistd.h delete mode 100644 components/libc/compilers/common_all/SConscript delete mode 100644 components/libc/compilers/common_all/dirent.h delete mode 100644 components/libc/compilers/common_all/readme.md delete mode 100644 components/libc/compilers/common_all/stdlib.c delete mode 100644 components/libc/compilers/common_all/sys/ioctl.h delete mode 100644 components/libc/compilers/common_all/sys/mman.h delete mode 100644 components/libc/compilers/common_all/sys/statfs.h delete mode 100644 components/libc/compilers/common_all/sys/termios.h delete mode 100644 components/libc/compilers/common_all/sys/time.h delete mode 100644 components/libc/compilers/common_all/termios.h delete mode 100644 components/libc/compilers/common_all/time.c delete mode 100644 components/libc/compilers/common_all/unistd.c delete mode 100644 components/libc/compilers/common_except_gcc/SConscript delete mode 100644 components/libc/compilers/common_except_gcc/fcntl.h delete mode 100644 components/libc/compilers/common_except_gcc/readme.md delete mode 100644 components/libc/compilers/common_except_gcc/sys/stat.h delete mode 100644 components/libc/compilers/common_except_gcc/sys/types.h delete mode 100644 components/libc/compilers/common_except_gcc/sys/unistd.h delete mode 100644 components/libc/compilers/common_except_gcc/unistd.h (limited to 'components/libc/compilers') diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index ed0600f1f7..828f15a0f5 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -12,7 +12,9 @@ #define __DFS_FS_H__ #include +#ifdef RT_USING_LIBC #include +#endif #ifdef __cplusplus extern "C" { diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript new file mode 100644 index 0000000000..4c815c49b8 --- /dev/null +++ b/components/libc/compilers/common/SConscript @@ -0,0 +1,15 @@ +# RT-Thread building script for bridge + +import os +from building import * + +cwd = GetCurrentDir() +objs = [] +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) + +Return('objs') diff --git a/components/libc/compilers/common/all/SConscript b/components/libc/compilers/common/all/SConscript new file mode 100644 index 0000000000..319e1a3555 --- /dev/null +++ b/components/libc/compilers/common/all/SConscript @@ -0,0 +1,27 @@ +from building import * + +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +group = [] +CPPPATH = [cwd] + +if GetDepend('RT_USING_LIBC'): + src += Glob('*.c') +else: + if GetDepend('RT_LIBC_USING_TIME'): + src += ['time.c'] + +if GetDepend('RT_USING_POSIX') == False: + SrcRemove(src, ['unistd.c']) + +if rtconfig.CROSS_TOOL == 'keil': + CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND'] +else: + CPPDEFINES = [] + +if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): + group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) + +Return('group') diff --git a/components/libc/compilers/common/all/dirent.h b/components/libc/compilers/common/all/dirent.h new file mode 100644 index 0000000000..bfba586093 --- /dev/null +++ b/components/libc/compilers/common/all/dirent.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef __RTT_DIRENT_H__ +#define __RTT_DIRENT_H__ + +#include + +/* +* dirent.h - format of directory entries + * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html + */ + +/* File types */ +#define FT_REGULAR 0 /* regular file */ +#define FT_SOCKET 1 /* socket file */ +#define FT_DIRECTORY 2 /* directory */ +#define FT_USER 3 /* user defined */ + +#define DT_UNKNOWN 0x00 +#define DT_REG 0x01 +#define DT_DIR 0x02 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef HAVE_DIR_STRUCTURE +typedef struct +{ + int fd; /* directory file */ + char buf[512]; + int num; + int cur; +} DIR; +#endif + +#ifndef HAVE_DIRENT_STRUCTURE +struct dirent +{ + rt_uint8_t d_type; /* The type of the file */ + rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ + rt_uint16_t d_reclen; /* length of this record */ + char d_name[256]; /* The null-terminated file name */ +}; +#endif + +int closedir(DIR *); +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +int readdir_r(DIR *, struct dirent *, struct dirent **); +void rewinddir(DIR *); +void seekdir(DIR *, long int); +long telldir(DIR *); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/libc/compilers/common/all/readme.md b/components/libc/compilers/common/all/readme.md new file mode 100644 index 0000000000..81bb005d0a --- /dev/null +++ b/components/libc/compilers/common/all/readme.md @@ -0,0 +1,10 @@ +## Attentions + +1. This folder is "common" for armlibc newlibc and dlib. + +2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg: + +```python +if GetDepend('RT_USING_POSIX') == False: + SrcRemove(src, ['unistd.c']) +``` \ No newline at end of file diff --git a/components/libc/compilers/common/all/stdlib.c b/components/libc/compilers/common/all/stdlib.c new file mode 100644 index 0000000000..9d8952e99e --- /dev/null +++ b/components/libc/compilers/common/all/stdlib.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-02-15 Meco Man first version + */ + +#include + +void __rt_libc_exit(int status) +{ + rt_thread_t self = rt_thread_self(); + + if (self != RT_NULL) + { + rt_kprintf("thread:%s exit:%d!\n", self->name, status); + rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL); + } +} + +int __rt_libc_system(const char *string) +{ + /* TODO */ + return 0; +} diff --git a/components/libc/compilers/common/all/sys/ioctl.h b/components/libc/compilers/common/all/sys/ioctl.h new file mode 100644 index 0000000000..648d90230d --- /dev/null +++ b/components/libc/compilers/common/all/sys/ioctl.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-01 Meco Man First Version + */ +#ifndef _SYS_IOCTL_H +#define _SYS_IOCTL_H + +#include +#ifdef RT_USING_POSIX +#include +#endif + +#endif diff --git a/components/libc/compilers/common/all/sys/mman.h b/components/libc/compilers/common/all/sys/mman.h new file mode 100644 index 0000000000..a9235d61f0 --- /dev/null +++ b/components/libc/compilers/common/all/sys/mman.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/11/30 Bernard The first version. + */ + +#ifndef _SYS_MMAN_H +#define _SYS_MMAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define MAP_FAILED ((void *) -1) + +#define MAP_SHARED 0x01 +#define MAP_PRIVATE 0x02 +#define MAP_TYPE 0x0f +#define MAP_FIXED 0x10 +#define MAP_ANON 0x20 +#define MAP_ANONYMOUS MAP_ANON +#define MAP_NORESERVE 0x4000 +#define MAP_GROWSDOWN 0x0100 +#define MAP_DENYWRITE 0x0800 +#define MAP_EXECUTABLE 0x1000 +#define MAP_LOCKED 0x2000 +#define MAP_POPULATE 0x8000 +#define MAP_NONBLOCK 0x10000 +#define MAP_STACK 0x20000 +#define MAP_HUGETLB 0x40000 +#define MAP_FILE 0 + +#define PROT_NONE 0 +#define PROT_READ 1 +#define PROT_WRITE 2 +#define PROT_EXEC 4 +#define PROT_GROWSDOWN 0x01000000 +#define PROT_GROWSUP 0x02000000 + +#define MS_ASYNC 1 +#define MS_INVALIDATE 2 +#define MS_SYNC 4 + +#define MCL_CURRENT 1 +#define MCL_FUTURE 2 +#define MCL_ONFAULT 4 + +void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off); +int munmap (void *start, size_t len); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/components/libc/compilers/common/all/sys/statfs.h b/components/libc/compilers/common/all/sys/statfs.h new file mode 100644 index 0000000000..0996af9a18 --- /dev/null +++ b/components/libc/compilers/common/all/sys/statfs.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef __RTT_STATFS_H__ +#define __RTT_STATFS_H__ + +#include + +struct statfs +{ + rt_size_t f_bsize; /* block size */ + rt_size_t f_blocks; /* total data blocks in file system */ + rt_size_t f_bfree; /* free blocks in file system */ +}; + +#endif diff --git a/components/libc/compilers/common/all/sys/termios.h b/components/libc/compilers/common/all/sys/termios.h new file mode 100644 index 0000000000..c4b42083c4 --- /dev/null +++ b/components/libc/compilers/common/all/sys/termios.h @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ diff --git a/components/libc/compilers/common/all/sys/time.h b/components/libc/compilers/common/all/sys/time.h new file mode 100644 index 0000000000..ef1c810608 --- /dev/null +++ b/components/libc/compilers/common/all/sys/time.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-07 Meco Man combine gcc armcc iccarm + * 2021-02-12 Meco Man move all definitions located in to this file + */ +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001. + */ +#if defined ( __ICCARM__ ) && (__VER__ >= 8010001) +#define _TIMESPEC_DEFINED +#endif + + +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED +/* + * Structure returned by gettimeofday(2) system call, + * and used in other calls. + */ +#if !(defined(_WIN32)) +struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ +}; +#endif +#endif /* _TIMEVAL_DEFINED */ + +#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !defined (__ICCARM__) && !defined (_WIN32) +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +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); +#if defined(__ARMCC_VERSION) || defined (__ICCARM__) +struct tm *gmtime_r(const time_t *timep, struct tm *r); +#endif + +#ifdef RT_USING_POSIX +#include +/* posix clock and timer */ +#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) + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 1 +#endif + +#define CLOCK_CPUTIME_ID 2 + +#ifndef CLOCK_PROCESS_CPUTIME_ID +#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID +#endif +#ifndef CLOCK_THREAD_CPUTIME_ID +#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID +#endif + +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 4 +#endif + +int clock_getres (clockid_t clockid, struct timespec *res); +int clock_gettime (clockid_t clockid, struct timespec *tp); +int clock_settime (clockid_t clockid, const struct timespec *tp); +int clock_time_to_tick(const struct timespec *time); +#endif /* RT_USING_POSIX */ + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS_TIME_H_ */ diff --git a/components/libc/compilers/common/all/termios.h b/components/libc/compilers/common/all/termios.h new file mode 100644 index 0000000000..2960d52c58 --- /dev/null +++ b/components/libc/compilers/common/all/termios.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef _TERMIOS_H__ +#define _TERMIOS_H__ + +#include + +#ifdef RT_USING_POSIX_TERMIOS +#include +#include +#endif + +#endif diff --git a/components/libc/compilers/common/all/time.c b/components/libc/compilers/common/all/time.c new file mode 100644 index 0000000000..33d8907165 --- /dev/null +++ b/components/libc/compilers/common/all/time.c @@ -0,0 +1,643 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 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() + * 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 + * 2021-02-12 Meco Man add errno + * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, + * which found by Rob + * 2021-02-12 Meco Man move all of the functions located in to this file + * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html + */ + +#include +#include + +#ifdef RT_USING_DEVICE +#include +#endif + +#define DBG_TAG "TIME" +#define DBG_LVL DBG_INFO +#include + +/* seconds per day */ +#define SPD 24*60*60 + +/* days per month -- nonleap! */ +static const short __spm[13] = +{ + 0, + (31), + (31 + 28), + (31 + 28 + 31), + (31 + 28 + 31 + 30), + (31 + 28 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), +}; + +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) +{ + /* every fourth year is a leap year except for century years that are + * not divisible by 400. */ + /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */ + return (!(year % 4) && ((year % 100) || !(year % 400))); +} + +static void num2str(char *c, int i) +{ + c[0] = i / 10 + '0'; + c[1] = i % 10 + '0'; +} + +/** + * Get time from RTC device (without timezone) + * @param tv: struct timeval + * @return -1 failure; 1 success + */ +static int get_timeval(struct timeval *tv) +{ +#ifdef RT_USING_RTC + static rt_device_t device = RT_NULL; + rt_err_t rst = -RT_ERROR; + + if (tv == RT_NULL) + return -1; + + /* default is 0 */ + tv->tv_sec = 0; + tv->tv_usec = 0; + + /* optimization: find rtc device only first */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } + + /* read timestamp from RTC device */ + if (device != RT_NULL) + { + if (rt_device_open(device, 0) == RT_EOK) + { + rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); + rt_device_close(device); + } + } + else + { + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + return -1; + } + + return (rst < 0) ? -1 : 1; + +#else + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + return -1; +#endif /* RT_USING_RTC */ +} + +/** + * Set time to RTC device (without timezone) + * @param tv: struct timeval + * @return -1 failure; 1 success + */ +static int set_timeval(struct timeval *tv) +{ +#ifdef RT_USING_RTC + static rt_device_t device = RT_NULL; + rt_err_t rst = -RT_ERROR; + + if (tv == RT_NULL) + return -1; + + /* optimization: find rtc device only first */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } + + /* read timestamp from RTC device */ + if (device != RT_NULL) + { + if (rt_device_open(device, 0) == RT_EOK) + { + rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec); + rt_device_close(device); + } + } + else + { + LOG_W("Cannot find a RTC device to provide time!"); + return -1; + } + + return (rst < 0) ? -1 : 1; + +#else + LOG_W("Cannot find a RTC device to provide time!"); + return -1; +#endif /* RT_USING_RTC */ +} + +struct tm *gmtime_r(const time_t *timep, struct tm *r) +{ + time_t i; + register time_t work = *timep % (SPD); + r->tm_sec = work % 60; + work /= 60; + r->tm_min = work % 60; + r->tm_hour = work / 60; + work = *timep / (SPD); + r->tm_wday = (4 + work) % 7; + for (i = 1970;; ++i) + { + register time_t k = __isleap(i) ? 366 : 365; + if (work >= k) + work -= k; + else + break; + } + r->tm_year = i - 1900; + r->tm_yday = work; + + r->tm_mday = 1; + if (__isleap(i) && (work > 58)) + { + if (work == 59) + r->tm_mday = 2; /* 29.2. */ + work -= 1; + } + + for (i = 11; i && (__spm[i] > work); --i) + ; + r->tm_mon = i; + r->tm_mday += work - __spm[i]; + + r->tm_isdst = 0; + return r; +} +RTM_EXPORT(gmtime_r); + +struct tm* gmtime(const time_t* t) +{ + static struct tm tmp; + return gmtime_r(t, &tmp); +} +RTM_EXPORT(gmtime); + +/*TODO: timezone */ +struct tm* localtime_r(const time_t* t, struct tm* r) +{ + time_t local_tz; + int utc_plus; + + utc_plus = 8; /* GMT: UTC+8 */ + local_tz = *t + utc_plus * 3600; + return gmtime_r(&local_tz, r); +} +RTM_EXPORT(localtime_r); + +struct tm* localtime(const time_t* t) +{ + static struct tm tmp; + return localtime_r(t, &tmp); +} +RTM_EXPORT(localtime); + +/* TODO: timezone */ +time_t mktime(struct tm * const t) +{ + time_t timestamp; + int utc_plus; + + utc_plus = 8; /* GMT: UTC+8 */ + timestamp = timegm(t); + timestamp = timestamp - 3600 * utc_plus; + return timestamp; +} +RTM_EXPORT(mktime); + +char* asctime_r(const struct tm *t, char *buf) +{ + /* "Wed Jun 30 21:49:08 1993\n" */ + *(int*) buf = *(int*) (days + (t->tm_wday << 2)); + *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); + num2str(buf + 8, t->tm_mday); + if (buf[8] == '0') + buf[8] = ' '; + buf[10] = ' '; + num2str(buf + 11, t->tm_hour); + buf[13] = ':'; + num2str(buf + 14, t->tm_min); + buf[16] = ':'; + num2str(buf + 17, t->tm_sec); + buf[19] = ' '; + num2str(buf + 20, (t->tm_year + 1900) / 100); + num2str(buf + 22, (t->tm_year + 1900) % 100); + buf[24] = '\n'; + buf[25] = '\0'; + return buf; +} +RTM_EXPORT(asctime_r); + +char* asctime(const struct tm *timeptr) +{ + static char buf[26]; + return asctime_r(timeptr, buf); +} +RTM_EXPORT(asctime); + +char *ctime_r (const time_t * tim_p, char * result) +{ + struct tm tm; + return asctime_r (localtime_r (tim_p, &tm), result); +} +RTM_EXPORT(ctime_r); + +char* ctime(const time_t *tim_p) +{ + return asctime (localtime (tim_p)); +} +RTM_EXPORT(ctime); + +/** + * Returns the current time. + * + * @param time_t * t the timestamp pointer, if not used, keep NULL. + * + * @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) +{ + struct timeval now; + + if(get_timeval(&now) > 0) + { + if (t) + { + *t = now.tv_sec; + } + return now.tv_sec; + } + else + { + errno = EFAULT; + return ((time_t)-1); + } +} +RTM_EXPORT(time); + +RT_WEAK clock_t clock(void) +{ + return rt_tick_get(); +} +RTM_EXPORT(clock); + +int stime(const time_t *t) +{ + struct timeval tv; + + if (!t) + { + errno = EFAULT; + return -1; + } + + tv.tv_sec = *t; + if (set_timeval(&tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(stime); + +time_t timegm(struct tm * const t) +{ + register time_t day; + register time_t i; + register time_t years = t->tm_year - 70; + + if (t->tm_sec > 60) + { + t->tm_min += t->tm_sec / 60; + t->tm_sec %= 60; + } + if (t->tm_min > 60) + { + t->tm_hour += t->tm_min / 60; + t->tm_min %= 60; + } + if (t->tm_hour > 24) + { + t->tm_mday += t->tm_hour / 24; + t->tm_hour %= 24; + } + if (t->tm_mon > 12) + { + t->tm_year += t->tm_mon / 12; + t->tm_mon %= 12; + } + while (t->tm_mday > __spm[1 + t->tm_mon]) + { + if (t->tm_mon == 1 && __isleap(t->tm_year + 1900)) + { + --t->tm_mday; + } + t->tm_mday -= __spm[t->tm_mon]; + ++t->tm_mon; + if (t->tm_mon > 11) + { + t->tm_mon = 0; + ++t->tm_year; + } + } + + if (t->tm_year < 70) + return (time_t) - 1; + + /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ + day = years * 365 + (years + 1) / 4; + + /* After 2100 we have to substract 3 leap years for every 400 years + This is not intuitive. Most mktime implementations do not support + dates after 2059, anyway, so we might leave this out for it's + bloat. */ + if (years >= 131) + { + years -= 131; + years /= 100; + day -= (years >> 2) * 3 + 1; + if ((years &= 3) == 3) + years--; + day -= years; + } + + day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 + + (__isleap(t->tm_year + 1900) & (t->tm_mon > 1)); + + /* day is now the number of days since 'Jan 1 1970' */ + i = 7; + t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ + + i = 24; + day *= i; + i = 60; + return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; +} +RTM_EXPORT(timegm); + +/* TODO: timezone */ +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + if (tv != RT_NULL && get_timeval(tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(gettimeofday); + +/* TODO: timezone */ +int settimeofday(const struct timeval *tv, const struct timezone *tz) +{ + if (tv != RT_NULL) + { + if(tv->tv_sec >= 0 && tv->tv_usec >= 0) + { + if(set_timeval((struct timeval *)tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } + } + else + { + errno = EINVAL; + return -1; + } + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(settimeofday); + +/* inherent in the toolchain */ +RTM_EXPORT(difftime); +RTM_EXPORT(strftime); + +#ifdef RT_USING_POSIX +static struct timeval _timevalue; +static int clock_time_system_init() +{ + 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 = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; + _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; + + return 0; +} +INIT_COMPONENT_EXPORT(clock_time_system_init); + +int clock_getres(clockid_t clockid, struct timespec *res) +{ + int ret = 0; + + if (res == RT_NULL) + { + rt_set_errno(EINVAL); + return -1; + } + + switch (clockid) + { + case CLOCK_REALTIME: + res->tv_sec = 0; + res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND; + break; + +#ifdef RT_USING_CPUTIME + case CLOCK_CPUTIME_ID: + res->tv_sec = 0; + res->tv_nsec = clock_cpu_getres(); + break; +#endif + + default: + ret = -1; + rt_set_errno(EINVAL); + break; + } + + return ret; +} +RTM_EXPORT(clock_getres); + +int clock_gettime(clockid_t clockid, struct timespec *tp) +{ + int ret = 0; + + if (tp == RT_NULL) + { + rt_set_errno(EINVAL); + return -1; + } + + switch (clockid) + { + case CLOCK_REALTIME: + { + /* get tick */ + int tick = rt_tick_get(); + + tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; + tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; + } + break; + +#ifdef RT_USING_CPUTIME + case CLOCK_CPUTIME_ID: + { + float unit = 0; + long long cpu_tick; + + unit = clock_cpu_getres(); + cpu_tick = clock_cpu_gettime(); + + tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND; + tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND; + } + break; +#endif + default: + rt_set_errno(EINVAL); + ret = -1; + } + + return ret; +} +RTM_EXPORT(clock_gettime); + +int clock_settime(clockid_t clockid, const struct timespec *tp) +{ + int second; + rt_tick_t tick; + rt_device_t device; + + if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) + { + rt_set_errno(EINVAL); + + return -1; + } + + /* get second */ + second = tp->tv_sec; + /* get tick */ + tick = rt_tick_get(); + + /* update timevalue */ + _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; + _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; + + /* update for RTC device */ + device = rt_device_find("rtc"); + if (device != RT_NULL) + { + /* set realtime seconds */ + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); + } + else + return -1; + + return 0; +} +RTM_EXPORT(clock_settime); + +int clock_time_to_tick(const struct timespec *time) +{ + int tick; + int nsecond, second; + struct timespec tp; + + RT_ASSERT(time != RT_NULL); + + tick = RT_WAITING_FOREVER; + if (time != NULL) + { + /* get current tp */ + clock_gettime(CLOCK_REALTIME, &tp); + + if ((time->tv_nsec - tp.tv_nsec) < 0) + { + nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec); + second = time->tv_sec - tp.tv_sec - 1; + } + else + { + nsecond = time->tv_nsec - tp.tv_nsec; + second = time->tv_sec - tp.tv_sec; + } + + tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND; + if (tick < 0) tick = 0; + } + + return tick; +} +RTM_EXPORT(clock_time_to_tick); + +#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/common/all/unistd.c b/components/libc/compilers/common/all/unistd.c new file mode 100644 index 0000000000..20130cbb8a --- /dev/null +++ b/components/libc/compilers/common/all/unistd.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-01 Meco Man first Version + * 2021-02-12 Meco Man move all functions located in to this file + */ + +#include +#include +#include + +#ifdef RT_USING_POSIX_TERMIOS +#include "termios.h" + +int isatty(int fd) +{ + struct termios ts; + return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/ +} +RTM_EXPORT(isatty); +#endif + +char *ttyname(int fd) +{ + return "/dev/tty0"; /*TODO: need to add more specific*/ +} +RTM_EXPORT(ttyname); + +unsigned int sleep(unsigned int seconds) +{ + rt_tick_t delta_tick; + + delta_tick = rt_tick_get(); + rt_thread_delay(seconds * RT_TICK_PER_SECOND); + delta_tick = rt_tick_get() - delta_tick; + + return seconds - delta_tick/RT_TICK_PER_SECOND; +} +RTM_EXPORT(sleep); + +int usleep(useconds_t usec) +{ + rt_thread_mdelay(usec / 1000u); + rt_hw_us_delay(usec % 1000u); + return 0; +} +RTM_EXPORT(usleep); + +pid_t getpid(void) +{ + /*TODO*/ + return 0; +} +RTM_EXPORT(getpid); + +pid_t getppid(void) +{ + return 0; +} +RTM_EXPORT(getppid); + +uid_t getuid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getuid); + +uid_t geteuid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(geteuid); + +gid_t getgid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getgid); + +gid_t getegid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getegid); diff --git a/components/libc/compilers/common/excgcc/SConscript b/components/libc/compilers/common/excgcc/SConscript new file mode 100644 index 0000000000..346e69b478 --- /dev/null +++ b/components/libc/compilers/common/excgcc/SConscript @@ -0,0 +1,13 @@ +from building import * + +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +CPPPATH = [cwd] +group = [] +src += Glob('*.c') + +if rtconfig.PLATFORM != 'gcc': + group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH) +Return('group') diff --git a/components/libc/compilers/common/excgcc/fcntl.h b/components/libc/compilers/common/excgcc/fcntl.h new file mode 100644 index 0000000000..f247b926e9 --- /dev/null +++ b/components/libc/compilers/common/excgcc/fcntl.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef FCNTL_H__ +#define FCNTL_H__ + +#include + +#ifdef RT_USING_DFS +#include +#endif + +#endif diff --git a/components/libc/compilers/common/excgcc/readme.md b/components/libc/compilers/common/excgcc/readme.md new file mode 100644 index 0000000000..15f8e60d59 --- /dev/null +++ b/components/libc/compilers/common/excgcc/readme.md @@ -0,0 +1,3 @@ +## Attentions + +This folder is "common" for armlibc and dlib. \ No newline at end of file diff --git a/components/libc/compilers/common/excgcc/sys/stat.h b/components/libc/compilers/common/excgcc/sys/stat.h new file mode 100644 index 0000000000..c4b42083c4 --- /dev/null +++ b/components/libc/compilers/common/excgcc/sys/stat.h @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ diff --git a/components/libc/compilers/common/excgcc/sys/types.h b/components/libc/compilers/common/excgcc/sys/types.h new file mode 100644 index 0000000000..7222326a2a --- /dev/null +++ b/components/libc/compilers/common/excgcc/sys/types.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-05 Meco Man fix bugs + * 2020-12-16 Meco Man add useconds_t + */ +#ifndef __TYPES_H__ +#define __TYPES_H__ + +#include + +typedef int32_t clockid_t; +typedef int32_t key_t; /* Used for interprocess communication. */ +typedef int pid_t; /* Used for process IDs and process group IDs. */ +typedef unsigned short uid_t; +typedef unsigned short gid_t; +typedef signed long off_t; +typedef int mode_t; +#ifndef ARCH_CPU_64BIT +typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ +#else +typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ +#endif +typedef unsigned long useconds_t; /* microseconds (unsigned) */ + +typedef unsigned long dev_t; + +typedef unsigned int u_int; +typedef unsigned char u_char; +typedef unsigned long u_long; + +#endif diff --git a/components/libc/compilers/common/excgcc/sys/unistd.h b/components/libc/compilers/common/excgcc/sys/unistd.h new file mode 100644 index 0000000000..7752a1caf7 --- /dev/null +++ b/components/libc/compilers/common/excgcc/sys/unistd.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-12-16 Meco Man add usleep + */ +#ifndef _SYS_UNISTD_H +#define _SYS_UNISTD_H + +#include +#include "types.h" + +#ifdef RT_USING_DFS + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +#include +#else +#define _FREAD 0x0001 /* read enabled */ +#define _FWRITE 0x0002 /* write enabled */ +#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ +#define _FMARK 0x0010 /* internal; mark during gc() */ +#define _FDEFER 0x0020 /* internal; defer for next gc pass */ +#define _FASYNC 0x0040 /* signal pgrp when data ready */ +#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ +#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ +#define _FCREAT 0x0200 /* open with file create */ +#define _FTRUNC 0x0400 /* open with truncation */ +#define _FEXCL 0x0800 /* error on open if file exists */ +#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ +#define _FSYNC 0x2000 /* do all writes synchronously */ +#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ +#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ +#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ + + +#ifndef O_RDONLY +#define O_RDONLY 0 /* +1 == FREAD */ +#endif +#ifndef O_WRONLY +#define O_WRONLY 1 /* +1 == FWRITE */ +#endif +#ifndef O_RDWR +#define O_RDWR 2 /* +1 == FREAD|FWRITE */ +#endif +#ifndef O_APPEND +#define O_APPEND _FAPPEND +#endif +#ifndef O_CREAT +#define O_CREAT _FCREAT +#endif +#ifndef O_TRUNC +#define O_TRUNC _FTRUNC +#endif +#ifndef O_EXCL +#define O_EXCL _FEXCL +#endif +#ifndef O_SYNC +#define O_SYNC _FSYNC +#endif + +#endif + + +int isatty (int fd); +char * ttyname (int desc); + +unsigned int sleep(unsigned int seconds); +int usleep(useconds_t usec); + +pid_t getpid(void); +pid_t getppid(void); +uid_t getuid(void); +uid_t geteuid(void); +gid_t getgid(void); +gid_t getegid(void); + +#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common/excgcc/unistd.h b/components/libc/compilers/common/excgcc/unistd.h new file mode 100644 index 0000000000..cd77a12e3b --- /dev/null +++ b/components/libc/compilers/common/excgcc/unistd.h @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#include "sys/unistd.h" + diff --git a/components/libc/compilers/common_all/SConscript b/components/libc/compilers/common_all/SConscript deleted file mode 100644 index 319e1a3555..0000000000 --- a/components/libc/compilers/common_all/SConscript +++ /dev/null @@ -1,27 +0,0 @@ -from building import * - -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -group = [] -CPPPATH = [cwd] - -if GetDepend('RT_USING_LIBC'): - src += Glob('*.c') -else: - if GetDepend('RT_LIBC_USING_TIME'): - src += ['time.c'] - -if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) - -if rtconfig.CROSS_TOOL == 'keil': - CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND'] -else: - CPPDEFINES = [] - -if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): - group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) - -Return('group') diff --git a/components/libc/compilers/common_all/dirent.h b/components/libc/compilers/common_all/dirent.h deleted file mode 100644 index bfba586093..0000000000 --- a/components/libc/compilers/common_all/dirent.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __RTT_DIRENT_H__ -#define __RTT_DIRENT_H__ - -#include - -/* -* dirent.h - format of directory entries - * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html - */ - -/* File types */ -#define FT_REGULAR 0 /* regular file */ -#define FT_SOCKET 1 /* socket file */ -#define FT_DIRECTORY 2 /* directory */ -#define FT_USER 3 /* user defined */ - -#define DT_UNKNOWN 0x00 -#define DT_REG 0x01 -#define DT_DIR 0x02 - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef HAVE_DIR_STRUCTURE -typedef struct -{ - int fd; /* directory file */ - char buf[512]; - int num; - int cur; -} DIR; -#endif - -#ifndef HAVE_DIRENT_STRUCTURE -struct dirent -{ - rt_uint8_t d_type; /* The type of the file */ - rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ - rt_uint16_t d_reclen; /* length of this record */ - char d_name[256]; /* The null-terminated file name */ -}; -#endif - -int closedir(DIR *); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); -void rewinddir(DIR *); -void seekdir(DIR *, long int); -long telldir(DIR *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/common_all/readme.md b/components/libc/compilers/common_all/readme.md deleted file mode 100644 index 81bb005d0a..0000000000 --- a/components/libc/compilers/common_all/readme.md +++ /dev/null @@ -1,10 +0,0 @@ -## Attentions - -1. This folder is "common" for armlibc newlibc and dlib. - -2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg: - -```python -if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) -``` \ No newline at end of file diff --git a/components/libc/compilers/common_all/stdlib.c b/components/libc/compilers/common_all/stdlib.c deleted file mode 100644 index 9d8952e99e..0000000000 --- a/components/libc/compilers/common_all/stdlib.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-02-15 Meco Man first version - */ - -#include - -void __rt_libc_exit(int status) -{ - rt_thread_t self = rt_thread_self(); - - if (self != RT_NULL) - { - rt_kprintf("thread:%s exit:%d!\n", self->name, status); - rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL); - } -} - -int __rt_libc_system(const char *string) -{ - /* TODO */ - return 0; -} diff --git a/components/libc/compilers/common_all/sys/ioctl.h b/components/libc/compilers/common_all/sys/ioctl.h deleted file mode 100644 index 648d90230d..0000000000 --- a/components/libc/compilers/common_all/sys/ioctl.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-01 Meco Man First Version - */ -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H - -#include -#ifdef RT_USING_POSIX -#include -#endif - -#endif diff --git a/components/libc/compilers/common_all/sys/mman.h b/components/libc/compilers/common_all/sys/mman.h deleted file mode 100644 index a9235d61f0..0000000000 --- a/components/libc/compilers/common_all/sys/mman.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/11/30 Bernard The first version. - */ - -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define MAP_FAILED ((void *) -1) - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_TYPE 0x0f -#define MAP_FIXED 0x10 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_NORESERVE 0x4000 -#define MAP_GROWSDOWN 0x0100 -#define MAP_DENYWRITE 0x0800 -#define MAP_EXECUTABLE 0x1000 -#define MAP_LOCKED 0x2000 -#define MAP_POPULATE 0x8000 -#define MAP_NONBLOCK 0x10000 -#define MAP_STACK 0x20000 -#define MAP_HUGETLB 0x40000 -#define MAP_FILE 0 - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 -#define MCL_ONFAULT 4 - -void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off); -int munmap (void *start, size_t len); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/components/libc/compilers/common_all/sys/statfs.h b/components/libc/compilers/common_all/sys/statfs.h deleted file mode 100644 index 0996af9a18..0000000000 --- a/components/libc/compilers/common_all/sys/statfs.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __RTT_STATFS_H__ -#define __RTT_STATFS_H__ - -#include - -struct statfs -{ - rt_size_t f_bsize; /* block size */ - rt_size_t f_blocks; /* total data blocks in file system */ - rt_size_t f_bfree; /* free blocks in file system */ -}; - -#endif diff --git a/components/libc/compilers/common_all/sys/termios.h b/components/libc/compilers/common_all/sys/termios.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/common_all/sys/termios.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/components/libc/compilers/common_all/sys/time.h b/components/libc/compilers/common_all/sys/time.h deleted file mode 100644 index ef1c810608..0000000000 --- a/components/libc/compilers/common_all/sys/time.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-07 Meco Man combine gcc armcc iccarm - * 2021-02-12 Meco Man move all definitions located in to this file - */ -#ifndef _SYS_TIME_H_ -#define _SYS_TIME_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001. - */ -#if defined ( __ICCARM__ ) && (__VER__ >= 8010001) -#define _TIMESPEC_DEFINED -#endif - - -#ifndef _TIMEVAL_DEFINED -#define _TIMEVAL_DEFINED -/* - * Structure returned by gettimeofday(2) system call, - * and used in other calls. - */ -#if !(defined(_WIN32)) -struct timeval { - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; -#endif -#endif /* _TIMEVAL_DEFINED */ - -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !defined (__ICCARM__) && !defined (_WIN32) -struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* and nanoseconds */ -}; -#endif - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - -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); -#if defined(__ARMCC_VERSION) || defined (__ICCARM__) -struct tm *gmtime_r(const time_t *timep, struct tm *r); -#endif - -#ifdef RT_USING_POSIX -#include -/* posix clock and timer */ -#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) - -#ifndef CLOCK_REALTIME -#define CLOCK_REALTIME 1 -#endif - -#define CLOCK_CPUTIME_ID 2 - -#ifndef CLOCK_PROCESS_CPUTIME_ID -#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID -#endif -#ifndef CLOCK_THREAD_CPUTIME_ID -#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID -#endif - -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC 4 -#endif - -int clock_getres (clockid_t clockid, struct timespec *res); -int clock_gettime (clockid_t clockid, struct timespec *tp); -int clock_settime (clockid_t clockid, const struct timespec *tp); -int clock_time_to_tick(const struct timespec *time); -#endif /* RT_USING_POSIX */ - -#ifdef __cplusplus -} -#endif - -#endif /* _SYS_TIME_H_ */ diff --git a/components/libc/compilers/common_all/termios.h b/components/libc/compilers/common_all/termios.h deleted file mode 100644 index 2960d52c58..0000000000 --- a/components/libc/compilers/common_all/termios.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef _TERMIOS_H__ -#define _TERMIOS_H__ - -#include - -#ifdef RT_USING_POSIX_TERMIOS -#include -#include -#endif - -#endif diff --git a/components/libc/compilers/common_all/time.c b/components/libc/compilers/common_all/time.c deleted file mode 100644 index 33d8907165..0000000000 --- a/components/libc/compilers/common_all/time.c +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 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() - * 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 - * 2021-02-12 Meco Man add errno - * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, - * which found by Rob - * 2021-02-12 Meco Man move all of the functions located in to this file - * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html - */ - -#include -#include - -#ifdef RT_USING_DEVICE -#include -#endif - -#define DBG_TAG "TIME" -#define DBG_LVL DBG_INFO -#include - -/* seconds per day */ -#define SPD 24*60*60 - -/* days per month -- nonleap! */ -static const short __spm[13] = -{ - 0, - (31), - (31 + 28), - (31 + 28 + 31), - (31 + 28 + 31 + 30), - (31 + 28 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), -}; - -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) -{ - /* every fourth year is a leap year except for century years that are - * not divisible by 400. */ - /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */ - return (!(year % 4) && ((year % 100) || !(year % 400))); -} - -static void num2str(char *c, int i) -{ - c[0] = i / 10 + '0'; - c[1] = i % 10 + '0'; -} - -/** - * Get time from RTC device (without timezone) - * @param tv: struct timeval - * @return -1 failure; 1 success - */ -static int get_timeval(struct timeval *tv) -{ -#ifdef RT_USING_RTC - static rt_device_t device = RT_NULL; - rt_err_t rst = -RT_ERROR; - - if (tv == RT_NULL) - return -1; - - /* default is 0 */ - tv->tv_sec = 0; - tv->tv_usec = 0; - - /* optimization: find rtc device only first */ - if (device == RT_NULL) - { - device = rt_device_find("rtc"); - } - - /* read timestamp from RTC device */ - if (device != RT_NULL) - { - if (rt_device_open(device, 0) == RT_EOK) - { - rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); - rt_device_close(device); - } - } - else - { - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - return -1; - } - - return (rst < 0) ? -1 : 1; - -#else - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - return -1; -#endif /* RT_USING_RTC */ -} - -/** - * Set time to RTC device (without timezone) - * @param tv: struct timeval - * @return -1 failure; 1 success - */ -static int set_timeval(struct timeval *tv) -{ -#ifdef RT_USING_RTC - static rt_device_t device = RT_NULL; - rt_err_t rst = -RT_ERROR; - - if (tv == RT_NULL) - return -1; - - /* optimization: find rtc device only first */ - if (device == RT_NULL) - { - device = rt_device_find("rtc"); - } - - /* read timestamp from RTC device */ - if (device != RT_NULL) - { - if (rt_device_open(device, 0) == RT_EOK) - { - rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec); - rt_device_close(device); - } - } - else - { - LOG_W("Cannot find a RTC device to provide time!"); - return -1; - } - - return (rst < 0) ? -1 : 1; - -#else - LOG_W("Cannot find a RTC device to provide time!"); - return -1; -#endif /* RT_USING_RTC */ -} - -struct tm *gmtime_r(const time_t *timep, struct tm *r) -{ - time_t i; - register time_t work = *timep % (SPD); - r->tm_sec = work % 60; - work /= 60; - r->tm_min = work % 60; - r->tm_hour = work / 60; - work = *timep / (SPD); - r->tm_wday = (4 + work) % 7; - for (i = 1970;; ++i) - { - register time_t k = __isleap(i) ? 366 : 365; - if (work >= k) - work -= k; - else - break; - } - r->tm_year = i - 1900; - r->tm_yday = work; - - r->tm_mday = 1; - if (__isleap(i) && (work > 58)) - { - if (work == 59) - r->tm_mday = 2; /* 29.2. */ - work -= 1; - } - - for (i = 11; i && (__spm[i] > work); --i) - ; - r->tm_mon = i; - r->tm_mday += work - __spm[i]; - - r->tm_isdst = 0; - return r; -} -RTM_EXPORT(gmtime_r); - -struct tm* gmtime(const time_t* t) -{ - static struct tm tmp; - return gmtime_r(t, &tmp); -} -RTM_EXPORT(gmtime); - -/*TODO: timezone */ -struct tm* localtime_r(const time_t* t, struct tm* r) -{ - time_t local_tz; - int utc_plus; - - utc_plus = 8; /* GMT: UTC+8 */ - local_tz = *t + utc_plus * 3600; - return gmtime_r(&local_tz, r); -} -RTM_EXPORT(localtime_r); - -struct tm* localtime(const time_t* t) -{ - static struct tm tmp; - return localtime_r(t, &tmp); -} -RTM_EXPORT(localtime); - -/* TODO: timezone */ -time_t mktime(struct tm * const t) -{ - time_t timestamp; - int utc_plus; - - utc_plus = 8; /* GMT: UTC+8 */ - timestamp = timegm(t); - timestamp = timestamp - 3600 * utc_plus; - return timestamp; -} -RTM_EXPORT(mktime); - -char* asctime_r(const struct tm *t, char *buf) -{ - /* "Wed Jun 30 21:49:08 1993\n" */ - *(int*) buf = *(int*) (days + (t->tm_wday << 2)); - *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); - num2str(buf + 8, t->tm_mday); - if (buf[8] == '0') - buf[8] = ' '; - buf[10] = ' '; - num2str(buf + 11, t->tm_hour); - buf[13] = ':'; - num2str(buf + 14, t->tm_min); - buf[16] = ':'; - num2str(buf + 17, t->tm_sec); - buf[19] = ' '; - num2str(buf + 20, (t->tm_year + 1900) / 100); - num2str(buf + 22, (t->tm_year + 1900) % 100); - buf[24] = '\n'; - buf[25] = '\0'; - return buf; -} -RTM_EXPORT(asctime_r); - -char* asctime(const struct tm *timeptr) -{ - static char buf[26]; - return asctime_r(timeptr, buf); -} -RTM_EXPORT(asctime); - -char *ctime_r (const time_t * tim_p, char * result) -{ - struct tm tm; - return asctime_r (localtime_r (tim_p, &tm), result); -} -RTM_EXPORT(ctime_r); - -char* ctime(const time_t *tim_p) -{ - return asctime (localtime (tim_p)); -} -RTM_EXPORT(ctime); - -/** - * Returns the current time. - * - * @param time_t * t the timestamp pointer, if not used, keep NULL. - * - * @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) -{ - struct timeval now; - - if(get_timeval(&now) > 0) - { - if (t) - { - *t = now.tv_sec; - } - return now.tv_sec; - } - else - { - errno = EFAULT; - return ((time_t)-1); - } -} -RTM_EXPORT(time); - -RT_WEAK clock_t clock(void) -{ - return rt_tick_get(); -} -RTM_EXPORT(clock); - -int stime(const time_t *t) -{ - struct timeval tv; - - if (!t) - { - errno = EFAULT; - return -1; - } - - tv.tv_sec = *t; - if (set_timeval(&tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(stime); - -time_t timegm(struct tm * const t) -{ - register time_t day; - register time_t i; - register time_t years = t->tm_year - 70; - - if (t->tm_sec > 60) - { - t->tm_min += t->tm_sec / 60; - t->tm_sec %= 60; - } - if (t->tm_min > 60) - { - t->tm_hour += t->tm_min / 60; - t->tm_min %= 60; - } - if (t->tm_hour > 24) - { - t->tm_mday += t->tm_hour / 24; - t->tm_hour %= 24; - } - if (t->tm_mon > 12) - { - t->tm_year += t->tm_mon / 12; - t->tm_mon %= 12; - } - while (t->tm_mday > __spm[1 + t->tm_mon]) - { - if (t->tm_mon == 1 && __isleap(t->tm_year + 1900)) - { - --t->tm_mday; - } - t->tm_mday -= __spm[t->tm_mon]; - ++t->tm_mon; - if (t->tm_mon > 11) - { - t->tm_mon = 0; - ++t->tm_year; - } - } - - if (t->tm_year < 70) - return (time_t) - 1; - - /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ - day = years * 365 + (years + 1) / 4; - - /* After 2100 we have to substract 3 leap years for every 400 years - This is not intuitive. Most mktime implementations do not support - dates after 2059, anyway, so we might leave this out for it's - bloat. */ - if (years >= 131) - { - years -= 131; - years /= 100; - day -= (years >> 2) * 3 + 1; - if ((years &= 3) == 3) - years--; - day -= years; - } - - day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 + - (__isleap(t->tm_year + 1900) & (t->tm_mon > 1)); - - /* day is now the number of days since 'Jan 1 1970' */ - i = 7; - t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ - - i = 24; - day *= i; - i = 60; - return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; -} -RTM_EXPORT(timegm); - -/* TODO: timezone */ -int gettimeofday(struct timeval *tv, struct timezone *tz) -{ - if (tv != RT_NULL && get_timeval(tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(gettimeofday); - -/* TODO: timezone */ -int settimeofday(const struct timeval *tv, const struct timezone *tz) -{ - if (tv != RT_NULL) - { - if(tv->tv_sec >= 0 && tv->tv_usec >= 0) - { - if(set_timeval((struct timeval *)tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } - } - else - { - errno = EINVAL; - return -1; - } - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(settimeofday); - -/* inherent in the toolchain */ -RTM_EXPORT(difftime); -RTM_EXPORT(strftime); - -#ifdef RT_USING_POSIX -static struct timeval _timevalue; -static int clock_time_system_init() -{ - 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 = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; - - return 0; -} -INIT_COMPONENT_EXPORT(clock_time_system_init); - -int clock_getres(clockid_t clockid, struct timespec *res) -{ - int ret = 0; - - if (res == RT_NULL) - { - rt_set_errno(EINVAL); - return -1; - } - - switch (clockid) - { - case CLOCK_REALTIME: - res->tv_sec = 0; - res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND; - break; - -#ifdef RT_USING_CPUTIME - case CLOCK_CPUTIME_ID: - res->tv_sec = 0; - res->tv_nsec = clock_cpu_getres(); - break; -#endif - - default: - ret = -1; - rt_set_errno(EINVAL); - break; - } - - return ret; -} -RTM_EXPORT(clock_getres); - -int clock_gettime(clockid_t clockid, struct timespec *tp) -{ - int ret = 0; - - if (tp == RT_NULL) - { - rt_set_errno(EINVAL); - return -1; - } - - switch (clockid) - { - case CLOCK_REALTIME: - { - /* get tick */ - int tick = rt_tick_get(); - - tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; - tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; - } - break; - -#ifdef RT_USING_CPUTIME - case CLOCK_CPUTIME_ID: - { - float unit = 0; - long long cpu_tick; - - unit = clock_cpu_getres(); - cpu_tick = clock_cpu_gettime(); - - tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND; - tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND; - } - break; -#endif - default: - rt_set_errno(EINVAL); - ret = -1; - } - - return ret; -} -RTM_EXPORT(clock_gettime); - -int clock_settime(clockid_t clockid, const struct timespec *tp) -{ - int second; - rt_tick_t tick; - rt_device_t device; - - if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) - { - rt_set_errno(EINVAL); - - return -1; - } - - /* get second */ - second = tp->tv_sec; - /* get tick */ - tick = rt_tick_get(); - - /* update timevalue */ - _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; - - /* update for RTC device */ - device = rt_device_find("rtc"); - if (device != RT_NULL) - { - /* set realtime seconds */ - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); - } - else - return -1; - - return 0; -} -RTM_EXPORT(clock_settime); - -int clock_time_to_tick(const struct timespec *time) -{ - int tick; - int nsecond, second; - struct timespec tp; - - RT_ASSERT(time != RT_NULL); - - tick = RT_WAITING_FOREVER; - if (time != NULL) - { - /* get current tp */ - clock_gettime(CLOCK_REALTIME, &tp); - - if ((time->tv_nsec - tp.tv_nsec) < 0) - { - nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec); - second = time->tv_sec - tp.tv_sec - 1; - } - else - { - nsecond = time->tv_nsec - tp.tv_nsec; - second = time->tv_sec - tp.tv_sec; - } - - tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND; - if (tick < 0) tick = 0; - } - - return tick; -} -RTM_EXPORT(clock_time_to_tick); - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/common_all/unistd.c b/components/libc/compilers/common_all/unistd.c deleted file mode 100644 index 20130cbb8a..0000000000 --- a/components/libc/compilers/common_all/unistd.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-01 Meco Man first Version - * 2021-02-12 Meco Man move all functions located in to this file - */ - -#include -#include -#include - -#ifdef RT_USING_POSIX_TERMIOS -#include "termios.h" - -int isatty(int fd) -{ - struct termios ts; - return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/ -} -RTM_EXPORT(isatty); -#endif - -char *ttyname(int fd) -{ - return "/dev/tty0"; /*TODO: need to add more specific*/ -} -RTM_EXPORT(ttyname); - -unsigned int sleep(unsigned int seconds) -{ - rt_tick_t delta_tick; - - delta_tick = rt_tick_get(); - rt_thread_delay(seconds * RT_TICK_PER_SECOND); - delta_tick = rt_tick_get() - delta_tick; - - return seconds - delta_tick/RT_TICK_PER_SECOND; -} -RTM_EXPORT(sleep); - -int usleep(useconds_t usec) -{ - rt_thread_mdelay(usec / 1000u); - rt_hw_us_delay(usec % 1000u); - return 0; -} -RTM_EXPORT(usleep); - -pid_t getpid(void) -{ - /*TODO*/ - return 0; -} -RTM_EXPORT(getpid); - -pid_t getppid(void) -{ - return 0; -} -RTM_EXPORT(getppid); - -uid_t getuid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getuid); - -uid_t geteuid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(geteuid); - -gid_t getgid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getgid); - -gid_t getegid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getegid); diff --git a/components/libc/compilers/common_except_gcc/SConscript b/components/libc/compilers/common_except_gcc/SConscript deleted file mode 100644 index 346e69b478..0000000000 --- a/components/libc/compilers/common_except_gcc/SConscript +++ /dev/null @@ -1,13 +0,0 @@ -from building import * - -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -CPPPATH = [cwd] -group = [] -src += Glob('*.c') - -if rtconfig.PLATFORM != 'gcc': - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH) -Return('group') diff --git a/components/libc/compilers/common_except_gcc/fcntl.h b/components/libc/compilers/common_except_gcc/fcntl.h deleted file mode 100644 index f247b926e9..0000000000 --- a/components/libc/compilers/common_except_gcc/fcntl.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef FCNTL_H__ -#define FCNTL_H__ - -#include - -#ifdef RT_USING_DFS -#include -#endif - -#endif diff --git a/components/libc/compilers/common_except_gcc/readme.md b/components/libc/compilers/common_except_gcc/readme.md deleted file mode 100644 index 15f8e60d59..0000000000 --- a/components/libc/compilers/common_except_gcc/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -## Attentions - -This folder is "common" for armlibc and dlib. \ No newline at end of file diff --git a/components/libc/compilers/common_except_gcc/sys/stat.h b/components/libc/compilers/common_except_gcc/sys/stat.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/common_except_gcc/sys/stat.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/components/libc/compilers/common_except_gcc/sys/types.h b/components/libc/compilers/common_except_gcc/sys/types.h deleted file mode 100644 index 7222326a2a..0000000000 --- a/components/libc/compilers/common_except_gcc/sys/types.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-05 Meco Man fix bugs - * 2020-12-16 Meco Man add useconds_t - */ -#ifndef __TYPES_H__ -#define __TYPES_H__ - -#include - -typedef int32_t clockid_t; -typedef int32_t key_t; /* Used for interprocess communication. */ -typedef int pid_t; /* Used for process IDs and process group IDs. */ -typedef unsigned short uid_t; -typedef unsigned short gid_t; -typedef signed long off_t; -typedef int mode_t; -#ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#endif -typedef unsigned long useconds_t; /* microseconds (unsigned) */ - -typedef unsigned long dev_t; - -typedef unsigned int u_int; -typedef unsigned char u_char; -typedef unsigned long u_long; - -#endif diff --git a/components/libc/compilers/common_except_gcc/sys/unistd.h b/components/libc/compilers/common_except_gcc/sys/unistd.h deleted file mode 100644 index 7752a1caf7..0000000000 --- a/components/libc/compilers/common_except_gcc/sys/unistd.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-12-16 Meco Man add usleep - */ -#ifndef _SYS_UNISTD_H -#define _SYS_UNISTD_H - -#include -#include "types.h" - -#ifdef RT_USING_DFS - -#define STDIN_FILENO 0 /* standard input file descriptor */ -#define STDOUT_FILENO 1 /* standard output file descriptor */ -#define STDERR_FILENO 2 /* standard error file descriptor */ - -#include -#else -#define _FREAD 0x0001 /* read enabled */ -#define _FWRITE 0x0002 /* write enabled */ -#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ -#define _FMARK 0x0010 /* internal; mark during gc() */ -#define _FDEFER 0x0020 /* internal; defer for next gc pass */ -#define _FASYNC 0x0040 /* signal pgrp when data ready */ -#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ -#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ -#define _FCREAT 0x0200 /* open with file create */ -#define _FTRUNC 0x0400 /* open with truncation */ -#define _FEXCL 0x0800 /* error on open if file exists */ -#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ -#define _FSYNC 0x2000 /* do all writes synchronously */ -#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ -#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ -#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ - - -#ifndef O_RDONLY -#define O_RDONLY 0 /* +1 == FREAD */ -#endif -#ifndef O_WRONLY -#define O_WRONLY 1 /* +1 == FWRITE */ -#endif -#ifndef O_RDWR -#define O_RDWR 2 /* +1 == FREAD|FWRITE */ -#endif -#ifndef O_APPEND -#define O_APPEND _FAPPEND -#endif -#ifndef O_CREAT -#define O_CREAT _FCREAT -#endif -#ifndef O_TRUNC -#define O_TRUNC _FTRUNC -#endif -#ifndef O_EXCL -#define O_EXCL _FEXCL -#endif -#ifndef O_SYNC -#define O_SYNC _FSYNC -#endif - -#endif - - -int isatty (int fd); -char * ttyname (int desc); - -unsigned int sleep(unsigned int seconds); -int usleep(useconds_t usec); - -pid_t getpid(void); -pid_t getppid(void); -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); - -#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common_except_gcc/unistd.h b/components/libc/compilers/common_except_gcc/unistd.h deleted file mode 100644 index cd77a12e3b..0000000000 --- a/components/libc/compilers/common_except_gcc/unistd.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#include "sys/unistd.h" - diff --git a/include/rtlibc.h b/include/rtlibc.h index 6f6777a2f3..50bddc6ee8 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -23,6 +23,13 @@ #include "libc/libc_limits.h" #include "libc/libc_stdio.h" +#ifndef RT_USING_LIBC +#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) +typedef signed long off_t; +typedef int mode_t; +#endif +#endif + #if defined(__MINGW32__) || defined(_WIN32) typedef signed long off_t; typedef int mode_t; -- cgit v1.3.1 From c871726e8930099efc1bbade8907e8b4571615eb Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 21 Apr 2021 02:16:29 +0800 Subject: update readme --- components/libc/compilers/common/all/readme.md | 2 +- components/libc/compilers/common/excgcc/readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/all/readme.md b/components/libc/compilers/common/all/readme.md index 81bb005d0a..856ddeb045 100644 --- a/components/libc/compilers/common/all/readme.md +++ b/components/libc/compilers/common/all/readme.md @@ -1,6 +1,6 @@ ## Attentions -1. This folder is "common" for armlibc newlibc and dlib. +1. This folder is "common" for all toolchains. 2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg: diff --git a/components/libc/compilers/common/excgcc/readme.md b/components/libc/compilers/common/excgcc/readme.md index 15f8e60d59..b10940d003 100644 --- a/components/libc/compilers/common/excgcc/readme.md +++ b/components/libc/compilers/common/excgcc/readme.md @@ -1,3 +1,3 @@ ## Attentions -This folder is "common" for armlibc and dlib. \ No newline at end of file +This folder is "common" for toolchains excluding gcc. \ No newline at end of file -- cgit v1.3.1 From f9ba41f4c22855b4dff8c422283ea6832ad1fc2b Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 25 Apr 2021 21:10:31 +0800 Subject: 更改libc目录为common 以及 none-gcc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/SConscript | 34 +- components/libc/compilers/common/all/SConscript | 27 - components/libc/compilers/common/all/dirent.h | 65 --- components/libc/compilers/common/all/readme.md | 10 - components/libc/compilers/common/all/stdlib.c | 28 - components/libc/compilers/common/all/sys/ioctl.h | 18 - components/libc/compilers/common/all/sys/mman.h | 60 -- components/libc/compilers/common/all/sys/statfs.h | 21 - components/libc/compilers/common/all/sys/termios.h | 8 - components/libc/compilers/common/all/sys/time.h | 101 ---- components/libc/compilers/common/all/termios.h | 19 - components/libc/compilers/common/all/time.c | 643 --------------------- components/libc/compilers/common/all/unistd.c | 88 --- components/libc/compilers/common/dirent.h | 65 +++ components/libc/compilers/common/excgcc/SConscript | 13 - components/libc/compilers/common/excgcc/fcntl.h | 18 - components/libc/compilers/common/excgcc/readme.md | 3 - components/libc/compilers/common/excgcc/sys/stat.h | 8 - .../libc/compilers/common/excgcc/sys/types.h | 36 -- .../libc/compilers/common/excgcc/sys/unistd.h | 83 --- components/libc/compilers/common/excgcc/unistd.h | 10 - .../libc/compilers/common/none-gcc/SConscript | 13 + components/libc/compilers/common/none-gcc/fcntl.h | 18 + .../libc/compilers/common/none-gcc/readme.md | 3 + .../libc/compilers/common/none-gcc/sys/stat.h | 8 + .../libc/compilers/common/none-gcc/sys/types.h | 36 ++ .../libc/compilers/common/none-gcc/sys/unistd.h | 83 +++ components/libc/compilers/common/none-gcc/unistd.h | 10 + components/libc/compilers/common/readme.md | 10 + components/libc/compilers/common/stdlib.c | 28 + components/libc/compilers/common/sys/ioctl.h | 18 + components/libc/compilers/common/sys/mman.h | 60 ++ components/libc/compilers/common/sys/statfs.h | 21 + components/libc/compilers/common/sys/termios.h | 8 + components/libc/compilers/common/sys/time.h | 101 ++++ components/libc/compilers/common/termios.h | 19 + components/libc/compilers/common/time.c | 643 +++++++++++++++++++++ components/libc/compilers/common/unistd.c | 88 +++ 38 files changed, 1255 insertions(+), 1270 deletions(-) delete mode 100644 components/libc/compilers/common/all/SConscript delete mode 100644 components/libc/compilers/common/all/dirent.h delete mode 100644 components/libc/compilers/common/all/readme.md delete mode 100644 components/libc/compilers/common/all/stdlib.c delete mode 100644 components/libc/compilers/common/all/sys/ioctl.h delete mode 100644 components/libc/compilers/common/all/sys/mman.h delete mode 100644 components/libc/compilers/common/all/sys/statfs.h delete mode 100644 components/libc/compilers/common/all/sys/termios.h delete mode 100644 components/libc/compilers/common/all/sys/time.h delete mode 100644 components/libc/compilers/common/all/termios.h delete mode 100644 components/libc/compilers/common/all/time.c delete mode 100644 components/libc/compilers/common/all/unistd.c create mode 100644 components/libc/compilers/common/dirent.h delete mode 100644 components/libc/compilers/common/excgcc/SConscript delete mode 100644 components/libc/compilers/common/excgcc/fcntl.h delete mode 100644 components/libc/compilers/common/excgcc/readme.md delete mode 100644 components/libc/compilers/common/excgcc/sys/stat.h delete mode 100644 components/libc/compilers/common/excgcc/sys/types.h delete mode 100644 components/libc/compilers/common/excgcc/sys/unistd.h delete mode 100644 components/libc/compilers/common/excgcc/unistd.h create mode 100644 components/libc/compilers/common/none-gcc/SConscript create mode 100644 components/libc/compilers/common/none-gcc/fcntl.h create mode 100644 components/libc/compilers/common/none-gcc/readme.md create mode 100644 components/libc/compilers/common/none-gcc/sys/stat.h create mode 100644 components/libc/compilers/common/none-gcc/sys/types.h create mode 100644 components/libc/compilers/common/none-gcc/sys/unistd.h create mode 100644 components/libc/compilers/common/none-gcc/unistd.h create mode 100644 components/libc/compilers/common/readme.md create mode 100644 components/libc/compilers/common/stdlib.c create mode 100644 components/libc/compilers/common/sys/ioctl.h create mode 100644 components/libc/compilers/common/sys/mman.h create mode 100644 components/libc/compilers/common/sys/statfs.h create mode 100644 components/libc/compilers/common/sys/termios.h create mode 100644 components/libc/compilers/common/sys/time.h create mode 100644 components/libc/compilers/common/termios.h create mode 100644 components/libc/compilers/common/time.c create mode 100644 components/libc/compilers/common/unistd.c (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 4c815c49b8..319e1a3555 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -1,15 +1,27 @@ -# RT-Thread building script for bridge - -import os from building import * -cwd = GetCurrentDir() -objs = [] -list = os.listdir(cwd) +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +group = [] +CPPPATH = [cwd] + +if GetDepend('RT_USING_LIBC'): + src += Glob('*.c') +else: + if GetDepend('RT_LIBC_USING_TIME'): + src += ['time.c'] + +if GetDepend('RT_USING_POSIX') == False: + SrcRemove(src, ['unistd.c']) + +if rtconfig.CROSS_TOOL == 'keil': + CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND'] +else: + CPPDEFINES = [] -for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(d, 'SConscript')) +if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): + group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) -Return('objs') +Return('group') diff --git a/components/libc/compilers/common/all/SConscript b/components/libc/compilers/common/all/SConscript deleted file mode 100644 index 319e1a3555..0000000000 --- a/components/libc/compilers/common/all/SConscript +++ /dev/null @@ -1,27 +0,0 @@ -from building import * - -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -group = [] -CPPPATH = [cwd] - -if GetDepend('RT_USING_LIBC'): - src += Glob('*.c') -else: - if GetDepend('RT_LIBC_USING_TIME'): - src += ['time.c'] - -if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) - -if rtconfig.CROSS_TOOL == 'keil': - CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND'] -else: - CPPDEFINES = [] - -if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): - group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) - -Return('group') diff --git a/components/libc/compilers/common/all/dirent.h b/components/libc/compilers/common/all/dirent.h deleted file mode 100644 index bfba586093..0000000000 --- a/components/libc/compilers/common/all/dirent.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __RTT_DIRENT_H__ -#define __RTT_DIRENT_H__ - -#include - -/* -* dirent.h - format of directory entries - * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html - */ - -/* File types */ -#define FT_REGULAR 0 /* regular file */ -#define FT_SOCKET 1 /* socket file */ -#define FT_DIRECTORY 2 /* directory */ -#define FT_USER 3 /* user defined */ - -#define DT_UNKNOWN 0x00 -#define DT_REG 0x01 -#define DT_DIR 0x02 - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef HAVE_DIR_STRUCTURE -typedef struct -{ - int fd; /* directory file */ - char buf[512]; - int num; - int cur; -} DIR; -#endif - -#ifndef HAVE_DIRENT_STRUCTURE -struct dirent -{ - rt_uint8_t d_type; /* The type of the file */ - rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ - rt_uint16_t d_reclen; /* length of this record */ - char d_name[256]; /* The null-terminated file name */ -}; -#endif - -int closedir(DIR *); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -int readdir_r(DIR *, struct dirent *, struct dirent **); -void rewinddir(DIR *); -void seekdir(DIR *, long int); -long telldir(DIR *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/common/all/readme.md b/components/libc/compilers/common/all/readme.md deleted file mode 100644 index 856ddeb045..0000000000 --- a/components/libc/compilers/common/all/readme.md +++ /dev/null @@ -1,10 +0,0 @@ -## Attentions - -1. This folder is "common" for all toolchains. - -2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg: - -```python -if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) -``` \ No newline at end of file diff --git a/components/libc/compilers/common/all/stdlib.c b/components/libc/compilers/common/all/stdlib.c deleted file mode 100644 index 9d8952e99e..0000000000 --- a/components/libc/compilers/common/all/stdlib.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2021-02-15 Meco Man first version - */ - -#include - -void __rt_libc_exit(int status) -{ - rt_thread_t self = rt_thread_self(); - - if (self != RT_NULL) - { - rt_kprintf("thread:%s exit:%d!\n", self->name, status); - rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL); - } -} - -int __rt_libc_system(const char *string) -{ - /* TODO */ - return 0; -} diff --git a/components/libc/compilers/common/all/sys/ioctl.h b/components/libc/compilers/common/all/sys/ioctl.h deleted file mode 100644 index 648d90230d..0000000000 --- a/components/libc/compilers/common/all/sys/ioctl.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-01 Meco Man First Version - */ -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H - -#include -#ifdef RT_USING_POSIX -#include -#endif - -#endif diff --git a/components/libc/compilers/common/all/sys/mman.h b/components/libc/compilers/common/all/sys/mman.h deleted file mode 100644 index a9235d61f0..0000000000 --- a/components/libc/compilers/common/all/sys/mman.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/11/30 Bernard The first version. - */ - -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define MAP_FAILED ((void *) -1) - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_TYPE 0x0f -#define MAP_FIXED 0x10 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_NORESERVE 0x4000 -#define MAP_GROWSDOWN 0x0100 -#define MAP_DENYWRITE 0x0800 -#define MAP_EXECUTABLE 0x1000 -#define MAP_LOCKED 0x2000 -#define MAP_POPULATE 0x8000 -#define MAP_NONBLOCK 0x10000 -#define MAP_STACK 0x20000 -#define MAP_HUGETLB 0x40000 -#define MAP_FILE 0 - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 -#define MCL_ONFAULT 4 - -void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off); -int munmap (void *start, size_t len); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/components/libc/compilers/common/all/sys/statfs.h b/components/libc/compilers/common/all/sys/statfs.h deleted file mode 100644 index 0996af9a18..0000000000 --- a/components/libc/compilers/common/all/sys/statfs.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __RTT_STATFS_H__ -#define __RTT_STATFS_H__ - -#include - -struct statfs -{ - rt_size_t f_bsize; /* block size */ - rt_size_t f_blocks; /* total data blocks in file system */ - rt_size_t f_bfree; /* free blocks in file system */ -}; - -#endif diff --git a/components/libc/compilers/common/all/sys/termios.h b/components/libc/compilers/common/all/sys/termios.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/common/all/sys/termios.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/components/libc/compilers/common/all/sys/time.h b/components/libc/compilers/common/all/sys/time.h deleted file mode 100644 index ef1c810608..0000000000 --- a/components/libc/compilers/common/all/sys/time.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-07 Meco Man combine gcc armcc iccarm - * 2021-02-12 Meco Man move all definitions located in to this file - */ -#ifndef _SYS_TIME_H_ -#define _SYS_TIME_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001. - */ -#if defined ( __ICCARM__ ) && (__VER__ >= 8010001) -#define _TIMESPEC_DEFINED -#endif - - -#ifndef _TIMEVAL_DEFINED -#define _TIMEVAL_DEFINED -/* - * Structure returned by gettimeofday(2) system call, - * and used in other calls. - */ -#if !(defined(_WIN32)) -struct timeval { - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; -#endif -#endif /* _TIMEVAL_DEFINED */ - -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !defined (__ICCARM__) && !defined (_WIN32) -struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* and nanoseconds */ -}; -#endif - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - -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); -#if defined(__ARMCC_VERSION) || defined (__ICCARM__) -struct tm *gmtime_r(const time_t *timep, struct tm *r); -#endif - -#ifdef RT_USING_POSIX -#include -/* posix clock and timer */ -#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) - -#ifndef CLOCK_REALTIME -#define CLOCK_REALTIME 1 -#endif - -#define CLOCK_CPUTIME_ID 2 - -#ifndef CLOCK_PROCESS_CPUTIME_ID -#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID -#endif -#ifndef CLOCK_THREAD_CPUTIME_ID -#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID -#endif - -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC 4 -#endif - -int clock_getres (clockid_t clockid, struct timespec *res); -int clock_gettime (clockid_t clockid, struct timespec *tp); -int clock_settime (clockid_t clockid, const struct timespec *tp); -int clock_time_to_tick(const struct timespec *time); -#endif /* RT_USING_POSIX */ - -#ifdef __cplusplus -} -#endif - -#endif /* _SYS_TIME_H_ */ diff --git a/components/libc/compilers/common/all/termios.h b/components/libc/compilers/common/all/termios.h deleted file mode 100644 index 2960d52c58..0000000000 --- a/components/libc/compilers/common/all/termios.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef _TERMIOS_H__ -#define _TERMIOS_H__ - -#include - -#ifdef RT_USING_POSIX_TERMIOS -#include -#include -#endif - -#endif diff --git a/components/libc/compilers/common/all/time.c b/components/libc/compilers/common/all/time.c deleted file mode 100644 index 33d8907165..0000000000 --- a/components/libc/compilers/common/all/time.c +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 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() - * 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 - * 2021-02-12 Meco Man add errno - * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, - * which found by Rob - * 2021-02-12 Meco Man move all of the functions located in to this file - * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html - */ - -#include -#include - -#ifdef RT_USING_DEVICE -#include -#endif - -#define DBG_TAG "TIME" -#define DBG_LVL DBG_INFO -#include - -/* seconds per day */ -#define SPD 24*60*60 - -/* days per month -- nonleap! */ -static const short __spm[13] = -{ - 0, - (31), - (31 + 28), - (31 + 28 + 31), - (31 + 28 + 31 + 30), - (31 + 28 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30), - (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), -}; - -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) -{ - /* every fourth year is a leap year except for century years that are - * not divisible by 400. */ - /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */ - return (!(year % 4) && ((year % 100) || !(year % 400))); -} - -static void num2str(char *c, int i) -{ - c[0] = i / 10 + '0'; - c[1] = i % 10 + '0'; -} - -/** - * Get time from RTC device (without timezone) - * @param tv: struct timeval - * @return -1 failure; 1 success - */ -static int get_timeval(struct timeval *tv) -{ -#ifdef RT_USING_RTC - static rt_device_t device = RT_NULL; - rt_err_t rst = -RT_ERROR; - - if (tv == RT_NULL) - return -1; - - /* default is 0 */ - tv->tv_sec = 0; - tv->tv_usec = 0; - - /* optimization: find rtc device only first */ - if (device == RT_NULL) - { - device = rt_device_find("rtc"); - } - - /* read timestamp from RTC device */ - if (device != RT_NULL) - { - if (rt_device_open(device, 0) == RT_EOK) - { - rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); - rt_device_close(device); - } - } - else - { - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - return -1; - } - - return (rst < 0) ? -1 : 1; - -#else - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - return -1; -#endif /* RT_USING_RTC */ -} - -/** - * Set time to RTC device (without timezone) - * @param tv: struct timeval - * @return -1 failure; 1 success - */ -static int set_timeval(struct timeval *tv) -{ -#ifdef RT_USING_RTC - static rt_device_t device = RT_NULL; - rt_err_t rst = -RT_ERROR; - - if (tv == RT_NULL) - return -1; - - /* optimization: find rtc device only first */ - if (device == RT_NULL) - { - device = rt_device_find("rtc"); - } - - /* read timestamp from RTC device */ - if (device != RT_NULL) - { - if (rt_device_open(device, 0) == RT_EOK) - { - rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec); - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec); - rt_device_close(device); - } - } - else - { - LOG_W("Cannot find a RTC device to provide time!"); - return -1; - } - - return (rst < 0) ? -1 : 1; - -#else - LOG_W("Cannot find a RTC device to provide time!"); - return -1; -#endif /* RT_USING_RTC */ -} - -struct tm *gmtime_r(const time_t *timep, struct tm *r) -{ - time_t i; - register time_t work = *timep % (SPD); - r->tm_sec = work % 60; - work /= 60; - r->tm_min = work % 60; - r->tm_hour = work / 60; - work = *timep / (SPD); - r->tm_wday = (4 + work) % 7; - for (i = 1970;; ++i) - { - register time_t k = __isleap(i) ? 366 : 365; - if (work >= k) - work -= k; - else - break; - } - r->tm_year = i - 1900; - r->tm_yday = work; - - r->tm_mday = 1; - if (__isleap(i) && (work > 58)) - { - if (work == 59) - r->tm_mday = 2; /* 29.2. */ - work -= 1; - } - - for (i = 11; i && (__spm[i] > work); --i) - ; - r->tm_mon = i; - r->tm_mday += work - __spm[i]; - - r->tm_isdst = 0; - return r; -} -RTM_EXPORT(gmtime_r); - -struct tm* gmtime(const time_t* t) -{ - static struct tm tmp; - return gmtime_r(t, &tmp); -} -RTM_EXPORT(gmtime); - -/*TODO: timezone */ -struct tm* localtime_r(const time_t* t, struct tm* r) -{ - time_t local_tz; - int utc_plus; - - utc_plus = 8; /* GMT: UTC+8 */ - local_tz = *t + utc_plus * 3600; - return gmtime_r(&local_tz, r); -} -RTM_EXPORT(localtime_r); - -struct tm* localtime(const time_t* t) -{ - static struct tm tmp; - return localtime_r(t, &tmp); -} -RTM_EXPORT(localtime); - -/* TODO: timezone */ -time_t mktime(struct tm * const t) -{ - time_t timestamp; - int utc_plus; - - utc_plus = 8; /* GMT: UTC+8 */ - timestamp = timegm(t); - timestamp = timestamp - 3600 * utc_plus; - return timestamp; -} -RTM_EXPORT(mktime); - -char* asctime_r(const struct tm *t, char *buf) -{ - /* "Wed Jun 30 21:49:08 1993\n" */ - *(int*) buf = *(int*) (days + (t->tm_wday << 2)); - *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); - num2str(buf + 8, t->tm_mday); - if (buf[8] == '0') - buf[8] = ' '; - buf[10] = ' '; - num2str(buf + 11, t->tm_hour); - buf[13] = ':'; - num2str(buf + 14, t->tm_min); - buf[16] = ':'; - num2str(buf + 17, t->tm_sec); - buf[19] = ' '; - num2str(buf + 20, (t->tm_year + 1900) / 100); - num2str(buf + 22, (t->tm_year + 1900) % 100); - buf[24] = '\n'; - buf[25] = '\0'; - return buf; -} -RTM_EXPORT(asctime_r); - -char* asctime(const struct tm *timeptr) -{ - static char buf[26]; - return asctime_r(timeptr, buf); -} -RTM_EXPORT(asctime); - -char *ctime_r (const time_t * tim_p, char * result) -{ - struct tm tm; - return asctime_r (localtime_r (tim_p, &tm), result); -} -RTM_EXPORT(ctime_r); - -char* ctime(const time_t *tim_p) -{ - return asctime (localtime (tim_p)); -} -RTM_EXPORT(ctime); - -/** - * Returns the current time. - * - * @param time_t * t the timestamp pointer, if not used, keep NULL. - * - * @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) -{ - struct timeval now; - - if(get_timeval(&now) > 0) - { - if (t) - { - *t = now.tv_sec; - } - return now.tv_sec; - } - else - { - errno = EFAULT; - return ((time_t)-1); - } -} -RTM_EXPORT(time); - -RT_WEAK clock_t clock(void) -{ - return rt_tick_get(); -} -RTM_EXPORT(clock); - -int stime(const time_t *t) -{ - struct timeval tv; - - if (!t) - { - errno = EFAULT; - return -1; - } - - tv.tv_sec = *t; - if (set_timeval(&tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(stime); - -time_t timegm(struct tm * const t) -{ - register time_t day; - register time_t i; - register time_t years = t->tm_year - 70; - - if (t->tm_sec > 60) - { - t->tm_min += t->tm_sec / 60; - t->tm_sec %= 60; - } - if (t->tm_min > 60) - { - t->tm_hour += t->tm_min / 60; - t->tm_min %= 60; - } - if (t->tm_hour > 24) - { - t->tm_mday += t->tm_hour / 24; - t->tm_hour %= 24; - } - if (t->tm_mon > 12) - { - t->tm_year += t->tm_mon / 12; - t->tm_mon %= 12; - } - while (t->tm_mday > __spm[1 + t->tm_mon]) - { - if (t->tm_mon == 1 && __isleap(t->tm_year + 1900)) - { - --t->tm_mday; - } - t->tm_mday -= __spm[t->tm_mon]; - ++t->tm_mon; - if (t->tm_mon > 11) - { - t->tm_mon = 0; - ++t->tm_year; - } - } - - if (t->tm_year < 70) - return (time_t) - 1; - - /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ - day = years * 365 + (years + 1) / 4; - - /* After 2100 we have to substract 3 leap years for every 400 years - This is not intuitive. Most mktime implementations do not support - dates after 2059, anyway, so we might leave this out for it's - bloat. */ - if (years >= 131) - { - years -= 131; - years /= 100; - day -= (years >> 2) * 3 + 1; - if ((years &= 3) == 3) - years--; - day -= years; - } - - day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 + - (__isleap(t->tm_year + 1900) & (t->tm_mon > 1)); - - /* day is now the number of days since 'Jan 1 1970' */ - i = 7; - t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ - - i = 24; - day *= i; - i = 60; - return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; -} -RTM_EXPORT(timegm); - -/* TODO: timezone */ -int gettimeofday(struct timeval *tv, struct timezone *tz) -{ - if (tv != RT_NULL && get_timeval(tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(gettimeofday); - -/* TODO: timezone */ -int settimeofday(const struct timeval *tv, const struct timezone *tz) -{ - if (tv != RT_NULL) - { - if(tv->tv_sec >= 0 && tv->tv_usec >= 0) - { - if(set_timeval((struct timeval *)tv) > 0) - { - return 0; - } - else - { - errno = EFAULT; - return -1; - } - } - else - { - errno = EINVAL; - return -1; - } - } - else - { - errno = EFAULT; - return -1; - } -} -RTM_EXPORT(settimeofday); - -/* inherent in the toolchain */ -RTM_EXPORT(difftime); -RTM_EXPORT(strftime); - -#ifdef RT_USING_POSIX -static struct timeval _timevalue; -static int clock_time_system_init() -{ - 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 = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; - - return 0; -} -INIT_COMPONENT_EXPORT(clock_time_system_init); - -int clock_getres(clockid_t clockid, struct timespec *res) -{ - int ret = 0; - - if (res == RT_NULL) - { - rt_set_errno(EINVAL); - return -1; - } - - switch (clockid) - { - case CLOCK_REALTIME: - res->tv_sec = 0; - res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND; - break; - -#ifdef RT_USING_CPUTIME - case CLOCK_CPUTIME_ID: - res->tv_sec = 0; - res->tv_nsec = clock_cpu_getres(); - break; -#endif - - default: - ret = -1; - rt_set_errno(EINVAL); - break; - } - - return ret; -} -RTM_EXPORT(clock_getres); - -int clock_gettime(clockid_t clockid, struct timespec *tp) -{ - int ret = 0; - - if (tp == RT_NULL) - { - rt_set_errno(EINVAL); - return -1; - } - - switch (clockid) - { - case CLOCK_REALTIME: - { - /* get tick */ - int tick = rt_tick_get(); - - tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; - tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; - } - break; - -#ifdef RT_USING_CPUTIME - case CLOCK_CPUTIME_ID: - { - float unit = 0; - long long cpu_tick; - - unit = clock_cpu_getres(); - cpu_tick = clock_cpu_gettime(); - - tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND; - tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND; - } - break; -#endif - default: - rt_set_errno(EINVAL); - ret = -1; - } - - return ret; -} -RTM_EXPORT(clock_gettime); - -int clock_settime(clockid_t clockid, const struct timespec *tp) -{ - int second; - rt_tick_t tick; - rt_device_t device; - - if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) - { - rt_set_errno(EINVAL); - - return -1; - } - - /* get second */ - second = tp->tv_sec; - /* get tick */ - tick = rt_tick_get(); - - /* update timevalue */ - _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; - - /* update for RTC device */ - device = rt_device_find("rtc"); - if (device != RT_NULL) - { - /* set realtime seconds */ - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); - } - else - return -1; - - return 0; -} -RTM_EXPORT(clock_settime); - -int clock_time_to_tick(const struct timespec *time) -{ - int tick; - int nsecond, second; - struct timespec tp; - - RT_ASSERT(time != RT_NULL); - - tick = RT_WAITING_FOREVER; - if (time != NULL) - { - /* get current tp */ - clock_gettime(CLOCK_REALTIME, &tp); - - if ((time->tv_nsec - tp.tv_nsec) < 0) - { - nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec); - second = time->tv_sec - tp.tv_sec - 1; - } - else - { - nsecond = time->tv_nsec - tp.tv_nsec; - second = time->tv_sec - tp.tv_sec; - } - - tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND; - if (tick < 0) tick = 0; - } - - return tick; -} -RTM_EXPORT(clock_time_to_tick); - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/common/all/unistd.c b/components/libc/compilers/common/all/unistd.c deleted file mode 100644 index 20130cbb8a..0000000000 --- a/components/libc/compilers/common/all/unistd.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-01 Meco Man first Version - * 2021-02-12 Meco Man move all functions located in to this file - */ - -#include -#include -#include - -#ifdef RT_USING_POSIX_TERMIOS -#include "termios.h" - -int isatty(int fd) -{ - struct termios ts; - return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/ -} -RTM_EXPORT(isatty); -#endif - -char *ttyname(int fd) -{ - return "/dev/tty0"; /*TODO: need to add more specific*/ -} -RTM_EXPORT(ttyname); - -unsigned int sleep(unsigned int seconds) -{ - rt_tick_t delta_tick; - - delta_tick = rt_tick_get(); - rt_thread_delay(seconds * RT_TICK_PER_SECOND); - delta_tick = rt_tick_get() - delta_tick; - - return seconds - delta_tick/RT_TICK_PER_SECOND; -} -RTM_EXPORT(sleep); - -int usleep(useconds_t usec) -{ - rt_thread_mdelay(usec / 1000u); - rt_hw_us_delay(usec % 1000u); - return 0; -} -RTM_EXPORT(usleep); - -pid_t getpid(void) -{ - /*TODO*/ - return 0; -} -RTM_EXPORT(getpid); - -pid_t getppid(void) -{ - return 0; -} -RTM_EXPORT(getppid); - -uid_t getuid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getuid); - -uid_t geteuid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(geteuid); - -gid_t getgid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getgid); - -gid_t getegid(void) -{ - return 0; /*ROOT*/ -} -RTM_EXPORT(getegid); diff --git a/components/libc/compilers/common/dirent.h b/components/libc/compilers/common/dirent.h new file mode 100644 index 0000000000..bfba586093 --- /dev/null +++ b/components/libc/compilers/common/dirent.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef __RTT_DIRENT_H__ +#define __RTT_DIRENT_H__ + +#include + +/* +* dirent.h - format of directory entries + * Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html + */ + +/* File types */ +#define FT_REGULAR 0 /* regular file */ +#define FT_SOCKET 1 /* socket file */ +#define FT_DIRECTORY 2 /* directory */ +#define FT_USER 3 /* user defined */ + +#define DT_UNKNOWN 0x00 +#define DT_REG 0x01 +#define DT_DIR 0x02 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef HAVE_DIR_STRUCTURE +typedef struct +{ + int fd; /* directory file */ + char buf[512]; + int num; + int cur; +} DIR; +#endif + +#ifndef HAVE_DIRENT_STRUCTURE +struct dirent +{ + rt_uint8_t d_type; /* The type of the file */ + rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ + rt_uint16_t d_reclen; /* length of this record */ + char d_name[256]; /* The null-terminated file name */ +}; +#endif + +int closedir(DIR *); +DIR *opendir(const char *); +struct dirent *readdir(DIR *); +int readdir_r(DIR *, struct dirent *, struct dirent **); +void rewinddir(DIR *); +void seekdir(DIR *, long int); +long telldir(DIR *); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/libc/compilers/common/excgcc/SConscript b/components/libc/compilers/common/excgcc/SConscript deleted file mode 100644 index 346e69b478..0000000000 --- a/components/libc/compilers/common/excgcc/SConscript +++ /dev/null @@ -1,13 +0,0 @@ -from building import * - -Import('rtconfig') - -src = [] -cwd = GetCurrentDir() -CPPPATH = [cwd] -group = [] -src += Glob('*.c') - -if rtconfig.PLATFORM != 'gcc': - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH) -Return('group') diff --git a/components/libc/compilers/common/excgcc/fcntl.h b/components/libc/compilers/common/excgcc/fcntl.h deleted file mode 100644 index f247b926e9..0000000000 --- a/components/libc/compilers/common/excgcc/fcntl.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef FCNTL_H__ -#define FCNTL_H__ - -#include - -#ifdef RT_USING_DFS -#include -#endif - -#endif diff --git a/components/libc/compilers/common/excgcc/readme.md b/components/libc/compilers/common/excgcc/readme.md deleted file mode 100644 index b10940d003..0000000000 --- a/components/libc/compilers/common/excgcc/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -## Attentions - -This folder is "common" for toolchains excluding gcc. \ No newline at end of file diff --git a/components/libc/compilers/common/excgcc/sys/stat.h b/components/libc/compilers/common/excgcc/sys/stat.h deleted file mode 100644 index c4b42083c4..0000000000 --- a/components/libc/compilers/common/excgcc/sys/stat.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ diff --git a/components/libc/compilers/common/excgcc/sys/types.h b/components/libc/compilers/common/excgcc/sys/types.h deleted file mode 100644 index 7222326a2a..0000000000 --- a/components/libc/compilers/common/excgcc/sys/types.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-05 Meco Man fix bugs - * 2020-12-16 Meco Man add useconds_t - */ -#ifndef __TYPES_H__ -#define __TYPES_H__ - -#include - -typedef int32_t clockid_t; -typedef int32_t key_t; /* Used for interprocess communication. */ -typedef int pid_t; /* Used for process IDs and process group IDs. */ -typedef unsigned short uid_t; -typedef unsigned short gid_t; -typedef signed long off_t; -typedef int mode_t; -#ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ -#endif -typedef unsigned long useconds_t; /* microseconds (unsigned) */ - -typedef unsigned long dev_t; - -typedef unsigned int u_int; -typedef unsigned char u_char; -typedef unsigned long u_long; - -#endif diff --git a/components/libc/compilers/common/excgcc/sys/unistd.h b/components/libc/compilers/common/excgcc/sys/unistd.h deleted file mode 100644 index 7752a1caf7..0000000000 --- a/components/libc/compilers/common/excgcc/sys/unistd.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-12-16 Meco Man add usleep - */ -#ifndef _SYS_UNISTD_H -#define _SYS_UNISTD_H - -#include -#include "types.h" - -#ifdef RT_USING_DFS - -#define STDIN_FILENO 0 /* standard input file descriptor */ -#define STDOUT_FILENO 1 /* standard output file descriptor */ -#define STDERR_FILENO 2 /* standard error file descriptor */ - -#include -#else -#define _FREAD 0x0001 /* read enabled */ -#define _FWRITE 0x0002 /* write enabled */ -#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ -#define _FMARK 0x0010 /* internal; mark during gc() */ -#define _FDEFER 0x0020 /* internal; defer for next gc pass */ -#define _FASYNC 0x0040 /* signal pgrp when data ready */ -#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ -#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ -#define _FCREAT 0x0200 /* open with file create */ -#define _FTRUNC 0x0400 /* open with truncation */ -#define _FEXCL 0x0800 /* error on open if file exists */ -#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ -#define _FSYNC 0x2000 /* do all writes synchronously */ -#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ -#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ -#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ - - -#ifndef O_RDONLY -#define O_RDONLY 0 /* +1 == FREAD */ -#endif -#ifndef O_WRONLY -#define O_WRONLY 1 /* +1 == FWRITE */ -#endif -#ifndef O_RDWR -#define O_RDWR 2 /* +1 == FREAD|FWRITE */ -#endif -#ifndef O_APPEND -#define O_APPEND _FAPPEND -#endif -#ifndef O_CREAT -#define O_CREAT _FCREAT -#endif -#ifndef O_TRUNC -#define O_TRUNC _FTRUNC -#endif -#ifndef O_EXCL -#define O_EXCL _FEXCL -#endif -#ifndef O_SYNC -#define O_SYNC _FSYNC -#endif - -#endif - - -int isatty (int fd); -char * ttyname (int desc); - -unsigned int sleep(unsigned int seconds); -int usleep(useconds_t usec); - -pid_t getpid(void); -pid_t getppid(void); -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); - -#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common/excgcc/unistd.h b/components/libc/compilers/common/excgcc/unistd.h deleted file mode 100644 index cd77a12e3b..0000000000 --- a/components/libc/compilers/common/excgcc/unistd.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#include "sys/unistd.h" - diff --git a/components/libc/compilers/common/none-gcc/SConscript b/components/libc/compilers/common/none-gcc/SConscript new file mode 100644 index 0000000000..346e69b478 --- /dev/null +++ b/components/libc/compilers/common/none-gcc/SConscript @@ -0,0 +1,13 @@ +from building import * + +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +CPPPATH = [cwd] +group = [] +src += Glob('*.c') + +if rtconfig.PLATFORM != 'gcc': + group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH) +Return('group') diff --git a/components/libc/compilers/common/none-gcc/fcntl.h b/components/libc/compilers/common/none-gcc/fcntl.h new file mode 100644 index 0000000000..f247b926e9 --- /dev/null +++ b/components/libc/compilers/common/none-gcc/fcntl.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef FCNTL_H__ +#define FCNTL_H__ + +#include + +#ifdef RT_USING_DFS +#include +#endif + +#endif diff --git a/components/libc/compilers/common/none-gcc/readme.md b/components/libc/compilers/common/none-gcc/readme.md new file mode 100644 index 0000000000..b10940d003 --- /dev/null +++ b/components/libc/compilers/common/none-gcc/readme.md @@ -0,0 +1,3 @@ +## Attentions + +This folder is "common" for toolchains excluding gcc. \ No newline at end of file diff --git a/components/libc/compilers/common/none-gcc/sys/stat.h b/components/libc/compilers/common/none-gcc/sys/stat.h new file mode 100644 index 0000000000..c4b42083c4 --- /dev/null +++ b/components/libc/compilers/common/none-gcc/sys/stat.h @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ diff --git a/components/libc/compilers/common/none-gcc/sys/types.h b/components/libc/compilers/common/none-gcc/sys/types.h new file mode 100644 index 0000000000..7222326a2a --- /dev/null +++ b/components/libc/compilers/common/none-gcc/sys/types.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-05 Meco Man fix bugs + * 2020-12-16 Meco Man add useconds_t + */ +#ifndef __TYPES_H__ +#define __TYPES_H__ + +#include + +typedef int32_t clockid_t; +typedef int32_t key_t; /* Used for interprocess communication. */ +typedef int pid_t; /* Used for process IDs and process group IDs. */ +typedef unsigned short uid_t; +typedef unsigned short gid_t; +typedef signed long off_t; +typedef int mode_t; +#ifndef ARCH_CPU_64BIT +typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ +#else +typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ +#endif +typedef unsigned long useconds_t; /* microseconds (unsigned) */ + +typedef unsigned long dev_t; + +typedef unsigned int u_int; +typedef unsigned char u_char; +typedef unsigned long u_long; + +#endif diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h new file mode 100644 index 0000000000..7752a1caf7 --- /dev/null +++ b/components/libc/compilers/common/none-gcc/sys/unistd.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-12-16 Meco Man add usleep + */ +#ifndef _SYS_UNISTD_H +#define _SYS_UNISTD_H + +#include +#include "types.h" + +#ifdef RT_USING_DFS + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +#include +#else +#define _FREAD 0x0001 /* read enabled */ +#define _FWRITE 0x0002 /* write enabled */ +#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ +#define _FMARK 0x0010 /* internal; mark during gc() */ +#define _FDEFER 0x0020 /* internal; defer for next gc pass */ +#define _FASYNC 0x0040 /* signal pgrp when data ready */ +#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ +#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ +#define _FCREAT 0x0200 /* open with file create */ +#define _FTRUNC 0x0400 /* open with truncation */ +#define _FEXCL 0x0800 /* error on open if file exists */ +#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ +#define _FSYNC 0x2000 /* do all writes synchronously */ +#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ +#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ +#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ + + +#ifndef O_RDONLY +#define O_RDONLY 0 /* +1 == FREAD */ +#endif +#ifndef O_WRONLY +#define O_WRONLY 1 /* +1 == FWRITE */ +#endif +#ifndef O_RDWR +#define O_RDWR 2 /* +1 == FREAD|FWRITE */ +#endif +#ifndef O_APPEND +#define O_APPEND _FAPPEND +#endif +#ifndef O_CREAT +#define O_CREAT _FCREAT +#endif +#ifndef O_TRUNC +#define O_TRUNC _FTRUNC +#endif +#ifndef O_EXCL +#define O_EXCL _FEXCL +#endif +#ifndef O_SYNC +#define O_SYNC _FSYNC +#endif + +#endif + + +int isatty (int fd); +char * ttyname (int desc); + +unsigned int sleep(unsigned int seconds); +int usleep(useconds_t usec); + +pid_t getpid(void); +pid_t getppid(void); +uid_t getuid(void); +uid_t geteuid(void); +gid_t getgid(void); +gid_t getegid(void); + +#endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/common/none-gcc/unistd.h b/components/libc/compilers/common/none-gcc/unistd.h new file mode 100644 index 0000000000..cd77a12e3b --- /dev/null +++ b/components/libc/compilers/common/none-gcc/unistd.h @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#include "sys/unistd.h" + diff --git a/components/libc/compilers/common/readme.md b/components/libc/compilers/common/readme.md new file mode 100644 index 0000000000..856ddeb045 --- /dev/null +++ b/components/libc/compilers/common/readme.md @@ -0,0 +1,10 @@ +## Attentions + +1. This folder is "common" for all toolchains. + +2. If you want to add new `.c` files, please do not forget to fix SConscript file too. eg: + +```python +if GetDepend('RT_USING_POSIX') == False: + SrcRemove(src, ['unistd.c']) +``` \ No newline at end of file diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c new file mode 100644 index 0000000000..9d8952e99e --- /dev/null +++ b/components/libc/compilers/common/stdlib.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-02-15 Meco Man first version + */ + +#include + +void __rt_libc_exit(int status) +{ + rt_thread_t self = rt_thread_self(); + + if (self != RT_NULL) + { + rt_kprintf("thread:%s exit:%d!\n", self->name, status); + rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL); + } +} + +int __rt_libc_system(const char *string) +{ + /* TODO */ + return 0; +} diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h new file mode 100644 index 0000000000..648d90230d --- /dev/null +++ b/components/libc/compilers/common/sys/ioctl.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-01 Meco Man First Version + */ +#ifndef _SYS_IOCTL_H +#define _SYS_IOCTL_H + +#include +#ifdef RT_USING_POSIX +#include +#endif + +#endif diff --git a/components/libc/compilers/common/sys/mman.h b/components/libc/compilers/common/sys/mman.h new file mode 100644 index 0000000000..a9235d61f0 --- /dev/null +++ b/components/libc/compilers/common/sys/mman.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017/11/30 Bernard The first version. + */ + +#ifndef _SYS_MMAN_H +#define _SYS_MMAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define MAP_FAILED ((void *) -1) + +#define MAP_SHARED 0x01 +#define MAP_PRIVATE 0x02 +#define MAP_TYPE 0x0f +#define MAP_FIXED 0x10 +#define MAP_ANON 0x20 +#define MAP_ANONYMOUS MAP_ANON +#define MAP_NORESERVE 0x4000 +#define MAP_GROWSDOWN 0x0100 +#define MAP_DENYWRITE 0x0800 +#define MAP_EXECUTABLE 0x1000 +#define MAP_LOCKED 0x2000 +#define MAP_POPULATE 0x8000 +#define MAP_NONBLOCK 0x10000 +#define MAP_STACK 0x20000 +#define MAP_HUGETLB 0x40000 +#define MAP_FILE 0 + +#define PROT_NONE 0 +#define PROT_READ 1 +#define PROT_WRITE 2 +#define PROT_EXEC 4 +#define PROT_GROWSDOWN 0x01000000 +#define PROT_GROWSUP 0x02000000 + +#define MS_ASYNC 1 +#define MS_INVALIDATE 2 +#define MS_SYNC 4 + +#define MCL_CURRENT 1 +#define MCL_FUTURE 2 +#define MCL_ONFAULT 4 + +void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off); +int munmap (void *start, size_t len); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/components/libc/compilers/common/sys/statfs.h b/components/libc/compilers/common/sys/statfs.h new file mode 100644 index 0000000000..0996af9a18 --- /dev/null +++ b/components/libc/compilers/common/sys/statfs.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef __RTT_STATFS_H__ +#define __RTT_STATFS_H__ + +#include + +struct statfs +{ + rt_size_t f_bsize; /* block size */ + rt_size_t f_blocks; /* total data blocks in file system */ + rt_size_t f_bfree; /* free blocks in file system */ +}; + +#endif diff --git a/components/libc/compilers/common/sys/termios.h b/components/libc/compilers/common/sys/termios.h new file mode 100644 index 0000000000..c4b42083c4 --- /dev/null +++ b/components/libc/compilers/common/sys/termios.h @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h new file mode 100644 index 0000000000..ef1c810608 --- /dev/null +++ b/components/libc/compilers/common/sys/time.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-07 Meco Man combine gcc armcc iccarm + * 2021-02-12 Meco Man move all definitions located in to this file + */ +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001. + */ +#if defined ( __ICCARM__ ) && (__VER__ >= 8010001) +#define _TIMESPEC_DEFINED +#endif + + +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED +/* + * Structure returned by gettimeofday(2) system call, + * and used in other calls. + */ +#if !(defined(_WIN32)) +struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ +}; +#endif +#endif /* _TIMEVAL_DEFINED */ + +#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !defined (__ICCARM__) && !defined (_WIN32) +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +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); +#if defined(__ARMCC_VERSION) || defined (__ICCARM__) +struct tm *gmtime_r(const time_t *timep, struct tm *r); +#endif + +#ifdef RT_USING_POSIX +#include +/* posix clock and timer */ +#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) + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 1 +#endif + +#define CLOCK_CPUTIME_ID 2 + +#ifndef CLOCK_PROCESS_CPUTIME_ID +#define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID +#endif +#ifndef CLOCK_THREAD_CPUTIME_ID +#define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID +#endif + +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 4 +#endif + +int clock_getres (clockid_t clockid, struct timespec *res); +int clock_gettime (clockid_t clockid, struct timespec *tp); +int clock_settime (clockid_t clockid, const struct timespec *tp); +int clock_time_to_tick(const struct timespec *time); +#endif /* RT_USING_POSIX */ + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS_TIME_H_ */ diff --git a/components/libc/compilers/common/termios.h b/components/libc/compilers/common/termios.h new file mode 100644 index 0000000000..2960d52c58 --- /dev/null +++ b/components/libc/compilers/common/termios.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + */ +#ifndef _TERMIOS_H__ +#define _TERMIOS_H__ + +#include + +#ifdef RT_USING_POSIX_TERMIOS +#include +#include +#endif + +#endif diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c new file mode 100644 index 0000000000..33d8907165 --- /dev/null +++ b/components/libc/compilers/common/time.c @@ -0,0 +1,643 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 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() + * 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 + * 2021-02-12 Meco Man add errno + * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, + * which found by Rob + * 2021-02-12 Meco Man move all of the functions located in to this file + * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html + */ + +#include +#include + +#ifdef RT_USING_DEVICE +#include +#endif + +#define DBG_TAG "TIME" +#define DBG_LVL DBG_INFO +#include + +/* seconds per day */ +#define SPD 24*60*60 + +/* days per month -- nonleap! */ +static const short __spm[13] = +{ + 0, + (31), + (31 + 28), + (31 + 28 + 31), + (31 + 28 + 31 + 30), + (31 + 28 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30), + (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), +}; + +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) +{ + /* every fourth year is a leap year except for century years that are + * not divisible by 400. */ + /* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */ + return (!(year % 4) && ((year % 100) || !(year % 400))); +} + +static void num2str(char *c, int i) +{ + c[0] = i / 10 + '0'; + c[1] = i % 10 + '0'; +} + +/** + * Get time from RTC device (without timezone) + * @param tv: struct timeval + * @return -1 failure; 1 success + */ +static int get_timeval(struct timeval *tv) +{ +#ifdef RT_USING_RTC + static rt_device_t device = RT_NULL; + rt_err_t rst = -RT_ERROR; + + if (tv == RT_NULL) + return -1; + + /* default is 0 */ + tv->tv_sec = 0; + tv->tv_usec = 0; + + /* optimization: find rtc device only first */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } + + /* read timestamp from RTC device */ + if (device != RT_NULL) + { + if (rt_device_open(device, 0) == RT_EOK) + { + rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME_US, &tv->tv_usec); + rt_device_close(device); + } + } + else + { + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + return -1; + } + + return (rst < 0) ? -1 : 1; + +#else + /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + return -1; +#endif /* RT_USING_RTC */ +} + +/** + * Set time to RTC device (without timezone) + * @param tv: struct timeval + * @return -1 failure; 1 success + */ +static int set_timeval(struct timeval *tv) +{ +#ifdef RT_USING_RTC + static rt_device_t device = RT_NULL; + rt_err_t rst = -RT_ERROR; + + if (tv == RT_NULL) + return -1; + + /* optimization: find rtc device only first */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } + + /* read timestamp from RTC device */ + if (device != RT_NULL) + { + if (rt_device_open(device, 0) == RT_EOK) + { + rst = rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &tv->tv_sec); + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME_US, &tv->tv_usec); + rt_device_close(device); + } + } + else + { + LOG_W("Cannot find a RTC device to provide time!"); + return -1; + } + + return (rst < 0) ? -1 : 1; + +#else + LOG_W("Cannot find a RTC device to provide time!"); + return -1; +#endif /* RT_USING_RTC */ +} + +struct tm *gmtime_r(const time_t *timep, struct tm *r) +{ + time_t i; + register time_t work = *timep % (SPD); + r->tm_sec = work % 60; + work /= 60; + r->tm_min = work % 60; + r->tm_hour = work / 60; + work = *timep / (SPD); + r->tm_wday = (4 + work) % 7; + for (i = 1970;; ++i) + { + register time_t k = __isleap(i) ? 366 : 365; + if (work >= k) + work -= k; + else + break; + } + r->tm_year = i - 1900; + r->tm_yday = work; + + r->tm_mday = 1; + if (__isleap(i) && (work > 58)) + { + if (work == 59) + r->tm_mday = 2; /* 29.2. */ + work -= 1; + } + + for (i = 11; i && (__spm[i] > work); --i) + ; + r->tm_mon = i; + r->tm_mday += work - __spm[i]; + + r->tm_isdst = 0; + return r; +} +RTM_EXPORT(gmtime_r); + +struct tm* gmtime(const time_t* t) +{ + static struct tm tmp; + return gmtime_r(t, &tmp); +} +RTM_EXPORT(gmtime); + +/*TODO: timezone */ +struct tm* localtime_r(const time_t* t, struct tm* r) +{ + time_t local_tz; + int utc_plus; + + utc_plus = 8; /* GMT: UTC+8 */ + local_tz = *t + utc_plus * 3600; + return gmtime_r(&local_tz, r); +} +RTM_EXPORT(localtime_r); + +struct tm* localtime(const time_t* t) +{ + static struct tm tmp; + return localtime_r(t, &tmp); +} +RTM_EXPORT(localtime); + +/* TODO: timezone */ +time_t mktime(struct tm * const t) +{ + time_t timestamp; + int utc_plus; + + utc_plus = 8; /* GMT: UTC+8 */ + timestamp = timegm(t); + timestamp = timestamp - 3600 * utc_plus; + return timestamp; +} +RTM_EXPORT(mktime); + +char* asctime_r(const struct tm *t, char *buf) +{ + /* "Wed Jun 30 21:49:08 1993\n" */ + *(int*) buf = *(int*) (days + (t->tm_wday << 2)); + *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); + num2str(buf + 8, t->tm_mday); + if (buf[8] == '0') + buf[8] = ' '; + buf[10] = ' '; + num2str(buf + 11, t->tm_hour); + buf[13] = ':'; + num2str(buf + 14, t->tm_min); + buf[16] = ':'; + num2str(buf + 17, t->tm_sec); + buf[19] = ' '; + num2str(buf + 20, (t->tm_year + 1900) / 100); + num2str(buf + 22, (t->tm_year + 1900) % 100); + buf[24] = '\n'; + buf[25] = '\0'; + return buf; +} +RTM_EXPORT(asctime_r); + +char* asctime(const struct tm *timeptr) +{ + static char buf[26]; + return asctime_r(timeptr, buf); +} +RTM_EXPORT(asctime); + +char *ctime_r (const time_t * tim_p, char * result) +{ + struct tm tm; + return asctime_r (localtime_r (tim_p, &tm), result); +} +RTM_EXPORT(ctime_r); + +char* ctime(const time_t *tim_p) +{ + return asctime (localtime (tim_p)); +} +RTM_EXPORT(ctime); + +/** + * Returns the current time. + * + * @param time_t * t the timestamp pointer, if not used, keep NULL. + * + * @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) +{ + struct timeval now; + + if(get_timeval(&now) > 0) + { + if (t) + { + *t = now.tv_sec; + } + return now.tv_sec; + } + else + { + errno = EFAULT; + return ((time_t)-1); + } +} +RTM_EXPORT(time); + +RT_WEAK clock_t clock(void) +{ + return rt_tick_get(); +} +RTM_EXPORT(clock); + +int stime(const time_t *t) +{ + struct timeval tv; + + if (!t) + { + errno = EFAULT; + return -1; + } + + tv.tv_sec = *t; + if (set_timeval(&tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(stime); + +time_t timegm(struct tm * const t) +{ + register time_t day; + register time_t i; + register time_t years = t->tm_year - 70; + + if (t->tm_sec > 60) + { + t->tm_min += t->tm_sec / 60; + t->tm_sec %= 60; + } + if (t->tm_min > 60) + { + t->tm_hour += t->tm_min / 60; + t->tm_min %= 60; + } + if (t->tm_hour > 24) + { + t->tm_mday += t->tm_hour / 24; + t->tm_hour %= 24; + } + if (t->tm_mon > 12) + { + t->tm_year += t->tm_mon / 12; + t->tm_mon %= 12; + } + while (t->tm_mday > __spm[1 + t->tm_mon]) + { + if (t->tm_mon == 1 && __isleap(t->tm_year + 1900)) + { + --t->tm_mday; + } + t->tm_mday -= __spm[t->tm_mon]; + ++t->tm_mon; + if (t->tm_mon > 11) + { + t->tm_mon = 0; + ++t->tm_year; + } + } + + if (t->tm_year < 70) + return (time_t) - 1; + + /* Days since 1970 is 365 * number of years + number of leap years since 1970 */ + day = years * 365 + (years + 1) / 4; + + /* After 2100 we have to substract 3 leap years for every 400 years + This is not intuitive. Most mktime implementations do not support + dates after 2059, anyway, so we might leave this out for it's + bloat. */ + if (years >= 131) + { + years -= 131; + years /= 100; + day -= (years >> 2) * 3 + 1; + if ((years &= 3) == 3) + years--; + day -= years; + } + + day += t->tm_yday = __spm[t->tm_mon] + t->tm_mday - 1 + + (__isleap(t->tm_year + 1900) & (t->tm_mon > 1)); + + /* day is now the number of days since 'Jan 1 1970' */ + i = 7; + t->tm_wday = (day + 4) % i; /* Sunday=0, Monday=1, ..., Saturday=6 */ + + i = 24; + day *= i; + i = 60; + return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; +} +RTM_EXPORT(timegm); + +/* TODO: timezone */ +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + if (tv != RT_NULL && get_timeval(tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(gettimeofday); + +/* TODO: timezone */ +int settimeofday(const struct timeval *tv, const struct timezone *tz) +{ + if (tv != RT_NULL) + { + if(tv->tv_sec >= 0 && tv->tv_usec >= 0) + { + if(set_timeval((struct timeval *)tv) > 0) + { + return 0; + } + else + { + errno = EFAULT; + return -1; + } + } + else + { + errno = EINVAL; + return -1; + } + } + else + { + errno = EFAULT; + return -1; + } +} +RTM_EXPORT(settimeofday); + +/* inherent in the toolchain */ +RTM_EXPORT(difftime); +RTM_EXPORT(strftime); + +#ifdef RT_USING_POSIX +static struct timeval _timevalue; +static int clock_time_system_init() +{ + 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 = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; + _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; + + return 0; +} +INIT_COMPONENT_EXPORT(clock_time_system_init); + +int clock_getres(clockid_t clockid, struct timespec *res) +{ + int ret = 0; + + if (res == RT_NULL) + { + rt_set_errno(EINVAL); + return -1; + } + + switch (clockid) + { + case CLOCK_REALTIME: + res->tv_sec = 0; + res->tv_nsec = NANOSECOND_PER_SECOND/RT_TICK_PER_SECOND; + break; + +#ifdef RT_USING_CPUTIME + case CLOCK_CPUTIME_ID: + res->tv_sec = 0; + res->tv_nsec = clock_cpu_getres(); + break; +#endif + + default: + ret = -1; + rt_set_errno(EINVAL); + break; + } + + return ret; +} +RTM_EXPORT(clock_getres); + +int clock_gettime(clockid_t clockid, struct timespec *tp) +{ + int ret = 0; + + if (tp == RT_NULL) + { + rt_set_errno(EINVAL); + return -1; + } + + switch (clockid) + { + case CLOCK_REALTIME: + { + /* get tick */ + int tick = rt_tick_get(); + + tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; + tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; + } + break; + +#ifdef RT_USING_CPUTIME + case CLOCK_CPUTIME_ID: + { + float unit = 0; + long long cpu_tick; + + unit = clock_cpu_getres(); + cpu_tick = clock_cpu_gettime(); + + tp->tv_sec = ((int)(cpu_tick * unit)) / NANOSECOND_PER_SECOND; + tp->tv_nsec = ((int)(cpu_tick * unit)) % NANOSECOND_PER_SECOND; + } + break; +#endif + default: + rt_set_errno(EINVAL); + ret = -1; + } + + return ret; +} +RTM_EXPORT(clock_gettime); + +int clock_settime(clockid_t clockid, const struct timespec *tp) +{ + int second; + rt_tick_t tick; + rt_device_t device; + + if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) + { + rt_set_errno(EINVAL); + + return -1; + } + + /* get second */ + second = tp->tv_sec; + /* get tick */ + tick = rt_tick_get(); + + /* update timevalue */ + _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; + _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; + + /* update for RTC device */ + device = rt_device_find("rtc"); + if (device != RT_NULL) + { + /* set realtime seconds */ + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); + } + else + return -1; + + return 0; +} +RTM_EXPORT(clock_settime); + +int clock_time_to_tick(const struct timespec *time) +{ + int tick; + int nsecond, second; + struct timespec tp; + + RT_ASSERT(time != RT_NULL); + + tick = RT_WAITING_FOREVER; + if (time != NULL) + { + /* get current tp */ + clock_gettime(CLOCK_REALTIME, &tp); + + if ((time->tv_nsec - tp.tv_nsec) < 0) + { + nsecond = NANOSECOND_PER_SECOND - (tp.tv_nsec - time->tv_nsec); + second = time->tv_sec - tp.tv_sec - 1; + } + else + { + nsecond = time->tv_nsec - tp.tv_nsec; + second = time->tv_sec - tp.tv_sec; + } + + tick = second * RT_TICK_PER_SECOND + nsecond * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND; + if (tick < 0) tick = 0; + } + + return tick; +} +RTM_EXPORT(clock_time_to_tick); + +#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c new file mode 100644 index 0000000000..20130cbb8a --- /dev/null +++ b/components/libc/compilers/common/unistd.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020-09-01 Meco Man first Version + * 2021-02-12 Meco Man move all functions located in to this file + */ + +#include +#include +#include + +#ifdef RT_USING_POSIX_TERMIOS +#include "termios.h" + +int isatty(int fd) +{ + struct termios ts; + return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/ +} +RTM_EXPORT(isatty); +#endif + +char *ttyname(int fd) +{ + return "/dev/tty0"; /*TODO: need to add more specific*/ +} +RTM_EXPORT(ttyname); + +unsigned int sleep(unsigned int seconds) +{ + rt_tick_t delta_tick; + + delta_tick = rt_tick_get(); + rt_thread_delay(seconds * RT_TICK_PER_SECOND); + delta_tick = rt_tick_get() - delta_tick; + + return seconds - delta_tick/RT_TICK_PER_SECOND; +} +RTM_EXPORT(sleep); + +int usleep(useconds_t usec) +{ + rt_thread_mdelay(usec / 1000u); + rt_hw_us_delay(usec % 1000u); + return 0; +} +RTM_EXPORT(usleep); + +pid_t getpid(void) +{ + /*TODO*/ + return 0; +} +RTM_EXPORT(getpid); + +pid_t getppid(void) +{ + return 0; +} +RTM_EXPORT(getppid); + +uid_t getuid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getuid); + +uid_t geteuid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(geteuid); + +gid_t getgid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getgid); + +gid_t getegid(void) +{ + return 0; /*ROOT*/ +} +RTM_EXPORT(getegid); -- cgit v1.3.1 From ae66d8262499c30e2f9617a101fc200b7e4814cb Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 25 Apr 2021 21:32:08 +0800 Subject: update sconscript --- components/libc/compilers/common/SConscript | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 319e1a3555..d9de1cf17f 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -23,5 +23,9 @@ else: if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) - + list = os.listdir(cwd) + for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + group = group + SConscript(os.path.join(d, 'SConscript')) Return('group') -- cgit v1.3.1 From 19347ed454621161caf4186f1a52ec656c3dc58f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 26 Apr 2021 14:31:31 +0800 Subject: [libc][unistd] 完善isatty() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/unistd.c | 26 +++++++++++++++++++++----- components/libc/compilers/newlib/syscalls.c | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c index 20130cbb8a..6c81fc7662 100644 --- a/components/libc/compilers/common/unistd.c +++ b/components/libc/compilers/common/unistd.c @@ -15,18 +15,29 @@ #ifdef RT_USING_POSIX_TERMIOS #include "termios.h" - int isatty(int fd) { struct termios ts; - return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/ + return(tcgetattr(fd, &ts) != -1); /*true if no error (is a tty)*/ +} +#else +int isatty(int fd) +{ + if (fd >=0 && fd < 3) + { + return 1; + } + else + { + return 0; + } } -RTM_EXPORT(isatty); #endif +RTM_EXPORT(isatty); char *ttyname(int fd) { - return "/dev/tty0"; /*TODO: need to add more specific*/ + return "/dev/tty"; /*TODO: need to add more specific*/ } RTM_EXPORT(ttyname); @@ -50,11 +61,16 @@ int usleep(useconds_t usec) } RTM_EXPORT(usleep); -pid_t getpid(void) +pid_t gettid(void) { /*TODO*/ return 0; } + +pid_t getpid(void) +{ + return gettid(); +} RTM_EXPORT(getpid); pid_t getppid(void) diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index 6cbc11fd6a..7c5d51eca6 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -98,6 +98,7 @@ _isatty_r(struct _reent *ptr, int fd) return 0; } } + int _kill_r(struct _reent *ptr, int pid, int sig) { -- cgit v1.3.1 From cb7fa8fceaf5b9e2aacaee132ce5bb0ad49c92aa Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 26 Apr 2021 14:34:26 +0800 Subject: implement pid_t gettid(void) --- components/libc/compilers/common/none-gcc/sys/unistd.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h index 7752a1caf7..2f01f660b3 100644 --- a/components/libc/compilers/common/none-gcc/sys/unistd.h +++ b/components/libc/compilers/common/none-gcc/sys/unistd.h @@ -66,13 +66,11 @@ #endif - int isatty (int fd); char * ttyname (int desc); - unsigned int sleep(unsigned int seconds); int usleep(useconds_t usec); - +pid_t gettid(void); pid_t getpid(void); pid_t getppid(void); uid_t getuid(void); -- cgit v1.3.1 From 850e1aeb5264818c133a32ff457794ff9bd9364d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 28 Apr 2021 13:03:43 +0800 Subject: [libc][time] 细微调整time.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 10 +++++----- components/libc/compilers/newlib/SConscript | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 33d8907165..5f4af8e572 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -16,7 +16,7 @@ * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, * which found by Rob * 2021-02-12 Meco Man move all of the functions located in to this file - * 2021-03-15 Meco Man fixed bug: https://club.rt-thread.org/ask/question/423650.html + * 2021-03-15 Meco Man fixed a bug of leaking memory in asctime() */ #include @@ -104,7 +104,7 @@ static int get_timeval(struct timeval *tv) } else { - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ rt_kprintf("Cannot find a RTC device to provide time!\r\n"); return -1; } @@ -112,7 +112,7 @@ static int get_timeval(struct timeval *tv) return (rst < 0) ? -1 : 1; #else - /* LOG_W will cause a recursive printing if ulog timestamp function is turned on */ + /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ rt_kprintf("Cannot find a RTC device to provide time!\r\n"); return -1; #endif /* RT_USING_RTC */ @@ -273,13 +273,13 @@ RTM_EXPORT(asctime); char *ctime_r (const time_t * tim_p, char * result) { struct tm tm; - return asctime_r (localtime_r (tim_p, &tm), result); + return asctime_r(localtime_r(tim_p, &tm), result); } RTM_EXPORT(ctime_r); char* ctime(const time_t *tim_p) { - return asctime (localtime (tim_p)); + return asctime(localtime(tim_p)); } RTM_EXPORT(ctime); diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript index b1ad6e4784..542cdecd40 100644 --- a/components/libc/compilers/newlib/SConscript +++ b/components/libc/compilers/newlib/SConscript @@ -4,17 +4,18 @@ Import('rtconfig') src = [] cwd = GetCurrentDir() group = [] - +LIBS = [] +CPPDEFINES = [] CPPPATH = [cwd] if rtconfig.PLATFORM == 'gcc': if GetDepend('RT_USING_LIBC'): - CPPDEFINES = ['RT_USING_NEWLIB'] + CPPDEFINES += ['RT_USING_NEWLIB'] # link with libc and libm: # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in # recent GCC tool chains. The linker would just link in the functions that have # been referenced. So setting this won't result in bigger text size. - LIBS = ['c', 'm'] + LIBS += ['c', 'm'] src += Glob('*.c') SrcRemove(src, ['minilib.c']) @@ -22,8 +23,6 @@ if rtconfig.PLATFORM == 'gcc': SrcRemove(src, ['libc_syms.c']) else: src += ['minilib.c'] - CPPDEFINES = [] - LIBS = [] group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) -- cgit v1.3.1 From 82f2d8e53d866598b993054990b73339ef457607 Mon Sep 17 00:00:00 2001 From: Meco Jianting Man <920369182@qq.com> Date: Thu, 29 Apr 2021 00:21:10 +0800 Subject: time.c 删除函数名与括号之间的空格 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 5f4af8e572..72542867d2 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -270,7 +270,7 @@ char* asctime(const struct tm *timeptr) } RTM_EXPORT(asctime); -char *ctime_r (const time_t * tim_p, char * result) +char *ctime_r(const time_t * tim_p, char * result) { struct tm tm; return asctime_r(localtime_r(tim_p, &tm), result); -- cgit v1.3.1 From 1627597fcc89a7d9babc972b5d1d46764ffc7ef8 Mon Sep 17 00:00:00 2001 From: Meco Jianting Man <920369182@qq.com> Date: Thu, 29 Apr 2021 04:42:11 +0800 Subject: remove _TIMESPEC_DEFINED --- components/libc/compilers/common/sys/time.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index ef1c810608..24da0b6c77 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -18,14 +18,6 @@ extern "C" { #endif -/* - * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001. - */ -#if defined ( __ICCARM__ ) && (__VER__ >= 8010001) -#define _TIMESPEC_DEFINED -#endif - - #ifndef _TIMEVAL_DEFINED #define _TIMEVAL_DEFINED /* @@ -40,7 +32,7 @@ struct timeval { #endif #endif /* _TIMEVAL_DEFINED */ -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !defined (__ICCARM__) && !defined (_WIN32) +#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32) struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ -- cgit v1.3.1 From a7a3ca9f0290131842f1a40bb8dca1a9490e4d27 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 1 May 2021 05:51:18 +0800 Subject: 增加手动设置时区的功能 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/Kconfig | 8 +++++++- components/libc/compilers/common/time.c | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/Kconfig b/components/libc/Kconfig index 49b97481d1..8a790c298d 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -55,8 +55,14 @@ endif if RT_USING_LIBC != y config RT_LIBC_USING_TIME - bool "Enable TIME FUNCTIONS WITHOUT COMPILER'S LIBC" + bool "Enable time functions without compiler's libc" default y endif +config RT_LIBC_FIXED_TIMEZONE + depends on (RT_LIBC_USING_TIME || RT_USING_LIBC) + int "Manually set a fixed time zone (UTC+)" + range -12 12 + default 8 + endmenu diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 33d8907165..8dda257937 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -214,7 +214,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r) time_t local_tz; int utc_plus; - utc_plus = 8; /* GMT: UTC+8 */ + utc_plus = RT_LIBC_FIXED_TIMEZONE; local_tz = *t + utc_plus * 3600; return gmtime_r(&local_tz, r); } @@ -233,7 +233,7 @@ time_t mktime(struct tm * const t) time_t timestamp; int utc_plus; - utc_plus = 8; /* GMT: UTC+8 */ + utc_plus = RT_LIBC_FIXED_TIMEZONE; timestamp = timegm(t); timestamp = timestamp - 3600 * utc_plus; return timestamp; -- cgit v1.3.1 From 0aa3b80fc3509a2377d727e76fd9393f4b4962d8 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 1 May 2021 06:03:46 +0800 Subject: 在time.c中增加RT_LIBC_FIXED_TIMEZONE默认值,防止有些工程没有配置RT_LIBC_FIXED_TIMEZONE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 8dda257937..3e23fc8242 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -30,6 +30,10 @@ #define DBG_LVL DBG_INFO #include +#ifndef RT_LIBC_FIXED_TIMEZONE +#define RT_LIBC_FIXED_TIMEZONE 8 +#endif + /* seconds per day */ #define SPD 24*60*60 -- cgit v1.3.1 From 65984a7116e747e022083774852f3a90617ca4e1 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 1 May 2021 06:06:03 +0800 Subject: add comment --- components/libc/compilers/common/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 3e23fc8242..f7f52be9b4 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -31,7 +31,7 @@ #include #ifndef RT_LIBC_FIXED_TIMEZONE -#define RT_LIBC_FIXED_TIMEZONE 8 +#define RT_LIBC_FIXED_TIMEZONE 8 /* UTC+8 */ #endif /* seconds per day */ -- cgit v1.3.1 From a611a6686402bd074cbaf53c53356c381ab54a5f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 1 May 2021 06:08:14 +0800 Subject: 精简代码 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index f7f52be9b4..799f71a2d0 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -212,14 +212,11 @@ struct tm* gmtime(const time_t* t) } RTM_EXPORT(gmtime); -/*TODO: timezone */ struct tm* localtime_r(const time_t* t, struct tm* r) { time_t local_tz; - int utc_plus; - utc_plus = RT_LIBC_FIXED_TIMEZONE; - local_tz = *t + utc_plus * 3600; + local_tz = *t + RT_LIBC_FIXED_TIMEZONE * 3600; return gmtime_r(&local_tz, r); } RTM_EXPORT(localtime_r); @@ -231,15 +228,12 @@ struct tm* localtime(const time_t* t) } RTM_EXPORT(localtime); -/* TODO: timezone */ time_t mktime(struct tm * const t) { time_t timestamp; - int utc_plus; - utc_plus = RT_LIBC_FIXED_TIMEZONE; timestamp = timegm(t); - timestamp = timestamp - 3600 * utc_plus; + timestamp = timestamp - 3600 * RT_LIBC_FIXED_TIMEZONE; return timestamp; } RTM_EXPORT(mktime); -- cgit v1.3.1 From f4015029d2f4682783fb26e9aa31588de4377783 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 1 May 2021 14:18:46 +0800 Subject: gettimeofday()函数支持时区;规范set_timeval/get_timeval函数返回值 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 57 ++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index deda18a560..6a2b5620ad 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -17,6 +17,7 @@ * which found by Rob * 2021-02-12 Meco Man move all of the functions located in to this file * 2021-03-15 Meco Man fixed a bug of leaking memory in asctime() + * 2021-05-01 Meco Man support fixed timezone */ #include @@ -73,18 +74,18 @@ static void num2str(char *c, int i) } /** - * Get time from RTC device (without timezone) + * Get time from RTC device (without timezone, UTC+0) * @param tv: struct timeval - * @return -1 failure; 1 success + * @return the operation status, RT_EOK on successful */ -static int get_timeval(struct timeval *tv) +static rt_err_t get_timeval(struct timeval *tv) { #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; rt_err_t rst = -RT_ERROR; if (tv == RT_NULL) - return -1; + return -RT_EINVAL; /* default is 0 */ tv->tv_sec = 0; @@ -110,22 +111,22 @@ static int get_timeval(struct timeval *tv) { /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - return -1; + return -RT_ENOSYS; } - return (rst < 0) ? -1 : 1; + return rst; #else /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ rt_kprintf("Cannot find a RTC device to provide time!\r\n"); - return -1; + return -RT_ENOSYS; #endif /* RT_USING_RTC */ } /** * Set time to RTC device (without timezone) * @param tv: struct timeval - * @return -1 failure; 1 success + * @return the operation status, RT_EOK on successful */ static int set_timeval(struct timeval *tv) { @@ -134,7 +135,7 @@ static int set_timeval(struct timeval *tv) rt_err_t rst = -RT_ERROR; if (tv == RT_NULL) - return -1; + return -RT_EINVAL; /* optimization: find rtc device only first */ if (device == RT_NULL) @@ -155,14 +156,14 @@ static int set_timeval(struct timeval *tv) else { LOG_W("Cannot find a RTC device to provide time!"); - return -1; + return -RT_ENOSYS; } - return (rst < 0) ? -1 : 1; + return rst; #else LOG_W("Cannot find a RTC device to provide time!"); - return -1; + return -RT_ENOSYS; #endif /* RT_USING_RTC */ } @@ -294,7 +295,7 @@ RT_WEAK time_t time(time_t *t) { struct timeval now; - if(get_timeval(&now) > 0) + if(get_timeval(&now) == RT_EOK) { if (t) { @@ -304,7 +305,7 @@ RT_WEAK time_t time(time_t *t) } else { - errno = EFAULT; + rt_set_errno(EFAULT); return ((time_t)-1); } } @@ -322,18 +323,18 @@ int stime(const time_t *t) if (!t) { - errno = EFAULT; + rt_set_errno(EFAULT); return -1; } tv.tv_sec = *t; - if (set_timeval(&tv) > 0) + if (set_timeval(&tv) == RT_EOK) { return 0; } else { - errno = EFAULT; + rt_set_errno(EFAULT); return -1; } } @@ -414,47 +415,53 @@ time_t timegm(struct tm * const t) } RTM_EXPORT(timegm); -/* TODO: timezone */ +/* TODO: Daylight Saving Time */ int gettimeofday(struct timeval *tv, struct timezone *tz) { - if (tv != RT_NULL && get_timeval(tv) > 0) + if(tz != RT_NULL) + { + tz->tz_dsttime = 0; + tz->tz_minuteswest = -(RT_LIBC_FIXED_TIMEZONE * 60); + } + + if (tv != RT_NULL && get_timeval(tv) == RT_EOK) { return 0; } else { - errno = EFAULT; + rt_set_errno(EFAULT); return -1; } } RTM_EXPORT(gettimeofday); -/* TODO: timezone */ +/* TODO: Daylight Saving Time */ int settimeofday(const struct timeval *tv, const struct timezone *tz) { if (tv != RT_NULL) { if(tv->tv_sec >= 0 && tv->tv_usec >= 0) { - if(set_timeval((struct timeval *)tv) > 0) + if(set_timeval((struct timeval *)tv) == RT_EOK) { return 0; } else { - errno = EFAULT; + rt_set_errno(EFAULT); return -1; } } else { - errno = EINVAL; + rt_set_errno(EINVAL); return -1; } } else { - errno = EFAULT; + rt_set_errno(EFAULT); return -1; } } -- cgit v1.3.1 From 6fa385b98743c78b61a72fa5d4ff8ea7be4a31fd Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 1 May 2021 14:23:50 +0800 Subject: [time] 补充注释 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 6a2b5620ad..388dc52ac3 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -124,11 +124,11 @@ static rt_err_t get_timeval(struct timeval *tv) } /** - * Set time to RTC device (without timezone) + * Set time to RTC device (without timezone, UTC+0) * @param tv: struct timeval * @return the operation status, RT_EOK on successful */ -static int set_timeval(struct timeval *tv) +static rt_err_t set_timeval(struct timeval *tv) { #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; -- cgit v1.3.1 From 47de5265250f76ed1f48f7d1c51beda690a4bd74 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 1 May 2021 16:21:52 +0800 Subject: 精简settimeofday代码; 在Linux中settimeofday以及gettimeofday函数的时区功能已经被废弃,因此增加注释予以提示。 gettimeofday实现了tz_minuteswest功能,tz_dsttime功能未实现,按废弃处理; settimeofday时区功能废弃。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 41 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 388dc52ac3..50fbe0d5cc 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -124,11 +124,11 @@ static rt_err_t get_timeval(struct timeval *tv) } /** - * Set time to RTC device (without timezone, UTC+0) + * Set time to RTC device (without timezone) * @param tv: struct timeval * @return the operation status, RT_EOK on successful */ -static rt_err_t set_timeval(struct timeval *tv) +static int set_timeval(const struct timeval *tv) { #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; @@ -415,9 +415,13 @@ time_t timegm(struct tm * const t) } RTM_EXPORT(timegm); -/* TODO: Daylight Saving Time */ int gettimeofday(struct timeval *tv, struct timezone *tz) { + /* The use of the timezone structure is obsolete; + * the tz argument should normally be specified as NULL. + * The tz_dsttime field has never been used under Linux. + * Thus, the following is purely of historic interest. + */ if(tz != RT_NULL) { tz->tz_dsttime = 0; @@ -436,32 +440,23 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) } RTM_EXPORT(gettimeofday); -/* TODO: Daylight Saving Time */ int settimeofday(const struct timeval *tv, const struct timezone *tz) { - if (tv != RT_NULL) + /* The use of the timezone structure is obsolete; + * the tz argument should normally be specified as NULL. + * The tz_dsttime field has never been used under Linux. + * Thus, the following is purely of historic interest. + */ + if (tv != RT_NULL + && tv->tv_sec >= 0 + && tv->tv_usec >= 0 + && set_timeval(tv) == RT_EOK) { - if(tv->tv_sec >= 0 && tv->tv_usec >= 0) - { - if(set_timeval((struct timeval *)tv) == RT_EOK) - { - return 0; - } - else - { - rt_set_errno(EFAULT); - return -1; - } - } - else - { - rt_set_errno(EINVAL); - return -1; - } + return 0; } else { - rt_set_errno(EFAULT); + rt_set_errno(EINVAL); return -1; } } -- cgit v1.3.1 From 8ec1a63b2347ce70e9d4bbd6693fd3e73c41be65 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 2 May 2021 09:24:41 +0800 Subject: 增加tz_dsttime类型定义 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/sys/mman.h | 2 +- components/libc/compilers/common/sys/time.h | 13 +++++++++++++ components/libc/compilers/common/time.c | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/sys/mman.h b/components/libc/compilers/common/sys/mman.h index a9235d61f0..2da2ddf716 100644 --- a/components/libc/compilers/common/sys/mman.h +++ b/components/libc/compilers/common/sys/mman.h @@ -16,7 +16,7 @@ extern "C" { #endif #include - + #define MAP_FAILED ((void *) -1) #define MAP_SHARED 0x01 diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 24da0b6c77..be453ba276 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -20,6 +20,19 @@ extern "C" { #ifndef _TIMEVAL_DEFINED #define _TIMEVAL_DEFINED + +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ +#define DST_GB 7 /* Great Britain and Eire */ +#define DST_RUM 8 /* Rumania */ +#define DST_TUR 9 /* Turkey */ +#define DST_AUSTALT 10 /* Australian style with shift in 1986 */ + /* * Structure returned by gettimeofday(2) system call, * and used in other calls. diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 50fbe0d5cc..8c32ee1ed0 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -424,7 +424,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) */ if(tz != RT_NULL) { - tz->tz_dsttime = 0; + tz->tz_dsttime = DST_NONE; tz->tz_minuteswest = -(RT_LIBC_FIXED_TIMEZONE * 60); } -- cgit v1.3.1 From 3f74758f3189e3d126454a6e06d1fb818747a090 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 2 May 2021 09:29:46 +0800 Subject: 将改为"sys/time.h" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 8c32ee1ed0..d5436e50e3 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -20,7 +20,7 @@ * 2021-05-01 Meco Man support fixed timezone */ -#include +#include "sys/time.h" #include #ifdef RT_USING_DEVICE -- cgit v1.3.1 From 1a55702ccb3f18f354c6f541d12e7a2eaa204569 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 2 May 2021 09:37:22 +0800 Subject: 修复DST_NONE 等宏定义位置放错导致报错的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/sys/time.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index be453ba276..bb1a9c96fd 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -18,9 +18,6 @@ extern "C" { #endif -#ifndef _TIMEVAL_DEFINED -#define _TIMEVAL_DEFINED - #define DST_NONE 0 /* not on dst */ #define DST_USA 1 /* USA style dst */ #define DST_AUST 2 /* Australian style dst */ @@ -33,6 +30,8 @@ extern "C" { #define DST_TUR 9 /* Turkey */ #define DST_AUSTALT 10 /* Australian style with shift in 1986 */ +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED /* * Structure returned by gettimeofday(2) system call, * and used in other calls. -- cgit v1.3.1 From 8fee8d2c8cd30dea66cb60fa45e89538f2961c35 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 3 May 2021 09:17:46 +0800 Subject: remove const in set_timeval --- components/libc/compilers/common/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index d5436e50e3..9996212444 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -128,7 +128,7 @@ static rt_err_t get_timeval(struct timeval *tv) * @param tv: struct timeval * @return the operation status, RT_EOK on successful */ -static int set_timeval(const struct timeval *tv) +static int set_timeval(struct timeval *tv) { #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; @@ -450,7 +450,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) if (tv != RT_NULL && tv->tv_sec >= 0 && tv->tv_usec >= 0 - && set_timeval(tv) == RT_EOK) + && set_timeval((struct timeval *)tv) == RT_EOK) { return 0; } -- cgit v1.3.1 From d9abe8fa30f04e0ac54a7ea2c50f3df750cff04e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 15 May 2021 21:27:31 +0800 Subject: 修复在simulator win32平台下,nonegcc文件夹路径没有添加到工程的bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/SConscript | 12 +++++++----- components/libc/compilers/common/none-gcc/SConscript | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index d9de1cf17f..039e53a0b3 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -23,9 +23,11 @@ else: if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) - list = os.listdir(cwd) - for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - group = group + SConscript(os.path.join(d, 'SConscript')) + +list = os.listdir(cwd) +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + group = group + SConscript(os.path.join(d, 'SConscript')) + Return('group') diff --git a/components/libc/compilers/common/none-gcc/SConscript b/components/libc/compilers/common/none-gcc/SConscript index 346e69b478..c5838f8949 100644 --- a/components/libc/compilers/common/none-gcc/SConscript +++ b/components/libc/compilers/common/none-gcc/SConscript @@ -8,6 +8,6 @@ CPPPATH = [cwd] group = [] src += Glob('*.c') -if rtconfig.PLATFORM != 'gcc': +if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim': group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH) Return('group') -- cgit v1.3.1 From a5f7635f31b237ad8ce09610ee76a75f4072e7d4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 22 May 2021 02:50:35 +0800 Subject: remove libc_errno.h & libc_limits.h --- components/dfs/include/dfs_fs.h | 2 +- .../libc/compilers/common/none-gcc/sys/errno.h | 199 ++++++++++++++++++++ components/libc/compilers/common/time.c | 1 + components/libc/getline/posix_getline.c | 6 +- components/libc/pthreads/posix_types.h | 2 +- components/libc/termios/posix_termios.c | 2 +- .../net/lwip-1.4.1/src/arch/include/arch/cc.h | 2 +- .../net/lwip-2.0.2/src/arch/include/arch/cc.h | 2 +- components/net/lwip-2.0.2/src/lwipopts.h | 2 + .../net/lwip-2.1.2/src/arch/include/arch/cc.h | 2 +- components/net/lwip-2.1.2/src/include/lwip/errno.h | 2 +- components/net/lwip-2.1.2/src/lwipopts.h | 1 + components/net/sal_socket/socket/net_sockets.c | 2 +- examples/libc/ex3.c | 2 +- examples/libc/ex6.c | 2 +- examples/libc/ex7.c | 2 +- examples/libc/file.c | 2 +- examples/libc/memory.c | 2 +- include/libc/libc_errno.h | 206 --------------------- include/libc/libc_limits.h | 25 --- include/rtlibc.h | 2 - 21 files changed, 219 insertions(+), 249 deletions(-) create mode 100644 components/libc/compilers/common/none-gcc/sys/errno.h delete mode 100644 include/libc/libc_errno.h delete mode 100644 include/libc/libc_limits.h (limited to 'components/libc/compilers') diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index 828f15a0f5..3d194515df 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -15,7 +15,7 @@ #ifdef RT_USING_LIBC #include #endif - +#include #ifdef __cplusplus extern "C" { #endif diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h new file mode 100644 index 0000000000..bdc3a3c9da --- /dev/null +++ b/components/libc/compilers/common/none-gcc/sys/errno.h @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-05-22 Meco Man The first version. + */ +#ifndef _SYS_ERRNO_H +#define _SYS_ERRNO_H + +#if defined(__CC_ARM) +/* +defined in armcc/errno.h + +#define EDOM 1 +#define ERANGE 2 +#define EILSEQ 4 +#define ESIGNUM 3 +#define EINVAL 5 +#define ENOMEM 6 +*/ + +#define ERROR_BASE_NO 7 + +#elif defined(__IAR_SYSTEMS_ICC__) +/* defined in iar/errno.h +#define EDOM 33 +#define ERANGE 34 +#define EFPOS 35 +#define EILSEQ 36 +*/ +#define ERROR_BASE_NO 36 + +#else +#define ERROR_BASE_NO 0 +#endif + +#if !defined(_WIN32) + +#include + +#define EPERM (ERROR_BASE_NO + 1) +#define ENOENT (ERROR_BASE_NO + 2) +#define ESRCH (ERROR_BASE_NO + 3) +#define EINTR (ERROR_BASE_NO + 4) +#define EIO (ERROR_BASE_NO + 5) +#define ENXIO (ERROR_BASE_NO + 6) +#define E2BIG (ERROR_BASE_NO + 7) +#define ENOEXEC (ERROR_BASE_NO + 8) +#define EBADF (ERROR_BASE_NO + 9) +#define ECHILD (ERROR_BASE_NO + 10) +#define EAGAIN (ERROR_BASE_NO + 11) + +#ifndef ENOMEM +#define ENOMEM (ERROR_BASE_NO + 12) +#endif + +#define EACCES (ERROR_BASE_NO + 13) +#define EFAULT (ERROR_BASE_NO + 14) +#define ENOTBLK (ERROR_BASE_NO + 15) +#define EBUSY (ERROR_BASE_NO + 16) +#define EEXIST (ERROR_BASE_NO + 17) +#define EXDEV (ERROR_BASE_NO + 18) +#define ENODEV (ERROR_BASE_NO + 19) +#define ENOTDIR (ERROR_BASE_NO + 20) +#define EISDIR (ERROR_BASE_NO + 21) + +#ifndef EINVAL +#define EINVAL (ERROR_BASE_NO + 22) +#endif + +#define ENFILE (ERROR_BASE_NO + 23) +#define EMFILE (ERROR_BASE_NO + 24) +#define ENOTTY (ERROR_BASE_NO + 25) +#define ETXTBSY (ERROR_BASE_NO + 26) +#define EFBIG (ERROR_BASE_NO + 27) +#define ENOSPC (ERROR_BASE_NO + 28) +#define ESPIPE (ERROR_BASE_NO + 29) +#define EROFS (ERROR_BASE_NO + 30) +#define EMLINK (ERROR_BASE_NO + 31) +#define EPIPE (ERROR_BASE_NO + 32) + +#ifndef EDOM +#define EDOM (ERROR_BASE_NO + 33) +#endif + +#ifndef ERANGE +#define ERANGE (ERROR_BASE_NO + 34) +#endif + +#define EDEADLK (ERROR_BASE_NO + 35) +#define ENAMETOOLONG (ERROR_BASE_NO + 36) +#define ENOLCK (ERROR_BASE_NO + 37) +#define ENOSYS (ERROR_BASE_NO + 38) +#define ENOTEMPTY (ERROR_BASE_NO + 39) +#define ELOOP (ERROR_BASE_NO + 40) +#define EWOULDBLOCK EAGAIN +#define ENOMSG (ERROR_BASE_NO + 42) +#define EIDRM (ERROR_BASE_NO + 43) +#define ECHRNG (ERROR_BASE_NO + 44) +#define EL2NSYNC (ERROR_BASE_NO + 45) +#define EL3HLT (ERROR_BASE_NO + 46) +#define EL3RST (ERROR_BASE_NO + 47) +#define ELNRNG (ERROR_BASE_NO + 48) +#define EUNATCH (ERROR_BASE_NO + 49) +#define ENOCSI (ERROR_BASE_NO + 50) +#define EL2HLT (ERROR_BASE_NO + 51) +#define EBADE (ERROR_BASE_NO + 52) +#define EBADR (ERROR_BASE_NO + 53) +#define EXFULL (ERROR_BASE_NO + 54) +#define ENOANO (ERROR_BASE_NO + 55) +#define EBADRQC (ERROR_BASE_NO + 56) +#define EBADSLT (ERROR_BASE_NO + 57) +#define EDEADLOCK EDEADLK +#define EBFONT (ERROR_BASE_NO + 59) +#define ENOSTR (ERROR_BASE_NO + 60) +#define ENODATA (ERROR_BASE_NO + 61) +#define ETIME (ERROR_BASE_NO + 62) +#define ENOSR (ERROR_BASE_NO + 63) +#define ENONET (ERROR_BASE_NO + 64) +#define ENOPKG (ERROR_BASE_NO + 65) +#define EREMOTE (ERROR_BASE_NO + 66) +#define ENOLINK (ERROR_BASE_NO + 67) +#define EADV (ERROR_BASE_NO + 68) +#define ESRMNT (ERROR_BASE_NO + 69) +#define ECOMM (ERROR_BASE_NO + 70) +#define EPROTO (ERROR_BASE_NO + 71) +#define EMULTIHOP (ERROR_BASE_NO + 72) +#define EDOTDOT (ERROR_BASE_NO + 73) +#define EBADMSG (ERROR_BASE_NO + 74) +#define EOVERFLOW (ERROR_BASE_NO + 75) +#define ENOTUNIQ (ERROR_BASE_NO + 76) +#define EBADFD (ERROR_BASE_NO + 77) +#define EREMCHG (ERROR_BASE_NO + 78) +#define ELIBACC (ERROR_BASE_NO + 79) +#define ELIBBAD (ERROR_BASE_NO + 80) +#define ELIBSCN (ERROR_BASE_NO + 81) +#define ELIBMAX (ERROR_BASE_NO + 82) +#define ELIBEXEC (ERROR_BASE_NO + 83) + +#ifndef EILSEQ +#define EILSEQ (ERROR_BASE_NO + 84) +#endif + +#define ERESTART (ERROR_BASE_NO + 85) +#define ESTRPIPE (ERROR_BASE_NO + 86) +#define EUSERS (ERROR_BASE_NO + 87) +#define ENOTSOCK (ERROR_BASE_NO + 88) +#define EDESTADDRREQ (ERROR_BASE_NO + 89) +#define EMSGSIZE (ERROR_BASE_NO + 90) +#define EPROTOTYPE (ERROR_BASE_NO + 91) +#define ENOPROTOOPT (ERROR_BASE_NO + 92) +#define EPROTONOSUPPORT (ERROR_BASE_NO + 93) +#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94) +#define EOPNOTSUPP (ERROR_BASE_NO + 95) +#define ENOTSUP EOPNOTSUPP +#define EPFNOSUPPORT (ERROR_BASE_NO + 96) +#define EAFNOSUPPORT (ERROR_BASE_NO + 97) +#define EADDRINUSE (ERROR_BASE_NO + 98) +#define EADDRNOTAVAIL (ERROR_BASE_NO + 99) +#define ENETDOWN (ERROR_BASE_NO + 100) +#define ENETUNREACH (ERROR_BASE_NO + 101) +#define ENETRESET (ERROR_BASE_NO + 102) +#define ECONNABORTED (ERROR_BASE_NO + 103) +#define ECONNRESET (ERROR_BASE_NO + 104) +#define ENOBUFS (ERROR_BASE_NO + 105) +#define EISCONN (ERROR_BASE_NO + 106) +#define ENOTCONN (ERROR_BASE_NO + 107) +#define ESHUTDOWN (ERROR_BASE_NO + 108) +#define ETOOMANYREFS (ERROR_BASE_NO + 109) +#define ETIMEDOUT (ERROR_BASE_NO + 110) +#define ECONNREFUSED (ERROR_BASE_NO + 111) +#define EHOSTDOWN (ERROR_BASE_NO + 112) +#define EHOSTUNREACH (ERROR_BASE_NO + 113) +#define EALREADY (ERROR_BASE_NO + 114) +#define EINPROGRESS (ERROR_BASE_NO + 115) +#define ESTALE (ERROR_BASE_NO + 116) +#define EUCLEAN (ERROR_BASE_NO + 117) +#define ENOTNAM (ERROR_BASE_NO + 118) +#define ENAVAIL (ERROR_BASE_NO + 119) +#define EISNAM (ERROR_BASE_NO + 120) +#define EREMOTEIO (ERROR_BASE_NO + 121) +#define EDQUOT (ERROR_BASE_NO + 122) +#define ENOMEDIUM (ERROR_BASE_NO + 123) +#define EMEDIUMTYPE (ERROR_BASE_NO + 124) +#define ECANCELED (ERROR_BASE_NO + 125) +#define ENOKEY (ERROR_BASE_NO + 126) +#define EKEYEXPIRED (ERROR_BASE_NO + 127) +#define EKEYREVOKED (ERROR_BASE_NO + 128) +#define EKEYREJECTED (ERROR_BASE_NO + 129) +#define EOWNERDEAD (ERROR_BASE_NO + 130) +#define ENOTRECOVERABLE (ERROR_BASE_NO + 131) +#define ERFKILL (ERROR_BASE_NO + 132) +#define EHWPOISON (ERROR_BASE_NO + 133) +#endif + +#endif diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 9996212444..4cdfe77343 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -21,6 +21,7 @@ */ #include "sys/time.h" +#include #include #ifdef RT_USING_DEVICE diff --git a/components/libc/getline/posix_getline.c b/components/libc/getline/posix_getline.c index 794ac3a07d..da80242ecc 100644 --- a/components/libc/getline/posix_getline.c +++ b/components/libc/getline/posix_getline.c @@ -11,8 +11,8 @@ #include "posix_getline.h" #include -#include -#include +#include +#include ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { char *cur_pos, *new_lineptr; @@ -43,7 +43,7 @@ ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { break; if ((*lineptr + *n - cur_pos) < 2) { - if (SSIZE_MAX / 2 < *n) { + if (LONG_MAX / 2 < *n) { #ifdef EOVERFLOW errno = EOVERFLOW; #else diff --git a/components/libc/pthreads/posix_types.h b/components/libc/pthreads/posix_types.h index 942657ef39..5838e8b370 100644 --- a/components/libc/pthreads/posix_types.h +++ b/components/libc/pthreads/posix_types.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #endif diff --git a/components/libc/termios/posix_termios.c b/components/libc/termios/posix_termios.c index 01ba010c86..10a1f466d6 100644 --- a/components/libc/termios/posix_termios.c +++ b/components/libc/termios/posix_termios.c @@ -11,7 +11,7 @@ #include #include #include - +#include #include int tcgetattr(int fd, struct termios *tio) diff --git a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h index 8dd59e8dee..880366d1f8 100644 --- a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h +++ b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h @@ -105,7 +105,7 @@ void sys_arch_assert(const char* file, int line); #define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0) #define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0) -#include "string.h" +#include #define SYS_ARCH_DECL_PROTECT(level) #define SYS_ARCH_PROTECT(level) rt_enter_critical() diff --git a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h index e3014f552c..a17b162805 100644 --- a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h @@ -84,7 +84,7 @@ void sys_arch_assert(const char* file, int line); #define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0) #define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0) -#include "string.h" +#include #define SYS_ARCH_DECL_PROTECT(level) #define SYS_ARCH_PROTECT(level) rt_enter_critical() diff --git a/components/net/lwip-2.0.2/src/lwipopts.h b/components/net/lwip-2.0.2/src/lwipopts.h index 09bd223aa4..b334c5ac17 100644 --- a/components/net/lwip-2.0.2/src/lwipopts.h +++ b/components/net/lwip-2.0.2/src/lwipopts.h @@ -5,6 +5,8 @@ #define ERRNO 1 +#define LWIP_ERRNO_STDINCLUDE + #define LWIP_IPV4 1 #ifdef RT_USING_LWIP_IPV6 diff --git a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h index 413fef65df..e85ca1d085 100644 --- a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h @@ -46,7 +46,7 @@ #define X32_F "lx" #ifdef RT_USING_LIBC -#include +#include #ifndef ENSRNOTFOUND #define ENSRNOTFOUND 163 /* Domain name not found */ #endif diff --git a/components/net/lwip-2.1.2/src/include/lwip/errno.h b/components/net/lwip-2.1.2/src/include/lwip/errno.h index 48d6b539d8..9fd88fc91a 100644 --- a/components/net/lwip-2.1.2/src/include/lwip/errno.h +++ b/components/net/lwip-2.1.2/src/include/lwip/errno.h @@ -181,7 +181,7 @@ extern int errno; /* Define LWIP_ERRNO_STDINCLUDE if you want to include here */ #ifdef LWIP_ERRNO_STDINCLUDE -#include +#include #else /* LWIP_ERRNO_STDINCLUDE */ /* Define LWIP_ERRNO_INCLUDE to an equivalent of to include the error defines here */ #ifdef LWIP_ERRNO_INCLUDE diff --git a/components/net/lwip-2.1.2/src/lwipopts.h b/components/net/lwip-2.1.2/src/lwipopts.h index 220bb6fa41..8c2bfbdd76 100644 --- a/components/net/lwip-2.1.2/src/lwipopts.h +++ b/components/net/lwip-2.1.2/src/lwipopts.h @@ -5,6 +5,7 @@ #define ERRNO 1 +#define LWIP_ERRNO_STDINCLUDE #define LWIP_SOCKET_SELECT 1 #define LWIP_SOCKET_POLL 1 diff --git a/components/net/sal_socket/socket/net_sockets.c b/components/net/sal_socket/socket/net_sockets.c index 3637635d50..7d4db34327 100644 --- a/components/net/sal_socket/socket/net_sockets.c +++ b/components/net/sal_socket/socket/net_sockets.c @@ -13,7 +13,7 @@ #include #include #include - +#include #include int accept(int s, struct sockaddr *addr, socklen_t *addrlen) diff --git a/examples/libc/ex3.c b/examples/libc/ex3.c index 1697e7145b..615ed8f35c 100644 --- a/examples/libc/ex3.c +++ b/examples/libc/ex3.c @@ -9,7 +9,7 @@ /* Multi-thread searching. Illustrates: thread cancellation, cleanup handlers. */ -#include +#include #include #include #include diff --git a/examples/libc/ex6.c b/examples/libc/ex6.c index ac6319d74c..ba687aa46f 100644 --- a/examples/libc/ex6.c +++ b/examples/libc/ex6.c @@ -6,7 +6,7 @@ * Change Logs: * Date Author Notes */ -#include +#include #include #include #include diff --git a/examples/libc/ex7.c b/examples/libc/ex7.c index e885f79c57..d1f05dbdcd 100644 --- a/examples/libc/ex7.c +++ b/examples/libc/ex7.c @@ -11,7 +11,7 @@ * Test case that illustrates a timed wait on a condition variable. */ -#include +#include #include #include #include diff --git a/examples/libc/file.c b/examples/libc/file.c index 79cdce3092..878d3a98d7 100644 --- a/examples/libc/file.c +++ b/examples/libc/file.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/examples/libc/memory.c b/examples/libc/memory.c index 063d90cfdc..4a31b69017 100644 --- a/examples/libc/memory.c +++ b/examples/libc/memory.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include static int errors = 0; static void merror(const char *msg) diff --git a/include/libc/libc_errno.h b/include/libc/libc_errno.h deleted file mode 100644 index 30d6092e33..0000000000 --- a/include/libc/libc_errno.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2016-11-12 Bernard The first version - */ - -#ifndef LIBC_ERRNO_H__ -#define LIBC_ERRNO_H__ - -#include - -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) -/* use errno.h file in toolchains */ -#include -#endif - -#if defined(__CC_ARM) -/* -defined in armcc/errno.h - -#define EDOM 1 -#define ERANGE 2 -#define EILSEQ 4 -#define ESIGNUM 3 -#define EINVAL 5 -#define ENOMEM 6 -*/ -#define ERROR_BASE_NO 7 - -#elif defined(__IAR_SYSTEMS_ICC__) -/* defined in iar/errno.h -#define EDOM 33 -#define ERANGE 34 -#define EFPOS 35 -#define EILSEQ 36 -*/ -#define ERROR_BASE_NO 36 - -#else - -#define ERROR_BASE_NO 0 -#endif - -#if !defined(RT_USING_NEWLIB) && !defined(_WIN32) && !(defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) - -#define EPERM (ERROR_BASE_NO + 1) -#define ENOENT (ERROR_BASE_NO + 2) -#define ESRCH (ERROR_BASE_NO + 3) -#define EINTR (ERROR_BASE_NO + 4) -#define EIO (ERROR_BASE_NO + 5) -#define ENXIO (ERROR_BASE_NO + 6) -#define E2BIG (ERROR_BASE_NO + 7) -#define ENOEXEC (ERROR_BASE_NO + 8) -#define EBADF (ERROR_BASE_NO + 9) -#define ECHILD (ERROR_BASE_NO + 10) -#define EAGAIN (ERROR_BASE_NO + 11) - -#ifndef ENOMEM -#define ENOMEM (ERROR_BASE_NO + 12) -#endif - -#define EACCES (ERROR_BASE_NO + 13) -#define EFAULT (ERROR_BASE_NO + 14) -#define ENOTBLK (ERROR_BASE_NO + 15) -#define EBUSY (ERROR_BASE_NO + 16) -#define EEXIST (ERROR_BASE_NO + 17) -#define EXDEV (ERROR_BASE_NO + 18) -#define ENODEV (ERROR_BASE_NO + 19) -#define ENOTDIR (ERROR_BASE_NO + 20) -#define EISDIR (ERROR_BASE_NO + 21) - -#ifndef EINVAL -#define EINVAL (ERROR_BASE_NO + 22) -#endif - -#define ENFILE (ERROR_BASE_NO + 23) -#define EMFILE (ERROR_BASE_NO + 24) -#define ENOTTY (ERROR_BASE_NO + 25) -#define ETXTBSY (ERROR_BASE_NO + 26) -#define EFBIG (ERROR_BASE_NO + 27) -#define ENOSPC (ERROR_BASE_NO + 28) -#define ESPIPE (ERROR_BASE_NO + 29) -#define EROFS (ERROR_BASE_NO + 30) -#define EMLINK (ERROR_BASE_NO + 31) -#define EPIPE (ERROR_BASE_NO + 32) - -#ifndef EDOM -#define EDOM (ERROR_BASE_NO + 33) -#endif - -#ifndef ERANGE -#define ERANGE (ERROR_BASE_NO + 34) -#endif - -#define EDEADLK (ERROR_BASE_NO + 35) -#define ENAMETOOLONG (ERROR_BASE_NO + 36) -#define ENOLCK (ERROR_BASE_NO + 37) -#define ENOSYS (ERROR_BASE_NO + 38) -#define ENOTEMPTY (ERROR_BASE_NO + 39) -#define ELOOP (ERROR_BASE_NO + 40) -#define EWOULDBLOCK EAGAIN -#define ENOMSG (ERROR_BASE_NO + 42) -#define EIDRM (ERROR_BASE_NO + 43) -#define ECHRNG (ERROR_BASE_NO + 44) -#define EL2NSYNC (ERROR_BASE_NO + 45) -#define EL3HLT (ERROR_BASE_NO + 46) -#define EL3RST (ERROR_BASE_NO + 47) -#define ELNRNG (ERROR_BASE_NO + 48) -#define EUNATCH (ERROR_BASE_NO + 49) -#define ENOCSI (ERROR_BASE_NO + 50) -#define EL2HLT (ERROR_BASE_NO + 51) -#define EBADE (ERROR_BASE_NO + 52) -#define EBADR (ERROR_BASE_NO + 53) -#define EXFULL (ERROR_BASE_NO + 54) -#define ENOANO (ERROR_BASE_NO + 55) -#define EBADRQC (ERROR_BASE_NO + 56) -#define EBADSLT (ERROR_BASE_NO + 57) -#define EDEADLOCK EDEADLK -#define EBFONT (ERROR_BASE_NO + 59) -#define ENOSTR (ERROR_BASE_NO + 60) -#define ENODATA (ERROR_BASE_NO + 61) -#define ETIME (ERROR_BASE_NO + 62) -#define ENOSR (ERROR_BASE_NO + 63) -#define ENONET (ERROR_BASE_NO + 64) -#define ENOPKG (ERROR_BASE_NO + 65) -#define EREMOTE (ERROR_BASE_NO + 66) -#define ENOLINK (ERROR_BASE_NO + 67) -#define EADV (ERROR_BASE_NO + 68) -#define ESRMNT (ERROR_BASE_NO + 69) -#define ECOMM (ERROR_BASE_NO + 70) -#define EPROTO (ERROR_BASE_NO + 71) -#define EMULTIHOP (ERROR_BASE_NO + 72) -#define EDOTDOT (ERROR_BASE_NO + 73) -#define EBADMSG (ERROR_BASE_NO + 74) -#define EOVERFLOW (ERROR_BASE_NO + 75) -#define ENOTUNIQ (ERROR_BASE_NO + 76) -#define EBADFD (ERROR_BASE_NO + 77) -#define EREMCHG (ERROR_BASE_NO + 78) -#define ELIBACC (ERROR_BASE_NO + 79) -#define ELIBBAD (ERROR_BASE_NO + 80) -#define ELIBSCN (ERROR_BASE_NO + 81) -#define ELIBMAX (ERROR_BASE_NO + 82) -#define ELIBEXEC (ERROR_BASE_NO + 83) - -#ifndef EILSEQ -#define EILSEQ (ERROR_BASE_NO + 84) -#endif - -#define ERESTART (ERROR_BASE_NO + 85) -#define ESTRPIPE (ERROR_BASE_NO + 86) -#define EUSERS (ERROR_BASE_NO + 87) -#define ENOTSOCK (ERROR_BASE_NO + 88) -#define EDESTADDRREQ (ERROR_BASE_NO + 89) -#define EMSGSIZE (ERROR_BASE_NO + 90) -#define EPROTOTYPE (ERROR_BASE_NO + 91) -#define ENOPROTOOPT (ERROR_BASE_NO + 92) -#define EPROTONOSUPPORT (ERROR_BASE_NO + 93) -#define ESOCKTNOSUPPORT (ERROR_BASE_NO + 94) -#define EOPNOTSUPP (ERROR_BASE_NO + 95) -#define ENOTSUP EOPNOTSUPP -#define EPFNOSUPPORT (ERROR_BASE_NO + 96) -#define EAFNOSUPPORT (ERROR_BASE_NO + 97) -#define EADDRINUSE (ERROR_BASE_NO + 98) -#define EADDRNOTAVAIL (ERROR_BASE_NO + 99) -#define ENETDOWN (ERROR_BASE_NO + 100) -#define ENETUNREACH (ERROR_BASE_NO + 101) -#define ENETRESET (ERROR_BASE_NO + 102) -#define ECONNABORTED (ERROR_BASE_NO + 103) -#define ECONNRESET (ERROR_BASE_NO + 104) -#define ENOBUFS (ERROR_BASE_NO + 105) -#define EISCONN (ERROR_BASE_NO + 106) -#define ENOTCONN (ERROR_BASE_NO + 107) -#define ESHUTDOWN (ERROR_BASE_NO + 108) -#define ETOOMANYREFS (ERROR_BASE_NO + 109) -#define ETIMEDOUT (ERROR_BASE_NO + 110) -#define ECONNREFUSED (ERROR_BASE_NO + 111) -#define EHOSTDOWN (ERROR_BASE_NO + 112) -#define EHOSTUNREACH (ERROR_BASE_NO + 113) -#define EALREADY (ERROR_BASE_NO + 114) -#define EINPROGRESS (ERROR_BASE_NO + 115) -#define ESTALE (ERROR_BASE_NO + 116) -#define EUCLEAN (ERROR_BASE_NO + 117) -#define ENOTNAM (ERROR_BASE_NO + 118) -#define ENAVAIL (ERROR_BASE_NO + 119) -#define EISNAM (ERROR_BASE_NO + 120) -#define EREMOTEIO (ERROR_BASE_NO + 121) -#define EDQUOT (ERROR_BASE_NO + 122) -#define ENOMEDIUM (ERROR_BASE_NO + 123) -#define EMEDIUMTYPE (ERROR_BASE_NO + 124) -#define ECANCELED (ERROR_BASE_NO + 125) -#define ENOKEY (ERROR_BASE_NO + 126) -#define EKEYEXPIRED (ERROR_BASE_NO + 127) -#define EKEYREVOKED (ERROR_BASE_NO + 128) -#define EKEYREJECTED (ERROR_BASE_NO + 129) -#define EOWNERDEAD (ERROR_BASE_NO + 130) -#define ENOTRECOVERABLE (ERROR_BASE_NO + 131) -#define ERFKILL (ERROR_BASE_NO + 132) -#define EHWPOISON (ERROR_BASE_NO + 133) - -#endif - -#endif diff --git a/include/libc/libc_limits.h b/include/libc/libc_limits.h deleted file mode 100644 index 36b8dbb202..0000000000 --- a/include/libc/libc_limits.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020-09-05 Meco Man the first version - */ - -#ifndef LIBC_LIMITS_H__ -#define LIBC_LIMITS_H__ - -#include -#include - -#ifdef RT_USING_POSIX - -#ifndef SSIZE_MAX -# define SSIZE_MAX LONG_MAX -#endif - -#endif - -#endif diff --git a/include/rtlibc.h b/include/rtlibc.h index 50bddc6ee8..a62051e157 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -13,14 +13,12 @@ /* definitions for libc if toolchain has no these definitions */ #include "libc/libc_stat.h" -#include "libc/libc_errno.h" #include "libc/libc_fcntl.h" #include "libc/libc_ioctl.h" #include "libc/libc_dirent.h" #include "libc/libc_signal.h" #include "libc/libc_fdset.h" -#include "libc/libc_limits.h" #include "libc/libc_stdio.h" #ifndef RT_USING_LIBC -- cgit v1.3.1 From b10bef6f241bfd9a6ecba3412351b20f3aa2eb13 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 22 May 2021 03:20:01 +0800 Subject: [sys/errno.h] 修复lwip报错 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/none-gcc/sys/errno.h | 4 +--- components/net/lwip-1.4.1/src/arch/include/arch/cc.h | 8 ++++---- components/net/lwip-2.0.2/src/arch/include/arch/cc.h | 12 ++++++++++++ components/net/lwip-2.1.2/src/arch/include/arch/cc.h | 7 +++---- 4 files changed, 20 insertions(+), 11 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h index bdc3a3c9da..773c2cd7d3 100644 --- a/components/libc/compilers/common/none-gcc/sys/errno.h +++ b/components/libc/compilers/common/none-gcc/sys/errno.h @@ -37,10 +37,8 @@ defined in armcc/errno.h #define ERROR_BASE_NO 0 #endif -#if !defined(_WIN32) - +#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) #include - #define EPERM (ERROR_BASE_NO + 1) #define ENOENT (ERROR_BASE_NO + 2) #define ESRCH (ERROR_BASE_NO + 3) diff --git a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h index 880366d1f8..23562703c3 100644 --- a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h +++ b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h @@ -54,16 +54,16 @@ typedef uintptr_t mem_ptr_t; #define S32_F "ld" #define X32_F "lx" -#ifdef RT_USING_LIBC -#if !defined(__CC_ARM) && !defined(__IAR_SYSTEMS_ICC__) - +#include /* some errno not defined in newlib */ +#ifndef ENSRNOTFOUND #define ENSRNOTFOUND 163 /* Domain name not found */ /* WARNING: ESHUTDOWN also not defined in newlib. We chose 180 here because the number "108" which is used in arch.h has been assigned to another error code. */ +#endif +#ifndef ESHUTDOWN #define ESHUTDOWN 180 -#endif /* __CC_ARM/__IAR_SYSTEMS_ICC__ */ #endif #if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) diff --git a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h index a17b162805..51662ae4a5 100644 --- a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h @@ -45,6 +45,18 @@ #define S32_F "ld" #define X32_F "lx" +#include +/* some errno not defined in newlib */ +#ifndef ENSRNOTFOUND +#define ENSRNOTFOUND 163 /* Domain name not found */ +/* WARNING: ESHUTDOWN also not defined in newlib. We chose + 180 here because the number "108" which is used + in arch.h has been assigned to another error code. */ +#endif +#ifndef ESHUTDOWN +#define ESHUTDOWN 180 +#endif + #if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) #include #define LWIP_TIMEVAL_PRIVATE 0 diff --git a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h index e85ca1d085..f4068c1d80 100644 --- a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h @@ -45,18 +45,17 @@ #define S32_F "ld" #define X32_F "lx" -#ifdef RT_USING_LIBC #include +/* some errno not defined in newlib */ #ifndef ENSRNOTFOUND #define ENSRNOTFOUND 163 /* Domain name not found */ -#endif -#ifndef ESHUTDOWN /* WARNING: ESHUTDOWN also not defined in newlib. We chose 180 here because the number "108" which is used in arch.h has been assigned to another error code. */ +#endif +#ifndef ESHUTDOWN #define ESHUTDOWN 180 #endif -#endif /* RT_USING_LIBC */ #if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) #include -- cgit v1.3.1 From 0e32728a5d688c51bc844617de7d89d7fdbe34d0 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 23 May 2021 00:14:22 +0800 Subject: [libc][rtlibc] remove libc_ioctl.h --- components/libc/compilers/common/sys/ioctl.h | 220 +++++++++++++++++++++++++ include/libc/libc_ioctl.h | 229 --------------------------- include/rtlibc.h | 1 - 3 files changed, 220 insertions(+), 230 deletions(-) delete mode 100644 include/libc/libc_ioctl.h (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h index 648d90230d..51f51f2ea4 100644 --- a/components/libc/compilers/common/sys/ioctl.h +++ b/components/libc/compilers/common/sys/ioctl.h @@ -15,4 +15,224 @@ #include #endif +struct winsize { + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; +}; + +#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) +#define _IOC_NONE 0U +#define _IOC_WRITE 1U +#define _IOC_READ 2U + +#if !defined (_WIN32) && !defined (__TASKING__) +#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) + +#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ +#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ +#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding in send queue */ +#endif + +#define TCGETS 0x5401 +#define TCSETS 0x5402 +#define TCSETSW 0x5403 +#define TCSETSF 0x5404 +#define TCGETA 0x5405 +#define TCSETA 0x5406 +#define TCSETAW 0x5407 +#define TCSETAF 0x5408 +#define TCSBRK 0x5409 +#define TCXONC 0x540A +#define TCFLSH 0x540B +#define TIOCEXCL 0x540C +#define TIOCNXCL 0x540D +#define TIOCSCTTY 0x540E +#define TIOCGPGRP 0x540F +#define TIOCSPGRP 0x5410 +#define TIOCOUTQ 0x5411 +#define TIOCSTI 0x5412 +#define TIOCGWINSZ 0x5413 +#define TIOCSWINSZ 0x5414 +#define TIOCMGET 0x5415 +#define TIOCMBIS 0x5416 +#define TIOCMBIC 0x5417 +#define TIOCMSET 0x5418 +#define TIOCGSOFTCAR 0x5419 +#define TIOCSSOFTCAR 0x541A +#ifndef FIONREAD +#define FIONREAD 0x541B +#endif +#define TIOCINQ FIONREAD +#define TIOCLINUX 0x541C +#define TIOCCONS 0x541D +#define TIOCGSERIAL 0x541E +#define TIOCSSERIAL 0x541F +#define TIOCPKT 0x5420 +#ifndef FIONBIO +#define FIONBIO 0x5421 +#endif +#define TIOCNOTTY 0x5422 +#define TIOCSETD 0x5423 +#define TIOCGETD 0x5424 +#define TCSBRKP 0x5425 +#define TIOCSBRK 0x5427 +#define TIOCCBRK 0x5428 +#define TIOCGSID 0x5429 +#define TIOCGRS485 0x542E +#define TIOCSRS485 0x542F +#define TIOCGPTN 0x80045430 +#define TIOCSPTLCK 0x40045431 +#define TIOCGDEV 0x80045432 +#define TCGETX 0x5432 +#define TCSETX 0x5433 +#define TCSETXF 0x5434 +#define TCSETXW 0x5435 +#define TIOCSIG 0x40045436 +#define TIOCVHANGUP 0x5437 +#define TIOCGPKT 0x80045438 +#define TIOCGPTLCK 0x80045439 +#define TIOCGEXCL 0x80045440 + +#define FIONCLEX 0x5450 +#define FIOCLEX 0x5451 + +#ifndef _WIN32 +#define FIOASYNC 0x5452 +#endif + +#define TIOCSERCONFIG 0x5453 +#define TIOCSERGWILD 0x5454 +#define TIOCSERSWILD 0x5455 +#define TIOCGLCKTRMIOS 0x5456 +#define TIOCSLCKTRMIOS 0x5457 +#define TIOCSERGSTRUCT 0x5458 +#define TIOCSERGETLSR 0x5459 +#define TIOCSERGETMULTI 0x545A +#define TIOCSERSETMULTI 0x545B + +#define TIOCMIWAIT 0x545C +#define TIOCGICOUNT 0x545D +#define FIOQSIZE 0x5460 + +#define TIOCPKT_DATA 0 +#define TIOCPKT_FLUSHREAD 1 +#define TIOCPKT_FLUSHWRITE 2 +#define TIOCPKT_STOP 4 +#define TIOCPKT_START 8 +#define TIOCPKT_NOSTOP 16 +#define TIOCPKT_DOSTOP 32 +#define TIOCPKT_IOCTL 64 + +#define TIOCSER_TEMT 0x01 + +#define TIOCM_LE 0x001 +#define TIOCM_DTR 0x002 +#define TIOCM_RTS 0x004 +#define TIOCM_ST 0x008 +#define TIOCM_SR 0x010 +#define TIOCM_CTS 0x020 +#define TIOCM_CAR 0x040 +#define TIOCM_RNG 0x080 +#define TIOCM_DSR 0x100 +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RI TIOCM_RNG +#define TIOCM_OUT1 0x2000 +#define TIOCM_OUT2 0x4000 +#define TIOCM_LOOP 0x8000 + +#define N_TTY 0 +#define N_SLIP 1 +#define N_MOUSE 2 +#define N_PPP 3 +#define N_STRIP 4 +#define N_AX25 5 +#define N_X25 6 +#define N_6PACK 7 +#define N_MASC 8 +#define N_R3964 9 +#define N_PROFIBUS_FDL 10 +#define N_IRDA 11 +#define N_SMSBLOCK 12 +#define N_HDLC 13 +#define N_SYNC_PPP 14 +#define N_HCI 15 + +#define FIOSETOWN 0x8901 +#define SIOCSPGRP 0x8902 +#define FIOGETOWN 0x8903 +#define SIOCGPGRP 0x8904 +#ifndef SIOCATMARK +#define SIOCATMARK 0x8905 +#endif +#define SIOCGSTAMP 0x8906 +#define SIOCGSTAMPNS 0x8907 + +#define SIOCADDRT 0x890B +#define SIOCDELRT 0x890C +#define SIOCRTMSG 0x890D + +#define SIOCGIFNAME 0x8910 +#define SIOCSIFLINK 0x8911 +#define SIOCGIFCONF 0x8912 +#define SIOCGIFFLAGS 0x8913 +#define SIOCSIFFLAGS 0x8914 +#define SIOCGIFADDR 0x8915 +#define SIOCSIFADDR 0x8916 +#define SIOCGIFDSTADDR 0x8917 +#define SIOCSIFDSTADDR 0x8918 +#define SIOCGIFBRDADDR 0x8919 +#define SIOCSIFBRDADDR 0x891a +#define SIOCGIFNETMASK 0x891b +#define SIOCSIFNETMASK 0x891c +#define SIOCGIFMETRIC 0x891d +#define SIOCSIFMETRIC 0x891e +#define SIOCGIFMEM 0x891f +#define SIOCSIFMEM 0x8920 +#define SIOCGIFMTU 0x8921 +#define SIOCSIFMTU 0x8922 +#define SIOCSIFNAME 0x8923 +#define SIOCSIFHWADDR 0x8924 +#define SIOCGIFENCAP 0x8925 +#define SIOCSIFENCAP 0x8926 +#define SIOCGIFHWADDR 0x8927 +#define SIOCGIFSLAVE 0x8929 +#define SIOCSIFSLAVE 0x8930 +#define SIOCADDMULTI 0x8931 +#define SIOCDELMULTI 0x8932 +#define SIOCGIFINDEX 0x8933 +#define SIOGIFINDEX SIOCGIFINDEX +#define SIOCSIFPFLAGS 0x8934 +#define SIOCGIFPFLAGS 0x8935 +#define SIOCDIFADDR 0x8936 +#define SIOCSIFHWBROADCAST 0x8937 +#define SIOCGIFCOUNT 0x8938 + +#define SIOCGIFBR 0x8940 +#define SIOCSIFBR 0x8941 + +#define SIOCGIFTXQLEN 0x8942 +#define SIOCSIFTXQLEN 0x8943 + +#define SIOCDARP 0x8953 +#define SIOCGARP 0x8954 +#define SIOCSARP 0x8955 + +#define SIOCDRARP 0x8960 +#define SIOCGRARP 0x8961 +#define SIOCSRARP 0x8962 + +#define SIOCGIFMAP 0x8970 +#define SIOCSIFMAP 0x8971 + +#define SIOCADDDLCI 0x8980 +#define SIOCDELDLCI 0x8981 + +#define SIOCDEVPRIVATE 0x89F0 +#define SIOCPROTOPRIVATE 0x89E0 + #endif diff --git a/include/libc/libc_ioctl.h b/include/libc/libc_ioctl.h deleted file mode 100644 index 05f0daa238..0000000000 --- a/include/libc/libc_ioctl.h +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017-01-21 Bernard the first version - */ - -#ifndef LIBC_IOCTL_H__ -#define LIBC_IOCTL_H__ - -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U - -#if !defined (_WIN32) && !defined (__TASKING__) -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) - -#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ -#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ -#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding - * in send queue. */ -#endif - -#define TCGETS 0x5401 -#define TCSETS 0x5402 -#define TCSETSW 0x5403 -#define TCSETSF 0x5404 -#define TCGETA 0x5405 -#define TCSETA 0x5406 -#define TCSETAW 0x5407 -#define TCSETAF 0x5408 -#define TCSBRK 0x5409 -#define TCXONC 0x540A -#define TCFLSH 0x540B -#define TIOCEXCL 0x540C -#define TIOCNXCL 0x540D -#define TIOCSCTTY 0x540E -#define TIOCGPGRP 0x540F -#define TIOCSPGRP 0x5410 -#define TIOCOUTQ 0x5411 -#define TIOCSTI 0x5412 -#define TIOCGWINSZ 0x5413 -#define TIOCSWINSZ 0x5414 -#define TIOCMGET 0x5415 -#define TIOCMBIS 0x5416 -#define TIOCMBIC 0x5417 -#define TIOCMSET 0x5418 -#define TIOCGSOFTCAR 0x5419 -#define TIOCSSOFTCAR 0x541A -// #define FIONREAD 0x541B -#define TIOCINQ FIONREAD -#define TIOCLINUX 0x541C -#define TIOCCONS 0x541D -#define TIOCGSERIAL 0x541E -#define TIOCSSERIAL 0x541F -#define TIOCPKT 0x5420 -// #define FIONBIO 0x5421 -#define TIOCNOTTY 0x5422 -#define TIOCSETD 0x5423 -#define TIOCGETD 0x5424 -#define TCSBRKP 0x5425 -#define TIOCSBRK 0x5427 -#define TIOCCBRK 0x5428 -#define TIOCGSID 0x5429 -#define TIOCGRS485 0x542E -#define TIOCSRS485 0x542F -#define TIOCGPTN 0x80045430 -#define TIOCSPTLCK 0x40045431 -#define TIOCGDEV 0x80045432 -#define TCGETX 0x5432 -#define TCSETX 0x5433 -#define TCSETXF 0x5434 -#define TCSETXW 0x5435 -#define TIOCSIG 0x40045436 -#define TIOCVHANGUP 0x5437 -#define TIOCGPKT 0x80045438 -#define TIOCGPTLCK 0x80045439 -#define TIOCGEXCL 0x80045440 - -#define FIONCLEX 0x5450 -#define FIOCLEX 0x5451 - -#ifndef _WIN32 -#define FIOASYNC 0x5452 -#endif - -#define TIOCSERCONFIG 0x5453 -#define TIOCSERGWILD 0x5454 -#define TIOCSERSWILD 0x5455 -#define TIOCGLCKTRMIOS 0x5456 -#define TIOCSLCKTRMIOS 0x5457 -#define TIOCSERGSTRUCT 0x5458 -#define TIOCSERGETLSR 0x5459 -#define TIOCSERGETMULTI 0x545A -#define TIOCSERSETMULTI 0x545B - -#define TIOCMIWAIT 0x545C -#define TIOCGICOUNT 0x545D -#define FIOQSIZE 0x5460 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 0x01 - -struct winsize { - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; -}; - -#define TIOCM_LE 0x001 -#define TIOCM_DTR 0x002 -#define TIOCM_RTS 0x004 -#define TIOCM_ST 0x008 -#define TIOCM_SR 0x010 -#define TIOCM_CTS 0x020 -#define TIOCM_CAR 0x040 -#define TIOCM_RNG 0x080 -#define TIOCM_DSR 0x100 -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RI TIOCM_RNG -#define TIOCM_OUT1 0x2000 -#define TIOCM_OUT2 0x4000 -#define TIOCM_LOOP 0x8000 - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 - -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -// #define SIOCATMARK 0x8905 -#define SIOCGSTAMP 0x8906 -#define SIOCGSTAMPNS 0x8907 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFNAME 0x8923 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 - -#endif diff --git a/include/rtlibc.h b/include/rtlibc.h index 50bddc6ee8..d69f3ca185 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -16,7 +16,6 @@ #include "libc/libc_errno.h" #include "libc/libc_fcntl.h" -#include "libc/libc_ioctl.h" #include "libc/libc_dirent.h" #include "libc/libc_signal.h" #include "libc/libc_fdset.h" -- cgit v1.3.1 From 740a810274b9b9ccd74c4163fa9b11b5ee7f7926 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 12 Jun 2021 18:11:51 +0800 Subject: [errno][libc] 解决sys头文件在libc未开启时的引入问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/src/pipe.c | 11 ++++++----- components/finsh/shell.c | 2 +- components/libc/compilers/common/SConscript | 13 +++++-------- components/libc/compilers/common/none-gcc/SConscript | 6 ++++-- components/libc/compilers/newlib/minilib.c | 14 ++++++-------- 5 files changed, 22 insertions(+), 24 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index 236c1ffec7..09448a8e9e 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/src/pipe.c @@ -11,8 +11,9 @@ #include #include #include +#include -#if defined(RT_USING_POSIX) +#ifdef RT_USING_POSIX #include #include #include @@ -374,7 +375,7 @@ rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t if (device == RT_NULL) { - rt_set_errno(-EINVAL); + rt_set_errno(EINVAL); return 0; } if (count == 0) return 0; @@ -402,7 +403,7 @@ rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt if (device == RT_NULL) { - rt_set_errno(-EINVAL); + rt_set_errno(EINVAL); return 0; } if (count == 0) return 0; @@ -516,12 +517,12 @@ int rt_pipe_delete(const char *name) } else { - result = -ENODEV; + result = -RT_EINVAL; } } else { - result = -ENODEV; + result = -RT_EINVAL; } return result; diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 6f1133bf3b..a749660629 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -97,7 +97,7 @@ int finsh_set_prompt(const char * prompt) } #endif /* RT_USING_HEAP */ -#if defined(RT_USING_DFS) +#ifdef RT_USING_DFS #include #endif /* RT_USING_DFS */ diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 039e53a0b3..2ebfc36c4e 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -9,20 +9,17 @@ CPPPATH = [cwd] if GetDepend('RT_USING_LIBC'): src += Glob('*.c') -else: - if GetDepend('RT_LIBC_USING_TIME'): - src += ['time.c'] - -if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) + if GetDepend('RT_USING_POSIX') == False: + SrcRemove(src, ['unistd.c']) +elif GetDepend('RT_LIBC_USING_TIME'): + src += ['time.c'] if rtconfig.CROSS_TOOL == 'keil': CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND'] else: CPPDEFINES = [] -if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'): - group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) +group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) list = os.listdir(cwd) for d in list: diff --git a/components/libc/compilers/common/none-gcc/SConscript b/components/libc/compilers/common/none-gcc/SConscript index c5838f8949..c766c8f82d 100644 --- a/components/libc/compilers/common/none-gcc/SConscript +++ b/components/libc/compilers/common/none-gcc/SConscript @@ -6,8 +6,10 @@ src = [] cwd = GetCurrentDir() CPPPATH = [cwd] group = [] -src += Glob('*.c') + +if GetDepend('RT_USING_LIBC'): + src += Glob('*.c') if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim': - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH) + group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/compilers/newlib/minilib.c b/components/libc/compilers/newlib/minilib.c index f6df38f67b..612554ca66 100644 --- a/components/libc/compilers/newlib/minilib.c +++ b/components/libc/compilers/newlib/minilib.c @@ -12,8 +12,9 @@ #include #ifdef RT_USING_HEAP /* Memory routine */ -void * -_malloc_r (struct _reent *ptr, size_t size) +#include + +void * _malloc_r (struct _reent *ptr, size_t size) { void* result; @@ -26,8 +27,7 @@ _malloc_r (struct _reent *ptr, size_t size) return result; } -void * -_realloc_r (struct _reent *ptr, void *old, size_t newlen) +void * _realloc_r (struct _reent *ptr, void *old, size_t newlen) { void* result; @@ -53,15 +53,13 @@ void *_calloc_r (struct _reent *ptr, size_t size, size_t len) return result; } -void -_free_r (struct _reent *ptr, void *addr) +void _free_r (struct _reent *ptr, void *addr) { rt_free (addr); } #else -void * -_sbrk_r(struct _reent *ptr, ptrdiff_t incr) +void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr) { return RT_NULL; } -- cgit v1.3.1 From 5bb6e86cf5573eac5395b2c31f7fb0650382605e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 13 Jun 2021 17:16:03 +0800 Subject: [sys/errno.h] 修复armclang支持问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/none-gcc/sys/errno.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h index 773c2cd7d3..ad3614024d 100644 --- a/components/libc/compilers/common/none-gcc/sys/errno.h +++ b/components/libc/compilers/common/none-gcc/sys/errno.h @@ -10,7 +10,7 @@ #ifndef _SYS_ERRNO_H #define _SYS_ERRNO_H -#if defined(__CC_ARM) +#if defined(__ARMCC_VERSION) /* defined in armcc/errno.h @@ -37,7 +37,7 @@ defined in armcc/errno.h #define ERROR_BASE_NO 0 #endif -#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) +#if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) #include #define EPERM (ERROR_BASE_NO + 1) #define ENOENT (ERROR_BASE_NO + 2) -- cgit v1.3.1 From 66b7289ee75653f6024ca3b9c0bdff96fe0bc046 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Tue, 15 Jun 2021 18:29:58 +0800 Subject: [update] usleep supports calling in interrupts. --- components/libc/compilers/common/unistd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c index 6c81fc7662..4385643f31 100644 --- a/components/libc/compilers/common/unistd.c +++ b/components/libc/compilers/common/unistd.c @@ -55,7 +55,14 @@ RTM_EXPORT(sleep); int usleep(useconds_t usec) { - rt_thread_mdelay(usec / 1000u); + if (rt_thread_self() != RT_NULL) + { + rt_thread_mdelay(usec / 1000u); + } + else + { + rt_hw_us_delay(usec / 1000u); + } rt_hw_us_delay(usec % 1000u); return 0; } -- cgit v1.3.1 From 6697fa0ff54219b6d0b4f65dd28cdcdd22e0158c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 16 Jun 2021 12:15:24 +0800 Subject: [sleep] 加入调度器尚未运行时的延时情况 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/unistd.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c index 4385643f31..9a457c4200 100644 --- a/components/libc/compilers/common/unistd.c +++ b/components/libc/compilers/common/unistd.c @@ -37,19 +37,26 @@ RTM_EXPORT(isatty); char *ttyname(int fd) { - return "/dev/tty"; /*TODO: need to add more specific*/ + return "/dev/tty"; /* TODO: need to add more specific */ } RTM_EXPORT(ttyname); unsigned int sleep(unsigned int seconds) { - rt_tick_t delta_tick; - - delta_tick = rt_tick_get(); - rt_thread_delay(seconds * RT_TICK_PER_SECOND); - delta_tick = rt_tick_get() - delta_tick; + if (rt_thread_self() != RT_NULL) + { + rt_thread_delay(seconds * RT_TICK_PER_SECOND); + } + else /* scheduler has not run yet */ + { + while(seconds > 0) + { + rt_hw_us_delay(1000000u); + seconds --; + } + } - return seconds - delta_tick/RT_TICK_PER_SECOND; + return 0; } RTM_EXPORT(sleep); @@ -59,11 +66,12 @@ int usleep(useconds_t usec) { rt_thread_mdelay(usec / 1000u); } - else + else /* scheduler has not run yet */ { rt_hw_us_delay(usec / 1000u); } rt_hw_us_delay(usec % 1000u); + return 0; } RTM_EXPORT(usleep); -- cgit v1.3.1 From 56e3571e8a8ede72b9aec00c968ace7b2bbe548c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 16 Jun 2021 14:02:43 +0800 Subject: implement delay.c/.h --- bsp/qemu-vexpress-a9/drivers/board.c | 5 ++++ bsp/qemu-vexpress-a9/drivers/drv_smc911x.c | 10 ------- components/libc/compilers/common/SConscript | 2 +- components/libc/compilers/common/delay.c | 41 +++++++++++++++++++++++++++++ components/libc/compilers/common/delay.h | 19 +++++++++++++ 5 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 components/libc/compilers/common/delay.c create mode 100644 components/libc/compilers/common/delay.h (limited to 'components/libc/compilers') diff --git a/bsp/qemu-vexpress-a9/drivers/board.c b/bsp/qemu-vexpress-a9/drivers/board.c index e236c68b80..84af3c1ccd 100644 --- a/bsp/qemu-vexpress-a9/drivers/board.c +++ b/bsp/qemu-vexpress-a9/drivers/board.c @@ -55,3 +55,8 @@ void rt_hw_board_init(void) rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler); #endif } + +void rt_hw_us_delay(rt_uint32_t us) +{ + +} diff --git a/bsp/qemu-vexpress-a9/drivers/drv_smc911x.c b/bsp/qemu-vexpress-a9/drivers/drv_smc911x.c index 2b2253328d..9d52b258af 100644 --- a/bsp/qemu-vexpress-a9/drivers/drv_smc911x.c +++ b/bsp/qemu-vexpress-a9/drivers/drv_smc911x.c @@ -33,16 +33,6 @@ struct eth_device_smc911x }; static struct eth_device_smc911x _emac; -int udelay(int value) -{ - return 0; -} - -int mdelay(int value) -{ - return 0; -} - #if defined (CONFIG_SMC911X_32_BIT) rt_inline uint32_t smc911x_reg_read(struct eth_device_smc911x *dev, uint32_t offset) { diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 2ebfc36c4e..b1982aa329 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -10,7 +10,7 @@ CPPPATH = [cwd] if GetDepend('RT_USING_LIBC'): src += Glob('*.c') if GetDepend('RT_USING_POSIX') == False: - SrcRemove(src, ['unistd.c']) + SrcRemove(src, ['unistd.c', 'delay.c']) elif GetDepend('RT_LIBC_USING_TIME'): src += ['time.c'] diff --git a/components/libc/compilers/common/delay.c b/components/libc/compilers/common/delay.c new file mode 100644 index 0000000000..4666258d3b --- /dev/null +++ b/components/libc/compilers/common/delay.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-05-07 Meco Man first Version + */ +#include +#include + +void msleep(unsigned int msecs) +{ + rt_thread_mdelay(msecs); +} +RTM_EXPORT(msleep); + +void ssleep(unsigned int seconds) +{ + msleep(seconds * 1000); +} +RTM_EXPORT(ssleep); + +void mdelay(unsigned long msecs) +{ + rt_hw_us_delay(msecs * 1000); +} +RTM_EXPORT(mdelay); + +void udelay(unsigned long usecs) +{ + rt_hw_us_delay(usecs); +} +RTM_EXPORT(udelay); + +void ndelay(unsigned long nsecs) +{ + rt_hw_us_delay(1); +} +RTM_EXPORT(ndelay); diff --git a/components/libc/compilers/common/delay.h b/components/libc/compilers/common/delay.h new file mode 100644 index 0000000000..f32708af55 --- /dev/null +++ b/components/libc/compilers/common/delay.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-05-07 Meco Man first Version + */ +#ifndef __DELAY_H__ +#define __DELAY_H__ + +void msleep(unsigned int msecs); +void ssleep(unsigned int seconds); +void mdelay(unsigned long msecs); +void udelay(unsigned long usecs); +void ndelay(unsigned long nsecs); + +#endif -- cgit v1.3.1 From fa3d95bb1c46c36023341e43f6c328c9a2077606 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 21 Jun 2021 21:15:22 +0800 Subject: [libc][syscall]整理函数格式 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/newlib/syscalls.c | 72 ++++++++++------------------- 1 file changed, 24 insertions(+), 48 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index 7c5d51eca6..e01dc59eb6 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -29,21 +29,18 @@ /* Reentrant versions of system calls. */ #ifndef _REENT_ONLY -int * -__errno () +int *__errno () { return _rt_errno(); } #endif -int -_getpid_r(struct _reent *ptr) +int _getpid_r(struct _reent *ptr) { return 0; } -int -_close_r(struct _reent *ptr, int fd) +int _close_r(struct _reent *ptr, int fd) { #ifndef RT_USING_DFS /* return "not supported" */ @@ -54,40 +51,35 @@ _close_r(struct _reent *ptr, int fd) #endif } -int -_execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) +int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) { /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } -int -_fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) +int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg) { /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } -int -_fork_r(struct _reent *ptr) +int _fork_r(struct _reent *ptr) { /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } -int -_fstat_r(struct _reent *ptr, int fd, struct stat *pstat) +int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) { /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } -int -_isatty_r(struct _reent *ptr, int fd) +int _isatty_r(struct _reent *ptr, int fd) { if (fd >=0 && fd < 3) { @@ -99,24 +91,21 @@ _isatty_r(struct _reent *ptr, int fd) } } -int -_kill_r(struct _reent *ptr, int pid, int sig) +int _kill_r(struct _reent *ptr, int pid, int sig) { /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } -int -_link_r(struct _reent *ptr, const char *old, const char *new) +int _link_r(struct _reent *ptr, const char *old, const char *new) { /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } -_off_t -_lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) +_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) { #ifndef RT_USING_DFS /* return "not supported" */ @@ -130,8 +119,7 @@ _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) #endif } -int -_mkdir_r(struct _reent *ptr, const char *name, int mode) +int _mkdir_r(struct _reent *ptr, const char *name, int mode) { #ifndef RT_USING_DFS /* return "not supported" */ @@ -145,8 +133,7 @@ _mkdir_r(struct _reent *ptr, const char *name, int mode) #endif } -int -_open_r(struct _reent *ptr, const char *file, int flags, int mode) +int _open_r(struct _reent *ptr, const char *file, int flags, int mode) { #ifndef RT_USING_DFS /* return "not supported" */ @@ -160,8 +147,7 @@ _open_r(struct _reent *ptr, const char *file, int flags, int mode) #endif } -_ssize_t -_read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) +_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { #ifndef RT_USING_DFS /* return "not supported" */ @@ -175,8 +161,7 @@ _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) #endif } -int -_rename_r(struct _reent *ptr, const char *old, const char *new) +int _rename_r(struct _reent *ptr, const char *old, const char *new) { #ifndef RT_USING_DFS /* return "not supported" */ @@ -190,8 +175,7 @@ _rename_r(struct _reent *ptr, const char *old, const char *new) #endif } -int -_stat_r(struct _reent *ptr, const char *file, struct stat *pstat) +int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { #ifndef RT_USING_DFS /* return "not supported" */ @@ -205,8 +189,7 @@ _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) #endif } -int -_unlink_r(struct _reent *ptr, const char *file) +int _unlink_r(struct _reent *ptr, const char *file) { #ifndef RT_USING_DFS /* return "not supported" */ @@ -217,16 +200,14 @@ _unlink_r(struct _reent *ptr, const char *file) #endif } -int -_wait_r(struct _reent *ptr, int *status) +int _wait_r(struct _reent *ptr, int *status) { /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; } -_ssize_t -_write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) +_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { #ifndef RT_USING_DFS #ifdef RT_USING_DEVICE @@ -253,8 +234,7 @@ _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) } #ifdef RT_USING_HEAP /* Memory routine */ -void * -_malloc_r (struct _reent *ptr, size_t size) +void *_malloc_r (struct _reent *ptr, size_t size) { void* result; @@ -267,8 +247,7 @@ _malloc_r (struct _reent *ptr, size_t size) return result; } -void * -_realloc_r (struct _reent *ptr, void *old, size_t newlen) +void *_realloc_r (struct _reent *ptr, void *old, size_t newlen) { void* result; @@ -294,8 +273,7 @@ void *_calloc_r (struct _reent *ptr, size_t size, size_t len) return result; } -void -_free_r (struct _reent *ptr, void *addr) +void _free_r (struct _reent *ptr, void *addr) { rt_free (addr); } @@ -309,16 +287,14 @@ _sbrk_r(struct _reent *ptr, ptrdiff_t incr) #endif /*RT_USING_HEAP*/ /* for exit() and abort() */ -__attribute__ ((noreturn)) void -_exit (int status) +__attribute__ ((noreturn)) void _exit (int status) { extern void __rt_libc_exit(int status); __rt_libc_exit(status); while(1); } -void -_system(const char *s) +void _system(const char *s) { extern int __rt_libc_system(const char *string); __rt_libc_system(s); -- cgit v1.3.1 From a2a7f3c2d926388c71d0be5fca0309bfef81e523 Mon Sep 17 00:00:00 2001 From: iysheng Date: Mon, 5 Jul 2021 11:34:11 +0800 Subject: [components][rtc] Add RTC framework V2.0 to simplify RTC registration process --- components/drivers/include/drivers/rtc.h | 3 + components/drivers/include/drivers/rtc_core.h | 43 ++++++++++ components/drivers/rtc/SConscript | 4 +- components/drivers/rtc/rtc.c | 1 + components/drivers/rtc/rtc_core.c | 117 ++++++++++++++++++++++++++ components/libc/compilers/common/time.c | 9 ++ include/rtdef.h | 6 -- 7 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 components/drivers/include/drivers/rtc_core.h create mode 100644 components/drivers/rtc/rtc_core.c (limited to 'components/libc/compilers') diff --git a/components/drivers/include/drivers/rtc.h b/components/drivers/include/drivers/rtc.h index 4845937113..3a318357da 100644 --- a/components/drivers/include/drivers/rtc.h +++ b/components/drivers/include/drivers/rtc.h @@ -11,6 +11,9 @@ #ifndef __RTC_H__ #define __RTC_H__ +#include +#include + rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day); rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second); diff --git a/components/drivers/include/drivers/rtc_core.h b/components/drivers/include/drivers/rtc_core.h new file mode 100644 index 0000000000..c093a1d749 --- /dev/null +++ b/components/drivers/include/drivers/rtc_core.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-06-11 iysheng first version. + */ + +#ifndef __RTC_CORE_H__ +#define __RTC_CORE_H__ + +#include + +#define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get second time */ +#define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set second time */ +#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x12 /**< get microsecond time */ +#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x13 /**< set microsecond time */ +#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x14 /**< get alarm */ +#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x15 /**< set alarm */ + +struct rt_rtc_ops +{ + rt_err_t (*init)(void); + rt_err_t (*get_secs)(void *arg); + rt_err_t (*set_secs)(void *arg); + rt_err_t (*get_alarm)(void *arg); + rt_err_t (*set_alarm)(void *arg); +}; + +typedef struct rt_rtc_device +{ + struct rt_device parent; + const struct rt_rtc_ops *ops; +} rt_rtc_dev_t; + +rt_err_t rt_rtc_dev_register(rt_rtc_dev_t *rtc, + const char *name, + rt_uint32_t flag, + void *data); + +#endif /* __RTC_CORE_H__ */ diff --git a/components/drivers/rtc/SConscript b/components/drivers/rtc/SConscript index e1f8f433c1..b922db70c2 100644 --- a/components/drivers/rtc/SConscript +++ b/components/drivers/rtc/SConscript @@ -13,7 +13,7 @@ CPPPATH = [cwd + '/../include'] group = [] if GetDepend(['RT_USING_RTC']): - src = src + rtc + src = src + ['rtc.c', 'rtc_core.c'] if GetDepend(['RT_USING_ALARM']): src = src + rtc_alarm if GetDepend(['RT_USING_SOFT_RTC']): @@ -21,4 +21,4 @@ if GetDepend(['RT_USING_RTC']): group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_RTC'], CPPPATH = CPPPATH) -Return('group') \ No newline at end of file +Return('group') diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index 98b60f9f95..2b9397da90 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef RT_USING_RTC diff --git a/components/drivers/rtc/rtc_core.c b/components/drivers/rtc/rtc_core.c new file mode 100644 index 0000000000..ada0ed283b --- /dev/null +++ b/components/drivers/rtc/rtc_core.c @@ -0,0 +1,117 @@ +/* + * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-06-11 iysheng first version. + */ + +#include + +#define TRY_DO_RTC_FUNC(rt_rtc_dev, func_name, args) \ + rt_rtc_dev->ops->func_name ? rt_rtc_dev->ops->func_name(args) : -RT_EINVAL; + +/* + * This function initializes rtc_core + */ +static rt_err_t rt_rtc_core_init(struct rt_device *dev) +{ + rt_rtc_dev_t *rtc_core; + + RT_ASSERT(dev != RT_NULL); + rtc_core = (rt_rtc_dev_t *)dev; + if (rtc_core->ops->init) + { + return (rtc_core->ops->init()); + } + + return (-RT_ENOSYS); +} + +static rt_err_t rt_rtc_core_open(struct rt_device *dev, rt_uint16_t oflag) +{ + return (RT_EOK); +} + +static rt_err_t rt_rtc_core_close(struct rt_device *dev) +{ + /* Add close member function in rt_rtc_ops when need, + * then call that function here. + * */ + return (RT_EOK); +} + +static rt_err_t rt_rtc_core_control(struct rt_device *dev, + int cmd, + void *args) +{ + rt_rtc_dev_t *rtc_core; + rt_err_t ret = -RT_EINVAL; + + RT_ASSERT(dev != RT_NULL); + rtc_core = (rt_rtc_dev_t *)dev; + + switch (cmd) + { + case RT_DEVICE_CTRL_RTC_GET_TIME: + ret = TRY_DO_RTC_FUNC(rtc_core, get_secs, args); + break; + case RT_DEVICE_CTRL_RTC_SET_TIME: + ret = TRY_DO_RTC_FUNC(rtc_core, set_secs, args); + break; + case RT_DEVICE_CTRL_RTC_GET_ALARM: + ret = TRY_DO_RTC_FUNC(rtc_core, get_alarm, args); + break; + case RT_DEVICE_CTRL_RTC_SET_ALARM: + ret = TRY_DO_RTC_FUNC(rtc_core, set_alarm, args); + break; + default: + break; + } + + return ret; +} +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops rtc_core_ops = +{ + rt_rtc_core_init, + rt_rtc_core_open, + rt_rtc_core_close, + RT_NULL, + RT_NULL, + rt_rtc_core_control, +}; +#endif + +rt_err_t rt_rtc_dev_register(rt_rtc_dev_t *rtc, + const char *name, + rt_uint32_t flag, + void *data) +{ + struct rt_device *device; + RT_ASSERT(rtc != RT_NULL); + + device = &(rtc->parent); + + device->type = RT_Device_Class_RTC; + device->rx_indicate = RT_NULL; + device->tx_complete = RT_NULL; + +#ifdef RT_USING_DEVICE_OPS + device->ops = &rtc_core_ops; +#else + device->init = rt_rtc_core_init; + device->open = rt_rtc_core_open; + device->close = rt_rtc_core_close; + device->read = RT_NULL; + device->write = RT_NULL; + device->control = rt_rtc_core_control; +#endif + device->user_data = data; + + /* register a character device */ + return rt_device_register(device, name, flag); +} + diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index deda18a560..e13f81c2f7 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -473,12 +473,17 @@ static int clock_time_system_init() rt_device_t device; time = 0; + +#ifdef RT_USING_RTC device = rt_device_find("rtc"); if (device != RT_NULL) { /* get realtime seconds */ rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); } +#else + LOG_W("Cannot find a RTC device to provide time!"); +#endif /* get tick */ tick = rt_tick_get(); @@ -591,6 +596,7 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; +#ifdef RT_USING_RTC /* update for RTC device */ device = rt_device_find("rtc"); if (device != RT_NULL) @@ -599,6 +605,9 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); } else +#else + LOG_W("Cannot find a RTC device to save time!"); +#endif return -1; return 0; diff --git a/include/rtdef.h b/include/rtdef.h index 111ac4a12c..2b4750330f 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -962,12 +962,6 @@ enum rt_device_class_type #define RT_DEVICE_CTRL_BLK_AUTOREFRESH 0x13 /**< block device : enter/exit auto refresh mode */ #define RT_DEVICE_CTRL_NETIF_GETMAC 0x10 /**< get mac address */ #define RT_DEVICE_CTRL_MTD_FORMAT 0x10 /**< format a MTD device */ -#define RT_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get second time */ -#define RT_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set second time */ -#define RT_DEVICE_CTRL_RTC_GET_TIME_US 0x12 /**< get microsecond time */ -#define RT_DEVICE_CTRL_RTC_SET_TIME_US 0x13 /**< set microsecond time */ -#define RT_DEVICE_CTRL_RTC_GET_ALARM 0x14 /**< get alarm */ -#define RT_DEVICE_CTRL_RTC_SET_ALARM 0x15 /**< set alarm */ typedef struct rt_device *rt_device_t; -- cgit v1.3.1 From 0f48449b5e326f4f66e443cbd1a0393ea00433e4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 18 Jul 2021 14:34:35 +0800 Subject: [timezone] implement timezone --- components/libc/Kconfig | 4 +-- components/libc/compilers/common/sys/time.h | 7 +++++ components/libc/compilers/common/time.c | 41 +++++++++++++++++++++++------ 3 files changed, 42 insertions(+), 10 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/Kconfig b/components/libc/Kconfig index a89b252caa..37a98ba836 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -59,9 +59,9 @@ if RT_USING_LIBC != y default y endif -config RT_LIBC_FIXED_TIMEZONE +config RT_LIBC_DEFAULT_TIMEZONE depends on (RT_LIBC_USING_TIME || RT_USING_LIBC) - int "Manually set a fixed time zone (UTC+)" + int "Set the default time zone (UTC+)" range -12 12 default 8 diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index bb1a9c96fd..4ca665c536 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -12,6 +12,7 @@ #define _SYS_TIME_H_ #include +#include #include #ifdef __cplusplus @@ -98,6 +99,12 @@ int clock_settime (clockid_t clockid, const struct timespec *tp); int clock_time_to_tick(const struct timespec *time); #endif /* RT_USING_POSIX */ + +/* timezone APIs (Not standard LIBC APIs) */ +void rt_tz_set(rt_int8_t tz); +rt_int8_t rt_tz_get(void); +rt_int8_t rt_tz_is_dst(void); + #ifdef __cplusplus } #endif diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index e79a22b9db..8f4856a330 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -18,6 +18,7 @@ * 2021-02-12 Meco Man move all of the functions located in to this file * 2021-03-15 Meco Man fixed a bug of leaking memory in asctime() * 2021-05-01 Meco Man support fixed timezone + * 2021-07-21 Meco Man implement that change/set timezone APIs */ #include "sys/time.h" @@ -32,10 +33,6 @@ #define DBG_LVL DBG_INFO #include -#ifndef RT_LIBC_FIXED_TIMEZONE -#define RT_LIBC_FIXED_TIMEZONE 8 /* UTC+8 */ -#endif - /* seconds per day */ #define SPD 24*60*60 @@ -202,7 +199,7 @@ 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; + r->tm_isdst = rt_tz_is_dst(); return r; } RTM_EXPORT(gmtime_r); @@ -218,7 +215,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r) { time_t local_tz; - local_tz = *t + RT_LIBC_FIXED_TIMEZONE * 3600; + local_tz = *t + rt_tz_get() * 3600; return gmtime_r(&local_tz, r); } RTM_EXPORT(localtime_r); @@ -235,7 +232,7 @@ time_t mktime(struct tm * const t) time_t timestamp; timestamp = timegm(t); - timestamp = timestamp - 3600 * RT_LIBC_FIXED_TIMEZONE; + timestamp = timestamp - 3600 * rt_tz_get(); return timestamp; } RTM_EXPORT(mktime); @@ -426,7 +423,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) if(tz != RT_NULL) { tz->tz_dsttime = DST_NONE; - tz->tz_minuteswest = -(RT_LIBC_FIXED_TIMEZONE * 60); + tz->tz_minuteswest = -(rt_tz_get() * 60); } if (tv != RT_NULL && get_timeval(tv) == RT_EOK) @@ -651,3 +648,31 @@ int clock_time_to_tick(const struct timespec *time) RTM_EXPORT(clock_time_to_tick); #endif /* RT_USING_POSIX */ + + +/* timezone APIs (Not standard LIBC APIs) */ +#ifndef RT_LIBC_DEFAULT_TIMEZONE +#define RT_LIBC_DEFAULT_TIMEZONE 8 +#endif + +#include + +volatile static rt_int8_t rt_current_timezone = RT_LIBC_DEFAULT_TIMEZONE; + +void rt_tz_set(rt_int8_t tz) +{ + register rt_base_t level; + level = rt_hw_interrupt_disable(); + rt_current_timezone = tz; + rt_hw_interrupt_enable(level); +} + +rt_int8_t rt_tz_get(void) +{ + return rt_current_timezone; +} + +rt_int8_t rt_tz_is_dst(void) +{ + return 0; +} -- cgit v1.3.1 From fc094e921103f9a37fa1c4cbf1301900419d2801 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 21 Jul 2021 01:43:48 +0800 Subject: [rtlibc] remove libc_signal.h and libc_fdset.h --- components/dfs/include/dfs_select.h | 2 +- components/libc/aio/posix_aio.c | 6 - components/libc/aio/posix_aio.h | 4 + .../libc/compilers/common/none-gcc/sys/errno.h | 4 +- .../libc/compilers/common/none-gcc/sys/stat.h | 5 + .../libc/compilers/common/none-gcc/sys/types.h | 4 +- .../libc/compilers/common/none-gcc/sys/unistd.h | 4 +- components/libc/compilers/common/sys/select.h | 49 ++++++ components/libc/compilers/common/sys/signal.h | 194 +++++++++++++++++++++ components/libc/pthreads/mqueue.c | 1 + components/libc/signal/posix_signal.c | 5 +- components/libc/signal/posix_signal.h | 1 - include/libc/libc_fdset.h | 60 ------- include/libc/libc_signal.h | 184 ------------------- include/rtdef.h | 2 +- include/rtlibc.h | 3 - 16 files changed, 263 insertions(+), 265 deletions(-) create mode 100644 components/libc/compilers/common/sys/select.h create mode 100644 components/libc/compilers/common/sys/signal.h delete mode 100644 include/libc/libc_fdset.h delete mode 100644 include/libc/libc_signal.h (limited to 'components/libc/compilers') diff --git a/components/dfs/include/dfs_select.h b/components/dfs/include/dfs_select.h index 458691df20..e0572c5059 100644 --- a/components/dfs/include/dfs_select.h +++ b/components/dfs/include/dfs_select.h @@ -10,7 +10,7 @@ #ifndef DFS_SELECT_H__ #define DFS_SELECT_H__ -#include +#include #ifdef __cplusplus extern "C" { diff --git a/components/libc/aio/posix_aio.c b/components/libc/aio/posix_aio.c index 66f15e4c57..66cced8687 100644 --- a/components/libc/aio/posix_aio.c +++ b/components/libc/aio/posix_aio.c @@ -9,14 +9,8 @@ */ #include -#include - #include -#include -#include - #include - #include "posix_aio.h" struct rt_workqueue* aio_queue = NULL; diff --git a/components/libc/aio/posix_aio.h b/components/libc/aio/posix_aio.h index de11738515..4e25e1d15b 100644 --- a/components/libc/aio/posix_aio.h +++ b/components/libc/aio/posix_aio.h @@ -11,6 +11,10 @@ #ifndef POSIX_AIO_H__ #define POSIX_AIO_H__ +#include +#include +#include + struct aiocb { int aio_fildes; /* File descriptor. */ diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h index ad3614024d..ff1abca387 100644 --- a/components/libc/compilers/common/none-gcc/sys/errno.h +++ b/components/libc/compilers/common/none-gcc/sys/errno.h @@ -7,8 +7,8 @@ * Date Author Notes * 2021-05-22 Meco Man The first version. */ -#ifndef _SYS_ERRNO_H -#define _SYS_ERRNO_H +#ifndef __SYS_ERRNO_H__ +#define __SYS_ERRNO_H__ #if defined(__ARMCC_VERSION) /* diff --git a/components/libc/compilers/common/none-gcc/sys/stat.h b/components/libc/compilers/common/none-gcc/sys/stat.h index c4b42083c4..c8f65df435 100644 --- a/components/libc/compilers/common/none-gcc/sys/stat.h +++ b/components/libc/compilers/common/none-gcc/sys/stat.h @@ -6,3 +6,8 @@ * Change Logs: * Date Author Notes */ + + #ifndef __SYS_STAT_H__ + #define __SYS_STAT_H__ + + #endif diff --git a/components/libc/compilers/common/none-gcc/sys/types.h b/components/libc/compilers/common/none-gcc/sys/types.h index 7222326a2a..e9f44f7762 100644 --- a/components/libc/compilers/common/none-gcc/sys/types.h +++ b/components/libc/compilers/common/none-gcc/sys/types.h @@ -8,8 +8,8 @@ * 2020-09-05 Meco Man fix bugs * 2020-12-16 Meco Man add useconds_t */ -#ifndef __TYPES_H__ -#define __TYPES_H__ +#ifndef __SYS_TYPES_H__ +#define __SYS_TYPES_H__ #include diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h index 2f01f660b3..ea2d674b0f 100644 --- a/components/libc/compilers/common/none-gcc/sys/unistd.h +++ b/components/libc/compilers/common/none-gcc/sys/unistd.h @@ -7,8 +7,8 @@ * Date Author Notes * 2020-12-16 Meco Man add usleep */ -#ifndef _SYS_UNISTD_H -#define _SYS_UNISTD_H +#ifndef __SYS_UNISTD_H__ +#define __SYS_UNISTD_H__ #include #include "types.h" diff --git a/components/libc/compilers/common/sys/select.h b/components/libc/compilers/common/sys/select.h new file mode 100644 index 0000000000..db42b6ebcc --- /dev/null +++ b/components/libc/compilers/common/sys/select.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-07-21 Meco Man The first version + */ + +#ifndef __SYS_SELECT_H__ +#define __SYS_SELECT_H__ + +#include +#include + +#ifndef FD_SETSIZE +#define FD_SETSIZE 32 +#endif + +#ifdef SAL_USING_POSIX +#ifdef FD_SETSIZE +#undef FD_SETSIZE +#endif +#define FD_SETSIZE DFS_FD_MAX +#endif /* SAL_USING_POSIX */ + +#define NBBY 8 /* number of bits in a byte */ + +typedef long fd_mask; + +#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ +#ifndef howmany +#define howmany(x,y) (((x)+((y)-1))/(y)) +#endif + +#ifndef _SYS_TYPES_FD_SET /* MIPS */ +typedef struct _types_fd_set { + fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; +} _types_fd_set; +#define fd_set _types_fd_set + +#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) +#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) +#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) +#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) +#endif /* _SYS_TYPES_FD_SET */ + +#endif /* __SYS_SELECT_H__ */ diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h new file mode 100644 index 0000000000..9787958a37 --- /dev/null +++ b/components/libc/compilers/common/sys/signal.h @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017-09-12 Bernard The first version + * 2021-07-21 Meco Man move to libc/common + */ + +#ifndef __SYS_SIGNAL_H__ +#define __SYS_SIGNAL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* Signal Generation and Delivery, P1003.1b-1993, p. 63 + NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and + sigev_notify_attributes to the sigevent structure. */ +union sigval +{ + int sival_int; /* Integer signal value */ + void *sival_ptr; /* Pointer signal value */ +}; + +struct sigevent +{ + int sigev_notify; /* Notification type */ + int sigev_signo; /* Signal number */ + union sigval sigev_value; /* Signal value */ + void (*sigev_notify_function)( union sigval ); + /* Notification function */ + void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */ +}; + +struct siginfo +{ + uint16_t si_signo; + uint16_t si_code; + + union sigval si_value; +}; +typedef struct siginfo siginfo_t; + +#define SI_USER 0x01 /* Signal sent by kill(). */ +#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */ +#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */ +#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */ +#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */ + +typedef void (*_sig_func_ptr)(int); +typedef unsigned long sigset_t; + +struct sigaction +{ + _sig_func_ptr sa_handler; + sigset_t sa_mask; + int sa_flags; +}; + +#define SIG_SETMASK 0 /* set mask with sigprocmask() */ +#define SIG_BLOCK 1 /* set of signals to block */ +#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ + +#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) +#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) +#define sigemptyset(what) (*(what) = 0, 0) +#define sigfillset(what) (*(what) = ~(0), 0) +#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) + +int sigprocmask (int how, const sigset_t *set, sigset_t *oset); +int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); + +#ifdef __ARMCC_VERSION +#define SIGHUP 1 +/* #define SIGINT 2 */ +#define SIGQUIT 3 +/* #define SIGILL 4 */ +#define SIGTRAP 5 +/* #define SIGABRT 6 */ +#define SIGEMT 7 +/* #define SIGFPE 8 */ +#define SIGKILL 9 +#define SIGBUS 10 +/* #define SIGSEGV 11 */ +#define SIGSYS 12 +#define SIGPIPE 13 +#define SIGALRM 14 +/* #define SIGTERM 15 */ +#define SIGURG 16 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGPOLL 23 +#define SIGWINCH 24 +/* #define SIGUSR1 25 */ +/* #define SIGUSR2 26 */ +#define SIGRTMIN 27 +#define SIGRTMAX 31 +#define NSIG 32 + +#include + +#elif defined(__IAR_SYSTEMS_ICC__) +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +/* #define SIGABRT 6 */ +#define SIGEMT 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGBUS 10 +#define SIGSEGV 11 +#define SIGSYS 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGURG 16 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGPOLL 23 +#define SIGWINCH 24 +#define SIGUSR1 25 +#define SIGUSR2 26 +#define SIGRTMIN 27 +#define SIGRTMAX 31 +#define NSIG 32 + +#include + +#elif defined(__GNUC__) +#define SIGHUP 1 /* hangup */ +#define SIGINT 2 /* interrupt */ +#define SIGQUIT 3 /* quit */ +#define SIGILL 4 /* illegal instruction (not reset when caught) */ +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#define SIGIOT 6 /* IOT instruction */ +#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ +#define SIGEMT 7 /* EMT instruction */ +#define SIGFPE 8 /* floating point exception */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGBUS 10 /* bus error */ +#define SIGSEGV 11 /* segmentation violation */ +#define SIGSYS 12 /* bad argument to system call */ +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#define SIGTERM 15 /* software termination signal from kill */ +#define SIGURG 16 /* urgent condition on IO channel */ +#define SIGSTOP 17 /* sendable stop signal not from tty */ +#define SIGTSTP 18 /* stop signal from tty */ +#define SIGCONT 19 /* continue a stopped process */ +#define SIGCHLD 20 /* to parent on child stop or exit */ +#define SIGCLD 20 /* System V name for SIGCHLD */ +#define SIGTTIN 21 /* to readers pgrp upon background tty read */ +#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ +#define SIGIO 23 /* input/output possible signal */ +#define SIGPOLL SIGIO /* System V name for SIGIO */ +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ +#define SIGPROF 27 /* profiling time alarm */ +#define SIGWINCH 28 /* window changed */ +#define SIGLOST 29 /* resource lost (eg, record-lock lost) */ +#define SIGUSR1 30 /* user defined signal 1 */ +#define SIGUSR2 31 /* user defined signal 2 */ +#define NSIG 32 /* signal 0 implied */ + +#ifndef _SIGNAL_H_ +/* Some applications take advantage of the fact that + * and are equivalent in glibc. Allow for that here. */ +#include +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/components/libc/pthreads/mqueue.c b/components/libc/pthreads/mqueue.c index 1af0ab2919..a59c7a445b 100644 --- a/components/libc/pthreads/mqueue.c +++ b/components/libc/pthreads/mqueue.c @@ -8,6 +8,7 @@ */ #include +#include #include "mqueue.h" #include "pthread_internal.h" diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c index 1cb561d428..45646f63ea 100644 --- a/components/libc/signal/posix_signal.c +++ b/components/libc/signal/posix_signal.c @@ -7,6 +7,7 @@ * Date Author Notes * 2017/10/1 Bernard The first version */ + #include #include @@ -14,6 +15,7 @@ #include #include "posix_signal.h" + #define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX) void (*signal(int sig, void (*func)(int))) (int) @@ -79,13 +81,10 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info, int ret = 0; int tick = RT_WAITING_FOREVER; -#ifdef RT_USING_PTHREADS if (timeout) { - extern int clock_time_to_tick(const struct timespec *time); tick = clock_time_to_tick(timeout); } -#endif ret = rt_signal_wait(set, info, tick); if (ret == 0) return 0; diff --git a/components/libc/signal/posix_signal.h b/components/libc/signal/posix_signal.h index fa8ad38fa6..f04b54c5f8 100644 --- a/components/libc/signal/posix_signal.h +++ b/components/libc/signal/posix_signal.h @@ -15,7 +15,6 @@ extern "C" { #endif -#include #include enum rt_signal_value{ diff --git a/include/libc/libc_fdset.h b/include/libc/libc_fdset.h deleted file mode 100644 index c542e6855c..0000000000 --- a/include/libc/libc_fdset.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017-10-30 Bernard The first version - */ - -#ifndef LIBC_FDSET_H__ -#define LIBC_FDSET_H__ - -#include - -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) -#include -#if defined(HAVE_SYS_SELECT_H) -#include -#endif - -#else - -#ifdef SAL_USING_POSIX - -#ifdef FD_SETSIZE -#undef FD_SETSIZE -#endif - -#define FD_SETSIZE DFS_FD_MAX -#endif - -# ifndef FD_SETSIZE -# define FD_SETSIZE 32 -# endif - -# define NBBY 8 /* number of bits in a byte */ - -typedef long fd_mask; -# define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ -# ifndef howmany -# define howmany(x,y) (((x)+((y)-1))/(y)) -# endif - -/* We use a macro for fd_set so that including Sockets.h afterwards - can work. */ -typedef struct _types_fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; -} _types_fd_set; - -#define fd_set _types_fd_set - -# define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) -# define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) -# define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) -# define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) - -#endif - -#endif diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h deleted file mode 100644 index 1fb8194643..0000000000 --- a/include/libc/libc_signal.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017-09-12 Bernard The first version - */ - -#ifndef LIBC_SIGNAL_H__ -#define LIBC_SIGNAL_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#ifdef HAVE_CCONFIG_H -#include -#endif - -#ifndef HAVE_SIGVAL -/* Signal Generation and Delivery, P1003.1b-1993, p. 63 - NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and - sigev_notify_attributes to the sigevent structure. */ - -union sigval -{ - int sival_int; /* Integer signal value */ - void *sival_ptr; /* Pointer signal value */ -}; -#endif - -#ifndef HAVE_SIGEVENT -struct sigevent -{ - int sigev_notify; /* Notification type */ - int sigev_signo; /* Signal number */ - union sigval sigev_value; /* Signal value */ - void (*sigev_notify_function)( union sigval ); - /* Notification function */ - void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */ -}; -#endif - -#ifndef HAVE_SIGINFO -struct siginfo -{ - uint16_t si_signo; - uint16_t si_code; - - union sigval si_value; -}; -typedef struct siginfo siginfo_t; -#endif - -#define SI_USER 0x01 /* Signal sent by kill(). */ -#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */ -#define SI_TIMER 0x03 /* Signal generated by expiration of a - timer set by timer_settime(). */ -#define SI_ASYNCIO 0x04 /* Signal generated by completion of an - asynchronous I/O request. */ -#define SI_MESGQ 0x05 /* Signal generated by arrival of a - message on an empty message queue. */ - -#if !defined(RT_USING_NEWLIB) -typedef void (*_sig_func_ptr)(int); -typedef unsigned long sigset_t; -#endif - -#include - -#ifdef __ARMCC_VERSION - -#define SIGHUP 1 -/* #define SIGINT 2 */ -#define SIGQUIT 3 -/* #define SIGILL 4 */ -#define SIGTRAP 5 -/* #define SIGABRT 6 */ -#define SIGEMT 7 -/* #define SIGFPE 8 */ -#define SIGKILL 9 -#define SIGBUS 10 -/* #define SIGSEGV 11 */ -#define SIGSYS 12 -#define SIGPIPE 13 -#define SIGALRM 14 -/* #define SIGTERM 15 */ -#define SIGURG 16 -#define SIGSTOP 17 -#define SIGTSTP 18 -#define SIGCONT 19 -#define SIGCHLD 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGPOLL 23 -#define SIGWINCH 24 -/* #define SIGUSR1 25 */ -/* #define SIGUSR2 26 */ -#define SIGRTMIN 27 -#define SIGRTMAX 31 -#define NSIG 32 - -#define SIG_SETMASK 0 /* set mask with sigprocmask() */ -#define SIG_BLOCK 1 /* set of signals to block */ -#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ - -struct sigaction -{ - _sig_func_ptr sa_handler; - sigset_t sa_mask; - int sa_flags; -}; - -#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) -#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) -#define sigemptyset(what) (*(what) = 0, 0) -#define sigfillset(what) (*(what) = ~(0), 0) -#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) - -int sigprocmask (int how, const sigset_t *set, sigset_t *oset); -int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); - -#elif defined(__IAR_SYSTEMS_ICC__) - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -/* #define SIGABRT 6 */ -#define SIGEMT 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGBUS 10 -#define SIGSEGV 11 -#define SIGSYS 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGURG 16 -#define SIGSTOP 17 -#define SIGTSTP 18 -#define SIGCONT 19 -#define SIGCHLD 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGPOLL 23 -#define SIGWINCH 24 -#define SIGUSR1 25 -#define SIGUSR2 26 -#define SIGRTMIN 27 -#define SIGRTMAX 31 -#define NSIG 32 - -#define SIG_SETMASK 0 /* set mask with sigprocmask() */ -#define SIG_BLOCK 1 /* set of signals to block */ -#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ - -struct sigaction -{ - _sig_func_ptr sa_handler; - sigset_t sa_mask; - int sa_flags; -}; - -#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) -#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) -#define sigemptyset(what) (*(what) = 0, 0) -#define sigfillset(what) (*(what) = ~(0), 0) -#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) - -int sigprocmask (int how, const sigset_t *set, sigset_t *oset); -int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/include/rtdef.h b/include/rtdef.h index 394bbca5d2..62d0a53685 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -510,7 +510,7 @@ typedef struct rt_timer *rt_timer_t; * @addtogroup Signal */ #ifdef RT_USING_SIGNALS -#include +#include typedef unsigned long rt_sigset_t; typedef void (*rt_sighandler_t)(int signo); typedef siginfo_t rt_siginfo_t; diff --git a/include/rtlibc.h b/include/rtlibc.h index ac44a97831..4b145b1b1b 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -13,11 +13,8 @@ /* definitions for libc if toolchain has no these definitions */ #include "libc/libc_stat.h" - #include "libc/libc_fcntl.h" #include "libc/libc_dirent.h" -#include "libc/libc_signal.h" -#include "libc/libc_fdset.h" #ifndef RT_USING_LIBC #if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) -- cgit v1.3.1 From 62ff77d4932bb81f5acaf8092cbb97e68de2a9ba Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 22 Jul 2021 00:35:08 +0800 Subject: [libc][time] 重命名非标准libc函数 并 调整time.h定义位置 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/sys/time.h | 42 ++++++++++++++--------------- components/libc/compilers/common/time.c | 23 ++++++++++------ components/libc/pthreads/mqueue.c | 2 +- components/libc/pthreads/pthread_cond.c | 2 +- components/libc/pthreads/semaphore.c | 2 +- components/libc/signal/posix_signal.c | 2 +- 6 files changed, 40 insertions(+), 33 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 4ca665c536..c2320429e0 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -19,6 +19,7 @@ extern "C" { #endif +/* timezone */ #define DST_NONE 0 /* not on dst */ #define DST_USA 1 /* USA style dst */ #define DST_AUST 2 /* Australian style dst */ @@ -31,12 +32,21 @@ extern "C" { #define DST_TUR 9 /* Turkey */ #define DST_AUSTALT 10 /* Australian style with shift in 1986 */ -#ifndef _TIMEVAL_DEFINED -#define _TIMEVAL_DEFINED +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +void rt_tz_set(rt_int8_t tz); +rt_int8_t rt_tz_get(void); +rt_int8_t rt_tz_is_dst(void); + /* * Structure returned by gettimeofday(2) system call, * and used in other calls. */ +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED #if !(defined(_WIN32)) struct timeval { long tv_sec; /* seconds */ @@ -45,18 +55,6 @@ struct timeval { #endif #endif /* _TIMEVAL_DEFINED */ -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32) -struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* and nanoseconds */ -}; -#endif - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - int stime(const time_t *t); time_t timegm(struct tm * const t); int gettimeofday(struct timeval *tv, struct timezone *tz); @@ -67,6 +65,14 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r); #ifdef RT_USING_POSIX #include + +#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32) +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + /* posix clock and timer */ #define MILLISECOND_PER_SECOND 1000UL #define MICROSECOND_PER_SECOND 1000000UL @@ -96,15 +102,9 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r); int clock_getres (clockid_t clockid, struct timespec *res); int clock_gettime (clockid_t clockid, struct timespec *tp); int clock_settime (clockid_t clockid, const struct timespec *tp); -int clock_time_to_tick(const struct timespec *time); +int rt_timespec_to_tick(const struct timespec *time); #endif /* RT_USING_POSIX */ - -/* timezone APIs (Not standard LIBC APIs) */ -void rt_tz_set(rt_int8_t tz); -rt_int8_t rt_tz_get(void); -rt_int8_t rt_tz_is_dst(void); - #ifdef __cplusplus } #endif diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 8f4856a330..6e4ec58950 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -465,8 +465,8 @@ RTM_EXPORT(difftime); RTM_EXPORT(strftime); #ifdef RT_USING_POSIX -static struct timeval _timevalue; -static int clock_time_system_init() +static volatile struct timeval _timevalue; +static int _rt_clock_time_system_init() { time_t time; rt_tick_t tick; @@ -493,7 +493,7 @@ static int clock_time_system_init() return 0; } -INIT_COMPONENT_EXPORT(clock_time_system_init); +INIT_COMPONENT_EXPORT(_rt_clock_time_system_init); int clock_getres(clockid_t clockid, struct timespec *res) { @@ -614,7 +614,7 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) } RTM_EXPORT(clock_settime); -int clock_time_to_tick(const struct timespec *time) +int rt_timespec_to_tick(const struct timespec *time) { int tick; int nsecond, second; @@ -645,19 +645,19 @@ int clock_time_to_tick(const struct timespec *time) return tick; } -RTM_EXPORT(clock_time_to_tick); +RTM_EXPORT(rt_timespec_to_tick); #endif /* RT_USING_POSIX */ -/* timezone APIs (Not standard LIBC APIs) */ +/* timezone */ #ifndef RT_LIBC_DEFAULT_TIMEZONE #define RT_LIBC_DEFAULT_TIMEZONE 8 #endif #include -volatile static rt_int8_t rt_current_timezone = RT_LIBC_DEFAULT_TIMEZONE; +static volatile rt_int8_t rt_current_timezone = RT_LIBC_DEFAULT_TIMEZONE; void rt_tz_set(rt_int8_t tz) { @@ -669,7 +669,14 @@ void rt_tz_set(rt_int8_t tz) rt_int8_t rt_tz_get(void) { - return rt_current_timezone; + rt_int8_t tz; + register rt_base_t level; + + level = rt_hw_interrupt_disable(); + tz = rt_current_timezone; + rt_hw_interrupt_enable(level); + + return tz; } rt_int8_t rt_tz_is_dst(void) diff --git a/components/libc/pthreads/mqueue.c b/components/libc/pthreads/mqueue.c index 1af0ab2919..ce2ff43e23 100644 --- a/components/libc/pthreads/mqueue.c +++ b/components/libc/pthreads/mqueue.c @@ -243,7 +243,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, return -1; } - tick = clock_time_to_tick(abs_timeout); + tick = rt_timespec_to_tick(abs_timeout); result = rt_mq_recv(mqdes->mq, msg_ptr, msg_len, tick); if (result == RT_EOK) diff --git a/components/libc/pthreads/pthread_cond.c b/components/libc/pthreads/pthread_cond.c index 59c271bf6e..9bf49704ed 100644 --- a/components/libc/pthreads/pthread_cond.c +++ b/components/libc/pthreads/pthread_cond.c @@ -222,7 +222,7 @@ int pthread_cond_timedwait(pthread_cond_t *cond, int timeout; rt_err_t result; - timeout = clock_time_to_tick(abstime); + timeout = rt_timespec_to_tick(abstime); result = _pthread_cond_timedwait(cond, mutex, timeout); if (result == RT_EOK) return 0; diff --git a/components/libc/pthreads/semaphore.c b/components/libc/pthreads/semaphore.c index 199b33bfe8..5e59ae850f 100644 --- a/components/libc/pthreads/semaphore.c +++ b/components/libc/pthreads/semaphore.c @@ -319,7 +319,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout) return EINVAL; /* calculate os tick */ - tick = clock_time_to_tick(abs_timeout); + tick = rt_timespec_to_tick(abs_timeout); result = rt_sem_take(sem->sem, tick); if (result == -RT_ETIMEOUT) diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c index 1cb561d428..d664feb24d 100644 --- a/components/libc/signal/posix_signal.c +++ b/components/libc/signal/posix_signal.c @@ -83,7 +83,7 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info, if (timeout) { extern int clock_time_to_tick(const struct timespec *time); - tick = clock_time_to_tick(timeout); + tick = rt_timespec_to_tick(timeout); } #endif -- cgit v1.3.1 From 4ce6b2f5de05ad9a31448a5c1b5dd8b1863472d4 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 22 Jul 2021 01:19:49 +0800 Subject: [libc][time] 对posix相关函数 获取时间结果的判断逻辑做出调整 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 59 +++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 6e4ec58950..45bedacf68 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -465,38 +465,42 @@ RTM_EXPORT(difftime); RTM_EXPORT(strftime); #ifdef RT_USING_POSIX + +#ifdef RT_USING_RTC static volatile struct timeval _timevalue; static int _rt_clock_time_system_init() { - time_t time; + time_t time = 0; rt_tick_t tick; rt_device_t device; - time = 0; - -#ifdef RT_USING_RTC device = rt_device_find("rtc"); if (device != RT_NULL) { /* get realtime seconds */ - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); + if(rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time) == RT_EOK) + { + /* get tick */ + tick = rt_tick_get(); + _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; + _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; + return 0; + } } -#else - LOG_W("Cannot find a RTC device to provide time!"); -#endif - - /* get tick */ - tick = rt_tick_get(); - - _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; - _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; - return 0; + _timevalue.tv_usec = 0; + _timevalue.tv_sec = 0; + return -1; } INIT_COMPONENT_EXPORT(_rt_clock_time_system_init); +#endif /* RT_USING_RTC */ int clock_getres(clockid_t clockid, struct timespec *res) { +#ifndef RT_USING_RTC + LOG_W("Cannot find a RTC device to save time!"); + return -1; +#else int ret = 0; if (res == RT_NULL) @@ -526,11 +530,16 @@ int clock_getres(clockid_t clockid, struct timespec *res) } return ret; +#endif /* RT_USING_RTC */ } RTM_EXPORT(clock_getres); int clock_gettime(clockid_t clockid, struct timespec *tp) { +#ifndef RT_USING_RTC + LOG_W("Cannot find a RTC device to save time!"); + return -1; +#else int ret = 0; if (tp == RT_NULL) @@ -571,11 +580,16 @@ int clock_gettime(clockid_t clockid, struct timespec *tp) } return ret; +#endif /* RT_USING_RTC */ } RTM_EXPORT(clock_gettime); int clock_settime(clockid_t clockid, const struct timespec *tp) { +#ifndef RT_USING_RTC + LOG_W("Cannot find a RTC device to save time!"); + return -1; +#else int second; rt_tick_t tick; rt_device_t device; @@ -583,7 +597,6 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) { rt_set_errno(EINVAL); - return -1; } @@ -596,21 +609,19 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; -#ifdef RT_USING_RTC /* update for RTC device */ device = rt_device_find("rtc"); if (device != RT_NULL) { /* set realtime seconds */ - rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); + if(rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second) == RT_EOK) + { + return 0; + } } - else -#else - LOG_W("Cannot find a RTC device to save time!"); -#endif - return -1; - return 0; + return -1; +#endif /* RT_USING_RTC */ } RTM_EXPORT(clock_settime); -- cgit v1.3.1 From 19c5088bb8b6cfdc9e3cecc63b6f9c116a799c49 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 22 Jul 2021 01:40:37 +0800 Subject: [libc][time] 修复posix相关函数没有进行临界区保护的问题 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 35 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 45bedacf68..50f6d4c71e 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -24,7 +24,7 @@ #include "sys/time.h" #include #include - +#include #ifdef RT_USING_DEVICE #include #endif @@ -470,6 +470,7 @@ RTM_EXPORT(strftime); static volatile struct timeval _timevalue; static int _rt_clock_time_system_init() { + register rt_base_t level; time_t time = 0; rt_tick_t tick; rt_device_t device; @@ -480,16 +481,20 @@ static int _rt_clock_time_system_init() /* get realtime seconds */ if(rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time) == RT_EOK) { - /* get tick */ - tick = rt_tick_get(); + level = rt_hw_interrupt_disable(); + tick = rt_tick_get(); /* get tick */ _timevalue.tv_usec = (tick%RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; _timevalue.tv_sec = time - tick/RT_TICK_PER_SECOND - 1; + rt_hw_interrupt_enable(level); return 0; } } + level = rt_hw_interrupt_disable(); _timevalue.tv_usec = 0; _timevalue.tv_sec = 0; + rt_hw_interrupt_enable(level); + return -1; } INIT_COMPONENT_EXPORT(_rt_clock_time_system_init); @@ -552,11 +557,14 @@ int clock_gettime(clockid_t clockid, struct timespec *tp) { case CLOCK_REALTIME: { - /* get tick */ - int tick = rt_tick_get(); + int tick; + register rt_base_t level; + level = rt_hw_interrupt_disable(); + tick = rt_tick_get(); /* get tick */ tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; + rt_hw_interrupt_enable(level); } break; @@ -590,6 +598,7 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) LOG_W("Cannot find a RTC device to save time!"); return -1; #else + register rt_base_t level; int second; rt_tick_t tick; rt_device_t device; @@ -602,12 +611,13 @@ int clock_settime(clockid_t clockid, const struct timespec *tp) /* get second */ second = tp->tv_sec; - /* get tick */ - tick = rt_tick_get(); + level = rt_hw_interrupt_disable(); + tick = rt_tick_get(); /* get tick */ /* update timevalue */ _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; + rt_hw_interrupt_enable(level); /* update for RTC device */ device = rt_device_find("rtc"); @@ -666,8 +676,6 @@ RTM_EXPORT(rt_timespec_to_tick); #define RT_LIBC_DEFAULT_TIMEZONE 8 #endif -#include - static volatile rt_int8_t rt_current_timezone = RT_LIBC_DEFAULT_TIMEZONE; void rt_tz_set(rt_int8_t tz) @@ -680,14 +688,7 @@ void rt_tz_set(rt_int8_t tz) rt_int8_t rt_tz_get(void) { - rt_int8_t tz; - register rt_base_t level; - - level = rt_hw_interrupt_disable(); - tz = rt_current_timezone; - rt_hw_interrupt_enable(level); - - return tz; + return rt_current_timezone; } rt_int8_t rt_tz_is_dst(void) -- cgit v1.3.1 From 3fae2266303f4e7424d333ebdb68eaab740e10d6 Mon Sep 17 00:00:00 2001 From: greedyhao Date: Wed, 11 Aug 2021 09:42:24 +0800 Subject: [newlib] fix compile error when closing RT_USING_CONSOLE --- components/libc/compilers/newlib/syscalls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index e01dc59eb6..aeb4d123e7 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -210,7 +210,7 @@ int _wait_r(struct _reent *ptr, int *status) _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { #ifndef RT_USING_DFS -#ifdef RT_USING_DEVICE +#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE) if (fileno(stdout) == fd) { rt_device_t console; -- cgit v1.3.1