-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwrite_pcap_task.sv
More file actions
47 lines (42 loc) · 1.67 KB
/
write_pcap_task.sv
File metadata and controls
47 lines (42 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
task automatic write_pcap_task
(
string file_name,
ref reg clk,
ref reg packet_en,
ref reg [7:0] packet[]
);
reg [7:0] file_hdr [23:0] = {
8'ha1,8'hb2,8'hc3,8'hd4,
8'h00,8'h02,8'h00,8'h04,
8'h00,8'h00,8'h00,8'h00,
8'h00,8'h00,8'h00,8'h00,
8'h00,8'h00,8'hff,8'hff,
8'h00,8'h00,8'h00,8'h01
};
reg [7:0] pcap_hdr [15:0] = {
8'h00,8'h00,8'h00,8'h00,
8'h00,8'h00,8'h00,8'h00,
8'h00,8'h00,8'h00,8'h00,
8'h00,8'h00,8'h00,8'h00
};
reg [31:0] len_pac=0;
automatic integer fd = $fopen(file_name,"wb");
foreach(file_hdr[i]) $fwrite(fd,"%c",file_hdr[i]);
@(posedge clk);
while(1) begin
@(posedge clk);
if (packet_en) begin
len_pac = packet.size();
pcap_hdr[0] = len_pac[7:0];
pcap_hdr[1] = len_pac[15:8];
pcap_hdr[2] = len_pac[23:16];
pcap_hdr[3] = len_pac[31:24];
pcap_hdr[4] = len_pac[7:0];
pcap_hdr[5] = len_pac[15:8];
pcap_hdr[6] = len_pac[23:16];
pcap_hdr[7] = len_pac[31:24];
foreach(pcap_hdr[i]) $fwrite(fd,"%c",pcap_hdr[i]);
foreach(packet[i]) $fwrite(fd,"%c",packet[i]);
end
end
endtask