Hi all,
Below is a very simple and straight forward flash Read/write code, The
Red Led is toggling indicating that the data has been written
correctly. However Im not able to read back the data correctly ( The
yellow Led is not glowing).

P.S. 1. The flash has been formatted using
/opt/tinyos1.x/apps/TestDeluge/formatflash
2. The volume is getting correctly mounted ( checked with an LED)

Here is the code
**************************configuration file*************************
includes Storage;

configuration FlashCheck{}

implementation{ 
        components Main,FlashCheckM,BlockStorageC,LedsC;
        
        Main.StdControl->FlashCheckM;
        
        FlashCheckM.Leds->LedsC;
        FlashCheckM.Mount->BlockStorageC.Mount[ unique("StorageManager")];
        FlashCheckM.BlockRead->BlockStorageC.BlockRead[ 
unique("StorageManager")];
        
FlashCheckM.BlockWrite->BlockStorageC.BlockWrite[unique("StorageManager")];
}
****************************** Module*******************************

module FlashCheckM{

        provides interface StdControl;
        uses{   
                interface Leds;
                interface Mount;
                interface BlockRead;
        interface BlockWrite;
        }
}
        
implementation{ 
        block_addr_t addr = 0x00;
        block_addr_t length = 10;
        uint8_t temp = 0xA0;
        uint8_t DataWriteBuf[10];
        uint8_t DataReadBuf[10];
        uint8_t i;
        bool DATA_OK=FALSE;
        
        task void FlashWriteTask(){
        
                for(i=0;i<10;i++)
                        DataWriteBuf[i] = temp++;
                call BlockWrite.write(addr,&DataWriteBuf[0],length);
        }
        
        task void FlashReadTask(){
                call BlockRead.read(addr,&DataReadBuf[0],length);
        }

        command result_t StdControl.init(){
                call Leds.init();
                return SUCCESS;
        }
        command result_t StdControl.start(){
                call Mount.mount(0xd1);
                return SUCCESS;
        }
        command result_t StdControl.stop(){
        return SUCCESS;
        }
        
        event void BlockWrite.writeDone(storage_result_t result, block_addr_t
address, void* buf, block_addr_t len){
                if(result==STORAGE_OK){
                        call Leds.redToggle();
                }else{
                        call Leds.greenToggle();
                }
                call BlockWrite.commit();
                
        }

        event void BlockRead.readDone(storage_result_t results, block_addr_t
x, void* buf, block_addr_t rlen){
                if(results == STORAGE_OK){
                        temp = 0xA0;
                        for(i=0;i<10;i++){
                                if(DataReadBuf[0]==temp++)
                                        DATA_OK = TRUE;
                        }
                        if(DATA_OK==TRUE)                               
                                call Leds.yellowToggle();
                }
        }

        event void Mount.mountDone(storage_result_t result, volume_id_t id) {
                        if(result==STORAGE_OK){
                                post FlashWriteTask();
                        }
                                
        }

        event void BlockRead.verifyDone(storage_result_t result){
                post FlashReadTask();
        }

        event void BlockRead.computeCrcDone(storage_result_t result, uint16_t
crc, block_addr_t address, block_addr_t len){}

        event void BlockWrite.eraseDone(storage_result_t result){
        }
        
        event void BlockWrite.commitDone(storage_result_t result){
        call BlockRead.verify();
        }
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to