From: prabal Date: Sun, 5 Nov 2006 08:01:02 +0000 (+0000) Subject: Tutorial Applications X-Git-Tag: tinyos/2.0.1~270 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=0c1c86677fc063ff667e4a2a59c5c0070223138f Tutorial Applications --- diff --git a/apps/tutorials/BlinkConfig/BlinkConfigAppC.nc b/apps/tutorials/BlinkConfig/BlinkConfigAppC.nc new file mode 100644 index 00000000..46c75967 --- /dev/null +++ b/apps/tutorials/BlinkConfig/BlinkConfigAppC.nc @@ -0,0 +1,42 @@ +// $Id$ + +/* + * "Copyright (c) 2000-2006 The Regents of the University of + * California. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose, without fee, and without written + * agreement is hereby granted, provided that the above copyright + * notice, the following two paragraphs and the author appear in all + * copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY + * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF + * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, + * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + */ +#include "StorageVolumes.h" + +configuration BlinkConfigAppC { +} +implementation { + components BlinkConfigC as App; + 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; +} diff --git a/apps/tutorials/BlinkConfig/BlinkConfigC.nc b/apps/tutorials/BlinkConfig/BlinkConfigC.nc new file mode 100644 index 00000000..394f5b2e --- /dev/null +++ b/apps/tutorials/BlinkConfig/BlinkConfigC.nc @@ -0,0 +1,109 @@ +// $Id$ + +/* + * "Copyright (c) 2000-2006 The Regents of the University of + * California. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose, without fee, and without written + * agreement is hereby granted, provided that the above copyright + * notice, the following two paragraphs and the author appear in all + * copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY + * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF + * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, + * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + */ + +module BlinkConfigC { + uses { + interface Boot; + 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 + } + } + + event void Mount.mountDone(error_t error) { + if (error != SUCCESS) { + // Handle failure + } + 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) { + } +} diff --git a/apps/tutorials/BlinkConfig/Makefile b/apps/tutorials/BlinkConfig/Makefile new file mode 100644 index 00000000..eda3bcdd --- /dev/null +++ b/apps/tutorials/BlinkConfig/Makefile @@ -0,0 +1,2 @@ +COMPONENT=BlinkConfigAppC +include $(MAKERULES) diff --git a/apps/tutorials/BlinkConfig/README.txt b/apps/tutorials/BlinkConfig/README.txt new file mode 100644 index 00000000..01332157 --- /dev/null +++ b/apps/tutorials/BlinkConfig/README.txt @@ -0,0 +1,17 @@ +$Id$ +README for Config +Author/Contact: tinyos-help@millennium.berkeley.edu + +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 will turn on the red led. + +Tools: + +Known bugs/limitations: + +None. diff --git a/apps/tutorials/BlinkConfig/volumes-at45db.xml b/apps/tutorials/BlinkConfig/volumes-at45db.xml new file mode 100644 index 00000000..7cc59802 --- /dev/null +++ b/apps/tutorials/BlinkConfig/volumes-at45db.xml @@ -0,0 +1,4 @@ + + + + diff --git a/apps/tutorials/BlinkConfig/volumes-stm25p.xml b/apps/tutorials/BlinkConfig/volumes-stm25p.xml new file mode 100644 index 00000000..adce9924 --- /dev/null +++ b/apps/tutorials/BlinkConfig/volumes-stm25p.xml @@ -0,0 +1,4 @@ + + + +