|
1 | | -// Copyright 2018 ETH Zurich and University of Bologna. |
| 1 | +// Copyright 2018, 2021 ETH Zurich and University of Bologna. |
2 | 2 | // |
3 | 3 | // Copyright and related rights are licensed under the Solderpad Hardware |
4 | 4 | // License, Version 0.51 (the "License"); you may not use this file except in |
|
8 | 8 | // this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
9 | 9 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
10 | 10 | // specific language governing permissions and limitations under the License. |
| 11 | +// SPDX-License-Identifier: SHL-0.51 |
| 12 | +// |
| 13 | +// Author: Stefan Mach <[email protected]> |
| 14 | +// Description: Common register defines for RTL designs |
11 | 15 |
|
12 | | -// Common register defines for RTL designs |
13 | 16 | `ifndef COMMON_CELLS_REGISTERS_SVH_ |
14 | 17 | `define COMMON_CELLS_REGISTERS_SVH_ |
15 | 18 |
|
16 | 19 | // Abridged Summary of available FF macros: |
17 | | -// `FF: asynchronous active-low reset (implicit clock and reset) |
| 20 | +// `FF: asynchronous active-low reset |
18 | 21 | // `FFAR: asynchronous active-high reset |
19 | | -// `FFARN: asynchronous active-low reset |
| 22 | +// `FFARN: [deprecated] asynchronous active-low reset |
20 | 23 | // `FFSR: synchronous active-high reset |
21 | 24 | // `FFSRN: synchronous active-low reset |
22 | 25 | // `FFNR: without reset |
23 | | -// `FFL: load-enable and asynchronous active-low reset (implicit clock and reset) |
| 26 | +// `FFL: load-enable and asynchronous active-low reset |
24 | 27 | // `FFLAR: load-enable and asynchronous active-high reset |
25 | | -// `FFLARN: load-enable and asynchronous active-low reset |
| 28 | +// `FFLARN: [deprecated] load-enable and asynchronous active-low reset |
26 | 29 | // `FFLARNC: load-enable and asynchronous active-low reset and synchronous active-high clear |
27 | 30 | // `FFLSR: load-enable and synchronous active-high reset |
28 | 31 | // `FFLSRN: load-enable and synchronous active-low reset |
29 | 32 | // `FFLNR: load-enable without reset |
30 | 33 |
|
| 34 | +`define REG_DFLT_CLK clk_i |
| 35 | +`define REG_DFLT_RST rst_ni |
31 | 36 |
|
32 | | -// Flip-Flop with asynchronous active-low reset (implicit clock and reset) |
| 37 | +// Flip-Flop with asynchronous active-low reset |
33 | 38 | // __q: Q output of FF |
34 | 39 | // __d: D input of FF |
35 | 40 | // __reset_value: value assigned upon reset |
36 | | -// Implicit: |
37 | | -// clk_i: clock input |
38 | | -// rst_ni: reset input (asynchronous, active low) |
39 | | -`define FF(__q, __d, __reset_value) \ |
40 | | - always_ff @(posedge clk_i or negedge rst_ni) begin \ |
41 | | - if (!rst_ni) begin \ |
42 | | - __q <= (__reset_value); \ |
43 | | - end else begin \ |
44 | | - __q <= (__d); \ |
45 | | - end \ |
| 41 | +// (__clk: clock input) |
| 42 | +// (__arst_n: asynchronous reset, active-low) |
| 43 | +`define FF(__q, __d, __reset_value, __clk = `REG_DFLT_CLK, __arst_n = `REG_DFLT_RST) \ |
| 44 | + always_ff @(posedge (__clk) or negedge (__arst_n)) begin \ |
| 45 | + if (!__arst_n) begin \ |
| 46 | + __q <= (__reset_value); \ |
| 47 | + end else begin \ |
| 48 | + __q <= (__d); \ |
| 49 | + end \ |
46 | 50 | end |
47 | 51 |
|
48 | 52 | // Flip-Flop with asynchronous active-high reset |
49 | 53 | // __q: Q output of FF |
50 | 54 | // __d: D input of FF |
51 | 55 | // __reset_value: value assigned upon reset |
52 | 56 | // __clk: clock input |
53 | | -// __arst: asynchronous reset |
| 57 | +// __arst: asynchronous reset, active-high |
54 | 58 | `define FFAR(__q, __d, __reset_value, __clk, __arst) \ |
55 | 59 | always_ff @(posedge (__clk) or posedge (__arst)) begin \ |
56 | 60 | if (__arst) begin \ |
|
60 | 64 | end \ |
61 | 65 | end |
62 | 66 |
|
| 67 | +// DEPRECATED - use `FF instead |
63 | 68 | // Flip-Flop with asynchronous active-low reset |
64 | 69 | // __q: Q output of FF |
65 | 70 | // __d: D input of FF |
66 | 71 | // __reset_value: value assigned upon reset |
67 | 72 | // __clk: clock input |
68 | | -// __arst_n: asynchronous reset |
69 | | -`define FFARN(__q, __d, __reset_value, __clk, __arst_n) \ |
70 | | - always_ff @(posedge (__clk) or negedge (__arst_n)) begin \ |
71 | | - if (!__arst_n) begin \ |
72 | | - __q <= (__reset_value); \ |
73 | | - end else begin \ |
74 | | - __q <= (__d); \ |
75 | | - end \ |
76 | | - end |
| 73 | +// __arst_n: asynchronous reset, active-low |
| 74 | +`define FFARN(__q, __d, __reset_value, __clk, __arst_n) \ |
| 75 | + `FF(__q, __d, __reset_value, __clk, __arst_n) |
77 | 76 |
|
78 | 77 | // Flip-Flop with synchronous active-high reset |
79 | 78 | // __q: Q output of FF |
80 | 79 | // __d: D input of FF |
81 | 80 | // __reset_value: value assigned upon reset |
82 | 81 | // __clk: clock input |
83 | | -// __reset_clk: reset input |
| 82 | +// __reset_clk: reset input, active-high |
84 | 83 | `define FFSR(__q, __d, __reset_value, __clk, __reset_clk) \ |
85 | 84 | `ifndef VERILATOR \ |
86 | 85 | /``* synopsys sync_set_reset `"__reset_clk`" *``/ \ |
|
94 | 93 | // __d: D input of FF |
95 | 94 | // __reset_value: value assigned upon reset |
96 | 95 | // __clk: clock input |
97 | | -// __reset_n_clk: reset input |
| 96 | +// __reset_n_clk: reset input, active-low |
98 | 97 | `define FFSRN(__q, __d, __reset_value, __clk, __reset_n_clk) \ |
99 | 98 | `ifndef VERILATOR \ |
100 | 99 | /``* synopsys sync_set_reset `"__reset_n_clk`" *``/ \ |
|
117 | 116 | // __d: D input of FF |
118 | 117 | // __load: load d value into FF |
119 | 118 | // __reset_value: value assigned upon reset |
120 | | -// Implicit: |
121 | | -// clk_i: clock input |
122 | | -// rst_ni: reset input (asynchronous, active low) |
123 | | -`define FFL(__q, __d, __load, __reset_value) \ |
124 | | - always_ff @(posedge clk_i or negedge rst_ni) begin \ |
125 | | - if (!rst_ni) begin \ |
126 | | - __q <= (__reset_value); \ |
127 | | - end else begin \ |
128 | | - __q <= (__load) ? (__d) : (__q); \ |
129 | | - end \ |
| 119 | +// (__clk: clock input) |
| 120 | +// (__arst_n: asynchronous reset, active-low) |
| 121 | +`define FFL(__q, __d, __load, __reset_value, __clk = `REG_DFLT_CLK, __arst_n = `REG_DFLT_RST) \ |
| 122 | + always_ff @(posedge (__clk) or negedge (__arst_n)) begin \ |
| 123 | + if (!__arst_n) begin \ |
| 124 | + __q <= (__reset_value); \ |
| 125 | + end else begin \ |
| 126 | + __q <= (__load) ? (__d) : (__q); \ |
| 127 | + end \ |
130 | 128 | end |
131 | 129 |
|
132 | 130 | // Flip-Flop with load-enable and asynchronous active-high reset |
|
135 | 133 | // __load: load d value into FF |
136 | 134 | // __reset_value: value assigned upon reset |
137 | 135 | // __clk: clock input |
138 | | -// __arst: asynchronous reset |
| 136 | +// __arst: asynchronous reset, active-high |
139 | 137 | `define FFLAR(__q, __d, __load, __reset_value, __clk, __arst) \ |
140 | 138 | always_ff @(posedge (__clk) or posedge (__arst)) begin \ |
141 | 139 | if (__arst) begin \ |
|
145 | 143 | end \ |
146 | 144 | end |
147 | 145 |
|
| 146 | +// DEPRECATED - use `FFL instead |
148 | 147 | // Flip-Flop with load-enable and asynchronous active-low reset |
149 | 148 | // __q: Q output of FF |
150 | 149 | // __d: D input of FF |
151 | 150 | // __load: load d value into FF |
152 | 151 | // __reset_value: value assigned upon reset |
153 | 152 | // __clk: clock input |
154 | | -// __arst_n: asynchronous reset |
| 153 | +// __arst_n: asynchronous reset, active-low |
155 | 154 | `define FFLARN(__q, __d, __load, __reset_value, __clk, __arst_n) \ |
156 | | - always_ff @(posedge (__clk) or negedge (__arst_n)) begin \ |
157 | | - if (!__arst_n) begin \ |
158 | | - __q <= (__reset_value); \ |
159 | | - end else begin \ |
160 | | - __q <= (__load) ? (__d) : (__q); \ |
161 | | - end \ |
162 | | - end |
| 155 | + `FFL(__q, __d, __load, __reset_value, __clk, __arst_n) |
163 | 156 |
|
164 | 157 | // Flip-Flop with load-enable and synchronous active-high reset |
165 | 158 | // __q: Q output of FF |
166 | 159 | // __d: D input of FF |
167 | 160 | // __load: load d value into FF |
168 | 161 | // __reset_value: value assigned upon reset |
169 | 162 | // __clk: clock input |
170 | | -// __reset_clk: reset input |
| 163 | +// __reset_clk: reset input, active-high |
171 | 164 | `define FFLSR(__q, __d, __load, __reset_value, __clk, __reset_clk) \ |
172 | 165 | `ifndef VERILATOR \ |
173 | 166 | /``* synopsys sync_set_reset `"__reset_clk`" *``/ \ |
|
182 | 175 | // __load: load d value into FF |
183 | 176 | // __reset_value: value assigned upon reset |
184 | 177 | // __clk: clock input |
185 | | -// __reset_n_clk: reset input |
| 178 | +// __reset_n_clk: reset input, active-low |
186 | 179 | `define FFLSRN(__q, __d, __load, __reset_value, __clk, __reset_n_clk) \ |
187 | 180 | `ifndef VERILATOR \ |
188 | 181 | /``* synopsys sync_set_reset `"__reset_n_clk`" *``/ \ |
|
198 | 191 | // __clear: assign reset value into FF |
199 | 192 | // __reset_value: value assigned upon reset |
200 | 193 | // __clk: clock input |
201 | | -// __arst_n: asynchronous reset |
| 194 | +// __arst_n: asynchronous reset, active-low |
202 | 195 | `define FFLARNC(__q, __d, __load, __clear, __reset_value, __clk, __arst_n) \ |
203 | 196 | `ifndef VERILATOR \ |
204 | 197 | /``* synopsys sync_set_reset `"__clear`" *``/ \ |
|
0 commit comments