can_top_level.vhd 33.2 KB
Newer Older
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1
--------------------------------------------------------------------------------
2
-- 
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
3
-- CTU CAN FD IP Core
4 5 6 7
-- Copyright (C) 2015-2018
-- 
-- Authors:
--     Ondrej Ille <ondrej.ille@gmail.com>
8
--     Martin Jerabek <martin.jerabek01@gmail.com>
9 10
-- 
-- Project advisors: 
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
11 12
-- 	Jiri Novak <jnovak@fel.cvut.cz>
-- 	Pavel Pisa <pisa@cmp.felk.cvut.cz>
13
-- 
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
14 15 16
-- Department of Measurement         (http://meas.fel.cvut.cz/)
-- Faculty of Electrical Engineering (http://www.fel.cvut.cz)
-- Czech Technical University        (http://www.cvut.cz/)
17
-- 
18 19 20 21 22
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this VHDL component and associated documentation files (the "Component"),
-- to deal in the Component without restriction, including without limitation
-- the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Component, and to permit persons to whom the
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
23
-- Component is furnished to do so, subject to the following conditions:
24
-- 
25
-- The above copyright notice and this permission notice shall be included in
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
26
-- all copies or substantial portions of the Component.
27
-- 
28 29 30 31
-- THE COMPONENT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33
-- FROM, OUT OF OR IN CONNECTION WITH THE COMPONENT OR THE USE OR OTHER DEALINGS
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
34
-- IN THE COMPONENT.
35
-- 
36 37
-- The CAN protocol is developed by Robert Bosch GmbH and protected by patents.
-- Anybody who wants to implement this IP core on silicon has to obtain a CAN
38
-- protocol license from Bosch.
39
-- 
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
40
--------------------------------------------------------------------------------
41

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
42
--------------------------------------------------------------------------------
43 44 45 46 47 48 49 50 51 52 53 54
-- Purpose:
--  Enity encapsulating all functionality of CAN FD node.
--  Instances:
--      1x Memory registers
--      1x Interrupt manager
--      1x Prescaler (v3)
--      1x Bus synchronizes
--      1x Event Logger
--      1x Rx buffer
--      2x TXT buffer
--      1x Tx Arbitrator
--      1x Acceptance filters
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
55
--------------------------------------------------------------------------------
56 57
-- Revision History:
--    July 2015   Created file
Martin Jeřábek's avatar
Martin Jeřábek committed
58
--    22.6.2016   1. Added rec_esi signal for error state propagation into
59 60 61 62 63
--                   RX buffer.
--                2. Added explicit architecture selection for each component
--                   (RTL)
--    24.8.2016   Added "use_logger" generic to the registers module.
--    28.11.2017  Added "rst_sync_comp" reset synchroniser.
Martin Jeřábek's avatar
Martin Jeřábek committed
64
--    30.11.2017  Changed TXT buffer to registers interface. The user is now
65 66 67
--                directly accessing the buffer by avalon access.
--    10.12.2017  Added "tx_time_sup" to enable/disable transmission at given
--                time and save some LUTs.
Martin Jeřábek's avatar
Martin Jeřábek committed
68
--    12.12.2017  Renamed "registers" entity to  "canfd_registers" to avoid
69
--                possible name conflicts.
70
--    20.12.2017  Removed obsolete "tran_data_in" signal.
71 72
--     10.2.2017  Removed "useFDsize" generic. When TX Buffer goes completely
--                to the Dual port RAM, there is no need to save memory
73 74 75
--                anymore.
--     15.2.2018  Added generic amount of TXT Buffers and support for TXT
--                buffer FSM, HW commands and SW commands.
76 77
--------------------------------------------------------------------------------

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
Library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
use ieee.math_real.ALL;

Library work;
use work.id_transfer.all;
use work.can_constants.all;
use work.can_components.all;
use work.can_types.all;
use work.cmn_lib.all;
use work.drv_stat_pkg.all;
use work.endian_swap.all;
use work.reduce_lib.all;

use work.CAN_FD_register_map.all;
use work.CAN_FD_frame_format.all;
95

96
entity can_top_level is
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    generic(
        -- Whenever event logger should be synthetised
        constant use_logger     : boolean                := true;

        -- Receive Buffer size
        constant rx_buffer_size : natural range 32 to 4096 := 128;

        -- Whenever internal synchroniser chain should be used for incoming bus
        -- signals. Dont turn off unless external synchronisation chain is put on
        -- input of FPGA by synthetiser
        constant use_sync       : boolean                := true;

        -- ID (bits  19-16 of adress)
        constant ID             : natural range 0 to 15  := 1;

        -- Optional synthesis of received message filters
        -- By default the behaviour is as if all the filters are present
        constant sup_filtA      : boolean                := true;
        constant sup_filtB      : boolean                := true;
        constant sup_filtC      : boolean                := true;
        constant sup_range      : boolean                := true;
        constant logger_size    : natural range 0 to 512 := 8
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
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
    port(
        --------------------------
        -- System clock and reset
        --------------------------
        signal clk_sys : in std_logic;
        signal res_n   : in std_logic;

        ---------------------
        -- Memory interface
        ---------------------
        signal data_in  : in  std_logic_vector(31 downto 0);
        signal data_out : out std_logic_vector(31 downto 0);
        signal adress   : in  std_logic_vector(23 downto 0);
        signal scs      : in  std_logic;    --Chip select
        signal srd      : in  std_logic;    --Serial read
        signal swr      : in  std_logic;    --Serial write
        signal sbe      : in  std_logic_vector(3 downto 0);
        --Note: This bus is Avalon compatible!

        --------------------
        -- Interrupt output
        --------------------
        signal int : out std_logic;

        -------------------
        -- CAN Bus output
        -------------------
        signal CAN_tx : out std_logic;
        signal CAN_rx : in  std_logic;

        ---------------------------
        -- Synchronisation signals
        ---------------------------
        --Time Quantum clocks possible to be used for synchronisation
        signal time_quanta_clk : out std_logic;

        -----------------------------------
        -- Internal signals for testbenches
        -----------------------------------
        -- synthesis translate_off
        signal drv_bus_o    : out std_logic_vector(1023 downto 0);
        signal stat_bus_o   : out std_logic_vector(511 downto 0);
        -- synthesis translate_on

        -------------------------------------------
        -- Timestamp value for time based messages
        -------------------------------------------
        signal timestamp : in std_logic_vector(63 downto 0)
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
168
    );
169
end entity CAN_top_level;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
170

171
architecture rtl of CAN_top_level is
Martin Jeřábek's avatar
Martin Jeřábek committed
172

173 174 175 176 177
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    ---- Internal signals
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
178

179 180 181
    ----------------------------------------------------------------------------
    -- Common control signals
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
182

183 184
    -- Overal reset (External+Reset by memory access)
    signal res_n_int  : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
185

186 187 188
    signal res_n_sync : std_logic;  -- Synchronised reset
    signal drv_bus    : std_logic_vector(1023 downto 0);
    signal stat_bus   : std_logic_vector(511 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
189

190 191 192 193
    --Interrupt signals
    signal int_vector :   std_logic_vector(INT_COUNT - 1 downto 0);
    signal int_ena    :   std_logic_vector(INT_COUNT - 1 downto 0);
    signal int_mask   :   std_logic_vector(INT_COUNT - 1 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
194

195 196 197
    ----------------------------------------------------------------------------
    -- Registers <--> RX Buffer Interface
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
198

199 200
    --Actually loaded data for reading
    signal rx_read_buff         : std_logic_vector(31 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
201

202 203
    --Actual size of synthetised message buffer (in 32 bit words)
    signal rx_buf_size          : std_logic_vector(12 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
204

205 206
    --Signal whenever buffer is full
    signal rx_full              : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
207

208 209
    --Signal whenever buffer is empty
    signal rx_empty             : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
210

211 212
    --Number of messaged stored in recieve buffer
    signal rx_message_count     : std_logic_vector(10 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
213

214 215
    --Number of free 32 bit wide ''windows''
    signal rx_mem_free          : std_logic_vector(12 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
216

217 218
    --Position of read pointer
    signal rx_read_pointer_pos  : std_logic_vector(11 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
219

220 221
    --Position of write pointer
    signal rx_write_pointer_pos : std_logic_vector(11 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
222

223 224
    --Message was discarded since Memory is full
    signal rx_message_disc      : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
225

226 227
    --Some data were discarded, register
    signal rx_data_overrun      : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
228

229 230 231 232 233 234
    -- Validated commands after Message filter
    signal rx_store_metadata_valid  : std_logic;
    signal rx_abort_valid           : std_logic;
    signal rx_store_data_valid      : std_logic;
    signal rec_message_store        : std_logic;

235 236 237
    ----------------------------------------------------------------------------
    -- Registers <--> TX Buffer, TXT Buffer
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
238

239 240 241 242
    --Data, Address and chip select into the RAM of TXT Buffer
    signal tran_data            : std_logic_vector(31 downto 0);
    signal tran_addr            : std_logic_vector(4 downto 0);
    signal tran_cs              : std_logic_vector(TXT_BUFFER_COUNT - 1 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
243

244
    -- Finite state machine types for TXT Buffer
245
    signal txtb_state           : txtb_state_type;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
246

247 248 249 250
    -- Software commands + buffer indices that should be activated
    signal txt_sw_cmd           :  txt_sw_cmd_type;
    signal txt_buf_cmd_index    :  std_logic_vector(TXT_BUFFER_COUNT - 1 downto 0);
    signal txt_buf_prior        :  txtb_priorities_type;
Martin Jeřábek's avatar
Martin Jeřábek committed
251

252 253 254
    -- Indicates that TXT Buffer has changed and that Retrransmitt counter
    -- should be erased by Protocol control.
    signal txtb_changed         :  std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
255

256 257 258
    ----------------------------------------------------------------------------
    -- Registers <--> event logger
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
259

260 261 262 263 264
    signal loger_act_data    : std_logic_vector(63 downto 0);
    signal log_write_pointer : std_logic_vector(7 downto 0);
    signal log_read_pointer  : std_logic_vector(7 downto 0);
    signal log_size          : std_logic_vector(7 downto 0);
    signal log_state_out     : logger_state_type;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
265 266


267 268 269
    ----------------------------------------------------------------------------
    --TX Arbitrator <--> TX Buffer, TXT Buffer
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
270

271 272
    signal txt_hw_cmd_buf_index : natural range 0 to TXT_BUFFER_COUNT - 1;
    signal txt_buf_ready        : std_logic_vector(TXT_BUFFER_COUNT - 1 downto 0);
273

274 275
    -- Frames in TXT buffers on output - Data(addressed), Metadata (paralell)
    signal txt_word             : txtb_output_type;
Martin Jeřábek's avatar
Martin Jeřábek committed
276 277


278 279 280
    ----------------------------------------------------------------------------
    -- TX Arbitrator <--> CAN Core
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
281

282 283
    --TX Message data
    signal tran_data_out        : std_logic_vector(31 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
284

285 286
    --TX Data length code
    signal tran_dlc_out         : std_logic_vector(3 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
287

288 289
    --TX is remote frame
    signal tran_is_rtr          : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
290

291 292
    --TX Identifier type (0-Basic,1-Extended);
    signal tran_ident_type_out  : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
293

294 295
    --TX Frame type
    signal tran_frame_type_out  : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
296

297 298
    --Bit rate shift for CAN FD frames
    signal tran_brs_out         : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
299

300 301 302
    --Signal for CAN Core that frame on the output is valid and can be
    --stored for transmitting
    signal tran_frame_valid_out : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
303

304 305
    -- Hardware commands to TXT Buffer from Protocol control
    signal txt_hw_cmd           : txt_hw_cmd_type;
Martin Jeřábek's avatar
Martin Jeřábek committed
306

307
    -- TXT Buffer HW CMD Interrupt activated on TXT Buffer
Ille, Ondrej, Ing.'s avatar
fixes  
Ille, Ondrej, Ing. committed
308 309
    signal txt_hw_cmd_int       : std_logic_vector(TXT_BUFFER_COUNT - 1
                                                    downto 0);
310

311 312 313
    -- Hardware command index set by TX Arbitrator based on the current
    -- internal state
    signal txt_hw_cmd_index     : natural range 0 to TXT_BUFFER_COUNT - 1;
Martin Jeřábek's avatar
Martin Jeřábek committed
314

315 316
    --Pointer to TXT buffer memory (from TX Arbitrator)
    signal txt_buf_ptr          : natural range 0 to 19;
Martin Jeřábek's avatar
Martin Jeřábek committed
317

318 319
    -- Pointer to TXT Buffer memory (from CAN Core)
    signal txtb_core_pointer    : natural range 0 to 19;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
320

321 322
    -- Transition of fault confinement state to bus-off
    signal bus_off_start        : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
323

324 325 326
    ----------------------------------------------------------------------------
    --RX Buffer <--> CAN Core
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
327

328 329
    --Message Identifier
    signal rec_ident_in      : std_logic_vector(28 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
330

331 332
    --Data length code
    signal rec_dlc_in        : std_logic_vector(3 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
333

334 335
    --Recieved identifier type (0-BASE Format, 1-Extended Format);
    signal rec_ident_type_in : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
336

337 338
    --Recieved frame type (0-Normal CAN, 1- CAN FD)
    signal rec_frame_type_in : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
339

340 341
    --Recieved frame is RTR Frame(0-No, 1-Yes)
    signal rec_is_rtr        : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
342

343 344
    --Frame is received properly (can be committed to RX Buffer)
    signal rec_message_valid : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
345

346 347
    --Whenever frame was recieved with BIT Rate shift
    signal rec_brs           : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
348

349 350
    -- Received Error state indicator
    signal rec_esi           : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
351

352 353
    -- Signals start of frame for storing timestamp
    signal sof_pulse         : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
354

355 356
    -- Metadata can be stored to the RX Buffer
    signal rx_store_metadata : std_logic;
357

358 359
    -- Data word can be stored in RX Buffer
    signal rx_store_data     : std_logic;
360

361 362
    -- Data word to be stored
    signal rx_store_data_word : std_logic_vector(31 downto 0);
363

364 365
    -- Abort storing of RX Frame (in case of Error frame)
    signal rx_abort           : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
366 367


368 369 370
    ----------------------------------------------------------------------------
    -- RX Buffer <--> Message filters
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
371

372 373
    --Signal whenever identifier matches the filter identifiers
    signal out_ident_valid : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
374 375


376 377 378
    ----------------------------------------------------------------------------
    -- Interrupt manager <--> CAN Core
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
379

380 381
    --Valid Error appeared for interrupt
    signal error_valid           : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
382

383 384
    --Error pasive /Error acitve functionality changed
    signal error_passive_changed : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
385

386 387
    --Error warning limit reached
    signal error_warning_limit   : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
388

389 390
    --Arbitration was lost input
    signal arbitration_lost      : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
391

392 393
    --Wake up appeared
    signal wake_up_valid         : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
394

395 396
    --Message stored in CAN Core was sucessfully transmitted
    signal tx_finished           : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
397

398 399
    --Bit Rate Was Shifted
    signal br_shifted            : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
400

401
    --Event logging finsihed
402
    signal loger_finished        : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
403 404


405 406 407
    ----------------------------------------------------------------------------
    -- Prescaler <--> CAN Core
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
408

409 410
    --Edge for synchronisation
    signal sync_edge      : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
411

412 413
    --Protocol control state
    signal OP_State       : oper_mode_type;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
414

415 416
    --Time quantum clock - Nominal bit time
    signal clk_tq_nbt : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
417

418 419
    --Bit time - Nominal bit time
    signal clk_tq_dbt : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
420

421 422
    --Sample signal for nominal bit time
    signal sample_nbt       : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
423

424 425
    --Sample signal of data bit time
    signal sample_dbt       : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
426

427 428 429 430 431
    --Delay sample signals by 1 or 2 clock cycle
    signal sample_nbt_del_1 : std_logic;
    signal sample_dbt_del_1 : std_logic;
    signal sample_nbt_del_2 : std_logic;
    signal sample_dbt_del_2 : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
432

433 434 435 436 437
    -- Transmitt signals and delayed transmitt signals by 1 clock cycle
    signal sync_nbt       : std_logic;
    signal sync_dbt       : std_logic;
    signal sync_nbt_del_1 : std_logic;
    signal sync_dbt_del_1 : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
438

439 440
    signal sp_control   : std_logic_vector(1 downto 0);
    signal sync_control : std_logic_vector(1 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
441

442
    signal bt_FSM_out : bit_time_type;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
443

444 445 446 447 448
    --Validated hard synchronisation edge to start Protocol control FSM
    signal hard_sync_edge_valid : std_logic;
    --Note: Sync edge from busSync.vhd cant be used! If it comes during sample
    -- nbt, sequence it causes errors! It needs to be strictly before or
    -- strictly after this sequence!!!
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
449 450


451 452 453
    ----------------------------------------------------------------------------
    -- Bus Synchroniser Interface
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
454

455 456
    --Transcieve data value
    signal data_tx           : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
457

458 459
    --Recieved data value
    signal data_rx           : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
460

461 462
    --Clear the Shift register at the  beginning of Data Phase!!!
    signal ssp_reset         : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
463

464 465
    --Calibration command for transciever delay compenstation (counter)
    signal trv_delay_calib   : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
466

467 468
    --Bit error with secondary sampling transciever!
    signal bit_Error_sec_sam : std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
469

470 471
    --Secondary sample signal
    signal sample_sec       : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
472

473 474
    --Bit destuffing trigger for secondary sample point
    signal sample_sec_del_1 : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
475

476 477
    --Rec trig for secondary sample point
    signal sample_sec_del_2 : std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
478

479 480
    -- Transceiver delay output
    signal trv_delay_out : std_logic_vector(15 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
481

482

483 484 485
    ----------------------------------------------------------------------------
    -- Defining explicit architectures for used entites
    ----------------------------------------------------------------------------
486 487 488 489 490 491 492 493 494
    for memory_registers_comp   : memory_registers use entity work.memory_registers(rtl);
    for rx_buffer_comp          : rx_buffer use entity work.rx_buffer(rtl);
    for tx_arbitrator_comp      : tx_arbitrator use entity work.tx_arbitrator(rtl);
    for frame_filters_comp      : frame_filters use entity work.frame_filters(rtl);
    for int_manager_comp        : int_manager use entity work.int_manager(rtl);
    for can_core_comp           : can_core use entity work.can_core(rtl);
    for prescaler_comp          : prescaler use entity work.prescaler(rtl);
    for bus_sampling_comp       : bus_sampling use entity work.bus_sampling(rtl);
    for rst_sync_comp           : rst_sync use entity work.rst_sync(rtl);
495 496

begin
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
497

498 499 500 501 502 503
    -- synthesis translate_off
    drv_bus_o   <= drv_bus;
    stat_bus_o  <= stat_bus;
    -- synthesis translate_on

    rst_sync_comp : rst_sync
504 505 506
    generic map(
        reset_polarity  => ACT_RESET
    )
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
507
    port map(
508
        clk             => clk_sys,
509 510
        arst            => res_n,
        rst             => res_n_sync
511
    );
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
512

513
    memory_registers_comp : memory_registers
514
    generic map(
515 516 517 518 519 520 521 522
        compType        => CAN_COMPONENT_TYPE,
        use_logger      => use_logger,
        sup_filtA       => sup_filtA,
        sup_filtB       => sup_filtB,
        sup_filtC       => sup_filtC,
        sup_range       => sup_range,
        sup_be          => true,
        buf_count       => TXT_BUFFER_COUNT,
523 524 525 526
        ID              => ID,
        DEVICE_ID       => CTU_CAN_FD_ID,
        VERSION_MINOR   => x"01",
        VERSION_MAJOR   => x"02"
527
    )
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
528
    port map(
529 530 531 532 533 534 535 536 537 538
        clk_sys              => clk_sys,
        res_n                => res_n_sync,
        res_out              => res_n_int,
        data_in              => data_in,
        data_out             => data_out,
        adress               => adress,
        scs                  => scs,
        srd                  => srd,
        swr                  => swr,
        sbe                  => sbe,
539
        timestamp            => timestamp,
540 541 542 543 544 545 546 547 548 549 550 551 552 553
        drv_bus              => drv_bus,
        stat_bus             => stat_bus,
        rx_read_buff         => rx_read_buff,
        rx_buf_size          => rx_buf_size,
        rx_full              => rx_full,
        rx_empty             => rx_empty,
        rx_message_count     => rx_message_count,
        rx_mem_free          => rx_mem_free,
        rx_read_pointer_pos  => rx_read_pointer_pos,
        rx_write_pointer_pos => rx_write_pointer_pos,
        rx_data_overrun      => rx_data_overrun,
        tran_data            => tran_data,
        tran_addr            => tran_addr,
        txtb_cs              => tran_cs,
554
        txtb_state           => txtb_state,
555 556 557 558 559 560 561 562 563 564 565 566 567
        txt_sw_cmd           => txt_sw_cmd,
        txt_buf_cmd_index    => txt_buf_cmd_index,
        txt_buf_prior_out    => txt_buf_prior,
        int_vector           => int_vector,
        int_ena              => int_ena,
        int_mask             => int_mask,
        trv_delay_out        => trv_delay_out,
        loger_act_data       => loger_act_data,
        log_write_pointer    => log_write_pointer,
        log_read_pointer     => log_read_pointer,
        log_size             => log_size,
        log_state_out        => log_state_out
    );
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
568

569

570
    rx_buffer_comp : rx_buffer
571
    generic map(
572 573
        buff_size            => rx_buffer_size
    )
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
574
    port map(
575 576 577 578 579 580 581 582 583 584
        clk_sys              => clk_sys,
        res_n                => res_n_int,
        rec_ident_in         => rec_ident_in,
        rec_dlc_in           => rec_dlc_in,
        rec_ident_type_in    => rec_ident_type_in,
        rec_frame_type_in    => rec_frame_type_in,
        rec_is_rtr           => rec_is_rtr,
        rec_brs              => rec_brs,
        rec_esi              => rec_esi,

585 586
        store_metadata       => rx_store_metadata_valid,
        store_data           => rx_store_data_valid,
587
        store_data_word      => rx_store_data_word,
588 589
        rec_message_valid    => rec_message_store,
        rec_abort            => rx_abort_valid,
590 591 592 593 594 595 596 597 598 599

        sof_pulse            => sof_pulse,
        rx_buf_size          => rx_buf_size,
        rx_full              => rx_full,
        rx_empty             => rx_empty,
        rx_message_count     => rx_message_count,
        rx_mem_free          => rx_mem_free,
        rx_read_pointer_pos  => rx_read_pointer_pos,
        rx_write_pointer_pos => rx_write_pointer_pos,
        rx_data_overrun      => rx_data_overrun,
Martin Jeřábek's avatar
Martin Jeřábek committed
600
        timestamp            => timestamp,
601 602 603 604 605
        rx_read_buff         => rx_read_buff,
        drv_bus              => drv_bus
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
606

607
    txt_buf_comp_gen : for i in 0 to TXT_BUFFER_COUNT - 1 generate
608
        txt_buffer_comp : txt_buffer
609 610 611 612 613 614 615 616 617 618 619 620
        generic map(
            buf_count             => TXT_BUFFER_COUNT,
            ID                    => i
        )
        port map(
            clk_sys               => clk_sys,
            res_n                 => res_n_int,
            tran_data             => tran_data,
            tran_addr             => tran_addr,
            tran_cs               => tran_cs(i),
            txt_sw_cmd            => txt_sw_cmd,
            txt_sw_buf_cmd_index  => txt_buf_cmd_index,
621
            txtb_state            => txtb_state(i),
622
            txt_hw_cmd            => txt_hw_cmd,
623
            txt_hw_cmd_int        => txt_hw_cmd_int(i),
624 625 626 627 628 629 630 631 632
            txt_hw_cmd_buf_index  => txt_hw_cmd_buf_index,
            bus_off_start         => bus_off_start,
            txt_word              => txt_word(i),
            txt_addr              => txt_buf_ptr,
            txt_buf_ready         => txt_buf_ready(i)
        );
    end generate;


633
    tx_arbitrator_comp : tx_arbitrator
634
    generic map(
635
        buf_count               => TXT_BUFFER_COUNT
636
    )
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
637
    port map(
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
        clk_sys                => clk_sys,
        res_n                  => res_n_int,
        txt_buf_in             => txt_word,
        txt_buf_ready          => txt_buf_ready,
        txtb_ptr               => txt_buf_ptr,
        tran_data_word_out     => tran_data_out,
        tran_dlc_out           => tran_dlc_out,
        tran_is_rtr            => tran_is_rtr,
        tran_ident_type_out    => tran_ident_type_out,
        tran_frame_type_out    => tran_frame_type_out,
        tran_brs_out           => tran_brs_out,
        tran_frame_valid_out   => tran_frame_valid_out,
        txt_hw_cmd             => txt_hw_cmd,
        txtb_changed           => txtb_changed,
        txt_hw_cmd_buf_index   => txt_hw_cmd_buf_index,
        txtb_core_pointer      => txtb_core_pointer,
        drv_bus                => drv_bus,
        txt_buf_prio           => txt_buf_prior,
        timestamp              => timestamp
657
    );
658

659
    frame_filters_comp : frame_filters
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
660
    generic map(
661 662 663 664 665
        sup_filtA       => sup_filtA,
        sup_filtB       => sup_filtB,
        sup_filtC       => sup_filtC,
        sup_range       => sup_range
    )
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
666
    port map(
667 668 669 670 671 672
        clk_sys         => clk_sys,
        res_n           => res_n_int,
        rec_ident_in    => rec_ident_in,
        ident_type      => rec_ident_type_in,
        frame_type      => rec_frame_type_in,

673 674 675 676 677 678 679
        ------------------------------------------------------------------------
        -- All commands on RX Buffer are generated by Protocol control when
        -- ID is already received (between CONTROL and EOF), thus ID
        -- comparison can be enabled always!
        ------------------------------------------------------------------------
        rec_ident_valid => '1',

680 681 682 683
        drv_bus         => drv_bus,
        out_ident_valid => out_ident_valid
    );

684 685 686 687 688 689 690 691 692
    ----------------------------------------------------------------------------
    -- Commands for storing Frame to RX Buffer are valid only when it passed
    -- message filter
    ----------------------------------------------------------------------------
    rx_store_metadata_valid <= rx_store_metadata and out_ident_valid;
    rx_abort_valid          <= rx_abort and out_ident_valid;
    rx_store_data_valid     <= rx_store_data and out_ident_valid;
    rec_message_store       <= rec_message_valid and out_ident_valid;

693
    int_manager_comp : int_manager
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
694
    generic map(
695 696
        int_count             => INT_COUNT
    )
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
697
    port map(
698 699 700 701 702 703 704 705 706 707 708 709
        clk_sys               => clk_sys,
        res_n                 => res_n_int,
        error_valid           => error_valid,
        error_passive_changed => error_passive_changed,
        error_warning_limit   => error_warning_limit,
        arbitration_lost      => arbitration_lost,
        tx_finished           => tx_finished,
        br_shifted            => br_shifted,
        rx_message_disc       => rx_data_overrun,
        rec_message_valid     => rec_message_valid,
        rx_full               => rx_full,
        rx_empty              => rx_empty,
710
        txt_hw_cmd_int        => txt_hw_cmd_int,
711 712 713 714 715 716 717 718
        loger_finished        => loger_finished,
        drv_bus               => drv_bus,
        int_out               => int,
        int_vector            => int_vector,
        int_ena               => int_ena,
        int_mask              => int_mask
    );

719
    can_core_comp : can_core
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
720
    port map(
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
        clk_sys               => clk_sys,
        res_n                 => res_n_int,
        drv_bus               => drv_bus,
        stat_bus              => stat_bus,
        tran_data_in          => tran_data_out,
        tran_dlc_in           => tran_dlc_out,
        tran_is_rtr_in        => tran_is_rtr,
        tran_ident_type_in    => tran_ident_type_out,
        tran_frame_type_in    => tran_frame_type_out,
        tran_brs_in           => tran_brs_out,
        tran_frame_valid_in   => tran_frame_valid_out,
        txt_hw_cmd            => txt_hw_cmd,
        txtb_changed          => txtb_changed,
        txt_buf_ptr           => txtb_core_pointer,
        rec_ident_out         => rec_ident_in,
        rec_dlc_out           => rec_dlc_in,
        rec_ident_type_out    => rec_ident_type_in,
        rec_frame_type_out    => rec_frame_type_in,
        rec_is_rtr_out        => rec_is_rtr,
        rec_brs_out           => rec_brs,
        rec_esi_out           => rec_esi,
        rec_message_valid_out => rec_message_valid,

        store_metadata        =>  rx_store_metadata,
        rec_abort             =>  rx_abort,
        store_data            =>  rx_store_data,
        store_data_word       =>  rx_store_data_word,

        arbitration_lost_out  => arbitration_lost,
        tx_finished           => tx_finished,
        br_shifted            => br_shifted,
        error_valid           => error_valid,
        error_passive_changed => error_passive_changed,
        error_warning_limit   => error_warning_limit,
        sample_nbt_del_2      => sample_nbt_del_2,
        sample_dbt_del_2      => sample_dbt_del_2,
        sample_nbt_del_1      => sample_nbt_del_1,
        sample_dbt_del_1      => sample_dbt_del_1,
        sync_nbt              => sync_nbt,
        sync_dbt              => sync_dbt,
        sync_nbt_del_1        => sync_nbt_del_1,
        sync_dbt_del_1        => sync_dbt_del_1,
        sample_sec            => sample_sec,
        sample_sec_del_1      => sample_sec_del_1,
        sample_sec_del_2      => sample_sec_del_2,
        sync_control          => sync_control,
        data_rx               => data_rx,
        data_tx               => data_tx,
        timestamp             => timestamp,
        sp_control            => sp_control,
        ssp_reset             => ssp_reset,
        trv_delay_calib       => trv_delay_calib,
        hard_sync_edge        => hard_sync_edge_valid,
        bit_Error_sec_sam     => bit_Error_sec_sam,
        bus_off_start         => bus_off_start,
        sof_pulse             => sof_pulse
    );

779
    prescaler_comp : prescaler
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
780
    port map(
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
        clk_sys              => clk_sys,
        res_n                => res_n_int,
        OP_State             => OP_State,
        sync_edge            => sync_edge,
        drv_bus              => drv_bus,
        clk_tq_nbt           => clk_tq_nbt,
        clk_tq_dbt           => clk_tq_dbt,
        sample_nbt           => sample_nbt,
        sample_dbt           => sample_dbt,
        bt_FSM_out           => bt_FSM_out,
        sample_nbt_del_1     => sample_nbt_del_1,
        sample_dbt_del_1     => sample_dbt_del_1,
        sample_nbt_del_2     => sample_nbt_del_2,
        sample_dbt_del_2     => sample_dbt_del_2,
        sync_nbt             => sync_nbt,
        sync_dbt             => sync_dbt,
        sync_nbt_del_1       => sync_nbt_del_1,
        sync_dbt_del_1       => sync_dbt_del_1,
        data_tx              => data_tx,
        hard_sync_edge_valid => hard_sync_edge_valid,
        sp_control           => sp_control,
        sync_control         => sync_control
    );

805
    bus_sampling_comp : bus_sampling
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
806
    generic map (
807 808
        use_Sync             => use_sync
    )
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
809
    port map(
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
        clk_sys              => clk_sys,
        res_n                => res_n_int,
        CAN_rx               => CAN_rx,
        CAN_tx               => CAN_tx,
        drv_bus              => drv_bus,
        sample_nbt           => sample_nbt,
        sample_dbt           => sample_dbt,
        sync_edge            => sync_edge,
        data_tx              => data_tx,
        data_rx              => data_rx,
        sp_control           => sp_control,
        ssp_reset            => ssp_reset,
        trv_delay_calib      => trv_delay_calib,

        --Note: Bit Error detection enabled always. bit_Error signal from this
        -- block used only for secondary sample point bit error detection!!
        bit_err_enable       => '1',

        sample_sec_out       => sample_sec,
        sample_sec_del_1_out => sample_sec_del_1,
        sample_sec_del_2_out => sample_sec_del_2,
        trv_delay_out        => trv_delay_out,
        bit_Error            => bit_Error_sec_sam
    );


836 837
    event_logger_gen_true : if (use_logger) generate
        event_logger_comp : event_logger
838 839
        generic map(
            memory_size         => logger_size
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
840
        )
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
        port map(
            clk_sys             => clk_sys,
            res_n               => res_n_int,

            drv_bus             => drv_bus,
            stat_bus            => stat_bus,
            sync_edge           => sync_edge,
            timestamp           => timestamp,

            loger_finished      => loger_finished,
            loger_act_data      => loger_act_data,
            log_write_pointer   => log_write_pointer,
            log_read_pointer    => log_read_pointer,
            log_size            => log_size,
            log_state_out       => log_state_out,
            bt_FSM              => bt_FSM_out,
            data_overrun        => rx_data_overrun
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
858
        );
859
    end generate event_logger_gen_true;
860

861
    event_logger_gen_false : if (not use_logger) generate
862 863 864 865 866
        loger_finished    <= '0';
        loger_act_data    <= (others => '0');
        log_write_pointer <= (others => '0');
        log_read_pointer  <= (others => '0');
        log_size          <= (others => '0');
867
		log_state_out     <= config;
868
    end generate event_logger_gen_false;
869 870 871

    --Bit time clock output propagation
    time_quanta_clk <= clk_tq_nbt when sp_control = NOMINAL_SAMPLE else
872
                       clk_tq_dbt;
873 874

    OP_State <= oper_mode_type'val(to_integer(unsigned(
875
                    stat_bus(STAT_OP_STATE_HIGH downto STAT_OP_STATE_LOW))));
Martin Jeřábek's avatar
Martin Jeřábek committed
876

877
end architecture;