60typedef struct __tmr tmr_id [];
78#define _TMR_INIT( _proc ) \
79 { _OBJ_INIT(), _HDR_INIT(), _proc, NULL, 0, 0, 0 }
89#define OS_TMR( tmr, proc ) \
90 tmr_t tmr[] = { _TMR_INIT( proc ) }
93#define static_TMR( tmr, proc ) \
94 static tmr_t tmr[] = { _TMR_INIT( proc ) }
104#define OS_TMR_DEF( tmr ) \
105 static void tmr##__fun( void ); \
106 OS_TMR( tmr, tmr##__fun ); \
107 static void tmr##__fun( void )
110#define static_TMR_DEF( tmr ) \
111 static void tmr##__fun( void ); \
112 static_TMR( tmr, tmr##__fun ); \
113 static void tmr##__fun( void )
132#define OS_TMR_START( tmr, delay, period ) \
133 static void tmr##__fun( void ); \
134 OS_TMR( tmr, tmr##__fun ); \
135 __CONSTRUCTOR static void tmr##__run( void ) { tmr_start(tmr, delay, period); } \
136 static void tmr##__fun( void )
141#define static_TMR_START( tmr, delay, period ) \
142 static void tmr##__fun( void ); \
143 static_TMR( tmr, tmr##__fun ); \
144 __CONSTRUCTOR static void tmr##__run( void ) { tmr_start(tmr, delay, period); } \
145 static void tmr##__fun( void )
160#define OS_TMR_UNTIL( tmr, time ) \
161 static void tmr##__fun( void ); \
162 OS_TMR( tmr, tmr##__fun ); \
163 __CONSTRUCTOR static void tmr##__run( void ) { tmr_startUntil(tmr, time); } \
164 static void tmr##__fun( void )
169#define static_TMR_UNTIL( tmr, time ) \
170 static void tmr##__fun( void ); \
171 static_TMR( tmr, tmr##__fun ); \
172 __CONSTRUCTOR static void tmr##__run( void ) { tmr_startUntil(tmr, time); } \
173 static void tmr##__fun( void )
188#define TMR_INIT( proc ) \
204#define TMR_CREATE( proc ) \
205 { TMR_INIT ( proc ) }
224tmr_t *
tmr_this(
void ) {
return (tmr_t *) System.cur; }
266void tmr_start( tmr_t *tmr, cnt_t delay, cnt_t period );
467#if defined(__cplusplus)
484struct baseTimer :
public __tmr
486 baseTimer(): __tmr _TMR_INIT(nullptr) {}
487#if __cplusplus >= 201402L
489 baseTimer( F&& _proc ): __tmr _TMR_INIT(fun_), fun{_proc} {}
491 baseTimer(
fun_t *_proc ): __tmr _TMR_INIT(_proc) {}
506#if __cplusplus >= 201402L
509 template<
typename T,
class F>
510 void startFrom (
const T& _delay,
const T& _period, F&& _proc ) { fun = Fun_t(_proc);
517 int take () {
return tmr_take (
this); }
526 int wait () {
return tmr_wait (
this); }
528 operator bool ()
const {
return __tmr::hdr.id != ID_STOPPED; }
530 template<
class T = baseTimer>
static
531 T * current () {
return static_cast<T *
>(
tmr_this()); }
533#if __cplusplus >= 201402L
537 auto tmr = current();
553#if __cplusplus >= 201402L
555 void flip ( std::nullptr_t ) {
tmr_flip (
nullptr); }
556 template<
class F>
static
557 void flip ( F&& _proc ) { current()->fun = Fun_t(_proc);
559 template<
typename F,
typename... A>
static
560 void flip ( F&& _proc, A&&... _args ) { flip(std::bind(std::forward<F>(_proc), std::forward<A>(_args)...)); }
565 template<
typename T>
static
570using thisTimer = baseTimer::Current;
571using this_timer = baseTimer::Current;
581struct Timer :
public baseTimer
584 Timer(): baseTimer{} {}
587 Timer( F&& _proc ): baseTimer{_proc} {}
588#if __cplusplus >= 201402L
590 Timer( std::nullptr_t ): baseTimer{} {}
592 template<
typename F,
typename... A>
593 Timer( F&& _proc, A&&... _args ): baseTimer{std::bind(std::forward<F>(_proc), std::forward<A>(_args)...)} {}
596 ~Timer() { assert(__tmr::hdr.
id == ID_STOPPED); }
599 Timer(
Timer&& _src ): baseTimer(static_cast<baseTimer&&>(_src))
601 assert(_src.hdr.id == ID_STOPPED && _src.obj.queue ==
nullptr);
610 template<
class S,
typename... A>
611 Timer( Starter, S&& _start, A&&... _args ):
Timer{static_cast<A&&>(_args)...} { _start(*
this); }
632 template<
class F>
static
638#if __cplusplus >= 201402L
647 template<
typename F,
typename... A>
static
650 return Make(std::bind(std::forward<F>(_proc), std::forward<A>(_args)...));
676 template<
typename T>
static
677 Timer Start(
const T& _delay,
const T& _period )
679 return { Starter{}, [&](
Timer& _tmr ){ _tmr.start(_delay, _period); } };
683 template<
typename T,
class F>
static
684 Timer Start(
const T& _delay,
const T& _period, F&& _proc )
686 return { Starter{}, [&](
Timer& _tmr ){ _tmr.start(_delay, _period); }, _proc };
689#if __cplusplus >= 201402L
691 template<
typename T>
static
692 Timer Start(
const T& _delay,
const T& _period, std::nullptr_t )
694 return Start(_delay, _period);
698 template<
typename T,
typename F,
typename... A>
static
699 Timer Start(
const T& _delay,
const T& _period, F&& _proc, A&&... _args )
701 return Start(_delay, _period, std::bind(std::forward<F>(_proc), std::forward<A>(_args)...));
722 template<
typename T>
static
725 return { Starter{}, [&](
Timer& _tmr ){ _tmr.startFor(_delay); } };
729 template<
typename T,
class F>
static
732 return { Starter{}, [&](
Timer& _tmr ){ _tmr.startFor(_delay); }, _proc };
735#if __cplusplus >= 201402L
737 template<
typename T>
static
744 template<
typename T,
typename F,
typename... A>
static
747 return StartFor(_delay, std::bind(std::forward<F>(_proc), std::forward<A>(_args)...));
770 template<
typename T>
static
773 return { Starter{}, [&](
Timer& _tmr ){ _tmr.startPeriodic(_period); } };
777 template<
typename T,
class F>
static
780 return { Starter{}, [&](
Timer& _tmr ){ _tmr.startPeriodic(_period); }, _proc };
783#if __cplusplus >= 201402L
785 template<
typename T>
static
792 template<
typename T,
typename F,
typename... A>
static
795 return StartPeriodic(_period, std::bind(std::forward<F>(_proc), std::forward<A>(_args)...));
814 template<
typename T>
static
817 return { Starter{}, [&](
Timer& _tmr ){ _tmr.startUntil(_time); } };
821 template<
typename T,
class F>
static
824 return { Starter{}, [&](
Timer& _tmr ){ _tmr.startUntil(_time); }, _proc };
827#if __cplusplus >= 201402L
829 template<
typename T>
static
836 template<
typename T,
typename F,
typename... A>
static
839 return StartUntil(_time, std::bind(std::forward<F>(_proc), std::forward<A>(_args)...));
#define INFINITE
infinite waiting
Definition osbase.h:250
void fun_t(void)
timer/task procedure
Definition osbase.h:142
int tmr_wait(tmr_t *tmr)
wait indefinitely until the timer finishes countdown
Definition ostimer.h:433
void tmr_startPeriodic(tmr_t *tmr, cnt_t period)
start/restart periodic timer for given duration of time
Definition ostimer.h:295
void tmr_reset(tmr_t *tmr)
reset the timer object and wake up all waiting tasks with 'E_STOPPED' event value
void tmr_stop(tmr_t *tmr)
stop timer
Definition ostimer.h:348
int tmr_tryWait(tmr_t *tmr)
alias of tmr_take()
Definition ostimer.h:368
int tmr_waitUntil(tmr_t *tmr, cnt_t time)
wait until given timepoint until the timer finishes countdown
void tmr_startUntil(tmr_t *tmr, cnt_t time)
start/restart one-shot timer until given timepoint
void tmr_init(tmr_t *tmr, fun_t *proc)
initialize a timer object
tmr_t * tmr_this(void)
return current timer object
Definition ostimer.h:223
int tmr_take(tmr_t *tmr)
check if the timer finishes countdown
void tmr_delay(cnt_t delay)
change delay time for current timer
Definition ostimer.h:458
void tmr_kill(tmr_t *tmr)
alias of tmr_reset()
Definition ostimer.h:247
void tmr_startNext(tmr_t *tmr, cnt_t delay)
restart the timer for given duration of time from the end of the previous countdown
void tmr_flip(fun_t *proc)
change callback procedure for current periodic timer (available in next period)
Definition ostimer.h:445
int tmr_waitFor(tmr_t *tmr, cnt_t delay)
wait for given duration of time until the timer finishes countdown
int tmr_expired(tmr_t *tmr)
alias of tmr_take()
Definition ostimer.h:364
void tmr_startFor(tmr_t *tmr, cnt_t delay)
start/restart one-shot timer for given duration of time
Definition ostimer.h:279
void tmr_start(tmr_t *tmr, cnt_t delay, cnt_t period)
start/restart periodic timer for given duration of time
void tmr_startFrom(tmr_t *tmr, cnt_t delay, cnt_t period, fun_t *proc)
start/restart periodic timer for given duration of time
int tmr_waitNext(tmr_t *tmr, cnt_t delay)
wait for given duration of time from the end of the previous countdown
static constexpr rep until(const std::chrono::time_point< Clock, _Duration > &_time)
time point in ticks, rounded up to whole ticks (only a time point of this clock)
Definition osclock.h:109
static constexpr rep count(const std::chrono::duration< _Rep, _Period > &_delay)
delay in ticks, rounded up to whole ticks; negative delay: IMMEDIATE, delay out of range: INFINITE
Definition osclock.h:102
create and initialize a timer object
Definition ostimer.h:581
Timer()
constructor, see the constructor parameters of the class
Definition ostimer.h:583
static Timer StartFor(const T &_delay)
create and initialize static timer object and start one-shot timer for given duration of time
Definition ostimer.h:722
static Timer Start(const T &_delay, const T &_period)
create and initialize static timer object and start periodic timer for given duration of time
Definition ostimer.h:676
static Timer StartUntil(const T &_time)
create and initialize static timer object and start one-shot timer until given timepoint
Definition ostimer.h:814
static Timer StartPeriodic(const T &_period)
create and initialize static timer object and start periodic timer for given duration of time
Definition ostimer.h:770
static Timer Make()
create and initialize static timer object
Definition ostimer.h:625