framework for later dev
This commit is contained in:
47
src/testbench/bitstream.sv
Normal file
47
src/testbench/bitstream.sv
Normal file
@@ -0,0 +1,47 @@
|
||||
`include <bitstream.svh>
|
||||
|
||||
`include <params.svh>
|
||||
|
||||
task bitstream::append_packet(input Packet pkt);
|
||||
for (int i = 0; i < PACKET_SIZE; i++) begin
|
||||
this.append_byte(pkt.get_pos(i));
|
||||
end
|
||||
endtask : append_packet
|
||||
|
||||
task bitstream::append_byte(input byte data);
|
||||
for (int i = 0; i < 8; i++) begin
|
||||
this.queue.push_back(data[i]);
|
||||
end
|
||||
endtask : append_byte
|
||||
|
||||
task bitstream::append_bit(input bit data);
|
||||
this.queue.push_back(data);
|
||||
endtask : append_bit
|
||||
|
||||
task bitstream::parse_packets(ref Packet results[]);
|
||||
Packet pkt_tmp;
|
||||
bit bit_tmp[PACKET_SIZE * 8];
|
||||
int curr = 0;
|
||||
logic in_packet = 0;
|
||||
for (int i = 0; i < this.queue.size(); i = i + 8) begin
|
||||
if ((!in_packet) & (this.queue[i:i + 7] == 0))
|
||||
continue;
|
||||
|
||||
in_packet = 1;
|
||||
bit_tmp[curr:curr + 7] = this.queue[i:i + 7];
|
||||
curr = curr + 8;
|
||||
|
||||
if (curr == PACKET_SIZE * 8) begin
|
||||
pkt_tmp.construct(bit_tmp);
|
||||
results.push_back(pkt_tmp);
|
||||
curr = 0;
|
||||
in_packet = 0;
|
||||
end
|
||||
end
|
||||
endtask : parse_packets
|
||||
|
||||
task bitstream::trim();
|
||||
while (this.queue.size() >= 8 & this.queue[0:7] == 0)
|
||||
for (int i = 0; i < 8; i++)
|
||||
this.queue.pop_front();
|
||||
endtask : trim
|
Reference in New Issue
Block a user