]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Sync test for flash logs
authoridgay <idgay>
Wed, 11 Jul 2007 18:10:34 +0000 (18:10 +0000)
committeridgay <idgay>
Wed, 11 Jul 2007 18:10:34 +0000 (18:10 +0000)
apps/tests/storage/SyncLog/Makefile [new file with mode: 0644]
apps/tests/storage/SyncLog/README.txt [new file with mode: 0644]
apps/tests/storage/SyncLog/SyncLogAppC.nc [new file with mode: 0644]
apps/tests/storage/SyncLog/SyncLogC.nc [new file with mode: 0644]
apps/tests/storage/SyncLog/volumes-at45db.xml [new file with mode: 0644]
apps/tests/storage/SyncLog/volumes-pxa27xp30.xml [new file with mode: 0644]
apps/tests/storage/SyncLog/volumes-stm25p.xml [new file with mode: 0644]

diff --git a/apps/tests/storage/SyncLog/Makefile b/apps/tests/storage/SyncLog/Makefile
new file mode 100644 (file)
index 0000000..911fac1
--- /dev/null
@@ -0,0 +1,2 @@
+COMPONENT=SyncLogAppC
+include $(MAKERULES)
diff --git a/apps/tests/storage/SyncLog/README.txt b/apps/tests/storage/SyncLog/README.txt
new file mode 100644 (file)
index 0000000..68410cb
--- /dev/null
@@ -0,0 +1,26 @@
+README for Log
+Author/Contact: tinyos-help@millennium.berkeley.edu
+
+Description:
+
+Application to test 'sync' functionality in the LogStorageC
+abstraction, using the log in linear mode. There must be a
+volumes-<chip>.xml file in this directory describing a 64kB volume
+named SYNCLOG for your flash chip.
+
+A successful test will send serial messages (id 11) with increasing
+sequence numbers (approximately 2 messages every 5 seconds) - the
+easiest way to see these messages is to connect the mote with the
+SyncLog code to your PC and run the java Listen tool:
+  MOTECOM=serial@<your mote details> java net.tinyos.tools.Listen
+
+This test is based on code and a bug report from Mayur Maheshwari
+(mayur.maheshwari@gmail.com).
+
+Tools:
+
+Known bugs/limitations:
+
+None.
+
+$Id$
diff --git a/apps/tests/storage/SyncLog/SyncLogAppC.nc b/apps/tests/storage/SyncLog/SyncLogAppC.nc
new file mode 100644 (file)
index 0000000..a8b7eb1
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * Test reading and writing to a log with lots of syncs. See README.txt for
+ * more details.
+ *
+ * @author Mayur Maheshwari (mayur.maheshwari@gmail.com)
+ * @author David Gay
+ */
+
+#include "StorageVolumes.h"
+
+configuration SyncLogAppC { }
+implementation {
+  components SyncLogC,
+    new TimerMilliC() as Timer0, new TimerMilliC() as Timer1,
+    new LogStorageC(VOLUME_SYNCLOG, FALSE), SerialActiveMessageC,
+    MainC, LedsC;
+
+  SyncLogC.Leds -> LedsC;
+  SyncLogC.Boot -> MainC;
+  SyncLogC.Timer0 -> Timer0;
+  SyncLogC.Timer1 -> Timer1;
+  SyncLogC.LogWrite -> LogStorageC;
+  SyncLogC.LogRead -> LogStorageC;
+  SyncLogC.AMSend -> SerialActiveMessageC.AMSend[11];
+  SyncLogC.AMControl -> SerialActiveMessageC;
+}
diff --git a/apps/tests/storage/SyncLog/SyncLogC.nc b/apps/tests/storage/SyncLog/SyncLogC.nc
new file mode 100644 (file)
index 0000000..8a8aad6
--- /dev/null
@@ -0,0 +1,122 @@
+/**
+ * Test reading and writing to a log with lots of syncs. See README.txt for
+ * more details.
+ *
+ * @author Mayur Maheshwari (mayur.maheshwari@gmail.com)
+ * @author David Gay
+ */
+
+module SyncLogC
+{
+  uses {
+    interface Leds;
+    interface Boot;
+    interface SplitControl as AMControl;
+    interface LogWrite;
+    interface LogRead;
+    interface Timer<TMilli> as Timer0;
+    interface Timer<TMilli> as Timer1;
+    interface AMSend;
+  }
+}
+implementation {
+
+  uint16_t data = 0;
+  uint16_t readings = 0;
+  message_t pkt;
+  bool busy = FALSE;
+  bool logBusy = FALSE;
+
+  task void sendTask();
+
+  storage_cookie_t readCookie;
+  storage_cookie_t writeCookie;
+
+#define SAMPLING_FREQUENCY 2333
+#define TIMER_PERIOD_MILLI 5120
+
+  event void Boot.booted() {
+    call AMControl.start();
+  }
+
+  event void AMControl.startDone(error_t err) {
+    if (err == SUCCESS)
+      call LogWrite.erase();
+    else
+      call AMControl.start();
+  }
+
+  event void LogWrite.eraseDone(error_t result) {
+    call Timer1.startPeriodic(SAMPLING_FREQUENCY);
+    call Timer0.startPeriodic(TIMER_PERIOD_MILLI);
+  }
+  
+  event void Timer1.fired()
+  {
+    readings++;
+    if (!logBusy)
+      {
+       logBusy = TRUE;
+       call LogWrite.append(&readings, sizeof(readings));
+      }
+  }
+
+  event void LogWrite.appendDone(void *buf, storage_len_t len, bool recordsLost, error_t result) {
+    if (result == SUCCESS)
+      call LogWrite.sync();
+  }
+
+  event void LogWrite.syncDone(error_t result) {
+    logBusy = FALSE;
+    call Leds.led2Toggle();
+  }
+
+  event void Timer0.fired() {
+    call Timer1.stop();
+    if (!logBusy)
+      {
+       call Leds.led0Toggle();
+       logBusy = TRUE;
+       call LogRead.read(&data, sizeof data);
+      }
+  }
+
+  event void LogRead.readDone(void* buf, storage_len_t len, error_t error) {
+    if (error == SUCCESS)
+      if (len == sizeof data)
+       post sendTask();
+      else
+       {
+         logBusy = FALSE;
+         call Timer1.startPeriodic(SAMPLING_FREQUENCY);
+       }
+  }
+
+  typedef nx_struct {
+    nx_uint16_t nodeid;
+    nx_uint16_t payloadData;
+  } SenseStoreRadioMsg;
+
+  task void sendTask() {
+    if (!busy)
+      {
+       SenseStoreRadioMsg* ssrpkt =
+         (SenseStoreRadioMsg*)(call AMSend.getPayload(&pkt));
+       ssrpkt->nodeid = TOS_NODE_ID;
+       ssrpkt->payloadData = data;
+       if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(SenseStoreRadioMsg)) == SUCCESS)
+         busy = TRUE;
+      }
+  }
+
+  event void AMSend.sendDone(message_t* msg, error_t err) {
+    if (&pkt == msg)
+      {
+       busy = FALSE;
+       call LogRead.read(&data, sizeof data);
+      }
+  }
+
+  event void LogRead.seekDone(error_t error) { }
+  event void AMControl.stopDone(error_t err) { }
+}
diff --git a/apps/tests/storage/SyncLog/volumes-at45db.xml b/apps/tests/storage/SyncLog/volumes-at45db.xml
new file mode 100644 (file)
index 0000000..d5dd77c
--- /dev/null
@@ -0,0 +1,3 @@
+<volume_table>
+  <volume name="SYNCLOG" size="65536"/>
+</volume_table>
diff --git a/apps/tests/storage/SyncLog/volumes-pxa27xp30.xml b/apps/tests/storage/SyncLog/volumes-pxa27xp30.xml
new file mode 100644 (file)
index 0000000..d5dd77c
--- /dev/null
@@ -0,0 +1,3 @@
+<volume_table>
+  <volume name="SYNCLOG" size="65536"/>
+</volume_table>
diff --git a/apps/tests/storage/SyncLog/volumes-stm25p.xml b/apps/tests/storage/SyncLog/volumes-stm25p.xml
new file mode 100644 (file)
index 0000000..d5dd77c
--- /dev/null
@@ -0,0 +1,3 @@
+<volume_table>
+  <volume name="SYNCLOG" size="65536"/>
+</volume_table>