bit_time_fsm.vhd 6.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
--------------------------------------------------------------------------------
-- 
-- CTU CAN FD IP Core
-- Copyright (C) 2015-2018
-- 
-- Authors:
--     Ondrej Ille <ondrej.ille@gmail.com>
--     Martin Jerabek <martin.jerabek01@gmail.com>
-- 
-- Project advisors: 
-- 	Jiri Novak <jnovak@fel.cvut.cz>
-- 	Pavel Pisa <pisa@cmp.felk.cvut.cz>
-- 
-- Department of Measurement         (http://meas.fel.cvut.cz/)
-- Faculty of Electrical Engineering (http://www.fel.cvut.cz)
-- Czech Technical University        (http://www.cvut.cz/)
-- 
-- 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
-- Component is furnished to do so, subject to the following conditions:
-- 
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Component.
-- 
-- 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
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE COMPONENT OR THE USE OR OTHER DEALINGS
-- IN THE COMPONENT.
-- 
-- 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
-- protocol license from Bosch.
-- 
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Purpose:
44 45
--  Bit time FSM.
--------------------------------------------------------------------------------
46
-- Revision History:
47
--    15.02.2019   Created file
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
--------------------------------------------------------------------------------

Library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
use ieee.math_real.ALL;

Library work;
use work.id_transfer.all;
use work.can_constants.all;
use work.can_components.all;
use work.can_types.all;
use work.cmn_lib.all;
use work.drv_stat_pkg.all;
use work.endian_swap.all;
use work.reduce_lib.all;

use work.CAN_FD_register_map.all;
use work.CAN_FD_frame_format.all;

68
entity bit_time_fsm is
69 70
    generic (
        -- Reset polarity
71
        reset_polarity  : std_logic := '0'
72 73 74 75 76 77 78 79 80
    );
    port(
        -----------------------------------------------------------------------
        -- Clock and reset
        -----------------------------------------------------------------------
        signal clk_sys          : in    std_logic;
        signal res_n            : in    std_logic;

        -----------------------------------------------------------------------
81 82 83 84 85 86 87 88 89 90 91 92
        -- Control interface 
        -----------------------------------------------------------------------
        -- Signalling segment end (either due to re-sync, or reaching expected
        -- length of segment)
        signal segm_end         : in    std_logic;
        signal h_sync_valid     : in    std_logic;

        -- Core is enabled
        signal drv_ena          : in    std_logic;
        
        -----------------------------------------------------------------------
        -- Status signals 
93
        -----------------------------------------------------------------------
94 95 96 97 98 99 100 101 102 103
        -- Bit time is in TSEG1
        signal is_tseg1         : out   std_logic;
        
        -- Bit time is in TSEG2
        signal is_tseg2         : out   std_logic;
        
        -- Sample point request (to sample point generator)
        signal sample_req       : out   std_logic;
        
        -- Sync signal request
104 105 106 107
        signal sync_req         : out   std_logic;
        
        -- Bit time FSM output
        signal bt_FSM_out       : out   bit_time_type
108 109 110
    );
end entity;

111
architecture rtl of bit_time_fsm is
112

113 114 115
    -- Bit time FSM
    signal current_state    : bit_time_type;
    signal next_state       : bit_time_type;
116

117 118
    -- Bit time FSM clock enable
    signal bt_fsm_ce        : std_logic;
119 120 121
    
begin

122 123 124
    ----------------------------------------------------------------------------
    -- Next state process (combinational)
    ----------------------------------------------------------------------------
125
    next_state_proc : process(current_state, h_sync_valid, segm_end, drv_ena)
126 127
    begin
        next_state <= current_state;
128
    
129 130 131 132
        if (drv_ena = CTU_CAN_DISABLED) then
            next_state <= reset;
        elsif (h_sync_valid = '1') then
            next_state <= tseg1;
133
        else
134 135
            case current_state is
            when tseg1 =>
136 137 138
                if (segm_end = '1') then
                    next_state <= tseg2;
                end if;
139
            when tseg2 =>
140 141 142
                if (segm_end = '1') then
                    next_state <= tseg1;
                end if;
143 144 145 146 147
            when reset =>
                next_state <= tseg1;
            end case;
        end if;
    end process;
148
    
149 150 151
    -- State register to output propagation
    bt_FSM_out <= current_state;
    
152 153 154
    ----------------------------------------------------------------------------
    -- Current state process (combinational)
    ----------------------------------------------------------------------------
155
    curr_state_proc : process(current_state, segm_end)
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    begin
        -- Default values
        is_tseg1       <= '0';
        is_tseg2       <= '0';
        sample_req     <= '0';
        sync_req       <= '0';
        
        case current_state is
        when reset =>
        when tseg1 =>
            is_tseg1 <= '1';
            if (segm_end = '1') then
                sample_req <= '1';
            end if;
            
        when tseg2 =>
            is_tseg2 <= '1';
            if (segm_end = '1') then
                sync_req <= '1';
            end if;
            
        end case;
    end process;
179
    
180 181 182 183
    ----------------------------------------------------------------------------
    -- State register assignment
    ----------------------------------------------------------------------------
    state_reg_proc : process(clk_sys, res_n)
184 185
    begin
        if (res_n = reset_polarity) then
186
            current_state <= reset;
187
        elsif (rising_edge(clk_sys)) then
188 189
            if (bt_fsm_ce = '1') then
                current_state <= next_state;
190 191 192 193
            end if;
        end if;
    end process;
    
194 195
    bt_fsm_ce <= '1' when (next_state /= current_state) else
                 '0'; 
196 197

end architecture rtl;