File size: 717 Bytes
7df9186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 16-bit ones-complement checksum calculator
// Applies to all of IP header, ICMP, and UDP checksums
// Well, difficult to use with UDP because of its pathological
// inclusion of _two_ copies of the UDP length.
// mostly cribbed from core/assemble_eth.v

module ones_chksum(
	input clk,
	input clear,
	input gate,
	input [7:0] din,
	output [7:0] sum,
	output all_ones
);

reg [7:0] chksum=0, chksum1=0;
reg chksum_carry=0;
always @(posedge clk) begin
	if (clear) {chksum_carry, chksum} <= 9'h0;
	else if (gate) {chksum_carry, chksum} <=
		chksum1 + din + chksum_carry;
	if (clear) chksum1 <= 8'h0;
	else if (gate) chksum1 <= chksum;
end
assign sum = ~(chksum1 + chksum_carry);
assign all_ones = &chksum;

endmodule