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

Subversion Repositories mac_layer_switch

[/] [mac_layer_switch/] [trunk/] [rtl/] [verilog/] [eth_l3_checksum .v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ranm11
`include "timescale.v"
2
 
3
module eth_l3_checksum
4
   (
5
     MRxClk ,Reset, RxData , ByteCnt, CheckSum ,CSready
6
   );
7
 
8
input    MRxClk;
9
input    Reset;
10
input [7:0] RxData;
11
input [15:0] ByteCnt;
12
output [15:0] CheckSum;
13
output        CSready;
14
 
15
reg   [15:0]   CheckSum;
16
reg   [31:0]   Sum;
17
reg            CSready;
18
reg   [1:0]    StartCalc;
19
reg            Divided_2_clk ;
20
reg            Divided_4_clk ;
21
reg [7:0] prev_latched_Rx;
22
reg [7:0] prev_latched_Rx1;
23
 
24
 initial Divided_2_clk=0;
25
 initial Divided_4_clk=0;
26
 
27
always @ (posedge MRxClk)
28
    begin
29
       Divided_2_clk <=  MRxClk^Divided_2_clk;
30
       if (ByteCnt[15:0] >= 16'h17 & ByteCnt[15:0] < (16'h17+16'd20))
31
           begin
32
           prev_latched_Rx[7:0] <= RxData[7:0];
33
           prev_latched_Rx1[7:0] <= prev_latched_Rx[7:0];
34
           end
35
 
36
    end
37
 
38
always @ (posedge Divided_2_clk)
39
      Divided_4_clk <= Divided_4_clk ^ Divided_2_clk;
40
 
41
 
42
always @ (posedge  Divided_2_clk or posedge Reset )
43
begin
44
    if (Reset)
45
        begin
46
        CheckSum[15:0] <= 16'd0;
47
        CSready <= 1'd0;
48
        end
49
    else
50
       if (ByteCnt[15:0]==16'h15)
51
           StartCalc[0] <= (RxData[7:0] == 8'h8);
52
       else
53
       if (ByteCnt[15:0]==16'h16)
54
           begin
55
           StartCalc[0] <= (RxData[7:0] == 8'h0) & StartCalc[0] ;
56
           CheckSum[15:0] <= 16'h0;
57
           Sum[31:0] <= 32'h0;
58
           CSready <= 1'b0;
59
           end
60
       else
61
       if (ByteCnt[15:0] >= 16'h17 & ByteCnt[15:0] < (16'h17+16'd20))
62
           begin
63
           StartCalc[1]<= (ByteCnt[15:0] > 16'h17) & StartCalc[0] ;
64
           end
65
       else
66
         StartCalc[1:0] <= 2'h0;
67
 
68
   if (ByteCnt[15:0]-16'h17== 16'd20)
69
       begin
70
         CSready <= 1'b1;
71
         CheckSum[15:0] <= ~(Sum[15:0]+Sum[31:16]);
72
       end
73
 
74
   end
75
 
76
 always @ (negedge Divided_4_clk)
77
 begin
78
      if (&StartCalc)
79
        Sum[31:0]<= Sum[31:0] + {prev_latched_Rx1[7:0] , RxData[7:0]};
80
 
81
  end
82
 
83
 
84
 
85
endmodule

powered by: WebSVN 2.1.0

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