miSim

misim
Class Port

java.lang.Object
  |
  +--misim.Register
        |
        +--misim.Port
Direct Known Subclasses:
PIC84_PortA, PIC84_PortB

public abstract class Port
extends Register

The Port class extends Register to emulate microcontroller Ports, with associated I/O capabilities. Ports have the means to receive input, generate output and inform PortListeners of changes to their output state. Methods to add and remove PortListeners are provided, though this more easily achieved through similar methods in the MachineState class.


Field Summary
protected  int inputBits
           
static int MAX_PORT_ID
           
 int outputMask
           
static java.lang.String Port_A
           
static java.lang.String Port_B
           
static java.lang.String Port_C
           
static java.lang.String Port_D
           
static java.lang.String Port_E
           
static int PortAId
           
static int PortBId
           
static int PortCId
           
static int PortDId
           
static int PortEId
           
protected  int portIdentifier
           
 
Fields inherited from class misim.Register
machineState, simple, val
 
Constructor Summary
Port(MachineState machineState, int bitWidth)
          Constructor method, sets machine state and bit width
 
Method Summary
 void addPortListener(PortListener pl)
          Add a port listener to this Port.
abstract  void checkPortInterrupt()
          Check to see if the new data placed on this port by an external device will cause an interrupt.
 void clearPortBits(int data)
          Clear the bits being applied to this port by an external device, this performs a logical AND of the port inputs with the complement of the given data.
 int getBitWidth()
          Return the bit width of this port.
 int getIdentifier()
          Return a unique identifier for this port.
 void handleUpdate()
          Dispatch a Port event to any listeners that are interested in it.
 void rebuildPortMasks()
          This rebuilds the masks for identifying when a significant event has occured on the processor ports.
 void removePortListener(PortListener pl)
          Remove a port listener from this port.
 void setPortBits(int data)
          Set the bits being applied to this port by an external device, this performs a logical OR of the given data.
 void writePort(int data, int mask)
          Set the data applied to this port according to the given mask and input.
 
Methods inherited from class misim.Register
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Port_A

public static final java.lang.String Port_A

Port_B

public static final java.lang.String Port_B

Port_C

public static final java.lang.String Port_C

Port_D

public static final java.lang.String Port_D

Port_E

public static final java.lang.String Port_E

PortAId

public static final int PortAId

PortBId

public static final int PortBId

PortCId

public static final int PortCId

PortDId

public static final int PortDId

PortEId

public static final int PortEId

MAX_PORT_ID

public static final int MAX_PORT_ID

outputMask

public int outputMask

portIdentifier

protected int portIdentifier

inputBits

protected int inputBits
Constructor Detail

Port

public Port(MachineState machineState,
            int bitWidth)
Constructor method, sets machine state and bit width
Method Detail

handleUpdate

public void handleUpdate()
Dispatch a Port event to any listeners that are interested in it.
Overrides:
handleUpdate in class Register

checkPortInterrupt

public abstract void checkPortInterrupt()
Check to see if the new data placed on this port by an external device will cause an interrupt. This should be overridden by specific implementations of the port.

setPortBits

public void setPortBits(int data)
Set the bits being applied to this port by an external device, this performs a logical OR of the given data.
Parameters:
data - The new bits applied to this port

clearPortBits

public void clearPortBits(int data)
Clear the bits being applied to this port by an external device, this performs a logical AND of the port inputs with the complement of the given data. So to clear bits 0 and 2, call this method with a value of '00000101' (binary).
Parameters:
data - The new bits applied to this port

writePort

public void writePort(int data,
                      int mask)
Set the data applied to this port according to the given mask and input. Only the bits that have a corresponding '1' in the mask will be set to the value of the input.
Parameters:
data - The data being applied to this port
mask - The mask indicating which bits should be altered.

getIdentifier

public int getIdentifier()
Return a unique identifier for this port. This will be used to identify this port to any listeners that must respond to events.
Returns:
An Integer that identifies this port

getBitWidth

public int getBitWidth()
Return the bit width of this port.
Returns:
The bit width of this port

addPortListener

public void addPortListener(PortListener pl)
Add a port listener to this Port. The portListener will be informed of the events that it notifies the port that it is interested in. The events are identified when the port listener is first added - if a portListener wishes to be notified of different events, it must be removed and re-added to the port
Parameters:
pl - The port listener to add

removePortListener

public void removePortListener(PortListener pl)
Remove a port listener from this port. This must also recalculate the masks and regs for the emulation to efficiently identify when a listened for event is to be handled.
Parameters:
pl - The port listener to remove.

rebuildPortMasks

public void rebuildPortMasks()
This rebuilds the masks for identifying when a significant event has occured on the processor ports. Note that this does not completely rebuild the details - if a listener has registered as being interested in a particular port, this will not check if that is still the port that it wishes to listen to.

miSim