the support for PSE51 (#5534)
* [add] the function realization of signal for posix. * [update] the posix support for armclang. * [add] the new macro "RT_USING_POSIX_TIMER". * [modify] select "RT_USING_SOFT_TIMER" when use posix'timer. * [bug] optimize the logic for the "time_xxx" functions. * [modify] use "RT_USING_POSIX_TIMER" to protect the macro definition. * [modify] error code when except happened. * [delete] the "environ" is useless at this time.
This commit is contained in:
parent
4dab5e0e59
commit
075e04e344
@ -28,6 +28,8 @@ typedef signed int ssize_t; /* Used for a count of bytes or an error
|
|||||||
#else
|
#else
|
||||||
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||||
#endif
|
#endif
|
||||||
|
typedef unsigned long __timer_t;
|
||||||
|
typedef __timer_t timer_t;
|
||||||
typedef long suseconds_t; /* microseconds. */
|
typedef long suseconds_t; /* microseconds. */
|
||||||
typedef unsigned long useconds_t; /* microseconds (unsigned) */
|
typedef unsigned long useconds_t; /* microseconds (unsigned) */
|
||||||
|
|
||||||
|
@ -19,10 +19,13 @@
|
|||||||
#define STDOUT_FILENO 1 /* standard output file descriptor */
|
#define STDOUT_FILENO 1 /* standard output file descriptor */
|
||||||
#define STDERR_FILENO 2 /* standard error 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 read(int fd, void *buf, size_t len);
|
||||||
ssize_t write(int fd, const 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);
|
off_t lseek(int fd, off_t offset, int whence);
|
||||||
|
int pause(void);
|
||||||
int fsync(int fildes);
|
int fsync(int fildes);
|
||||||
|
long sysconf(int __name);
|
||||||
int unlink(const char *pathname);
|
int unlink(const char *pathname);
|
||||||
int close(int d);
|
int close(int d);
|
||||||
int ftruncate(int fd, off_t length);
|
int ftruncate(int fd, off_t length);
|
||||||
|
@ -17,6 +17,19 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#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
|
/* Signal Generation and Delivery, P1003.1b-1993, p. 63
|
||||||
NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
|
NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
|
||||||
@ -62,6 +75,16 @@ struct sigaction
|
|||||||
int sa_flags;
|
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_SETMASK 0 /* set mask with sigprocmask() */
|
||||||
#define SIG_BLOCK 1 /* set of signals to block */
|
#define SIG_BLOCK 1 /* set of signals to block */
|
||||||
#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
|
#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
|
||||||
@ -73,6 +96,15 @@ struct sigaction
|
|||||||
#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
|
#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
|
||||||
|
|
||||||
int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
|
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);
|
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
|
||||||
|
|
||||||
#ifdef __ARMCC_VERSION
|
#ifdef __ARMCC_VERSION
|
||||||
@ -100,6 +132,9 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
|
|||||||
#define SIGTTOU 22
|
#define SIGTTOU 22
|
||||||
#define SIGPOLL 23
|
#define SIGPOLL 23
|
||||||
#define SIGWINCH 24
|
#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 SIGUSR1 25 */
|
||||||
/* #define SIGUSR2 26 */
|
/* #define SIGUSR2 26 */
|
||||||
#define SIGRTMIN 27
|
#define SIGRTMIN 27
|
||||||
@ -133,6 +168,9 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
|
|||||||
#define SIGTTOU 22
|
#define SIGTTOU 22
|
||||||
#define SIGPOLL 23
|
#define SIGPOLL 23
|
||||||
#define SIGWINCH 24
|
#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 SIGUSR1 25
|
||||||
#define SIGUSR2 26
|
#define SIGUSR2 26
|
||||||
#define SIGRTMIN 27
|
#define SIGRTMIN 27
|
||||||
|
@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
@ -60,6 +60,16 @@ struct timespec
|
|||||||
time_t tv_sec; /* seconds */
|
time_t tv_sec; /* seconds */
|
||||||
long tv_nsec; /* and nanoseconds */
|
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
|
#endif
|
||||||
|
|
||||||
int stime(const time_t *t);
|
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);
|
int settimeofday(const struct timeval *tv, const struct timezone *tz);
|
||||||
#if defined(__ARMCC_VERSION) || defined (__ICCARM__)
|
#if defined(__ARMCC_VERSION) || defined (__ICCARM__)
|
||||||
struct tm *gmtime_r(const time_t *timep, struct tm *r);
|
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)
|
#elif defined(_WIN32)
|
||||||
struct tm* gmtime_r(const time_t* timep, struct tm* r);
|
struct tm* gmtime_r(const time_t* timep, struct tm* r);
|
||||||
struct tm* gmtime(const time_t* t);
|
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);
|
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
||||||
#endif /* RT_USING_POSIX_DELAY */
|
#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 */
|
/* POSIX clock and timer */
|
||||||
#define MILLISECOND_PER_SECOND 1000UL
|
#define MILLISECOND_PER_SECOND 1000UL
|
||||||
#define MICROSECOND_PER_SECOND 1000000UL
|
#define MICROSECOND_PER_SECOND 1000000UL
|
||||||
@ -110,7 +123,9 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
|||||||
#ifndef CLOCK_MONOTONIC
|
#ifndef CLOCK_MONOTONIC
|
||||||
#define CLOCK_MONOTONIC 4
|
#define CLOCK_MONOTONIC 4
|
||||||
#endif
|
#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_getres (clockid_t clockid, struct timespec *res);
|
||||||
int clock_gettime (clockid_t clockid, struct timespec *tp);
|
int clock_gettime (clockid_t clockid, struct timespec *tp);
|
||||||
int clock_settime (clockid_t clockid, const 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);
|
int rt_timespec_to_tick(const struct timespec *time);
|
||||||
#endif /* RT_USING_POSIX_CLOCK */
|
#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 */
|
/* timezone */
|
||||||
void tz_set(int8_t tz);
|
void tz_set(int8_t tz);
|
||||||
int8_t tz_get(void);
|
int8_t tz_get(void);
|
||||||
|
@ -718,6 +718,269 @@ RTM_EXPORT(rt_timespec_to_tick);
|
|||||||
|
|
||||||
#endif /* RT_USING_POSIX_CLOCK */
|
#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;
|
||||||
|
rt_int64_t nsecs, secs;
|
||||||
|
|
||||||
|
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;
|
||||||
|
rt_uint32_t duration, current;
|
||||||
|
|
||||||
|
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 */
|
/* timezone */
|
||||||
#ifndef RT_LIBC_DEFAULT_TIMEZONE
|
#ifndef RT_LIBC_DEFAULT_TIMEZONE
|
||||||
#define RT_LIBC_DEFAULT_TIMEZONE 8
|
#define RT_LIBC_DEFAULT_TIMEZONE 8
|
||||||
|
327
components/libc/posix-info.txt
Normal file
327
components/libc/posix-info.txt
Normal file
@ -0,0 +1,327 @@
|
|||||||
|
### The list of function support for POSIX 51 standard in the RT-Thread
|
||||||
|
|
||||||
|
<ctype.h>
|
||||||
|
+ isalnum()
|
||||||
|
+ isalpha()
|
||||||
|
+ isblank()
|
||||||
|
+ iscntrl()
|
||||||
|
+ isdigit()
|
||||||
|
+ isgraph()
|
||||||
|
+ islower()
|
||||||
|
+ isprint()
|
||||||
|
+ ispunct()
|
||||||
|
+ isspace()
|
||||||
|
+ isupper()
|
||||||
|
+ isxdigit()
|
||||||
|
+ tolower()
|
||||||
|
+ toupper()
|
||||||
|
|
||||||
|
<errno.h> -> for gcc, keil, iar platform at the same time;
|
||||||
|
Suggest to choose <sys/errno.h>
|
||||||
|
+ errno
|
||||||
|
|
||||||
|
<fcntl.h>
|
||||||
|
+ open()
|
||||||
|
|
||||||
|
<fenv.h> ;the 'env' should combined with non-volatile devices
|
||||||
|
+ feclearexcept()
|
||||||
|
+ fegetenv()
|
||||||
|
+ fegetexceptflag()
|
||||||
|
+ fegetround()
|
||||||
|
+ feholdexcept()
|
||||||
|
+ feraiseexcept()
|
||||||
|
+ fesetenv()
|
||||||
|
+ fesetexceptflag()
|
||||||
|
+ fesetround()
|
||||||
|
+ fetestexcept()
|
||||||
|
+ feupdateenv()
|
||||||
|
|
||||||
|
<inttypes.h>
|
||||||
|
+ imaxabs()
|
||||||
|
+ imaxdiv()
|
||||||
|
+ strtoimax()
|
||||||
|
+ strtoumax()
|
||||||
|
|
||||||
|
<locale.h>
|
||||||
|
+ localeconv()
|
||||||
|
+ setlocale()
|
||||||
|
|
||||||
|
<pthread.h>
|
||||||
|
+ pthread_atfork()
|
||||||
|
+ pthread_attr_destroy()
|
||||||
|
+ pthread_attr_getdetachstate()
|
||||||
|
+ pthread_attr_getguardsize()
|
||||||
|
+ pthread_attr_getinheritsched()
|
||||||
|
+ pthread_attr_getschedparam()
|
||||||
|
+ pthread_attr_getschedpolicy()
|
||||||
|
+ pthread_attr_getscope()
|
||||||
|
+ pthread_attr_getstack()
|
||||||
|
+ pthread_attr_getstackaddr()
|
||||||
|
+ pthread_attr_getstacksize()
|
||||||
|
+ pthread_attr_init()
|
||||||
|
+ pthread_attr_setdetachstate()
|
||||||
|
+ pthread_attr_setguardsize()
|
||||||
|
+ pthread_attr_setinheritsched()
|
||||||
|
+ pthread_attr_setschedparam()
|
||||||
|
+ pthread_attr_setschedpolicy()
|
||||||
|
+ pthread_attr_setscope()
|
||||||
|
+ pthread_attr_setstack()
|
||||||
|
+ pthread_attr_setstackaddr()
|
||||||
|
+ pthread_attr_setstacksize()
|
||||||
|
+ pthread_cancel()
|
||||||
|
+ pthread_cleanup_pop()
|
||||||
|
+ pthread_cleanup_push()
|
||||||
|
+ pthread_cond_broadcast()
|
||||||
|
+ pthread_cond_destroy()
|
||||||
|
+ pthread_cond_init()
|
||||||
|
+ pthread_cond_signal()
|
||||||
|
+ pthread_cond_timedwait()
|
||||||
|
+ pthread_cond_wait()
|
||||||
|
+ pthread_condattr_destroy()
|
||||||
|
+ pthread_condattr_getclock()
|
||||||
|
+ pthread_condattr_init()
|
||||||
|
+ pthread_condattr_setclock()
|
||||||
|
+ pthread_create()
|
||||||
|
+ pthread_detach()
|
||||||
|
+ pthread_equal()
|
||||||
|
+ pthread_exit()
|
||||||
|
+ pthread_getcpuclockid()
|
||||||
|
+ pthread_getconcurrency()
|
||||||
|
+ pthread_getschedparam()
|
||||||
|
+ pthread_getspecific()
|
||||||
|
+ pthread_join()
|
||||||
|
+ pthread_key_create()
|
||||||
|
+ pthread_key_delete()
|
||||||
|
+ pthread_mutex_destroy()
|
||||||
|
+ pthread_mutex_getprioceiling()
|
||||||
|
+ pthread_mutex_init()
|
||||||
|
+ pthread_mutex_lock()
|
||||||
|
+ pthread_mutex_setprioceiling()
|
||||||
|
+ pthread_mutex_trylock()
|
||||||
|
+ pthread_mutex_unlock()
|
||||||
|
+ pthread_mutexattr_destroy()
|
||||||
|
+ pthread_mutexattr_getprioceiling()
|
||||||
|
+ pthread_mutexattr_getprotocol()
|
||||||
|
+ pthread_mutexattr_gettype()
|
||||||
|
+ pthread_mutexattr_init()
|
||||||
|
+ pthread_mutexattr_setprioceiling()
|
||||||
|
+ pthread_mutexattr_setprotocol()
|
||||||
|
+ pthread_mutexattr_settype()
|
||||||
|
+ pthread_once()
|
||||||
|
+ pthread_self()
|
||||||
|
+ pthread_setcancelstate()
|
||||||
|
+ pthread_setcanceltype()
|
||||||
|
+ pthread_setconcurrency()
|
||||||
|
+ pthread_setschedparam()
|
||||||
|
+ pthread_setschedprio()
|
||||||
|
+ pthread_setspecific()
|
||||||
|
+ pthread_testcancel()
|
||||||
|
|
||||||
|
<sched.h>
|
||||||
|
+ sched_get_priority_max()
|
||||||
|
+ sched_get_priority_min()
|
||||||
|
+ sched_rr_get_interval()
|
||||||
|
|
||||||
|
<samaphore.h>
|
||||||
|
+ sem_close()
|
||||||
|
+ sem_destroy()
|
||||||
|
+ sem_getvalue()
|
||||||
|
+ sem_init()
|
||||||
|
+ sem_open()
|
||||||
|
+ sem_post()
|
||||||
|
+ sem_timedwait()
|
||||||
|
+ sem_trywait()
|
||||||
|
+ sem_unlink()
|
||||||
|
+ sem_wait()
|
||||||
|
|
||||||
|
<setjmp.h>
|
||||||
|
+ longjmp()
|
||||||
|
+ setjmp()
|
||||||
|
|
||||||
|
<signal.h> -> for gcc, keil, iar platform at the same time;
|
||||||
|
Suggest to choose <sys/signal.h>
|
||||||
|
+ kill()
|
||||||
|
+ pthread_kill()
|
||||||
|
+ pthread_sigmask()
|
||||||
|
+ raise()
|
||||||
|
+ sigaction()
|
||||||
|
+ sigaddset()
|
||||||
|
+ sigdelset()
|
||||||
|
+ sigemptyset()
|
||||||
|
+ sigfillset()
|
||||||
|
+ sigismember()
|
||||||
|
+ signal()
|
||||||
|
+ sigpending()
|
||||||
|
+ sigprocmask()
|
||||||
|
- sigqueue()
|
||||||
|
+ sigsuspend()
|
||||||
|
+ sigtimedwait()
|
||||||
|
+ sigwait()
|
||||||
|
+ sigwaitinfo()
|
||||||
|
|
||||||
|
<stdarg.h>
|
||||||
|
+ va_arg()
|
||||||
|
+ va_copy()
|
||||||
|
+ va_end()
|
||||||
|
+ va_start()
|
||||||
|
|
||||||
|
<stdio.h>
|
||||||
|
+ clearerr()
|
||||||
|
+ fclose()
|
||||||
|
- fdopen()
|
||||||
|
+ feof()
|
||||||
|
+ ferror()
|
||||||
|
+ fflush()
|
||||||
|
+ fgetc()
|
||||||
|
+ fgets()
|
||||||
|
- fileno()
|
||||||
|
- flockfile()
|
||||||
|
+ fopen()
|
||||||
|
+ fprintf()
|
||||||
|
+ fputc()
|
||||||
|
+ fputs()
|
||||||
|
+ fread()
|
||||||
|
+ freopen()
|
||||||
|
+ fscanf()
|
||||||
|
- ftrylockfile()
|
||||||
|
- funlockfile()
|
||||||
|
+ fwrite()
|
||||||
|
+ getc()
|
||||||
|
% getc_unlocked() ; thread safe in the default
|
||||||
|
+ getchar()
|
||||||
|
+ getchar_unlocked()
|
||||||
|
+ gets()
|
||||||
|
+ perror()
|
||||||
|
+ printf()
|
||||||
|
+ putc()
|
||||||
|
% putc_unlocked() ; thread safe in the default
|
||||||
|
+ putchar()
|
||||||
|
% putchar_unlocked() ; thread safe in the default
|
||||||
|
+ puts()
|
||||||
|
+ scanf()
|
||||||
|
+ setbuf()
|
||||||
|
+ setvbuf()
|
||||||
|
+ snprintf()
|
||||||
|
+ sprintf()
|
||||||
|
+ sscanf()
|
||||||
|
+ stderr
|
||||||
|
+ stdin
|
||||||
|
+ stdout
|
||||||
|
+ ungetc()
|
||||||
|
+ vfprintf()
|
||||||
|
+ vfscanf()
|
||||||
|
+ vprintf()
|
||||||
|
+ vscanf()
|
||||||
|
+ vsnprintf()
|
||||||
|
+ vsprintf()
|
||||||
|
+ vsscanf()
|
||||||
|
|
||||||
|
<stdlib.h>
|
||||||
|
+ abort()
|
||||||
|
+ abs()
|
||||||
|
+ atof()
|
||||||
|
+ atoi()
|
||||||
|
+ atol()
|
||||||
|
+ atoll()
|
||||||
|
+ bsearch()
|
||||||
|
+ calloc()
|
||||||
|
+ div()
|
||||||
|
+ free()
|
||||||
|
+ getenv()
|
||||||
|
+ labs()
|
||||||
|
+ ldiv()
|
||||||
|
+ llabs()
|
||||||
|
+ lldiv()
|
||||||
|
+ malloc()
|
||||||
|
+ qsort()
|
||||||
|
+ rand()
|
||||||
|
% rand_r() ; thread safe in the default
|
||||||
|
+ realloc()
|
||||||
|
- setenv() ;the 'env' should combined with non-volatile devices
|
||||||
|
+ srand()
|
||||||
|
+ strtod()
|
||||||
|
+ strtof()
|
||||||
|
+ strtol()
|
||||||
|
+ strtold()
|
||||||
|
+ strtoll()
|
||||||
|
+ strtoul()
|
||||||
|
+ strtoull()
|
||||||
|
- unsetenv() ;the 'env' should combined with non-volatile devices
|
||||||
|
|
||||||
|
<string.h>
|
||||||
|
+ memchr()
|
||||||
|
+ memcmp()
|
||||||
|
+ memcpy()
|
||||||
|
+ memmove()
|
||||||
|
+ memset()
|
||||||
|
+ strcat()
|
||||||
|
+ strchr()
|
||||||
|
+ strcmp()
|
||||||
|
+ strcoll()
|
||||||
|
+ strcpy()
|
||||||
|
+ strcspn()
|
||||||
|
+ strerror()
|
||||||
|
% strerror_r() ; thread safe in the default
|
||||||
|
+ strlen()
|
||||||
|
+ strncat()
|
||||||
|
+ strncmp()
|
||||||
|
+ strncpy()
|
||||||
|
+ strpbrk()
|
||||||
|
+ strrchr()
|
||||||
|
+ strspn()
|
||||||
|
+ strstr()
|
||||||
|
+ strtok()
|
||||||
|
% strtok_r() ; thread safe in the default
|
||||||
|
+ strxfrm()
|
||||||
|
|
||||||
|
<sys/mman.h>
|
||||||
|
- mlockall()
|
||||||
|
+ mmap()
|
||||||
|
- munlock()
|
||||||
|
+ munmap()
|
||||||
|
- shm_open()
|
||||||
|
- shm_unlink()
|
||||||
|
|
||||||
|
<sys/utsname.h>
|
||||||
|
+ uname()
|
||||||
|
|
||||||
|
<time.h> -> for gcc, keil, iar platform at the same time;
|
||||||
|
Suggest to choose <sys/time.h>
|
||||||
|
+ asctime()
|
||||||
|
+ asctime_r()
|
||||||
|
+ clock_getres()
|
||||||
|
+ clock_gettime()
|
||||||
|
+ clock_nanosleep()
|
||||||
|
+ clock_settime()
|
||||||
|
+ ctime()
|
||||||
|
+ ctime_r()
|
||||||
|
+ difftime()
|
||||||
|
+ gmtime()
|
||||||
|
+ gmtime_r()
|
||||||
|
+ localtime()
|
||||||
|
+ localtime_r()
|
||||||
|
+ mktime()
|
||||||
|
+ nanosleep()
|
||||||
|
+ strftime()
|
||||||
|
+ time()
|
||||||
|
+ timer_create()
|
||||||
|
+ timer_delete()
|
||||||
|
+ timer_getoverrun()
|
||||||
|
+ timer_gettime()
|
||||||
|
+ timer_settime()
|
||||||
|
% tzname ; you should better use 'tz_xxx' in the rt-thread.
|
||||||
|
% tzset() ; you should better use 'tz_xxx' in the rt-thread.
|
||||||
|
|
||||||
|
<unistd.h>
|
||||||
|
+ alarm()
|
||||||
|
+ close()
|
||||||
|
+ environ
|
||||||
|
% fdatasync() ;smaller ranther than <fsync>, in the rt-thread, it is universal
|
||||||
|
+ fsync()
|
||||||
|
+ pause()
|
||||||
|
+ read()
|
||||||
|
+ sysconf()
|
||||||
|
+ write()
|
||||||
|
- confstr()
|
||||||
|
|
||||||
|
|
@ -49,6 +49,11 @@ config RT_USING_POSIX_CLOCK
|
|||||||
select RT_USING_POSIX_DELAY
|
select RT_USING_POSIX_DELAY
|
||||||
default n
|
default n
|
||||||
|
|
||||||
|
config RT_USING_POSIX_TIMER
|
||||||
|
select RT_USING_TIMER_SOFT
|
||||||
|
bool "Enable posix time functions, timer_create()/timer_gettime()/timer_settime() etc"
|
||||||
|
default n
|
||||||
|
|
||||||
config RT_USING_PTHREADS
|
config RT_USING_PTHREADS
|
||||||
bool "Enable pthreads APIs"
|
bool "Enable pthreads APIs"
|
||||||
select RT_USING_POSIX_CLOCK
|
select RT_USING_POSIX_CLOCK
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#ifndef __DELAY_H__
|
#ifndef __DELAY_H__
|
||||||
#define __DELAY_H__
|
#define __DELAY_H__
|
||||||
|
|
||||||
|
unsigned int sleep(unsigned int seconds);
|
||||||
void msleep(unsigned int msecs);
|
void msleep(unsigned int msecs);
|
||||||
void ssleep(unsigned int seconds);
|
void ssleep(unsigned int seconds);
|
||||||
void mdelay(unsigned long msecs);
|
void mdelay(unsigned long msecs);
|
||||||
|
@ -185,6 +185,10 @@ int pthread_setschedprio(pthread_t thread, int prio);
|
|||||||
void pthread_exit (void *value_ptr);
|
void pthread_exit (void *value_ptr);
|
||||||
int pthread_once(pthread_once_t * once_control, void (*init_routine) (void));
|
int pthread_once(pthread_once_t * once_control, void (*init_routine) (void));
|
||||||
|
|
||||||
|
#ifdef RT_USING_SIGNALS
|
||||||
|
int pthread_sigmask(int how, const sigset_t *set, sigset_t *oset);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* pthread cleanup */
|
/* pthread cleanup */
|
||||||
void pthread_cleanup_pop(int execute);
|
void pthread_cleanup_pop(int execute);
|
||||||
void pthread_cleanup_push(void (*routine)(void*), void *arg);
|
void pthread_cleanup_push(void (*routine)(void*), void *arg);
|
||||||
|
@ -55,6 +55,35 @@ int sigprocmask (int how, const sigset_t *set, sigset_t *oset)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sigpending (sigset_t *set)
|
||||||
|
{
|
||||||
|
sigprocmask(SIG_SETMASK, RT_NULL, set);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sigsuspend (const sigset_t *set)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
sigset_t origin_set;
|
||||||
|
sigset_t suspend_set;
|
||||||
|
siginfo_t info; /* unless paremeter */
|
||||||
|
|
||||||
|
/* get the origin signal information */
|
||||||
|
sigpending(&origin_set);
|
||||||
|
|
||||||
|
/* set the new signal information */
|
||||||
|
sigprocmask(SIG_BLOCK, set, RT_NULL);
|
||||||
|
sigpending(&suspend_set);
|
||||||
|
|
||||||
|
ret = rt_signal_wait(&suspend_set, &info, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
|
/* restore the original sigprocmask */
|
||||||
|
sigprocmask(SIG_UNBLOCK, (sigset_t *)0xffffUL, RT_NULL);
|
||||||
|
sigprocmask(SIG_BLOCK, &origin_set, RT_NULL);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
|
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
|
||||||
{
|
{
|
||||||
rt_sighandler_t old = RT_NULL;
|
rt_sighandler_t old = RT_NULL;
|
||||||
@ -75,8 +104,7 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sigtimedwait(const sigset_t *set, siginfo_t *info,
|
int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout)
|
||||||
const struct timespec *timeout)
|
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int tick = RT_WAITING_FOREVER;
|
int tick = RT_WAITING_FOREVER;
|
||||||
@ -114,3 +142,11 @@ int raise(int sig)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
int sigqueue (pid_t pid, int signo, const union sigval value)
|
||||||
|
{
|
||||||
|
/* no support, signal queue */
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -487,6 +487,7 @@ struct rt_object_information
|
|||||||
#define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
|
#define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
|
||||||
#define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
|
#define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
|
||||||
#define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/
|
#define RT_TIMER_CTRL_GET_STATE 0x4 /**< get timer run state active or deactive*/
|
||||||
|
#define RT_TIMER_CTRL_GET_REMAIN_TIME 0x5 /**< get the remaining hang time */
|
||||||
|
|
||||||
#ifndef RT_TIMER_SKIP_LIST_LEVEL
|
#ifndef RT_TIMER_SKIP_LIST_LEVEL
|
||||||
#define RT_TIMER_SKIP_LIST_LEVEL 1
|
#define RT_TIMER_SKIP_LIST_LEVEL 1
|
||||||
|
@ -581,6 +581,8 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
|
|||||||
/*timer is stop*/
|
/*timer is stop*/
|
||||||
*(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED;
|
*(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED;
|
||||||
}
|
}
|
||||||
|
case RT_TIMER_CTRL_GET_REMAIN_TIME:
|
||||||
|
*(rt_tick_t *)arg = timer->timeout_tick;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user