Merge remote-tracking branch 'remotes/gitee/master'

This commit is contained in:
guozhanxin
2021-07-12 10:14:20 +08:00
1620 changed files with 379763 additions and 45497 deletions

View File

@@ -16,26 +16,26 @@ endif
if RT_USING_LIBC && RT_USING_DFS
config RT_USING_POSIX
bool "Enable POSIX layer for poll/select, stdin etc"
bool "Enable POSIX layer for compatibility with UNIX APIs, poll/select etc"
select RT_USING_DFS_DEVFS
default y
if RT_USING_POSIX
config RT_USING_POSIX_MMAP
bool "Enable mmap() API"
default n
config RT_USING_POSIX_MMAP
bool "Enable mmap() API"
default n
config RT_USING_POSIX_TERMIOS
bool "Enable termios APIs"
default n
config RT_USING_POSIX_TERMIOS
bool "Enable termios APIs"
default n
config RT_USING_POSIX_GETLINE
bool "Enable getline()/getdelim() APIs"
default n
config RT_USING_POSIX_GETLINE
bool "Enable getline()/getdelim() APIs"
default n
config RT_USING_POSIX_AIO
bool "Enable AIO"
default n
config RT_USING_POSIX_AIO
bool "Enable AIO"
default n
endif
endif

View File

@@ -9,23 +9,22 @@ 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)
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'))
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')

View File

@@ -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);

View File

@@ -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

View File

@@ -6,8 +6,10 @@ src = []
cwd = GetCurrentDir()
CPPPATH = [cwd]
group = []
src += Glob('*.c')
if rtconfig.PLATFORM != 'gcc':
group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH)
if GetDepend('RT_USING_LIBC'):
src += Glob('*.c')
if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim':
group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
Return('group')

View File

@@ -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

View File

@@ -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

View File

@@ -16,7 +16,7 @@ extern "C" {
#endif
#include <sys/types.h>
#define MAP_FAILED ((void *) -1)
#define MAP_SHARED 0x01

View File

@@ -18,6 +18,18 @@
extern "C" {
#endif
#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 */
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
/*

View File

@@ -17,9 +17,11 @@
* which found by Rob <rdent@iinet.net.au>
* 2021-02-12 Meco Man move all of the functions located in <clock_time.c> 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 <sys/time.h>
#include "sys/time.h"
#include <sys/errno.h>
#include <rtthread.h>
#ifdef RT_USING_DEVICE
@@ -73,18 +75,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 +112,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 +136,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 +157,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 +296,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 +306,7 @@ RT_WEAK time_t time(time_t *t)
}
else
{
errno = EFAULT;
rt_set_errno(EFAULT);
return ((time_t)-1);
}
}
@@ -322,18 +324,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 +416,48 @@ time_t timegm(struct tm * const t)
}
RTM_EXPORT(timegm);
/* TODO: timezone */
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
if (tv != RT_NULL && get_timeval(tv) > 0)
/* 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 = DST_NONE;
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 */
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((struct timeval *)tv) == RT_EOK)
{
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;
}
return 0;
}
else
{
errno = EFAULT;
rt_set_errno(EINVAL);
return -1;
}
}

View File

@@ -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;
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 --;
}
}
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;
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);

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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

View File

@@ -19,16 +19,9 @@
#include <sys/types.h>
#include <sys/time.h>
/* errno for Keil MDK */
#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__)
#include <sys/errno.h>
#include <sys/unistd.h>
#else
#include <unistd.h>
#include <errno.h>
#include <sys/errno.h>
#include <fcntl.h>
#endif
#endif

View File

@@ -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)

View File

@@ -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

View File

@@ -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" {