我正在尝试为多速率数据总线建立环形拓扑。我不知道如何根据数据包的优先级在节点上获得输出。假设我要从环形节点中获取数据包。我想根据其优先级获取数据包。谁能指导我如何为这件事编写Verilog代码。我试图写嵌套的if else条件,如下所示。
module demux0(
input clock,
input reset,
input [43:0]in,
output reg [43:0]out0,
output reg [43:0]out1
);
always @(posedge clock)
begin
if(reset)
begin
out0<=0;
out1<=0;
end
else if(in[3:0]==4'b0000 && in[13:4]==10'b0000000001) //so nested if else to gain the priority
begin
out1<=in; //so the packet with the highest priority goes to the output
if(in[3:0]==4'b0000 && in[13:4]==10'b0000000010) //check the second priority packet
begin
out1<=in;
if(in[3:0]==4'b0000 && in[13:4]==10'b0000000100)
begin
out1<=in;
if(in[3:0]==4'b0000 && in[13:4]==10'b0000001000)
begin
out1<=in;
end
end
end
end
else
begin
out0<=in;
end
end
endmodule
所以这是一个多路分配器,如果输入[3:0]和输入[13:4]中的位匹配,则选择输出1,否则选择输出0。 但是此代码的问题是对环进行了计时,因此,如果在一个时钟周期我得到了具有最高优先级的数据包,即10'b0000000001,而在3个时钟周期之后,我得到了我第二高优先级的数据包,即10'b0000000010,那么我如果不执行循环,则嵌套。 谁能告诉我该怎么做?
答案 0 :(得分:0)
我认为您可以将代码重新设计为:
always(posedge clock)
if (reset) begin
out0 <= 0;
out1 <= 0;
end
else
if ({in[3:0], in[13:4]} == 14'b0000_0000000001)
out1<=in;
else if ({in[3:0], in[13:4]} == 14'b0000_0000000010)
out1<=in;
else if ({in[3:0], in[13:4]} == 14'b0000_0000000100)
out1<=in;
else if ({in[3:0], in[13:4]} == 14'b0000_0000001000)
out1<=in;
else
out0<=in;
或替换为if / else大小写
always(posedge clock)
if (reset) begin
out0 <= 0;
out1 <= 0;
end
else
case ({in[3:0], in[13:4]})
14'b0000_0000000001: out1<=in;
14'b0000_0000000010: out1<=in;
14'b0000_0000000100: out1<=in;
14'b0000_0000001000: out1<=in;
default: out0<=in;
enscase