CANtestLib.vhd 191 KB
Newer Older
1
--------------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
2
--
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
3
-- CTU CAN FD IP Core
4
-- Copyright (C) 2015-2018
Martin Jeřábek's avatar
Martin Jeřábek committed
5
--
6 7
-- Authors:
--     Ondrej Ille <ondrej.ille@gmail.com>
8
--     Martin Jerabek <martin.jerabek01@gmail.com>
Martin Jeřábek's avatar
Martin Jeřábek committed
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>
Martin Jeřábek's avatar
Martin Jeřábek committed
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/)
Martin Jeřábek's avatar
Martin Jeřábek committed
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:
Martin Jeřábek's avatar
Martin Jeřábek committed
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.
Martin Jeřábek's avatar
Martin Jeřábek committed
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.
Martin Jeřábek's avatar
Martin Jeřábek committed
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.
Martin Jeřábek's avatar
Martin Jeřábek committed
39
--
40 41
--------------------------------------------------------------------------------

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
42
--------------------------------------------------------------------------------
43
--  Purpose:
Martin Jeřábek's avatar
Martin Jeřábek committed
44
--    Main test library for CTU CAN FD controller. Contains all test resources
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
45 46 47 48 49
--    for running CANTest framework and low-level access functions.
--
--    Note that in this library several types are (nearly) the same as types
--    in synthesizable code! This is done on purpose, to avoid using wrongly
--    defined values. These types are defined from documentation manually.
50
--
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
51
--------------------------------------------------------------------------------
52 53
-- Revision History:
--    27.5.2016   Created file
Martin Jeřábek's avatar
Martin Jeřábek committed
54 55
--    13.1.2017   Added formatting of identifier in CAN_send_frame,
--                CAN_read_frame to fit the native decimal interpretation
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
56 57 58 59
--                (the same way as in C driver)
--    27.11.2017  Added "reset_test" function fix. Implemented reset synchroniser
--                to avoid async reset in the core. As consequnce after the core
--                reset is released, the core has to wait at least TWO clock
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
60
--                cycles till the reset is synchronised and deasserted.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
61 62
--    06.02.2018  Modified the library to work with generated constants from the
--                8 bit register map generated from IP-XACT.
63
--    09.02.2018  Added support fow RWCNT field in the SW_CAN_Frame.
Martin Jeřábek's avatar
Martin Jeřábek committed
64
--    15.02.2018  Added support for TXT Buffer commands in CAN Send frame
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
65 66 67
--                procedure.
--    23.02.2018  Corrected "CAN_generate_frame" function for proper placement
--                of BASE identifier to unsigned value.
68 69 70
--     28.4.2018  Converted TXT Buffer access functions to use generated macros.
--      1.5.2018  1. Added HAL layer types and functions.
--                2. Added Byte enable support to memory access functions.
71
--      7.6.2018  Added "CAN_insert_TX_frame" procedure.
Martin Jeřábek's avatar
Martin Jeřábek committed
72
--     18.6.2018  Added optimized clock_gen_proc, timestamp_gen_proc procedures.
73
--     15.9.2018  Added support for message filter manipulation!
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
74 75
--     27.9.2018  Added burst support for avalon access. Added option to read
--                frame from RX Buffer via burst partially!
76 77
--    19.11.2019  Added options to force transmitter delay and timestamp in
--                feature tests.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
78
--------------------------------------------------------------------------------
79

80 81 82
Library ieee;
USE IEEE.std_logic_1164.all;
USE IEEE.numeric_std.ALL;
83 84
use STD.textio.all;
use IEEE.std_logic_textio.all;
85 86
USE ieee.math_real.ALL;
USE work.randomLib.All;
87
use work.can_constants.all;
88
use work.drv_stat_pkg.all;
89
use work.can_config.all;
90

91
use work.CAN_FD_register_map.all;
92
use work.CAN_FD_frame_format.all;
93

94 95
library vunit_lib;
context vunit_lib.vunit_context;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
96

97 98
package CANtestLib is

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
99 100 101 102 103 104 105 106 107 108 109 110
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    -- Types
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------

    ----------------------------------------------------------------------------
    --Common test types
    ----------------------------------------------------------------------------

    -- Logger severity type (severities in increasing order)
    type log_lvl_type is (
111
        debug_l,
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
112 113 114 115
        info_l,
        warning_l,
        error_l
    );
116

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
117 118 119 120 121
    -- Behaviour of the test when error occurs
    type err_beh_type is (
        quit,
        go_on
    );
122

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
123 124 125 126 127 128
    -- Status of test
    type test_status_type is (
        waiting,
        running,
        passed,
        failed
129
    );
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
130 131


132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    ----------------------------------------------------------------------------
    -- Memory access types
    ----------------------------------------------------------------------------

    -- Avalon bus access size (to support "byte enable" functionality)
    type aval_access_size is (
        BIT_8,
        BIT_16,
        BIT_32
    );

    ----------------------------------------------------------------------------
    -- Core common types for register map (generated in future)
    -- Implemented to create HAL like abstraction and allow easier modifications
    -- of register map without touching the test code!
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
148

149 150 151 152
    -- Controller modes
    type SW_mode is record
        reset                   :   boolean;
        listen_only             :   boolean;
153
        test                    :   boolean;
154 155 156 157 158
        self_test               :   boolean;
        acceptance_filter       :   boolean;
        flexible_data_rate      :   boolean;
        rtr_pref                :   boolean;
        acknowledge_forbidden   :   boolean;
159 160
        internal_loopback       :   boolean;
        iso_fd_support          :   boolean;
161
    end record;
162 163
    
    constant SW_mode_rst_val : SW_mode := (false, false, false, false, false,
164
        true, false, false, false, true);
165 166 167 168 169

    -- Controller commands
    type SW_command is record
        release_rec_buffer      :   boolean;
        clear_data_overrun      :   boolean;
170 171 172
        err_ctrs_rst            :   boolean;
        rx_frame_ctr_rst        :   boolean;
        tx_frame_ctr_rst        :   boolean;
173 174
    end record;

175 176
    constant SW_command_rst_val : SW_command :=
        (false, false, false, false, false);
177 178 179 180 181

    -- Controller status
    type SW_status is record
        receive_buffer          :   boolean;
        data_overrun            :   boolean;
182
        tx_buffer_empty         :   boolean;
183 184 185 186 187 188 189 190
        error_transmission      :   boolean;
        receiver                :   boolean;
        transmitter             :   boolean;
        error_warning           :   boolean;
        bus_status              :   boolean;
    end record;


191
    -- Interrupt sources
192 193 194 195 196
    type SW_interrupts is record
        receive_int             :   boolean;
        transmitt_int           :   boolean;
        error_warning_int       :   boolean;
        data_overrun_int        :   boolean;
197
        fcs_changed_int         :   boolean;
198 199 200 201 202 203 204
        arb_lost_int            :   boolean;
        bus_error_int           :   boolean;
        logger_finished_int     :   boolean;
        rx_buffer_full_int      :   boolean;
        bit_rate_shift_int      :   boolean;
        rx_buffer_not_empty_int :   boolean;
        tx_buffer_hw_cmd        :   boolean;
Martin Jeřábek's avatar
Martin Jeřábek committed
205
    end record;
206 207 208 209
    
    constant SW_interrupts_rst_val : SW_interrupts := (
        false, false, false, false, false, false, false, false,
        false, false, false, false);
210 211 212 213 214 215 216 217

    -- Fault confinement states
    type SW_fault_state is (
        fc_error_active,
        fc_error_passive,
        fc_bus_off
    );

218 219 220 221 222
    -- Fault confinement state thresholds
    type SW_fault_thresholds is record
        ewl                     :   natural range 0 to 255;
        erp                     :   natural range 0 to 255;
    end record;
223

224
    -- Error counters (Normal and Special)
225
    type SW_error_counters is record
226 227
        rx_counter              :   natural range 0 to 2 ** 9 - 1;
        tx_counter              :   natural range 0 to 2 ** 9 - 1;
228 229 230 231 232
        err_norm                :   natural range 0 to 2 ** 16 - 1;
        err_fd                  :   natural range 0 to 2 ** 16 - 1;
    end record;


233 234 235 236 237 238 239
    -- Traffic counters
    type SW_traffic_counters is record
        rx_frames               :   natural;
        tx_frames               :   natural;
    end record;


240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
    -- RX Buffer info and status
    type SW_RX_Buffer_info is record
        rx_buff_size            :   natural range 0 to 2 ** 13 - 1;
        rx_mem_free             :   natural range 0 to 2 ** 13 - 1;
        rx_write_pointer        :   natural range 0 to 2 ** 13 - 1;
        rx_read_pointer         :   natural range 0 to 2 ** 13 - 1;
        rx_full                 :   boolean;
        rx_empty                :   boolean;
        rx_frame_count          :   natural range 0 to 2 ** 11 - 1;
    end record;


    -- RX Buffer options
    type SW_RX_Buffer_options is record
        rx_time_stamp_options   :   boolean;
    end record;


    -- TXT Buffer priorities
    type SW_TXT_priority is record
        txt_buffer_1_priority   :   natural range 0 to 7;
        txt_buffer_2_priority   :   natural range 0 to 7;
        txt_buffer_3_priority   :   natural range 0 to 7;
        txt_buffer_4_priority   :   natural range 0 to 7;
    end record;

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    type SW_error_type is (
        can_err_bit,
        can_err_form,
        can_err_ack,
        can_err_crc,
        can_err_stuff        
    );
    
    type SW_error_position is (
        err_pos_sof,
        err_pos_arbitration,
        err_pos_ctrl,
        err_pos_data,
        err_pos_crc,
        err_pos_ack,
        err_pos_interframe_space,
        err_pos_err_frame,
        err_pos_overload_frame,
        err_pos_other
    );
    
    -- Error code capture data
    type SW_error_capture is record
        err_pos         : SW_error_position;
        err_type        : SW_error_type;
    end record;
292

293 294
    -- SSP (Secondary Sampling Point) configuration options
    type SSP_set_command_type is (
Martin Jeřábek's avatar
Martin Jeřábek committed
295
        ssp_meas_n_offset,
296
        ssp_no_ssp,
Martin Jeřábek's avatar
Martin Jeřábek committed
297
        ssp_offset
298
    );
299

300 301
    -- Protocol control Debug values
    type SW_PC_Debug is (
302
        pc_deb_none,
303
        pc_deb_sof,
304 305 306 307 308 309 310 311 312 313 314 315 316
        pc_deb_arbitration,
        pc_deb_control,
        pc_deb_data,
        pc_deb_stuff_count,
        pc_deb_crc,
        pc_deb_crc_delim,
        pc_deb_ack,
        pc_deb_ack_delim,
        pc_deb_eof,
        pc_deb_intermission,
        pc_deb_suspend,
        pc_deb_overload
    );
317

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
318 319 320 321
    ----------------------------------------------------------------------------
    -- Message filter types
    ----------------------------------------------------------------------------

Martin Jeřábek's avatar
Martin Jeřábek committed
322
    -- Frame information on input of message filter
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
323 324 325 326 327 328 329 330 331 332 333 334 335
    type mess_filter_input_type is record
        rec_ident_in            :   std_logic_vector(28 downto 0);
        ident_type              :   std_logic;
        frame_type              :   std_logic;
    end record;

    -- Driving bus values on the input off message filter
    type mess_filter_drv_type is record

        -- Filter A bit mask, control bits and bit value
        drv_filter_A_mask       :   std_logic_vector(28 downto 0);
        drv_filter_A_ctrl       :   std_logic_vector(3 downto 0);
        drv_filter_A_bits       :   std_logic_vector(28 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
336

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
337 338 339 340
        -- Filter B bit mask, control bits and bit value
        drv_filter_B_mask       :   std_logic_vector(28 downto 0);
        drv_filter_B_ctrl       :   std_logic_vector(3 downto 0);
        drv_filter_B_bits       :   std_logic_vector(28 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
341

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
342 343 344 345
        -- Filter C bit mask, control bits and bit value
        drv_filter_C_mask       :   std_logic_vector(28 downto 0);
        drv_filter_C_ctrl       :   std_logic_vector(3 downto 0);
        drv_filter_C_bits       :   std_logic_vector(28 downto 0);
Martin Jeřábek's avatar
Martin Jeřábek committed
346

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
347 348 349 350 351 352 353 354 355 356 357 358 359
        -- Range filter control bits, lower and upper thresholds
        drv_filter_ran_ctrl     :   std_logic_vector(3 downto 0);
        drv_filter_ran_lo_th    :   std_logic_vector(28 downto 0);
        drv_filter_ran_hi_th    :   std_logic_vector(28 downto 0);

        -- Filters are enabled
        drv_filters_ena         :   std_logic;

    end record;

    ----------------------------------------------------------------------------
    -- Prescaler types
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
360

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
361 362
    -- Driving bus settings for prescaler
    type presc_drv_type is record
Martin Jeřábek's avatar
Martin Jeřábek committed
363

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
364 365 366 367 368 369 370 371 372 373 374 375 376
        -- Time quanta (Nominal and Data)
        drv_tq_nbt              :   std_logic_vector (7 downto 0);
        drv_tq_dbt              :   std_logic_vector (7 downto 0);

        -- Propagation segment (Nominal and Data)
        drv_prs_nbt             :   std_logic_vector (6 downto 0);
        drv_prs_dbt             :   std_logic_vector (5 downto 0);

        -- Phase 1 segment (Nominal and Data)
        drv_ph1_nbt             :   std_logic_vector (5 downto 0);
        drv_ph1_dbt             :   std_logic_vector (4 downto 0);

        -- Phase 2 segment (Nominal and Data)
Martin Jeřábek's avatar
Martin Jeřábek committed
377 378
        drv_ph2_nbt             :   std_logic_vector (5 downto 0);
        drv_ph2_dbt             :   std_logic_vector (4 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
379 380 381 382 383 384 385 386 387

        -- Synchronisation jump width (Nominal and Data)
        drv_sjw_nbt             :   std_logic_vector(4 downto 0);
        drv_sjw_dbt             :   std_logic_vector(4 downto 0);

    end record;

    -- Triggering signals joined to single record
    type presc_triggers_type is record
Martin Jeřábek's avatar
Martin Jeřábek committed
388

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
        -- Sample signal (Nominal and Data)
        -- (Used for bus sampling)
        sample_nbt              :   std_logic;
        sample_dbt              :   std_logic;

        -- Sample signal delayed by one clock cycle (Nominal and Data)
        -- (Used for Bit destuffing)
        sample_nbt_del_1        :   std_logic;
        sample_dbt_del_1        :   std_logic;

        -- Synchronisation signal
        -- (Used to transmitt data)
        sync_nbt                :   std_logic;
        sync_dbt                :   std_logic;
    end record;


    ----------------------------------------------------------------------------
    -- TXT Buffer types
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
409

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
410 411 412 413 414 415 416 417 418 419
    -- TXT Buffer state (used in test access, not in synthesizable code)
    type SW_TXT_Buffer_state_type is (
        buf_empty,
        buf_ready,
        buf_tx_progress,
        buf_ab_progress,
        buf_aborted,
        buf_failed,
        buf_done
    );
420

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
    -- TXT Buffer commands (used in test access, not synthesizable code)
    type SW_TXT_Buffer_command_type is (
        buf_set_empty,
        buf_set_ready,
        buf_set_abort
    );


    ----------------------------------------------------------------------------
    -- Avalon memory interface type
    ----------------------------------------------------------------------------
    type Avalon_mem_type is record
        clk_sys                 :   std_logic;
        data_in                 :   std_logic_vector(31 downto 0);
        data_out                :   std_logic_vector(31 downto 0);
436
        address                 :   std_logic_vector(31 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
437 438 439
        scs                     :   std_logic;
        swr                     :   std_logic;
        srd                     :   std_logic;
440
        sbe                     :   std_logic_vector(3 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
    end record;


    ----------------------------------------------------------------------------
    -- Main Bus timing configuration type used in feature and sanity tests
    -- (using "naturals" instead of std_logic_vector)
    ----------------------------------------------------------------------------
    type bit_time_config_type is record
         tq_nbt                 :   natural;
         tq_dbt                 :   natural;
         prop_nbt               :   natural;
         ph1_nbt                :   natural;
         ph2_nbt                :   natural;
         sjw_nbt                :   natural;
         prop_dbt               :   natural;
         ph1_dbt                :   natural;
         ph2_dbt                :   natural;
         sjw_dbt                :   natural;
    end record;


462 463
    type SW_CAN_data_type is array (0 to 63) of std_logic_vector(7 downto 0);

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
464 465 466 467 468 469 470 471 472 473 474
    ----------------------------------------------------------------------------
    -- Software CAN Frame type. Used for generation, transmission, reception,
    -- comparison of CAN Frames.
    ----------------------------------------------------------------------------
    type SW_CAN_frame_type is record

        -- CAN Identifier. Decimal value. Note that the value differs for
        -- BASE and EXTENDED Identifiers!
        identifier              :   natural;

        -- Data payload
475
        data                    :   SW_CAN_data_type;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494

        -- Data length code as defined in CAN Standard
        dlc                     :   std_logic_vector(3 downto 0);

        -- Data length in bytes
        data_length             :   natural range 0 to 64;

        -- Identifier type (0 - BASE Format, 1 - Extended Format);
        ident_type              :   std_logic;

        -- Frame type (0 - Normal CAN, 1 - CAN FD)
        frame_format            :   std_logic;

        -- RTR Flag (0 - No RTR Frame, 1 - RTR Frame)
        rtr                     :   std_logic;

        -- Bit rate shift flag
        brs                     :   std_logic;

495 496 497
        -- ESI Flag (Error state indicator)
        esi                     :   std_logic;

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
498 499 500 501 502 503 504 505 506 507 508
        -- Timestamp (as defined in TIMESTAMP_U_W and TIMESTAMP_L_W)
        timestamp               :   std_logic_vector(63 downto 0);

        -- Receive word count field as stored in RX Buffer FRAME_FORM_W.
        -- Indicates number of 32 bit words which Frame ocupies in RX Buffer
        -- without FRAME_FORM_W.
        -- Note that this value is valid only for received frames and has
        -- no meaning in TXT Buffer.
        rwcnt                   :   natural;
    end record;

509 510 511 512

    type SW_CAN_mask_filter_type is (
        filter_A,
        filter_B,
Martin Jeřábek's avatar
Martin Jeřábek committed
513
        filter_C
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
    );


    type SW_CAN_mask_filter_config is record
        ID_value                :   natural;
        ID_mask                 :   natural;
        ident_type              :   std_logic;
        acc_CAN_2_0             :   boolean;
        acc_CAN_FD              :   boolean;
    end record;


    type SW_CAN_range_filter_config is record
        ID_th_low               :   natural;
        ID_th_high              :   natural;
Martin Jeřábek's avatar
Martin Jeřábek committed
529
        ident_type              :   std_logic;
530 531 532 533 534
        acc_CAN_2_0             :   boolean;
        acc_CAN_FD              :   boolean;
    end record;


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
535 536 537 538 539 540 541 542 543 544 545
    ----------------------------------------------------------------------------
    -- Transceiver delay type
    ----------------------------------------------------------------------------
    type tran_delay_type is record
        tx_delay_sr             :   std_logic_vector(255 downto 0);
        rx_delay_sr             :   std_logic_vector(255 downto 0);
        tx_point                :   std_logic;
        rx_point                :   std_logic;
    end record;


546 547 548 549 550
    ----------------------------------------------------------------------------
    -- Test storage memory
    ----------------------------------------------------------------------------
    type test_mem_type is array (0 to 255) of std_logic_vector(31 downto 0);

Martin Jeřábek's avatar
Martin Jeřábek committed
551 552 553 554 555 556 557 558
    ----------------------------------------------------------------------------
    -- Clock params
    ----------------------------------------------------------------------------
    type generate_clock_precomputed_t is record
        low_time : time;
        high_time : time;
    end record;

559 560 561
    ----------------------------------------------------------------------------
    -- Bit sequence generator
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
562

563 564 565 566 567 568 569 570 571 572 573 574 575 576
    -- Longest possible CAN FD Frame is aroud 700 bits. If each bit has opposite
    -- polarity than previous one, this could use up to 700 entries. Have some
    -- reserve...
    constant BS_MAX_LENGTH      :   natural := 1024;

    type bs_durations_type is array (1 to BS_MAX_LENGTH) of natural;
    type bs_values_type is array (1 to BS_MAX_LENGTH) of std_logic;

    type bit_seq_type is record
        bit_durations           :   bs_durations_type;
        bit_values              :   bs_values_type;
        length                  :   natural;
    end record;

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
577 578 579 580 581 582 583 584 585

    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    -- Constants
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    constant f100_MHZ           :   natural := 10000;


586 587 588 589 590 591 592 593 594 595 596 597 598 599
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    -- sanity test Stuff; must be in a package
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    constant NODE_COUNT : natural := 4;
    type bus_matrix_type is array(1 to NODE_COUNT, 1 to NODE_COUNT) of real;
    type anat_t is array (integer range <>) of natural;
    subtype anat_nc_t is anat_t (1 to NODE_COUNT);

    subtype epsilon_type is anat_nc_t;
    subtype trv_del_type is anat_nc_t;
    subtype timing_config_t is anat_t(1 to 10);

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
600 601 602 603 604 605 606

    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    -- Functions definitions
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------

Martin Jeřábek's avatar
Martin Jeřábek committed
607

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
608 609 610 611 612 613 614 615 616
    ----------------------------------------------------------------------------
    -- Function called at the end of the test which evaluates results of test.
    -- If Error threshold is bigger than number of errors which ocurred in the
    -- test, test status will be updated to "passed", if not, test status will
    -- be updated to "failed". After the evaluation test simulation is finished.
    --
    -- Arguments:
    --  error_th        Error threshold.
    --  errors          Number of errors which occurred in the test
Martin Jeřábek's avatar
Martin Jeřábek committed
617
    --  status          Status to be updated
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
618 619
    ----------------------------------------------------------------------------
    procedure evaluate_test(
Martin Jeřábek's avatar
Martin Jeřábek committed
620 621 622
        constant error_th         : in    natural;
        constant errors           : in    natural;
        signal   status           : out   test_status_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
623 624 625
    );


626 627 628 629 630 631
    ----------------------------------------------------------------------------
    -- Set highest loglevel that should be shown.
    -- Log levels are connected to CAN_test as input signals and driven by
    -- VUnit from configuration.
    --
    -- Log levels are bound to Vunit Logging library:
632 633
    --  debug_l   - All logs are shown (even pass and trace)
    --  info_l    - info(), warning(), error(), failure() are shown
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
    --  warning_l - warning(), error(), failure() are shown
    --  error_l   - error(), failure() are shown
    --
    -- Default VUnit logger is used.
    --
    -- Arguments:
    --  log_level        Severity level which is set in current test.
    ----------------------------------------------------------------------------
    procedure set_log_level(
          constant log_level      : in    log_lvl_type
    );


    ---------------------------------------------------------------------------
    -- Configure error behaviour (Quit / Go On) of Vunit.
    --
    -- Arguments:
    --  log_level        Severity level which is set in current test.
    ----------------------------------------------------------------------------
    procedure set_error_beh(
          constant error_beh      : in    err_beh_type
    );
Martin Jeřábek's avatar
Martin Jeřábek committed
656

657

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
658 659 660 661 662
    ----------------------------------------------------------------------------
    -- Generates clock signal for the test with custom period, duty cycle and
    -- clock jitter.
    --
    -- Arguments:
Martin Jeřábek's avatar
Martin Jeřábek committed
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
    --  par             Precomputed parameters.
    --  out_clk         Generated clock.
    ----------------------------------------------------------------------------
    procedure generate_clock(
        constant par            : in    generate_clock_precomputed_t;
        signal   out_clk        : out   std_logic
    );

    -- deprecated compatibility wrapper (lower performance)
    procedure generate_clock(
        constant period         : in    natural;
        constant duty           : in    natural;
        constant epsilon_ppm    : in    natural;
        signal   out_clk        : out   std_logic
    );

    ----------------------------------------------------------------------------
    -- Combinatorial procedure, which infinitely generates clock signal.
    --
    -- Arguments:
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
683 684 685 686 687
    --  period          Period of generated clock in picoseconds.
    --  duty            Duty cycle of generated clock in percents.
    --  epsilon_ppm     Clock uncertainty (jitter) which is always added to the
    --                  default clock period.
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
688
    procedure clock_gen_proc(
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
689 690 691 692 693 694 695
        constant period         : in    natural;
        constant duty           : in    natural;
        constant epsilon_ppm    : in    natural;
        signal   out_clk        : out   std_logic
    );


Martin Jeřábek's avatar
Martin Jeřábek committed
696 697 698 699 700 701 702 703 704
    ----------------------------------------------------------------------------
    -- Combinatorial procedure, which infinitely generates timestamp.
    --
    -- Arguments:
    --  clk             Input clock.
    --  timestamp       Output timestamp counter.
    ----------------------------------------------------------------------------
    procedure timestamp_gen_proc(
        signal     clk           : in    std_logic;
705 706 707
        signal     timestamp     : out   std_logic_vector(63 downto 0);
        signal     ts_preset     : in    std_logic;
        signal     ts_preset_val : in    std_logic_vector(63 downto 0)
Martin Jeřábek's avatar
Martin Jeřábek committed
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
    );


    ----------------------------------------------------------------------------
    -- Precompute constants for clock signal generation for the test with
    -- custom period, duty cycle and clock jitter.
    --
    -- Arguments:
    --  period          Period of generated clock in picoseconds.
    --  duty            Duty cycle of generated clock in percents.
    --  epsilon_ppm     Clock uncertainty (jitter) which is always added to the
    --                  default clock period.
    -- Returns: precomputed params
    ----------------------------------------------------------------------------
    function precompute_clock(
        constant period         : in    natural;
        constant duty           : in    natural;
        constant epsilon_ppm    : in    natural
    ) return generate_clock_precomputed_t;

728

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
    ----------------------------------------------------------------------------
    -- Asserts reset signal to restart the operated circuit. Then waits until
    -- run condition signal becomes "true" and sets test status to "running" and
    -- sets error counter to 0. Finally, deasserts reset signal.
    --
    -- Arguments:
    --  res_n           Reset signal (active low).
    --  status          Test status to assert "running".
    --  run             Run condition to wait until comes true.
    --  error_ctr       Error counter to erase.
    ----------------------------------------------------------------------------
    procedure reset_test(
        signal res_n            : out   std_logic;
        signal status           : out   test_status_type;
        signal run              : in    boolean;
        signal error_ctr        : out   natural
    );


    ----------------------------------------------------------------------------
    -- Process error ocurrence in the test. This consists of following steps:
    --  1. Increment error counter
    --  2. If Error behaviour is "quit", assert Immediate exit flag to "true".
    --     Otherwise assert Immediate exit flag to "false".
Martin Jeřábek's avatar
Martin Jeřábek committed
753
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
754 755 756 757 758 759
    -- Arguments:
    --  error_ctr       Error counter to increment.
    --  error_beh       Error behaviour to evaluate.
    --  exit_imm        Immediate exit flag to assert.
    ----------------------------------------------------------------------------
    procedure process_error(
Martin Jeřábek's avatar
Martin Jeřábek committed
760 761 762
        signal   error_ctr      : inout natural;
        constant error_beh      : in    err_beh_type;
        signal   exit_imm       : out   boolean
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
763 764 765 766 767
    );


    ----------------------------------------------------------------------------
    -- Print basic testbench information.
Martin Jeřábek's avatar
Martin Jeřábek committed
768
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
769 770 771 772 773 774 775
    -- Arguments:
    --  iterations      Number of iterations to execute in test.
    --  log_level       Severity level which is set in actual frame.
    --  error_beh       Error behaviour of test.
    --  error_tol       Error tolerance of test.
    ----------------------------------------------------------------------------
    procedure print_test_info(
Martin Jeřábek's avatar
Martin Jeřábek committed
776 777 778 779
        constant iterations     : in    natural;
        constant log_level      : in    log_lvl_type;
        constant error_beh      : in    err_beh_type;
        constant error_tol      : in    natural
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
780 781 782
    );


783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
    ----------------------------------------------------------------------------
    -- Sets random counter based on the seed that was given. To differentiate
    -- individual counters, fixed offset can be added.
    --
    -- Arguments:
    --  seed            Random seed input.
    --  offset          Offset of counter
    --  rand_ctr        Random counter to set.
    ----------------------------------------------------------------------------
    procedure apply_rand_seed(
        constant seed            : in   natural;
        constant offset          : in   natural;
        signal   rand_ctr        : out  natural range 0 to RAND_POOL_SIZE
    );


799
    -- variation of above, only returns the seed value
800
    impure function apply_rand_seed(
801 802 803 804
        constant seed            : in   natural;
        constant offset          : in   natural
    ) return natural;

805

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
806 807 808
    ----------------------------------------------------------------------------
    -- Decode data length code from value as defined in CAN FD Standard to
    -- length of frame in bytes.
Martin Jeřábek's avatar
Martin Jeřábek committed
809
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
810 811
    -- Arguments:
    --  dlc             Data length code as received or transmitted.
Martin Jeřábek's avatar
Martin Jeřábek committed
812
    --  length          Length of CAN Frame in bytes
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
813 814 815 816 817 818 819 820 821 822 823
    ----------------------------------------------------------------------------
    procedure decode_dlc(
        constant dlc            : in    std_logic_vector(3 downto 0);
        variable length         : out   natural
    );


    ----------------------------------------------------------------------------
    -- Decode Read word count value as present in FRAME_FORMAT_W of RX Buffer
    -- from DLC. Read word count value indicates how many 32-bit words will the
    -- buffer occupy in RX Buffer without Frame Format word.
Martin Jeřábek's avatar
Martin Jeřábek committed
824
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
825 826 827 828 829 830 831 832 833 834
    -- Arguments:
    --  dlc             Data length code to decode as transmitted or received.
    --  rwcnt           Read word count value.
    ----------------------------------------------------------------------------
    procedure decode_dlc_rx_buff(
        constant dlc            : in    std_logic_vector(3 downto 0);
        variable rwcnt          : out   natural
    );


835 836 837 838 839 840 841 842 843 844 845 846 847
	----------------------------------------------------------------------------
    -- Decode length do DLC code.
    --
    -- Arguments:
    --  length          Data lenght in bytes.
    --  dlc				Variable where output Data lenght code  will be stored.
    ----------------------------------------------------------------------------
	procedure decode_length(
		constant length			: in	natural;
		variable dlc			: out	std_logic_vector(3 downto 0)
	);


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
848 849 850
    ----------------------------------------------------------------------------
    -- Decode number of 32-bit words CAN Frame will occupy in RX Buffer
    -- (together with Frame format word).
Martin Jeřábek's avatar
Martin Jeřábek committed
851
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
852 853 854 855 856
    -- Arguments:
    --  dlc             Data length code to decode as transmitted or received.
    --  buff_space      Number of 32-bit words.
    ----------------------------------------------------------------------------
    procedure decode_dlc_buff(
Martin Jeřábek's avatar
Martin Jeřábek committed
857
        constant dlc            : in    std_logic_vector(3 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
858 859
        variable buff_space     : out   natural
    );
Martin Jeřábek's avatar
Martin Jeřábek committed
860

861

862 863 864
    ----------------------------------------------------------------------------
    -- Convert identifier from register format (as stored in IDENTIFIER_W of
    --  TXT Buffers and RX Buffer) to integer value as used by SW.
Martin Jeřábek's avatar
Martin Jeřábek committed
865
    --
866 867 868 869 870 871 872 873 874 875 876 877 878
    -- Arguments:
    --  identifier      Input identifier as stored in IDENTIFIER_W
    --  id_type         Type of identifier (BASE or EXTENDED)
    --  out             Identifier in integer format
    ----------------------------------------------------------------------------
    procedure id_hw_to_sw(
        constant id_in          : in    std_logic_vector(28 downto 0);
        constant id_type        : in    std_logic;
        variable id_out         : out   natural
    );


    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
879
    -- Convert identifier from SW format to register format (as stored in
880
    --  IDENTIFIER_W of TXT Buffers and RX Buffer).
Martin Jeřábek's avatar
Martin Jeřábek committed
881
    --
882 883 884 885 886 887 888 889 890 891 892 893
    -- Arguments:
    --  identifier      Input identifier in integer format (as used by SW).
    --  id_type         Type of identifier (BASE or EXTENDED)
    --  out             Identifier in register format as stored in IDENTIFIER_W.
    ----------------------------------------------------------------------------
    procedure id_sw_to_hw(
        constant id_in          : in    natural;
        constant id_type        : in    std_logic;
        variable id_out         : out   std_logic_vector(28 downto 0)
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
894 895 896
    ----------------------------------------------------------------------------
    -- Generate simple triggering signals.
    -- Two signals are generated, "sync" and "sample". No bit rate switch is
Martin Jeřábek's avatar
Martin Jeřábek committed
897 898 899
    -- implemented in this procedure. There is random amount of clock cycles
    -- between sync and sample, but not less than "min_diff" and not more than
    -- 10 clock cycles! "min_diff" is intended for determining how many clock
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
900
    -- cycles each circuit needs between bit transmittion and reception!
Martin Jeřábek's avatar
Martin Jeřábek committed
901
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
    -- Arguments:
    --  rand_ctr        Pointer to random pool.
    --  sync            Synchronisation trigger (for transmission)
    --  sample          Sampling trigger (for reception)
    --  clk_sys         Clock signal
    --  min_diff        Minimal gap (in clock cycles) between sync and sample
    --                  signals.
    ----------------------------------------------------------------------------
    procedure generate_simple_trig(
        signal   rand_ctr       : inout natural range 0 to RAND_POOL_SIZE;
        signal   sync           : out   std_logic;
        signal   sample         : out   std_logic;
        signal   clk_sys        : in    std_logic;
        variable min_diff       : in    natural
    );


    procedure generate_trig(
        signal    sync          : out   std_logic;
        signal    sample        : out   std_logic;
        signal    clk_sys       : in    std_logic;
        signal    seg1          : in    natural;
        signal    seg2          : in    natural
    );
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
    
    ---------------------------------------------------------------------------
    -- Force bus level to given value. Applicable in feature tests testbench.
    --
    -- Arguments:
    --  bus_val     Value to be forced
    --  bl_force    Force bus level signal.
    --  bl_inject   Force bus level value.
    ---------------------------------------------------------------------------
    procedure force_bus_level(
        constant value           : in    std_logic;
        signal   bl_force        : out   boolean;
        signal   bl_inject       : out   std_logic
    );

    ---------------------------------------------------------------------------
    -- Release bus level.
    --
    -- Arguments:
    --  bl_force    Bus level force signal
    ---------------------------------------------------------------------------
    procedure release_bus_level(
        signal  bl_force        : out   boolean
    );
Martin Jeřábek's avatar
Martin Jeřábek committed
950

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
951 952 953 954 955 956

    ----------------------------------------------------------------------------
    -- Memory access routines
    ----------------------------------------------------------------------------

    ----------------------------------------------------------------------------
957 958
    -- Execute write access on Avalon memory bus. Does not support unaligned
    -- accesses.
Martin Jeřábek's avatar
Martin Jeřábek committed
959
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
960 961 962
    -- Arguments:
    --  w_data          Data to write.
    --  w_address       Address where to write the data
963
    --  w_size          Size of the access (8 Bit, 16 bit or 32 bit)
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
964 965 966 967
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure aval_write(
        constant  w_data        : in    std_logic_vector(31 downto 0);
968
        constant  w_address     : in    std_logic_vector;
969
        constant  w_size        : in    aval_access_size;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
970 971 972 973 974
        signal    mem_bus       : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
975 976
    -- Execute read access on Avalon memory bus. Does not supports unaligned
    -- accesses.
Martin Jeřábek's avatar
Martin Jeřábek committed
977
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
978 979 980
    -- Arguments:
    --  r_data          Variable in which Read data will be returned.
    --  r_address       Address to read the data from.
981
    --  r_size          Size of the access (8 Bit, 16 bit or 32 bit)
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
982 983 984 985
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure aval_read(
        variable  r_data        : out   std_logic_vector(31 downto 0);
986
        constant  r_address     : in    std_logic_vector;
987
        constant  r_size        : in    aval_access_size;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
988 989 990 991
        signal    mem_bus       : inout Avalon_mem_type
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
992
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
993
    -- Execute write access on Avalon memory bus via Avalon burst.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
    -- Does not support unaligned accesses. Size of the burst is given by
    -- length of "w_data".
    --
    -- Arguments:
    --  w_data          Data to write (Little endian)
    --  w_address       Address where to start write burst.
    --  stat_burst      True for "stationary" burst where address should not
    --                  be incremented during the burst!
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure aval_write_burst(
        constant  w_data        : in    std_logic_vector;
1006
        constant  w_address     : in    std_logic_vector;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1007 1008 1009 1010 1011 1012
        constant  stat_burst    : in    boolean := false;
        signal    mem_bus       : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
1013
    -- Execute read access on Avalon memory bus via Avalon burst.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
    -- Does not support unaligned accesses. Size of the burst is given by
    -- length of "r_data".
    --
    -- Arguments:
    --  r_data          Data to be read(Little endian)
    --  w_address       Address where to start write burst.
    --  stat_burst      True for "stationary" burst where address should not
    --                  be incremented during the burst!
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure aval_read_burst(
        variable  r_data        : out   std_logic_vector;
1026
        constant  r_address     : in    std_logic_vector;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1027 1028 1029 1030 1031
        constant  stat_burst    : in    boolean := false;
        signal    mem_bus       : inout Avalon_mem_type
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1032
    ----------------------------------------------------------------------------
1033
    -- Execute write access to CTU CAN FD Core over Avalon Bus. If size is not
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1034 1035
    -- specified, 32 bit access is executed. If input data size is other than
    -- 32 bits, burst access is executed.
1036 1037
    --
    -- Address bits meaning is following:
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1038 1039 1040
    --  [15:12]     Identifier (Index) of core. Allows to distinguish between
    --              up to 16 instances of CTU CAN FD Core.
    --  [11:0]      Register or Buffer offset within a the core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1041
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1042 1043 1044 1045 1046
    -- Arguments:
    --  w_data          Data to write to CTU CAN FD Core.
    --  w_offset        Register or buffer offset (bits 11:0).
    --  ID              Index of CTU CAN FD Core instance (bits 15:12)
    --  mem_bus         Avalon memory bus to execute the access on.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1047 1048
    --  stat_burst      If Burst access is executed, address should not be
    --                  incremented during the burst.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1049 1050
    ----------------------------------------------------------------------------
    procedure CAN_write(
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1051
        constant  w_data        : in    std_logic_vector;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1052 1053
        constant  w_offset      : in    std_logic_vector(11 downto 0);
        constant  ID            : in    natural range 0 to 15;
1054
        signal    mem_bus       : inout Avalon_mem_type;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1055 1056
        constant  w_size        : in    aval_access_size := BIT_32;
        constant  stat_burst    : in    boolean := false
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1057 1058 1059 1060
    );


    ----------------------------------------------------------------------------
1061
    -- Execute read access from CTU CAN FD Core over Avalon Bus. If size is not
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1062 1063
    -- specified, 32 bit access is executed. If input data size is other than
    -- 32 bits, burst access is executed.
1064 1065
    --
    -- Address bits meaning is following:
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1066 1067 1068
    --  [15:12]     Identifier (Index) of core. Allows to distinguish between
    --              up to 16 instances of CTU CAN FD Core.
    --  [11:0]      Register or Buffer offset within a the core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1069
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1070 1071 1072 1073 1074
    -- Arguments:
    --  r_data          Variable in which Read data will be returned.
    --  r_offset        Register or buffer offset (bits 11:0).
    --  ID              Index of CTU CAN FD Core instance (bits 15:12)
    --  mem_bus         Avalon memory bus to execute the access on.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1075 1076
    --  stat_burst      If Burst access is executed, address should not be
    --                  incremented during the burst.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1077 1078
    ----------------------------------------------------------------------------
    procedure CAN_read(
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1079
        variable  r_data        : out   std_logic_vector;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1080 1081
        constant  r_offset      : in    std_logic_vector(11 downto 0);
        constant  ID            : in    natural range 0 to 15;
1082
        signal    mem_bus       : inout Avalon_mem_type;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1083 1084
        constant  r_size        : in    aval_access_size := BIT_32;
        constant  stat_burst    : in    boolean := false
Martin Jeřábek's avatar
Martin Jeřábek committed
1085
    );
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1086 1087


1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    -- CAN feauture TB configuration routines
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    
    -- Signals for feature test intialization
    
    type t_ftr_tx_delay is array (1 to 2) of time;
    
    ----------------------------------------------------------------------------
    -- Configure transmitter delay in feature TB.
    --
    -- Arguments:
    --  tx_del          Delay to be set
    --  ID              ID of the node where delay shall be set.
1104
    --  actual_delay    Delay signal to force
1105 1106 1107 1108 1109 1110
    ----------------------------------------------------------------------------
    procedure ftr_tb_set_tran_delay(
        constant tx_del         : in    time;
        constant ID             : in    natural range 0 to 15;
        signal   actual_delay   : out   t_ftr_tx_delay
    );
1111

1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
    ----------------------------------------------------------------------------
    -- Configure timestamp in feature TB.
    --
    -- Arguments:
    --  ts_value        Value to be forced to timestamp.
    --  ID              ID of the node where delay shall be set.
    --  ts_preset       Vector controlling presetting.
    --  ts_preset_val   Value controlling presetting.
    ----------------------------------------------------------------------------
    procedure ftr_tb_set_timestamp(
        constant ts_value       : in    std_logic_vector(63 downto 0);
        constant ID             : in    natural range 0 to 15;
        signal   ts_preset      : out   std_logic_vector;
        signal   ts_preset_val  : out   std_logic_vector(63 downto 0)
    );


1129

1130
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1131 1132
    ----------------------------------------------------------------------------
    -- CAN configuration routines
1133
    ----------------------------------------------------------------------------
1134
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
1135

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1136 1137 1138
    ----------------------------------------------------------------------------
    -- Configure Bus timing on CTU CAN FD Core.
    -- (duration of bit phases, synchronisation jump width, baud-rate prescaler)
Martin Jeřábek's avatar
Martin Jeřábek committed
1139
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1140 1141 1142 1143 1144 1145 1146 1147
    -- Arguments:
    --  bus_timing      Bus timing structure that contains timing configuration
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_configure_timing(
        constant bus_timing     : in    bit_time_config_type;
        constant ID             : in    natural range 0 to 15;
Martin Jeřábek's avatar
Martin Jeřábek committed
1148
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1149 1150 1151 1152 1153 1154
    );


    ----------------------------------------------------------------------------
    -- Read Bus timing configuration from CTU CAN FD Core.
    -- (duration of bit phases, synchronisation jump width, baud-rate prescaler)
Martin Jeřábek's avatar
Martin Jeřábek committed
1155
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1156 1157 1158 1159 1160 1161 1162 1163 1164
    -- Arguments:
    --  bus_timing      Bus timing structure that will be filled by timing
    --                  configuration.
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_read_timing(
        signal   bus_timing     : out   bit_time_config_type;
        constant ID             : in    natural range 0 to 15;
Martin Jeřábek's avatar
Martin Jeřábek committed
1165
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1166 1167
    );

1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
    ----------------------------------------------------------------------------
    -- Read Bus timing configuration from CTU CAN FD Core.
    -- (duration of bit phases, synchronisation jump width, baud-rate prescaler)
    --
    -- Arguments:
    --  bus_timing      Bus timing structure that will be filled by timing
    --                  configuration.
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_read_timing_v(
        variable bus_timing     : out   bit_time_config_type;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );

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

1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
    ----------------------------------------------------------------------------
    -- Print Bus timing configuration of CTU CAN FD Core.
    -- (duration of bit phases, synchronisation jump width, baud-rate prescaler)
    --
    -- Arguments:
    --  bus_timing      Bus timing structure that will be printed in simulator.
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_print_timing(
        constant   bus_timing     : in   bit_time_config_type
    );


    ----------------------------------------------------------------------------
    -- Print Bus matrix from sanity test configuration.
    --
    -- Arguments:
    --  bus_matrix      Bus Matrix to be printed.
    ----------------------------------------------------------------------------
    procedure CAN_print_bus_matrix(
        constant   bus_matrix     : in   bus_matrix_type
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1210 1211
    ----------------------------------------------------------------------------
    -- Turn on/off CTU_CAN_FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1212
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1213 1214 1215 1216 1217 1218 1219 1220
    -- Arguments:
    --  turn_on         Turns on the Core when "true". Turns off otherwise.
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_turn_controller(
        constant turn_on        : in    boolean;
        constant ID             : in    natural range 0 to 15;
Martin Jeřábek's avatar
Martin Jeřábek committed
1221
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1222 1223 1224 1225 1226
    );


    ----------------------------------------------------------------------------
    -- Enables/Disabled Retransmitt limiting in CTU CAN FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1227