I used $urandom_range to add errors at random bit positions in data. I am sending this data to a decoder to correct the error. I used the code given by Mr. Bone here on stackoverflow. I am having trouble making it loop for every new error added. It only displays the final data and thats the one that gets sent to the decoder. I want it to iterate over a range and send all the new iterations to the decoder to work on.
module test_bench ();
parameter DATA_WIDTH = 13;
parameter IDX_WIDTH = $clog2(DATA_WIDTH);
wire [4:0] parity_out_enc;
wire [7:0] corr_data_out;
wire [4:0] syndrome;
wire uncorr, corr;
wire flag;
wire [4:0] vxh;
wire [4:0] parity_out;
wire [7:0] data_dec;
wire [4:0] parity_dec;
wire [IDX_WIDTH-1:0] idx_to_flip;
reg [7:0] data_enc;
initial
begin
$display ("time\t parity_out_enc data_enc idx_flip data_dec parity_dec corr_data_out syndrome uncorr corr vxh flag parity_out");
$monitor ("%g\t %b %b %d %b %b %b %b %b %b %b %b %b", $time, parity_out_enc, data_enc, idx_to_flip, data_dec, parity_dec, corr_data_out, syndrome, uncorr, corr, vxh, flag, parity_out);
data_enc = 8'b10101010;
end
secded_8_enc encoder (parity_out_enc, data_enc);
error_inject error_module (data_enc, parity_out_enc, data_dec, parity_dec, idx_to_flip);
secded_8_dec decoder (corr_data_out, syndrome, uncorr, corr, vxh, flag, parity_out, data_dec, parity_dec);
endmodule
module error_inject (data_in, parity_in, data_out, parity_out, idx_to_flip);
parameter DATA_WIDTH = 13;
parameter IDX_WIDTH = $clog2(DATA_WIDTH);
input [7:0] data_in;
input [4:0] parity_in;
output reg [7:0] data_out;
output reg [4:0] parity_out;
int i;
output reg [IDX_WIDTH-1:0] idx_to_flip;
reg [DATA_WIDTH-1:0] int_data;
always@(*)
begin
for (i=0;i<10;i=i+1)
//repeat(10)
begin
int_data = {data_in, parity_in};
idx_to_flip = $urandom_range(DATA_WIDTH-1);
$display("Flipping data bit %d", idx_to_flip);
int_data[idx_to_flip] = !int_data[idx_to_flip];
$display("bad data = %b",int_data);
data_out = int_data[12:5];
parity_out = int_data[4:0];
end
end
endmodule
Aucun commentaire:
Enregistrer un commentaire