Hi
I am working on AHB-LITE code. I am using questasim for this purpose. I am trying to run my code by including classes but getting the following error:
vlog -work work -vopt -sv -stats=none C:/questasim64_2021.1/examples/AHB-LITE/sim/environment.sv
QuestaSim-64 vlog 2021.1 Compiler 2021.01 Jan 19 2021
– Compiling interface ahb_lite
– Compiling interface wrapper
– Compiling module wrap
** Warning: ** while parsing file included at C:/questasim64_2021.1/examples/AHB-LITE/sim/environment.sv(5)
** at monitor.sv(4): (vlog-2283) Extra semicolon in $unit (global) scope.
** Error: ** while parsing file included at C:/questasim64_2021.1/examples/AHB-LITE/sim/environment.sv(5)
** at monitor.sv(10): Invalid type ‘transaction’. Please check the type of the variable ‘tr’.
** Error: ** while parsing file included at C:/questasim64_2021.1/examples/AHB-LITE/sim/environment.sv(6)
** at generator.sv(8): (vlog-2294) The ‘var’ keyword is missing.
** Error: (vlog-13069) ** while parsing file included at C:/questasim64_2021.1/examples/AHB-LITE/sim/environment.sv(6)
** at generator.sv(8): near “tr”: syntax error, unexpected IDENTIFIER, expecting ‘;’ or ‘,’.
class transaction;
logic [1:0] HTRANS;
logic [2:0] HSIZE;
logic [2:0] HBURST;
rand logic [7:0] HADDR;
logic HWRITE;
logic [3:0] HPROT;
rand logic [31:0] HWDATA;
logic HREADYOUT;
logic HRESP;
logic [31:0] HRDATA;
bit HRESETn;
bit HSEL;
transaction tr;
endclass
`ifndef include_n
`include "transaction.sv"
`endif
class generator;
mailbox gen2driv;
rand transaction tr;
int tr_count;
function new(mailbox gen2driv, int tr_count);
this.gen2driv = gen2driv;
this.tr_count = tr_count;
endfunction
localparam BYTE = 000;
localparam HALF_WORD = 001;
localparam WORD = 010;
localparam SINGLE = 000;
localparam INCR = 001;
localparam WRAP4 = 010;
localparam INCR4 = 011;
localparam WRAP8 = 100;
localparam INCR8 = 101;
localparam WRAP16 = 110;
localparam INCR16 = 111;
task create_size(input [2:0] burst_type, input [2:0] burst_size, int wrap_or_incr_size, bit read_write);
int addr;
if(burst_type == 3'b010 || 3'b100 || 3'b110) begin
for(int i = 0; i < wrap_or_incr_size; i++) begin
tr = new;
tr.randomize();
if(i == 0) begin
addr = tr.HADDR;
tr.HTRANS = 2'b10; //NONSEQ
end
else begin
tr.HADDR <= addr + 4;
tr.HTRANS <= 2'b11; //SEQ
end
tr.HWRITE <= read_write;
tr.HBURST <= burst_type;
tr.HSIZE <= burst_size;
tr.HPROT <= 4'b0011;
gen2driv.put(tr);
tr_count++;
end
end
else begin
int wrap = 0;
int start_addr;
for(int i = 0; i < 40; i++) begin
tr = new;
tr.randomize();
if(wrap < wrap_or_incr_size) begin
if(i == 0) begin
addr <= tr.HADDR;
start_addr <= tr.HADDR;
tr.HTRANS <= 2'b10; //NONSEQ
wrap++;
end
else begin
tr.HADDR <= addr + 4;
tr.HTRANS <= 2'b11; //SEQ
wrap++;
end
end
else begin
addr <= start_addr;
wrap = 0;
end
tr.HPROT <= 4'b0011;
tr.HSIZE <= burst_size;
tr.HBURST <= burst_type;
tr.HWRITE <= read_write;
tr.HPROT <= 4'b0011;
gen2driv.put(tr);
tr_count++;
end
end
endtask
task byte_sized_single_burst_write();
create_size(SINGLE, BYTE, 0, 1);
endtask
task byte_sized_single_burst_read();
create_size(SINGLE, BYTE, 0, 0);
endtask
task byte_sized_incr_burst_write();
create_size(INCR, BYTE, 100, 1);
endtask
task byte_sized_incr_burst_read();
create_size(INCR, BYTE, 100, 0);
endtask
task byte_sized_incr4_burst_write();
create_size(INCR4, BYTE, 4, 1);
endtask
task byte_sized_incr4_burst_read();
create_size(INCR4, BYTE, 4, 0);
endtask
task byte_sized_incr8_burst_write();
create_size(INCR8, BYTE, 8, 1);
endtask
task byte_sized_incr8_burst_read();
create_size(INCR8, BYTE, 8, 0);
endtask
task byte_sized_incr16_burst_write();
create_size(INCR16, BYTE, 16, 1);
endtask
task byte_sized_incr16_burst_read();
create_size(INCR16, BYTE, 16, 0);
endtask
task halfword_sized_single_burst_write();
create_size(SINGLE, HALF_WORD, 0, 1);
endtask
task halfword_sized_single_burst_read();
create_size(SINGLE, HALF_WORD, 0, 0);
endtask
task halfword_sized_incr_burst_write();
create_size(INCR, HALF_WORD, 100, 1);
endtask
task halfword_sized_incr_burst_read();
create_size(INCR, HALF_WORD, 100, 0);
endtask
task halfword_sized_incr4_burst_write();
create_size(INCR4, HALF_WORD, 4, 1);
endtask
task halfword_sized_incr4_burst_read();
create_size(INCR4, HALF_WORD, 4, 0);
endtask
task halfword_sized_incr8_burst_write();
create_size(INCR8, HALF_WORD, 8, 1);
endtask
task halfword_sized_incr8_burst_read();
create_size(INCR8, HALF_WORD, 8, 0);
endtask
task halfword_sized_incr16_burst_write();
create_size(INCR16, HALF_WORD, 16, 1);
endtask
task halfword_sized_incr16_burst_read();
create_size(INCR16, HALF_WORD, 16, 0);
endtask
task word_sized_single_burst_write();
create_size(SINGLE, WORD, 0, 1);
endtask
task word_sized_single_burst_read();
create_size(SINGLE, WORD, 0, 0);
endtask
task word_sized_incr_burst_write();
create_size(INCR, WORD, 100, 1);
endtask
task word_sized_incr_burst_read();
create_size(INCR, WORD, 100, 0);
endtask
task word_sized_incr4_burst_write();
create_size(INCR4, WORD, 4, 1);
endtask
task word_sized_incr4_burst_read();
create_size(INCR4, WORD, 4, 0);
endtask
task word_sized_incr8_burst_write();
create_size(INCR8, WORD, 8, 1);
endtask
task word_sized_incr8_burst_read();
create_size(INCR8, WORD, 8, 0);
endtask
task word_sized_incr16_burst_write();
create_size(INCR16, WORD, 16, 1);
endtask
task word_sized_incr16_burst_read();
create_size(INCR16, WORD, 16, 0);
endtask
task run();
byte_sized_single_burst_write();
byte_sized_incr_burst_write();
byte_sized_incr4_burst_write();
byte_sized_incr8_burst_write();
byte_sized_incr16_burst_write();
byte_sized_single_burst_read();
byte_sized_incr_burst_read();
byte_sized_incr4_burst_read();
byte_sized_incr8_burst_read();
byte_sized_incr16_burst_read();
half_word_sized_single_burst_write();
half_word_sized_incr_burst_write();
half_word_sized_incr4_burst_write();
half_word_sized_incr8_burst_write();
half_word_sized_incr16_burst_write();
half_word_sized_single_burst_read();
half_word_sized_incr_burst_read();
half_word_sized_incr4_burst_read();
half_word_sized_incr8_burst_read();
half_word_sized_incr16_burst_read();
word_sized_single_burst_write();
word_sized_incr_burst_write();
word_sized_incr4_burst_write();
word_sized_incr8_burst_write();
word_sized_incr16_burst_write();
word_sized_single_burst_read();
word_sized_incr_burst_read();
word_sized_incr4_burst_read();
word_sized_incr8_burst_read();
word_sized_incr16_burst_read();
endtask
endclass
`ifndef include_n
`include "transaction.sv"
`endif
class driver;
virtual ahb_lite.master driver_if;
mailbox gen2driv;
function new(virtual ahb_lite.master driver_if, mailbox gen2driv);
this.driver_if = driver_if;
this.gen2driv= gen2driv;
endfunction
task reset();
wait(driver_if.HRESETn);
driver_if.HADDR <= 0;
driver_if.HBURST <= 0;
driver_if.HPROT <= 0;
driver_if.HSIZE <= 0;
driver_if.HTRANS <= 0;
driver_if.HWDATA <= 0;
driver_if.HWRITE <= 0;
driver_if.HRESP <= 0;
driver_if.HREADY <= 0;
endtask
task write();
transaction tr;
gen2driv.get(tr);
if(driver_if.HREADYOUT && !driver_if.HRESP)begin
driver_if.HADDR <= tr.HADDR;
driver_if.HBURST <= tr.HBURST;
driver_if.HPROT <= tr.HPROT;
driver_if.HSIZE <= tr.HSIZE;
driver_if.HTRANS <= tr.HTRANS;
driver_if.HWDATA <= 0;
driver_if.HWRITE <= 1;
driver_if.HREADY <= 1;
@(posedge driver_if.HCLK)
driver_if.HWDATA <= tr.HWDATA;
end
endtask
task read();
transaction tr;
gen2driv.get(tr);
if(driver_if.HREADYOUT && !driver_if.HRESP)begin
driver_if.HADDR <= tr.HADDR;
driver_if.HBURST <= tr.HBURST;
driver_if.HPROT <= tr.HPROT;
driver_if.HSIZE <= tr.HSIZE;
driver_if.HTRANS <= tr.HTRANS;
driver_if.HWDATA <= 0;
driver_if.HWRITE <= 0;
driver_if.HREADY <= 1;
end
endtask
task run;
reset();
write();
read();
endtask
endclass
`ifndef include_n
`include "transaction.sv"
`endif
class monitor;
mailbox mon2scb;
virtual interface ahb_lite.mon mon_inf;
transaction tr;
event receive;
function new(virtual ahb_lite.mon mon_inf, mailbox mon2scb);
this.mon_inf = mon_inf;
this.mon2scb = mon2scb;
endfunction
task run();
forever begin
if(!mon_inf.HRESP && mon_inf.HREADYOUT) begin
tr = new();
tr.HADDR = mon_inf.HADDR;
tr.HBURST = mon_inf.HBURST;
tr.HPROT = mon_inf.HPROT;
tr.HSIZE = mon_inf.HSIZE;
tr.HTRANS = mon_inf.HTRANS;
tr.HWDATA = mon_inf.HWDATA;
if(mon_inf.HWRITE)begin
@(posedge monitor_if.HCLK)
tr.HWDATA <= monitor_if.HWDATA;
end
mon2scb.tr.put(tr);
->receive;
end
end
endtask
endclass
`ifndef include_n
`include "transaction.sv"
`endif
class scoreboard;
mailbox mon2scb;
transaction tr;
logic [31:0]memory[int];
int tr_count;
int error_count;
task run();
forever begin
mon2scb.get(tr);
if(tr.HWRITE)begin
memory[tr.HADDR] = tr.HWDATA;
tr_count++;
end
else if(memory[tr.HADDR] == tr.HWDATA)begin
$display("Data matched on this specific address");
tr_count++;
end
else begin
$display("Data does not match on this specific address");
error_count++;
end
end
endtask
endclass
ifdef
define include_n
include "transaction.sv"
endif
include "monitor.sv"
include “generator.sv”
include "driver.sv"
include “scoreboard.sv”
class environment;
mailbox gen_driv;
mailbox mon_scb;
generator gen;
driver driv;
monitor mon;
scoreboard scb;
virtual interface ahb_lite inf;
function new(virtual interface ahb_lite inf);
this.inf = inf;
gen_driv = new();
mon_scb = new();
gen = new(gen_driv);
driv = new(gen_driv, inf);
mon = new(mon_scb, inf);
scb = new(mon_scb);
endfunction
task before_test();
driv.reset();
endtask
task test();
fork
gen.run();
driv.run();
mon.run();
scb.run();
join_any
endtask
task after_test();
wait(gen.tr_count == 1000);
wait(scb.tr_count == 1000);
endtask
task run();
before_test();
test();
after_test();
endtask
endclass