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

Subversion Repositories ha1588

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

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
  input [79:0] ptp_time,
11
 
12
  output reg        ptp_found,
13
  output reg [91:0] ptp_infor
14
);
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
    ptp_seqid <= 8'd0;
62
  end
63
  else if (ptp_valid_d1 && ptp_sop_d1) begin
64
    ptp_vlan  <= 1'b0;
65
    ptp_ip    <= 1'b0;
66
    ptp_udp   <= 1'b0;
67
    ptp_port  <= 1'b0;
68
    ptp_event <= 1'b0;
69
    ptp_seqid <= 8'd0;
70
  end
71
  else begin
72
    if (ptp_valid_d1 && ptp_cnt==10'd4)  // ether_type == vlan
73
      ptp_vlan  <= ( ptp_data_d1[31:16]==16'h8100);
74
    if (ptp_valid_d1 && ptp_cnt==10'd4)  // ether_type == ip
75
      ptp_ip    <= ( ptp_data_d1[31:16]==16'h0800);
76
    if (ptp_valid_d1 && ptp_cnt==10'd6)  // ip_type == udp
77
      ptp_udp   <= ( ptp_data_d1[ 7: 0]== 8'h11 && ptp_ip);
78
    if (ptp_valid_d1 && ptp_cnt==10'd10) // udp_dest_port == ptp_event
79
      ptp_port  <= ( ptp_data_d1[31:16]==16'h013f && ptp_udp);
80
    if (ptp_valid_d1 && ptp_cnt==10'd11) // ptp_message_id == sync || delay_req
81
      ptp_event <= ((ptp_data_d1[11: 8]== 4'h0 || ptp_data_d1[11:8]==4'h2) && ptp_port);
82
 
83
    if (ptp_valid_d1 && ptp_cnt==10'd11) // ptp_sequence_id
84
      ptp_msgid <=   ptp_data_d1[11: 8];
85
    if (ptp_valid_d1 && ptp_cnt==10'd19) // ptp_sequence_id
86
      ptp_seqid <=   ptp_data_d1[31:16];
87
  end
88
end
89
 
90
always @(posedge rst or posedge clk) begin
91
  if (rst) begin
92
    ptp_found <=  1'b0;
93
    ptp_infor <= 91'd0;
94
  end
95
  else if (ptp_valid_d1 && ptp_sop_d1) begin
96
    ptp_found <=  1'b0;
97
    ptp_infor <= 91'd0;
98
  end
99
  else if (ptp_valid_d1 && ptp_eop_d1) begin
100
    ptp_found <=  ptp_event;
101
    ptp_infor <= {ptp_msgid, ptp_seqid, ptp_time};
102
  end
103
  else begin
104
    ptp_found <=  1'b0;
105
    ptp_infor <= 91'd0;
106
  end
107
end
108
 
109
endmodule

powered by: WebSVN 2.1.0

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