How to access the structures from testbench

583 Views Asked by At
typedef struct packed signed{
    bit valid;
    bit tag;
    bit signed[31:0] data;
}my_data;

module structure_example5(input clk,input my_data a);

always@(posedge clk) begin
    if(a.tag>a.valid)begin
      $display("G");
    end
    else begin
      $display("L");
    end
  end

endmodule:structure_example5

//TEST BENCH

module structure_example5_tb;

reg clk;
  reg a.tag,a.valid;  

  structure_example5 uut (clk,a);

  initial begin
   #5 
   clk=0;
   forever
     #5clk=!clk;
  end

  initial begin
    a.tag=1'b1;
    a.valid=1'b0;
    #50
    $finish();
  end 
endmodule:structure_example5_tb
1

There are 1 best solutions below

2
On BEST ANSWER

Until and unless struct is of single direction there won't be any difficulty in connecting test-bench and DUT ports together

Here at your test-bench code comment out reg declaration of structure members and use structure declaration

//reg a.tag,a.valid;  
my_data a;

and try to run your code, the corrected/working code can be found in the link

UPDATE:

As per Dave's suggestion, it is recommended that when sharing typedefs with multiple modules using a package is the better solution, to use, define all your typedefs inside the package and import the package in the required module, it can be any module including testbench and DUT.

eg:

package my_pkg;    
typedef struct packed signed{
          bit valid;
          bit tag;
          bit signed[31:0] data;
      }my_data;
endpackage

and whenever you require content of package inside your module use

import my_pkg::*;  

Also updated the link mentioned above with package