File: /__w/ctu-can-regression/ctu-can-regression/test/main_tb/agents/timestamp_agent/timestamp_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: -- Timestamp agent - Generates timestamp on DUT input.
71: --
72: -- Has following features:
73: -- - Initialization of timestamp
74: -- - Step of timestamp (next value bigger than previous by step)
75: -- - Prescaler of timestamp (how many cycles needed to increment by step).
76: -- - Start/Stop counting.
77: --
78: --------------------------------------------------------------------------------
79: -- Revision History:
80: -- 12.3.2021 Created file
81: --------------------------------------------------------------------------------
82:
83: Library ctu_can_fd_tb;
84: context ctu_can_fd_tb.ieee_context;
85: context ctu_can_fd_tb.tb_common_context;
86:
87: use ctu_can_fd_tb.timestamp_agent_pkg.all;
88: use ctu_can_fd_tb.tb_shared_vars_pkg.all;
89:
90:
91: entity timestamp_agent is
92: port (
93: clk_sys : in std_logic;
94: timestamp : out std_logic_vector(63 downto 0)
95: );
96: end entity;
97:
98:
99: architecture tb of timestamp_agent is
100:
101: ---------------------------------------------------------------------------
102: -- Parameters configured over communication library
103: ---------------------------------------------------------------------------
104: signal step : unsigned(63 downto 0);
105: signal prescaler : natural := 1;
106:
107: signal running : boolean := false;
108:
109: signal timestamp_i : unsigned(63 downto 0) := (OTHERS => '0');
110:
111: signal timestamp_preset_val : std_logic_vector(63 downto 0);
112: signal timestamp_preset : std_logic;
113:
114: signal prescaler_ctr : natural := 0;
115: signal last_clk_event : time;
116:
117: begin
118:
119: ---------------------------------------------------------------------------
120: -- Comunication receiver process
121: ---------------------------------------------------------------------------
122: receiver_proc : process
123: variable cmd : integer;
124: variable reply_code : integer;
125: variable tmp : std_logic_vector(127 downto 0);
126: variable tmp_int : integer;
127: begin
128: receive_start(default_channel, C_TIMESTAMP_AGENT_ID);
129:
130: -- Command is sent as message type
131: cmd := com_channel_data.get_msg_code;
132: reply_code := C_REPLY_CODE_OK;
133:
134: case cmd is
135: when TIMESTAMP_AGENT_CMD_START =>
136: running <= true;
137:
138: when TIMESTAMP_AGENT_CMD_STOP =>
139: running <= false;
140:
141: when TIMESTAMP_AGENT_CMD_STEP_SET =>
142: tmp_int := com_channel_data.get_param;
143: step <= to_unsigned(tmp_int, 64);
144:
145: when TIMESTAMP_AGENT_CMD_PRESCALER_SET =>
146: prescaler <= com_channel_data.get_param;
147:
148: when TIMESTAMP_AGENT_CMD_TIMESTAMP_PRESET =>
149: tmp := com_channel_data.get_param;
150: timestamp_preset_val <= tmp(63 downto 0);
151: wait for 0 ns;
152: timestamp_preset <= '1';
153: wait for 0 ns;
154: timestamp_preset <= '0';
155: wait for 0 ns;
156:
157: when TIMESTAMP_AGENT_CMD_GET_TIMESTAMP =>
158: com_channel_data.set_param(std_logic_vector(timestamp_i));
159:
160: when others =>
161: info_m("Invalid message type: " & integer'image(cmd));
162: reply_code := C_REPLY_CODE_ERR;
163:
164: end case;
165: receive_finish(default_channel, reply_code);
166: end process;
167:
168: ---------------------------------------------------------------------------
169: -- Timestamp generation
170: ---------------------------------------------------------------------------
171: timestamp_gen_proc : process
172: begin
173: if (running = false) then
174: wait until running = true;
175: end if;
176:
177: if (timestamp_preset'last_event < (now - last_clk_event)) then
178: timestamp_i <= unsigned(timestamp_preset_val);
179: end if;
180:
181: last_clk_event <= now;
182: wait until rising_edge(clk_sys);
183:
184: if (prescaler > 1) then
185: if (prescaler_ctr = prescaler - 1) then
186: prescaler_ctr <= 0;
187: timestamp_i <= timestamp_i + step;
188: else
189: prescaler_ctr <= prescaler_ctr + 1;
190: end if;
191: else
192: timestamp_i <= timestamp_i + step;
193: end if;
194:
195: end process;
196:
197: timestamp <= std_logic_vector(timestamp_i);
198:
199: end architecture;