OpenCores
URL https://opencores.org/ocsvn/ha1588/ha1588/trunk

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [rtl/] [tsu/] [ptp_parser.v] - Blame information for rev 11

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ash_riple
`timescale 1ns/1ns
2
 
3
module ptp_parser (
4
  input        clk, rst,
5 10 edn_walter
  input [31:0] int_data,
6
  input        int_valid,
7
  input        int_sop,
8
  input        int_eop,
9
  input [ 1:0] int_mod,
10
  input [31:0] sop_time,
11 4 ash_riple
 
12
  output reg        ptp_found,
13 9 edn_walter
  output reg [51:0] ptp_infor
14 4 ash_riple
);
15
 
16 10 edn_walter
reg [31:0] int_data_d1;
17
reg        int_valid_d1;
18
reg        int_sop_d1;
19
reg        int_eop_d1;
20
reg [ 1:0] int_mod_d1;
21 4 ash_riple
always @(posedge rst or posedge clk) begin
22
  if (rst) begin
23 10 edn_walter
    int_data_d1  <= 32'h00000000;
24
    int_valid_d1 <= 1'b0;
25
    int_sop_d1   <= 1'b0;
26
    int_eop_d1   <= 1'b0;
27
    int_mod_d1   <= 2'b00;
28 4 ash_riple
  end
29
  else begin
30 10 edn_walter
    if (int_valid) begin
31
      int_data_d1  <= int_data;
32
      int_mod_d1   <= int_mod;
33 4 ash_riple
    end
34 10 edn_walter
      int_valid_d1 <= int_valid;
35
      int_sop_d1   <= int_sop;
36
      int_eop_d1   <= int_eop;
37 4 ash_riple
  end
38
end
39
 
40 10 edn_walter
reg [ 9:0] int_cnt, bypass_ipv4_cnt, bypass_ipv6_cnt, bypass_udp_cnt, ptp_cnt;
41
reg bypass_vlan, ptp_l2, bypass_ipv4, bypass_ipv6, found_udp, bypass_udp, ptp_l4, ptp_event;
42 8 edn_walter
reg [ 3:0] ptp_msgid;
43
reg [15:0] ptp_seqid;
44 4 ash_riple
always @(posedge rst or posedge clk) begin
45 10 edn_walter
  if (rst) begin
46
    int_cnt <= 10'd0;
47
    bypass_ipv4_cnt <= 10'd0;
48 11 edn_walter
    bypass_ipv6_cnt <= 10'd0;
49 10 edn_walter
    bypass_udp_cnt <= 10'd0;
50
  end
51
  else begin
52
    if (int_valid_d1 && int_sop_d1)
53
      int_cnt <= 10'd0;
54
    else if (int_valid_d1)
55 11 edn_walter
      int_cnt <= int_cnt + 10'd1 - bypass_vlan - (bypass_ipv4 || bypass_ipv6 || bypass_udp);
56 10 edn_walter
 
57
    if (int_valid_d1 && int_sop_d1)
58
      bypass_ipv4_cnt <= 10'd0;
59
    else if (int_valid_d1 && bypass_ipv4)
60
      bypass_ipv4_cnt <= bypass_ipv4_cnt + 10'd1;
61
 
62
    if (int_valid_d1 && int_sop_d1)
63 11 edn_walter
      bypass_ipv6_cnt <= 10'd0;
64
    else if (int_valid_d1 && bypass_ipv6)
65
      bypass_ipv6_cnt <= bypass_ipv6_cnt + 10'd1;
66
 
67
    if (int_valid_d1 && int_sop_d1)
68 10 edn_walter
      bypass_udp_cnt <= 10'd0;
69
    else if (int_valid_d1 && bypass_udp)
70
      bypass_udp_cnt <= bypass_udp_cnt + 10'd1;
71
  end
72 4 ash_riple
end
73
 
74
always @(posedge rst or posedge clk) begin
75
  if (rst) begin
76 10 edn_walter
    bypass_vlan  <= 1'b0;
77
    bypass_ipv4  <= 1'b0;
78 11 edn_walter
    bypass_ipv6  <= 1'b0;
79 10 edn_walter
    found_udp    <= 1'b0;
80
    bypass_udp   <= 1'b0;
81
    ptp_l2    <= 1'b0;
82
    ptp_l4    <= 1'b0;
83 4 ash_riple
    ptp_event <= 1'b0;
84 10 edn_walter
  end
85
  else if (int_valid_d1 && int_sop_d1) begin
86
    bypass_vlan  <= 1'b0;
87
    bypass_ipv4  <= 1'b0;
88 11 edn_walter
    bypass_ipv6  <= 1'b0;
89 10 edn_walter
    found_udp    <= 1'b0;
90
    bypass_udp   <= 1'b0;
91
    ptp_l2    <= 1'b0;
92
    ptp_l4    <= 1'b0;
93
    ptp_event <= 1'b0;
94
  end
95
  else begin
96
    // bypass vlan
97
    // ether_type == cvlan
98
    if (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h8100)
99
      bypass_vlan <= 1'b1;
100
    else
101
      bypass_vlan <= 1'b0;
102
    // ether_type == svlan
103
    // TO BE ADDED HERE
104
 
105
    // bypass ipv4
106
    // ether_type == ip, ip_version == 4
107
    if      (int_valid_d1 && int_cnt==10'd3 && bypass_ipv4_cnt==10'd0 &&
108
             int_data_d1[31:16]==16'h0800 && int_data_d1[15:12]==4'h4)
109
      bypass_ipv4 <= 1'b1;
110
    else if (int_valid_d1 && bypass_ipv4_cnt==10'd4)
111
      bypass_ipv4 <= 1'b0;
112
 
113
    // bypass ipv6
114
    // ether_type == ip, ip_version == 6
115 11 edn_walter
    if      (int_valid_d1 && int_cnt==10'd3 && bypass_ipv4_cnt==10'd0 &&
116
             int_data_d1[31:16]==16'h86dd && int_data_d1[15:12]==4'h6)
117
      bypass_ipv6 <= 1'b1;
118
    else if (int_valid_d1 && bypass_ipv6_cnt==10'd9)
119
      bypass_ipv6 <= 1'b0;
120 10 edn_walter
 
121
    // check if it is UDP
122
    // ipv4_protocol == udp
123
    if      (int_valid_d1 && bypass_ipv4_cnt==10'd1 && int_data_d1[ 7: 0]== 8'h11)
124
      found_udp <= 1'b1;
125
    // ipv6_protocol == udp
126 11 edn_walter
    else if (int_valid_d1 && bypass_ipv6_cnt==10'd1 && int_data_d1[31:24]== 8'h11)
127
      found_udp <= 1'b1;
128 10 edn_walter
 
129
    // bypass udp
130
    // ipv4_udp
131
    if      (int_valid_d1 && bypass_ipv4_cnt==10'd4 && bypass_udp_cnt==10'd0 && found_udp)
132
      bypass_udp <= 1'b1;
133
    else if (int_valid_d1 && bypass_udp_cnt==10'd2)
134
      bypass_udp <= 1'b0;
135
    // ipv6_udp
136 11 edn_walter
    else if (int_valid_d1 && bypass_ipv6_cnt==10'd9 && bypass_udp_cnt==10'd0 && found_udp)
137
      bypass_udp <= 1'b1;
138
    else if (int_valid_d1 && bypass_udp_cnt==10'd2)
139
      bypass_udp <= 1'b0;
140 10 edn_walter
 
141
    // check if it is L2 PTP
142
    // ether_type == ptp
143
    if (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h88F7)
144
      ptp_l2 <= 1'b1;
145
    // check if it is L4 PTP
146 11 edn_walter
    // udp_dest_port == ptp_event
147 10 edn_walter
    if (int_valid_d1 && bypass_udp_cnt==10'd0 && bypass_udp && int_data_d1[31:16]==16'h013f)
148
      ptp_l4 <= 1'b1;
149
 
150
    // check if it is PTP Event message
151
    if      (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h88F7    && (int_data_d1[11: 8]== 4'h0 || int_data_d1[11:8]==4'h2))
152
      // ptp_message_id == sync || delay_req
153
      ptp_event <= 1'b1;
154
    else if (int_valid_d1 && int_cnt==10'd4 && bypass_udp_cnt==10'd1 && ptp_l4 && (int_data_d1[11: 8]== 4'h0 || int_data_d1[11:8]==4'h2))
155
      // ptp_message_id == sync || delay_req
156
      ptp_event <= 1'b1;
157
  end
158
end
159
 
160
always @(posedge rst or posedge clk) begin
161
  if (rst) begin
162 7 edn_walter
    ptp_msgid <= 4'd0;
163 8 edn_walter
    ptp_seqid <= 16'd0;
164 4 ash_riple
  end
165 10 edn_walter
  else if (int_valid_d1 && int_sop_d1) begin
166 7 edn_walter
    ptp_msgid <= 4'd0;
167 8 edn_walter
    ptp_seqid <= 16'd0;
168 4 ash_riple
  end
169
  else begin
170 10 edn_walter
    // get PTP identification information as additional information to Timestamp
171
    // message id
172
    if      (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h88F7)
173
      ptp_msgid <=   int_data_d1[11: 8];
174
    else if (int_valid_d1 && int_cnt==10'd4 && bypass_udp_cnt==10'd1 && ptp_l4)
175
      ptp_msgid <=   int_data_d1[11: 8];
176
    // sequence id
177
    if      (int_valid_d1 && int_cnt==10'd11 && ptp_l2)
178
      ptp_seqid <=   int_data_d1[31:16];
179
    else if (int_valid_d1 && int_cnt==10'd10 && ptp_l4)
180
      ptp_seqid <=   int_data_d1[31:16];
181 4 ash_riple
  end
182
end
183
 
184
always @(posedge rst or posedge clk) begin
185
  if (rst) begin
186
    ptp_found <=  1'b0;
187 9 edn_walter
    ptp_infor <= 52'd0;
188 4 ash_riple
  end
189 10 edn_walter
  else if (int_valid_d1 && int_sop_d1) begin
190 4 ash_riple
    ptp_found <=  1'b0;
191 9 edn_walter
    ptp_infor <= 52'd0;
192 4 ash_riple
  end
193 10 edn_walter
  else if (int_valid_d1 && int_eop_d1) begin
194 4 ash_riple
    ptp_found <=  ptp_event;
195 10 edn_walter
    ptp_infor <= {ptp_seqid, ptp_msgid, sop_time};  // 16+4+32
196 4 ash_riple
  end
197
  else begin
198
    ptp_found <=  1'b0;
199 9 edn_walter
    ptp_infor <= 52'd0;
200 4 ash_riple
  end
201
end
202
 
203
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.