Advertisement
Guest User

dev_new_tb.sv

a guest
Apr 30th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1 ps/ 1 ps
  2.  
  3. //command bit definitions
  4. import cmd_bits::*;
  5.  
  6. module dev_new_tb();
  7.  
  8.     //parameters
  9.     parameter DW = 8;
  10.  
  11.     // test vector input registers
  12.     logic clk;
  13.     logic cs;
  14.     logic [DW-1:0] din;
  15.     logic rst;
  16.     // module output connections
  17.     logic busy;
  18.     logic [DW-1:0] dout;
  19.     logic drdy;
  20.     // testbench variables
  21.     logic [DW-1:0] res;
  22.  
  23.     //device under test
  24.     dev_new #(.DW(DW)) dut (
  25.         .busy(busy),
  26.         .clk(clk),
  27.         .cs(cs),
  28.         .din(din),
  29.         .dout(dout),
  30.         .drdy(drdy),
  31.         .rst(rst)
  32.     );
  33.  
  34.     // create clock
  35.     initial                                                
  36.     begin                                                  
  37.         clk=0;
  38.         forever #10 clk=~clk;
  39.     end                                                    
  40.  
  41.     // reset circuit and run several transactions
  42.     initial
  43.     begin
  44.         // reset
  45.         rst=0;
  46.         @(negedge clk) rst=1;
  47.         //skip one edge after reset
  48.         @(posedge clk);
  49.         // send two operands and initial cmd register
  50.         write_transaction((1<<b_op_1)|(1<<b_op_2)|(1<<b_addop)|(1<<b_tx),$random,$random);
  51.         // transmit the result
  52.         transmitor(res);
  53.         // send one operand
  54.         write_transaction((1<<b_op_1)|(1<<b_addres)|(1<<b_tx),$random,0);
  55.         // transmit the result
  56.         transmitor(res);
  57.         //wait couple clock cycles
  58.         repeat (2) @(posedge clk);
  59.         //stop simulation
  60.         $stop;
  61.     end
  62.    
  63.     //basic transaction with module
  64.     task write_transaction;
  65.         //input signals
  66.         input [DW-1:0] cmd;
  67.         input [DW-1:0] op_1;
  68.         input [DW-1:0] op_2;
  69.         //output [DW-1:0] result;
  70.         //transaction implementation
  71.         begin
  72.             //wait while device is busy
  73.             while (busy) @(posedge clk);
  74.             //set chip select and write command to DUT
  75.             cs=1;
  76.             din=cmd;
  77.             //clear chip select
  78.             @(posedge clk);
  79.             cs=0;
  80.             //write op_1 if required and wait for one clock cycle
  81.             if (cmd[b_op_1])
  82.             begin
  83.                 din=op_1;
  84.                 @(posedge clk);
  85.             end
  86.             //write op_2 if required and wait for one clock cycle
  87.             if (cmd[b_op_2])
  88.             begin
  89.                 din=op_2;
  90.                 @(posedge clk);
  91.             end
  92.            
  93.         end
  94.     endtask
  95.  
  96.     // Transmission of the result of the operation to the output
  97.  
  98.     task transmitor;
  99.         output [DW-1:0] result;
  100.  
  101.         begin
  102.             while (busy) @(posedge clk);
  103.                 while (!drdy) @(posedge clk);
  104.                 result = dout;
  105.         end
  106.     endtask
  107.  
  108.        
  109.    
  110. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement