[Tinyos-2-commits] CVS: tinyos-2.x/apps/tutorials/BlinkConfig
BlinkConfigAppC.nc, 1.4, 1.5 BlinkConfigC.nc, 1.4,
1.5 README.txt, 1.5, 1.6
Prabal Dutta
prabal at users.sourceforge.net
Thu Apr 5 18:14:01 PDT 2007
- Previous message: [Tinyos-2-commits]
CVS: tinyos-2.x/apps/tests/msp430/Adc12 Makefile, NONE,
1.1 TestAdcAppC.nc, NONE, 1.1 TestAdcC.nc, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/apps/tutorials/BlinkConfig
BlinkConfigC.nc, 1.5, 1.6 README.txt, 1.6, 1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-2.x/apps/tutorials/BlinkConfig
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2518
Modified Files:
BlinkConfigAppC.nc BlinkConfigC.nc README.txt
Log Message:
New tutorial
Index: BlinkConfigAppC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/apps/tutorials/BlinkConfig/BlinkConfigAppC.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** BlinkConfigAppC.nc 12 Dec 2006 18:22:52 -0000 1.4
--- BlinkConfigAppC.nc 6 Apr 2007 01:13:59 -0000 1.5
***************
*** 25,36 ****
*/
#include "StorageVolumes.h"
/**
! * Application to demonstrate the ConfigStorageC abstraction. A value
! * is written to, and read from, the flash storage. A successful test
! * will turn on both the green and blue (yellow) LEDs. A failed test
! * is any other LED configuration.
*
! * @author Prabal Dutta
*/
configuration BlinkConfigAppC {
--- 25,36 ----
*/
#include "StorageVolumes.h"
+ #include "Timer.h"
/**
! * Application to demonstrate the ConfigStorageC abstraction. A timer
! * period is read from flash, divided by two, and written back to
! * flash. An LED is toggled each time the timer fires.
*
! * @author Prabal Dutta <prabal at cs.berkeley.edu>
*/
configuration BlinkConfigAppC {
***************
*** 40,50 ****
components new ConfigStorageC(VOLUME_CONFIGTEST);
components MainC, LedsC, PlatformC, SerialActiveMessageC;
! App.Boot -> MainC.Boot;
!
! App.AMControl -> SerialActiveMessageC;
! App.AMSend -> SerialActiveMessageC.AMSend[1];
! App.Config -> ConfigStorageC.ConfigStorage;
! App.Mount -> ConfigStorageC.Mount;
! App.Leds -> LedsC;
}
--- 40,49 ----
components new ConfigStorageC(VOLUME_CONFIGTEST);
components MainC, LedsC, PlatformC, SerialActiveMessageC;
+ components new TimerMilliC() as Timer0;
! App.Boot -> MainC.Boot;
! App.Config -> ConfigStorageC.ConfigStorage;
! App.Mount -> ConfigStorageC.Mount;
! App.Leds -> LedsC;
! App.Timer0 -> Timer0;
}
Index: BlinkConfigC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/apps/tutorials/BlinkConfig/BlinkConfigC.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** BlinkConfigC.nc 12 Dec 2006 18:22:52 -0000 1.4
--- BlinkConfigC.nc 6 Apr 2007 01:13:59 -0000 1.5
***************
*** 26,36 ****
/**
! * Application to demonstrate the ConfigStorageC abstraction. A value
! * is written to, and read from, the flash storage. A successful test
! * will turn on both the green and blue (yellow) LEDs. A failed test
! * is any other LED combination..
*
! * @author Prabal Dutta
*/
module BlinkConfigC {
uses {
--- 26,37 ----
/**
! * Application to demonstrate the ConfigStorageC abstraction. A timer
! * period is read from flash, divided by two, and written back to
! * flash. An LED is toggled each time the timer fires.
*
! * @author Prabal Dutta <prabal at cs.berkeley.edu>
*/
+ #include <Timer.h>
+
module BlinkConfigC {
uses {
***************
*** 38,62 ****
interface Leds;
interface ConfigStorage as Config;
- interface AMSend;
- interface SplitControl as AMControl;
interface Mount as Mount;
}
}
implementation {
! uint16_t period = 2048;
! uint16_t period2 = 1024;
enum {
CONFIG_ADDR = 0,
};
! event void Boot.booted() {
! call AMControl.start();
! }
! event void AMControl.startDone(error_t error) {
! if (error != SUCCESS) {
! call AMControl.start();
! }
if (call Mount.mount() != SUCCESS) {
// Handle failure
--- 39,63 ----
interface Leds;
interface ConfigStorage as Config;
interface Mount as Mount;
+ interface Timer<TMilli> as Timer0;
}
}
implementation {
!
! typedef struct config_t {
! uint16_t version;
! uint16_t period;
! } config_t;
enum {
CONFIG_ADDR = 0,
+ CONFIG_VERSION = 1,
+ DEFAULT_PERIOD = 1024
};
! uint8_t state;
! config_t conf;
! event void Boot.booted() {
if (call Mount.mount() != SUCCESS) {
// Handle failure
***************
*** 69,117 ****
}
else{
! call Config.write(CONFIG_ADDR, &period, sizeof(period));
}
}
! event void Config.writeDone(storage_addr_t addr, void *buf,
! storage_len_t len, error_t result) {
! // Verify addr and len
! if (result == SUCCESS) {
! // Note success
}
else {
! // Handle failure
! }
! if (call Config.commit() != SUCCESS) {
! // Handle failure
! }
! }
!
! event void Config.commitDone(error_t error) {
! if (call Config.read(CONFIG_ADDR, &period2, sizeof(period2)) != SUCCESS) {
! // Handle failure
}
}
! event void Config.readDone(storage_addr_t addr, void* buf,
! storage_len_t len, error_t result) __attribute__((noinline)) {
! memcpy(&period2, buf, len);
! if (period == period2) {
! call Leds.led2On();
}
!
! if (len == 2 && addr == CONFIG_ADDR) {
! call Leds.led1On();
}
}
! event void AMSend.sendDone(message_t* msg, error_t error) {
! if (error != SUCCESS) {
! call Leds.led0On();
}
}
! event void AMControl.stopDone(error_t error) {
}
}
--- 70,125 ----
}
else{
! if (call Config.read(CONFIG_ADDR, &conf, sizeof(conf)) != SUCCESS) {
! // Handle failure
! }
}
}
! event void Config.readDone(storage_addr_t addr, void* buf,
! storage_len_t len, error_t err) __attribute__((noinline)) {
! if (err == SUCCESS) {
! memcpy(&conf, buf, len);
! if (conf.version == CONFIG_VERSION) {
! conf.period = conf.period > 128 ? conf.period/2 : DEFAULT_PERIOD;
! }
! else {
! // Version mismatch. Restore default.
! call Leds.led1On();
! conf.version = CONFIG_VERSION;
! conf.period = DEFAULT_PERIOD;
! }
! call Leds.led0On();
! call Config.write(CONFIG_ADDR, &conf, sizeof(conf));
}
else {
! // Handle failure.
}
}
! event void Config.writeDone(storage_addr_t addr, void *buf,
! storage_len_t len, error_t err) {
! // Verify addr and len
! if (err == SUCCESS) {
! if (call Config.commit() != SUCCESS) {
! // Handle failure
! }
}
! else {
! // Handle failure
}
}
! event void Config.commitDone(error_t err) {
! call Leds.led0Off();
! call Timer0.startPeriodic(conf.period);
! if (err == SUCCESS) {
! // Handle failure
}
}
! event void Timer0.fired() {
! call Leds.led2Toggle();
}
}
Index: README.txt
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/apps/tutorials/BlinkConfig/README.txt,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** README.txt 12 Dec 2006 18:22:52 -0000 1.5
--- README.txt 6 Apr 2007 01:13:59 -0000 1.6
***************
*** 1,3 ****
! $Id$
README for Config
--- 1,3 ----
! $Id$: README.txt,v 1.5 2006/12/12 18:22:52 vlahan Exp $
README for Config
***************
*** 6,14 ****
Description:
! Application to demonstrate the ConfigStorageC abstraction. A value is
! written to, and read from, the flash storage.
! A successful test will turn on both the green and blue (yellow)
! LEDs. A failed test is any other LED combination.
Tools:
--- 6,32 ----
Description:
! Application to demonstrate the ConfigStorageC abstraction. A timer
! period is read from flash, divided by two, and written back to
! flash. An LED is toggled each time the timer fires.
! To use this application:
!
! (i) Program a mote with this application (e.g. make telos install)
! (ii) Wait until the red LED turns off (writing to flash is done)
! (iii) Power cycle the mote and wait until the red LED turns off.
! (iv) Repeat step (iii) and notice that the blink rate of the blue
! (yellow) LED doubles each time the mote is power cycled. The
! 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 red LED will remain lit during the flash write/commit operation.
!
! The blue (yellow) LED blinks at the period stored and read from flash.
!
! See Lesson 7 for details.
Tools:
- Previous message: [Tinyos-2-commits]
CVS: tinyos-2.x/apps/tests/msp430/Adc12 Makefile, NONE,
1.1 TestAdcAppC.nc, NONE, 1.1 TestAdcC.nc, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/apps/tutorials/BlinkConfig
BlinkConfigC.nc, 1.5, 1.6 README.txt, 1.6, 1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-2-commits
mailing list