38#ifndef _RTEMS_SCORE_WATCHDOGIMPL_H
39#define _RTEMS_SCORE_WATCHDOGIMPL_H
49#include <sys/timespec.h>
96 #define WATCHDOG_INITIALIZER( routine ) \
98 { { { NULL, NULL, NULL, WATCHDOG_INACTIVE } } }, \
99 &_Per_CPU_Information[ 0 ].per_cpu, \
104 #define WATCHDOG_INITIALIZER( routine ) \
106 { { { NULL, NULL, NULL, WATCHDOG_INACTIVE } } }, \
117static inline void _Watchdog_Header_initialize(
121 _RBTree_Initialize_empty( &header->
Watchdogs );
122 header->
first = NULL;
144static inline void _Watchdog_Header_destroy(
179static inline void _Watchdog_Set_state(
184 RTEMS_RB_COLOR( &the_watchdog->
Node.
RBTree, Node ) = state;
198#if defined(RTEMS_SMP)
199 return the_watchdog->cpu;
201 return _Per_CPU_Get_by_index( 0 );
211static inline void _Watchdog_Set_CPU(
216#if defined(RTEMS_SMP)
217 the_watchdog->cpu = cpu;
231static inline void _Watchdog_Preinitialize(
236 _Watchdog_Set_CPU( the_watchdog, cpu );
239#if defined(RTEMS_DEBUG)
253static inline void _Watchdog_Initialize(
259 the_watchdog->
routine = routine;
277#
if defined(RTEMS_SMP)
278 ISR_lock_Control *lock,
283#if defined(RTEMS_SMP)
284 #define _Watchdog_Tickle( header, first, now, lock, lock_context ) \
285 _Watchdog_Do_tickle( header, first, now, lock, lock_context )
287 #define _Watchdog_Tickle( header, first, now, lock, lock_context ) \
288 _Watchdog_Do_tickle( header, first, now, lock_context )
335static inline uint64_t _Watchdog_Cancel(
344 expire = the_watchdog->
expire;
346 if ( now < expire ) {
347 remaining = expire - now;
365static inline bool _Watchdog_Is_scheduled(
384static inline void _Watchdog_Next_first(
410 if ( right != NULL ) {
411 _Assert( RTEMS_RB_COLOR( right, Node ) == RTEMS_RB_RED );
412 _Assert( _RBTree_Left( right ) == NULL );
413 _Assert( _RBTree_Right( right ) == NULL );
414 header->
first = right;
423#define WATCHDOG_MAXIMUM_TICKS UINT64_MAX
425#define WATCHDOG_NANOSECONDS_PER_SECOND 1000000000
435#define WATCHDOG_BITS_FOR_1E9_NANOSECONDS 30
443#define WATCHDOG_MAX_SECONDS 0x3ffffffff
453static inline bool _Watchdog_Is_valid_timespec(
454 const struct timespec *ts
458 && (
unsigned long) ts->tv_nsec < WATCHDOG_NANOSECONDS_PER_SECOND;
469static inline bool _Watchdog_Is_valid_interval_timespec(
470 const struct timespec *ts
473 return _Watchdog_Is_valid_timespec( ts ) && ts->tv_sec >= 0;
486static inline const struct timespec * _Watchdog_Future_timespec(
487 struct timespec *now,
488 const struct timespec *delta
493 if ( !_Watchdog_Is_valid_interval_timespec( delta ) ) {
497 sec = (uint64_t) now->tv_sec;
498 sec += (uint64_t) delta->tv_sec;
499 now->tv_nsec += delta->tv_nsec;
502 if ( now->tv_nsec >= WATCHDOG_NANOSECONDS_PER_SECOND ) {
503 now->tv_nsec -= WATCHDOG_NANOSECONDS_PER_SECOND;
507 if ( sec <= INT64_MAX ) {
510 now->tv_sec = INT64_MAX;
524static inline bool _Watchdog_Is_far_future_timespec(
525 const struct timespec *ts
538static inline uint64_t _Watchdog_Ticks_from_seconds(
542 uint64_t ticks = seconds;
556static inline uint64_t _Watchdog_Ticks_from_timespec(
557 const struct timespec *ts
562 _Assert( _Watchdog_Is_valid_timespec( ts ) );
564 _Assert( !_Watchdog_Is_far_future_timespec( ts ) );
566 ticks = (uint64_t) ts->tv_sec;
568 ticks |= (uint32_t) ts->tv_nsec;
580static inline void _Watchdog_Ticks_to_timespec(
596static inline uint64_t _Watchdog_Ticks_from_sbintime( int64_t sbt )
600 ticks |= ( (uint64_t) 1000000000 * (uint32_t) sbt ) >> 32;
611static inline void _Watchdog_Per_CPU_acquire_critical(
625static inline void _Watchdog_Per_CPU_release_critical(
643static inline uint64_t _Watchdog_Per_CPU_insert_ticks(
655 _Watchdog_Set_CPU( the_watchdog, cpu );
657 _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context );
660 _Watchdog_Per_CPU_release_critical( cpu, &lock_context );
675static inline uint64_t _Watchdog_Per_CPU_insert(
684 _Watchdog_Set_CPU( the_watchdog, cpu );
686 _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context );
688 _Watchdog_Per_CPU_release_critical( cpu, &lock_context );
699static inline void _Watchdog_Per_CPU_remove(
707 _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context );
712 _Watchdog_Per_CPU_release_critical( cpu, &lock_context );
720static inline void _Watchdog_Per_CPU_remove_ticks(
726 cpu = _Watchdog_Get_CPU( the_watchdog );
727 _Watchdog_Per_CPU_remove(
This header file provides the interfaces of the Assert Handler.
This header file provides interfaces of the Watchdog Handler which are used by the implementation and...
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG and static analysis runs.
Definition: assert.h:96
#define _ISR_lock_Release(_lock, _context)
Releases an ISR lock inside an ISR disabled section.
Definition: isrlock.h:282
#define _ISR_lock_Acquire(_lock, _context)
Acquires an ISR lock inside an ISR disabled section.
Definition: isrlock.h:259
@ PER_CPU_WATCHDOG_TICKS
Index for tick clock per-CPU watchdog header.
Definition: percpu.h:353
Watchdog_State
Watchdog states.
Definition: watchdogimpl.h:64
#define WATCHDOG_BITS_FOR_1E9_NANOSECONDS
The bits necessary to store 1000000000 (= WATCHDOG_NANOSECONDS_PER_SECOND) nanoseconds.
Definition: watchdogimpl.h:435
void _Watchdog_Insert(Watchdog_Header *header, Watchdog_Control *the_watchdog, uint64_t expire)
Inserts a watchdog into the set of scheduled watchdogs according to the specified expiration time.
Definition: watchdoginsert.c:43
void _Watchdog_Remove(Watchdog_Header *header, Watchdog_Control *the_watchdog)
In the case the watchdog is scheduled, then it is removed from the set of scheduled watchdogs.
Definition: watchdogremove.c:43
void _Watchdog_Tick(struct Per_CPU_Control *cpu)
Performs a watchdog tick.
Definition: watchdogtick.c:76
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition: watchdogticks.h:59
#define WATCHDOG_MAX_SECONDS
The maximum number of seconds representable in the nanoseconds watchdog format.
Definition: watchdogimpl.h:443
void _Watchdog_Do_tickle(Watchdog_Header *header, Watchdog_Control *first, uint64_t now, ISR_lock_Context *lock_context)
Calls the routine of each not expired watchdog control node.
Definition: watchdogtick.c:46
Watchdog_Service_routine(* Watchdog_Service_routine_entry)(Watchdog_Control *)
Pointer to a watchdog service routine.
Definition: watchdog.h:85
@ WATCHDOG_SCHEDULED_BLACK
The watchdog is scheduled and a black node in the red-black tree.
Definition: watchdogimpl.h:68
@ WATCHDOG_INACTIVE
The watchdog is inactive.
Definition: watchdogimpl.h:78
@ WATCHDOG_PENDING
The watchdog is on a chain of pending watchdogs.
Definition: watchdogimpl.h:85
@ WATCHDOG_SCHEDULED_RED
The watchdog is scheduled and a red node in the red-black tree.
Definition: watchdogimpl.h:73
This header file provides the interfaces of the ISR Locks.
This header file provides interfaces of the Red-Black Tree Handler which are only used by the impleme...
This header file provides the interfaces of the Per-CPU Information.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:94
Per CPU Core Structure.
Definition: percpu.h:384
Watchdog_Header Header[PER_CPU_WATCHDOG_COUNT]
Header for watchdogs.
Definition: percpu.h:513
uint64_t ticks
Watchdog ticks on this processor used for monotonic clock watchdogs.
Definition: percpu.h:506
struct Per_CPU_Control::@4403 Watchdog
Watchdog state for this processor.
Red-black tree node.
Definition: rbtree.h:73
The control block used to manage each watchdog timer.
Definition: watchdog.h:109
RBTree_Node RBTree
this field is a red-black tree node structure and allows this to be placed on a red-black tree used t...
Definition: watchdog.h:118
uint64_t expire
This field is the expiration time point.
Definition: watchdog.h:136
Watchdog_Service_routine_entry routine
This field is the function to invoke.
Definition: watchdog.h:133
union Watchdog_Control::@4413 Node
Nodes for the watchdog.
This header file provides the interfaces of the Watchdog Handler related to watchdog ticks which are ...