加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
rand.v 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
Cody Schafer 提交于 2011-04-18 05:14 . names are too long.
module randomizer(
input reset, clk,
input in_bits,
input in_valid,
output reg out_bits,
output reg out_valid,
input [14:0] rand_iv,
input reload);
reg [14:0] vect;
reg nout;
reg nvalid;
/* XXX: EFFICIENCY: there should be a way to do this 8 bits at a time,
* as mentioned in "OFDM Baseband Transmitter Implementation Compliant
* IEEE Std 802.16d on FPGA" */
always @ (posedge clk or posedge reset) begin
if (reset) begin
nout <= 0;
nvalid <= 0;
vect <= 0;
end else begin
if (reload) begin
nvalid <= 0;
nout <= 0;
vect <= rand_iv;
end else if (in_valid) begin
nvalid <= 1;
nout <= in_bits ^ (vect[13] ^ vect[14]);
vect <= { vect[13:0], vect[13] ^ vect[14] };
end else begin
nvalid <= 0;
nout <= 0;
vect <= vect;
end
end
end
always @ (negedge clk or posedge reset) begin
if (reset) begin
out_valid <= 0;
out_bits <= 0;
end else begin
out_valid <= nvalid;
out_bits <= nout;
end
end
endmodule
/* Processes 8 (or some variation between 1 and 14 bits) at a time */
module rand_parm
#(parameter bits_pclk = 8)(
input reset, clk,
input [bits_pclk-1:0] in_bits,
input in_valid,
output reg [bits_pclk-1:0] out_bits,
output reg out_valid,
input [14:0] rand_iv,
input reload);
reg [14:0] vect;
reg [bits_pclk-1:0] nout;
reg nvalid;
always @ (posedge clk or posedge reset) begin
if (reset) begin
nvalid <= 0;
nout <= 0;
vect <= 0;
end else begin
if (reload) begin
nvalid <= 0;
nout <= 0;
vect <= rand_iv;
end else if (in_valid) begin
nvalid <= 1;
nout <= in_bits ^ (vect[13 -: bits_pclk] ^ vect[14 -: bits_pclk]);
vect <= { vect[14 - bits_pclk:0],
vect[13 -: bits_pclk] ^ vect[14 -: bits_pclk] };
end else begin
nvalid <= 0;
nout <= 0;
vect <= vect;
end
end
end
always @ (negedge clk or posedge reset) begin
if (reset) begin
out_valid <= 0;
out_bits <= 0;
end else begin
out_valid <= nvalid;
out_bits <= nout;
end
end
endmodule
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化