Parsing files
This commit is contained in:
parent
3244deeaac
commit
ca60668859
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
This reads a binary or ASCII file and creates an AXI stream,
|
||||
used for testbench purposes. Can optionally add in random flow control.
|
||||
|
||||
Only binary is supported at this moment.
|
||||
|
||||
Copyright (C) 2019 Benjamin Devlin and Zcash Foundation
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
module file_to_axi #(
|
||||
parameter HDR_BYTS,
|
||||
parameter DAT_BYTS,
|
||||
parameter BINARY, // 0 for ASCII, 1 for binary
|
||||
parameter string FILE = "", // Path to file
|
||||
parameter FP = 0 // Forward pressure, if this is non-zero then this is the % of cycles o_axi.val will be low
|
||||
) (
|
||||
input i_clk, i_rst,
|
||||
if_axi_stream.source o_axi
|
||||
);
|
||||
|
||||
|
||||
logic [DAT_BYTS*8-1:0] data_temp;
|
||||
integer fp, r;
|
||||
logic sop_l;
|
||||
|
||||
initial begin
|
||||
o_axi.reset_source();
|
||||
sop_l = 0;
|
||||
fp = $fopen(FILE, BINARY ? "rb" : "r");
|
||||
if (fp==0) $fatal(1, "%m %t ERROR: file_to_axi could not open file %s", $time, FILE);
|
||||
|
||||
if (BINARY == 0) begin
|
||||
$fatal(1, "%m %t ERROR: file_to_axi BINARY == 0 not supported", $time);
|
||||
end else begin
|
||||
while(!$feof(fp)) begin
|
||||
r = $fread(o_axi.dat, fp);
|
||||
o_axi.val = 1; // TODO
|
||||
o_axi.sop = ~sop_l;
|
||||
sop_l = 1;
|
||||
o_axi.eop = $feof(fp);
|
||||
o_axi.mod = $feof(fp) ? r : 0;
|
||||
|
||||
@(posedge o_axi.clk);
|
||||
while (!(o_axi.val && o_axi.rdy)) @(posedge o_axi.clk);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
o_axi.reset_source();
|
||||
$display("%m %t INFO: file_to_axi finished reading file %s", $time, FILE);
|
||||
$fclose(fp);
|
||||
end
|
||||
|
||||
endmodule
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
This takes in a AXI stream, appends a header, and outputs the resulting stream.
|
||||
|
||||
Copyright (C) 2019 Benjamin Devlin and Zcash Foundation
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
module header_adder #(
|
||||
parameter HDR_BYTS,
|
||||
parameter DAT_BYTS
|
||||
) (
|
||||
input i_clk, i_rst,
|
||||
|
||||
input [HDR_BYTS*8-1:0] i_header, // Must be valid during i_axi.val
|
||||
if_axi_stream.sink i_axi,
|
||||
if_axi_stream.source o_axi
|
||||
);
|
||||
|
||||
logic [(DAT_BYTS+(HDR_BYTS % DAT_BYTS))*8-1:0] dat_buff;
|
||||
logic sop_l;
|
||||
logic [$clog2(HDR_BYTS)-1:0] hdr_cnt;
|
||||
|
||||
always_comb begin
|
||||
i_axi.dat = dat_buff[HDR_BYTS*8 +: DAT_BYTS*8];
|
||||
end
|
||||
|
||||
always_ff @ (posedge i_clk) begin
|
||||
if (i_rst) begin
|
||||
dat_buff <= 0;
|
||||
hdr_cnt <= 0;
|
||||
i_axi.rdy <= 0;
|
||||
sop_l <= 0;
|
||||
o_axi.reset_source();
|
||||
end else begin
|
||||
i_axi.rdy <= o_axi.rdy && (hdr_cnt + DAT_BYTS >= HDR_BYTS);
|
||||
if (~o_axi.val || (~o_axi.val && o_axi.rdy)) begin
|
||||
o_axi.sop <= ~sop_l;
|
||||
o_axi.val <= i_axi.val;
|
||||
o_axi.err <= i_axi.err;
|
||||
o_axi.ctl <= i_axi.ctl;
|
||||
o_axi.mod <= (i_axi.mod + HDR_BYTS) % DAT_BYTS;
|
||||
o_axi.eop <= i_axi.eop;
|
||||
hdr_cnt <= (hdr_cnt + DAT_BYTS >= HDR_BYTS) ? hdr_cnt : hdr_cnt + DAT_BYTS;
|
||||
sop_l <= i_axi.sop;
|
||||
//TODO
|
||||
dat_buff <= {dat_buff[0 +: (HDR_BYTS % DAT_BYTS)*8], i_axi.dat};
|
||||
|
||||
|
||||
if (i_axi.eop) hdr_cnt <= 0;
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
Loading…
Reference in New Issue