lejos.pc.comm
Class NXTSamba

java.lang.Object
  extended by lejos.pc.comm.NXTSamba

public class NXTSamba
extends java.lang.Object

Implements a sub-set of the Atmel SAM-BA download protocol. Only those functions required for program download to the NXT flash are currently implemented.


Field Summary
static int FLASH_BASE
          The NXT has 256KB Flash starting at 0x100000, divided into 256byte pages.
static int FLASH_MAX
           
static int FLASH_SIZE
           
static int PAGE_MAX
           
static int PAGE_SIZE
           
 
Constructor Summary
NXTSamba()
           
 
Method Summary
 void close()
          Close the device.
 java.io.InputStream createInputStream(int addr, int len)
           
 java.lang.String getVersion()
          returns the SAM-BA version string for the current device.
 void jump(int addr)
          Start execution of code at the specified address.
 boolean open(NXTInfo nxt)
          Open the specified USB device and check that it is in SAM-BA mode.
 void readBytes(int addr, byte[] data, int off, int len)
          Read a 32 bit word from the specified address.
 int readHalfword(int addr)
          Read a 16 bit halfword from the specified address.
 int readOctet(int addr)
          Read a 8 bit octet from the specified address.
 void readPage(int page, byte[] data, int offset)
          Read a single page from flash memory.
 void readPages(int first, byte[] data, int start, int len)
          Read a series of pages from flash memory.
 int readWord(int addr)
          Read a 32 bit word from the specified address.
 void reboot()
           
 NXTInfo[] search()
          Locate all NXT devices that are running in SAM-BA mode.
 void unlockAllPages()
          Turn off the lock bits for all of flash memory.
 void writeBytes(int addr, byte[] data)
          Write a series of bytes to the device.
 void writeHalfword(int addr, int val)
          Write a 16 bit halfword to the specified address.
 void writeOctet(int addr, int val)
          Write a 8 bit octet to the specified address.
 void writePage(int page, byte[] data, int offset)
          Write a single page to flash memory.
 void writePage(int page, byte[] data, int offset, int len)
          Write a single page to flash memory.
 void writePages(int firstPage, byte[] data, int offset, int len)
          Write a series of pages to flash memory.
 void writeWord(int addr, int val)
          Write a 32 bit word to the specified address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLASH_BASE

public static final int FLASH_BASE
The NXT has 256KB Flash starting at 0x100000, divided into 256byte pages.

See Also:
Constant Field Values

FLASH_MAX

public static final int FLASH_MAX
See Also:
Constant Field Values

FLASH_SIZE

public static final int FLASH_SIZE
See Also:
Constant Field Values

PAGE_SIZE

public static final int PAGE_SIZE
See Also:
Constant Field Values

PAGE_MAX

public static final int PAGE_MAX
See Also:
Constant Field Values
Constructor Detail

NXTSamba

public NXTSamba()
         throws java.io.IOException
Throws:
java.io.IOException
Method Detail

search

public NXTInfo[] search()
                 throws NXTCommException
Locate all NXT devices that are running in SAM-BA mode.

Returns:
An array of devices in SAM-BA mode
Throws:
NXTCommException

writeOctet

public void writeOctet(int addr,
                       int val)
                throws java.io.IOException
Write a 8 bit octet to the specified address.

Parameters:
addr -
val -
Throws:
java.io.IOException

writeHalfword

public void writeHalfword(int addr,
                          int val)
                   throws java.io.IOException
Write a 16 bit halfword to the specified address.

Parameters:
addr -
val -
Throws:
java.io.IOException

writeWord

public void writeWord(int addr,
                      int val)
               throws java.io.IOException
Write a 32 bit word to the specified address.

Parameters:
addr -
val -
Throws:
java.io.IOException

readOctet

public int readOctet(int addr)
              throws java.io.IOException
Read a 8 bit octet from the specified address.

Parameters:
addr -
Returns:
value read from addr
Throws:
java.io.IOException

readHalfword

public int readHalfword(int addr)
                 throws java.io.IOException
Read a 16 bit halfword from the specified address.

Parameters:
addr -
Returns:
value read from addr
Throws:
java.io.IOException

readWord

public int readWord(int addr)
             throws java.io.IOException
Read a 32 bit word from the specified address.

Parameters:
addr -
Returns:
value read from addr
Throws:
java.io.IOException

createInputStream

public java.io.InputStream createInputStream(int addr,
                                             int len)
                                      throws java.io.IOException
Throws:
java.io.IOException

readBytes

public void readBytes(int addr,
                      byte[] data,
                      int off,
                      int len)
               throws java.io.IOException
Read a 32 bit word from the specified address.

Parameters:
addr -
data - the return data
off - the offset
len - the length
Throws:
java.io.IOException

writeBytes

public void writeBytes(int addr,
                       byte[] data)
                throws java.io.IOException
Write a series of bytes to the device.

Parameters:
addr -
data -
Throws:
java.io.IOException

jump

public void jump(int addr)
          throws java.io.IOException
Start execution of code at the specified address.

Parameters:
addr -
Throws:
java.io.IOException

reboot

public void reboot()
            throws java.io.IOException
Throws:
java.io.IOException

unlockAllPages

public void unlockAllPages()
                    throws java.io.IOException
Turn off the lock bits for all of flash memory.

Throws:
java.io.IOException

writePage

public void writePage(int page,
                      byte[] data,
                      int offset)
               throws java.io.IOException
Write a single page to flash memory. We write the page to ram and then use the FlashWriter code to transfer this data to flash. The FlashWriter code must have already been downloaded.

Parameters:
page -
data -
offset -
Throws:
java.io.IOException

writePage

public void writePage(int page,
                      byte[] data,
                      int offset,
                      int len)
               throws java.io.IOException
Write a single page to flash memory. We write the page to ram and then use the FlashWriter code to transfer this data to flash. The FlashWriter code must have already been downloaded.

Parameters:
page -
data -
offset -
len -
Throws:
java.io.IOException

writePages

public void writePages(int firstPage,
                       byte[] data,
                       int offset,
                       int len)
                throws java.io.IOException
Write a series of pages to flash memory.

Parameters:
firstPage -
data -
offset -
len -
Throws:
java.io.IOException

readPage

public void readPage(int page,
                     byte[] data,
                     int offset)
              throws java.io.IOException
Read a single page from flash memory.

Parameters:
page -
data -
offset -
Throws:
java.io.IOException

readPages

public void readPages(int first,
                      byte[] data,
                      int start,
                      int len)
               throws java.io.IOException
Read a series of pages from flash memory.

Parameters:
first -
data -
start -
len -
Throws:
java.io.IOException

open

public boolean open(NXTInfo nxt)
             throws java.io.IOException
Open the specified USB device and check that it is in SAM-BA mode. We switch the device into "quiet" mode and also download the FlashWrite program.

Parameters:
nxt - Device to open.
Returns:
true if the device is now open, false otherwise.
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close the device.

Throws:
java.io.IOException

getVersion

public java.lang.String getVersion()
                            throws java.io.IOException
returns the SAM-BA version string for the current device.

Returns:
The SAM-BA version.
Throws:
java.io.IOException