1 |
46 |
laurentiud |
/*
|
2 |
|
|
file: monitor_of_verifla.v
|
3 |
|
|
license: GNU GPL
|
4 |
|
|
author: Laurentiu DUCA
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
module monitor_of_verifla (clk, rst_l,
|
9 |
|
|
sys_run, user_run, data_in,
|
10 |
|
|
mem_port_A_address, mem_port_A_data_in, mem_port_A_wen,
|
11 |
|
|
ack_sc_run, sc_done, sc_run);
|
12 |
|
|
|
13 |
|
|
`include "common_internal_verifla.v"
|
14 |
|
|
|
15 |
|
|
// MON_states
|
16 |
|
|
parameter
|
17 |
|
|
MON_STATES_BITS=4,
|
18 |
|
|
MON_STATE_IDLE=0,
|
19 |
|
|
MON_STATE_DO_MEM_CLEAN=1,
|
20 |
|
|
MON_STATE_PREPARE_RUN=2,
|
21 |
|
|
MON_STATE_WAIT_TRIGGER_MATCH=3,
|
22 |
|
|
MON_STATE_AFTER_TRIGGER=4,
|
23 |
|
|
MON_STATE_CLEAN_REMAINING_MEMORY1=5,
|
24 |
|
|
MON_STATE_CLEAN_REMAINING_MEMORY2=6,
|
25 |
|
|
MON_STATE_SAVE_BT_QUEUE_TAIL_ADDRESS=7,
|
26 |
|
|
MON_STATE_SC_RUN=8,
|
27 |
|
|
MON_STATE_WAIT_SC_DONE=9;
|
28 |
|
|
|
29 |
|
|
// input
|
30 |
|
|
input clk, rst_l;
|
31 |
|
|
input [LA_DATA_INPUT_WORDLEN_BITS-1:0] data_in;
|
32 |
|
|
input sys_run, user_run, ack_sc_run, sc_done;
|
33 |
|
|
// output
|
34 |
|
|
output [LA_MEM_ADDRESS_BITS-1:0] mem_port_A_address;
|
35 |
|
|
output [LA_MEM_WORDLEN_BITS-1:0] mem_port_A_data_in;
|
36 |
|
|
output mem_port_A_wen;
|
37 |
|
|
output sc_run;
|
38 |
|
|
reg [LA_MEM_ADDRESS_BITS-1:0] mem_port_A_address;
|
39 |
|
|
reg [LA_MEM_WORDLEN_BITS-1:0] mem_port_A_data_in;
|
40 |
|
|
reg mem_port_A_wen;
|
41 |
|
|
reg sys_run_reg, sc_run, next_sc_run;
|
42 |
|
|
|
43 |
|
|
// local
|
44 |
|
|
reg [MON_STATES_BITS-1:0] mon_state, next_mon_state;
|
45 |
|
|
reg [LA_MAX_SAMPLES_AFTER_TRIGGER_BITS-1:0]
|
46 |
|
|
next_mon_samples_after_trigger, mon_samples_after_trigger;
|
47 |
|
|
reg [LA_MEM_ADDRESS_BITS-1:0] next_mon_write_address, mon_write_address;
|
48 |
|
|
reg [LA_MEM_ADDRESS_BITS-1:0] next_bt_queue_tail_address, bt_queue_tail_address;
|
49 |
|
|
reg next_bt_cycled, bt_cycled;
|
50 |
|
|
reg [LA_DATA_INPUT_WORDLEN_BITS-1:0] mon_old_data_in,
|
51 |
|
|
mon_current_data_in; //={LA_DATA_INPUT_WORDLEN_BITS{1'b0}};
|
52 |
|
|
reg [LA_IDENTICAL_SAMPLES_BITS-1:0] mon_clones_nr, next_mon_clones_nr;
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
// Register the input data
|
56 |
|
|
// such that mon_current_data_in is constant the full clock period.
|
57 |
|
|
always @(posedge clk or negedge rst_l)
|
58 |
|
|
begin
|
59 |
|
|
if(~rst_l)
|
60 |
|
|
begin
|
61 |
|
|
mon_old_data_in <= 0;
|
62 |
|
|
mon_current_data_in <= 0;
|
63 |
|
|
sys_run_reg <= 0;
|
64 |
|
|
end
|
65 |
|
|
else begin
|
66 |
|
|
mon_old_data_in <= mon_current_data_in;
|
67 |
|
|
mon_current_data_in <= data_in;
|
68 |
|
|
sys_run_reg <= sys_run;
|
69 |
|
|
end
|
70 |
|
|
end
|
71 |
|
|
|
72 |
|
|
// set new values
|
73 |
|
|
always @(posedge clk or negedge rst_l)
|
74 |
|
|
begin
|
75 |
|
|
if(~rst_l)
|
76 |
|
|
begin
|
77 |
|
|
mon_state <= MON_STATE_IDLE;
|
78 |
|
|
sc_run <= 0;
|
79 |
|
|
mon_write_address <= LA_MEM_FIRST_ADDR;
|
80 |
|
|
bt_queue_tail_address <= 0;
|
81 |
|
|
bt_cycled <= 0;
|
82 |
|
|
mon_samples_after_trigger <= 0;
|
83 |
|
|
mon_clones_nr <= 1;
|
84 |
|
|
end
|
85 |
|
|
else begin
|
86 |
|
|
mon_state <= next_mon_state;
|
87 |
|
|
sc_run <= next_sc_run;
|
88 |
|
|
mon_write_address <= next_mon_write_address;
|
89 |
|
|
bt_queue_tail_address <= next_bt_queue_tail_address;
|
90 |
|
|
bt_cycled <= next_bt_cycled;
|
91 |
|
|
mon_samples_after_trigger <= next_mon_samples_after_trigger;
|
92 |
|
|
mon_clones_nr <= next_mon_clones_nr;
|
93 |
|
|
end
|
94 |
|
|
end
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
// continuous assignments
|
98 |
|
|
wire [LA_MEM_ADDRESS_BITS-1:0] one_plus_mon_write_address = (mon_write_address+1);
|
99 |
|
|
wire [LA_IDENTICAL_SAMPLES_BITS-1:0] oneplus_mon_clones_nr = (mon_clones_nr+1);
|
100 |
|
|
wire data_in_changed = ((mon_current_data_in & LA_TRACE_MASK) != (mon_old_data_in & LA_TRACE_MASK));
|
101 |
|
|
wire last_mem_addr_before_trigger = (mon_write_address == LA_MEM_LAST_ADDR_BEFORE_TRIGGER);
|
102 |
|
|
wire not_maximum_mon_clones_nr = (mon_clones_nr < LA_MAX_IDENTICAL_SAMPLES);
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
// mon_prepare_run is called from states MON_STATE_IDLE and MON_STATE_PREPARE_RUN
|
106 |
|
|
task mon_prepare_run;
|
107 |
|
|
begin
|
108 |
|
|
// we share the same clock as memory.
|
109 |
|
|
mem_port_A_address=LA_MEM_FIRST_ADDR;
|
110 |
|
|
mem_port_A_data_in={{(LA_IDENTICAL_SAMPLES_BITS-1){1'b0}}, 1'b1, mon_current_data_in};
|
111 |
|
|
mem_port_A_wen=1;
|
112 |
|
|
next_mon_write_address=LA_MEM_FIRST_ADDR;
|
113 |
|
|
next_mon_clones_nr=2;
|
114 |
|
|
next_mon_state = MON_STATE_WAIT_TRIGGER_MATCH;
|
115 |
|
|
end
|
116 |
|
|
endtask
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
// state machine
|
120 |
|
|
always @(*)
|
121 |
|
|
/*
|
122 |
|
|
mon_state or sys_run_reg
|
123 |
|
|
or ack_sc_run or sc_done or sc_run
|
124 |
|
|
// eliminate warnings
|
125 |
|
|
or mon_write_address or bt_queue_tail_address or mon_samples_after_trigger
|
126 |
|
|
or mon_current_data_in or mon_old_data_in or mon_clones_nr
|
127 |
|
|
or data_in_changed or oneplus_mon_clones_nr or one_plus_mon_write_address
|
128 |
|
|
or not_maximum_mon_clones_nr
|
129 |
|
|
or last_mem_addr_before_trigger)
|
130 |
|
|
*/
|
131 |
|
|
begin
|
132 |
|
|
// implicit
|
133 |
|
|
next_mon_state=mon_state;
|
134 |
|
|
next_sc_run=sc_run;
|
135 |
|
|
next_mon_write_address=mon_write_address;
|
136 |
|
|
next_bt_queue_tail_address=bt_queue_tail_address;
|
137 |
|
|
next_bt_cycled=bt_cycled;
|
138 |
|
|
next_mon_samples_after_trigger=mon_samples_after_trigger;
|
139 |
|
|
next_mon_clones_nr = mon_clones_nr;
|
140 |
|
|
mem_port_A_address=0;
|
141 |
|
|
mem_port_A_data_in=0;
|
142 |
|
|
mem_port_A_wen=0;
|
143 |
|
|
|
144 |
|
|
// state dependent
|
145 |
|
|
case(mon_state)
|
146 |
|
|
MON_STATE_IDLE:
|
147 |
|
|
begin
|
148 |
|
|
next_bt_cycled = 0;
|
149 |
|
|
if(sys_run_reg || user_run)
|
150 |
|
|
begin
|
151 |
|
|
if(user_run) begin
|
152 |
|
|
next_mon_write_address=LA_MEM_FIRST_ADDR;
|
153 |
|
|
next_mon_state=MON_STATE_DO_MEM_CLEAN;
|
154 |
|
|
end else
|
155 |
|
|
mon_prepare_run;
|
156 |
|
|
end
|
157 |
|
|
else
|
158 |
|
|
next_mon_state=MON_STATE_IDLE;
|
159 |
|
|
end
|
160 |
|
|
|
161 |
|
|
MON_STATE_DO_MEM_CLEAN:
|
162 |
|
|
begin
|
163 |
|
|
mem_port_A_address=mon_write_address;
|
164 |
|
|
mem_port_A_data_in=LA_MEM_EMPTY_SLOT;
|
165 |
|
|
mem_port_A_wen=1;
|
166 |
|
|
if(mon_write_address < LA_MEM_LAST_ADDR)
|
167 |
|
|
begin
|
168 |
|
|
next_mon_write_address=mon_write_address+1;
|
169 |
|
|
next_mon_state = MON_STATE_DO_MEM_CLEAN;
|
170 |
|
|
end
|
171 |
|
|
else
|
172 |
|
|
// at the new posedge clock, will clean memory at its last address
|
173 |
|
|
next_mon_state = MON_STATE_PREPARE_RUN;
|
174 |
|
|
end
|
175 |
|
|
|
176 |
|
|
MON_STATE_PREPARE_RUN:
|
177 |
|
|
begin
|
178 |
|
|
mon_prepare_run;
|
179 |
|
|
end
|
180 |
|
|
|
181 |
|
|
MON_STATE_WAIT_TRIGGER_MATCH:
|
182 |
|
|
begin
|
183 |
|
|
// circular queue
|
184 |
|
|
if((mon_current_data_in & LA_TRIGGER_MASK) !=
|
185 |
|
|
(LA_TRIGGER_VALUE & LA_TRIGGER_MASK))
|
186 |
|
|
begin
|
187 |
|
|
next_mon_state = MON_STATE_WAIT_TRIGGER_MATCH;
|
188 |
|
|
mem_port_A_wen = 1;
|
189 |
|
|
mem_port_A_address = data_in_changed ?
|
190 |
|
|
(last_mem_addr_before_trigger ? LA_MEM_FIRST_ADDR : one_plus_mon_write_address) :
|
191 |
|
|
(not_maximum_mon_clones_nr ? mon_write_address :
|
192 |
|
|
(last_mem_addr_before_trigger ? LA_MEM_FIRST_ADDR : one_plus_mon_write_address));
|
193 |
|
|
mem_port_A_data_in = data_in_changed ?
|
194 |
|
|
{{(LA_IDENTICAL_SAMPLES_BITS-1){1'b0}}, 1'b1, mon_current_data_in} :
|
195 |
|
|
(not_maximum_mon_clones_nr ? {mon_clones_nr, mon_current_data_in} :
|
196 |
|
|
{{(LA_IDENTICAL_SAMPLES_BITS-1){1'b0}}, 1'b1, mon_current_data_in});
|
197 |
|
|
next_mon_clones_nr = data_in_changed ? 2 :
|
198 |
|
|
(not_maximum_mon_clones_nr ? oneplus_mon_clones_nr : 2);
|
199 |
|
|
next_mon_write_address = data_in_changed ?
|
200 |
|
|
(last_mem_addr_before_trigger ? LA_MEM_FIRST_ADDR: one_plus_mon_write_address) :
|
201 |
|
|
(not_maximum_mon_clones_nr ? mon_write_address :
|
202 |
|
|
(last_mem_addr_before_trigger ? LA_MEM_FIRST_ADDR : one_plus_mon_write_address));
|
203 |
|
|
if(!bt_cycled)
|
204 |
|
|
next_bt_cycled = ((data_in_changed && last_mem_addr_before_trigger) ||
|
205 |
|
|
(!data_in_changed && !not_maximum_mon_clones_nr && last_mem_addr_before_trigger));
|
206 |
|
|
end
|
207 |
|
|
else begin
|
208 |
|
|
// trigger matched
|
209 |
|
|
next_mon_state=MON_STATE_AFTER_TRIGGER;
|
210 |
|
|
mem_port_A_address=LA_TRIGGER_MATCH_MEM_ADDR;
|
211 |
|
|
mem_port_A_data_in = {{{(LA_IDENTICAL_SAMPLES_BITS-1){1'b0}}, 1'b1}, mon_current_data_in};
|
212 |
|
|
mem_port_A_wen=1;
|
213 |
|
|
next_mon_write_address=LA_TRIGGER_MATCH_MEM_ADDR;
|
214 |
|
|
next_mon_clones_nr=2;
|
215 |
|
|
next_bt_queue_tail_address = mon_write_address;
|
216 |
|
|
next_mon_samples_after_trigger=1;
|
217 |
|
|
end
|
218 |
|
|
end
|
219 |
|
|
|
220 |
|
|
MON_STATE_AFTER_TRIGGER:
|
221 |
|
|
begin
|
222 |
|
|
if((mon_samples_after_trigger < LA_MAX_SAMPLES_AFTER_TRIGGER) &&
|
223 |
|
|
(mon_write_address < LA_MEM_LAST_ADDR))
|
224 |
|
|
begin
|
225 |
|
|
mem_port_A_wen = 1;
|
226 |
|
|
mem_port_A_address = data_in_changed ? one_plus_mon_write_address :
|
227 |
|
|
(not_maximum_mon_clones_nr ? mon_write_address : one_plus_mon_write_address);
|
228 |
|
|
mem_port_A_data_in = data_in_changed ? {{(LA_IDENTICAL_SAMPLES_BITS-1){1'b0}}, 1'b1, mon_current_data_in} :
|
229 |
|
|
(not_maximum_mon_clones_nr ? {mon_clones_nr, mon_current_data_in} :
|
230 |
|
|
{{(LA_IDENTICAL_SAMPLES_BITS-1){1'b0}}, 1'b1, mon_current_data_in});
|
231 |
|
|
next_mon_clones_nr = data_in_changed ? 2 :
|
232 |
|
|
(not_maximum_mon_clones_nr ? oneplus_mon_clones_nr : 2);
|
233 |
|
|
next_mon_write_address = data_in_changed ? one_plus_mon_write_address :
|
234 |
|
|
(not_maximum_mon_clones_nr ? mon_write_address : one_plus_mon_write_address);
|
235 |
|
|
next_mon_samples_after_trigger=mon_samples_after_trigger+1;
|
236 |
|
|
next_mon_state=MON_STATE_AFTER_TRIGGER;
|
237 |
|
|
end
|
238 |
|
|
else begin
|
239 |
|
|
mem_port_A_wen=0;
|
240 |
|
|
if(mon_write_address < LA_MEM_LAST_ADDR) begin
|
241 |
|
|
next_mon_write_address = one_plus_mon_write_address;
|
242 |
|
|
next_mon_state = MON_STATE_CLEAN_REMAINING_MEMORY1;
|
243 |
|
|
end else
|
244 |
|
|
next_mon_state = MON_STATE_CLEAN_REMAINING_MEMORY2;
|
245 |
|
|
end
|
246 |
|
|
end
|
247 |
|
|
MON_STATE_CLEAN_REMAINING_MEMORY1:
|
248 |
|
|
begin
|
249 |
|
|
if(mon_write_address < LA_MEM_LAST_ADDR) begin
|
250 |
|
|
mem_port_A_data_in = LA_MEM_EMPTY_SLOT;
|
251 |
|
|
mem_port_A_wen = 1;
|
252 |
|
|
mem_port_A_address = mon_write_address;
|
253 |
|
|
next_mon_write_address = one_plus_mon_write_address;
|
254 |
|
|
end else begin
|
255 |
|
|
mem_port_A_wen=0;
|
256 |
|
|
if(bt_cycled) begin
|
257 |
|
|
next_mon_state = MON_STATE_SAVE_BT_QUEUE_TAIL_ADDRESS;
|
258 |
|
|
end else begin
|
259 |
|
|
next_mon_write_address = bt_queue_tail_address+1;
|
260 |
|
|
next_mon_state = MON_STATE_CLEAN_REMAINING_MEMORY2;
|
261 |
|
|
end
|
262 |
|
|
end
|
263 |
|
|
end
|
264 |
|
|
MON_STATE_CLEAN_REMAINING_MEMORY2:
|
265 |
|
|
begin
|
266 |
|
|
if(mon_write_address < LA_TRIGGER_MATCH_MEM_ADDR) begin
|
267 |
|
|
mem_port_A_data_in = LA_MEM_EMPTY_SLOT;
|
268 |
|
|
mem_port_A_wen = 1;
|
269 |
|
|
mem_port_A_address = mon_write_address;
|
270 |
|
|
next_mon_write_address = mon_write_address+1;
|
271 |
|
|
end else begin
|
272 |
|
|
mem_port_A_wen=0;
|
273 |
|
|
next_mon_state=MON_STATE_SAVE_BT_QUEUE_TAIL_ADDRESS;
|
274 |
|
|
end
|
275 |
|
|
end
|
276 |
|
|
MON_STATE_SAVE_BT_QUEUE_TAIL_ADDRESS:
|
277 |
|
|
begin
|
278 |
|
|
// Save bt_queue_tail_address
|
279 |
|
|
mem_port_A_address = LA_BT_QUEUE_TAIL_ADDRESS;
|
280 |
|
|
mem_port_A_data_in =
|
281 |
|
|
{{(LA_MEM_WORDLEN_BITS-LA_MEM_ADDRESS_BITS){1'b0}},
|
282 |
|
|
bt_queue_tail_address};
|
283 |
|
|
mem_port_A_wen = 1;
|
284 |
|
|
next_mon_state=MON_STATE_SC_RUN;
|
285 |
|
|
end
|
286 |
|
|
|
287 |
|
|
MON_STATE_SC_RUN:
|
288 |
|
|
begin
|
289 |
|
|
next_mon_state=MON_STATE_WAIT_SC_DONE;
|
290 |
|
|
next_sc_run=1;
|
291 |
|
|
end
|
292 |
|
|
MON_STATE_WAIT_SC_DONE:
|
293 |
|
|
begin
|
294 |
|
|
// sc_run must already be 1, when entering state MON_STATE_SEND_CAPTURE.
|
295 |
|
|
if(ack_sc_run)
|
296 |
|
|
next_sc_run=0;
|
297 |
|
|
if((sc_run == 0) && (sc_done))
|
298 |
|
|
next_mon_state=MON_STATE_IDLE;
|
299 |
|
|
else
|
300 |
|
|
next_mon_state=MON_STATE_WAIT_SC_DONE;
|
301 |
|
|
end
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
default: // should never get here
|
305 |
|
|
begin
|
306 |
|
|
next_mon_state=4'bxxxx;
|
307 |
|
|
next_sc_run=1'bx;
|
308 |
|
|
next_mon_write_address={LA_MEM_ADDRESS_BITS{1'bx}};
|
309 |
|
|
next_bt_queue_tail_address={(LA_MEM_ADDRESS_BITS){1'bx}};
|
310 |
|
|
next_mon_samples_after_trigger={LA_MAX_SAMPLES_AFTER_TRIGGER_BITS{1'bx}};
|
311 |
|
|
next_mon_clones_nr={LA_IDENTICAL_SAMPLES_BITS{1'bx}};
|
312 |
|
|
mem_port_A_address={LA_MEM_ADDRESS_BITS{1'bx}};
|
313 |
|
|
mem_port_A_data_in={LA_MEM_WORDLEN_BITS{1'bx}};
|
314 |
|
|
mem_port_A_wen=1'bx;
|
315 |
|
|
end
|
316 |
|
|
endcase
|
317 |
|
|
end
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
endmodule
|