|
SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
POSIX time extensions for STK: clock_gettime(), clock_getres(), nanosleep(), clock_nanosleep(), usleep(), sleep(), timespec_get() and POSIX timers (timer_create() and friends). Implemented by stk_c_pthread.cpp (no dependency on the STK C API). More...
#include <stdint.h>#include <stddef.h>#include <sys/types.h>Go to the source code of this file.
Classes | |
| union | sigval |
| struct | sigevent |
| struct | itimerspec |
Macros | |
| #define | _SYS__PTHREADTYPES_H_ |
| #define | STK_C_PTHREADTYPES_GUARD |
| #define | CLOCK_REALTIME (0) |
| #define | CLOCK_MONOTONIC (1) |
| #define | TIMER_ABSTIME (1) |
| #define | TIME_UTC (1) |
| #define | STK_C_DEFINE_SIGEVENT (1) |
| 1: this header defines union sigval / struct sigevent / SIGEV_* itself (toolchains which have no definition of their own). 0 (default for newlib and glibc, detected automatically): they come from the toolchain's <signal.h>, include the layer's signal.h to use them with timer_create(). | |
| #define | SIGEV_NONE (0) |
| #define | SIGEV_SIGNAL (1) |
| #define | SIGEV_THREAD (2) |
| #define | STK_C_TIMERS_MAX (8U) |
| Number of POSIX timers which can exist at the same time. | |
Typedefs | |
| typedef void * | timer_t |
Functions | |
| int | clock_gettime (clockid_t clk_id, struct timespec *ts) |
| Get the current time of a clock. | |
| int | clock_getres (clockid_t clk_id, struct timespec *res) |
| Get the resolution (one kernel tick) of a clock. | |
| int | timespec_get (struct timespec *ts, int base) |
| C11 timespec_get(): base must be TIME_UTC (reports the same STK timeline). | |
| int | nanosleep (const struct timespec *req, struct timespec *rem) |
| Suspend the calling task for a relative time (rounded UP to whole ticks). Cancellation point. | |
| int | clock_nanosleep (clockid_t clk_id, int flags, const struct timespec *req, struct timespec *rem) |
| Suspend for a relative time or until an absolute time (flags = TIMER_ABSTIME). Cancellation point. | |
| int | usleep (useconds_t usec) |
| Suspend for usec microseconds. Cancellation point. | |
| unsigned int | sleep (unsigned int seconds) |
| Suspend for seconds seconds. Cancellation point. | |
| void | stk_posix_set_wall_time (int64_t unix_seconds) |
| Set the current wall time used by time() and gettimeofday() (see sys/time.h). | |
| void | stk_posix_timer_bind_host (void *timer_host) |
| Provide the timer host which runs POSIX timers. | |
| int | timer_create (clockid_t clk_id, struct sigevent *sevp, timer_t *timerid) |
| Create a timer. | |
| int | timer_delete (timer_t timerid) |
| Delete a timer (waits until a running notification has returned). | |
| int | timer_settime (timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec *old_value) |
| Arm (it_value != 0) or disarm (it_value == 0) a timer. | |
| int | timer_gettime (timer_t timerid, struct itimerspec *curr_value) |
| Get the time until the next expiration and the period. | |
| int | timer_getoverrun (timer_t timerid) |
| Get the overrun count. STK does not track overruns. | |
POSIX time extensions for STK: clock_gettime(), clock_getres(), nanosleep(), clock_nanosleep(), usleep(), sleep(), timespec_get() and POSIX timers (timer_create() and friends). Implemented by stk_c_pthread.cpp (no dependency on the STK C API).
This header EXTENDS the toolchain's <time.h>: it first includes the standard header (via #include_next on GCC/Clang, or the header named by STK_C_SYSTEM_TIME_H on other compilers) and then adds the declarations above, so it can be placed ahead of the toolchain on the include path.
Clocks: STK has a single time source, the kernel tick counter. CLOCK_MONOTONIC and CLOCK_REALTIME both report the time since the kernel was started (there is no calendar time), with the resolution of a kernel tick. All absolute deadlines of the pthread/semaphore/mqueue timed calls use the same timeline.
Sleeping functions are cancellation points of pthread_cancel() and can be interrupted early (EINTR) by IKernelService::SleepCancel(); timers are provided on top of an application-owned stk::time::TimerHost, see stk_posix_timer_bind_host().
Definition in file time.h.
| #define SIGEV_NONE (0) |
Definition at line 185 of file time.h.
Referenced by timer_create().
| #define SIGEV_THREAD (2) |
Definition at line 187 of file time.h.
Referenced by timer_create().
| #define STK_C_DEFINE_SIGEVENT (1) |
1: this header defines union sigval / struct sigevent / SIGEV_* itself (toolchains which have no definition of their own). 0 (default for newlib and glibc, detected automatically): they come from the toolchain's <signal.h>, include the layer's signal.h to use them with timer_create().
| #define STK_C_TIMERS_MAX (8U) |
Number of POSIX timers which can exist at the same time.
Definition at line 207 of file time.h.
Referenced by sysconf(), timer_create(), and TimerOf().
| #define TIME_UTC (1) |
Definition at line 98 of file time.h.
Referenced by timespec_get().
| #define TIMER_ABSTIME (1) |
Definition at line 95 of file time.h.
Referenced by clock_nanosleep(), and timer_settime().
| int clock_getres | ( | clockid_t | clk_id, |
| struct timespec * | res ) |
Get the resolution (one kernel tick) of a clock.
Definition at line 3145 of file stk_c_pthread.cpp.
References stk::pthread::IsSupportedClock(), and stk::pthread::TicksToTimespec().
| int clock_gettime | ( | clockid_t | clk_id, |
| struct timespec * | ts ) |
Get the current time of a clock.
| [in] | clk_id | CLOCK_REALTIME or CLOCK_MONOTONIC (the same STK kernel timeline). |
Definition at line 3128 of file stk_c_pthread.cpp.
References stk::GetTicks(), stk::pthread::IsSupportedClock(), and stk::pthread::TicksToTimespec().
Referenced by timespec_get().
| int clock_nanosleep | ( | clockid_t | clk_id, |
| int | flags, | ||
| const struct timespec * | req, | ||
| struct timespec * | rem ) |
Suspend for a relative time or until an absolute time (flags = TIMER_ABSTIME). Cancellation point.
Definition at line 3206 of file stk_c_pthread.cpp.
References stk::pthread::IsSupportedClock(), stk::pthread::IsValidTimespec(), nanosleep(), stk::NO_WAIT, stk::pthread::SleepTicksInterruptible(), stk::pthread::TestCancelPoint(), TIMER_ABSTIME, and stk::pthread::TimespecToRelativeTimeout().
| int nanosleep | ( | const struct timespec * | req, |
| struct timespec * | rem ) |
Suspend the calling task for a relative time (rounded UP to whole ticks). Cancellation point.
| [out] | rem | Receives the remaining time if interrupted (may be NULL). |
Definition at line 3171 of file stk_c_pthread.cpp.
References stk::pthread::IsValidTimespec(), stk::pthread::RelativeTicksCeil(), stk::pthread::SleepTicksInterruptible(), stk::pthread::TestCancelPoint(), and stk::pthread::TicksToTimespec().
Referenced by clock_nanosleep(), sleep(), thrd_sleep(), and usleep().
| unsigned int sleep | ( | unsigned int | seconds | ) |
Suspend for seconds seconds. Cancellation point.
Definition at line 3243 of file stk_c_pthread.cpp.
References nanosleep().
Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedOut(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::InitTraps(), and CtrlTask< _AccessMode >::Run().
| void stk_posix_set_wall_time | ( | int64_t | unix_seconds | ) |
Set the current wall time used by time() and gettimeofday() (see sys/time.h).
| [in] | unix_seconds | Seconds since 1970-01-01 00:00:00 UTC at the moment of the call. |
Definition at line 3360 of file stk_c_pthread.cpp.
References SetWallTimeUs().
| void stk_posix_timer_bind_host | ( | void * | timer_host | ) |
Provide the timer host which runs POSIX timers.
| [in] | timer_host | Pointer to an initialized stk::time::TimerHost (task mode), or NULL to unbind. The host is owned by the application (it decides weights, stacks and thread count); without a bound host timer_create() fails with EAGAIN. |
Definition at line 3594 of file stk_c_pthread.cpp.
References s_TimerHost.
Create a timer.
| [in] | sevp | SIGEV_THREAD (the function is called from a timer handler task) or SIGEV_NONE (poll with timer_gettime()). NULL means SIGEV_NONE (there are no signals). SIGEV_SIGNAL gives ENOTSUP. |
Definition at line 3599 of file stk_c_pthread.cpp.
References stk::pthread::IsSupportedClock(), PosixTimer::m_notify, PosixTimer::m_used, PosixTimer::m_value, s_PosixTimers, s_TimerHost, SIGEV_NONE, sigevent::sigev_notify, sigevent::sigev_notify_function, SIGEV_THREAD, sigevent::sigev_value, and STK_C_TIMERS_MAX.
| int timer_delete | ( | timer_t | timerid | ) |
Delete a timer (waits until a running notification has returned).
Definition at line 3658 of file stk_c_pthread.cpp.
References PosixTimer::m_notify, PosixTimer::m_used, s_TimerHost, and TimerOf().
| int timer_getoverrun | ( | timer_t | timerid | ) |
Get the overrun count. STK does not track overruns.
Definition at line 3763 of file stk_c_pthread.cpp.
References TimerOf().
| int timer_gettime | ( | timer_t | timerid, |
| struct itimerspec * | curr_value ) |
Get the time until the next expiration and the period.
Definition at line 3685 of file stk_c_pthread.cpp.
References stk::time::TimerHost::TimerInfo::active, itimerspec::it_interval, itimerspec::it_value, stk::time::TimerHost::TimerInfo::period, stk::time::TimerHost::TimerInfo::remaining, s_TimerHost, stk::pthread::TicksToTimespec(), TimerOf(), and TimerResultToErrno().
Referenced by timer_settime().
| int timer_settime | ( | timer_t | timerid, |
| int | flags, | ||
| const struct itimerspec * | new_value, | ||
| struct itimerspec * | old_value ) |
Arm (it_value != 0) or disarm (it_value == 0) a timer.
| [in] | flags | 0 (relative) or TIMER_ABSTIME. Times are rounded up to whole ticks. |
| [out] | old_value | Previous setting (may be NULL). |
Definition at line 3711 of file stk_c_pthread.cpp.
References ClampTicks32(), stk::pthread::IsValidTimespec(), itimerspec::it_interval, itimerspec::it_value, stk::pthread::RelativeTicksCeil(), s_TimerHost, TIMER_ABSTIME, timer_gettime(), TimerOf(), TimerResultToErrno(), and stk::pthread::TimespecToRelativeTimeout().
| int timespec_get | ( | struct timespec * | ts, |
| int | base ) |
C11 timespec_get(): base must be TIME_UTC (reports the same STK timeline).
Definition at line 3166 of file stk_c_pthread.cpp.
References clock_gettime(), CLOCK_REALTIME, and TIME_UTC.
| int usleep | ( | useconds_t | usec | ) |
Suspend for usec microseconds. Cancellation point.
Definition at line 3233 of file stk_c_pthread.cpp.
References nanosleep().