rtr_pref_feature_tb.vhd 8.69 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

38
--------------------------------------------------------------------------------
39
-- Purpose:
40 41
--  Feature test for RTR preferred behaviour of CTU CAN FD. RTR preffered
--  behaviour determines whether inserted DLC will be sent as part of RTR frame
Martin Jeřábek's avatar
Martin Jeřábek committed
42 43
--  or all zeroes will be sent in RTR Frame.
--
44
--  Test sequence is like so:
45 46 47 48 49 50
--      1. Part 1:
--          1.1 Generate frame with arbitrary DLC and force RTR flag
--          1.2 Configure RTR behaviour to send all zeroes.
--          1.3 Send frame by Node 1.
--          1.4 Wait until Node 2 receives the frame. Read frame from Node 2
--          1.5 Check if received DLC is 0.
Martin Jeřábek's avatar
Martin Jeřábek committed
51
--      2. Part 2:
52 53 54 55
--          2.1 Configure RTR behaviour to send the original value
--          2.2 Send frame by Node 1.
--          2.3 Wait until Node 2 receives the frame. Read frame from Node 2
--          2.4 Check if received DLC is matching transmitted DLC.
56
--
57
--------------------------------------------------------------------------------
58 59 60
-- Revision History:
--
--    23.6.2016   Created file
61
--    06.02.2018  Modified to work with the IP-XACT generated memory map
62 63 64
--     12.6.2018  Updated to use CAN Test library functions instead of direct
--                register access.
--------------------------------------------------------------------------------
65

66 67 68 69 70 71 72
Library ieee;
USE IEEE.std_logic_1164.all;
USE IEEE.numeric_std.ALL;
USE ieee.math_real.ALL;
use work.CANconstants.all;
USE work.CANtestLib.All;
USE work.randomLib.All;
Martin Jeřábek's avatar
Martin Jeřábek committed
73
use work.pkg_feature_exec_dispath.all;
74

75
use work.CAN_FD_register_map.all;
76
use work.CAN_FD_frame_format.all;
77

78
package rtr_pref_feature is
79
    procedure rtr_pref_feature_exec(
80 81
        variable    o               : out    feature_outputs_t;
        signal      so              : out    feature_signal_outputs_t;
82
        signal      rand_ctr        : inout  natural range 0 to RAND_POOL_SIZE;
83 84 85
        signal      iout            : in     instance_inputs_arr_t;
        signal      mem_bus         : inout  mem_bus_arr_t;
        signal      bus_level       : in     std_logic
86
    );
87 88 89 90
end package;


package body rtr_pref_feature is
91
    procedure rtr_pref_feature_exec(
92 93
        variable    o               : out    feature_outputs_t;
        signal      so              : out    feature_signal_outputs_t;
94
        signal      rand_ctr        : inout  natural range 0 to RAND_POOL_SIZE;
95 96 97 98
        signal      iout            : in     instance_inputs_arr_t;
        signal      mem_bus         : inout  mem_bus_arr_t;
        signal      bus_level       : in     std_logic
    ) is
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
99 100
        variable ID_1               :        natural := 1;
        variable ID_2               :        natural := 2;
101 102 103 104 105
        variable tx_frame           :        SW_CAN_frame_type;
        variable rx_frame           :        SW_CAN_frame_type;
        variable frame_sent         :        boolean := false;
        variable command            :        SW_command := (false, false, false);
        variable status             :        SW_status;
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
106 107 108
        variable mode               :        SW_mode := (false, false, false,
                                                false, false, false, false,
                                                false, false, false);
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    begin
        outcome := true;

        ------------------------------------------------------------------------
        -- Part 1
        ------------------------------------------------------------------------
        ------------------------------------------------------------------------
        -- Generate CAN frame with arbitrary DLC and force RTR after.
        ------------------------------------------------------------------------
        CAN_generate_frame(rand_ctr, tx_frame);
        tx_frame.rtr := RTR_FRAME;
        tx_frame.frame_format := NORMAL_CAN;

        ------------------------------------------------------------------------
        -- Set the RTR preferred behaviour to send the DLC all zeroes..
        ------------------------------------------------------------------------
        mode.rtr_pref := true;
        set_core_mode(mode, ID_2, mem_bus_2);
        set_core_mode(mode, ID_1, mem_bus_1);

        ------------------------------------------------------------------------
        -- Restart the content of the Node 2 RX Buffer
        ------------------------------------------------------------------------
        command.release_rec_buffer := true;
        give_controller_command(command, ID_2, mem_bus_2);
        command.release_rec_buffer := false;

        ------------------------------------------------------------------------
        -- Insert the frame for transmittion and wait until it was sent
        ------------------------------------------------------------------------
        CAN_send_frame(tx_frame, 1, ID_1, mem_bus_1, frame_sent);
        if (not frame_sent) then
            outcome := false;
        end if;
        CAN_wait_frame_sent(ID_2, mem_bus_2);

        ------------------------------------------------------------------------
        -- Check that recieved DLC is zero
        ------------------------------------------------------------------------
        CAN_read_frame(rx_frame, ID_2, mem_bus_2);
        if (rx_frame.dlc /= x"0") then
            outcome := false;
        end if;


        ------------------------------------------------------------------------
        -- Part 2
        ------------------------------------------------------------------------
        ------------------------------------------------------------------------
        -- Set the RTR preferred behaviour to send the original DLC
        ------------------------------------------------------------------------
        mode.rtr_pref := false;
        set_core_mode(mode, ID_2, mem_bus_2);
        set_core_mode(mode, ID_1, mem_bus_1);

        ------------------------------------------------------------------------
        -- Restart the content of the Node 2 RX Buffer
        ------------------------------------------------------------------------
        command.release_rec_buffer := true;
        give_controller_command(command, ID_2, mem_bus_2);
        command.release_rec_buffer := false;

        ------------------------------------------------------------------------
        -- Insert the frame for transmittion and wait until recieved
        ------------------------------------------------------------------------
        CAN_send_frame(tx_frame, 1, ID_1, mem_bus_1, frame_sent);
        if (not frame_sent) then
            outcome := false;
        end if;
        CAN_wait_frame_sent(ID_2, mem_bus_2);

        ------------------------------------------------------------------------
        -- Check that recieved DLC is matching transmitted DLC
        ------------------------------------------------------------------------
        CAN_read_frame(rx_frame, ID_2, mem_bus_2);
        if (rx_frame.dlc /= tx_frame.dlc) then
            outcome := false;
        end if;
187

Martin Jeřábek's avatar
Martin Jeřábek committed
188
  end procedure;
189

Martin Jeřábek's avatar
Martin Jeřábek committed
190
end package body;