Hello,
In an effort to test the external Flash on the Tmote I wrote an
application that samples light and temperature and both store the data
in a buffer and at the same time sends the data to TOS Base. When the
buffer is full the data 256bits is committed to the ext Flash, red and
send to TOS Base as well, before the whole process repeats with a
counter moving the address space of the flash by 256bits. The problem is
that it is very unstable in that it has not written past a 7th page on
the flash and at the same time is inconsistent to where the write
process stops functioning, sometimes it all ready errors on the second
page. The code is attached and any suggestions to what might cause the
errors are appreciated.
Thanks
Mikael
/* ************Test Flash Packet structure****************** */
#ifndef TESTFLASHMSG_H;
#define TESTFLASHMSG_H;
enum {
SP_ADCFLASH_TYPE = 4,
};
typedef struct
{
nx_uint8_t src;
nx_uint16_t local_count_num;
nx_uint16_t count_num;
nx_uint16_t adc_read_light;
nx_uint16_t adc_read_temp;
}TestADCMsg_t;
typedef struct
{
nx_uint8_t src;
nx_uint16_t count_num;
nx_uint8_t r_count;
nx_uint16_t memoryRead[12];
}TestFlashMsg_t;
#endif
// First Test of FlashMemory May 29-2007
//
// Configuration based on RandRWC and
//
http://mail.millennium.berkeley.edu/pipermail/tinyos-help/2006-March/015260.html
//
configuration TestFlashC {}
implementation {
components TestFlashM as MyApp,
Main,
SPC,
LedsC,
HumidityC,
DemoSensorC,
BlockStorageC,
new TimerMilliC() as T1,
new TimerMilliC() as T2;
enum {
BLOCKSTORAGE_MYAPP = unique("Blockstorage"),
};
Main.StdControl -> MyApp;
Main.StdControl -> DemoSensorC;
MyApp.ADC_light -> DemoSensorC;
MyApp.ADC_temperature -> HumidityC.Temperature;
MyApp.TemperatureError -> HumidityC.TemperatureError;
MyApp.HumidityControl -> HumidityC;
MyApp.SPSend -> SPC.SPSend[SP_ADCFLASH_TYPE];
MyApp.Mount -> BlockStorageC.Mount[BLOCKSTORAGE_MYAPP];
MyApp.BlockRead -> BlockStorageC.BlockRead[BLOCKSTORAGE_MYAPP];
MyApp.BlockWrite -> BlockStorageC.BlockWrite[BLOCKSTORAGE_MYAPP];
MyApp.TimerADC -> T1; //TimerMilliC;
MyApp.TimerFlash -> T2; //TimerMilliC;
MyApp.Leds -> LedsC;
}
// Author Mikael Ifversen
// Inspired by RandRW ongoing June 18-2007
#include "TestFlashMsg.h"
module TestFlashM {
provides interface StdControl;
uses {
interface Mount;
interface BlockRead;
interface BlockWrite;
interface SPSend;
interface Leds;
interface Timer2<TMilli> as TimerADC;
interface Timer2<TMilli> as TimerFlash;
interface ADC as ADC_temperature;
interface ADC as ADC_light;
interface SplitControl as HumidityControl;
interface ADCError as TemperatureError;
}
}
implementation {
enum {
OFFSET = 2,
READSHIFT = 12,
};
uint8_t length, i, local_count, packet_count, read_count, test;
TOS_Msg m_data;
sp_message_t m_spmsg;
bool flash, adc;
uint16_t readBuffer[128];
uint16_t writeBuffer2[128];
uint16_t l_adc, count, t_adc;
task void sendADCData();
task void commitWriting() {
if(read_count == 0)
call BlockWrite.write(0x0, &writeBuffer2, 256);
else
call BlockWrite.write(256 * read_count, &writeBuffer2, 256);
}
task void readAddressCounter() {
if(read_count == 0)
call BlockRead.read(0x0, &readBuffer, 256);
else
call BlockRead.read(256 * read_count, &readBuffer, 256);
}
task void fillWriteBuffer2() {
test = local_count;
if(test == 0) {
i = test;
atomic writeBuffer2[i] = count;
atomic writeBuffer2[i+1] = l_adc;
atomic writeBuffer2[i+2] = t_adc;
post sendADCData();
}
if(test > 0 && test < 42) {
i = test + OFFSET * test;
atomic writeBuffer2[i] = count;
atomic writeBuffer2[i+1] = l_adc;
atomic writeBuffer2[i+2] = t_adc;
post sendADCData();
}
if(test > 40) {
adc = FALSE;
post commitWriting();
}
}
/* *** Packet structure and send function to be created as a read from the
flash memory *** */
task void sendFlashData() {
TestFlashMsg_t* struct_ptr = (TestFlashMsg_t*) m_data.data;
if(packet_count > 10) {
packet_count = 0;
read_count++;
adc = TRUE;
call TimerADC.startOneShot(100);
}
else {
for(i = 0; i < READSHIFT; i++) {
if(packet_count == 0)
atomic struct_ptr -> memoryRead[i] =
readBuffer[i];
else
atomic struct_ptr -> memoryRead[i] =
readBuffer[i + READSHIFT*packet_count];
}
struct_ptr -> src = (TOS_LOCAL_ADDRESS);
struct_ptr -> count_num = packet_count;
struct_ptr -> r_count = read_count;
call SPSend.send(&m_spmsg, &m_data, TOS_BCAST_ADDR,
sizeof(TestFlashMsg_t));
packet_count++;
call Leds.yellowOn();
}
}
/* *** Packet structure and send function for the immediate sensor data (light
& temperature) *** */
task void sendADCData() {
TestADCMsg_t* struct_ptr = (TestADCMsg_t*) m_data.data;
atomic struct_ptr -> count_num = count;
atomic struct_ptr -> adc_read_light = l_adc;
atomic struct_ptr -> adc_read_temp = t_adc;
struct_ptr -> src = (TOS_LOCAL_ADDRESS);
struct_ptr -> local_count_num = local_count;
call SPSend.send(&m_spmsg, &m_data, TOS_BCAST_ADDR,
sizeof(TestADCMsg_t));
if(adc == FALSE)
local_count = 0;
call Leds.redOn();
}
command result_t StdControl.init() {
adc = TRUE;
flash = FALSE; //Not used
count = 0; // counting sensor samples
length = 42;
read_count = 0; //Count to change address for Block.read/write
local_count = 0; //Count to fill writeBuffer
packet_count = 0; //Count to copy from readBuffer to message structure
call Leds.init();
call HumidityControl.init();
call Mount.mount(1);
return SUCCESS;
}
event result_t HumidityControl.initDone() {
return SUCCESS;
}
command result_t StdControl.start() {
call BlockWrite.erase();
call HumidityControl.start();
return SUCCESS;
}
event result_t HumidityControl.startDone() {
return SUCCESS;
}
command result_t StdControl.stop () {
call HumidityControl.stop();
return SUCCESS;
}
event result_t HumidityControl.stopDone() {
call TemperatureError.disable();
return SUCCESS;
}
event void TimerADC.fired() {
call ADC_light.getData();
}
event void TimerFlash.fired() { //Not used
}
async event result_t ADC_light.dataReady(uint16_t data) {
count++;
atomic l_adc = data;
call ADC_temperature.getData();
return SUCCESS;
}
async event result_t ADC_temperature.dataReady(uint16_t data) {
atomic t_adc = data;
post fillWriteBuffer2();
return SUCCESS;
}
event result_t TemperatureError.error(uint8_t token) {
atomic t_adc = 0;
return SUCCESS;
}
event void Mount.mountDone(storage_result_t result, volume_id_t id) {}
event void BlockWrite.eraseDone(storage_result_t result) {
call TimerADC.startOneShot(100);
}
event void BlockWrite.commitDone(storage_result_t result) {}
event void BlockWrite.writeDone(storage_result_t result, block_addr_t addr,
void *buf, block_addr_t len) {
post readAddressCounter();
}
event void BlockRead.computeCrcDone(storage_result_t result, uint16_t crc,
block_addr_t addr, block_addr_t len) {}
event void BlockRead.readDone(storage_result_t result, block_addr_t addr, void
*buf, block_addr_t len) {}
event void BlockRead.verifyDone(storage_result_t result) {}
event void SPSend.sendDone( sp_message_t *msg, sp_message_flags_t flags,
sp_error_t error ) {
if(adc == TRUE) {
local_count++;
call TimerADC.startOneShot(500);
}
if(adc == FALSE)
post sendFlashData();
call Leds.yellowOff();
call Leds.redOff();
}
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help