diff options
| author | Wayne Lin <[email protected]> | 2022-01-25 18:53:52 +0800 |
|---|---|---|
| committer | Wayne Lin <[email protected]> | 2022-01-25 18:53:52 +0800 |
| commit | c95c296e9915a38a666ae1a2575c2a4d0ba1d376 (patch) | |
| tree | c6e5a1ffe4ceb997e853ba0c3daffc9dc60c8b79 /components/libc/compilers | |
| parent | f7ba146a01fcf23a2b06a141d1b1a56cb27b878c (diff) | |
| parent | 32a5668593c578b85560338c29d76f3a252c8dbc (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
# Conflicts:
# bsp/gd32/gd32107c-eval/rtconfig.h
Diffstat (limited to 'components/libc/compilers')
| -rw-r--r-- | components/libc/compilers/armlibc/libc_syms.c | 43 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/SConscript (renamed from components/libc/compilers/common/nogcc/SConscript) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/fcntl.h (renamed from components/libc/compilers/common/nogcc/fcntl.h) | 4 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/readme.md | 4 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/errno.h (renamed from components/libc/compilers/common/nogcc/sys/errno.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/select.h (renamed from components/libc/compilers/common/nogcc/sys/select.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/stat.h (renamed from components/libc/compilers/common/nogcc/sys/stat.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/types.h (renamed from components/libc/compilers/common/nogcc/sys/types.h) | 2 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/sys/unistd.h (renamed from components/libc/compilers/common/nogcc/sys/unistd.h) | 3 | ||||
| -rw-r--r-- | components/libc/compilers/common/extension/unistd.h (renamed from components/libc/compilers/common/nogcc/unistd.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/common/nogcc/readme.md | 3 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/ioctl.h | 77 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/signal.h | 38 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/time.h | 29 | ||||
| -rw-r--r-- | components/libc/compilers/common/time.c | 266 | ||||
| -rw-r--r-- | components/libc/compilers/gcc/newlib/legacy/SConscript | 15 | ||||
| -rw-r--r-- | components/libc/compilers/gcc/newlib/libc_syms.c | 53 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/README.md (renamed from components/libc/compilers/gcc/newlib/README.md) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/SConscript (renamed from components/libc/compilers/gcc/newlib/SConscript) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/fcntl.h (renamed from components/libc/compilers/gcc/newlib/fcntl.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/legacy/SConscript (renamed from components/libc/compilers/gcc/SConscript) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/legacy/_select/SConscript (renamed from components/libc/compilers/gcc/newlib/legacy/_select/SConscript) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/legacy/_select/readme.md (renamed from components/libc/compilers/gcc/newlib/legacy/_select/readme.md) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/legacy/_select/sys/select.h (renamed from components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/machine/time.h (renamed from components/libc/compilers/gcc/newlib/machine/time.h) | 0 | ||||
| -rw-r--r-- | components/libc/compilers/newlib/syscalls.c (renamed from components/libc/compilers/gcc/newlib/syscalls.c) | 0 |
26 files changed, 395 insertions, 142 deletions
diff --git a/components/libc/compilers/armlibc/libc_syms.c b/components/libc/compilers/armlibc/libc_syms.c deleted file mode 100644 index 2b370a25a6..0000000000 --- a/components/libc/compilers/armlibc/libc_syms.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <rtm.h> - -/* some export routines for module */ - -RTM_EXPORT(strstr); -RTM_EXPORT(strlen); -RTM_EXPORT(strchr); -RTM_EXPORT(strcpy); -RTM_EXPORT(strncpy); -RTM_EXPORT(strcmp); -RTM_EXPORT(strncmp); -RTM_EXPORT(strcat); -RTM_EXPORT(strtol); - -RTM_EXPORT(memcpy); -RTM_EXPORT(memcmp); -RTM_EXPORT(memmove); -RTM_EXPORT(memset); -RTM_EXPORT(memchr); - -RTM_EXPORT(toupper); -RTM_EXPORT(atoi); - -/* import the full stdio for printf */ -#if defined(RT_USING_MODULE) && defined(__MICROLIB) -#error "[RT_USING_LIBC] Please use standard libc but not microlib." -#endif - -RTM_EXPORT(puts); -RTM_EXPORT(printf); diff --git a/components/libc/compilers/common/nogcc/SConscript b/components/libc/compilers/common/extension/SConscript index dbc26ac177..dbc26ac177 100644 --- a/components/libc/compilers/common/nogcc/SConscript +++ b/components/libc/compilers/common/extension/SConscript diff --git a/components/libc/compilers/common/nogcc/fcntl.h b/components/libc/compilers/common/extension/fcntl.h index 83c3ec0b6b..ac642abcbb 100644 --- a/components/libc/compilers/common/nogcc/fcntl.h +++ b/components/libc/compilers/common/extension/fcntl.h @@ -11,7 +11,7 @@ #ifndef __FCNTL_H__ #define __FCNTL_H__ -#include <sys/types.h> +#include "sys/types.h" #define O_RDONLY 00 #define O_WRONLY 01 @@ -66,6 +66,6 @@ int open(const char *file, int flags, ...); int fcntl(int fildes, int cmd, ...); -int creat(const char *, mode_t); +int creat(const char *path, mode_t mode); #endif diff --git a/components/libc/compilers/common/extension/readme.md b/components/libc/compilers/common/extension/readme.md new file mode 100644 index 0000000000..ca0df69246 --- /dev/null +++ b/components/libc/compilers/common/extension/readme.md @@ -0,0 +1,4 @@ +## Attentions + +This folder is "common" for toolchains, which only support ISO C, as an extension part, such as Keil-MDK and IAR. + diff --git a/components/libc/compilers/common/nogcc/sys/errno.h b/components/libc/compilers/common/extension/sys/errno.h index d53ce4b386..d53ce4b386 100644 --- a/components/libc/compilers/common/nogcc/sys/errno.h +++ b/components/libc/compilers/common/extension/sys/errno.h diff --git a/components/libc/compilers/common/nogcc/sys/select.h b/components/libc/compilers/common/extension/sys/select.h index 44f9b4ed91..44f9b4ed91 100644 --- a/components/libc/compilers/common/nogcc/sys/select.h +++ b/components/libc/compilers/common/extension/sys/select.h diff --git a/components/libc/compilers/common/nogcc/sys/stat.h b/components/libc/compilers/common/extension/sys/stat.h index 107c15decf..107c15decf 100644 --- a/components/libc/compilers/common/nogcc/sys/stat.h +++ b/components/libc/compilers/common/extension/sys/stat.h diff --git a/components/libc/compilers/common/nogcc/sys/types.h b/components/libc/compilers/common/extension/sys/types.h index 32b2493c95..85cd4fea21 100644 --- a/components/libc/compilers/common/nogcc/sys/types.h +++ b/components/libc/compilers/common/extension/sys/types.h @@ -28,6 +28,8 @@ typedef signed int ssize_t; /* Used for a count of bytes or an error #else typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ #endif +typedef unsigned long __timer_t; +typedef __timer_t timer_t; typedef long suseconds_t; /* microseconds. */ typedef unsigned long useconds_t; /* microseconds (unsigned) */ diff --git a/components/libc/compilers/common/nogcc/sys/unistd.h b/components/libc/compilers/common/extension/sys/unistd.h index 650c87dc18..29ec3f70c4 100644 --- a/components/libc/compilers/common/nogcc/sys/unistd.h +++ b/components/libc/compilers/common/extension/sys/unistd.h @@ -19,10 +19,13 @@ #define STDOUT_FILENO 1 /* standard output file descriptor */ #define STDERR_FILENO 2 /* standard error file descriptor */ +unsigned alarm(unsigned __secs); ssize_t read(int fd, void *buf, size_t len); ssize_t write(int fd, const void *buf, size_t len); off_t lseek(int fd, off_t offset, int whence); +int pause(void); int fsync(int fildes); +long sysconf(int __name); int unlink(const char *pathname); int close(int d); int ftruncate(int fd, off_t length); diff --git a/components/libc/compilers/common/nogcc/unistd.h b/components/libc/compilers/common/extension/unistd.h index 4dd71c842e..4dd71c842e 100644 --- a/components/libc/compilers/common/nogcc/unistd.h +++ b/components/libc/compilers/common/extension/unistd.h diff --git a/components/libc/compilers/common/nogcc/readme.md b/components/libc/compilers/common/nogcc/readme.md deleted file mode 100644 index b10940d003..0000000000 --- a/components/libc/compilers/common/nogcc/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -## Attentions - -This folder is "common" for toolchains excluding gcc.
\ No newline at end of file diff --git a/components/libc/compilers/common/sys/ioctl.h b/components/libc/compilers/common/sys/ioctl.h index d93c79115a..0b1edca699 100644 --- a/components/libc/compilers/common/sys/ioctl.h +++ b/components/libc/compilers/common/sys/ioctl.h @@ -11,35 +11,79 @@ #ifndef __SYS_IOCTL_H__ #define __SYS_IOCTL_H__ -#include <rtconfig.h> -#include <dfs_posix.h> - #ifdef _WIN32 #include <winsock.h> #endif -struct winsize { +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) ) +/* + * Direction bits, which any architecture can choose to override + * before including this file. + */ + +#ifndef _IOC_NONE #define _IOC_NONE 0U +#endif + +#ifndef _IOC_WRITE #define _IOC_WRITE 1U +#endif + +#ifndef _IOC_READ #define _IOC_READ 2U +#endif -#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)) +#ifndef _IOC +#define _IOC(a,b,c,d) (((a)<<30) | ((b)<<8) | (c) | ((d)<<16)) +#endif + +#ifndef _IO +#define _IO(a,b) _IOC(_IOC_NONE, (a), (b), 0) +#endif + +#ifndef _IOW +#define _IOW(a,b,c) _IOC(_IOC_WRITE, (a), (b), sizeof(c)) +#endif + +#ifndef _IOR +#define _IOR(a,b,c) _IOC(_IOC_READ, (a), (b), sizeof(c)) +#endif + +#ifndef _IOWR +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE, (a), (b), sizeof(c)) +#endif +#ifndef FIONREAD #define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ +#endif + +#ifndef FIONBIO #define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ #endif + +#ifndef FIOASYNC +#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */ +#endif + +#ifndef FIONWRITE #define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding in send queue */ +#endif + +/* Socket I/O Controls */ +#ifndef SIOCSHIWAT +#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */ +#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */ +#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */ +#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */ +#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ +#endif #define TCGETS 0x5401 #define TCSETS 0x5402 @@ -67,18 +111,12 @@ struct winsize { #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 @@ -104,10 +142,6 @@ struct winsize { #define FIONCLEX 0x5450 #define FIOCLEX 0x5451 -#ifndef _WIN32 -#define FIOASYNC 0x5452 -#endif - #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 @@ -169,9 +203,6 @@ struct winsize { #define SIOCSPGRP 0x8902 #define FIOGETOWN 0x8903 #define SIOCGPGRP 0x8904 -#ifndef SIOCATMARK -#define SIOCATMARK 0x8905 -#endif #define SIOCGSTAMP 0x8906 #define SIOCGSTAMPNS 0x8907 diff --git a/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h index 9787958a37..041dd765b7 100644 --- a/components/libc/compilers/common/sys/signal.h +++ b/components/libc/compilers/common/sys/signal.h @@ -17,6 +17,19 @@ extern "C" { #endif #include <stdint.h> +#include <sys/types.h> + + +/* sigev_notify values + NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */ + +#define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */ + /* when the event of interest occurs. */ +#define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */ + /* value, shall be delivered when the event of */ + /* interest occurs. */ +#define SIGEV_THREAD 3 /* A notification function shall be called to */ + /* perform notification. */ /* Signal Generation and Delivery, P1003.1b-1993, p. 63 NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and @@ -62,6 +75,16 @@ struct sigaction int sa_flags; }; +/* + * Structure used in sigaltstack call. + */ +typedef struct sigaltstack +{ + void *ss_sp; /* Stack base or pointer. */ + int ss_flags; /* Flags. */ + size_t ss_size; /* Stack size. */ +} stack_t; + #define SIG_SETMASK 0 /* set mask with sigprocmask() */ #define SIG_BLOCK 1 /* set of signals to block */ #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ @@ -73,6 +96,15 @@ struct sigaction #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) int sigprocmask (int how, const sigset_t *set, sigset_t *oset); +int sigpending (sigset_t *set); +int sigsuspend (const sigset_t *set); + +#include "time.h" +int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout); +int sigwait(const sigset_t *set, int *sig); +int sigwaitinfo(const sigset_t *set, siginfo_t *info); +int raise(int sig); +int sigqueue(pid_t pid, int signo, const union sigval value); int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); #ifdef __ARMCC_VERSION @@ -100,6 +132,9 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #define SIGTTOU 22 #define SIGPOLL 23 #define SIGWINCH 24 +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ /* #define SIGUSR1 25 */ /* #define SIGUSR2 26 */ #define SIGRTMIN 27 @@ -133,6 +168,9 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #define SIGTTOU 22 #define SIGPOLL 23 #define SIGWINCH 24 +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ #define SIGUSR1 25 #define SIGUSR2 26 #define SIGRTMIN 27 diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 758333796d..a3af31b20b 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021, RT-Thread Development Team + * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -60,6 +60,16 @@ struct timespec time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ }; + +/* + * Structure defined by POSIX.1b to be like a itimerval, but with + * timespecs. Used in the timer_*() system calls. + */ +struct itimerspec +{ + struct timespec it_interval; + struct timespec it_value; +}; #endif int stime(const time_t *t); @@ -68,6 +78,9 @@ int gettimeofday(struct timeval *tv, struct timezone *tz); int settimeofday(const struct timeval *tv, const struct timezone *tz); #if defined(__ARMCC_VERSION) || defined (__ICCARM__) struct tm *gmtime_r(const time_t *timep, struct tm *r); +struct tm* localtime_r(const time_t* t, struct tm* r); +char* asctime_r(const struct tm *t, char *buf); +char *ctime_r(const time_t * tim_p, char * result); #elif defined(_WIN32) struct tm* gmtime_r(const time_t* timep, struct tm* r); struct tm* gmtime(const time_t* t); @@ -84,7 +97,7 @@ time_t time(time_t* t); int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); #endif /* RT_USING_POSIX_DELAY */ -#ifdef RT_USING_POSIX_CLOCK +#if defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) /* POSIX clock and timer */ #define MILLISECOND_PER_SECOND 1000UL #define MICROSECOND_PER_SECOND 1000000UL @@ -110,7 +123,9 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC 4 #endif +#endif /* defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) */ +#ifdef RT_USING_POSIX_CLOCK int clock_getres (clockid_t clockid, struct timespec *res); int clock_gettime (clockid_t clockid, struct timespec *tp); int clock_settime (clockid_t clockid, const struct timespec *tp); @@ -118,6 +133,16 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, s int rt_timespec_to_tick(const struct timespec *time); #endif /* RT_USING_POSIX_CLOCK */ +#ifdef RT_USING_POSIX_TIMER +#include "signal.h" +int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid); +int timer_delete(timer_t timerid); +int timer_getoverrun(timer_t timerid); +int timer_gettime(timer_t timerid, struct itimerspec *its); +int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, + struct itimerspec *ovalue); +#endif /* RT_USING_POSIX_TIMER */ + /* timezone */ void tz_set(int8_t tz); int8_t tz_get(void); diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 46bb0c1355..71755b8bbb 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -25,6 +25,10 @@ #include <sys/errno.h> #include <rtthread.h> #include <rthw.h> +#include <unistd.h> +#ifdef RT_USING_POSIX_DELAY +#include <delay.h> +#endif #ifdef RT_USING_RTC #include <rtdevice.h> #endif @@ -489,7 +493,6 @@ RTM_EXPORT(difftime); RTM_EXPORT(strftime); #ifdef RT_USING_POSIX_DELAY -#include <delay.h> int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { sleep(rqtp->tv_sec); @@ -715,6 +718,267 @@ RTM_EXPORT(rt_timespec_to_tick); #endif /* RT_USING_POSIX_CLOCK */ +#ifdef RT_USING_POSIX_TIMER + +#define ACTIVE 1 +#define NOT_ACTIVE 0 + +struct timer_obj +{ + struct rt_timer timer; + void (*sigev_notify_function)(union sigval val); + union sigval val; + struct timespec interval; /* Reload value */ + rt_uint32_t reload; /* Reload value in ms */ + rt_uint32_t status; +}; + +static void rtthread_timer_wrapper(void *timerobj) +{ + struct timer_obj *timer; + + timer = (struct timer_obj *)timerobj; + + if (timer->reload == 0U) + { + timer->status = NOT_ACTIVE; + } + + if(timer->sigev_notify_function != RT_NULL) + { + (timer->sigev_notify_function)(timer->val); + } +} + +/** + * @brief Create a per-process timer. + * + * This API does not accept SIGEV_THREAD as valid signal event notification + * type. + * + * See IEEE 1003.1 + */ +int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid) +{ + static int num = 0; + struct timer_obj *timer; + char timername[RT_NAME_MAX] = {0}; + + if (clockid != CLOCK_MONOTONIC || evp == NULL || + (evp->sigev_notify != SIGEV_NONE && + evp->sigev_notify != SIGEV_SIGNAL)) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + timer = rt_malloc(sizeof(struct timer_obj)); + if(timer == RT_NULL) + { + rt_set_errno(ENOMEM); + return -RT_ENOMEM; + } + + RT_ASSERT(evp->sigev_notify_function != RT_NULL); + rt_snprintf(timername, RT_NAME_MAX, "psx_tm%02d", num++); + num %= 100; + timer->sigev_notify_function = evp->sigev_notify_function; + timer->val = evp->sigev_value; + timer->interval.tv_sec = 0; + timer->interval.tv_nsec = 0; + timer->reload = 0U; + timer->status = NOT_ACTIVE; + + if (evp->sigev_notify == SIGEV_NONE) + { + rt_timer_init(&timer->timer, timername, RT_NULL, RT_NULL, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); + } + else + { + rt_timer_init(&timer->timer, timername, rtthread_timer_wrapper, timer, 0, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); + } + + *timerid = (timer_t)timer; + + return RT_EOK; +} +RTM_EXPORT(timer_create); + +/** + * @brief Delete a per-process timer. + * + * See IEEE 1003.1 + */ +int timer_delete(timer_t timerid) +{ + struct timer_obj *timer = (struct timer_obj *)timerid; + + if (timer == RT_NULL) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + if (timer->status == ACTIVE) + { + timer->status = NOT_ACTIVE; + rt_timer_stop(&timer->timer); + } + + rt_free(timer); + + return RT_EOK; +} +RTM_EXPORT(timer_delete); + +/** + * + * Return the overrun count for the last timer expiration. + * It is subefficient to create a new structure to get overrun count. + **/ +int timer_getoverrun(timer_t timerid) +{ + rt_set_errno(ENOSYS); + return -RT_ERROR; +} + +/** + * @brief Get amount of time left for expiration on a per-process timer. + * + * See IEEE 1003.1 + */ +int timer_gettime(timer_t timerid, struct itimerspec *its) +{ + struct timer_obj *timer = (struct timer_obj *)timerid; + rt_tick_t remaining; + rt_uint32_t seconds, nanoseconds; + + if (timer == NULL) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + if (its == NULL) + { + rt_set_errno(EFAULT); + return -RT_ERROR; + } + + if (timer->status == ACTIVE) + { + rt_tick_t remain_tick; + + rt_timer_control(&timer->timer, RT_TIMER_CTRL_GET_REMAIN_TIME, &remain_tick); + + /* 'remain_tick' is minimum-unit in the RT-Thread' timer, + * so the seconds, nanoseconds will be calculated by 'remain_tick'. + */ + remaining = remain_tick - rt_tick_get(); + + /* calculate 'second' */ + seconds = remaining / RT_TICK_PER_SECOND; + + /* calculate 'nanosecond'; To avoid lost of accuracy, because "RT_TICK_PER_SECOND" maybe 100, 1000, 1024 and so on. + * + * remain_tick millisecond remain_tick * MILLISECOND_PER_SECOND + * ------------------------- = -------------------------- ---> millisecond = ------------------------------------------- + * RT_TICK_PER_SECOND MILLISECOND_PER_SECOND RT_TICK_PER_SECOND + * + * remain_tick * MILLISECOND_PER_SECOND remain_tick * MILLISECOND_PER_SECOND * MICROSECOND_PER_SECOND + * millisecond = ---------------------------------------- ---> nanosecond = ------------------------------------------------------------------- + * RT_TICK_PER_SECOND RT_TICK_PER_SECOND + * + */ + nanoseconds = (((remaining % RT_TICK_PER_SECOND) * MILLISECOND_PER_SECOND) * MICROSECOND_PER_SECOND) / RT_TICK_PER_SECOND ; + + its->it_value.tv_sec = (rt_int32_t)seconds; + its->it_value.tv_nsec = (rt_int32_t)nanoseconds; + } + else + { + /* Timer is disarmed */ + its->it_value.tv_sec = 0; + its->it_value.tv_nsec = 0; + } + + /* The interval last set by timer_settime() */ + its->it_interval = timer->interval; + return RT_EOK; +} +RTM_EXPORT(timer_gettime); + +/** + * @brief Sets expiration time of per-process timer. + * + * See IEEE 1003.1 + */ +int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, + struct itimerspec *ovalue) +{ + struct timer_obj *timer = (struct timer_obj *)timerid; + + if (timer == NULL || + value->it_interval.tv_nsec < 0 || + value->it_interval.tv_nsec >= NANOSECOND_PER_SECOND || + value->it_value.tv_nsec < 0 || + value->it_value.tv_nsec >= NANOSECOND_PER_SECOND) + { + rt_set_errno(EINVAL); + return -RT_ERROR; + } + + if (value == NULL || ovalue == NULL) + { + rt_set_errno(EFAULT); + return -RT_ERROR; + } + + /* Save time to expire and old reload value. */ + if (ovalue != NULL) + { + timer_gettime(timerid, ovalue); + } + + /* Stop the timer if the value is 0 */ + if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) + { + if (timer->status == ACTIVE) + { + rt_timer_stop(&timer->timer); + } + + timer->status = NOT_ACTIVE; + return RT_EOK; + } + + /* calculate timer period(tick); To avoid lost of accuracy, because "RT_TICK_PER_SECOND" maybe 100, 1000, 1024 and so on. + * + * tick nanosecond nanosecond * RT_TICK_PER_SECOND + * ------------------------- = -------------------------- ---> tick = ------------------------------------- + * RT_TICK_PER_SECOND NANOSECOND_PER_SECOND NANOSECOND_PER_SECOND + * + */ + timer->reload = (value->it_interval.tv_sec * RT_TICK_PER_SECOND) + (value->it_interval.tv_nsec * RT_TICK_PER_SECOND) / NANOSECOND_PER_SECOND; + timer->interval.tv_sec = value->it_interval.tv_sec; + timer->interval.tv_nsec = value->it_interval.tv_nsec; + + if (timer->status == ACTIVE) + { + rt_timer_stop(&timer->timer); + } + + timer->status = ACTIVE; + rt_timer_control(&timer->timer, RT_TIMER_CTRL_SET_TIME, (void *)timer->reload); + rt_timer_control(&timer->timer, RT_TIMER_CTRL_SET_PERIODIC, RT_NULL); + rt_timer_start(&timer->timer); + + return RT_EOK; +} +RTM_EXPORT(timer_settime); +#endif /* RT_USING_POSIX_TIMER */ + + /* timezone */ #ifndef RT_LIBC_DEFAULT_TIMEZONE #define RT_LIBC_DEFAULT_TIMEZONE 8 diff --git a/components/libc/compilers/gcc/newlib/legacy/SConscript b/components/libc/compilers/gcc/newlib/legacy/SConscript deleted file mode 100644 index 4c815c49b8..0000000000 --- a/components/libc/compilers/gcc/newlib/legacy/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -# RT-Thread building script for bridge - -import os -from building import * - -cwd = GetCurrentDir() -objs = [] -list = os.listdir(cwd) - -for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(d, 'SConscript')) - -Return('objs') diff --git a/components/libc/compilers/gcc/newlib/libc_syms.c b/components/libc/compilers/gcc/newlib/libc_syms.c deleted file mode 100644 index e6ca23b393..0000000000 --- a/components/libc/compilers/gcc/newlib/libc_syms.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ - -#include <rtthread.h> -#include <rtm.h> - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> - -RTM_EXPORT(strcpy); -RTM_EXPORT(strncpy); -RTM_EXPORT(strlen); -RTM_EXPORT(strcat); -RTM_EXPORT(strstr); -RTM_EXPORT(strchr); -RTM_EXPORT(strcmp); -RTM_EXPORT(strtol); -RTM_EXPORT(strtoul); -RTM_EXPORT(strncmp); - -RTM_EXPORT(memcpy); -RTM_EXPORT(memcmp); -RTM_EXPORT(memmove); -RTM_EXPORT(memset); -RTM_EXPORT(memchr); - -RTM_EXPORT(putchar); -RTM_EXPORT(puts); -RTM_EXPORT(printf); -RTM_EXPORT(sprintf); -RTM_EXPORT(snprintf); - -RTM_EXPORT(fwrite); - -#include <setjmp.h> -RTM_EXPORT(longjmp); -RTM_EXPORT(setjmp); - -RTM_EXPORT(exit); -RTM_EXPORT(abort); - -RTM_EXPORT(rand); - -#include <assert.h> -RTM_EXPORT(__assert_func); diff --git a/components/libc/compilers/gcc/newlib/README.md b/components/libc/compilers/newlib/README.md index 4614375b45..4614375b45 100644 --- a/components/libc/compilers/gcc/newlib/README.md +++ b/components/libc/compilers/newlib/README.md diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/newlib/SConscript index 8076a73727..8076a73727 100644 --- a/components/libc/compilers/gcc/newlib/SConscript +++ b/components/libc/compilers/newlib/SConscript diff --git a/components/libc/compilers/gcc/newlib/fcntl.h b/components/libc/compilers/newlib/fcntl.h index 847ae3d35b..847ae3d35b 100644 --- a/components/libc/compilers/gcc/newlib/fcntl.h +++ b/components/libc/compilers/newlib/fcntl.h diff --git a/components/libc/compilers/gcc/SConscript b/components/libc/compilers/newlib/legacy/SConscript index 4c815c49b8..4c815c49b8 100644 --- a/components/libc/compilers/gcc/SConscript +++ b/components/libc/compilers/newlib/legacy/SConscript diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript b/components/libc/compilers/newlib/legacy/_select/SConscript index b7bd86a36c..b7bd86a36c 100644 --- a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript +++ b/components/libc/compilers/newlib/legacy/_select/SConscript diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/readme.md b/components/libc/compilers/newlib/legacy/_select/readme.md index 4ad9f21923..4ad9f21923 100644 --- a/components/libc/compilers/gcc/newlib/legacy/_select/readme.md +++ b/components/libc/compilers/newlib/legacy/_select/readme.md diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h b/components/libc/compilers/newlib/legacy/_select/sys/select.h index 02fb77dd89..02fb77dd89 100644 --- a/components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h +++ b/components/libc/compilers/newlib/legacy/_select/sys/select.h diff --git a/components/libc/compilers/gcc/newlib/machine/time.h b/components/libc/compilers/newlib/machine/time.h index 805b061aea..805b061aea 100644 --- a/components/libc/compilers/gcc/newlib/machine/time.h +++ b/components/libc/compilers/newlib/machine/time.h diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index dcf26ccfb7..dcf26ccfb7 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c |
