summaryrefslogtreecommitdiffhomepage
path: root/source/link_timer.v
blob: e467f25f71de0b0d2e4ae9b808fa1f99ccd251ca (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 *       link_timer.v
 *
 *   Copyright 2020 Mind Chasers Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *	function: Generate link timer pulse (1.6 and 10 ms) per SGMII and IEEE 802.3
 *	
 */

module link_timer(
	input rstn,
	input	clk,			// 125 MHz data clock
	output 	pulse_1_6ms,
	output	pulse_10ms
);

	wire clk;
	reg [13:0] cnt;		// 0.1 ms counter
	reg [3:0]  cnt_1_6ms;
	reg [6:0]  cnt_10ms;
	
	// 0.1 ms counter
	always @ (posedge clk or negedge rstn) 
	   if  ( !rstn )
		   cnt <= 'd0;
	   else if (cnt == 'd12500)
	   		cnt <= 'd0;
	   else
		   cnt <= cnt + 1;
	   
   // 1.6 ms counter
   always @ (posedge clk or negedge rstn) 
   	if  ( !rstn )
   		cnt_1_6ms <= 'd0;
	else if (cnt == 'd12500)
		if (cnt_1_6ms == 'd16)
			cnt_1_6ms <= 'd0;
		else
			cnt_1_6ms <= cnt_1_6ms + 1;
   	
   	assign pulse_1_6ms = (cnt == 'd12500 && cnt_1_6ms == 'd15);
   	
   	// 10 ms counter
   	always @ (posedge clk or negedge rstn) 
   		if  ( !rstn )
   			cnt_10ms <= 'd0;
	else if (cnt == 'd12500)
   		if (cnt_10ms == 'd99)
   			cnt_10ms <= 'd0;
   		else
   			cnt_10ms <= cnt_10ms + 1;
   		
   	assign pulse_10ms = (cnt == 'd12500 && cnt_10ms == 'd99);
	   
	   
endmodule

Highly Recommended Verilog Books