[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/rincon/apps/FlashBridge/apps/FlashBridgeViewer FlashBridgeViewer.h, NONE, 1.1 FlashBridgeViewerC.nc, NONE, 1.1 Makefile, NONE, 1.1 FlashBridgeViewerTestC.nc, NONE, 1.1 FlashBridgeViewerM.nc, NONE, 1.1 readme.txt, NONE, 1.1

dmm rincon at users.sourceforge.net
Tue Jul 18 09:25:25 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/rincon/apps/FlashBridge/apps/FlashBridgeViewer
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv13205/contrib/rincon/apps/FlashBridge/apps/FlashBridgeViewer

Added Files:
	FlashBridgeViewer.h FlashBridgeViewerC.nc Makefile 
	FlashBridgeViewerTestC.nc FlashBridgeViewerM.nc readme.txt 
Log Message:
Extracted the FlashBridge component and test app from Blackbook5

--- NEW FILE: FlashBridgeViewer.h ---
/*
 * Copyright (c) 2004-2006 Rincon Research Corporation.  
 * All rights reserved.
 * 
 * Rincon Research will permit distribution and use by others subject to
 * the restrictions of a licensing agreement which contains (among other things)
 * the following restrictions:
 * 
 *  1. No credit will be taken for the Work of others.
 *  2. It will not be resold for a price in excess of reproduction and 
 *      distribution costs.
 *  3. Others are not restricted from copying it or using it except as 
 *      set forward in the licensing agreement.
 *  4. Commented source code of any modifications or additions will be 
 *      made available to Rincon Research on the same terms.
 *  5. This notice will remain intact and displayed prominently.
 * 
 * Copies of the complete licensing agreement may be obtained by contacting 
 * Rincon Research, 101 N. Wilmot, Suite 101, Tucson, AZ 85711.
 * 
 * There is no warranty with this product, either expressed or implied.  
 * Use at your own risk.  Rincon Research is not liable or responsible for 
 * damage or loss incurred or resulting from the use or misuse of this software.
 */

#include "AM.h"

typedef struct ViewerMsg {
  uint32_t addr;
  uint16_t len;
  uint8_t cmd;
  uint8_t id; 
  uint8_t data[TOSH_DATA_LENGTH - 8];
} ViewerMsg;


enum {
  AM_VIEWERMSG = 0xA1,
};

enum {
  CMD_READ = 0,
  CMD_WRITE = 1, 
  CMD_ERASE = 2,
  CMD_MOUNT = 3,
  CMD_FLUSH = 4,
  CMD_PING = 5,
  CMD_CRC = 6,
  
  REPLY_READ = 10,
  REPLY_WRITE = 11,
  REPLY_ERASE = 12,
  REPLY_FLUSH = 14,
  REPLY_PING = 15,
  REPLY_CRC = 16,
  
  REPLY_READ_CALL_FAILED = 20,
  REPLY_WRITE_CALL_FAILED = 21,
  REPLY_ERASE_CALL_FAILED = 22,
  REPLY_FLUSH_CALL_FAILED = 24,
  REPLY_CRC_CALL_FAILED = 26,
  
  REPLY_READ_FAILED = 30,
  REPLY_WRITE_FAILED = 31,
  REPLY_ERASE_FAILED = 32,
  REPLY_FLUSH_FAILED = 34,
  REPLY_CRC_FAILED = 36,
  
  REPLY_INVALID_COMMAND = 50,
};




--- NEW FILE: FlashBridgeViewerC.nc ---
/*
 * Copyright (c) 2004-2006 Rincon Research Corporation.  
 * All rights reserved.
 * 
 * Rincon Research will permit distribution and use by others subject to
 * the restrictions of a licensing agreement which contains (among other things)
 * the following restrictions:
 * 
 *  1. No credit will be taken for the Work of others.
 *  2. It will not be resold for a price in excess of reproduction and 
 *      distribution costs.
 *  3. Others are not restricted from copying it or using it except as 
 *      set forward in the licensing agreement.
 *  4. Commented source code of any modifications or additions will be 
 *      made available to Rincon Research on the same terms.
 *  5. This notice will remain intact and displayed prominently.
 * 
 * Copies of the complete licensing agreement may be obtained by contacting 
 * Rincon Research, 101 N. Wilmot, Suite 101, Tucson, AZ 85711.
 * 
 * There is no warranty with this product, either expressed or implied.  
 * Use at your own risk.  Rincon Research is not liable or responsible for 
 * damage or loss incurred or resulting from the use or misuse of this software.
 */
 
/**
 * Flash Viewer application
 * Allows the user to view a hex map of the flash from
 * the PC.
 */
includes FlashBridgeViewer;

configuration FlashBridgeViewerC {
  provides {
    interface StdControl;
  }
}

implementation {
  components FlashBridgeViewerM, TransceiverC, LedsC, FlashBridgeC, StateM;
  
  StdControl = FlashBridgeViewerM;
  StdControl = TransceiverC;

  StdControl = StateM;
  StdControl = FlashBridgeC;
  
  FlashBridgeViewerM.FlashBridge -> FlashBridgeC.FlashBridge[unique("FlashBridge")];
  FlashBridgeViewerM.Leds -> LedsC;
  FlashBridgeViewerM.State -> StateM.State[unique("State")];
  FlashBridgeViewerM.Transceiver -> TransceiverC.Transceiver[AM_VIEWERMSG];

}




--- NEW FILE: Makefile ---
COMPONENT=FlashBridgeViewerTestC

# Choose a flash type:
#CFLAGS += -I../../media/AT45DB
CFLAGS += -I../../media/STM25P

# Standard include directories:
CFLAGS += -I../../interfaces
CFLAGS += -I../../../../tos/lib/State 

# If you use Boomerang, comment this line out:
CFLAGS += -I../../../../tos/lib/Transceiver

# If you use Boomerang, uncomment these lines:
#CFLAGS += -DSTM25P_BOOMERANG_VERSION
#CFLAGS += -I../../../../tos/lib/sptransceiver

include $(MAKERULES)


 

--- NEW FILE: FlashBridgeViewerTestC.nc ---
/*
 * Copyright (c) 2004-2006 Rincon Research Corporation.  
 * All rights reserved.
 * 
 * Rincon Research will permit distribution and use by others subject to
 * the restrictions of a licensing agreement which contains (among other things)
 * the following restrictions:
 * 
 *  1. No credit will be taken for the Work of others.
 *  2. It will not be resold for a price in excess of reproduction and 
 *      distribution costs.
 *  3. Others are not restricted from copying it or using it except as 
 *      set forward in the licensing agreement.
 *  4. Commented source code of any modifications or additions will be 
 *      made available to Rincon Research on the same terms.
 *  5. This notice will remain intact and displayed prominently.
 * 
 * Copies of the complete licensing agreement may be obtained by contacting 
 * Rincon Research, 101 N. Wilmot, Suite 101, Tucson, AZ 85711.
 * 
 * There is no warranty with this product, either expressed or implied.  
 * Use at your own risk.  Rincon Research is not liable or responsible for 
 * damage or loss incurred or resulting from the use or misuse of this software.
 */

/**
 * FlashBridgeViewerTest configuration
 * Since FlashBridgeViewer is made to add on to an existing application,
 * the minimum it needs is some configuration to wire up Main.StdControl.
 * This configuration does that.
 */

configuration FlashBridgeViewerTestC {
}

implementation {
  components Main, FlashBridgeViewerC;
  
  Main.StdControl -> FlashBridgeViewerC;
}

--- NEW FILE: FlashBridgeViewerM.nc ---
/*
 * Copyright (c) 2004-2006 Rincon Research Corporation.  
 * All rights reserved.
 * 
 * Rincon Research will permit distribution and use by others subject to
 * the restrictions of a licensing agreement which contains (among other things)
 * the following restrictions:
 * 
 *  1. No credit will be taken for the Work of others.
 *  2. It will not be resold for a price in excess of reproduction and 
 *      distribution costs.
 *  3. Others are not restricted from copying it or using it except as 
 *      set forward in the licensing agreement.
 *  4. Commented source code of any modifications or additions will be 
 *      made available to Rincon Research on the same terms.
 *  5. This notice will remain intact and displayed prominently.
 * 
 * Copies of the complete licensing agreement may be obtained by contacting 
 * Rincon Research, 101 N. Wilmot, Suite 101, Tucson, AZ 85711.
 * 
 * There is no warranty with this product, either expressed or implied.  
 * Use at your own risk.  Rincon Research is not liable or responsible for 
 * damage or loss incurred or resulting from the use or misuse of this software.
 */
 
/**
 * Flash Viewer implementation
 * Receives commands from the computer and replies with
 * a command or data.
 */
includes FlashBridgeViewer;

module FlashBridgeViewerM {
  provides {
    interface StdControl;
  }
  
  uses {
    interface Leds;
    interface State;
    interface Transceiver;
    interface FlashBridge;
  }
}

implementation { 
  
  /** Pointer to the allocated TOS_Msg */
  TOS_MsgPtr tosPtr;
  
  /** Pointer to the ViewerMsg payload inside the TOS_Msg */
  ViewerMsg *outMsg;
  
  /** Pointer to the incoming message payload */
  ViewerMsg *inMsg;
  
  /** the current method of communication */
  uint8_t commMethod;
  
  /** comm method options */
  enum {
    RADIO,
    UART,
  };
  
  enum { 
    S_IDLE = 0,
    S_BUSY,
  };

  /***************** Prototypes ****************/
  /** Allocate a new message to send */
  result_t newMessage();
  
  /** Execute the received command */
  void execute(ViewerMsg *message);
  
  /** Send a message over the method the command was received */
  void sendMessage();
  

  /***************** StdControl ****************/
  command result_t StdControl.init() { 
    call Leds.init();
    return SUCCESS;
  }
  
  command result_t StdControl.start() {
    return SUCCESS;
  }
  
  command result_t StdControl.stop() {
    return SUCCESS;
  }
  
  
  /***************** Transceiver ****************/
  /**
   * A message was possibly sent over the radio.
   * Check the result to see if it sent successfully.
   * @param m - a pointer to the sent message, valid for the duration of the event.
   * @param result - SUCCESS or FAIL.
   */
  event result_t Transceiver.radioSendDone(TOS_MsgPtr m, result_t result) {
    return SUCCESS;
  }
  
  /**
   * A message was sent over UART.
   * @param m - a pointer to the sent message, valid for the duration of the event.
   * @param result - SUCCESS or FAIL.
   */
  event result_t Transceiver.uartSendDone(TOS_MsgPtr m, result_t result) {
    return SUCCESS;
  }
  
  /**
   * Received a message over the radio.  This is just a forward from
   * GenericComm.ReceiveMsg
   */
  event TOS_MsgPtr Transceiver.receiveRadio(TOS_MsgPtr m) {
    inMsg = (ViewerMsg *) m->data;
    if(inMsg->cmd > 9) {
      // This is a reply from another mote
      return m;
    }
    
    if(!call State.requestState(S_BUSY)) {
      return m;
    }
    
    commMethod = RADIO;
    execute(inMsg);
    return m;
  }
  
  /**
   * Received a message over UART.  This is just a forward from
   * UARTComm.ReceiveMsg
   */
  event TOS_MsgPtr Transceiver.receiveUart(TOS_MsgPtr m) {
    inMsg = (ViewerMsg *) m->data;
    if(inMsg->cmd > 9) {
      // This is a reply from another mote
      return m;
    }
    
    if(!call State.requestState(S_BUSY)) {
      return m;
    }
    
    commMethod = UART;
    execute(inMsg);
    return m;
  }

  /***************** FlashBridge Events ****************/
  /**
   * Read is complete
   * @param addr - the address to read from
   * @param *buf - the buffer to read into
   * @param len - the amount to read
   * @return SUCCESS if the bytes will be read
   */
  event void FlashBridge.readDone(uint32_t addr, void *buf, uint32_t len, result_t result) {
    if(result) {
      outMsg->cmd = REPLY_READ;
    } else {
      outMsg->cmd = REPLY_READ_FAILED;
    }
    outMsg->addr = addr;
    outMsg->len = len;
    sendMessage();
  }
  
  /**
   * Write is complete
   * @param addr - the address to write to
   * @param *buf - the buffer to write from
   * @param len - the amount to write
   * @return SUCCESS if the bytes will be written
   */
  event void FlashBridge.writeDone(uint32_t addr, void *buf, uint32_t len, result_t result) {
    if(result) {
      outMsg->cmd = REPLY_WRITE;
    } else {
      outMsg->cmd = REPLY_WRITE_FAILED;
    }
    outMsg->addr = addr;
    outMsg->len = len;
    sendMessage();
  }
  
  /**
   * Erase is complete
   * @param sector - the sector id to erase
   * @return SUCCESS if the sector will be erased
   */
  event void FlashBridge.eraseDone(uint16_t sector, result_t result) {
    if(result) {
      outMsg->cmd = REPLY_ERASE;
    } else {
      outMsg->cmd = REPLY_ERASE_FAILED;
    }
    outMsg->addr = sector;
    sendMessage();
  }
  
  /**
   * Flush is complete
   * @param result - SUCCESS if the flash was flushed
   */
  event void FlashBridge.flushDone(result_t result) {
    if(result) {
      outMsg->cmd = REPLY_FLUSH;
    } else {
      outMsg->cmd = REPLY_FLUSH_FAILED;
    }
    sendMessage();
  }
  
  /**
   * CRC-16 is computed
   * @param crc - the computed CRC.
   * @param addr - the address to start the CRC computation
   * @param len - the amount of data to obtain the CRC for
   * @return SUCCESS if the CRC will be computed.
   */
  event void FlashBridge.crcDone(uint16_t crc, uint32_t addr, uint32_t len, result_t result) {
    if(result) {
      outMsg->cmd = REPLY_CRC;
    } else {
      outMsg->cmd = REPLY_CRC_FAILED;
    }
    outMsg->len = crc;
    sendMessage();
  }

  event void FlashBridge.ready(result_t result) {
    call Leds.yellowOff();
    if(result) {
      call Leds.greenOn();
      call Leds.redOff();
    } else {
      call Leds.redOn();
      call Leds.greenOff();
    }
  }
  
  /***************** Functions ****************/
  /**
   * Allocate and define a new message
   */
  result_t newMessage() { 
    if((tosPtr = call Transceiver.requestWrite()) != NULL) {
      outMsg = (ViewerMsg *) tosPtr->data;
      memset(outMsg, 0x0, sizeof(outMsg));
      return SUCCESS;
    }
    return FAIL;
  }
  
  /**
   * Send the message over the communications method the command
   * was received
   */
  void sendMessage() {
    if(commMethod == RADIO) {
      call Transceiver.sendRadio(TOS_BCAST_ADDR, sizeof(ViewerMsg));
    } else {
      call Transceiver.sendUart(sizeof(ViewerMsg));
    }
    call State.toIdle();
  }
  
  /**
   * Execute a command 
   */
  void execute(ViewerMsg *message) {
    switch(message->cmd) {
      case CMD_READ:
        if(newMessage()) {
          if(message->len > sizeof(outMsg->data)) {
            message->len = sizeof(outMsg->data);
          }
          if(!call FlashBridge.read(message->addr, outMsg->data, message->len)) {
            outMsg->cmd = REPLY_READ_CALL_FAILED;
            sendMessage();
          }
        }
        break;
        
      case CMD_WRITE:
        if(newMessage()) {
          if(message->len > sizeof(outMsg->data)) {
            message->len = sizeof(outMsg->data);
          }
          memcpy(outMsg->data, message->data, message->len);
          if(!call FlashBridge.write(message->addr, message->data, message->len)) {
            outMsg->cmd = REPLY_WRITE_CALL_FAILED;
            sendMessage();
          }
        }
        break;
      
      case CMD_ERASE:
        if(newMessage()) {
          if(!call FlashBridge.erase(message->addr)) {
            outMsg->addr = message->addr;
            outMsg->cmd = REPLY_ERASE_CALL_FAILED;
            sendMessage();
          }
        }
        break;
        
      case CMD_FLUSH:
        if(newMessage()) {
          if(!call FlashBridge.flush()) {
            outMsg->cmd = REPLY_FLUSH_CALL_FAILED;
            sendMessage();
          }
        }
        break;
        
     case CMD_CRC:
        if(newMessage()) {
          if(!call FlashBridge.crc(message->addr, message->len)) {
            outMsg->cmd = REPLY_CRC_CALL_FAILED;
            sendMessage();
          }
        }
        break;
        
      case CMD_PING:
        if(newMessage()) {
          outMsg->cmd = REPLY_PING;
          sendMessage();
        }
        break;
        
      default:
    }
  }
}



--- NEW FILE: readme.txt ---
This FlashBridgeViewer is similar to the FlashViewer application
previously uploaded to tinyos-1.x/contrib/rincon/apps/FlashViewer,
except it doesn't use the BlockStorage interface.

It uses the FlashBridge interface, which is a general
flash interface designed to minimize behavior differences between 
many different flash chips, allowing apps that use the flash to 
be compatible with many different motes.

You can use the FlashBridge for any app that requires access to flash 
and should expect it to work the same across all mote types.  Developers
are encouraged to port the FlashBridge to other flash types as needed.

Although you can compile and install this application on the mote
alone from this directory, you can also include the FlashBridgeViewerC 
component in any application where you want to dig down into the flash.
Take a look at that BlackbookConnect, for example.  I just 
added in the component FlashBridgeViewerC (and made sure the
Makefile knew where it was) and then wired up Main.StdControl to it.
Whammo.  BlackbookConnect doubled its effectiveness, and people can
compile in BlackbookConnect to the mote, make changes to the file
system, and see those changes on the flash.

Below are some examples to show you what this puppy does.
You'll also need the com.rincon.flashbridgeviewer Java application
to be located in your own tools/java directory.

Finally, one more thing to mention is you'll need to specify
which flash type you're compiling for in the Makefile.
If you're working with a mica- type mote, you've got an AT45DB flash,
and with a tmote, you've got an ST M25P80 flash (STM25P).

@author David Moss (dmm at rincon.com)



I always alias "flashbridge" to "java com.rincon.flashbridgeviewer.FlashViewer"
just so you know what's going on...


First let's take a look at what commands we have available from the
FlashBridge.  Compile FlashBridgeViewerTest or BlackbookConnect or something
to the mote and connect to the mote with your serial forwarder.  Then...


$ flashbridge
No arguments found
Usage: java com.rincon.flashviewer [mote] [command]
  COMMANDS
    -read [start address] [range]
    -write [start address] [22 characters]
    -erase [sector]
    -flush
    -crc [start address] [range]
    -ping


Let's ping the mote to see if we have FlashBridgeViewer installed:
$ flashbridge -ping
Pong! The mote has FlashViewer installed.


Great, now let's read a page of data:
$ flashbridge -read 0 0x100
0x0 to 0x100
_________________________________________________
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |   
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |


Let's write some data.  The FlashBridge itself lets you
write as much data at a time as you want, but our TOS_Msg's being
passed back and forth over UART only hold so much.  And there's
not much you can specify on the command line anyway, so here's what 
happens:

$ flashbridge -write 0x0 hello_flashbridge!
Writing data
0x68 0x65 0x6c 0x6c 0x6f 0x5f 0x66 0x6c 0x61 0x73 0x68 0x62 0x72 0x69 0x64 0x67
0x65 0x21
SUCCESS: 18 bytes written to 0x0


We'll read 0x20 bytes back from 0x0 to make sure what we wrote exists:
$ flashbridge -read 0 0x20
0x0 to 0x20
_________________________________________________
68 65 6C 6C 6F 5F 66 6C   61 73 68 62 72 69 64 67   |  hello_fl  ashbridge
65 21 FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |   !                

Keep in mind that the AT45DB flash doesn't necessarily put what you wrote
onto the physical flash until you flush it out, so here's how you flush:

$ flashbridge -flush
SUCCESS: Flush complete


We can take the CRC of the data we just wrote:
$ flashbridge -crc 0x0 18
SUCCESS: CRC is 0x6D3F


And we can erase the entire sector.  FlashBridge was designed for sector
erases, which you can actually go in and edit if you want - but it's not
entirely recommended.  The ST M25P80 flash erases in sector-lengths, which 
is 64kB at a time.  Atmel's AT45DB flash chip erases in page-lengths, which
is 256B at a time.  To maintain compatibility between the two chips,
FlashBridge erases the full 64kB at a time on both the AT45DB and the STM25P
chips.  It can probably be done faster on the AT45DB implementation
than it is right now, but I haven't programmed any of the block erase
stuff that the chip actually supports.

Another option would be to go in and edit the FlashSettings.h
file for the AT45DB and define smaller sector sizes and readjust
all those flash parameters, and that should maintain compatibility as well.

So let's erase.  It takes about 1 second/sector - which is 1 second per erase.
$ flashbridge -erase 0             
SUCCESS: Sector 0 erase complete   

And for that AT45DB you'll want to flush after that as well to make sure
changes are commmited to flash.



Now let's read back address 0x0:
$ flashbridge -read 0 0x100
0x0 to 0x100
_________________________________________________
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                     
FF FF FF FF FF FF FF FF   FF FF FF FF FF FF FF FF   |                    


Cool.




More information about the Tinyos-contrib-commits mailing list