我想使用always块中另一个模块的输出。 目前,以使此代码工作的唯一途径是通过增加#1的 pi_in分配后,使有足够的时间已经过去了,让曹丕完成。Verilog:在always块中等待模块逻辑评估
有关部分从模块pLayer.v:
Pi pi(pi_in,pi_out);
always @(*)
begin
for(i=0; i<constants.nSBox; i++) begin
for(j=0; j<8; j++) begin
x = (state_value[(constants.nSBox-1)-i]>>j) & 1'b1;
pi_in = 8*i+j;#1; /* wait for pi to finish */
PermutedBitNo = pi_out;
y = PermutedBitNo>>3;
tmp[(constants.nSBox-1)-y] ^= x<<(PermutedBitNo-8*y);
end
end
state_out = tmp;
end
Modllue Pi.v
`include "constants.v"
module Pi(in, out);
input [31:0] in;
output [31:0] out;
reg [31:0] out;
always @* begin
if (in != constants.nBits-1) begin
out = (in*constants.nBits/4)%(constants.nBits-1);
end else begin
out = constants.nBits-1;
end
end
endmodule
延误的,应当不会在最终实现中使用,所以有不使用#1另一种方式?
在本质上我想PermutedBitNo = pi_out后才裨模块完成其与pi_in(= 8 * I + J)作为输入作业进行评估。 如何在Pi完成之前阻止此行?
我必须使用时钟吗?如果是这样,请给我一个提示。
更新:
基于Krouitch建议我修改的模块。以下是更新版本:
从pLayer.v:
Pi pi(.clk (clk),
.rst (rst),
.in (pi_in),
.out (pi_out));
counter c_i (clk, rst, stp_i, lmt_i, i);
counter c_j (clk, rst, stp_j, lmt_j, j);
always @(posedge clk)
begin
if (rst) begin
state_out = 0;
end else begin
if (c_j.count == lmt_j) begin
stp_i = 1;
end else begin
stp_i = 0;
end
// here, the logic starts
x = (state_value[(constants.nSBox-1)-i]>>j) & 1'b1;
pi_in = 8*i+j;
PermutedBitNo = pi_out;
y = PermutedBitNo>>3;
tmp[(constants.nSBox-1)-y] ^= x<<(PermutedBitNo-8*y);
// at end
if (i == lmt_i-1)
if (j == lmt_j) begin
state_out = tmp;
end
end
end
endmodule
module counter(
input wire clk,
input wire rst,
input wire stp,
input wire [32:0] lmt,
output reg [32:0] count
);
[email protected](posedge clk or posedge rst)
if(rst)
count <= 0;
else if (count >= lmt)
count <= 0;
else if (stp)
count <= count + 1;
endmodule
从Pi.v:
always @* begin
if (rst == 1'b1) begin
out_comb = 0;
end
if (in != constants.nBits-1) begin
out_comb = (in*constants.nBits/4)%(constants.nBits-1);
end else begin
out_comb = constants.nBits-1;
end
end
[email protected](posedge clk) begin
if (rst)
out <= 0;
else
out <= out_comb;
end
谢谢你,你的提示让我更进一步。 但是,现在我有问题,out_comb总是不是一个,但(出于某种原因)两个周期后。 所以当我想在tmp中使用PermuteBitNo时,它会返回不正确的结果。 – cie
你可以附加你的文章吗? – Krouitch
请注意,out_comb必须是一个reg,因为它被分配在always块中。另外我不知道你为什么使用否定重置。有没有特定的原因? – cie