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
}
}
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.
-$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
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.