import java.io.*; import byucc.jhdl.base.*; import byucc.jhdl.Logic.*; /** * tb_fsmMemCtl - Testbench for memory controller FSM example. * */ public class tb_fsmMemCtl extends Synchronous implements TestBench { // These are the wires which will be passed into FSM Wire clr; Wire wReq; Wire rReq; Wire latchAddr; Wire rw_; Wire ack; // The constructor for the testbench public tb_fsmMemCtl (Node parent) { super (parent, "tb_fsmMemCtl"); // Instance all wires in this design clr = Logic.wire(this, "clr"); wReq = Logic.wire(this, "wReq"); rReq = Logic.wire(this, "rReq"); latchAddr = Logic.wire(this, "latchAddr"); rw_ = Logic.wire(this, "rw_"); ack = Logic.wire(this, "ack"); // Build the FSM fsmMemCtl f = new fsmMemCtl (this, clr, wReq, rReq, latchAddr, rw_, ack, "fsmMemCtl.fsm"); } // This routine gets called on initialization public void reset() { clr.put(this, 1); wReq.put(this, 0); rReq.put(this, 0); } // Here are the inputs which will be driven into the circuit each cycle static String inputs[] = { "100", "000", "010", "000", "000", "000", "011", "000", "000", "000", "000", "001", "000", "000", "000", }; // Here are the input/output combinations we expect to get back out static String results[] = { "100 010", // Reset the circuit "100 010", "000 010", "010 110", // Write request arrived, assert latchAddr "000 010", "000 001", // Strobe rw_ signal and assert ack "000 010", "011 110", // Write request takes priority over read request "000 010", "000 001", // Strobe rw_ signal and assert ack "000 010", "000 010", "001 110", // Read request arrived, assert latchAddr "000 011", // Assert ack "000 010" }; // Global flag to signal a simulation error occured static boolean simError = false; // Count number of clock cycles int clkCnt = 0; // This routine gets called each cycle. Will check outputs and // assert new inputs. public void clock() { String s; // Build results string s = "" + clr.get(this)+ wReq.get(this)+ rReq.get(this) + " "; s += "" + latchAddr.get(this)+ rw_.get(this) + ack.get(this); System.out.println(s); // See if we got the right answer if (!s.equals(results[clkCnt])){ simError = true; System.err.println(" Error in cycle " + clkCnt + " - expected " + results[clkCnt] + " , got " + s + " instead."); } // Get new inputs to drive out and assign them s = inputs[clkCnt]; clkCnt++; clr.put(this, s.charAt(0) - '0'); wReq.put(this, s.charAt(1) - '0'); rReq.put(this, s.charAt(2) - '0'); } // Main routine. Build testbench and execute it. Tell user if // error occured. public static void main (String[] args) { System.err.println("fsmMemCtl Test"); HWSystem system = new HWSystem(); new tb_fsmMemCtl (system); System.err.println("Everything is built...."); system.cycle(inputs.length); if (!simError) System.out.println("**** Simulation OK ****"); } }