From f9cbe56bab883ead465349630e7680ac97c30564 Mon Sep 17 00:00:00 2001 From: prabal Date: Fri, 6 Apr 2007 02:48:44 +0000 Subject: [PATCH] Added volume valid check. Verified operation with telos and micaz --- apps/tutorials/BlinkConfig/BlinkConfigC.nc | 32 +++++++++++++++++----- apps/tutorials/BlinkConfig/README.txt | 12 ++++---- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/apps/tutorials/BlinkConfig/BlinkConfigC.nc b/apps/tutorials/BlinkConfig/BlinkConfigC.nc index 13cb987f..928e8982 100644 --- a/apps/tutorials/BlinkConfig/BlinkConfigC.nc +++ b/apps/tutorials/BlinkConfig/BlinkConfigC.nc @@ -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. diff --git a/apps/tutorials/BlinkConfig/README.txt b/apps/tutorials/BlinkConfig/README.txt index 07de8285..01a02ae3 100644 --- a/apps/tutorials/BlinkConfig/README.txt +++ b/apps/tutorials/BlinkConfig/README.txt @@ -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. -- 2.39.2