RTEMS
Files | Classes | Macros | Typedefs | Enumerations | Functions | Variables
Watchdog Handler

Watchdog Handler. More...

Files

file  watchdog.h
 Constants and Structures Associated with Watchdog Timers.
 
file  watchdogimpl.h
 Inlined Routines in the Watchdog Handler.
 
file  watchdogticks.h
 Constants for the watchdog ticks.
 
file  watchdoginsert.c
 Watchdog Insert.
 
file  watchdogremove.c
 Remove Watchdog.
 
file  watchdogtickssinceboot.c
 Watchdog Ticks Since Boot.
 

Classes

struct  Watchdog_Header
 The watchdog header to manage scheduled watchdogs. More...
 
struct  Watchdog_Control
 The control block used to manage each watchdog timer. More...
 

Macros

#define WATCHDOG_INITIALIZER(routine)
 Watchdog initializer for static initialization. More...
 
#define _Watchdog_Tickle(header, first, now, lock, lock_context)   _Watchdog_Do_tickle( header, first, now, lock, lock_context )
 
#define WATCHDOG_MAXIMUM_TICKS   UINT64_MAX
 The maximum watchdog ticks value for the far future.
 
#define WATCHDOG_NANOSECONDS_PER_SECOND   1000000000
 
#define WATCHDOG_BITS_FOR_1E9_NANOSECONDS   30
 The bits necessary to store 1000000000 (= WATCHDOG_NANOSECONDS_PER_SECOND) nanoseconds. More...
 
#define WATCHDOG_MAX_SECONDS   0x3ffffffff
 The maximum number of seconds representable in the nanoseconds watchdog format. More...
 
#define WATCHDOG_NO_TIMEOUT   0
 Special watchdog ticks value to indicate an infinite wait.
 
#define WATCHDOG_TICKS_PER_TIMESLICE_DEFAULT   50
 Default value for the watchdog ticks per timeslice.
 

Typedefs

typedef struct Watchdog_Control Watchdog_Control
 
typedef void Watchdog_Service_routine
 Return type from a Watchdog Service Routine. More...
 
typedef Watchdog_Service_routine(* Watchdog_Service_routine_entry) (Watchdog_Control *)
 Pointer to a watchdog service routine. More...
 
typedef uint32_t Watchdog_Interval
 Type is used to specify the length of intervals. More...
 

Enumerations

enum  Watchdog_State { WATCHDOG_SCHEDULED_BLACK, WATCHDOG_SCHEDULED_RED, WATCHDOG_INACTIVE, WATCHDOG_PENDING }
 Watchdog states. More...
 

Functions

static __inline__ void _Watchdog_Header_initialize (Watchdog_Header *header)
 Initializes the watchdog header. More...
 
static __inline__ Watchdog_Control_Watchdog_Header_first (const Watchdog_Header *header)
 Returns the first of the watchdog header. More...
 
static __inline__ void _Watchdog_Header_destroy (Watchdog_Header *header)
 Destroys the watchdog header. More...
 
void _Watchdog_Tick (struct Per_CPU_Control *cpu)
 Performs a watchdog tick. More...
 
static __inline__ Watchdog_State _Watchdog_Get_state (const Watchdog_Control *the_watchdog)
 Gets the state of the watchdog. More...
 
static __inline__ void _Watchdog_Set_state (Watchdog_Control *the_watchdog, Watchdog_State state)
 Sets the state of the watchdog. More...
 
static __inline__ Per_CPU_Control_Watchdog_Get_CPU (const Watchdog_Control *the_watchdog)
 Gets the watchdog's cpu. More...
 
static __inline__ void _Watchdog_Set_CPU (Watchdog_Control *the_watchdog, Per_CPU_Control *cpu)
 Sets the cpu for the watchdog. More...
 
static __inline__ void _Watchdog_Preinitialize (Watchdog_Control *the_watchdog, Per_CPU_Control *cpu)
 Pre-initializes a watchdog. More...
 
static __inline__ void _Watchdog_Initialize (Watchdog_Control *the_watchdog, Watchdog_Service_routine_entry routine)
 Initializes a watchdog with a new service routine. More...
 
void _Watchdog_Do_tickle (Watchdog_Header *header, Watchdog_Control *first, uint64_t now, ISR_lock_Control *lock, ISR_lock_Context *lock_context)
 Calls the routine of each not expired watchdog control node. More...
 
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. More...
 
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. More...
 
static __inline__ uint64_t _Watchdog_Cancel (Watchdog_Header *header, Watchdog_Control *the_watchdog, uint64_t now)
 In the case the watchdog is scheduled, then it is removed from the set of scheduled watchdogs. More...
 
static __inline__ bool _Watchdog_Is_scheduled (const Watchdog_Control *the_watchdog)
 Checks if the watchdog is scheduled. More...
 
static __inline__ void _Watchdog_Next_first (Watchdog_Header *header, Watchdog_Control *the_watchdog)
 Sets the first node of the header. More...
 
static __inline__ bool _Watchdog_Is_valid_timespec (const struct timespec *ts)
 Checks if the timespec is a valid timespec for a watchdog. More...
 
static __inline__ bool _Watchdog_Is_valid_interval_timespec (const struct timespec *ts)
 Checks if the timespec is a valid interval timespec for a watchdog. More...
 
static __inline__ const struct timespec * _Watchdog_Future_timespec (struct timespec *now, const struct timespec *delta)
 Adds the delta timespec to the current time if the delta is a valid interval timespec. More...
 
static __inline__ bool _Watchdog_Is_far_future_timespec (const struct timespec *ts)
 Checks if the timespec is too far in the future. More...
 
static __inline__ uint64_t _Watchdog_Ticks_from_seconds (uint32_t seconds)
 Converts the seconds to ticks. More...
 
static __inline__ uint64_t _Watchdog_Ticks_from_timespec (const struct timespec *ts)
 Converts the timespec in ticks. More...
 
static __inline__ uint64_t _Watchdog_Ticks_from_sbintime (int64_t sbt)
 Converts the sbintime in ticks. More...
 
static __inline__ void _Watchdog_Per_CPU_acquire_critical (Per_CPU_Control *cpu, ISR_lock_Context *lock_context)
 Acquires the per cpu watchdog lock in a critical section. More...
 
static __inline__ void _Watchdog_Per_CPU_release_critical (Per_CPU_Control *cpu, ISR_lock_Context *lock_context)
 Releases the per cpu watchdog lock in a critical section. More...
 
static __inline__ uint64_t _Watchdog_Per_CPU_insert_ticks (Watchdog_Control *the_watchdog, Per_CPU_Control *cpu, Watchdog_Interval ticks)
 Sets the watchdog's cpu to the given instance and sets its expiration time to the watchdog expiration time of the cpu plus the ticks. More...
 
static __inline__ uint64_t _Watchdog_Per_CPU_insert (Watchdog_Control *the_watchdog, Per_CPU_Control *cpu, Watchdog_Header *header, uint64_t expire)
 Sets the watchdog's cpu and inserts it with the given expiration time in the scheduled watchdogs. More...
 
static __inline__ void _Watchdog_Per_CPU_remove (Watchdog_Control *the_watchdog, Per_CPU_Control *cpu, Watchdog_Header *header)
 Removes the watchdog from the cpu and the scheduled watchdogs. More...
 
static __inline__ void _Watchdog_Per_CPU_remove_ticks (Watchdog_Control *the_watchdog)
 Removes the watchdog from the cpu and the scheduled watchdogs. More...
 

Variables

volatile Watchdog_Interval _Watchdog_Ticks_since_boot
 The watchdog ticks counter. More...
 
const uint32_t _Watchdog_Microseconds_per_tick
 The watchdog microseconds per tick. More...
 
const uint32_t _Watchdog_Nanoseconds_per_tick
 The watchdog nanoseconds per tick. More...
 
const uint32_t _Watchdog_Ticks_per_second
 The watchdog ticks per second. More...
 
const uint32_t _Watchdog_Ticks_per_timeslice
 The watchdog ticks per timeslice. More...
 

Detailed Description

Watchdog Handler.

This handler encapsulates functionality related to the scheduling of watchdog functions to be called at specific times in the future.

Note
This handler does not have anything to do with hardware watchdog timers.

Macro Definition Documentation

◆ WATCHDOG_BITS_FOR_1E9_NANOSECONDS

#define WATCHDOG_BITS_FOR_1E9_NANOSECONDS   30

The bits necessary to store 1000000000 (= WATCHDOG_NANOSECONDS_PER_SECOND) nanoseconds.

The expiration time is an unsigned 64-bit integer. To store nanoseconds timeouts we use 30 bits (2**30 == 1073741824) for the nanoseconds and 34 bits for the seconds since UNIX Epoch. This leads to a year 2514 problem.

Definition at line 401 of file watchdogimpl.h.

◆ WATCHDOG_INITIALIZER

#define WATCHDOG_INITIALIZER (   routine)
Value:
{ \
{ { { NULL, NULL, NULL, WATCHDOG_INACTIVE } } }, \
&_Per_CPU_Information[ 0 ].per_cpu, \
( routine ), \
0 \
}
The watchdog is inactive.
Definition: watchdogimpl.h:61

Watchdog initializer for static initialization.

The processor of this watchdog is set to processor with index zero.

See also
_Watchdog_Preinitialize().

Definition at line 79 of file watchdogimpl.h.

◆ WATCHDOG_MAX_SECONDS

#define WATCHDOG_MAX_SECONDS   0x3ffffffff

The maximum number of seconds representable in the nanoseconds watchdog format.

We have 2**34 bits for the seconds part.

Definition at line 409 of file watchdogimpl.h.

Typedef Documentation

◆ Watchdog_Interval

typedef uint32_t Watchdog_Interval

Type is used to specify the length of intervals.

This type is used to specify the length of intervals.

Definition at line 38 of file watchdogticks.h.

◆ Watchdog_Service_routine

Return type from a Watchdog Service Routine.

This type defines the return type from a Watchdog Service Routine.

Definition at line 58 of file watchdog.h.

◆ Watchdog_Service_routine_entry

typedef Watchdog_Service_routine( * Watchdog_Service_routine_entry) (Watchdog_Control *)

Pointer to a watchdog service routine.

This type define a pointer to a watchdog service routine.

Definition at line 66 of file watchdog.h.

Enumeration Type Documentation

◆ Watchdog_State

Watchdog states.

Enumerator
WATCHDOG_SCHEDULED_BLACK 

The watchdog is scheduled and a black node in the red-black tree.

WATCHDOG_SCHEDULED_RED 

The watchdog is scheduled and a red node in the red-black tree.

WATCHDOG_INACTIVE 

The watchdog is inactive.

WATCHDOG_PENDING 

The watchdog is on a chain of pending watchdogs.

This state is used by the timer server for example.

Definition at line 47 of file watchdogimpl.h.

Function Documentation

◆ _Watchdog_Cancel()

static __inline__ uint64_t _Watchdog_Cancel ( Watchdog_Header header,
Watchdog_Control the_watchdog,
uint64_t  now 
)
static

In the case the watchdog is scheduled, then it is removed from the set of scheduled watchdogs.

The watchdog must be initialized before this call.

Parameters
[in,out]headerThe scheduled watchdogs.
[in,out]the_watchdogThe watchdog to remove.
nowThe current time.
Return values
otherThe difference of the now and expiration time.
0The now time is greater than or equal to the expiration time of the watchdog.

Definition at line 318 of file watchdogimpl.h.

◆ _Watchdog_Do_tickle()

void _Watchdog_Do_tickle ( Watchdog_Header header,
Watchdog_Control first,
uint64_t  now,
ISR_lock_Control lock,
ISR_lock_Context lock_context 
)

Calls the routine of each not expired watchdog control node.

Parameters
headerThe watchdog header.
firstThe first watchdog control node.
nowThe current time to check the expiration time against.
lockThe lock that is released before calling the routine and then acquired after the call.
lock_contextThe lock context for the release before calling the routine and for the acquire after.

Definition at line 24 of file watchdogtick.c.

◆ _Watchdog_Future_timespec()

static __inline__ const struct timespec* _Watchdog_Future_timespec ( struct timespec *  now,
const struct timespec *  delta 
)
static

Adds the delta timespec to the current time if the delta is a valid interval timespec.

Parameters
[in,out]nowThe current time.
deltaThe delta timespec for the addition.
Return values
pointerPointer to the now timespec.
NULLdelta is not a valid interval timespec.

Definition at line 452 of file watchdogimpl.h.

◆ _Watchdog_Get_CPU()

static __inline__ Per_CPU_Control* _Watchdog_Get_CPU ( const Watchdog_Control the_watchdog)
static

Gets the watchdog's cpu.

Parameters
the_watchdogThe watchdog to get the cpu of.
Returns
The cpu of the watchdog.

Definition at line 177 of file watchdogimpl.h.

◆ _Watchdog_Get_state()

static __inline__ Watchdog_State _Watchdog_Get_state ( const Watchdog_Control the_watchdog)
static

Gets the state of the watchdog.

Parameters
the_watchdogThe watchdog to get the state of.
Returns
The RB_COLOR of the_watchdog.

Definition at line 149 of file watchdogimpl.h.

◆ _Watchdog_Header_destroy()

static __inline__ void _Watchdog_Header_destroy ( Watchdog_Header header)
static

Destroys the watchdog header.

Parameters
headerThe watchdog header to destroy.

Definition at line 127 of file watchdogimpl.h.

◆ _Watchdog_Header_first()

static __inline__ Watchdog_Control* _Watchdog_Header_first ( const Watchdog_Header header)
static

Returns the first of the watchdog header.

Parameters
headerThe watchdog header to remove the first of.
Returns
The first of header.

Definition at line 115 of file watchdogimpl.h.

◆ _Watchdog_Header_initialize()

static __inline__ void _Watchdog_Header_initialize ( Watchdog_Header header)
static

Initializes the watchdog header.

Parameters
[out]headerThe header to initialize.

Definition at line 100 of file watchdogimpl.h.

◆ _Watchdog_Initialize()

static __inline__ void _Watchdog_Initialize ( Watchdog_Control the_watchdog,
Watchdog_Service_routine_entry  routine 
)
static

Initializes a watchdog with a new service routine.

The watchdog must be inactive.

Parameters
[out]the_watchdogThe watchdog to initialize.
routingThe service routine for the_watchdog.

Definition at line 236 of file watchdogimpl.h.

◆ _Watchdog_Insert()

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.

The watchdog must be inactive.

Parameters
[in,out]headerThe set of scheduler watchdogs to insert into.
[in,out]the_watchdogThe watchdog to insert.
expireThe expiration time for the watchdog.

Definition at line 29 of file watchdoginsert.c.

◆ _Watchdog_Is_far_future_timespec()

static __inline__ bool _Watchdog_Is_far_future_timespec ( const struct timespec *  ts)
static

Checks if the timespec is too far in the future.

Parameters
tsThe timespec for the verification.
Return values
truets is too far in the future.
falsets is not too far in the future.

Definition at line 490 of file watchdogimpl.h.

◆ _Watchdog_Is_scheduled()

static __inline__ bool _Watchdog_Is_scheduled ( const Watchdog_Control the_watchdog)
static

Checks if the watchdog is scheduled.

Parameters
the_watchdogThe watchdog for the verification.
Return values
trueThe watchdog is scheduled.
falseThe watchdog is inactive.

Definition at line 348 of file watchdogimpl.h.

◆ _Watchdog_Is_valid_interval_timespec()

static __inline__ bool _Watchdog_Is_valid_interval_timespec ( const struct timespec *  ts)
static

Checks if the timespec is a valid interval timespec for a watchdog.

Parameters
tsThe timespec for the verification.
Return values
trueThe timespec is a valid interval timespec.
falseThe timespec is invalid.

Definition at line 435 of file watchdogimpl.h.

◆ _Watchdog_Is_valid_timespec()

static __inline__ bool _Watchdog_Is_valid_timespec ( const struct timespec *  ts)
static

Checks if the timespec is a valid timespec for a watchdog.

Parameters
tsThe timespec for the verification.
Return values
trueThe timespec is a valid timespec.
falseThe timespec is invalid.

Definition at line 419 of file watchdogimpl.h.

◆ _Watchdog_Next_first()

static __inline__ void _Watchdog_Next_first ( Watchdog_Header header,
Watchdog_Control the_watchdog 
)
static

Sets the first node of the header.

Sets the first node of the header to either the leftmost child node of the watchdog control node, or if not present sets it to the right child node of the watchdog control node. if both are not present, the new first node is the parent node of the current first node.

Parameters
[in,out]headerThe watchdog header.
the_watchdogThe watchdog control node for the operation.

Definition at line 366 of file watchdogimpl.h.

◆ _Watchdog_Per_CPU_acquire_critical()

static __inline__ void _Watchdog_Per_CPU_acquire_critical ( Per_CPU_Control cpu,
ISR_lock_Context lock_context 
)
static

Acquires the per cpu watchdog lock in a critical section.

Parameters
cpuThe cpu to acquire the watchdog lock of.
lock_contextThe lock context.

Definition at line 561 of file watchdogimpl.h.

◆ _Watchdog_Per_CPU_insert()

static __inline__ uint64_t _Watchdog_Per_CPU_insert ( Watchdog_Control the_watchdog,
Per_CPU_Control cpu,
Watchdog_Header header,
uint64_t  expire 
)
static

Sets the watchdog's cpu and inserts it with the given expiration time in the scheduled watchdogs.

Parameters
[in,out]the_watchdogThe watchdog to set cpu and expiration time of.
cpuThe cpu for the operation.
[in,out]headerThe scheduled watchdogs.
expireThe expiration time for the watchdog.
Returns
The expiration time of the watchdog.

Definition at line 625 of file watchdogimpl.h.

◆ _Watchdog_Per_CPU_insert_ticks()

static __inline__ uint64_t _Watchdog_Per_CPU_insert_ticks ( Watchdog_Control the_watchdog,
Per_CPU_Control cpu,
Watchdog_Interval  ticks 
)
static

Sets the watchdog's cpu to the given instance and sets its expiration time to the watchdog expiration time of the cpu plus the ticks.

Parameters
[in,out]the_watchdogThe watchdog to set the cpu and expiration time of.
cpuThe cpu for the watchdog.
ticksThe ticks to add to the expiration time.
Returns
The new expiration time of the watchdog.

Definition at line 593 of file watchdogimpl.h.

◆ _Watchdog_Per_CPU_release_critical()

static __inline__ void _Watchdog_Per_CPU_release_critical ( Per_CPU_Control cpu,
ISR_lock_Context lock_context 
)
static

Releases the per cpu watchdog lock in a critical section.

Parameters
cpuThe cpu to release the watchdog lock of.
lock_contextThe lock context.

Definition at line 575 of file watchdogimpl.h.

◆ _Watchdog_Per_CPU_remove()

static __inline__ void _Watchdog_Per_CPU_remove ( Watchdog_Control the_watchdog,
Per_CPU_Control cpu,
Watchdog_Header header 
)
static

Removes the watchdog from the cpu and the scheduled watchdogs.

Parameters
[in,out]the_watchdogThe watchdog to remove.
cpuThe cpu to remove the watchdog from.
[in,out]Thescheduled watchdogs.

Definition at line 649 of file watchdogimpl.h.

◆ _Watchdog_Per_CPU_remove_ticks()

static __inline__ void _Watchdog_Per_CPU_remove_ticks ( Watchdog_Control the_watchdog)
static

Removes the watchdog from the cpu and the scheduled watchdogs.

Parameters
[in,out]the_watchdogThe watchdog to remove.

Definition at line 670 of file watchdogimpl.h.

◆ _Watchdog_Preinitialize()

static __inline__ void _Watchdog_Preinitialize ( Watchdog_Control the_watchdog,
Per_CPU_Control cpu 
)
static

Pre-initializes a watchdog.

This routine must be called before a watchdog is used in any way. The exception are statically initialized watchdogs via WATCHDOG_INITIALIZER().

Parameters
[out]the_watchdogThe uninitialized watchdog.

Definition at line 214 of file watchdogimpl.h.

◆ _Watchdog_Remove()

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.

The watchdog must be initialized before this call.

Parameters
[in,out]headerThe scheduled watchdogs.
[in,out]the_watchdogThe watchdog to remove.

Definition at line 29 of file watchdogremove.c.

◆ _Watchdog_Set_CPU()

static __inline__ void _Watchdog_Set_CPU ( Watchdog_Control the_watchdog,
Per_CPU_Control cpu 
)
static

Sets the cpu for the watchdog.

Parameters
[out]the_watchdogThe watchdog to set the cpu of.
cpuThe cpu to be set as the_watchdog's cpu.

Definition at line 194 of file watchdogimpl.h.

◆ _Watchdog_Set_state()

static __inline__ void _Watchdog_Set_state ( Watchdog_Control the_watchdog,
Watchdog_State  state 
)
static

Sets the state of the watchdog.

Parameters
[out]the_watchdogThe watchdog to set the state of.
stateThe state to set the watchdog to.

Definition at line 162 of file watchdogimpl.h.

◆ _Watchdog_Tick()

void _Watchdog_Tick ( struct Per_CPU_Control cpu)

Performs a watchdog tick.

Parameters
cpuThe processor for this watchdog tick.

Definition at line 54 of file watchdogtick.c.

◆ _Watchdog_Ticks_from_sbintime()

static __inline__ uint64_t _Watchdog_Ticks_from_sbintime ( int64_t  sbt)
static

Converts the sbintime in ticks.

Parameters
sbtThe sbintime to convert to ticks.
Returns
sbt converted to ticks.

Definition at line 546 of file watchdogimpl.h.

◆ _Watchdog_Ticks_from_seconds()

static __inline__ uint64_t _Watchdog_Ticks_from_seconds ( uint32_t  seconds)
static

Converts the seconds to ticks.

Parameters
secondsThe seconds to convert to ticks.
Returns
seconds converted to ticks.

Definition at line 504 of file watchdogimpl.h.

◆ _Watchdog_Ticks_from_timespec()

static __inline__ uint64_t _Watchdog_Ticks_from_timespec ( const struct timespec *  ts)
static

Converts the timespec in ticks.

Parameters
tsThe timespec to convert to ticks.
Returns
ts converted to ticks.

Definition at line 522 of file watchdogimpl.h.

Variable Documentation

◆ _Watchdog_Microseconds_per_tick

const uint32_t _Watchdog_Microseconds_per_tick

The watchdog microseconds per tick.

This constant is defined by the application configuration via <rtems/confdefs.h>.

◆ _Watchdog_Nanoseconds_per_tick

const uint32_t _Watchdog_Nanoseconds_per_tick

The watchdog nanoseconds per tick.

This constant is defined by the application configuration via <rtems/confdefs.h>.

◆ _Watchdog_Ticks_per_second

const uint32_t _Watchdog_Ticks_per_second

The watchdog ticks per second.

This constant is defined by the application configuration via <rtems/confdefs.h>.

◆ _Watchdog_Ticks_per_timeslice

const uint32_t _Watchdog_Ticks_per_timeslice

The watchdog ticks per timeslice.

This constant is defined by the application configuration via <rtems/confdefs.h>.

Definition at line 34 of file watchdogtimeslicedefault.c.

◆ _Watchdog_Ticks_since_boot

volatile Watchdog_Interval _Watchdog_Ticks_since_boot

The watchdog ticks counter.

With a 1ms watchdog tick, this counter overflows after 50 days since boot.

Definition at line 29 of file watchdogtickssinceboot.c.