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

Subversion Repositories ha1588

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

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
    bypass_udp_cnt <= 10'd0;
49
  end
50
  else begin
51
    if (int_valid_d1 && int_sop_d1)
52
      int_cnt <= 10'd0;
53
    else if (int_valid_d1)
54
      int_cnt <= int_cnt + 10'd1 - bypass_vlan - (bypass_ipv4 || bypass_udp);
55
 
56
    if (int_valid_d1 && int_sop_d1)
57
      bypass_ipv4_cnt <= 10'd0;
58
    else if (int_valid_d1 && bypass_ipv4)
59
      bypass_ipv4_cnt <= bypass_ipv4_cnt + 10'd1;
60
 
61
    if (int_valid_d1 && int_sop_d1)
62
      bypass_udp_cnt <= 10'd0;
63
    else if (int_valid_d1 && bypass_udp)
64
      bypass_udp_cnt <= bypass_udp_cnt + 10'd1;
65
  end
66 4 ash_riple
end
67
 
68
always @(posedge rst or posedge clk) begin
69
  if (rst) begin
70 10 edn_walter
    bypass_vlan  <= 1'b0;
71
    bypass_ipv4  <= 1'b0;
72
    found_udp    <= 1'b0;
73
    bypass_udp   <= 1'b0;
74
    ptp_l2    <= 1'b0;
75
    ptp_l4    <= 1'b0;
76 4 ash_riple
    ptp_event <= 1'b0;
77 10 edn_walter
  end
78
  else if (int_valid_d1 && int_sop_d1) begin
79
    bypass_vlan  <= 1'b0;
80
    bypass_ipv4  <= 1'b0;
81
    found_udp    <= 1'b0;
82
    bypass_udp   <= 1'b0;
83
    ptp_l2    <= 1'b0;
84
    ptp_l4    <= 1'b0;
85
    ptp_event <= 1'b0;
86
  end
87
  else begin
88
    // bypass vlan
89
    // ether_type == cvlan
90
    if (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h8100)
91
      bypass_vlan <= 1'b1;
92
    else
93
      bypass_vlan <= 1'b0;
94
    // ether_type == svlan
95
    // TO BE ADDED HERE
96
 
97
    // bypass ipv4
98
    // ether_type == ip, ip_version == 4
99
    if      (int_valid_d1 && int_cnt==10'd3 && bypass_ipv4_cnt==10'd0 &&
100
             int_data_d1[31:16]==16'h0800 && int_data_d1[15:12]==4'h4)
101
      bypass_ipv4 <= 1'b1;
102
    else if (int_valid_d1 && bypass_ipv4_cnt==10'd4)
103
      bypass_ipv4 <= 1'b0;
104
 
105
    // bypass ipv6
106
    // ether_type == ip, ip_version == 6
107
    // TO BE ADDED HERE
108
 
109
    // check if it is UDP
110
    // ipv4_protocol == udp
111
    if      (int_valid_d1 && bypass_ipv4_cnt==10'd1 && int_data_d1[ 7: 0]== 8'h11)
112
      found_udp <= 1'b1;
113
    // ipv6_protocol == udp
114
    // TO BE ADDED HERE
115
 
116
    // bypass udp
117
    // ipv4_udp
118
    if      (int_valid_d1 && bypass_ipv4_cnt==10'd4 && bypass_udp_cnt==10'd0 && found_udp)
119
      bypass_udp <= 1'b1;
120
    else if (int_valid_d1 && bypass_udp_cnt==10'd2)
121
      bypass_udp <= 1'b0;
122
    // ipv6_udp
123
    // TO BE ADDED HERE
124
 
125
    // check if it is L2 PTP
126
    // ether_type == ptp
127
    if (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h88F7)
128
      ptp_l2 <= 1'b1;
129
    // check if it is L4 PTP
130
    // ipv4_udp_dest_port == ptp_event
131
    if (int_valid_d1 && bypass_udp_cnt==10'd0 && bypass_udp && int_data_d1[31:16]==16'h013f)
132
      ptp_l4 <= 1'b1;
133
    // ipv6_udp_dest_port == ptp_event
134
    // TO BE ADDED HERE
135
 
136
    // check if it is PTP Event message
137
    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))
138
      // ptp_message_id == sync || delay_req
139
      ptp_event <= 1'b1;
140
    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))
141
      // ptp_message_id == sync || delay_req
142
      ptp_event <= 1'b1;
143
  end
144
end
145
 
146
always @(posedge rst or posedge clk) begin
147
  if (rst) begin
148 7 edn_walter
    ptp_msgid <= 4'd0;
149 8 edn_walter
    ptp_seqid <= 16'd0;
150 4 ash_riple
  end
151 10 edn_walter
  else if (int_valid_d1 && int_sop_d1) begin
152 7 edn_walter
    ptp_msgid <= 4'd0;
153 8 edn_walter
    ptp_seqid <= 16'd0;
154 4 ash_riple
  end
155
  else begin
156 10 edn_walter
    // get PTP identification information as additional information to Timestamp
157
    // message id
158
    if      (int_valid_d1 && int_cnt==10'd3 && int_data_d1[31:16]==16'h88F7)
159
      ptp_msgid <=   int_data_d1[11: 8];
160
    else if (int_valid_d1 && int_cnt==10'd4 && bypass_udp_cnt==10'd1 && ptp_l4)
161
      ptp_msgid <=   int_data_d1[11: 8];
162
    // sequence id
163
    if      (int_valid_d1 && int_cnt==10'd11 && ptp_l2)
164
      ptp_seqid <=   int_data_d1[31:16];
165
    else if (int_valid_d1 && int_cnt==10'd10 && ptp_l4)
166
      ptp_seqid <=   int_data_d1[31:16];
167 4 ash_riple
  end
168
end
169
 
170
always @(posedge rst or posedge clk) begin
171
  if (rst) begin
172
    ptp_found <=  1'b0;
173 9 edn_walter
    ptp_infor <= 52'd0;
174 4 ash_riple
  end
175 10 edn_walter
  else if (int_valid_d1 && int_sop_d1) begin
176 4 ash_riple
    ptp_found <=  1'b0;
177 9 edn_walter
    ptp_infor <= 52'd0;
178 4 ash_riple
  end
179 10 edn_walter
  else if (int_valid_d1 && int_eop_d1) begin
180 4 ash_riple
    ptp_found <=  ptp_event;
181 10 edn_walter
    ptp_infor <= {ptp_seqid, ptp_msgid, sop_time};  // 16+4+32
182 4 ash_riple
  end
183
  else begin
184
    ptp_found <=  1'b0;
185 9 edn_walter
    ptp_infor <= 52'd0;
186 4 ash_riple
  end
187
end
188
 
189
endmodule

powered by: WebSVN 2.1.0

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