CANtestLib.vhd 133 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.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
68
--------------------------------------------------------------------------------
69

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

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

package CANtestLib is

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

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

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

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

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


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

133 134 135 136 137 138 139 140 141 142
    -- 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;
143 144
        internal_loopback       :   boolean;
        iso_fd_support          :   boolean;
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    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;
160
        tx_buffer_empty         :   boolean;
161 162 163 164 165 166 167 168
        error_transmission      :   boolean;
        receiver                :   boolean;
        transmitter             :   boolean;
        error_warning           :   boolean;
        bus_status              :   boolean;
    end record;


169
    -- Interrupt sources
170 171 172 173 174 175 176 177 178 179 180 181 182
    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;
183
    end record;    
184 185 186 187 188 189 190 191

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

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

198
    -- Error counters (Normal and Special)
199 200 201 202 203 204 205 206
    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;


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


214 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
    -- 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
243 244 245 246
    ----------------------------------------------------------------------------
    -- Message filter types
    ----------------------------------------------------------------------------

Martin Jeřábek's avatar
Martin Jeřábek committed
247
    -- Frame information on input of message filter
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
248 249 250 251
    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
252
        rec_ident_valid         :   std_logic;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
253 254 255 256 257 258 259 260 261
    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
262

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

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

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

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

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

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

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
315 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
        -- 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
345

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
346 347 348 349 350 351 352 353 354 355
    -- 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
    );
356

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


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

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

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

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


457 458 459 460 461
    ----------------------------------------------------------------------------
    -- Test storage memory
    ----------------------------------------------------------------------------
    type test_mem_type is array (0 to 255) of std_logic_vector(31 downto 0);

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477

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



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

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

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
479 480 481 482 483 484 485 486 487
    ----------------------------------------------------------------------------
    -- 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
488
    --  status          Status to be updated
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
489 490
    ----------------------------------------------------------------------------
    procedure evaluate_test(
Martin Jeřábek's avatar
Martin Jeřábek committed
491 492 493
        constant error_th         : in    natural;
        constant errors           : in    natural;
        signal   status           : out   test_status_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
    );


    ----------------------------------------------------------------------------
    -- Generates clock signal 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.
    --  out_clk         Generated clock.
    ----------------------------------------------------------------------------
    procedure generate_clock(
        constant period         : in    natural;
        constant duty           : in    natural;
        constant epsilon_ppm    : in    natural;
        signal   out_clk        : out   std_logic
    );


    ----------------------------------------------------------------------------
    -- 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;
        signal   log_level      : in    log_lvl_type
    );


    ----------------------------------------------------------------------------
    -- 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
556
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
557 558 559 560 561 562
    -- 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
563 564 565
        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
566 567 568 569 570
    );


    ----------------------------------------------------------------------------
    -- Print basic testbench information.
Martin Jeřábek's avatar
Martin Jeřábek committed
571
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
572 573 574 575 576 577 578 579 580 581 582 583 584 585
    -- 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(
        signal iterations       : in    natural;
        signal log_level        : in    log_lvl_type;
        signal error_beh        : in    err_beh_type;
        signal error_tol        : in    natural
    );


586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
    ----------------------------------------------------------------------------
    -- 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
    );


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
602 603 604
    ----------------------------------------------------------------------------
    -- 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
605
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
606 607
    -- Arguments:
    --  dlc             Data length code as received or transmitted.
Martin Jeřábek's avatar
Martin Jeřábek committed
608
    --  length          Length of CAN Frame in bytes
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
609 610 611 612 613 614 615 616 617 618 619
    ----------------------------------------------------------------------------
    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
620
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
621 622 623 624 625 626 627 628 629 630 631 632 633
    -- 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
    );


    ----------------------------------------------------------------------------
    -- 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
634
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
635 636 637 638 639
    -- 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
640
        constant dlc            : in    std_logic_vector(3 downto 0);
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
641 642
        variable buff_space     : out   natural
    );
Martin Jeřábek's avatar
Martin Jeřábek committed
643

644

645 646 647
    ----------------------------------------------------------------------------
    -- 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
648
    --
649 650 651 652 653 654 655 656 657 658 659 660 661
    -- 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
662
    -- Convert identifier from SW format to register format (as stored in
663
    --  IDENTIFIER_W of TXT Buffers and RX Buffer).
Martin Jeřábek's avatar
Martin Jeřábek committed
664
    --
665 666 667 668 669 670 671 672 673 674 675 676
    -- 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
677 678 679
    ----------------------------------------------------------------------------
    -- 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
680 681 682
    -- 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
683
    -- cycles each circuit needs between bit transmittion and reception!
Martin Jeřábek's avatar
Martin Jeřábek committed
684
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
    -- 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
709

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
710 711 712 713 714 715

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

    ----------------------------------------------------------------------------
716 717
    -- Execute write access on Avalon memory bus. Does not support unaligned
    -- accesses.
Martin Jeřábek's avatar
Martin Jeřábek committed
718
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
719 720 721
    -- Arguments:
    --  w_data          Data to write.
    --  w_address       Address where to write the data
722
    --  w_size          Size of the access (8 Bit, 16 bit or 32 bit)
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
723 724 725 726 727
    --  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);
728
        constant  w_size        : in    aval_access_size;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
729 730 731 732 733
        signal    mem_bus       : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
734 735
    -- Execute read access on Avalon memory bus. Does not supports unaligned
    -- accesses.
Martin Jeřábek's avatar
Martin Jeřábek committed
736
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
737 738 739
    -- Arguments:
    --  r_data          Variable in which Read data will be returned.
    --  r_address       Address to read the data from.
740
    --  r_size          Size of the access (8 Bit, 16 bit or 32 bit)
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
741 742 743 744 745
    --  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);
746
        constant  r_size        : in    aval_access_size;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
747 748 749 750 751
        signal    mem_bus       : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
752 753 754 755
    -- 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
756 757 758 759
    --  [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
760
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
761 762 763 764 765 766 767 768 769 770
    -- 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;
771 772
        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
773 774 775 776
    );


    ----------------------------------------------------------------------------
777 778 779 780
    -- 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
781 782 783 784
    --  [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
785
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
786 787 788 789 790 791 792 793 794 795
    -- 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;
796 797
        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
798
    );
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
799 800


801 802


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
803 804
    ----------------------------------------------------------------------------
    -- CAN configuration routines
805
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
806

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
807 808 809
    ----------------------------------------------------------------------------
    -- 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
810
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
811 812 813 814 815 816 817 818
    -- 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
819
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
820 821 822 823 824 825
    );


    ----------------------------------------------------------------------------
    -- 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
826
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
827 828 829 830 831 832 833 834 835
    -- 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
836
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
837 838 839 840 841
    );


    ----------------------------------------------------------------------------
    -- Turn on/off CTU_CAN_FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
842
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
843 844 845 846 847 848 849 850
    -- 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
851
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
852 853 854 855 856
    );


    ----------------------------------------------------------------------------
    -- Enables/Disabled Retransmitt limiting in CTU CAN FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
857
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
858 859 860 861 862 863 864 865 866 867 868
    -- 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
869
        signal   mem_bus        : inout Avalon_mem_type
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
870 871 872 873 874
    );


    ----------------------------------------------------------------------------
    -- Generate random CAN FD Frame.
Martin Jeřábek's avatar
Martin Jeřábek committed
875
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
876 877 878
    -- 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
879
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
880 881 882 883 884 885
    procedure CAN_generate_frame(
        signal   rand_ctr       : inout natural range 0 to RAND_POOL_SIZE;
        variable frame          : inout SW_CAN_frame_type
    );


886 887
    ----------------------------------------------------------------------------
    -- Prints CAN Frame to simulator output
Martin Jeřábek's avatar
Martin Jeřábek committed
888
    --
889 890 891
    -- 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
892
    ----------------------------------------------------------------------------
893 894 895 896 897 898
    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
899 900
    ----------------------------------------------------------------------------
    -- Compare two CAN FD frames and decide if they are equal.
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
    -- 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
910
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
911 912 913 914 915 916 917 918
    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
    );


919 920 921 922 923 924 925 926
 	----------------------------------------------------------------------------
    -- 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
927 928
	--		5-20. DATA
    --
929 930 931 932 933
    -- Arguments:
    --  frame         	Frame to store.
    --  memory			Memory to store the frame into
	--	pointer			Pointer to the memory index where frame shouldbe stored
    ----------------------------------------------------------------------------
934
    procedure store_frame_to_test_mem(
935 936 937 938 939 940 941 942 943 944 945 946 947 948
        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
949
	--		5-20. DATA
950 951 952 953 954
	--
    -- 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
955
    ----------------------------------------------------------------------------
956
    procedure read_frame_from_test_mem(
957 958 959 960 961 962
        variable frame          :  inout    SW_CAN_frame_type;
        constant memory         :  in       test_mem_type;
        variable pointer        :  inout    natural
    );


963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
    ----------------------------------------------------------------------------
    -- Inserts frame to TXT Buffer. Function does NOT check state of the
    -- buffer.
    -- 
    -- 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.
    --  outcome         Returns "true" if the frame was inserted properly, 
    --                  "false" if TXT Buffer was in states : Ready,
    --                  TX in progress, Abort in progress
    ---------------------------------------------------------------------------- 
    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
985 986 987 988
    ----------------------------------------------------------------------------
    -- 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
989
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
990 991 992 993 994 995
    -- 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
996
    --  outcome         Returns "true" if the frame was inserted properly,
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
997 998
    --                  "false" if TXT Buffer was in states : Ready,
    --                  TX in progress, Abort in progress
Martin Jeřábek's avatar
Martin Jeřábek committed
999
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
    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
1011
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
    -- 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
1029
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
    -- 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
1042
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
    -- 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
1059
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1060 1061 1062 1063 1064 1065 1066 1067
    -- 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
1068

Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1069 1070 1071

    ----------------------------------------------------------------------------
    -- Calculate length of CAN Frame in bits (stuff bits not included).
Martin Jeřábek's avatar
Martin Jeřábek committed
1072
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1073 1074 1075 1076 1077 1078 1079 1080 1081
    -- 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
1082 1083


Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1084 1085 1086 1087 1088 1089 1090 1091
    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
1092
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
    -- 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
1109
    --
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1110 1111 1112 1113
    -- 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
1114
    --  ID              Index of CTU CAN FD Core instance.
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1115
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1116
    ----------------------------------------------------------------------------
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
1117 1118 1119 1120 1121 1122 1123 1124
    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
    );


1125 1126
    ----------------------------------------------------------------------------
    -- Read state of RX Buffer.
Martin Jeřábek's avatar
Martin Jeřábek committed
1127
    --
1128 1129 1130
    -- Arguments:
    --  retVal          Variable in which return state of the buffer will be
    --                  returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1131
    --  ID              Index of CTU CAN FD Core instance.
1132
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1133
    ----------------------------------------------------------------------------
1134 1135 1136 1137 1138 1139 1140
    procedure get_rx_buf_state(
        variable retVal         : out   SW_RX_Buffer_info;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


1141 1142 1143
    ----------------------------------------------------------------------------
    -- Read version register and return the actual version of the core like so:
    --  MAJOR_VERSION * 10 + MINOR_VERSION.
Martin Jeřábek's avatar
Martin Jeřábek committed
1144
    --
1145 1146
    -- Arguments:
    --  retVal          Variable in which return version will be returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1147
    --  ID              Index of CTU CAN FD Core instance.
1148
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1149
    ----------------------------------------------------------------------------
1150 1151 1152 1153 1154 1155 1156
    procedure get_core_version(
        variable retVal         : out   natural;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


1157 1158
    ----------------------------------------------------------------------------
    -- Sets mode of CTU CAN FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1159
    --
1160 1161
    -- Arguments:
    --  mode            Mode to set.
Martin Jeřábek's avatar
Martin Jeřábek committed
1162
    --  ID              Index of CTU CAN FD Core instance.
1163
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1164
    ----------------------------------------------------------------------------
1165 1166 1167 1168 1169 1170 1171 1172 1173
    procedure set_core_mode(
        constant mode           : in    SW_mode;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Reads mode from CTU CAN FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1174
    --
1175 1176
    -- Arguments:
    --  mode            Variable to which returned mode will be stored.
Martin Jeřábek's avatar
Martin Jeřábek committed
1177
    --  ID              Index of CTU CAN FD Core instance.
1178
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1179
    ----------------------------------------------------------------------------
1180 1181 1182 1183 1184 1185 1186 1187 1188
    procedure get_core_mode(
        variable mode           : out   SW_mode;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Send command to execute SW reset
Martin Jeřábek's avatar
Martin Jeřábek committed
1189
    --
1190
    -- Arguments:
Martin Jeřábek's avatar
Martin Jeřábek committed
1191
    --  ID              Index of CTU CAN FD Core instance.
1192
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1193
    ----------------------------------------------------------------------------
1194 1195 1196 1197 1198 1199 1200 1201
    procedure exec_SW_reset(
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Send arbitrary command to the controller.
Martin Jeřábek's avatar
Martin Jeřábek committed
1202
    --
1203 1204
    -- Arguments:
    --  command         Command to send to the controller.
Martin Jeřábek's avatar
Martin Jeřábek committed
1205
    --  ID              Index of CTU CAN FD Core instance.
1206
    --  mem_bus         Avalon memory bus to execute the access on.
Martin Jeřábek's avatar
Martin Jeřábek committed
1207
    ----------------------------------------------------------------------------
1208 1209 1210 1211 1212
    procedure give_controller_command(
        constant command        : in    SW_command;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );
1213 1214


1215 1216
    ----------------------------------------------------------------------------
    -- Read status of CTU CAN FD controller.
Martin Jeřábek's avatar
Martin Jeřábek committed
1217
    --
1218 1219
    -- Arguments:
    --  status          Variable in which status of the Core will be returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1220
    --  ID              Index of CTU CAN FD Core instance.
1221
    --  mem_bus         Avalon memory bus to execute the access on.
1222
    ----------------------------------------------------------------------------
1223 1224 1225 1226 1227 1228
    procedure get_controller_status(
        variable status         : out   SW_status;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );

1229 1230 1231 1232

    ----------------------------------------------------------------------------
    -- Read captured interrupt vector (status). "true" indicates interrupt
    -- occurred.
Martin Jeřábek's avatar
Martin Jeřábek committed
1233
    --
1234 1235
    -- Arguments:
    --  interrupts      Variable in which Interrupt vector will be returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1236
    --  ID              Index of CTU CAN FD Core instance.
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure read_int_status(
        variable interrupts     : out   SW_interrupts;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Clear captured interrupt vector (status). "true" indicates interrupt
    -- should be cleared.
Martin Jeřábek's avatar
Martin Jeřábek committed
1249
    --
1250 1251
    -- Arguments:
    --  interrupts      Interrupts which should be cleared.
Martin Jeřábek's avatar
Martin Jeřábek committed
1252
    --  ID              Index of CTU CAN FD Core instance.
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure clear_int_status(
        constant interrupts     : in    SW_interrupts;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Read interrupt enable vector. "true" indicates interrupt
    -- is enabled for capturing.
Martin Jeřábek's avatar
Martin Jeřábek committed
1265
    --
1266
    -- Arguments:
Martin Jeřábek's avatar
Martin Jeřábek committed
1267
    --  interrupts      Variable in which interrupt enable vector will be
1268
    --                  returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1269
    --  ID              Index of CTU CAN FD Core instance.
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure read_int_enable(
        variable interrupts     : out   SW_interrupts;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Write interrupt enable vector (status). "true" indicates interrupt
    -- will be enabled for capturing, "false" indicates interrupt will be
    -- disabled for capturing.
Martin Jeřábek's avatar
Martin Jeřábek committed
1283
    --
1284 1285
    -- Arguments:
    --  interrupts      Variable in which status of the Core will be returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1286
    --  ID              Index of CTU CAN FD Core instance.
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure write_int_enable(
        constant interrupts     : in    SW_interrupts;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
1297
    -- Read interrupt mask. "true" indicates interrupt is masked, thus it does
1298
    -- not affect "int" output of CTU CAN FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1299
    --
1300 1301
    -- Arguments:
    --  interrupts      Variable in which interrupt mask will be returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1302
    --  ID              Index of CTU CAN FD Core instance.
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure read_int_mask(
        variable interrupts     : out   SW_interrupts;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Write interrupt mask. "true" indicates interrupt is masked, thus it does
    -- not affect "int" output of CTU CAN FD Core.
Martin Jeřábek's avatar
Martin Jeřábek committed
1315
    --
1316 1317
    -- Arguments:
    --  interrupts      Interrupt mask to write.
Martin Jeřábek's avatar
Martin Jeřábek committed
1318
    --  ID              Index of CTU CAN FD Core instance.
1319 1320 1321 1322 1323 1324 1325 1326 1327
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure write_int_mask(
        constant interrupts     : in    SW_interrupts;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


1328
    ----------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
1329 1330
    -- Read fault confinement state of CTU CAN FD Core.
    --
1331 1332 1333
    -- Arguments:
    --  fault_state     Variable in which fault confinement state will be
    --                  returned.
Martin Jeřábek's avatar
Martin Jeřábek committed
1334
    --  ID              Index of CTU CAN FD Core instance.
1335 1336 1337 1338 1339 1340 1341 1342 1343
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure get_fault_state(
        variable fault_state    : out   SW_fault_state;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
    ----------------------------------------------------------------------------
    -- Set fault confinement thresholds for Error warning limit and for 
    -- Error passive.
    -- 
    -- Arguments:
    --  fault_th        Variable with fault confinement thresholds.
    --  ID              Index of CTU CAN FD Core instance.    
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure set_fault_thresholds(
        constant fault_th       : in    SW_fault_thresholds;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


    ----------------------------------------------------------------------------
    -- Set fault confinement thresholds for Error warning limit and for 
    -- Error passive.
    -- 
    -- Arguments:
    --  fault_th        Variable with fault confinement thresholds.
    --  ID              Index of CTU CAN FD Core instance.    
    --  mem_bus         Avalon memory bus to execute the access on.
    ----------------------------------------------------------------------------
    procedure get_fault_thresholds(
        variable fault_th       : out   SW_fault_thresholds;
        constant ID             : in    natural range 0 to 15;
        signal   mem_bus        : inout Avalon_mem_type
    );


1376 <