From 54266a2025b5e1246459c8d625b96f3294362425 Mon Sep 17 00:00:00 2001 From: idgay Date: Wed, 11 Jul 2007 18:10:34 +0000 Subject: [PATCH] Sync test for flash logs --- apps/tests/storage/SyncLog/Makefile | 2 + apps/tests/storage/SyncLog/README.txt | 26 ++++ apps/tests/storage/SyncLog/SyncLogAppC.nc | 26 ++++ apps/tests/storage/SyncLog/SyncLogC.nc | 122 ++++++++++++++++++ apps/tests/storage/SyncLog/volumes-at45db.xml | 3 + .../storage/SyncLog/volumes-pxa27xp30.xml | 3 + apps/tests/storage/SyncLog/volumes-stm25p.xml | 3 + 7 files changed, 185 insertions(+) create mode 100644 apps/tests/storage/SyncLog/Makefile create mode 100644 apps/tests/storage/SyncLog/README.txt create mode 100644 apps/tests/storage/SyncLog/SyncLogAppC.nc create mode 100644 apps/tests/storage/SyncLog/SyncLogC.nc create mode 100644 apps/tests/storage/SyncLog/volumes-at45db.xml create mode 100644 apps/tests/storage/SyncLog/volumes-pxa27xp30.xml create mode 100644 apps/tests/storage/SyncLog/volumes-stm25p.xml diff --git a/apps/tests/storage/SyncLog/Makefile b/apps/tests/storage/SyncLog/Makefile new file mode 100644 index 00000000..911fac19 --- /dev/null +++ b/apps/tests/storage/SyncLog/Makefile @@ -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 index 00000000..68410cbd --- /dev/null +++ b/apps/tests/storage/SyncLog/README.txt @@ -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-.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@ 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 index 00000000..a8b7eb17 --- /dev/null +++ b/apps/tests/storage/SyncLog/SyncLogAppC.nc @@ -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 index 00000000..8a8aad60 --- /dev/null +++ b/apps/tests/storage/SyncLog/SyncLogC.nc @@ -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 as Timer0; + interface Timer 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 index 00000000..d5dd77c2 --- /dev/null +++ b/apps/tests/storage/SyncLog/volumes-at45db.xml @@ -0,0 +1,3 @@ + + + diff --git a/apps/tests/storage/SyncLog/volumes-pxa27xp30.xml b/apps/tests/storage/SyncLog/volumes-pxa27xp30.xml new file mode 100644 index 00000000..d5dd77c2 --- /dev/null +++ b/apps/tests/storage/SyncLog/volumes-pxa27xp30.xml @@ -0,0 +1,3 @@ + + + diff --git a/apps/tests/storage/SyncLog/volumes-stm25p.xml b/apps/tests/storage/SyncLog/volumes-stm25p.xml new file mode 100644 index 00000000..d5dd77c2 --- /dev/null +++ b/apps/tests/storage/SyncLog/volumes-stm25p.xml @@ -0,0 +1,3 @@ + + + -- 2.39.2