changeset 2351:b96d8e8b904e

Use mutex for exclusion instead of DSR lock
author gthomas
date Sun, 14 Jan 2007 12:17:26 +0000
parents 25616cc0f362
children bafbb0c01fb4
files packages/io/wallclock/current/ChangeLog packages/io/wallclock/current/src/wallclock.cxx
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/packages/io/wallclock/current/ChangeLog
+++ b/packages/io/wallclock/current/ChangeLog
@@ -1,3 +1,10 @@
+2007-01-14  Gary Thomas  <gary@mlbassoc.com>
+
+	* src/wallclock.cxx: Use a mutex for exclusion during get/set
+	operations as the DSR lock may not be appropriate for systems
+	that need to use interrupts to accomplish these functions,
+	(e.g. I2C clock devices).
+
 2003-09-23  Dan Jakubiec <firstname.lastname@systech.com>
 
 	* src/emulate.cxx (get_hw_seconds): Modified the ticks-to-seconds
--- a/packages/io/wallclock/current/src/wallclock.cxx
+++ b/packages/io/wallclock/current/src/wallclock.cxx
@@ -87,6 +87,8 @@ static cyg_uint32 epoch_ticks;
 static cyg_uint32 epoch_time_stamp;
 #endif
 
+static cyg_drv_mutex_t wallclock_lock;
+
 Cyg_WallClock *Cyg_WallClock::wallclock;
 
 //-----------------------------------------------------------------------------
@@ -97,6 +99,9 @@ Cyg_WallClock::Cyg_WallClock()
     // install instance pointer
     wallclock = &wallclock_instance;
 
+    // Initialize lock used for mutually exclusive access to hardware
+    cyg_drv_mutex_init(&wallclock_lock);
+
     // Always allow low-level driver to initialize clock, even though it
     // may not be necessary for set-get mode.
     init_hw_seconds();
@@ -111,7 +116,7 @@ cyg_uint32 Cyg_WallClock::get_current_ti
 {
     cyg_uint32 res;
 
-    cyg_drv_dsr_lock();
+    while (!cyg_drv_mutex_lock(&wallclock_lock));
 
 #ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
     res = get_hw_seconds();
@@ -119,7 +124,7 @@ cyg_uint32 Cyg_WallClock::get_current_ti
     res = epoch_time_stamp + get_hw_seconds() - epoch_ticks;
 #endif
 
-    cyg_drv_dsr_unlock();
+    cyg_drv_mutex_unlock(&wallclock_lock);
 
     return res;
 }
@@ -130,7 +135,7 @@ cyg_uint32 Cyg_WallClock::get_current_ti
 // anything up to a second to complete.
 void Cyg_WallClock::set_current_time( cyg_uint32 time_stamp )
 {
-    cyg_drv_dsr_lock();
+    while (!cyg_drv_mutex_lock(&wallclock_lock));
 
 #ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
     set_hw_seconds(time_stamp);
@@ -139,7 +144,7 @@ void Cyg_WallClock::set_current_time( cy
     epoch_ticks         = get_hw_seconds();
 #endif
 
-    cyg_drv_dsr_unlock();
+    cyg_drv_mutex_unlock(&wallclock_lock);
 }
 
 //-----------------------------------------------------------------------------