[rtems commit] score: Add _Watchdog_Acquire|Release|Flash()

Sebastian Huber sebh at rtems.org
Wed May 20 07:12:03 UTC 2015


Module:    rtems
Branch:    master
Commit:    6d2539413bcc0be45b6fb40e93b4012a1d91b58f
Changeset: http://git.rtems.org/rtems/commit/?id=6d2539413bcc0be45b6fb40e93b4012a1d91b58f

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Apr 15 16:28:42 2015 +0200

score: Add _Watchdog_Acquire|Release|Flash()

Update #2307.

---

 cpukit/score/include/rtems/score/watchdogimpl.h | 30 +++++++++++++++++++++++++
 cpukit/score/src/watchdogadjust.c               | 16 ++++++-------
 cpukit/score/src/watchdogadjusttochain.c        |  8 +++----
 cpukit/score/src/watchdoginsert.c               | 10 ++++-----
 cpukit/score/src/watchdogremove.c               |  6 ++---
 cpukit/score/src/watchdogtickle.c               | 12 +++++-----
 6 files changed, 56 insertions(+), 26 deletions(-)

diff --git a/cpukit/score/include/rtems/score/watchdogimpl.h b/cpukit/score/include/rtems/score/watchdogimpl.h
index ddd1ca4..f52b55d 100644
--- a/cpukit/score/include/rtems/score/watchdogimpl.h
+++ b/cpukit/score/include/rtems/score/watchdogimpl.h
@@ -21,6 +21,7 @@
 
 #include <rtems/score/watchdog.h>
 #include <rtems/score/chainimpl.h>
+#include <rtems/score/isrlock.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -49,6 +50,11 @@ extern "C" {
  */
 typedef struct {
   /**
+   * @brief ISR lock to protect this watchdog chain.
+   */
+  ISR_LOCK_MEMBER( Lock )
+
+  /**
    * @brief The chain of active or transient watchdogs.
    */
   Chain_Control Watchdogs;
@@ -84,6 +90,30 @@ SCORE_EXTERN Watchdog_Header _Watchdog_Ticks_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.
  *
diff --git a/cpukit/score/src/watchdogadjust.c b/cpukit/score/src/watchdogadjust.c
index 687f063..04fc1a5 100644
--- a/cpukit/score/src/watchdogadjust.c
+++ b/cpukit/score/src/watchdogadjust.c
@@ -27,15 +27,15 @@ void _Watchdog_Adjust_backward(
   Watchdog_Interval  units
 )
 {
-  ISR_Level level;
+  ISR_lock_Context lock_context;
 
-  _ISR_Disable( level );
+  _Watchdog_Acquire( header, &lock_context );
 
   if ( !_Watchdog_Is_empty( header ) ) {
      _Watchdog_First( header )->delta_interval += units;
   }
 
-  _ISR_Enable( level );
+  _Watchdog_Release( header, &lock_context );
 }
 
 void _Watchdog_Adjust_forward(
@@ -43,9 +43,9 @@ void _Watchdog_Adjust_forward(
   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 ) {
     Watchdog_Control *first = _Watchdog_First( header );
@@ -57,13 +57,13 @@ void _Watchdog_Adjust_forward(
       units -= first->delta_interval;
       first->delta_interval = 1;
 
-      _ISR_Enable( level );
+      _Watchdog_Release( header, &lock_context );
 
       _Watchdog_Tickle( header );
 
-      _ISR_Disable( level );
+      _Watchdog_Acquire( header, &lock_context );
     }
   }
 
-  _ISR_Enable( level );
+  _Watchdog_Release( header, &lock_context );
 }
diff --git a/cpukit/score/src/watchdogadjusttochain.c b/cpukit/score/src/watchdogadjusttochain.c
index 1926656..b3063e4 100644
--- a/cpukit/score/src/watchdogadjusttochain.c
+++ b/cpukit/score/src/watchdogadjusttochain.c
@@ -29,10 +29,10 @@ void _Watchdog_Adjust_to_chain(
 )
 {
   Watchdog_Interval  units = units_arg;
-  ISR_Level          level;
+  ISR_lock_Context   lock_context;
   Watchdog_Control  *first;
 
-  _ISR_Disable( level );
+  _Watchdog_Acquire( header, &lock_context );
 
   while ( 1 ) {
     if ( _Watchdog_Is_empty( header ) ) {
@@ -60,7 +60,7 @@ void _Watchdog_Adjust_to_chain(
       _Chain_Extract_unprotected( &first->Node );
       _Chain_Append_unprotected( to_fire, &first->Node );
 
-      _ISR_Flash( level );
+      _Watchdog_Flash( header, &lock_context );
 
       if ( _Watchdog_Is_empty( header ) )
         break;
@@ -70,6 +70,6 @@ void _Watchdog_Adjust_to_chain(
     }
   }
 
-  _ISR_Enable( level );
+  _Watchdog_Release( header, &lock_context );
 }
 
diff --git a/cpukit/score/src/watchdoginsert.c b/cpukit/score/src/watchdoginsert.c
index 272cac8..0ad59ff 100644
--- a/cpukit/score/src/watchdoginsert.c
+++ b/cpukit/score/src/watchdoginsert.c
@@ -27,7 +27,7 @@ void _Watchdog_Insert(
   Watchdog_Control      *the_watchdog
 )
 {
-  ISR_Level          level;
+  ISR_lock_Context   lock_context;
   Watchdog_Control  *after;
   uint32_t           insert_isr_nest_level;
   Watchdog_Interval  delta_interval;
@@ -35,7 +35,7 @@ void _Watchdog_Insert(
 
   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
@@ -43,7 +43,7 @@ void _Watchdog_Insert(
    */
 
   if ( the_watchdog->state != WATCHDOG_INACTIVE ) {
-    _ISR_Enable( level );
+    _Watchdog_Release( header, &lock_context );
     return;
   }
 
@@ -67,7 +67,7 @@ restart:
 
      delta_interval -= after->delta_interval;
 
-     _ISR_Flash( level );
+     _Watchdog_Flash( header, &lock_context );
 
      if ( the_watchdog->state != WATCHDOG_BEING_INSERTED ) {
        goto exit_insert;
@@ -90,5 +90,5 @@ restart:
 exit_insert:
   _Watchdog_Sync_level = insert_isr_nest_level;
   _Watchdog_Sync_count--;
-  _ISR_Enable( level );
+  _Watchdog_Release( header, &lock_context );
 }
diff --git a/cpukit/score/src/watchdogremove.c b/cpukit/score/src/watchdogremove.c
index d689e3c..c765ac5 100644
--- a/cpukit/score/src/watchdogremove.c
+++ b/cpukit/score/src/watchdogremove.c
@@ -27,11 +27,11 @@ Watchdog_States _Watchdog_Remove(
   Watchdog_Control *the_watchdog
 )
 {
-  ISR_Level         level;
+  ISR_lock_Context  lock_context;
   Watchdog_States   previous_state;
   Watchdog_Control *next_watchdog;
 
-  _ISR_Disable( level );
+  _Watchdog_Acquire( header, &lock_context );
   previous_state = the_watchdog->state;
   switch ( previous_state ) {
     case WATCHDOG_INACTIVE:
@@ -63,6 +63,6 @@ Watchdog_States _Watchdog_Remove(
   }
   the_watchdog->stop_time = _Watchdog_Ticks_since_boot;
 
-  _ISR_Enable( level );
+  _Watchdog_Release( header, &lock_context );
   return( previous_state );
 }
diff --git a/cpukit/score/src/watchdogtickle.c b/cpukit/score/src/watchdogtickle.c
index 5b2f258..2092010 100644
--- a/cpukit/score/src/watchdogtickle.c
+++ b/cpukit/score/src/watchdogtickle.c
@@ -25,9 +25,9 @@ void _Watchdog_Tickle(
   Watchdog_Header *header
 )
 {
-  ISR_Level level;
+  ISR_lock_Context  lock_context;
   Watchdog_Control *the_watchdog;
-  Watchdog_States  watchdog_state;
+  Watchdog_States   watchdog_state;
 
   /*
    * See the comment in watchdoginsert.c and watchdogadjust.c
@@ -35,7 +35,7 @@ void _Watchdog_Tickle(
    * volatile data - till, 2003/7
    */
 
-  _ISR_Disable( level );
+  _Watchdog_Acquire( header, &lock_context );
 
   if ( _Watchdog_Is_empty( header ) )
     goto leave;
@@ -76,7 +76,7 @@ void _Watchdog_Tickle(
   do {
      watchdog_state = _Watchdog_Remove( header, the_watchdog );
 
-     _ISR_Enable( level );
+     _Watchdog_Release( header, &lock_context );
 
      switch( watchdog_state ) {
        case WATCHDOG_ACTIVE:
@@ -106,12 +106,12 @@ void _Watchdog_Tickle(
          break;
      }
 
-     _ISR_Disable( level );
+     _Watchdog_Acquire( header, &lock_context );
 
      the_watchdog = _Watchdog_First( header );
    } while ( !_Watchdog_Is_empty( header ) &&
              (the_watchdog->delta_interval == 0) );
 
 leave:
-   _ISR_Enable(level);
+   _Watchdog_Release( header, &lock_context );
 }



More information about the vc mailing list