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 --- .../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 +- 5 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 components/libc/compilers/common/none-gcc/sys/errno.h (limited to 'components/libc') 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) -- cgit v1.3.1 From 0e0e2a0f951ca3c8b5ff84137be369db6dab2922 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 22 May 2021 02:56:53 +0800 Subject: fix warning of posix_signal --- components/libc/signal/posix_signal.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'components/libc') diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c index b06fe12685..1cb561d428 100644 --- a/components/libc/signal/posix_signal.c +++ b/components/libc/signal/posix_signal.c @@ -10,7 +10,8 @@ #include #include -#include +#include +#include #include "posix_signal.h" #define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX) -- 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') 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') 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 5bce56473857e9145b34c77b4355494744838e37 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 23 May 2021 00:25:49 +0800 Subject: add sys/ioctl.h for posix_termios.h --- components/libc/termios/posix_termios.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/libc') diff --git a/components/libc/termios/posix_termios.h b/components/libc/termios/posix_termios.h index 5bd1999b0a..6dc5531955 100644 --- a/components/libc/termios/posix_termios.h +++ b/components/libc/termios/posix_termios.h @@ -10,8 +10,8 @@ #ifndef TERMIOS_H__ #define TERMIOS_H__ -#include #include +#include #ifdef __cplusplus extern "C" { -- cgit v1.3.1 From 07cab33b50107e71b9fb22230f07c33030e8fc82 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 23 May 2021 00:30:29 +0800 Subject: add sys/ioctl.h for pipe.c --- components/drivers/src/pipe.c | 1 + components/libc/termios/posix_termios.c | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'components/libc') diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index 236c1ffec7..0e35248480 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/src/pipe.c @@ -16,6 +16,7 @@ #include #include #include +#include static int pipe_fops_open(struct dfs_fd *fd) { diff --git a/components/libc/termios/posix_termios.c b/components/libc/termios/posix_termios.c index 01ba010c86..1816bbae57 100644 --- a/components/libc/termios/posix_termios.c +++ b/components/libc/termios/posix_termios.c @@ -9,9 +9,7 @@ */ #include #include -#include #include - #include int tcgetattr(int fd, struct termios *tio) @@ -128,4 +126,3 @@ int cfsetspeed(struct termios *tio, speed_t speed) return cfsetospeed(tio, speed); } #endif - -- 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') 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 f94980af34bc9b1e86a4db393af034ea0707fa83 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 13 Jun 2021 12:45:04 +0800 Subject: solve conflict --- components/libc/termios/posix_termios.c | 1 + 1 file changed, 1 insertion(+) (limited to 'components/libc') diff --git a/components/libc/termios/posix_termios.c b/components/libc/termios/posix_termios.c index 1816bbae57..9f33c857e6 100644 --- a/components/libc/termios/posix_termios.c +++ b/components/libc/termios/posix_termios.c @@ -10,6 +10,7 @@ #include #include #include +#include #include int tcgetattr(int fd, struct termios *tio) -- 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') 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') 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') 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') 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') 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') 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 b277135f06c8a62d0447dac06ee08cd3d11fc3ac Mon Sep 17 00:00:00 2001 From: CornerOfSkyline Date: Fri, 9 Jul 2021 11:51:48 +0800 Subject: Fix the sem init check bug in pthread. --- components/libc/pthreads/semaphore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/libc') diff --git a/components/libc/pthreads/semaphore.c b/components/libc/pthreads/semaphore.c index 398cdf1f49..199b33bfe8 100644 --- a/components/libc/pthreads/semaphore.c +++ b/components/libc/pthreads/semaphore.c @@ -186,7 +186,7 @@ int sem_init(sem_t *sem, int pshared, unsigned int value) rt_snprintf(name, sizeof(name), "psem%02d", psem_number++); sem->sem = rt_sem_create(name, value, RT_IPC_FLAG_FIFO); - if (sem == RT_NULL) + if (sem->sem == RT_NULL) { rt_set_errno(ENOMEM); -- 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') 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