rx_status_feature_tb.vhd 10.7 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 40
-- Purpose:
--  RX Buffer status feature test implementation.
Martin Jeřábek's avatar
Martin Jeřábek committed
41
--
42 43 44
--  Test sequence:
--    1. RX Buffer size is read and buffer is cleared.
--    2. Free memory, buffer status and message count is checked.
45
--    3. Random frames are sent on the bus by node 2 and recieved by node 1
46 47 48 49
--    4. After each frame amount of remaining memory is checked towards expected
--       value.
--    5. When buffer is filled Data overrun flag is checked and cleared.
--    6. After clearing Overrun flag, it is checked it was really cleared.
50
--
51 52 53 54
--------------------------------------------------------------------------------
-- Revision History:
--
--    21.6.2016   Created file
55
--    06.02.2018  Modified to work with the IP-XACT generated memory map
56 57
--     11.6.2018  Modified to use CAN Test lib functions instead of direct
--                register access.
58
--------------------------------------------------------------------------------
59

60 61 62 63 64 65 66
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
67
use work.pkg_feature_exec_dispath.all;
68

69
use work.CAN_FD_register_map.all;
70
use work.CAN_FD_frame_format.all;
71

72
package rx_status_feature is
73
    procedure rx_status_feature_exec(
Martin Jeřábek's avatar
Martin Jeřábek committed
74
        variable    o               : out    feature_outputs_t;
75
        signal      so              : out    feature_signal_outputs_t;
Martin Jeřábek's avatar
Martin Jeřábek committed
76
        signal      rand_ctr        : inout  natural range 0 to RAND_POOL_SIZE;
77
        signal      iout            : in     instance_outputs_arr_t;
Martin Jeřábek's avatar
Martin Jeřábek committed
78 79
        signal      mem_bus         : inout  mem_bus_arr_t;
        signal      bus_level       : in     std_logic
80
    );
81 82 83 84
end package;


package body rx_status_feature is
85
    procedure rx_status_feature_exec(
Martin Jeřábek's avatar
Martin Jeřábek committed
86
        variable    o               : out    feature_outputs_t;
87
        signal      so              : out    feature_signal_outputs_t;
Martin Jeřábek's avatar
Martin Jeřábek committed
88
        signal      rand_ctr        : inout  natural range 0 to RAND_POOL_SIZE;
89
        signal      iout            : in     instance_outputs_arr_t;
Martin Jeřábek's avatar
Martin Jeřábek committed
90 91
        signal      mem_bus         : inout  mem_bus_arr_t;
        signal      bus_level       : in     std_logic
92 93 94 95 96 97 98 99 100 101 102
    ) is
        variable ID_1           	:       natural range 0 to 15 := 1;
        variable ID_2           	:       natural range 0 to 15 := 2;
        variable CAN_frame          :       SW_CAN_frame_type;
        variable send_more          :       boolean := true;
        variable in_RX_buf          :       natural range 0 to 1023;
        variable frame_sent         :       boolean := false;
        variable number_frms_sent   :       natural range 0 to 1023;

        variable buf_info           :       SW_RX_Buffer_info;
        variable command            :       SW_command := (false, false, false);
Martin Jeřábek's avatar
Martin Jeřábek committed
103
        variable status             :       SW_status;
104
    begin
Martin Jeřábek's avatar
Martin Jeřábek committed
105
        o.outcome := true;
106 107 108 109 110

        ------------------------------------------------------------------------
        -- Restart the content of the buffer...
        ------------------------------------------------------------------------
        command.release_rec_buffer := true;
Martin Jeřábek's avatar
Martin Jeřábek committed
111
        give_controller_command(command, ID_1, mem_bus(1));
112 113 114 115 116
        command.release_rec_buffer := false;

        ------------------------------------------------------------------------
        -- Read the size of the synthesized buffer
        ------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
117
        get_rx_buf_state(buf_info, ID_1, mem_bus(1));
Martin Jeřábek's avatar
Martin Jeřábek committed
118

119 120 121 122
        ------------------------------------------------------------------------
        -- Check that buffer is empty
        ------------------------------------------------------------------------
        if (not buf_info.rx_empty) then
123
            -- LCOV_EXCL_START
Martin Jeřábek's avatar
Martin Jeřábek committed
124
            o.outcome := false;
125 126 127
            report "RX Buffer is not empty after Release receive Buffer command"
                severity error;
            -- LCOV_EXCL_STOP
128 129 130 131 132 133
        end if;

        ------------------------------------------------------------------------
        -- Check that free memory is equal to buffer size
        ------------------------------------------------------------------------
        if (buf_info.rx_buff_size /= buf_info.rx_mem_free) then
134 135 136
            -- LCOV_EXCL_START
            report "Number of free words in RX Buffer after Release Receive " &
                "Buffer command is not equal to buffer size" severity error;
Martin Jeřábek's avatar
Martin Jeřábek committed
137
            o.outcome := false;
138
            -- LCOV_EXCL_STOP
139 140 141 142 143 144 145 146 147
        end if;

        ------------------------------------------------------------------------
        -- Check that both pointers are 0 as well
        -- as message count
        ------------------------------------------------------------------------
        if (buf_info.rx_frame_count /= 0 or buf_info.rx_write_pointer /= 0 or
            buf_info.rx_read_pointer /= 0)
        then
148
            -- LCOV_EXCL_START
Martin Jeřábek's avatar
Martin Jeřábek committed
149
            o.outcome := false;
150 151 152
            report "RX Buffer pointers are not 0 after Release Receieve Buffer" &
                    " command" severity error;
            -- LCOV_EXCL_START
153
        end if;
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

        ------------------------------------------------------------------------
        -- Generate the CAN frames and send them by Node 2
        ------------------------------------------------------------------------
        while send_more loop
            CAN_generate_frame(rand_ctr, CAN_frame);

            -- Evaluate if next frame should be sent
            if (CAN_frame.rtr = RTR_FRAME and
                CAN_frame.frame_format = NORMAL_CAN)
            then
                if (in_RX_buf + 4 > buf_info.rx_buff_size) then
                    send_more := false;
                end if;
            else
                if (CAN_frame.data_length mod 4 = 0) then
                    if ((in_RX_buf + CAN_frame.data_length / 4 + 4) >
                        buf_info.rx_buff_size)
                    then
                        send_more := false;
                    end if;
                else
                    if ((in_RX_buf + CAN_frame.data_length / 4 + 5) >
                        buf_info.rx_buff_size)
                    then
                        send_more := false;
                    end if;
                end if;
182
            end if;
183

Martin Jeřábek's avatar
Martin Jeřábek committed
184 185
            CAN_send_frame(CAN_frame, 1, ID_2, mem_bus(2), frame_sent);
            CAN_wait_frame_sent(ID_1, mem_bus(1));
186 187 188 189 190 191
            number_frms_sent := number_frms_sent + 1;
            in_RX_buf := in_RX_buf + CAN_frame.rwcnt + 1;

            --------------------------------------------------------------------
            -- Check that message count was incremented and memfree is correct!
            --------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
192
            get_rx_buf_state(buf_info, ID_1, mem_bus(1));
193
            if (number_frms_sent /= buf_info.rx_frame_count and send_more) then
194
                -- LCOV_EXCL_START
Martin Jeřábek's avatar
Martin Jeřábek committed
195
                o.outcome := false;
196 197 198
                report "Number of frames in RX Buffer not incremented"
                    severity error;
                -- LCOV_EXCL_STOP
199
            end if;
200 201 202
            if ((buf_info.rx_mem_free + in_RX_buf) /= buf_info.rx_buff_size
                and send_more)
            then
203
                -- LCOV_EXCL_START
Martin Jeřábek's avatar
Martin Jeřábek committed
204
                o.outcome := false;
Ille, Ondrej, Ing.'s avatar
Bug-fix  
Ille, Ondrej, Ing. committed
205
                report "RX Buffer free memory + Number of stored words does " &
206 207
                    "not equal to RX Buffer size!" severity error;
                -- LCOV_EXCL_STOP
Martin Jeřábek's avatar
Martin Jeřábek committed
208
            end if;
209 210

        end loop;
Martin Jeřábek's avatar
Martin Jeřábek committed
211

212 213 214 215
        ------------------------------------------------------------------------
        -- Check that data overrun status is set (we sent one more frame than
        -- needed... Overrun should be present
        ------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
216
        get_controller_status(status, ID_1, mem_bus(1));
217
        if (not status.data_overrun) then
218
            -- LCOV_EXCL_START
Martin Jeřábek's avatar
Martin Jeřábek committed
219
            o.outcome := false;
220 221
            report "Data overrun not ocurred as expected!" severity error;
            -- LCOV_EXCL_STOP
222
        end if;
Martin Jeřábek's avatar
Martin Jeřábek committed
223

224 225 226 227
        ------------------------------------------------------------------------
        -- Clear the data overrun flag
        ------------------------------------------------------------------------
        command.clear_data_overrun := true;
Martin Jeřábek's avatar
Martin Jeřábek committed
228
        give_controller_command(command, ID_1, mem_bus(1));
229 230 231 232 233
        command.clear_data_overrun := false;

        ------------------------------------------------------------------------
        -- Check that overrun flag was cleared
        ------------------------------------------------------------------------
Martin Jeřábek's avatar
Martin Jeřábek committed
234
        get_controller_status(status, ID_1, mem_bus(1));
235
        if (status.data_overrun) then
236
            -- LCOV_EXCL_START
Martin Jeřábek's avatar
Martin Jeřábek committed
237
            o.outcome := false;
238 239
            report "Data Overrun flag not active!" severity error;
            -- LCOV_EXCL_STOP
240
        end if;
Martin Jeřábek's avatar
Martin Jeřábek committed
241

242
    end procedure;
Martin Jeřábek's avatar
Martin Jeřábek committed
243

244
end package body;