From 54cf0e34c5d6b8be0ce136eac7c4e11c1d487d7f Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 10 Apr 2015 16:19:48 +0200 Subject: score: Add Watchdog_Header This type is intended to encapsulate all state to manage a watchdog chain. Update #2307. --- cpukit/rtems/include/rtems/rtems/timerimpl.h | 5 +- cpukit/rtems/src/timerreset.c | 2 +- cpukit/rtems/src/timerserver.c | 37 +++++++-------- cpukit/score/include/rtems/score/watchdogimpl.h | 62 +++++++++++++++++-------- cpukit/score/src/coretodset.c | 4 +- cpukit/score/src/watchdog.c | 6 +-- cpukit/score/src/watchdogadjust.c | 8 ++-- cpukit/score/src/watchdogadjusttochain.c | 13 +++--- cpukit/score/src/watchdoginsert.c | 6 +-- cpukit/score/src/watchdogtickle.c | 9 ++-- 10 files changed, 86 insertions(+), 66 deletions(-) (limited to 'cpukit') diff --git a/cpukit/rtems/include/rtems/rtems/timerimpl.h b/cpukit/rtems/include/rtems/rtems/timerimpl.h index 667a86a686..b695d5e2fe 100644 --- a/cpukit/rtems/include/rtems/rtems/timerimpl.h +++ b/cpukit/rtems/include/rtems/rtems/timerimpl.h @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -64,9 +65,9 @@ typedef struct { Watchdog_Control System_watchdog; /** - * @brief Chain for watchdogs which will be triggered by the timer server. + * @brief Watchdog header managed by the timer server. */ - Chain_Control Chain; + Watchdog_Header Header; /** * @brief Last known time snapshot of the timer server. diff --git a/cpukit/rtems/src/timerreset.c b/cpukit/rtems/src/timerreset.c index 8afb7ab17f..495780aa8d 100644 --- a/cpukit/rtems/src/timerreset.c +++ b/cpukit/rtems/src/timerreset.c @@ -52,7 +52,7 @@ rtems_status_code rtems_timer_reset( case OBJECTS_LOCAL: if ( the_timer->the_class == TIMER_INTERVAL ) { _Watchdog_Remove( &the_timer->Ticker ); - _Watchdog_Insert( &_Watchdog_Ticks_chain, &the_timer->Ticker ); + _Watchdog_Insert( &_Watchdog_Ticks_header, &the_timer->Ticker ); } else if ( the_timer->the_class == TIMER_INTERVAL_ON_TASK ) { Timer_server_Control *timer_server = _Timer_server; diff --git a/cpukit/rtems/src/timerserver.c b/cpukit/rtems/src/timerserver.c index 00f29ccdda..25191e43d7 100644 --- a/cpukit/rtems/src/timerserver.c +++ b/cpukit/rtems/src/timerserver.c @@ -31,7 +31,6 @@ #include #include #include -#include static Timer_server_Control _Timer_server_Default; @@ -51,9 +50,9 @@ static void _Timer_server_Reset_interval_system_watchdog( _Timer_server_Stop_interval_system_watchdog( ts ); _ISR_Disable( level ); - if ( !_Chain_Is_empty( &ts->Interval_watchdogs.Chain ) ) { + if ( !_Watchdog_Is_empty( &ts->Interval_watchdogs.Header ) ) { Watchdog_Interval delta_interval = - _Watchdog_First( &ts->Interval_watchdogs.Chain )->delta_interval; + _Watchdog_First( &ts->Interval_watchdogs.Header )->delta_interval; _ISR_Enable( level ); /* @@ -84,9 +83,9 @@ static void _Timer_server_Reset_tod_system_watchdog( _Timer_server_Stop_tod_system_watchdog( ts ); _ISR_Disable( level ); - if ( !_Chain_Is_empty( &ts->TOD_watchdogs.Chain ) ) { + if ( !_Watchdog_Is_empty( &ts->TOD_watchdogs.Header ) ) { Watchdog_Interval delta_interval = - _Watchdog_First( &ts->TOD_watchdogs.Chain )->delta_interval; + _Watchdog_First( &ts->TOD_watchdogs.Header )->delta_interval; _ISR_Enable( level ); /* @@ -107,9 +106,9 @@ static void _Timer_server_Insert_timer( ) { if ( timer->the_class == TIMER_INTERVAL_ON_TASK ) { - _Watchdog_Insert( &ts->Interval_watchdogs.Chain, &timer->Ticker ); + _Watchdog_Insert( &ts->Interval_watchdogs.Header, &timer->Ticker ); } else if ( timer->the_class == TIMER_TIME_OF_DAY_ON_TASK ) { - _Watchdog_Insert( &ts->TOD_watchdogs.Chain, &timer->Ticker ); + _Watchdog_Insert( &ts->TOD_watchdogs.Header, &timer->Ticker ); } } @@ -144,8 +143,8 @@ static void _Timer_server_Insert_timer_and_make_snapshot( _ISR_Disable( level ); snapshot = _Watchdog_Ticks_since_boot; last_snapshot = ts->Interval_watchdogs.last_snapshot; - if ( !_Chain_Is_empty( &ts->Interval_watchdogs.Chain ) ) { - first_watchdog = _Watchdog_First( &ts->Interval_watchdogs.Chain ); + if ( !_Watchdog_Is_empty( &ts->Interval_watchdogs.Header ) ) { + first_watchdog = _Watchdog_First( &ts->Interval_watchdogs.Header ); /* * We assume adequate unsigned arithmetic here. @@ -163,7 +162,7 @@ static void _Timer_server_Insert_timer_and_make_snapshot( ts->Interval_watchdogs.last_snapshot = snapshot; _ISR_Enable( level ); - _Watchdog_Insert( &ts->Interval_watchdogs.Chain, &timer->Ticker ); + _Watchdog_Insert( &ts->Interval_watchdogs.Header, &timer->Ticker ); if ( !ts->active ) { _Timer_server_Reset_interval_system_watchdog( ts ); @@ -176,8 +175,8 @@ static void _Timer_server_Insert_timer_and_make_snapshot( _ISR_Disable( level ); snapshot = (Watchdog_Interval) _TOD_Seconds_since_epoch(); last_snapshot = ts->TOD_watchdogs.last_snapshot; - if ( !_Chain_Is_empty( &ts->TOD_watchdogs.Chain ) ) { - first_watchdog = _Watchdog_First( &ts->TOD_watchdogs.Chain ); + if ( !_Watchdog_Is_empty( &ts->TOD_watchdogs.Header ) ) { + first_watchdog = _Watchdog_First( &ts->TOD_watchdogs.Header ); delta_interval = first_watchdog->delta_interval; if ( snapshot > last_snapshot ) { /* @@ -201,7 +200,7 @@ static void _Timer_server_Insert_timer_and_make_snapshot( ts->TOD_watchdogs.last_snapshot = snapshot; _ISR_Enable( level ); - _Watchdog_Insert( &ts->TOD_watchdogs.Chain, &timer->Ticker ); + _Watchdog_Insert( &ts->TOD_watchdogs.Header, &timer->Ticker ); if ( !ts->active ) { _Timer_server_Reset_tod_system_watchdog( ts ); @@ -244,7 +243,7 @@ static void _Timer_server_Process_interval_watchdogs( watchdogs->last_snapshot = snapshot; - _Watchdog_Adjust_to_chain( &watchdogs->Chain, delta, fire_chain ); + _Watchdog_Adjust_to_chain( &watchdogs->Header, delta, fire_chain ); } static void _Timer_server_Process_tod_watchdogs( @@ -259,7 +258,7 @@ static void _Timer_server_Process_tod_watchdogs( /* * Process the seconds chain. Start by checking that the Time * of Day (TOD) has not been set backwards. If it has then - * we want to adjust the watchdogs->Chain to indicate this. + * we want to adjust the watchdogs->Header to indicate this. */ if ( snapshot > last_snapshot ) { /* @@ -267,7 +266,7 @@ static void _Timer_server_Process_tod_watchdogs( * TOD has been set forward. */ delta = snapshot - last_snapshot; - _Watchdog_Adjust_to_chain( &watchdogs->Chain, delta, fire_chain ); + _Watchdog_Adjust_to_chain( &watchdogs->Header, delta, fire_chain ); } else if ( snapshot < last_snapshot ) { /* @@ -275,7 +274,7 @@ static void _Timer_server_Process_tod_watchdogs( * TOD has been set backwards. */ delta = last_snapshot - snapshot; - _Watchdog_Adjust_backward( &watchdogs->Chain, delta ); + _Watchdog_Adjust_backward( &watchdogs->Header, delta ); } watchdogs->last_snapshot = snapshot; @@ -543,8 +542,8 @@ rtems_status_code rtems_timer_initiate_server( /* * Initialize the timer lists that the server will manage. */ - _Chain_Initialize_empty( &ts->Interval_watchdogs.Chain ); - _Chain_Initialize_empty( &ts->TOD_watchdogs.Chain ); + _Watchdog_Header_initialize( &ts->Interval_watchdogs.Header ); + _Watchdog_Header_initialize( &ts->TOD_watchdogs.Header ); /* * Initialize the timers that will be used to control when the diff --git a/cpukit/score/include/rtems/score/watchdogimpl.h b/cpukit/score/include/rtems/score/watchdogimpl.h index 9eb0951949..67a2d69cf3 100644 --- a/cpukit/score/include/rtems/score/watchdogimpl.h +++ b/cpukit/score/include/rtems/score/watchdogimpl.h @@ -52,6 +52,16 @@ extern "C" { ( routine ), ( id ), ( user_data ) \ } +/** + * @brief Watchdog header. + */ +typedef struct { + /** + * @brief The chain of active or transient watchdogs. + */ + Chain_Control Watchdogs; +} Watchdog_Header; + /** * @brief Watchdog synchronization level. * @@ -73,14 +83,14 @@ SCORE_EXTERN volatile uint32_t _Watchdog_Sync_count; * * This is the watchdog chain which is managed at ticks. */ -SCORE_EXTERN Chain_Control _Watchdog_Ticks_chain; +SCORE_EXTERN Watchdog_Header _Watchdog_Ticks_header; /** * @brief Watchdog chain which is managed at second boundaries. * * This is the watchdog chain which is managed at second boundaries. */ -SCORE_EXTERN Chain_Control _Watchdog_Seconds_chain; +SCORE_EXTERN Watchdog_Header _Watchdog_Seconds_header; /** * @brief Initialize the watchdog handler. @@ -112,7 +122,7 @@ Watchdog_States _Watchdog_Remove ( * @param[in] units The units of ticks to adjust. */ void _Watchdog_Adjust_backward( - Chain_Control *header, + Watchdog_Header *header, Watchdog_Interval units ); @@ -126,7 +136,7 @@ void _Watchdog_Adjust_backward( * @param[in] units The units of ticks to adjust. */ void _Watchdog_Adjust_forward( - Chain_Control *header, + Watchdog_Header *header, Watchdog_Interval units ); @@ -145,9 +155,9 @@ void _Watchdog_Adjust_forward( * @note This always adjusts forward. */ void _Watchdog_Adjust_to_chain( - Chain_Control *header, - Watchdog_Interval units_arg, - Chain_Control *to_fire + Watchdog_Header *header, + Watchdog_Interval units_arg, + Chain_Control *to_fire ); @@ -163,8 +173,8 @@ void _Watchdog_Adjust_to_chain( * @param[in] the_watchdog is the watchdog to insert */ void _Watchdog_Insert ( - Chain_Control *header, - Watchdog_Control *the_watchdog + Watchdog_Header *header, + Watchdog_Control *the_watchdog ); /** @@ -178,7 +188,7 @@ void _Watchdog_Insert ( * @param[in] header is the watchdog chain to tickle */ void _Watchdog_Tickle ( - Chain_Control *header + Watchdog_Header *header ); /** @@ -250,7 +260,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Deactivate( RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_ticks( void ) { - _Watchdog_Tickle( &_Watchdog_Ticks_chain ); + _Watchdog_Tickle( &_Watchdog_Ticks_header ); } @@ -262,7 +272,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_ticks( void ) RTEMS_INLINE_ROUTINE void _Watchdog_Tickle_seconds( void ) { - _Watchdog_Tickle( &_Watchdog_Seconds_chain ); + _Watchdog_Tickle( &_Watchdog_Seconds_header ); } @@ -281,7 +291,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Insert_ticks( the_watchdog->initial = units; - _Watchdog_Insert( &_Watchdog_Ticks_chain, the_watchdog ); + _Watchdog_Insert( &_Watchdog_Ticks_header, the_watchdog ); } @@ -300,7 +310,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Insert_seconds( the_watchdog->initial = units; - _Watchdog_Insert( &_Watchdog_Seconds_chain, the_watchdog ); + _Watchdog_Insert( &_Watchdog_Seconds_header, the_watchdog ); } @@ -318,7 +328,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Reset( (void) _Watchdog_Remove( the_watchdog ); - _Watchdog_Insert( &_Watchdog_Ticks_chain, the_watchdog ); + _Watchdog_Insert( &_Watchdog_Ticks_header, the_watchdog ); } @@ -356,11 +366,11 @@ RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Previous( */ RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_First( - Chain_Control *header + Watchdog_Header *header ) { - return ( (Watchdog_Control *) _Chain_First( header ) ); + return ( (Watchdog_Control *) _Chain_First( &header->Watchdogs ) ); } @@ -370,12 +380,26 @@ RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_First( */ RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Last( - Chain_Control *header + Watchdog_Header *header ) { - return ( (Watchdog_Control *) _Chain_Last( header ) ); + return ( (Watchdog_Control *) _Chain_Last( &header->Watchdogs ) ); + +} + +RTEMS_INLINE_ROUTINE bool _Watchdog_Is_empty( + const Watchdog_Header *header +) +{ + return _Chain_Is_empty( &header->Watchdogs ); +} +RTEMS_INLINE_ROUTINE void _Watchdog_Header_initialize( + Watchdog_Header *header +) +{ + _Chain_Initialize_empty( &header->Watchdogs ); } /** @} */ diff --git a/cpukit/score/src/coretodset.c b/cpukit/score/src/coretodset.c index 8c4ef8b135..7c7731aae0 100644 --- a/cpukit/score/src/coretodset.c +++ b/cpukit/score/src/coretodset.c @@ -31,12 +31,12 @@ void _TOD_Set_with_timestamp( Watchdog_Interval seconds_next = _Timestamp_Get_seconds( tod_as_timestamp ); Watchdog_Interval seconds_now; ISR_lock_Context lock_context; - Chain_Control *header; + Watchdog_Header *header; _Thread_Disable_dispatch(); seconds_now = _TOD_Seconds_since_epoch(); - header = &_Watchdog_Seconds_chain; + header = &_Watchdog_Seconds_header; if ( seconds_next < seconds_now ) _Watchdog_Adjust_backward( header, seconds_now - seconds_next ); diff --git a/cpukit/score/src/watchdog.c b/cpukit/score/src/watchdog.c index 4b093d52e1..0db60efe6b 100644 --- a/cpukit/score/src/watchdog.c +++ b/cpukit/score/src/watchdog.c @@ -21,8 +21,6 @@ #include "config.h" #endif -#include -#include #include void _Watchdog_Handler_initialization( void ) @@ -31,6 +29,6 @@ void _Watchdog_Handler_initialization( void ) _Watchdog_Sync_level = 0; _Watchdog_Ticks_since_boot = 0; - _Chain_Initialize_empty( &_Watchdog_Ticks_chain ); - _Chain_Initialize_empty( &_Watchdog_Seconds_chain ); + _Watchdog_Header_initialize( &_Watchdog_Ticks_header ); + _Watchdog_Header_initialize( &_Watchdog_Seconds_header ); } diff --git a/cpukit/score/src/watchdogadjust.c b/cpukit/score/src/watchdogadjust.c index 5d841049dc..687f063482 100644 --- a/cpukit/score/src/watchdogadjust.c +++ b/cpukit/score/src/watchdogadjust.c @@ -23,7 +23,7 @@ #include void _Watchdog_Adjust_backward( - Chain_Control *header, + Watchdog_Header *header, Watchdog_Interval units ) { @@ -31,7 +31,7 @@ void _Watchdog_Adjust_backward( _ISR_Disable( level ); - if ( !_Chain_Is_empty( header ) ) { + if ( !_Watchdog_Is_empty( header ) ) { _Watchdog_First( header )->delta_interval += units; } @@ -39,7 +39,7 @@ void _Watchdog_Adjust_backward( } void _Watchdog_Adjust_forward( - Chain_Control *header, + Watchdog_Header *header, Watchdog_Interval units ) { @@ -47,7 +47,7 @@ void _Watchdog_Adjust_forward( _ISR_Disable( level ); - while ( !_Chain_Is_empty( header ) && units > 0 ) { + while ( !_Watchdog_Is_empty( header ) && units > 0 ) { Watchdog_Control *first = _Watchdog_First( header ); if ( units < first->delta_interval ) { diff --git a/cpukit/score/src/watchdogadjusttochain.c b/cpukit/score/src/watchdogadjusttochain.c index 1cddcbc637..1926656ca3 100644 --- a/cpukit/score/src/watchdogadjusttochain.c +++ b/cpukit/score/src/watchdogadjusttochain.c @@ -18,14 +18,13 @@ #include "config.h" #endif -#include -#include #include +#include void _Watchdog_Adjust_to_chain( - Chain_Control *header, - Watchdog_Interval units_arg, - Chain_Control *to_fire + Watchdog_Header *header, + Watchdog_Interval units_arg, + Chain_Control *to_fire ) { @@ -36,7 +35,7 @@ void _Watchdog_Adjust_to_chain( _ISR_Disable( level ); while ( 1 ) { - if ( _Chain_Is_empty( header ) ) { + if ( _Watchdog_Is_empty( header ) ) { break; } first = _Watchdog_First( header ); @@ -63,7 +62,7 @@ void _Watchdog_Adjust_to_chain( _ISR_Flash( level ); - if ( _Chain_Is_empty( header ) ) + if ( _Watchdog_Is_empty( header ) ) break; first = _Watchdog_First( header ); if ( first->delta_interval != 0 ) diff --git a/cpukit/score/src/watchdoginsert.c b/cpukit/score/src/watchdoginsert.c index 3169c80a37..272cac8db1 100644 --- a/cpukit/score/src/watchdoginsert.c +++ b/cpukit/score/src/watchdoginsert.c @@ -18,12 +18,12 @@ #include "config.h" #endif -#include -#include #include +#include +#include void _Watchdog_Insert( - Chain_Control *header, + Watchdog_Header *header, Watchdog_Control *the_watchdog ) { diff --git a/cpukit/score/src/watchdogtickle.c b/cpukit/score/src/watchdogtickle.c index 8e410a5399..8c1a3a74b9 100644 --- a/cpukit/score/src/watchdogtickle.c +++ b/cpukit/score/src/watchdogtickle.c @@ -18,12 +18,11 @@ #include "config.h" #endif -#include -#include #include +#include void _Watchdog_Tickle( - Chain_Control *header + Watchdog_Header *header ) { ISR_Level level; @@ -38,7 +37,7 @@ void _Watchdog_Tickle( _ISR_Disable( level ); - if ( _Chain_Is_empty( header ) ) + if ( _Watchdog_Is_empty( header ) ) goto leave; the_watchdog = _Watchdog_First( header ); @@ -110,7 +109,7 @@ void _Watchdog_Tickle( _ISR_Disable( level ); the_watchdog = _Watchdog_First( header ); - } while ( !_Chain_Is_empty( header ) && + } while ( !_Watchdog_Is_empty( header ) && (the_watchdog->delta_interval == 0) ); leave: -- cgit v1.2.3