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

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [rtl/] [tsu/] [ptp_parser.v] - Diff between revs 35 and 37

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 35 Rev 37
Line 1... Line 1...
/*
/*
 * $ptp_parser.v
 * $ptp_parser.v
 *
 *
 * Copyright (c) 2012, BBY&HW. All rights reserved.
 * Copyright (c) 2012, BABY&HW. All rights reserved.
 *
 *
 * This library is free software; you can redistribute it and/or
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * version 2.1 of the License, or (at your option) any later version.
Line 28... Line 28...
  input        int_sop,
  input        int_sop,
  input        int_eop,
  input        int_eop,
  input [ 1:0] int_mod,
  input [ 1:0] int_mod,
 
 
  output reg        ptp_found,
  output reg        ptp_found,
  output reg [19:0] ptp_infor
  output reg [31:0] ptp_infor
);
);
 
 
reg [31:0] int_data_d1;
reg [31:0] int_data_d1;
always @(posedge rst or posedge clk) begin
always @(posedge rst or posedge clk) begin
  if (rst) begin
  if (rst) begin
Line 46... Line 46...
end
end
 
 
// packet parser: counter
// packet parser: counter
reg [ 9:0] int_cnt, bypass_ipv4_cnt, bypass_ipv6_cnt, bypass_udp_cnt, ptp_cnt;
reg [ 9:0] int_cnt, bypass_ipv4_cnt, bypass_ipv6_cnt, bypass_udp_cnt, ptp_cnt;
reg bypass_vlan, ptp_l2, bypass_mpls, bypass_ipv4, bypass_ipv6, found_udp, bypass_udp, ptp_l4, ptp_event;
reg bypass_vlan, ptp_l2, bypass_mpls, bypass_ipv4, bypass_ipv6, found_udp, bypass_udp, ptp_l4, ptp_event;
reg [ 3:0] ptp_msgid;
 
reg [15:0] ptp_seqid;
 
always @(posedge rst or posedge clk) begin
always @(posedge rst or posedge clk) begin
  if (rst) begin
  if (rst) begin
    int_cnt <= 10'd0;
    int_cnt <= 10'd0;
    bypass_ipv4_cnt <= 10'd0;
    bypass_ipv4_cnt <= 10'd0;
    bypass_ipv6_cnt <= 10'd0;
    bypass_ipv6_cnt <= 10'd0;
Line 166... Line 164...
       (int_data[31:16]==16'h013f || int_data[31:16]==16'h0140))  // udp_dest_port == ptp_event || ptp_general
       (int_data[31:16]==16'h013f || int_data[31:16]==16'h0140))  // udp_dest_port == ptp_event || ptp_general
      ptp_l4 <= 1'b1;
      ptp_l4 <= 1'b1;
 
 
    // check if it is PTP Event message
    // check if it is PTP Event message
    if      (int_valid && (int_cnt==10'd3 || bypass_vlan && int_cnt==10'd4) && int_data[31:16]==16'h88F7 &&
    if      (int_valid && (int_cnt==10'd3 || bypass_vlan && int_cnt==10'd4) && int_data[31:16]==16'h88F7 &&
            (int_data[11: 8]== 4'h0 || int_data[11:8]==4'h2))  // ptp_message_id == sync || delay_req
            (int_data[11: 8]>= 4'h0 && int_data[11:8]<=4'h7))  // ptp_message_id == ptp_event
      ptp_event <= 1'b1;
      ptp_event <= 1'b1;
    else if (int_valid && int_cnt==10'd4 && bypass_udp_cnt==10'd1 && ptp_l4 &&
    else if (int_valid && int_cnt==10'd4 && bypass_udp_cnt==10'd1 && ptp_l4 &&
            (int_data[11: 8]== 4'h0 || int_data[11:8]==4'h2))  // ptp_message_id == sync || delay_req
            (int_data[11: 8]>= 4'h0 && int_data[11:8]<=4'h7))  // ptp_message_id == ptp_event
      ptp_event <= 1'b1;
      ptp_event <= 1'b1;
  end
  end
end
end
 
 
// ptp message
// ptp message
reg [31:0] ptp_data;
reg [31:0] ptp_data;
 
reg [ 3:0] ptp_msgid;
 
reg [15:0] ptp_seqid;
 
reg [11:0] ptp_cksum;
always @(posedge rst or posedge clk) begin
always @(posedge rst or posedge clk) begin
  if (rst) begin
  if (rst) begin
    ptp_data  <= 32'd0;
    ptp_data  <= 32'd0;
    ptp_msgid <= 4'd0;
    ptp_msgid <= 4'd0;
    ptp_seqid <= 16'd0;
    ptp_seqid <= 16'd0;
 
    ptp_cksum <= 12'd0;
  end
  end
  else if (int_valid && int_sop) begin
  else if (int_valid && int_sop) begin
    ptp_data  <= 32'd0;
    ptp_data  <= 32'd0;
    ptp_msgid <= 4'd0;
    ptp_msgid <= 4'd0;
    ptp_seqid <= 16'd0;
    ptp_seqid <= 16'd0;
 
    ptp_cksum <= 12'd0;
  end
  end
  else begin
  else begin
    // get PTP identification information as additional information to Timestamp
    // get PTP identification information as additional information to Timestamp
    // ptp message body
    // ptp message body
    if (int_valid && (ptp_l2 || (bypass_udp_cnt>=10'd2 && ptp_l4)))
    if (int_valid && (ptp_l2 || (bypass_udp_cnt>=10'd2 && ptp_l4)))
Line 198... Line 201...
    if (int_valid && ptp_cnt==10'd1)
    if (int_valid && ptp_cnt==10'd1)
      ptp_msgid <=   ptp_data[27:24];
      ptp_msgid <=   ptp_data[27:24];
    // sequence id
    // sequence id
    if (int_valid && ptp_cnt==10'd8)
    if (int_valid && ptp_cnt==10'd8)
      ptp_seqid <=   ptp_data[15:0];
      ptp_seqid <=   ptp_data[15:0];
 
    // sum up clock id and source port id
 
    if (int_valid && ptp_cnt==10'd6)
 
      ptp_cksum <= ptp_data[31:24] + ptp_data[23:16] + ptp_data[15: 8] + ptp_data[ 7: 0] + ptp_cksum;
 
    if (int_valid && ptp_cnt==10'd7)
 
      ptp_cksum <= ptp_data[31:24] + ptp_data[23:16] + ptp_data[15: 8] + ptp_data[ 7: 0] + ptp_cksum;
 
    if (int_valid && ptp_cnt==10'd8)
 
      ptp_cksum <= ptp_data[31:24] + ptp_data[23:16]                                     + ptp_cksum;
  end
  end
end
end
 
 
// parser output
// parser output
always @(posedge rst or posedge clk) begin
always @(posedge rst or posedge clk) begin
  if (rst) begin
  if (rst) begin
    ptp_found <=  1'b0;
    ptp_found <=  1'b0;
    ptp_infor <= 20'd0;
    ptp_infor <= 32'd0;
  end
  end
  else if (int_valid && int_sop) begin
  else if (int_valid && int_sop) begin
    ptp_found <=  1'b0;
    ptp_found <=  1'b0;
    ptp_infor <= 20'd0;
    ptp_infor <= 32'd0;
  end
  end
  else if (int_valid && ptp_cnt==10'd9) begin
  else if (int_valid && ptp_cnt==10'd9) begin
    ptp_found <=  ptp_event;
    ptp_found <=  ptp_event;
    ptp_infor <= {ptp_msgid, ptp_seqid};  // 4+16
    ptp_infor <= {ptp_msgid, ptp_cksum, ptp_seqid};  // 4+12+16
  end
  end
end
end
 
 
endmodule
endmodule
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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