diff options
| author | Wayne Lin <[email protected]> | 2021-07-12 18:17:25 +0800 |
|---|---|---|
| committer | Wayne Lin <[email protected]> | 2021-07-12 18:17:25 +0800 |
| commit | 735285360929c97d49ed51dbc41dfeec570a35b3 (patch) | |
| tree | 9c1b5303717e80442037fd43f4144ff67c86bc5c /components/libc | |
| parent | 978ea520d982ede86feee1f5f08b04bddd6efd1e (diff) | |
| parent | 19f1c82bc8355879d157805748b23e6dabed701d (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
Diffstat (limited to 'components/libc')
| -rw-r--r-- | components/libc/compilers/common/SConscript | 13 | ||||
| -rw-r--r-- | components/libc/compilers/common/delay.c | 41 | ||||
| -rw-r--r-- | components/libc/compilers/common/delay.h | 19 | ||||
| -rw-r--r-- | components/libc/compilers/common/none-gcc/SConscript | 6 | ||||
| -rw-r--r-- | components/libc/compilers/common/none-gcc/sys/errno.h | 197 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/ioctl.h | 220 | ||||
| -rw-r--r-- | components/libc/compilers/common/time.c | 10 | ||||
| -rw-r--r-- | components/libc/compilers/common/unistd.c | 31 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/minilib.c | 14 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/syscalls.c | 72 | ||||
| -rw-r--r-- | components/libc/getline/posix_getline.c | 6 | ||||
| -rw-r--r-- | components/libc/pthreads/posix_types.h | 2 | ||||
| -rw-r--r-- | components/libc/signal/posix_signal.c | 3 | ||||
| -rw-r--r-- | components/libc/termios/posix_termios.c | 4 | ||||
| -rw-r--r-- | components/libc/termios/posix_termios.h | 2 |
15 files changed, 557 insertions, 83 deletions
diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 039e53a0b3..b1982aa329 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', 'delay.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/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 <rtthread.h> +#include <rthw.h> + +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 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/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h new file mode 100644 index 0000000000..ad3614024d --- /dev/null +++ b/components/libc/compilers/common/none-gcc/sys/errno.h @@ -0,0 +1,197 @@ +/* + * 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(__ARMCC_VERSION) +/* +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(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__) +#include <errno.h> +#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/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 <dfs_posix.h> #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/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 9996212444..e79a22b9db 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -21,6 +21,7 @@ */ #include "sys/time.h" +#include <sys/errno.h> #include <rtthread.h> #ifdef RT_USING_DEVICE @@ -475,12 +476,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(); @@ -593,6 +599,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) @@ -601,6 +608,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/components/libc/compilers/common/unistd.c b/components/libc/compilers/common/unistd.c index 6c81fc7662..9a457c4200 100644 --- a/components/libc/compilers/common/unistd.c +++ b/components/libc/compilers/common/unistd.c @@ -37,26 +37,41 @@ 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); int usleep(useconds_t usec) { - rt_thread_mdelay(usec / 1000u); + if (rt_thread_self() != RT_NULL) + { + rt_thread_mdelay(usec / 1000u); + } + else /* scheduler has not run yet */ + { + rt_hw_us_delay(usec / 1000u); + } rt_hw_us_delay(usec % 1000u); + return 0; } RTM_EXPORT(usleep); 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 <rtthread.h> #ifdef RT_USING_HEAP /* Memory routine */ -void * -_malloc_r (struct _reent *ptr, size_t size) +#include <sys/errno.h> + +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; } 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); 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 <stdlib.h> -#include <errno.h> -#include <rtlibc.h> +#include <limits.h> +#include <sys/errno.h> 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 <sys/types.h> #include <sys/time.h> #include <unistd.h> -#include <errno.h> +#include <sys/errno.h> #include <fcntl.h> #endif 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 <rthw.h> #include <rtthread.h> -#include <time.h> +#include <sys/time.h> +#include <sys/errno.h> #include "posix_signal.h" #define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX) diff --git a/components/libc/termios/posix_termios.c b/components/libc/termios/posix_termios.c index 01ba010c86..9f33c857e6 100644 --- a/components/libc/termios/posix_termios.c +++ b/components/libc/termios/posix_termios.c @@ -9,9 +9,8 @@ */ #include <stdlib.h> #include <string.h> -#include <rtthread.h> #include <dfs_posix.h> - +#include <sys/errno.h> #include <termios.h> int tcgetattr(int fd, struct termios *tio) @@ -128,4 +127,3 @@ int cfsetspeed(struct termios *tio, speed_t speed) return cfsetospeed(tio, speed); } #endif - 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 <rtthread.h> #include <sys/types.h> +#include <sys/ioctl.h> #ifdef __cplusplus extern "C" { |
