CANtestLib.vhd 150 KB
Newer Older
1
--------------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
2
--
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
3 4
-- CTU CAN FD IP Core
-- Copyright (C) 2015-2018 Ondrej Ille <ondrej.ille@gmail.com>
Martin Jeřábek's avatar
Martin Jeřábek committed
5 6
--
-- Project advisors and co-authors:
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
7 8 9
-- 	Jiri Novak <jnovak@fel.cvut.cz>
-- 	Pavel Pisa <pisa@cmp.felk.cvut.cz>
-- 	Martin Jerabek <jerabma7@fel.cvut.cz>
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
10 11 12
-- 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
13 14 15 16 17 18
--
-- 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
19
-- Component is furnished to do so, subject to the following conditions:
Martin Jeřábek's avatar
Martin Jeřábek committed
20 21
--
-- The above copyright notice and this permission notice shall be included in
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
22
-- all copies or substantial portions of the Component.
Martin Jeřábek's avatar
Martin Jeřábek committed
23 24 25 26 27
--
-- 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
28
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Martin Jeřábek's avatar
Martin Jeřábek committed
29
-- FROM, OUT OF OR IN CONNECTION WITH THE COMPONENT OR THE USE OR OTHER DEALINGS
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
30
-- IN THE COMPONENT.
Martin Jeřábek's avatar
Martin Jeřábek committed
31 32 33
--
-- 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
34
-- protocol license from Bosch.
Martin Jeřábek's avatar
Martin Jeřábek committed
35
--
36 37
--------------------------------------------------------------------------------

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
38
--------------------------------------------------------------------------------
39
--  Purpose:
Martin Jeřábek's avatar
Martin Jeřábek committed
40
--    Main test library for CTU CAN FD controller. Contains all test resources
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
41 42 43 44 45
--    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.
46
--
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
47
--------------------------------------------------------------------------------
48 49
-- Revision History:
--    27.5.2016   Created file
Martin Jeřábek's avatar
Martin Jeřábek committed
50 51
--    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
52 53 54 55
--                (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
56
--                cycles till the reset is synchronised and deasserted.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
57 58
--    06.02.2018  Modified the library to work with generated constants from the
--                8 bit register map generated from IP-XACT.
59
--    09.02.2018  Added support fow RWCNT field in the SW_CAN_Frame.
Martin Jeřábek's avatar
Martin Jeřábek committed
60
--    15.02.2018  Added support for TXT Buffer commands in CAN Send frame
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
61 62 63
--                procedure.
--    23.02.2018  Corrected "CAN_generate_frame" function for proper placement
--                of BASE identifier to unsigned value.
64 65 66
--     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.
67
--      7.6.2018  Added "CAN_insert_TX_frame" procedure.
Martin Jeřábek's avatar
Martin Jeřábek committed
68
--     18.6.2018  Added optimized clock_gen_proc, timestamp_gen_proc procedures.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
69
--------------------------------------------------------------------------------
70

71 72 73
Library ieee;
USE IEEE.std_logic_1164.all;
USE IEEE.numeric_std.ALL;
74 75
use STD.textio.all;
use IEEE.std_logic_textio.all;
76 77 78 79
USE ieee.math_real.ALL;
USE work.randomLib.All;
use work.CANconstants.all;

80
use work.CAN_FD_register_map.all;
81
use work.CAN_FD_frame_format.all;
82 83 84

package CANtestLib is

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    -- Types
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------

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

    -- Logger severity type (severities in increasing order)
    type log_lvl_type is (
        info_l,
        warning_l,
        error_l
    );
101

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
102 103 104 105 106
    -- Behaviour of the test when error occurs
    type err_beh_type is (
        quit,
        go_on
    );
107

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
108 109 110 111 112 113
    -- Status of test
    type test_status_type is (
        waiting,
        running,
        passed,
        failed
114
    );
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
115 116


117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    ----------------------------------------------------------------------------
    -- 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
133

134 135 136 137 138 139 140 141 142 143
    -- Controller modes
    type SW_mode is record
        reset                   :   boolean;
        listen_only             :   boolean;
        self_test               :   boolean;
        acceptance_filter       :   boolean;
        flexible_data_rate      :   boolean;
        rtr_pref                :   boolean;
        tripple_sampling        :   boolean;
        acknowledge_forbidden   :   boolean;
144 145
        internal_loopback       :   boolean;
        iso_fd_support          :   boolean;
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    end record;


    -- Controller commands
    type SW_command is record
        abort_transmission      :   boolean;
        release_rec_buffer      :   boolean;
        clear_data_overrun      :   boolean;
    end record;


    -- Controller status
    type SW_status is record
        receive_buffer          :   boolean;
        data_overrun            :   boolean;
161
        tx_buffer_empty         :   boolean;
162 163 164 165 166 167 168 169
        error_transmission      :   boolean;
        receiver                :   boolean;
        transmitter             :   boolean;
        error_warning           :   boolean;
        bus_status              :   boolean;
    end record;


170
    -- Interrupt sources
171 172 173 174 175 176 177 178 179 180 181 182 183
    type SW_interrupts is record
        receive_int             :   boolean;
        transmitt_int           :   boolean;
        error_warning_int       :   boolean;
        data_overrun_int        :   boolean;
        error_passive_int       :   boolean;
        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
184
    end record;
185 186 187 188 189 190 191 192

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

193 194 195 196 197
    -- Fault confinement state thresholds
    type SW_fault_thresholds is record
        ewl                     :   natural range 0 to 255;
        erp                     :   natural range 0 to 255;
    end record;
198

199
    -- Error counters (Normal and Special)
200 201 202 203 204 205 206 207
    type SW_error_counters is record
        rx_counter              :   natural range 0 to 2 ** 16 - 1;
        tx_counter              :   natural range 0 to 2 ** 16 - 1;
        err_norm                :   natural range 0 to 2 ** 16 - 1;
        err_fd                  :   natural range 0 to 2 ** 16 - 1;
    end record;


208 209 210 211 212 213 214
    -- Traffic counters
    type SW_traffic_counters is record
        rx_frames               :   natural;
        tx_frames               :   natural;
    end record;


215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
    -- 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;




Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
244 245 246 247
    ----------------------------------------------------------------------------
    -- Message filter types
    ----------------------------------------------------------------------------

Martin Jeřábek's avatar
Martin Jeřábek committed
248
    -- Frame information on input of message filter
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
249 250 251 252
    type mess_filter_input_type is record
        rec_ident_in            :   std_logic_vector(28 downto 0);
        ident_type              :   std_logic;
        frame_type              :   std_logic;
Martin Jeřábek's avatar
Martin Jeřábek committed
253
        rec_ident_valid         :   std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
254 255 256 257 258 259 260 261 262
    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
263

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
264 265 266 267
        -- 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
268

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
269 270 271 272
        -- 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
273

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
274 275 276 277 278 279 280 281 282 283 284 285 286
        -- 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
287

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

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
291 292 293 294 295 296 297 298 299 300 301 302 303
        -- 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
304 305
        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
306 307 308 309 310 311 312 313 314

        -- 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
315

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
        -- 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;

        -- Sample signal delayed by two clock cycle (Nominal and Data)
        -- (Used for Processing the data by Protocol control)
        sample_nbt_del_2        :   std_logic;
        sample_dbt_del_2        :   std_logic;

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

        -- Synchronisation signal by one clock cycle (Nominal and Data)
        -- (Used for Bit stuffing)
        sync_nbt_del_1          :   std_logic;
        sync_dbt_del_1          :   std_logic;
    end record;


    ----------------------------------------------------------------------------
    -- TXT Buffer types
    ----------------------------------------------------------------------------
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
    -- 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
    );
357

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
    -- 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);
        address                 :   std_logic_vector(23 downto 0);
        scs                     :   std_logic;
        swr                     :   std_logic;
        srd                     :   std_logic;
378
        sbe                     :   std_logic_vector(3 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
    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;


400 401
    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
402 403 404 405 406 407 408 409 410 411 412
    ----------------------------------------------------------------------------
    -- 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
413
        data                    :   SW_CAN_data_type;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432

        -- 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;

433 434 435
        -- ESI Flag (Error state indicator)
        esi                     :   std_logic;

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
        -- 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;

    ----------------------------------------------------------------------------
    -- 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;


458 459 460 461 462
    ----------------------------------------------------------------------------
    -- 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
463 464 465 466 467 468 469 470
    ----------------------------------------------------------------------------
    -- Clock params
    ----------------------------------------------------------------------------
    type generate_clock_precomputed_t is record
        low_time : time;
        high_time : time;
    end record;

471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
    ----------------------------------------------------------------------------
    -- Bit sequence generator
    ----------------------------------------------------------------------------
    
    -- 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
489 490 491 492 493 494 495 496 497

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


498 499 500 501 502 503 504 505 506 507 508 509 510 511
    ----------------------------------------------------------------------------
    ----------------------------------------------------------------------------
    -- 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
512 513 514 515 516 517 518

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

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

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
520 521 522 523 524 525 526 527 528
    ----------------------------------------------------------------------------
    -- 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
529
    --  status          Status to be updated
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
530 531
    ----------------------------------------------------------------------------
    procedure evaluate_test(
Martin Jeřábek's avatar
Martin Jeřábek committed
532 533 534
        constant error_th         : in    natural;
        constant errors           : in    natural;
        signal   status           : out   test_status_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
535 536 537 538 539 540 541 542
    );


    ----------------------------------------------------------------------------
    -- Generates clock signal for the test with custom period, duty cycle and
    -- clock jitter.
    --
    -- Arguments:
Martin Jeřábek's avatar
Martin Jeřábek committed
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
    --  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
563 564 565 566 567
    --  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
568
    procedure clock_gen_proc(
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
569 570 571 572 573 574 575
        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
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
    ----------------------------------------------------------------------------
    -- Combinatorial procedure, which infinitely generates timestamp.
    --
    -- Arguments:
    --  clk             Input clock.
    --  timestamp       Output timestamp counter.
    ----------------------------------------------------------------------------
    procedure timestamp_gen_proc(
        signal     clk           : in    std_logic;
        signal     timestamp     : out   std_logic_vector(63 downto 0)
    );


    ----------------------------------------------------------------------------
    -- 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;

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
606 607 608 609 610 611 612 613 614 615 616 617
    ----------------------------------------------------------------------------
    -- Reports message when severity level is lower or equal than severity
    -- of message.
    --
    -- Arguments:
    --  message         String to be reported.
    --  log_severity    Severity level which is set in current test.
    --  log_level       Severity of message
    ----------------------------------------------------------------------------
    procedure log(
        constant message        : in    String;
        constant log_severity   : in    log_lvl_type;
Martin Jeřábek's avatar
Martin Jeřábek committed
618
        constant log_level      : in    log_lvl_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
    );


    ----------------------------------------------------------------------------
    -- 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
646
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
647 648 649 650 651 652
    -- 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
653 654 655
        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
656 657 658 659 660
    );


    ----------------------------------------------------------------------------
    -- Print basic testbench information.
Martin Jeřábek's avatar
Martin Jeřábek committed
661
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
662 663 664 665 666 667 668
    -- 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
669 670 671 672
        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
673 674 675
    );


676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
    ----------------------------------------------------------------------------
    -- 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
    );


692 693 694 695 696 697
    -- variation of above, only returns the seed value
    function apply_rand_seed(
        constant seed            : in   natural;
        constant offset          : in   natural
    ) return natural;

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
698 699 700
    ----------------------------------------------------------------------------
    -- 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
701
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
702 703
    -- Arguments:
    --  dlc             Data length code as received or transmitted.
Martin Jeřábek's avatar
Martin Jeřábek committed
704
    --  length          Length of CAN Frame in bytes
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
705 706 707 708 709 710 711 712 713 714 715
    ----------------------------------------------------------------------------
    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
716
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
717 718 719 720 721 722 723 724 725 726
    -- 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
    );


727 728 729 730 731 732 733 734 735 736 737 738 739
	----------------------------------------------------------------------------
    -- 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
740 741 742
    ----------------------------------------------------------------------------
    -- 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
743
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
744 745 746 747 748
    -- 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
749
        constant dlc            : in    std_logic_vector(3 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
750 751
        variable buff_space     : out   natural
    );
Martin Jeřábek's avatar
Martin Jeřábek committed
752

753

754 755 756
    ----------------------------------------------------------------------------
    -- 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
757
    --
758 759 760 761 762 763 764 765 766 767 768 769 770
    -- 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
771
    -- Convert identifier from SW format to register format (as stored in
772
    --  IDENTIFIER_W of TXT Buffers and RX Buffer).
Martin Jeřábek's avatar
Martin Jeřábek committed
773
    --
774 775 776 777 778 779 780 781 782 783 784 785
    -- 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
786 787 788
    ----------------------------------------------------------------------------
    -- 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
789 790 791
    -- 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
792
    -- cycles each circuit needs between bit transmittion and reception!
Martin Jeřábek's avatar
Martin Jeřábek committed
793
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
    -- 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
    );
Martin Jeřábek's avatar
Martin Jeřábek committed
818

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
819 820 821 822 823 824

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

    ----------------------------------------------------------------------------
825 826
    -- Execute write access on Avalon memory bus. Does not support unaligned
    -- accesses.
Martin Jeřábek's avatar
Martin Jeřábek committed
827
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
828 829 830
    -- Arguments:
    --  w_data          Data to write.
    --  w_address       Address where to write the data
831
    --  w_size          Size of the access (8 Bit, 16 bit or 32 bit)
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
832 833 834 835 836
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure aval_write(
        constant  w_data        : in    std_logic_vector(31 downto 0);
        constant  w_address     : in    std_logic_vector(23 downto 0);
837
        constant  w_size        : in    aval_access_size;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
838 839 840 841 842
        signal    mem_bus       : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
843 844
    -- Execute read access on Avalon memory bus. Does not supports unaligned
    -- accesses.
Martin Jeřábek's avatar
Martin Jeřábek committed
845
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
846 847 848
    -- Arguments:
    --  r_data          Variable in which Read data will be returned.
    --  r_address       Address to read the data from.
849
    --  r_size          Size of the access (8 Bit, 16 bit or 32 bit)
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
850 851 852 853 854
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure aval_read(
        variable  r_data        : out   std_logic_vector(31 downto 0);
        constant  r_address     : in    std_logic_vector(23 downto 0);
855
        constant  r_size        : in    aval_access_size;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
856 857 858 859 860
        signal    mem_bus       : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
861 862 863 864
    -- Execute write access to CTU CAN FD Core over Avalon Bus. If size is not
    -- specified, 32 bit access is executed.
    --
    -- Address bits meaning is following:
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
865 866 867 868
    --  [19:16]     Component type (always CAN_COMPONENT_TYPE)
    --  [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
869
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
870 871 872 873 874 875 876 877 878 879
    -- 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.
    ----------------------------------------------------------------------------
    procedure CAN_write(
        constant  w_data        : in    std_logic_vector(31 downto 0);
        constant  w_offset      : in    std_logic_vector(11 downto 0);
        constant  ID            : in    natural range 0 to 15;
880 881
        signal    mem_bus       : inout Avalon_mem_type;
        constant  w_size        : in    aval_access_size := BIT_32
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
882 883 884 885
    );


    ----------------------------------------------------------------------------
886 887 888 889
    -- Execute read access from CTU CAN FD Core over Avalon Bus. If size is not
    -- specified, 32 bit access is executed.
    --
    -- Address bits meaning is following:
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
890 891 892 893
    --  [19:16]     Component type (always CAN_COMPONENT_TYPE)
    --  [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
894
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
895 896 897 898 899 900 901 902 903 904
    -- 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.
    ----------------------------------------------------------------------------
    procedure CAN_read(
        variable  r_data        : out   std_logic_vector(31 downto 0);
        constant  r_offset      : in    std_logic_vector(11 downto 0);
        constant  ID            : in    natural range 0 to 15;
905 906
        signal    mem_bus       : inout Avalon_mem_type;
        constant  r_size        : in    aval_access_size := BIT_32
Martin Jeřábek's avatar
Martin Jeřábek committed
907
    );
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
908 909


910 911


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
912 913
    ----------------------------------------------------------------------------
    -- CAN configuration routines
914
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
915

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
916 917 918
    ----------------------------------------------------------------------------
    -- 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
919
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
920 921 922 923 924 925 926 927
    -- 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
928
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
929 930 931 932 933 934
    );


    ----------------------------------------------------------------------------
    -- 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
935
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
936 937 938 939 940 941 942 943 944
    -- 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
945
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
946 947
    );

948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
    ----------------------------------------------------------------------------
    -- 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
964

965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
    ----------------------------------------------------------------------------
    -- 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
990 991
    ----------------------------------------------------------------------------
    -- Turn on/off CTU_CAN_FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
992
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
993 994 995 996 997 998 999 1000
    -- 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
1001
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1002 1003 1004 1005 1006
    );


    ----------------------------------------------------------------------------
    -- Enables/Disabled Retransmitt limiting in CTU CAN FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1007
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
    -- Arguments:
    --  enable          Enables retransmitt limiting when "true".
    --                  Disables rettransmitt limiting otherwise.
    --  limit           Limit for number of retransmissions.
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_enable_retr_limit(
        constant enable         : in    boolean;
        constant limit          : in    natural range 0 to 15;
        constant ID             : in    natural range 0 to 15;
Martin Jeřábek's avatar
Martin Jeřábek committed
1019
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1020 1021 1022 1023 1024
    );


    ----------------------------------------------------------------------------
    -- Generate random CAN FD Frame.
Martin Jeřábek's avatar
Martin Jeřábek committed
1025
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1026 1027 1028
    -- Arguments:
    --  rand_ctr        Pointer to pool of random values.
    --  frame           Output variable in which CAN FD Frame sill be generated.
Martin Jeřábek's avatar
Martin Jeřábek committed
1029
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1030 1031 1032 1033 1034 1035
    procedure CAN_generate_frame(
        signal   rand_ctr       : inout natural range 0 to RAND_POOL_SIZE;
        variable frame          : inout SW_CAN_frame_type
    );


1036 1037
    ----------------------------------------------------------------------------
    -- Prints CAN Frame to simulator output
Martin Jeřábek's avatar
Martin Jeřábek committed
1038
    --
1039 1040 1041
    -- Arguments:
    --  frame           Frame to print
    --  severity        Severity level that should be used to print the frame.
Martin Jeřábek's avatar
Martin Jeřábek committed
1042
    ----------------------------------------------------------------------------
1043 1044 1045 1046 1047 1048
    procedure CAN_print_frame(
        constant frame          : in    SW_CAN_frame_type;
        constant log_level      : in    log_lvl_type
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1049 1050
    ----------------------------------------------------------------------------
    -- Compare two CAN FD frames and decide if they are equal.
Martin Jeřábek's avatar
Martin Jeřábek committed
1051
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1052 1053 1054 1055 1056 1057 1058 1059
    -- Arguments:
    --  frame_A         First frame in comparison
    --  frame_B         Second frame in comparison
    --  comp_ts         When "true" timestamps should be considered in
    --                  comparison. When "false" timestamps should not be
    --                  considered.
    --  outcome         Variable to store result of comparison into. When frames
    --                  are equal "true" is stored, "false" otherwise.
Martin Jeřábek's avatar
Martin Jeřábek committed
1060
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1061 1062 1063 1064 1065 1066 1067 1068
    procedure CAN_compare_frames(
        constant frame_A        : in    SW_CAN_frame_type;
        constant frame_B        : in    SW_CAN_frame_type;
        constant comp_ts        : in    boolean;
        variable outcome        : inout boolean
    );


1069 1070 1071 1072 1073 1074 1075 1076
 	----------------------------------------------------------------------------
    -- Stores CAN Frame to auxiliarly test memory. Used for creating SW models
	-- of Buffers. Frame is stored in the same order as in TXT Buffer and RX
	-- Buffer:
	--		1. FRAME_FORMAT
	--		2. IDENTIFIER
	--		3. TIMESTAMP_L
	--		4. TIMESTAMP_U
Martin Jeřábek's avatar
Martin Jeřábek committed
1077 1078
	--		5-20. DATA
    --
1079 1080 1081 1082 1083
    -- Arguments:
    --  frame         	Frame to store.
    --  memory			Memory to store the frame into
	--	pointer			Pointer to the memory index where frame shouldbe stored
    ----------------------------------------------------------------------------
1084
    procedure store_frame_to_test_mem(
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
        constant frame          :  in       SW_CAN_frame_type;
        signal   memory         :  out      test_mem_type;
        signal   pointer        :  inout    natural
    );


	----------------------------------------------------------------------------
    -- Read frame from auxiliarly test memory. Used for creating SW models of
	-- Buffers. Frame is expected to be in the same format as IN TXT Buffer and
	-- RX Buffer:
	--		1. FRAME_FORMAT
	--		2. IDENTIFIER
	--		3. TIMESTAMP_L
	--		4. TIMESTAMP_U
Martin Jeřábek's avatar
Martin Jeřábek committed
1099
	--		5-20. DATA
1100 1101 1102 1103 1104
	--
    -- Arguments:
    --  frame           Output variable in which CAN FD Frame sill be generated.
    --  memory          Memory from which the CAN frame should be read.
    --  pointer         Pointer to memory where CAN Frame is starting.
Martin Jeřábek's avatar
Martin Jeřábek committed
1105
    ----------------------------------------------------------------------------
1106
    procedure read_frame_from_test_mem(
1107 1108 1109 1110 1111 1112
        variable frame          :  inout    SW_CAN_frame_type;
        constant memory         :  in       test_mem_type;
        variable pointer        :  inout    natural
    );


1113 1114 1115
    ----------------------------------------------------------------------------
    -- Inserts frame to TXT Buffer. Function does NOT check state of the
    -- buffer.
Martin Jeřábek's avatar
Martin Jeřábek committed
1116
    --
1117 1118 1119 1120 1121 1122
    -- Arguments:
    --  frame           CAN FD Frame to send
    --  buf_nr          Number of TXT Buffer from which the frame should be
    --                  sent (1:4)
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1123
    --  outcome         Returns "true" if the frame was inserted properly,
1124 1125
    --                  "false" if TXT Buffer was in states : Ready,
    --                  TX in progress, Abort in progress
Martin Jeřábek's avatar
Martin Jeřábek committed
1126
    ----------------------------------------------------------------------------
1127 1128 1129 1130 1131 1132 1133 1134
    procedure CAN_insert_TX_frame(
        constant frame          : in    SW_CAN_frame_type;
        constant buf_nr         : in    natural range 1 to 4;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1135 1136 1137 1138
    ----------------------------------------------------------------------------
    -- Check whether TXT Buffer is accessible (Empty, Aborted, TX Failed or Done)
    -- If yes, insert the frame to TXT Buffer and give "set_ready" command.
    -- The function does not wait until the frame is transmitted.
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
    -- Arguments:
    --  frame           CAN FD Frame to send
    --  buf_nr          Number of TXT Buffer from which the frame should be
    --                  sent (1:4)
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1146
    --  outcome         Returns "true" if the frame was inserted properly,
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1147 1148
    --                  "false" if TXT Buffer was in states : Ready,
    --                  TX in progress, Abort in progress
Martin Jeřábek's avatar
Martin Jeřábek committed
1149
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
    procedure CAN_send_frame(
        constant frame          : in    SW_CAN_frame_type;
        constant buf_nr         : in    natural range 1 to 4;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type;
        variable outcome        : out   boolean
    );


    ----------------------------------------------------------------------------
    -- Reads CAN Frame from RX Buffer FIFO.
Martin Jeřábek's avatar
Martin Jeřábek committed
1161
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
    -- Arguments:
    --  frame           Output variable where CAN FD Frame will be stored
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_read_frame(
        variable frame          : inout SW_CAN_frame_type;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Waits until frame starts (unit turns transceiver or receiver),
    -- and then waits until frame finishes (bus becomes idle).
    --
    -- Procedure is polling on status of CTU CAN FD Core over Avalon bus!
Martin Jeřábek's avatar
Martin Jeřábek committed
1179
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
    -- Arguments:
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_wait_frame_sent(
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Waits until CAN bus becomes idle (no frame in progress).
Martin Jeřábek's avatar
Martin Jeřábek committed
1192
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
    -- Procedure is polling on status of CTU CAN FD Core over Avalon bus!
    --
    -- Arguments:
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_wait_bus_idle(
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Waits until CAN bus becomes idle (no frame in progress).
    --
    -- Procedure is polling on status of CTU CAN FD Core over Avalon bus!
Martin Jeřábek's avatar
Martin Jeřábek committed
1209
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1210 1211 1212 1213 1214 1215 1216 1217
    -- Arguments:
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_wait_error_transmitted(
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );
Martin Jeřábek's avatar
Martin Jeřábek committed
1218

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

1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
    ----------------------------------------------------------------------------
    -- Reads bit timing parameters and waits for length of several bit times.
    --
    -- Arguments:
    --  bits            Number of Bit times to wait for
    --  nominal         "true" if Nominal Bit time should be used, "false" if
    --                  Data Bit Time should be used.
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_wait_n_bits(
        constant bits           : in    natural;
        constant nominal        : in    boolean;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
    ----------------------------------------------------------------------------
    -- Waits until transmission or reception is started by a Node.
    --
    -- Arguments:
    --  bits            Number of Bit times to wait for
    --  exit_trans      Exit when unit turns transceiver.         
    --  exit_rec        Exit when unit turns receiver.
    --  ID              Index of CTU CAN FD Core instance
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure CAN_wait_tx_rx_start(
        constant exit_trans     : in    boolean;
        constant exit_rec       : in    boolean;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1256 1257
    ----------------------------------------------------------------------------
    -- Calculate length of CAN Frame in bits (stuff bits not included).
Martin Jeřábek's avatar
Martin Jeřábek committed
1258
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1259 1260 1261 1262 1263 1264 1265 1266 1267
    -- Arguments:
    --  frame           CAN Frame whose length should be calculated.
    --  bit_length      Variable in which the length of CAN Frame in bits is
    --                  stored.
    ----------------------------------------------------------------------------
    procedure CAN_calc_frame_length(
        constant frame          : in    SW_CAN_frame_type;
        variable bit_length     : inout natural
    );
Martin Jeřábek's avatar
Martin Jeřábek committed
1268 1269


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1270 1271 1272 1273 1274 1275 1276 1277
    function CAN_add_unsigned(
        operator1               : in    std_logic_vector(11 downto 0);
        operator2               : in    std_logic_vector(11 downto 0)
    ) return std_logic_vector;


    ----------------------------------------------------------------------------
    -- Give command to TXT Buffer.
Martin Jeřábek's avatar
Martin Jeřábek committed
1278
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
    -- Arguments:
    --  cmd             Command to give to TXT Buffer.
    --  buf_index       Number of TXT Buffer which should receive the command.
    --  ID              Index of CTU CAN FD Core instance.
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure send_TXT_buf_cmd(
        constant cmd            : in    SW_TXT_Buffer_command_type;
        constant buf_n          : in    natural range 1 to 4;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Read state of TXT Buffer.
Martin Jeřábek's avatar
Martin Jeřábek committed
1295
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1296 1297 1298 1299
    -- Arguments:
    --  buf_index       TXT Buffer number.
    --  retVal          Variable in which return state of the buffer will be
    --                  returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1300
    --  ID              Index of CTU CAN FD Core instance.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1301
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1302
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1303 1304 1305 1306 1307 1308 1309 1310
    procedure get_tx_buf_state(
        constant buf_n          : in    natural range 1 to 4;
        variable retVal         : out   SW_TXT_Buffer_state_type;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );