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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [Projects/] [opencores.org/] [adv_debug_sys/] [Hardware/] [adv_dbg_if/] [rtl/] [verilog/] [adbg_syncflop.v] - Blame information for rev 131

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 131 jt_eaton
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  adbg_syncflop.v                                             ////
4
////                                                              ////
5
////                                                              ////
6
////  A generic synchronization device between two clock domains  ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////       Nathan Yawn (nathan.yawn@opencores.org)                ////
10
////                                                              ////
11
////                                                              ////
12
////                                                              ////
13
//////////////////////////////////////////////////////////////////////
14
////                                                              ////
15
//// Copyright (C) 2010 Authors                                   ////
16
////                                                              ////
17
//// This source file may be used and distributed without         ////
18
//// restriction provided that this copyright statement is not    ////
19
//// removed from the file and that any derivative work contains  ////
20
//// the original copyright notice and the associated disclaimer. ////
21
////                                                              ////
22
//// This source file is free software; you can redistribute it   ////
23
//// and/or modify it under the terms of the GNU Lesser General   ////
24
//// Public License as published by the Free Software Foundation; ////
25
//// either version 2.1 of the License, or (at your option) any   ////
26
//// later version.                                               ////
27
////                                                              ////
28
//// This source is distributed in the hope that it will be       ////
29
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
30
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
31
//// PURPOSE.  See the GNU Lesser General Public License for more ////
32
//// details.                                                     ////
33
////                                                              ////
34
//// You should have received a copy of the GNU Lesser General    ////
35
//// Public License along with this source; if not, download it   ////
36
//// from http://www.opencores.org/lgpl.shtml                     ////
37
////                                                              ////
38
//////////////////////////////////////////////////////////////////////
39
//
40
// This is a synchronization element between two clock domains. It
41
// uses toggle signaling - that is, clock domain 1 changes the state
42
// of TOGGLE_IN to indicate a change, rather than setting the level
43
// high.  When TOGGLE_IN changes state, the output on D_OUT will be
44
// set to level '1', and will hold that value until D_RST is held
45
// high during a rising edge of DEST_CLK.  D_OUT will be updated
46
// on the second rising edge of DEST_CLK after the state of
47
// TOGGLE_IN has changed.
48
// RESET is asynchronous.  This is necessary to coordinate the reset
49
// between different clock domains with potentially different reset
50
// signals.
51
//
52
// Ports:
53
// DEST_CLK:  Clock for the target clock domain
54
// D_SET:     Synchronously set the output to '1'
55
// D_CLR:     Synchronously reset the output to '0'
56
// RESET:     Set all FF's to '0' (asynchronous)
57
// TOGGLE_IN: Toggle data signal from source clock domain
58
// D_OUT:     Output to clock domain 2
59
 
60
 
61
// Top module
62
module `VARIANT`SYNCFLOP(
63
                DEST_CLK,
64
                D_SET,
65
                D_RST,
66
                RESET,
67
                TOGGLE_IN,
68
                D_OUT
69
                );
70
 
71
 
72
   input   DEST_CLK;
73
   input   D_SET;
74
   input   D_RST;
75
   input   RESET;
76
   input   TOGGLE_IN;
77
   output  D_OUT;
78
 
79
   reg     sync1;
80
   reg     sync2;
81
   reg     syncprev;
82
   reg     srflop;
83
 
84
   wire    syncxor;
85
   wire    srinput;
86
   wire    D_OUT;
87
 
88
   // Combinatorial assignments
89
   assign  syncxor = sync2 ^ syncprev;
90
   assign  srinput = syncxor | D_SET;
91
   assign  D_OUT = srflop | syncxor;
92
 
93
   // First DFF (always enabled)
94
   always @ (posedge DEST_CLK or posedge RESET)
95
     begin
96
        if(RESET) sync1 <= 1'b0;
97
        else sync1 <= TOGGLE_IN;
98
     end
99
 
100
 
101
   // Second DFF (always enabled)
102
   always @ (posedge DEST_CLK or posedge RESET)
103
     begin
104
        if(RESET) sync2 <= 1'b0;
105
        else sync2 <= sync1;
106
     end
107
 
108
 
109
   // Third DFF (always enabled, used to detect toggles)
110
   always @ (posedge DEST_CLK or posedge RESET)
111
     begin
112
        if(RESET) syncprev <= 1'b0;
113
        else syncprev <= sync2;
114
     end
115
 
116
 
117
   // Set/Reset FF (holds detected toggles)
118
   always @ (posedge DEST_CLK or posedge RESET)
119
     begin
120
        if(RESET)         srflop <= 1'b0;
121
        else if(D_RST)    srflop <= 1'b0;
122
        else if (srinput) srflop <= 1'b1;
123
     end
124
 
125
 
126
endmodule

powered by: WebSVN 2.1.0

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