]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Added volume valid check. Verified operation with telos and micaz
authorprabal <prabal>
Fri, 6 Apr 2007 02:48:44 +0000 (02:48 +0000)
committerprabal <prabal>
Fri, 6 Apr 2007 02:48:44 +0000 (02:48 +0000)
apps/tutorials/BlinkConfig/BlinkConfigC.nc
apps/tutorials/BlinkConfig/README.txt

index 13cb987f2902bee1fabf3f9a7fb6ce57e08df19f..928e89820d783fba1b182542358fdf4826f6ec29 100644 (file)
@@ -52,26 +52,42 @@ implementation {
   enum {
     CONFIG_ADDR = 0,
     CONFIG_VERSION = 1,
-    DEFAULT_PERIOD = 1024
+    DEFAULT_PERIOD = 1024,
+    MIN_PERIOD     = 128,
+    MAX_PERIOD     = 1024
   };
 
   uint8_t state;
   config_t conf;
 
   event void Boot.booted() {
+    conf.period = DEFAULT_PERIOD;
+
     if (call Mount.mount() != SUCCESS) {
       // Handle failure
     }
   }
 
   event void Mount.mountDone(error_t error) {
-    if (error != SUCCESS) {
-      // Handle failure
+    if (error == SUCCESS) {
+      if (call Config.valid() == TRUE) {
+        if (call Config.read(CONFIG_ADDR, &conf, sizeof(conf)) != SUCCESS) {
+          // Handle failure
+       }
+      }
+      else {
+       // Invalid volume.  Commit to make valid.
+       call Leds.led1On();
+       if (call Config.commit() == SUCCESS) {
+         call Leds.led0On();
+       }
+       else {
+         // Handle failure
+       }
+      }
     }
     else{
-      if (call Config.read(CONFIG_ADDR, &conf, sizeof(conf)) != SUCCESS) {
-       // Handle failure
-      }
+      // Handle failure
     }
   }
 
@@ -81,7 +97,9 @@ implementation {
     if (err == SUCCESS) {
       memcpy(&conf, buf, len);
       if (conf.version == CONFIG_VERSION) {
-        conf.period = conf.period > 128 ? conf.period/2 : DEFAULT_PERIOD;
+        conf.period = conf.period/2;
+       conf.period = conf.period > MAX_PERIOD ? MAX_PERIOD : conf.period;
+        conf.period = conf.period < MIN_PERIOD ? MAX_PERIOD : conf.period;
       }
       else {
         // Version mismatch. Restore default.
index 07de82855656f2679ace854989d10cc957c6a2e9..01a02ae3249ee6b207419057e0b23659db74f7f4 100644 (file)
@@ -1,4 +1,4 @@
-$Id$: README.txt,v 1.5 2006/12/12 18:22:52 vlahan Exp $
+$Id$
 
 README for Config
 Author/Contact: tinyos-help@millennium.berkeley.edu
@@ -19,13 +19,15 @@ Description:
           blink rate cycles through the following values: 1Hz, 2Hz, 4Hz, 
           and 8Hz.
 
-  The first time this application is installed, the green LED will
-  light up and remain on (indicating that the configuration storage
-  volume did not have the expected version number).
+  The first two times this application is installed, the green LED
+  will light up and remain on (the first time indicating that the
+  storage volume is not valid and second time that the volume does not
+  have the expected version number).
 
   The red LED will remain lit during the flash write/commit operation.
 
-  The blue (yellow) LED blinks at the period stored and read from flash.
+  The blue (yellow) LED blinks with the period stored and read from
+  flash.
 
   See Lesson 7 for details.