-
Notifications
You must be signed in to change notification settings - Fork 0
/
dff.sv
192 lines (167 loc) · 4.44 KB
/
dff.sv
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*-----------------------------------------------------------------
-- Projet d'approfondissement - DUT D Flip-Flop
--
-- File : dff.sv
-- Description : Functional design of the D Flip-Flop
--
-- Author : Sami Foery
-- Master : MSE Mechatronics
-- Date : 10.05.2021
-----------------------------------------------------------------*/
`timescale 1ns/1ps
`include "library_const.sv"
import library_const::*;
module dff (
input logic lset = 1, res = 1, clk, d,
output logic q, qbar,
logic int_state = 0, int_state_gap = 0, data_check_pulse, data_check_prop, fin_point, simult_nd_pt
);
// Clocking block -> Necessary for working with clock strokes
default clocking cb @(posedge clk);
endclocking
//Variable declarations
real diff_val;
logic save_data;
realtime time_1, time_2;
logic qs, qas, qar, qu; //Intermediate work signals
// Synchronous mode
always @(posedge clk iff (res == 1 && lset == 1)) begin
save_data = $past(d,1); //Assigning the value of d to a previous clock stroke
//Condition with d at its high level
fork : wait_data
begin //Pulse data
fork : wait_pulse
begin //data high
time_1 = $realtime;
@(negedge clk)
if ((save_data !== d) && (d == 1)) begin
@(posedge clk)
time_2 = $realtime;
diff_val = time_2-time_1;
if (diff_val >= pulse_data_high) begin
data_check_pulse = 1;
disable wait_pulse;
end else
data_check_pulse = 0;
disable wait_pulse;
end
end
begin //data low
if (d !== 0) begin
#pulse_data_low;
if (d === 0) begin
data_check_pulse = 0;
disable wait_pulse;
end else
data_check_pulse = 1;
end
end
join
end
begin //Propagation delay
fork : wait_prop
begin
#rand_value_clock;
data_check_prop = 1;
disable wait_prop;
end
begin
#clock_max_value;
data_check_prop = 0;
disable wait_prop;
end
join
end
join
fin_point = 1; //Point at which parallel processes end
if (data_check_prop == 1)
qs = d;
fin_point = 0;
end
//Asynchronous mode where set has been called
always @(negedge lset iff (res == 1)) begin
//Parallel execution of processes
fork : wait_or_timeout_set
begin
#pulse_value; //#12ns
int_state = 1;
#(rand_value_res_set-pulse_value);
qas = 1;
disable wait_or_timeout_set;
end
begin
@(posedge lset);
int_state = 0;
disable wait_or_timeout_set;
end
join
end
//Asynchronous mode where reset has been called
always @(negedge res iff (lset == 1)) begin
//Parallel execution of processes
fork : wait_or_timeout_reset
begin
#pulse_value; //#12ns
int_state = 1;
#(rand_value_res_set-pulse_value);
qar = 0;
disable wait_or_timeout_reset;
end
begin
@(posedge res);
int_state = 0;
disable wait_or_timeout_reset;
end
join
end
//Asynchronous mode where set and reset has been called
always @(negedge lset iff (res == 0)) begin
#rand_value_res_set;
qu = 1; // Both outputs remain high as long as set and reset are low at the same time.
end
always @(negedge res iff (lset == 0)) begin
#rand_value_res_set;
qu = 1; //Both outputs remain high as long as set and reset are low at the same time.
end
//Set and reset to their high states simultaneously
always @(posedge lset or posedge res) begin
fork : simult_test //Competing processes between SET or RESET state change and delay.
begin
@(posedge res iff lset==1 or posedge lset iff res==1)
simult_nd_pt = 1;
qs = 5'bx;
disable simult_test;
end
begin
#5; //Maximum time defined before state changes are not considered "simultaneous".
simult_nd_pt = 0;
disable simult_test;
end
join
end
//Assigning the correct signal to the real output
//Multiplexer design
always_comb begin
if (res == 1 && lset == 1) begin
q = qs;
qbar = ~qs;
end else if (res == 1 && lset == 0) begin
q = qas;
qbar = ~qas;
end else if (res == 0 && lset == 1) begin
q = qar;
qbar = ~qar;
end else if (res == 0 && lset == 0) begin
q = qu;
qbar = qu;
end
end
// the "macro" to dump signals
`ifdef COCOTB_SIM
initial begin
$dumpfile ("dff.vcd");
$dumpvars (0, dff);
#1;
end
`endif
endmodule