import byucc.jhdl.Xilinx.*; import byucc.jhdl.base.*; import byucc.jhdl.Xilinx.XC4000.*; import byucc.jhdl.Logic.*; //testbench for DES. This testbench instantiates encipher and decipher //hardware and randomly generates keys and data. If the output is the same //as the input, the circuit works public class tb_DES extends Logic implements TestBench { //main method for simulation from command line public static void main(String argv[]) { //create HWSystem HWSystem hw = new HWSystem(); //create testbench tb_DES tb = new tb_DES(hw); //cycle circuit hw.cycle(10+1); } //create Wire pointers for circuit inputs and outputs Wire data_in; Wire key_in; Wire data_out; Wire data_enc; //reset behavior public void reset() { data_in.putL(this,0); key_in.putL(this,0); count = 0; } //declare and initialize cycle count variable int count = 0; //synchronous behavior for testbench public void clock() { //randomly generate key and data long data = (long)(Math.random()*Math.pow(2,63)); long key = (long)(Math.random()*Math.pow(2,63)); //put key and data in input ports data_in.putL(this,data); key_in.putL(this,key); //get output from output port and print results System.out.println("\nCycle = "+count+":"); System.out.println("\tData in="+Long.toHexString(data_in.getL(this))); System.out.println("\tData out="+Long.toHexString(data_out.getL(this))); //increment cycle count variable count++; } //testbench constructor public tb_DES(Node parent) { //superclass constructor super(parent); //create wires for inputs and output data_in = Logic.wire(this,64,"data_in"); data_enc = Logic.wire(this,64,"data_enc"); key_in = Logic.wire(this,64,"key_in"); data_out = Logic.wire(this,64,"data_out"); //set Techmapping XC4000TechMapper tm = new XC4000TechMapper( true ); Logic.setDefaultTechMapper(tm); Logic.setTechMappingEnabled(true); //create circuits. static Logic methods are used to "hardwire" the //to encipher and decipher DES my_DESe = new DES(this,Logic.constant(this,1,1),data_in,key_in, data_enc); DES my_DESd = new DES(this,Logic.constant(this,1,0),data_enc,key_in, data_out); tm.netlist(my_DESe,"my_DESe.edn"); } }