hades.models.pic
Class SmartPic16F84

java.lang.Object
  extended byhades.simulator.SimObject
      extended byhades.models.pic.SmartPic16F84
All Implemented Interfaces:
java.lang.Cloneable, ContextToolTip, java.io.Serializable, Simulatable, Wakeable

public class SmartPic16F84
extends SimObject
implements Simulatable, Wakeable

A HADES simulation model for the Arizona Microchip PIC16x84 microcontroller. We use the hades.models.pic.PicExec with its helper classes for the processor core.

To reduce HADES event count for the PIC x4 input clock, this model uses an internally generated clock signal with regular wakeup events for the synchronisation with the simulation engine. As long as no external I/O activity occurs, this generates one HADES event per processor instruction cycle (which is much more efficient than using an external component like hades.models.io.ClockGen to feed the PIC clock input at 12 HADES events per processor instruction cycle).

However, note that the processor ignores its Clkin pin, and that internal processor cycles may desynchronize up to 1 clk-period with the rest of the external simulation. For example, sampling of the Port A/B inputs may occur 1/4 cycle too early, and also the timing of Port B interrupts detection differs a little from the real device. If exact timing is a requirement for your system, use the hades.models.Pic16C84 instead of the SmartPic16C84.

As performance experiments indicated, that up to 70% of total simulation time was spent in the HADES interfacing in older versions of the Pic processor model, the current version uses several data structures to reduce costly and time-consuming interaction with HADES. These consist of four variables that store the last input values to the processor core and the last values written to the port A/B output registers by the processor itself.

These arrays/values are initialized on object construction and again on each elaborate() call. During simulation, the portInputA/B variables are updated on each evaluate() call, and the portOutputA/B variables are updated once the processor writes to its PORTA/B registers or the corresponding TRISA/B registers.

See Also:
Serialized Form

Field Summary
(package private) static boolean[] _StdLogic1164ToBooleanTable
           
 int[] currentPortInputsA
           
 int[] currentPortInputsB
           
 int[] currentPortOutputsA
           
 int[] currentPortOutputsB
           
 int lastClk
           
 int lastOsc2
           
 int[] lastPortInputsB
           
 int lastT0cki
           
 int n_cycles
           
 int n_dirty_pa
           
 int n_dirty_pb
           
 int n_dirty_ta
           
 int n_dirty_tb
           
 int n_handledPortChanges
           
 int n_inputPortChanges
           
 PicExec pic
           
 PortStdLogic1164[] portA
           
 PortStdLogic1164[] portB
           
 PortStdLogic1164 portClkin
           
 PortStdLogic1164 portClkout
           
 PortStdLogic1164 portMclr
           
 PicPortReg regPortA
           
 PicPortReg regPortB
           
 PicWordReg regTrisA
           
 PicWordReg regTrisB
           
 boolean resetActive
           
 StringDialog sd
           
 ShowPic2 show
           
 Signal[] signalA
           
 Signal[] signalB
           
 Signal signalClkin
           
 Signal signalClkout
           
 Signal signalMclr
           
 double t_delay
           
(package private)  double t_now
           
 StdLogic1164 value_0
           
 StdLogic1164 value_1
           
 StdLogic1164 value_Z
           
 
Fields inherited from class hades.simulator.SimObject
classloader, console, debug, editor, name, parent, ports, propertySheet, simulator, symbol, versionId, visible
 
Constructor Summary
SmartPic16F84()
           
 
Method Summary
 void configure()
          create and display a 'ConfigDialog' to set the parameters for a SimObject.
 boolean convertToBoolean(int value)
           
 boolean convertToBoolean(StdLogic1164 value)
           
 void createClockPeriodGUI()
           
 void createPicExec()
           
 void createPorts()
           
 void doCheckBreakpoint()
           
 void doCheckIncrementTMR0()
           
 void doCheckPortsForInterrupt()
           
 void doPrintPortRegDirtyStatistics()
           
 void doReadPortsRaw()
           
 void doReset()
           
 void doSamplePorts()
           
 void doSetClkout(StdLogic1164 value, double t)
           
 void doSetPorts()
           
 void doUpdateShowPic()
           
 void elaborate(java.lang.Object arg)
          elaborate: initialize the SmartPic16C84 model.
 void evaluate(java.lang.Object arg)
          evaluate(): called by the simulation engine on all events that concern this object.
 void finalize()
           
 java.lang.String[] getExternalResources()
          return a String[] array of length 1 with the program ROM init file.
 java.awt.Component getPropertySheet()
          return a reference to the 'property sheet' or configuration window for this SimObject.
 java.lang.String getToolTip(java.awt.Point position, long millis)
          construct a tool tip message (with the timing parameters)
 boolean initialize(java.lang.String s)
          initialize PicEprom from a String.
 void instructionCycle()
           
 boolean needsExternalResources()
          we use one external resource: the program ROM initialization file.
 boolean nextExternalEventIsLate()
           
 boolean nextExternalEventIsLateOLD()
           
 void printPortBackupArrays()
           
 void readInputPorts()
          read the values of all StdLogic1164 signals connected to ports A/B and initialize the currentPortInputsA/B arrays.
 java.lang.String toString()
          toString: generate a text description for this SimObject.
 void wakeup(java.lang.Object event)
          wakeup: either the main clock-period or the watchdog-timer period has elapsed.
 void write(java.io.PrintWriter ps)
          write FastPIC configuration data to a HADES design file: versionID, clk4Period (instruction cycle time), program EPROM resource name
 
Methods inherited from class hades.simulator.SimObject
constructDynamicSymbol, copy, getBindkey, getClassLoader, getDebug, getEditor, getFullName, getName, getParent, getPort, getPorts, getResourceAsStream, getSimulator, getSymbol, getSymbolResourceName, getVersionId, isVisible, keyPressed, message, mousePressed, needsDynamicSymbol, setClassLoader, setConsole, setDebug, setEditor, setName, setParent, setPorts, setSimulator, setSymbol, setVersionId, setVisible, tearDown
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface hades.simulator.Simulatable
message
 

Field Detail

show

public ShowPic2 show

sd

public StringDialog sd

pic

public PicExec pic

regPortA

public PicPortReg regPortA

regPortB

public PicPortReg regPortB

regTrisA

public PicWordReg regTrisA

regTrisB

public PicWordReg regTrisB

portClkin

public PortStdLogic1164 portClkin

portClkout

public PortStdLogic1164 portClkout

portMclr

public PortStdLogic1164 portMclr

portA

public PortStdLogic1164[] portA

portB

public PortStdLogic1164[] portB

value_Z

public StdLogic1164 value_Z

value_0

public StdLogic1164 value_0

value_1

public StdLogic1164 value_1

signalClkin

public Signal signalClkin

signalClkout

public Signal signalClkout

signalMclr

public Signal signalMclr

signalA

public Signal[] signalA

signalB

public Signal[] signalB

currentPortInputsA

public int[] currentPortInputsA

currentPortInputsB

public int[] currentPortInputsB

lastPortInputsB

public int[] lastPortInputsB

currentPortOutputsA

public int[] currentPortOutputsA

currentPortOutputsB

public int[] currentPortOutputsB

n_inputPortChanges

public int n_inputPortChanges

n_handledPortChanges

public int n_handledPortChanges

t_now

double t_now

n_cycles

public int n_cycles

n_dirty_pa

public int n_dirty_pa

n_dirty_ta

public int n_dirty_ta

n_dirty_pb

public int n_dirty_pb

n_dirty_tb

public int n_dirty_tb

lastClk

public int lastClk

lastOsc2

public int lastOsc2

lastT0cki

public int lastT0cki

resetActive

public boolean resetActive

t_delay

public double t_delay

_StdLogic1164ToBooleanTable

static boolean[] _StdLogic1164ToBooleanTable
Constructor Detail

SmartPic16F84

public SmartPic16F84()
Method Detail

createPicExec

public void createPicExec()

needsExternalResources

public boolean needsExternalResources()
we use one external resource: the program ROM initialization file.

Overrides:
needsExternalResources in class SimObject

getExternalResources

public java.lang.String[] getExternalResources()
return a String[] array of length 1 with the program ROM init file.

Overrides:
getExternalResources in class SimObject

toString

public java.lang.String toString()
Description copied from class: SimObject
toString: generate a text description for this SimObject. This method currently combines the class name for the SimObject (or subclass) and its full name in the current Hades Design, e.g. "hades.models.gates.And2: /uut/adder16/adder1/i3".

Overrides:
toString in class SimObject

getToolTip

public java.lang.String getToolTip(java.awt.Point position,
                                   long millis)
construct a tool tip message (with the timing parameters)

Specified by:
getToolTip in interface ContextToolTip
Overrides:
getToolTip in class SimObject

createPorts

public void createPorts()

initialize

public boolean initialize(java.lang.String s)
initialize PicEprom from a String. Currently, the String should contain the following things: the Pic16C84-versionId, and the filename of the RAM datafile to parse, e.g.
       1001 /home/rink/hades/models/pic/echo232.rom
    

Overrides:
initialize in class SimObject

write

public void write(java.io.PrintWriter ps)
write FastPIC configuration data to a HADES design file: versionID, clk4Period (instruction cycle time), program EPROM resource name

Overrides:
write in class SimObject

elaborate

public void elaborate(java.lang.Object arg)
elaborate: initialize the SmartPic16C84 model. We schedule the initial wakeup-events of both the main processor clock and the watchdog timer.

Specified by:
elaborate in interface Simulatable
Overrides:
elaborate in class SimObject

wakeup

public void wakeup(java.lang.Object event)
wakeup: either the main clock-period or the watchdog-timer period has elapsed.

Specified by:
wakeup in interface Wakeable

nextExternalEventIsLate

public boolean nextExternalEventIsLate()

nextExternalEventIsLateOLD

public boolean nextExternalEventIsLateOLD()

printPortBackupArrays

public void printPortBackupArrays()

evaluate

public void evaluate(java.lang.Object arg)
Description copied from interface: Simulatable
evaluate(): called by the simulation engine on all events that concern this object. The object is responsible for updating its internal state and for scheduling all pending output events.

Specified by:
evaluate in interface Simulatable
Overrides:
evaluate in class SimObject
Parameters:
arg - an arbitrary object argument

doReset

public void doReset()

readInputPorts

public void readInputPorts()
read the values of all StdLogic1164 signals connected to ports A/B and initialize the currentPortInputsA/B arrays.


doCheckPortsForInterrupt

public void doCheckPortsForInterrupt()

doCheckIncrementTMR0

public void doCheckIncrementTMR0()

doReadPortsRaw

public void doReadPortsRaw()

doSamplePorts

public void doSamplePorts()

doSetPorts

public void doSetPorts()

doPrintPortRegDirtyStatistics

public void doPrintPortRegDirtyStatistics()

finalize

public void finalize()
              throws java.lang.Throwable
Throws:
java.lang.Throwable

doCheckBreakpoint

public void doCheckBreakpoint()

doUpdateShowPic

public void doUpdateShowPic()

doSetClkout

public void doSetClkout(StdLogic1164 value,
                        double t)

instructionCycle

public void instructionCycle()

getPropertySheet

public java.awt.Component getPropertySheet()
Description copied from class: SimObject
return a reference to the 'property sheet' or configuration window for this SimObject. We cast the return value to an AWT Component, but typically you can expect either a hades.gui.PropertySheet or an java.awt.Window (Dialog or Frame).

Overrides:
getPropertySheet in class SimObject

configure

public void configure()
Description copied from class: SimObject
create and display a 'ConfigDialog' to set the parameters for a SimObject. The default ConfigDialog for the base class (SimObject) itself is empty except for the 'instance name' of the SimObject.

Overrides:
configure in class SimObject

convertToBoolean

public final boolean convertToBoolean(int value)

convertToBoolean

public boolean convertToBoolean(StdLogic1164 value)

createClockPeriodGUI

public void createClockPeriodGUI()