File: /__w/ctu-can-regression/ctu-can-regression/test/main_tb/agents/test_controller_agent/test_controller_agent.vhd
0: --------------------------------------------------------------------------------
1: --
2: -- CTU CAN FD IP Core
3: -- Copyright (C) 2021-2023 Ondrej Ille
4: -- Copyright (C) 2023- Logic Design Services Ltd.s
5: --
6: -- Permission is hereby granted, free of charge, to any person obtaining a copy
7: -- of this VHDL component and associated documentation files (the "Component"),
8: -- to use, copy, modify, merge, publish, distribute the Component for
9: -- non-commercial purposes. Using the Component for commercial purposes is
10: -- forbidden unless previously agreed with Copyright holder.
11: --
12: -- The above copyright notice and this permission notice shall be included in
13: -- all copies or substantial portions of the Component.
14: --
15: -- THE COMPONENT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16: -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17: -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18: -- AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19: -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20: -- FROM, OUT OF OR IN CONNECTION WITH THE COMPONENT OR THE USE OR OTHER DEALINGS
21: -- IN THE COMPONENT.
22: --
23: -- The CAN protocol is developed by Robert Bosch GmbH and protected by patents.
24: -- Anybody who wants to implement this IP core on silicon has to obtain a CAN
25: -- protocol license from Bosch.
26: --
27: -- -------------------------------------------------------------------------------
28: --
29: -- CTU CAN FD IP Core
30: -- Copyright (C) 2015-2020 MIT License
31: --
32: -- Authors:
33: -- Ondrej Ille <ondrej.ille@gmail.com>
34: -- Martin Jerabek <martin.jerabek01@gmail.com>
35: --
36: -- Project advisors:
37: -- Jiri Novak <jnovak@fel.cvut.cz>
38: -- Pavel Pisa <pisa@cmp.felk.cvut.cz>
39: --
40: -- Department of Measurement (http://meas.fel.cvut.cz/)
41: -- Faculty of Electrical Engineering (http://www.fel.cvut.cz)
42: -- Czech Technical University (http://www.cvut.cz/)
43: --
44: -- Permission is hereby granted, free of charge, to any person obtaining a copy
45: -- of this VHDL component and associated documentation files (the "Component"),
46: -- to deal in the Component without restriction, including without limitation
47: -- the rights to use, copy, modify, merge, publish, distribute, sublicense,
48: -- and/or sell copies of the Component, and to permit persons to whom the
49: -- Component is furnished to do so, subject to the following conditions:
50: --
51: -- The above copyright notice and this permission notice shall be included in
52: -- all copies or substantial portions of the Component.
53: --
54: -- THE COMPONENT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55: -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56: -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57: -- AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58: -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
59: -- FROM, OUT OF OR IN CONNECTION WITH THE COMPONENT OR THE USE OR OTHER DEALINGS
60: -- IN THE COMPONENT.
61: --
62: -- The CAN protocol is developed by Robert Bosch GmbH and protected by patents.
63: -- Anybody who wants to implement this IP core on silicon has to obtain a CAN
64: -- protocol license from Bosch.
65: --
66: --------------------------------------------------------------------------------
67:
68: --------------------------------------------------------------------------------
69: -- @Purpose:
70: -- Test controller agent - Controls rest of CTU CAN FD VIP
71: --
72: --------------------------------------------------------------------------------
73: -- Revision History:
74: -- 12.3.2021 Created file
75: --------------------------------------------------------------------------------
76:
77: Library ctu_can_fd_tb;
78: context ctu_can_fd_tb.ieee_context;
79: context ctu_can_fd_tb.tb_common_context;
80:
81: use ctu_can_fd_tb.test_controller_agent_pkg.all;
82: use ctu_can_fd_tb.timestamp_agent_pkg.all;
83: use ctu_can_fd_tb.mem_bus_agent_pkg.all;
84: use ctu_can_fd_tb.interrupt_agent_pkg.all;
85: use ctu_can_fd_tb.clk_gen_agent_pkg.all;
86: use ctu_can_fd_tb.test_probe_agent_pkg.all;
87: use ctu_can_fd_tb.reset_agent_pkg.all;
88: use ctu_can_fd_tb.can_agent_pkg.all;
89: use ctu_can_fd_tb.tb_shared_vars_pkg.all;
90:
91: entity test_controller_agent is
92: generic(
93: -- Test configuration
94: test_name : string;
95: test_type : string;
96: seed : natural;
97:
98: -- DUT configuration
99: -- DUT Clock period
100: cfg_sys_clk_period : string;
101:
102: -- Bit timing cofnig used in; compliance tests
103: cfg_brp : natural;
104: cfg_prop : natural;
105: cfg_ph_1 : natural;
106: cfg_ph_2 : natural;
107: cfg_sjw : natural;
108: cfg_brp_fd : natural;
109: cfg_prop_fd : natural;
110: cfg_ph_1_fd : natural;
111: cfg_ph_2_fd : natural;
112: cfg_sjw_fd : natural
113: );
114: port (
115: -- VIP test control / status signals
116: test_start : in std_logic;
117: test_done : out std_logic := '0';
118: test_success : out std_logic := '0';
119:
120: -- PLI interface for communication with compliance test library
121: pli_clk : out std_logic;
122: pli_req : in std_logic;
123: pli_ack : out std_logic := '0';
124: pli_cmd : in std_logic_vector(7 downto 0);
125: pli_dest : in std_logic_vector(7 downto 0);
126: pli_data_in : in std_logic_vector(63 downto 0);
127: pli_data_in_2 : in std_logic_vector(63 downto 0);
128: pli_str_buf_in : in std_logic_vector(511 downto 0);
129: pli_data_out : out std_logic_vector(63 downto 0);
130:
131: -- PLI interface for giving test control to compliance test library
132: pli_control_req : out std_logic := '0';
133: pli_control_gnt : in std_logic
134: );
135: end entity;
136:
137: architecture tb of test_controller_agent is
138:
139: signal seed_applied : boolean := false;
140:
141: begin
142:
143: ---------------------------------------------------------------------------
144: -- Connect configuration internally to shared signal so that packages
145: -- can read it (avoid generic packages since not all simulators support
146: -- them).
147: ---------------------------------------------------------------------------
148: cfg_brp_i <= cfg_brp;
149: cfg_prop_i <= cfg_prop;
150: cfg_ph_1_i <= cfg_ph_1;
151: cfg_ph_2_i <= cfg_ph_2;
152: cfg_sjw_i <= cfg_sjw;
153: cfg_brp_fd_i <= cfg_brp_fd;
154: cfg_prop_fd_i <= cfg_prop_fd;
155: cfg_ph_1_fd_i <= cfg_ph_1_fd;
156: cfg_ph_2_fd_i <= cfg_ph_2_fd;
157: cfg_sjw_fd_i <= cfg_sjw_fd;
158: cfg_sys_clk_period_i <= time'value(cfg_sys_clk_period);
159: cfg_seed_i <= seed;
160:
161: ---------------------------------------------------------------------------
162: ---------------------------------------------------------------------------
163: -- Main test process
164: --
165: -- Gives commands to other processes / agents like so:
166: -- Feature tests:
167: -- Invoke Feature test agent which runs the test and gives back result
168: --
169: -- Reference tests:
170: -- Invoke Reference test agent which runs the test and gives back result
171: --
172: -- Compliance tests:
173: -- Pass control to compliance_test_proc which invokes compliance test
174: -- library (test control over PLI).
175: ---------------------------------------------------------------------------
176: ---------------------------------------------------------------------------
177: main_test_proc : process
178: variable test_success_i : std_logic := '0';
179: variable init_timestamp : std_logic_vector(63 downto 0);
180: begin
181: wait for 1 ns;
182: wait until test_start = '1';
183:
184: -- Apply random seed, but only if it was not applied before.
185: -- If there are multiple iterations, we want different random data
186: -- to be used for each one!
187: if (seed_applied = false) then
188: apply_rand_seed(seed);
189: seed_applied <= true;
190: end if;
191:
192: -----------------------------------------------------------------------
193: -- Configure System clock,
194: -- - Period based on generic
195: -----------------------------------------------------------------------
196: info_m("Configuring Clock agent");
197: clk_agent_set_period(default_channel, time'value(cfg_sys_clk_period));
198: clk_agent_set_duty(default_channel, 50);
199: clk_agent_set_jitter(default_channel, 0 ns);
200: clk_gen_agent_start(default_channel);
201:
202: -----------------------------------------------------------------------
203: -- Configure Timestamp generation
204: -- - Step 1
205: -- - Each clock cycle
206: -----------------------------------------------------------------------
207: info_m("Configuring Timestamp agent");
208: timestamp_agent_set_step(default_channel, 1);
209: timestamp_agent_set_prescaler(default_channel, 1);
210: timestamp_agent_timestamp_preset(default_channel, x"0000000000000000");
211: timestamp_agent_start(default_channel);
212:
213: -----------------------------------------------------------------------
214: -- Randomize starting timestamp for better toggle coverage
215: -----------------------------------------------------------------------
216: rand_logic_vect_v(init_timestamp, 0.5);
217: timestamp_agent_timestamp_preset(default_channel, init_timestamp);
218:
219: -----------------------------------------------------------------------
220: -- Configure Reset agent and Exectue reset
221: -- - Polarity 0
222: -----------------------------------------------------------------------
223: info_m("Configuring Reset agent, executing reset");
224: rst_agent_polarity_set(default_channel, '0');
225: rst_agent_assert(default_channel);
226: wait for 10 ns;
227: rst_agent_deassert(default_channel);
228: wait for 100 ns; -- For reset to internally de-assert!
229:
230: -----------------------------------------------------------------------
231: -- Configure Memory bus agent
232: -----------------------------------------------------------------------
233: info_m("Configuring Memory bus agent");
234: mem_bus_agent_x_mode_start(default_channel);
235: mem_bus_agent_set_x_mode_setup(default_channel, 2 ns);
236: mem_bus_agent_set_x_mode_hold(default_channel, 2 ns);
237: mem_bus_agent_set_output_delay(default_channel, 4 ns);
238: mem_bus_agent_start(default_channel);
239:
240: -----------------------------------------------------------------------
241: -- Configure CAN agent
242: --
243: -- Present in compliance tests and reference tests only!
244: -----------------------------------------------------------------------
245: if (test_type = "compliance" or test_type = "reference") then
246: info_m("Configuring CAN Agent");
247: can_agent_monitor_flush(default_channel);
248: can_agent_driver_flush(default_channel);
249: can_agent_monitor_stop(default_channel);
250: can_agent_driver_stop(default_channel);
251: can_agent_monitor_set_input_delay(default_channel, 20 ns);
252: end if;
253:
254: -----------------------------------------------------------------------
255: -- Start the test (give command to corresponding test type agent)
256: -----------------------------------------------------------------------
257: if (test_type = "compliance") then
258: compliance_start <= '1';
259: wait until compliance_done = '1';
260: test_success_i := pli_test_result;
261:
262: elsif (test_type = "feature") then
263: feature_start <= '1';
264: wait until feature_done = '1';
265: test_success_i := feature_result;
266:
267: elsif (test_type = "reference") then
268: reference_start <= '1';
269: wait until reference_done = '1';
270: test_success_i := reference_result;
271:
272: else
273: error_m("Unknown test type!");
274: end if;
275:
276: -----------------------------------------------------------------------
277: -- Reset the DUT to clean-up
278: -----------------------------------------------------------------------
279: rst_agent_assert(default_channel);
280: wait for 10 ns;
281: rst_agent_deassert(default_channel);
282: wait for 100 ns;
283:
284: -- Stop clock agent (not to generate any further simulation events)
285: clk_gen_agent_stop(default_channel);
286:
287: compliance_start <= '0';
288: feature_start <= '0';
289: reference_start <= '0';
290: wait for 5 ns;
291:
292: test_done <= '1';
293: test_success <= test_success_i;
294:
295: info_m("******************************************");
296: if (test_success_i = '1') then
297: info_m("CTU CAN FD VIP: Test PASSED");
298: else
299: error_m("CTU CAN FD VIP: Test FAILED");
300: end if;
301: info_m("******************************************");
302:
303: wait until test_start = '0';
304: test_done <= '0';
305:
306: end process;
307:
308:
309: ---------------------------------------------------------------------------
310: ---------------------------------------------------------------------------
311: -- Compliance test specific part
312: ---------------------------------------------------------------------------
313: ---------------------------------------------------------------------------
314: compliance_tests_gen : if (test_type = "compliance") generate
315:
316: ---------------------------------------------------------------------------
317: -- Compliance test handling process
318: --
319: -- Passes control to Compliance test library linked to simulator.
320: -- Communication with this library is done via PLI interface.
321: ---------------------------------------------------------------------------
322: compliance_test_proc : process
323: begin
324: wait until compliance_start = '1';
325:
326: -----------------------------------------------------------------------
327: -- Give control over the TB to compliance test library which runs the
328: -- test and operates on other agents.
329: -----------------------------------------------------------------------
330: info_m("Requesting TB control from Compliance test library via PLI...");
331: pli_control_req <= '1';
332: wait for 1 ns;
333:
334: if (pli_control_gnt /= '1') then
335: wait until pli_control_gnt = '1' for 10 ns;
336: end if;
337:
338: wait for 0 ns;
339: check_m(pli_control_gnt = '1',
340: "Compliance test library took over simulation control!");
341: wait for 0 ns;
342:
343: info_m("Waiting till Compliance test library is done running test...");
344: wait until (pli_test_end = '1');
345: compliance_done <= '1';
346: info_m("Compliance test library signals test has ended");
347:
348: wait for 50 ns;
349: pli_control_req <= '0';
350: compliance_done <= '0';
351: wait for 50 ns;
352: end process;
353:
354: -----------------------------------------------------------------------
355: -- Listen on PLI commands and send them to individual agents!
356: -----------------------------------------------------------------------
357: pli_listener_process : process
358: begin
359:
360: -------------------------------------------------------------------
361: -- Poll on for pli_req = '1'
362: -------------------------------------------------------------------
363: wait until (pli_req = '1');
364: wait for 1 ps;
365:
366: -------------------------------------------------------------------
367: -- Process command (and get answer in case of read)
368: -------------------------------------------------------------------
369: case pli_dest is
370: when PLI_DEST_RES_GEN_AGENT =>
371: pli_process_rst_agnt(pli_cmd, pli_data_out, pli_data_in,
372: default_channel);
373:
374: when PLI_DEST_CLK_GEN_AGENT =>
375: pli_process_clk_agent(pli_cmd, pli_data_out, pli_data_in,
376: default_channel);
377:
378: when PLI_DEST_MEM_BUS_AGENT =>
379: pli_process_mem_bus_agent(pli_cmd, pli_data_out, pli_data_in,
380: default_channel);
381:
382: when PLI_DEST_CAN_AGENT =>
383: pli_process_can_agent(pli_cmd, pli_data_out, pli_data_in,
384: pli_data_in_2, pli_str_buf_in, default_channel);
385:
386: when PLI_DEST_TEST_CONTROLLER_AGENT =>
387: pli_process_test_agent(pli_cmd, pli_data_out, pli_data_in,
388: pli_str_buf_in, pli_test_end, pli_test_result);
389:
390: when OTHERS =>
391: error_m("Unknown agent destination: " & to_hstring(pli_dest));
392: end case;
393:
394: wait for 1 ps;
395:
396: -------------------------------------------------------------------
397: -- Issue pli_ack = '1'
398: -------------------------------------------------------------------
399: pli_ack <= '1';
400: wait for 1 ps;
401:
402: -------------------------------------------------------------------
403: -- Finish the PLI handshake
404: -------------------------------------------------------------------
405: wait until (pli_req = '0');
406: wait for 1 ps;
407: pli_ack <= '0';
408: wait for 1 ps;
409:
410: end process;
411:
412:
413: -----------------------------------------------------------------------
414: -- PLI clock generation
415: --
416: -- Create clock for synchronous communication over PLI interface.
417: -- Although compliance test library executes test in different context,
418: -- it needs to synchronize with simulator context. To do this,
419: -- compliance test library passes all messages to TB via shared memory,
420: -- which is read synchronously with PLI callbacks!
421: -----------------------------------------------------------------------
422: pli_clk_gen_proc : process
423: begin
424: pli_clk <= '1';
425: wait for 5 ns;
426: pli_clk <= '0';
427: wait for 5 ns;
428: end process;
429:
430: end generate;
431:
432:
433: end architecture;