[Tinyos-commits] CVS: tinyos-1.x/apps/TestNewFlash/Block Makefile,
NONE, 1.1 README.txt, NONE, 1.1 RandRW.nc, NONE,
1.1 RandRWC.nc, NONE, 1.1
David Gay
idgay at users.sourceforge.net
Mon Jul 11 16:27:40 PDT 2005
Update of /cvsroot/tinyos/tinyos-1.x/apps/TestNewFlash/Block
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24401/Block
Added Files:
Makefile README.txt RandRW.nc RandRWC.nc
Log Message:
tests for new flash abstraction
--- NEW FILE: Makefile ---
COMPONENT=RandRWC
include ../../Makerules
--- NEW FILE: README.txt ---
Application to test the BlockStorage abstraction. You must partition the flash
chip first, by installing the TestNewFlash/Format application.
Install this application with a moteid of k*4 + 3 to do a full flash test.
If you install with an id of k*4+1, only the write portion of the test will
be performed.
If you install with an id of k*4, data from a previous installation will be
read (the test will fail if you didn't previously install with an id of
k*4+1 or k*4+3).
A successful test will blink the yellow led a few times, then turn on the
green led. A failed test will turn on the red led.
--- NEW FILE: RandRW.nc ---
/* $Id: RandRW.nc,v 1.1 2005/07/11 23:27:38 idgay Exp $
* Copyright (c) 2005 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* @author David Gay
*/
/*
address & 3:
0, 2: r
1: w
3: r&w
*/
module RandRW {
provides interface StdControl;
uses {
interface Leds;
interface Mount;
interface BlockRead;
interface BlockWrite;
}
}
implementation {
enum {
S_MOUNT,
S_ERASE,
S_WRITE,
S_COMMIT,
S_VERIFY,
S_READ
} state;
enum {
SIZE = 1024L * 256,
NWRITES = SIZE / 4096
};
uint16_t shiftReg;
uint16_t initSeed;
uint16_t mask;
/* Return the next 16 bit random number */
uint16_t rand() {
bool endbit;
uint16_t tmpShiftReg;
tmpShiftReg = shiftReg;
endbit = ((tmpShiftReg & 0x8000) != 0);
tmpShiftReg <<= 1;
if (endbit)
tmpShiftReg ^= 0x100b;
tmpShiftReg++;
shiftReg = tmpShiftReg;
tmpShiftReg = tmpShiftReg ^ mask;
return tmpShiftReg;
}
void resetSeed() {
shiftReg = 119 * 119 * ((TOS_LOCAL_ADDRESS >> 2) + 1);
initSeed = shiftReg;
mask = 137 * 29 * ((TOS_LOCAL_ADDRESS >> 2) + 1);
}
uint8_t data[512], rdata[512];
int count;
uint32_t addr, len;
uint16_t offset;
bool scheck(storage_result_t r) __attribute__((noinline)) {
if (r != STORAGE_OK)
call Leds.redOn();
return r == STORAGE_OK;
}
bool rcheck(result_t r) {
if (r != SUCCESS)
call Leds.redOn();
return r == SUCCESS;
}
void setParameters() {
addr = (uint32_t)count << 12 | (rand() >> 6);
len = rand() >> 7;
if (addr + len > SIZE)
addr = SIZE - len;
offset = rand() >> 8;
if (offset + len > sizeof data)
offset = sizeof data - len;
}
command result_t StdControl.init() {
int i;
call Leds.init();
resetSeed();
for (i = 0; i < sizeof data; i++)
data[i++] = rand() >> 8;
return SUCCESS;
}
task void mount() {
state = S_MOUNT;
rcheck(call Mount.mount(1));
}
command result_t StdControl.start() {
post mount();
return SUCCESS;
}
command result_t StdControl.stop() {
return SUCCESS;
}
void nextRead() {
if (++count == NWRITES)
{
call Leds.greenOn();
}
else
{
setParameters();
rcheck(call BlockRead.read(addr, rdata, len));
}
}
void nextWrite() {
if (++count == NWRITES)
{
call Leds.yellowToggle();
state = S_COMMIT;
rcheck(call BlockWrite.commit());
}
else
{
setParameters();
rcheck(call BlockWrite.write(addr, data + offset, len));
}
}
event void Mount.mountDone(storage_result_t result, volume_id_t id) {
if (scheck(result))
{
if (TOS_LOCAL_ADDRESS & 1)
{
state = S_ERASE;
rcheck(call BlockWrite.erase());
}
else
{
state = S_VERIFY;
rcheck(call BlockRead.verify());
}
}
}
event void BlockWrite.writeDone(storage_result_t result, block_addr_t x, void* buf, block_addr_t y) {
if (scheck(result))
nextWrite();
}
event void BlockWrite.eraseDone(storage_result_t result) {
if (scheck(result))
{
call Leds.yellowToggle();
state = S_WRITE;
count = 0;
resetSeed();
nextWrite();
}
}
event void BlockWrite.commitDone(storage_result_t result) {
if (scheck(result))
{
if (TOS_LOCAL_ADDRESS & 2)
{
call Leds.yellowToggle();
state = S_VERIFY;
rcheck(call BlockRead.verify());
}
else
call Leds.greenOn();
}
}
event void BlockRead.readDone(storage_result_t result, block_addr_t x, void* buf, block_addr_t rlen) __attribute__((noinline)) {
if (scheck(result) && rcheck(x == addr && rlen == len && buf == rdata &&
memcmp(data + offset, rdata, rlen) == 0))
nextRead();
}
event void BlockRead.verifyDone(storage_result_t result) {
if (scheck(result))
{
call Leds.yellowToggle();
state = S_READ;
count = 0;
resetSeed();
nextRead();
}
}
event void BlockRead.computeCrcDone(storage_result_t result, uint16_t z, block_addr_t x, block_addr_t y) {
}
}
--- NEW FILE: RandRWC.nc ---
/* $Id: RandRWC.nc,v 1.1 2005/07/11 23:27:38 idgay Exp $
* Copyright (c) 2005 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* @author David Gay
*/
configuration RandRWC { }
implementation {
components RandRW, BlockStorageC, Main, LedsC;
enum { ID = unique("StorageManager") };
Main.StdControl -> RandRW;
RandRW.Mount -> BlockStorageC.Mount[ID];
RandRW.BlockRead -> BlockStorageC.BlockRead[ID];
RandRW.BlockWrite -> BlockStorageC.BlockWrite[ID];
RandRW.Leds -> LedsC;
}
More information about the Tinyos-commits
mailing list