问题描述
有人可以帮我理解为什么我的功能无法正常工作吗?
module TestBench2();
localparam SELECT_NONE = 0;
localparam SELECT_RAM = 1;
localparam SELECT_VGA = 2;
localparam SELECT_UNKNowN = 8;
logic iClk;
logic reset;
logic [ 4 : 0 ] chipSelect;
logic [ 4 : 0 ] requestChipSelect;
logic [ 4 : 0 ] chipSelected;
logic oVGAInitReadRequest;
logic oVgalineComplete;
initial
begin
reset = 1;
oVGAInitReadRequest = 0;
oVgalineComplete = 0;
chipSelected = SELECT_UNKNowN;
end
function automatic logic [ 4 : 0 ] chipSelectFunc;
input requestChipSelect,oVGAInitReadRequest,oVgalineComplete;
if( requestChipSelect == SELECT_VGA )
begin
$display( " requestChipSelect == SELECT_VGA? -> YES");
chipSelectFunc = SELECT_VGA;
chipSelected = SELECT_VGA;
end
else
if( oVGAInitReadRequest )
begin
$display( " oVGAInitReadRequest? -> YES");
chipSelectFunc = SELECT_VGA;
chipSelected = SELECT_VGA;
end
else
if( oVgalineComplete )
begin
$display( " oVgalineComplete? -> YES");
chipSelectFunc = SELECT_NONE;
chipSelected = SELECT_NONE;
end
else
if( requestChipSelect == SELECT_RAM )
begin
$display( " requestChipSelect == SELECT_RAM? -> YES");
chipSelectFunc = SELECT_RAM;
chipSelected = SELECT_RAM;
end
else
if( requestChipSelect == SELECT_NONE )
begin
$display( " requestChipSelect == SELECT_NONE? -> YES");
chipSelectFunc = SELECT_NONE;
chipSelected = SELECT_NONE;
end
else
begin
$display( "requestChipSelect -> STAY SAME");
// Leave it as-is
chipSelectFunc = chipSelected;
end
endfunction
assign chipSelect = chipSelectFunc( requestChipSelect,oVgalineComplete );
integer count = 0;
always @( posedge iClk )
begin
reset = 0;
case( count )
1: begin
$strobe ("%2d:requestChipSelect <= SELECT_VGA",count);
requestChipSelect <= SELECT_VGA;
end
2: begin
$strobe ("%2d:requestChipSelect <= SELECT_NONE",count);
requestChipSelect <= SELECT_NONE;
end
default: begin
$strobe ("%2d:Default case",count);
end
endcase
$strobe ("%2d:chipSelect: %d ",count,chipSelect);
count ++;
end
endmodule
# requestChipSelect -> STAY SAME
# 1:Default case
# 1:chipSelect: 8
# requestChipSelect == SELECT_NONE? -> YES
# 2:requestChipSelect <= SELECT_VGA
# 2:chipSelect: 0
# requestChipSelect == SELECT_NONE? -> YES
为什么将requestChipSelect
设置为SELECT_VGA
(2)时,我的函数始终将其视为/ 0
处理?
解决方法
因为您已声明requestChipSelect
为1位宽:
function automatic logic [ 4 : 0 ] chipSelectFunc;
input requestChipSelect,oVGAInitReadRequest,oVGALineComplete;
代替(例如)5,就像您的返回值一样:
function automatic logic [ 4 : 0 ] chipSelectFunc;
input [ 4 : 0 ] requestChipSelect;
input oVGAInitReadRequest,oVGALineComplete;