I’m trying to use a function to do the same as this line (which is commented out in the below testbench):
assign chipSelect = ( reset ) ? SELECT_NONE : SELECT_VGA;
The expected output for 3 clock cycles is:
# TestBench2 : time 0 chipSelect: 0
# TestBench2 : time 20000 chipSelect: 2
# TestBench2 : time 40000 chipSelect: 2
But when I run the below testbench using a function, I get this:
# TestBench2 : time 0 chipSelect: 0
# TestBench2 : time 20000 chipSelect: 0
# TestBench2 : time 40000 chipSelect: 0
Why won’t my function behave as expected? There must be something fundamental I am missing. I realise there is no point in using a function for this trivial example but I’d like to know why it won’t work anyway - I was hoping to use a function in a more complicated use case.
module TestBench2();
logic iClk;
localparam SELECT_NONE = 0;
localparam SELECT_VGA = 2;
logic [ 2 : 0 ] chipSelect;
logic reset;
initial
begin
reset = 1;
end
function automatic logic [ 2 : 0 ] chipSelectFunc();
if( reset )
begin
chipSelectFunc = SELECT_NONE;
end
else
begin
chipSelectFunc = SELECT_VGA;
end
endfunction
assign chipSelect = chipSelectFunc();
//assign chipSelect = ( reset ) ? SELECT_NONE : SELECT_VGA; // This works as expected
always @( posedge iClk )
begin
$display ("%m : time %t chipSelect: %d ", $time, chipSelect);
reset = 0;
end
endmodule