jmce - 1_02

jmce.sim
Class I2cBus

java.lang.Object
  extended by jmce.sim.AbstractHardware
      extended by jmce.sim.AbstractPeripheral
          extended by jmce.sim.I2cBus
All Implemented Interfaces:
Hardware, MemoryWriteListener, Peripheral
Direct Known Subclasses:
DiseqcI2cBus

public class I2cBus
extends AbstractPeripheral
implements MemoryWriteListener

I2C Bus manager.

This peripheral manage all the operation between one master (the CPU) and one or more slave connected using the I2C protocol. To implement the interface the CPU must have two OpenCollectorMemoryBit mapped to phisical register.

The following bus condition are supported:

This version is not multi master can support only one master connected to one or more slave devices.

Version:
1.00
Author:
Mario Viara
See Also:
I2cSlave

Field Summary
protected  MemoryBit SCL
          Memory bit connected to SCL wire
protected  MemoryBit SDA
          Memory bit connected to SDA Wire
 
Fields inherited from class jmce.sim.AbstractPeripheral
cpu
 
Constructor Summary
I2cBus()
          Default constructor
 
Method Summary
protected  void bus(boolean scl, boolean sda)
          Bus manager.
protected  void i2cFail(boolean bit)
          Called on the failing edge od the clock.
protected  void i2cRecv(boolean sda)
          Called when a new bit is received
protected  void i2cRecv(int value)
          Process one received byte
protected  void i2cRise(boolean bit)
          Called on the rising edge of the clock
protected  void i2cSend(boolean sda)
          Called when is necessary to send one byte.
protected  void i2cStart()
          Called when a start or repeted start condition is detected
protected  void i2cStop()
          Called when the stop condition is detected
 void reset()
          Reset the the device to the initial state.
 void setScl(OpenCollectorMemoryBit scl)
          Set the memory bit used for SCL
 void setSda(OpenCollectorMemoryBit sda)
          Set the memory bit used for SDA
 void writeMemory(Memory m, int address, int value, int oldValue)
          Implementation of listener to receive write on the bit mapped to the wire of the I2cBUS.
 
Methods inherited from class jmce.sim.AbstractPeripheral
idle, registerCPU, setIdle, setLive
 
Methods inherited from class jmce.sim.AbstractHardware
addHardware, createFrame, destroy, getHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareForName, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, setHardware, setHardware, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jmce.sim.Hardware
addHardware, destroy, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, setHardware, setHardware, setName
 

Field Detail

SCL

protected MemoryBit SCL
Memory bit connected to SCL wire


SDA

protected MemoryBit SDA
Memory bit connected to SDA Wire

Constructor Detail

I2cBus

public I2cBus()
Default constructor

Method Detail

setScl

public void setScl(OpenCollectorMemoryBit scl)
Set the memory bit used for SCL

Parameters:
scl - - Memory bit.

setSda

public void setSda(OpenCollectorMemoryBit sda)
Set the memory bit used for SDA

Parameters:
sda - - Memory bit

reset

public void reset()
           throws SIMException
Description copied from interface: Hardware
Reset the the device to the initial state. This method will be called after init.

Specified by:
reset in interface Hardware
Overrides:
reset in class AbstractHardware
Throws:
SIMException

i2cStart

protected void i2cStart()
Called when a start or repeted start condition is detected


i2cStop

protected void i2cStop()
Called when the stop condition is detected


i2cRecv

protected void i2cRecv(int value)
                throws SIMException
Process one received byte

Throws:
SIMException

i2cSend

protected void i2cSend(boolean sda)
                throws SIMException
Called when is necessary to send one byte.

Throws:
SIMException

i2cRecv

protected void i2cRecv(boolean sda)
                throws SIMException
Called when a new bit is received

Throws:
SIMException

i2cRise

protected void i2cRise(boolean bit)
                throws SIMException
Called on the rising edge of the clock

Throws:
SIMException

i2cFail

protected void i2cFail(boolean bit)
                throws SIMException
Called on the failing edge od the clock.

Throws:
SIMException

bus

protected void bus(boolean scl,
                   boolean sda)
            throws SIMException
Bus manager. This function is the main implementation of the I2C bus and process the bit change.

Parameters:
scl - - Current value of clock.
sda - - Current value of data.
Throws:
SIMException

writeMemory

public void writeMemory(Memory m,
                        int address,
                        int value,
                        int oldValue)
                 throws SIMException
Implementation of listener to receive write on the bit mapped to the wire of the I2cBUS.

Specified by:
writeMemory in interface MemoryWriteListener
Parameters:
m - - Memory involved in the write operation.
address - - Address written.
value - - Value written.
oldValue - - Old value of this memory location.
Throws:
SIMException

jmce - 1_02