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

Subversion Repositories ha1588

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

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
  input [31:0] ptp_data,
6
  input        ptp_valid,
7
  input        ptp_sop,
8
  input        ptp_eop,
9
  input [ 1:0] ptp_mod,
10 7 edn_walter
  input [29:0] ptp_time,
11 4 ash_riple
 
12
  output reg        ptp_found,
13 7 edn_walter
  output reg [41:0] ptp_infor
14 4 ash_riple
);
15
 
16
reg [31:0] ptp_data_d1;
17
reg        ptp_valid_d1;
18
reg        ptp_sop_d1;
19
reg        ptp_eop_d1;
20
reg [ 1:0] ptp_mod_d1;
21
always @(posedge rst or posedge clk) begin
22
  if (rst) begin
23
    ptp_data_d1  <= 32'h00000000;
24
    ptp_valid_d1 <= 1'b0;
25
    ptp_sop_d1   <= 1'b0;
26
    ptp_eop_d1   <= 1'b0;
27
    ptp_mod_d1   <= 2'b00;
28
  end
29
  else begin
30
    if (ptp_valid) begin
31
      ptp_data_d1  <= ptp_data;
32
      ptp_mod_d1   <= ptp_mod;
33
    end
34
      ptp_valid_d1 <= ptp_valid;
35
      ptp_sop_d1   <= ptp_sop;
36
      ptp_eop_d1   <= ptp_eop;
37
  end
38
end
39
 
40
reg [9:0] ptp_cnt;
41
reg ptp_vlan, ptp_ip, ptp_udp, ptp_port, ptp_event;
42
reg [3:0] ptp_msgid;
43
reg [7:0] ptp_seqid;
44
always @(posedge rst or posedge clk) begin
45
  if (rst)
46
    ptp_cnt <= 10'd0;
47
  else
48
    if (ptp_valid && ptp_sop)
49
      ptp_cnt <= 10'd0;
50
    else if (ptp_valid)
51
      ptp_cnt <= ptp_cnt + 10'd1 - ptp_vlan;
52
end
53
 
54
always @(posedge rst or posedge clk) begin
55
  if (rst) begin
56
    ptp_vlan  <= 1'b0;
57
    ptp_ip    <= 1'b0;
58
    ptp_udp   <= 1'b0;
59
    ptp_port  <= 1'b0;
60
    ptp_event <= 1'b0;
61 7 edn_walter
    ptp_msgid <= 4'd0;
62 4 ash_riple
    ptp_seqid <= 8'd0;
63
  end
64
  else if (ptp_valid_d1 && ptp_sop_d1) begin
65
    ptp_vlan  <= 1'b0;
66
    ptp_ip    <= 1'b0;
67
    ptp_udp   <= 1'b0;
68
    ptp_port  <= 1'b0;
69
    ptp_event <= 1'b0;
70 7 edn_walter
    ptp_msgid <= 4'd0;
71 4 ash_riple
    ptp_seqid <= 8'd0;
72
  end
73
  else begin
74
    if (ptp_valid_d1 && ptp_cnt==10'd4)  // ether_type == vlan
75
      ptp_vlan  <= ( ptp_data_d1[31:16]==16'h8100);
76 7 edn_walter
    else
77
      ptp_vlan  <= 1'b0;
78 4 ash_riple
    if (ptp_valid_d1 && ptp_cnt==10'd4)  // ether_type == ip
79
      ptp_ip    <= ( ptp_data_d1[31:16]==16'h0800);
80
    if (ptp_valid_d1 && ptp_cnt==10'd6)  // ip_type == udp
81
      ptp_udp   <= ( ptp_data_d1[ 7: 0]== 8'h11 && ptp_ip);
82
    if (ptp_valid_d1 && ptp_cnt==10'd10) // udp_dest_port == ptp_event
83
      ptp_port  <= ( ptp_data_d1[31:16]==16'h013f && ptp_udp);
84
    if (ptp_valid_d1 && ptp_cnt==10'd11) // ptp_message_id == sync || delay_req
85
      ptp_event <= ((ptp_data_d1[11: 8]== 4'h0 || ptp_data_d1[11:8]==4'h2) && ptp_port);
86
 
87
    if (ptp_valid_d1 && ptp_cnt==10'd11) // ptp_sequence_id
88
      ptp_msgid <=   ptp_data_d1[11: 8];
89
    if (ptp_valid_d1 && ptp_cnt==10'd19) // ptp_sequence_id
90
      ptp_seqid <=   ptp_data_d1[31:16];
91
  end
92
end
93
 
94
always @(posedge rst or posedge clk) begin
95
  if (rst) begin
96
    ptp_found <=  1'b0;
97 7 edn_walter
    ptp_infor <= 42'd0;
98 4 ash_riple
  end
99
  else if (ptp_valid_d1 && ptp_sop_d1) begin
100
    ptp_found <=  1'b0;
101 7 edn_walter
    ptp_infor <= 42'd0;
102 4 ash_riple
  end
103
  else if (ptp_valid_d1 && ptp_eop_d1) begin
104
    ptp_found <=  ptp_event;
105
    ptp_infor <= {ptp_msgid, ptp_seqid, ptp_time};
106
  end
107
  else begin
108
    ptp_found <=  1'b0;
109 7 edn_walter
    ptp_infor <= 42'd0;
110 4 ash_riple
  end
111
end
112
 
113
endmodule

powered by: WebSVN 2.1.0

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