ioio.lib.impl
Class IcspMasterImpl

java.lang.Object
  extended by ioio.lib.impl.AbstractResource
      extended by ioio.lib.impl.IcspMasterImpl
All Implemented Interfaces:
Closeable, IcspMaster

public class IcspMasterImpl
extends AbstractResource
implements IcspMaster


Constructor Summary
IcspMasterImpl(IOIOImpl ioio)
           
 
Method Summary
 void close()
           
 void dataReceived(byte[] data, int size)
           
 void disconnected()
           
 void enterProgramming()
          Initiate a sequence that will put the slave device in programming mode.
 void executeInstruction(int instruction)
          Execute a single instruction on the slave MCU.
 void exitProgramming()
          Initiate a sequence that will put the slave device out of programming mode.
 void readVisi()
          Request a read of the VISI register on the slave MCU.
 void reportAdditionalBuffer(int bytesToAdd)
           
 int waitVisiResult()
          Wait and return a result of a call to IcspMaster.readVisi().
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IcspMasterImpl

public IcspMasterImpl(IOIOImpl ioio)
               throws ConnectionLostException
Throws:
ConnectionLostException
Method Detail

dataReceived

public void dataReceived(byte[] data,
                         int size)

reportAdditionalBuffer

public void reportAdditionalBuffer(int bytesToAdd)

enterProgramming

public void enterProgramming()
                      throws ConnectionLostException
Description copied from interface: IcspMaster
Initiate a sequence that will put the slave device in programming mode. This sequence is necessary for executing instructions and reading register values.

Specified by:
enterProgramming in interface IcspMaster
Throws:
ConnectionLostException - Connection to the IOIO has been lost.

exitProgramming

public void exitProgramming()
                     throws ConnectionLostException
Description copied from interface: IcspMaster
Initiate a sequence that will put the slave device out of programming mode. It will be held in reset.

Specified by:
exitProgramming in interface IcspMaster
Throws:
ConnectionLostException - Connection to the IOIO has been lost.

executeInstruction

public void executeInstruction(int instruction)
                        throws ConnectionLostException
Description copied from interface: IcspMaster
Execute a single instruction on the slave MCU.

Specified by:
executeInstruction in interface IcspMaster
Parameters:
instruction - a 24-bit PIC instruction.
Throws:
ConnectionLostException - Connection to the IOIO has been lost.

readVisi

public void readVisi()
              throws ConnectionLostException,
                     java.lang.InterruptedException
Description copied from interface: IcspMaster
Request a read of the VISI register on the slave MCU. This is an asynchronous call, in which the 16-bit result is obtained by IcspMaster.waitVisiResult(). This method may block if the read queue on the IOIO is full, but this should be for short periods only.

Specified by:
readVisi in interface IcspMaster
Throws:
ConnectionLostException - Connection to the IOIO has been lost.
java.lang.InterruptedException - Interrupted while blocking.

close

public void close()
Specified by:
close in interface Closeable
Overrides:
close in class AbstractResource

disconnected

public void disconnected()
Overrides:
disconnected in class AbstractResource

waitVisiResult

public int waitVisiResult()
                   throws ConnectionLostException,
                          java.lang.InterruptedException
Description copied from interface: IcspMaster
Wait and return a result of a call to IcspMaster.readVisi(). Results will be returned in the same order as requested. The call will block until there is data, until interrupted, or until connection to the IOIO has been lost.

Specified by:
waitVisiResult in interface IcspMaster
Returns:
The result - an unsigned 16-bit number.
Throws:
ConnectionLostException - Connection to the IOIO has been lost.
java.lang.InterruptedException - Interrupted while blocking.