forked from Imagelibrary/rtems
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <rtems/score/watchdog.h>
|
#include <rtems/score/watchdog.h>
|
||||||
#include <rtems/score/chainimpl.h>
|
#include <rtems/score/chainimpl.h>
|
||||||
|
#include <rtems/score/isrlock.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -48,6 +49,11 @@ extern "C" {
|
|||||||
* @brief Watchdog header.
|
* @brief Watchdog header.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
/**
|
||||||
|
* @brief ISR lock to protect this watchdog chain.
|
||||||
|
*/
|
||||||
|
ISR_LOCK_MEMBER( Lock )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The chain of active or transient watchdogs.
|
* @brief The chain of active or transient watchdogs.
|
||||||
*/
|
*/
|
||||||
@@ -84,6 +90,30 @@ SCORE_EXTERN Watchdog_Header _Watchdog_Ticks_header;
|
|||||||
*/
|
*/
|
||||||
SCORE_EXTERN Watchdog_Header _Watchdog_Seconds_header;
|
SCORE_EXTERN Watchdog_Header _Watchdog_Seconds_header;
|
||||||
|
|
||||||
|
RTEMS_INLINE_ROUTINE void _Watchdog_Acquire(
|
||||||
|
Watchdog_Header *header,
|
||||||
|
ISR_lock_Context *lock_context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
_ISR_lock_ISR_disable_and_acquire( &header->Lock, lock_context );
|
||||||
|
}
|
||||||
|
|
||||||
|
RTEMS_INLINE_ROUTINE void _Watchdog_Release(
|
||||||
|
Watchdog_Header *header,
|
||||||
|
ISR_lock_Context *lock_context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
_ISR_lock_Release_and_ISR_enable( &header->Lock, lock_context );
|
||||||
|
}
|
||||||
|
|
||||||
|
RTEMS_INLINE_ROUTINE void _Watchdog_Flash(
|
||||||
|
Watchdog_Header *header,
|
||||||
|
ISR_lock_Context *lock_context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
_ISR_lock_Flash( &header->Lock, lock_context );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the watchdog handler.
|
* @brief Initialize the watchdog handler.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ void _Watchdog_Adjust_backward(
|
|||||||
Watchdog_Interval units
|
Watchdog_Interval units
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ISR_Level level;
|
ISR_lock_Context lock_context;
|
||||||
|
|
||||||
_ISR_Disable( level );
|
_Watchdog_Acquire( header, &lock_context );
|
||||||
|
|
||||||
if ( !_Watchdog_Is_empty( header ) ) {
|
if ( !_Watchdog_Is_empty( header ) ) {
|
||||||
_Watchdog_First( header )->delta_interval += units;
|
_Watchdog_First( header )->delta_interval += units;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ISR_Enable( level );
|
_Watchdog_Release( header, &lock_context );
|
||||||
}
|
}
|
||||||
|
|
||||||
void _Watchdog_Adjust_forward(
|
void _Watchdog_Adjust_forward(
|
||||||
@@ -43,9 +43,9 @@ void _Watchdog_Adjust_forward(
|
|||||||
Watchdog_Interval units
|
Watchdog_Interval units
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ISR_Level level;
|
ISR_lock_Context lock_context;
|
||||||
|
|
||||||
_ISR_Disable( level );
|
_Watchdog_Acquire( header, &lock_context );
|
||||||
|
|
||||||
while ( !_Watchdog_Is_empty( header ) && units > 0 ) {
|
while ( !_Watchdog_Is_empty( header ) && units > 0 ) {
|
||||||
Watchdog_Control *first = _Watchdog_First( header );
|
Watchdog_Control *first = _Watchdog_First( header );
|
||||||
@@ -57,13 +57,13 @@ void _Watchdog_Adjust_forward(
|
|||||||
units -= first->delta_interval;
|
units -= first->delta_interval;
|
||||||
first->delta_interval = 1;
|
first->delta_interval = 1;
|
||||||
|
|
||||||
_ISR_Enable( level );
|
_Watchdog_Release( header, &lock_context );
|
||||||
|
|
||||||
_Watchdog_Tickle( header );
|
_Watchdog_Tickle( header );
|
||||||
|
|
||||||
_ISR_Disable( level );
|
_Watchdog_Acquire( header, &lock_context );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ISR_Enable( level );
|
_Watchdog_Release( header, &lock_context );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ void _Watchdog_Adjust_to_chain(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
Watchdog_Interval units = units_arg;
|
Watchdog_Interval units = units_arg;
|
||||||
ISR_Level level;
|
ISR_lock_Context lock_context;
|
||||||
Watchdog_Control *first;
|
Watchdog_Control *first;
|
||||||
|
|
||||||
_ISR_Disable( level );
|
_Watchdog_Acquire( header, &lock_context );
|
||||||
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
if ( _Watchdog_Is_empty( header ) ) {
|
if ( _Watchdog_Is_empty( header ) ) {
|
||||||
@@ -60,7 +60,7 @@ void _Watchdog_Adjust_to_chain(
|
|||||||
_Chain_Extract_unprotected( &first->Node );
|
_Chain_Extract_unprotected( &first->Node );
|
||||||
_Chain_Append_unprotected( to_fire, &first->Node );
|
_Chain_Append_unprotected( to_fire, &first->Node );
|
||||||
|
|
||||||
_ISR_Flash( level );
|
_Watchdog_Flash( header, &lock_context );
|
||||||
|
|
||||||
if ( _Watchdog_Is_empty( header ) )
|
if ( _Watchdog_Is_empty( header ) )
|
||||||
break;
|
break;
|
||||||
@@ -70,6 +70,6 @@ void _Watchdog_Adjust_to_chain(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ISR_Enable( level );
|
_Watchdog_Release( header, &lock_context );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ void _Watchdog_Insert(
|
|||||||
Watchdog_Control *the_watchdog
|
Watchdog_Control *the_watchdog
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ISR_Level level;
|
ISR_lock_Context lock_context;
|
||||||
Watchdog_Control *after;
|
Watchdog_Control *after;
|
||||||
uint32_t insert_isr_nest_level;
|
uint32_t insert_isr_nest_level;
|
||||||
Watchdog_Interval delta_interval;
|
Watchdog_Interval delta_interval;
|
||||||
@@ -35,7 +35,7 @@ void _Watchdog_Insert(
|
|||||||
|
|
||||||
insert_isr_nest_level = _ISR_Nest_level;
|
insert_isr_nest_level = _ISR_Nest_level;
|
||||||
|
|
||||||
_ISR_Disable( level );
|
_Watchdog_Acquire( header, &lock_context );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check to see if the watchdog has just been inserted by a
|
* Check to see if the watchdog has just been inserted by a
|
||||||
@@ -43,7 +43,7 @@ void _Watchdog_Insert(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if ( the_watchdog->state != WATCHDOG_INACTIVE ) {
|
if ( the_watchdog->state != WATCHDOG_INACTIVE ) {
|
||||||
_ISR_Enable( level );
|
_Watchdog_Release( header, &lock_context );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ restart:
|
|||||||
|
|
||||||
delta_interval -= after->delta_interval;
|
delta_interval -= after->delta_interval;
|
||||||
|
|
||||||
_ISR_Flash( level );
|
_Watchdog_Flash( header, &lock_context );
|
||||||
|
|
||||||
if ( the_watchdog->state != WATCHDOG_BEING_INSERTED ) {
|
if ( the_watchdog->state != WATCHDOG_BEING_INSERTED ) {
|
||||||
goto exit_insert;
|
goto exit_insert;
|
||||||
@@ -90,5 +90,5 @@ restart:
|
|||||||
exit_insert:
|
exit_insert:
|
||||||
_Watchdog_Sync_level = insert_isr_nest_level;
|
_Watchdog_Sync_level = insert_isr_nest_level;
|
||||||
_Watchdog_Sync_count--;
|
_Watchdog_Sync_count--;
|
||||||
_ISR_Enable( level );
|
_Watchdog_Release( header, &lock_context );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ Watchdog_States _Watchdog_Remove(
|
|||||||
Watchdog_Control *the_watchdog
|
Watchdog_Control *the_watchdog
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ISR_Level level;
|
ISR_lock_Context lock_context;
|
||||||
Watchdog_States previous_state;
|
Watchdog_States previous_state;
|
||||||
Watchdog_Control *next_watchdog;
|
Watchdog_Control *next_watchdog;
|
||||||
|
|
||||||
_ISR_Disable( level );
|
_Watchdog_Acquire( header, &lock_context );
|
||||||
previous_state = the_watchdog->state;
|
previous_state = the_watchdog->state;
|
||||||
switch ( previous_state ) {
|
switch ( previous_state ) {
|
||||||
case WATCHDOG_INACTIVE:
|
case WATCHDOG_INACTIVE:
|
||||||
@@ -63,6 +63,6 @@ Watchdog_States _Watchdog_Remove(
|
|||||||
}
|
}
|
||||||
the_watchdog->stop_time = _Watchdog_Ticks_since_boot;
|
the_watchdog->stop_time = _Watchdog_Ticks_since_boot;
|
||||||
|
|
||||||
_ISR_Enable( level );
|
_Watchdog_Release( header, &lock_context );
|
||||||
return( previous_state );
|
return( previous_state );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ void _Watchdog_Tickle(
|
|||||||
Watchdog_Header *header
|
Watchdog_Header *header
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ISR_Level level;
|
ISR_lock_Context lock_context;
|
||||||
Watchdog_Control *the_watchdog;
|
Watchdog_Control *the_watchdog;
|
||||||
Watchdog_States watchdog_state;
|
Watchdog_States watchdog_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See the comment in watchdoginsert.c and watchdogadjust.c
|
* See the comment in watchdoginsert.c and watchdogadjust.c
|
||||||
@@ -35,7 +35,7 @@ void _Watchdog_Tickle(
|
|||||||
* volatile data - till, 2003/7
|
* volatile data - till, 2003/7
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_ISR_Disable( level );
|
_Watchdog_Acquire( header, &lock_context );
|
||||||
|
|
||||||
if ( _Watchdog_Is_empty( header ) )
|
if ( _Watchdog_Is_empty( header ) )
|
||||||
goto leave;
|
goto leave;
|
||||||
@@ -76,7 +76,7 @@ void _Watchdog_Tickle(
|
|||||||
do {
|
do {
|
||||||
watchdog_state = _Watchdog_Remove( header, the_watchdog );
|
watchdog_state = _Watchdog_Remove( header, the_watchdog );
|
||||||
|
|
||||||
_ISR_Enable( level );
|
_Watchdog_Release( header, &lock_context );
|
||||||
|
|
||||||
switch( watchdog_state ) {
|
switch( watchdog_state ) {
|
||||||
case WATCHDOG_ACTIVE:
|
case WATCHDOG_ACTIVE:
|
||||||
@@ -106,12 +106,12 @@ void _Watchdog_Tickle(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ISR_Disable( level );
|
_Watchdog_Acquire( header, &lock_context );
|
||||||
|
|
||||||
the_watchdog = _Watchdog_First( header );
|
the_watchdog = _Watchdog_First( header );
|
||||||
} while ( !_Watchdog_Is_empty( header ) &&
|
} while ( !_Watchdog_Is_empty( header ) &&
|
||||||
(the_watchdog->delta_interval == 0) );
|
(the_watchdog->delta_interval == 0) );
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
_ISR_Enable(level);
|
_Watchdog_Release( header, &lock_context );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user