]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Tutorial Applications
authorprabal <prabal>
Sun, 5 Nov 2006 08:01:02 +0000 (08:01 +0000)
committerprabal <prabal>
Sun, 5 Nov 2006 08:01:02 +0000 (08:01 +0000)
apps/tutorials/BlinkConfig/BlinkConfigAppC.nc [new file with mode: 0644]
apps/tutorials/BlinkConfig/BlinkConfigC.nc [new file with mode: 0644]
apps/tutorials/BlinkConfig/Makefile [new file with mode: 0644]
apps/tutorials/BlinkConfig/README.txt [new file with mode: 0644]
apps/tutorials/BlinkConfig/volumes-at45db.xml [new file with mode: 0644]
apps/tutorials/BlinkConfig/volumes-stm25p.xml [new file with mode: 0644]

diff --git a/apps/tutorials/BlinkConfig/BlinkConfigAppC.nc b/apps/tutorials/BlinkConfig/BlinkConfigAppC.nc
new file mode 100644 (file)
index 0000000..46c7596
--- /dev/null
@@ -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 (file)
index 0000000..394f5b2
--- /dev/null
@@ -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 (file)
index 0000000..eda3bcd
--- /dev/null
@@ -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 (file)
index 0000000..0133215
--- /dev/null
@@ -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 (file)
index 0000000..7cc5980
--- /dev/null
@@ -0,0 +1,4 @@
+<volume_table>
+  <volume name="LOGTEST" size="262144"/>
+  <volume name="CONFIGTEST" size="4608"/>
+</volume_table>
diff --git a/apps/tutorials/BlinkConfig/volumes-stm25p.xml b/apps/tutorials/BlinkConfig/volumes-stm25p.xml
new file mode 100644 (file)
index 0000000..adce992
--- /dev/null
@@ -0,0 +1,4 @@
+<volume_table>
+  <volume name="LOGTEST" size="262144"/>
+  <volume name="CONFIGTEST" size="131072"/>
+</volume_table>