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;
202 return _Per_CPU_Get_by_index( 0 );
212static inline void _Watchdog_Set_CPU(
217#if defined(RTEMS_SMP)
218 the_watchdog->cpu = cpu;
233static inline void _Watchdog_Preinitialize(
238 _Watchdog_Set_CPU( the_watchdog, cpu );
241#if defined(RTEMS_DEBUG)
255static inline void _Watchdog_Initialize(
261 the_watchdog->
routine = routine;
279#
if defined(RTEMS_SMP)
280 ISR_lock_Control *lock,
285#if defined(RTEMS_SMP)
286 #define _Watchdog_Tickle( header, first, now, lock, lock_context ) \
287 _Watchdog_Do_tickle( header, first, now, lock, lock_context )
289 #define _Watchdog_Tickle( header, first, now, lock, lock_context ) \
290 _Watchdog_Do_tickle( header, first, now, lock_context )
337static inline uint64_t _Watchdog_Cancel(
346 expire = the_watchdog->
expire;
348 if ( now < expire ) {
349 remaining = expire - now;
367static inline bool _Watchdog_Is_scheduled(
386static inline void _Watchdog_Next_first(
412 if ( right != NULL ) {
413 _Assert( RTEMS_RB_COLOR( right, Node ) == RTEMS_RB_RED );
414 _Assert( _RBTree_Left( right ) == NULL );
415 _Assert( _RBTree_Right( right ) == NULL );
416 header->
first = right;
425#define WATCHDOG_MAXIMUM_TICKS UINT64_MAX
427#define WATCHDOG_NANOSECONDS_PER_SECOND 1000000000
437#define WATCHDOG_BITS_FOR_1E9_NANOSECONDS 30
445#define WATCHDOG_MAX_SECONDS 0x3ffffffff
455static inline bool _Watchdog_Is_valid_timespec(
456 const struct timespec *ts
460 && (
unsigned long) ts->tv_nsec < WATCHDOG_NANOSECONDS_PER_SECOND;
471static inline bool _Watchdog_Is_valid_interval_timespec(
472 const struct timespec *ts
475 return _Watchdog_Is_valid_timespec( ts ) && ts->tv_sec >= 0;
488static inline const struct timespec * _Watchdog_Future_timespec(
489 struct timespec *now,
490 const struct timespec *delta
495 if ( !_Watchdog_Is_valid_interval_timespec( delta ) ) {
499 sec = (uint64_t) now->tv_sec;
500 sec += (uint64_t) delta->tv_sec;
501 now->tv_nsec += delta->tv_nsec;
504 if ( now->tv_nsec >= WATCHDOG_NANOSECONDS_PER_SECOND ) {
505 now->tv_nsec -= WATCHDOG_NANOSECONDS_PER_SECOND;
509 if ( sec <= INT64_MAX ) {
512 now->tv_sec = INT64_MAX;
526static inline bool _Watchdog_Is_far_future_timespec(
527 const struct timespec *ts
540static inline uint64_t _Watchdog_Ticks_from_seconds(
544 uint64_t ticks = seconds;
558static inline uint64_t _Watchdog_Ticks_from_timespec(
559 const struct timespec *ts
564 _Assert( _Watchdog_Is_valid_timespec( ts ) );
566 _Assert( !_Watchdog_Is_far_future_timespec( ts ) );
568 ticks = (uint64_t) ts->tv_sec;
570 ticks |= (uint32_t) ts->tv_nsec;
582static inline void _Watchdog_Ticks_to_timespec(
598static inline uint64_t _Watchdog_Ticks_from_sbintime( int64_t sbt )
602 ticks |= ( (uint64_t) 1000000000 * (uint32_t) sbt ) >> 32;
613static inline void _Watchdog_Per_CPU_acquire_critical(
630static inline void _Watchdog_Per_CPU_release_critical(
651static inline uint64_t _Watchdog_Per_CPU_insert_ticks(
663 _Watchdog_Set_CPU( the_watchdog, cpu );
665 _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context );
668 _Watchdog_Per_CPU_release_critical( cpu, &lock_context );
683static inline uint64_t _Watchdog_Per_CPU_insert(
692 _Watchdog_Set_CPU( the_watchdog, cpu );
694 _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context );
696 _Watchdog_Per_CPU_release_critical( cpu, &lock_context );
707static inline void _Watchdog_Per_CPU_remove(
715 _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context );
720 _Watchdog_Per_CPU_release_critical( cpu, &lock_context );
728static inline void _Watchdog_Per_CPU_remove_ticks(
734 cpu = _Watchdog_Get_CPU( the_watchdog );
735 _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:437
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:445
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
struct Per_CPU_Control::@4363 Watchdog
Watchdog state for this processor.
uint64_t ticks
Watchdog ticks on this processor used for monotonic clock watchdogs.
Definition: percpu.h:506
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
union Watchdog_Control::@4373 Node
Nodes for the watchdog.
Watchdog_Service_routine_entry routine
This field is the function to invoke.
Definition: watchdog.h:133
This header file provides the interfaces of the Watchdog Handler related to watchdog ticks which are ...