| 1 | ----------------------------------------------------------------------------------
|
|---|
| 2 | -- Company: ETH Zurich, Institute for Particle Physics
|
|---|
| 3 | -- Engineer: Q. Weitzel, P. Vogler
|
|---|
| 4 | --
|
|---|
| 5 | -- Create Date: 09/13/2010
|
|---|
| 6 | -- Design Name:
|
|---|
| 7 | -- Module Name: FTU_rs485_interpreter - Behavioral
|
|---|
| 8 | -- Project Name:
|
|---|
| 9 | -- Target Devices:
|
|---|
| 10 | -- Tool versions:
|
|---|
| 11 | -- Description: command interpreter of FTU RS485 module
|
|---|
| 12 | --
|
|---|
| 13 | -- Dependencies:
|
|---|
| 14 | --
|
|---|
| 15 | -- Revision:
|
|---|
| 16 | -- Revision 0.01 - File Created
|
|---|
| 17 | -- Additional Comments:
|
|---|
| 18 | --
|
|---|
| 19 | ----------------------------------------------------------------------------------
|
|---|
| 20 |
|
|---|
| 21 | library IEEE;
|
|---|
| 22 | use IEEE.STD_LOGIC_1164.ALL;
|
|---|
| 23 | use IEEE.STD_LOGIC_ARITH.ALL;
|
|---|
| 24 | use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
|---|
| 25 |
|
|---|
| 26 | library ftu_definitions;
|
|---|
| 27 | USE ftu_definitions.ftu_array_types.all;
|
|---|
| 28 | USE ftu_definitions.ftu_constants.all;
|
|---|
| 29 |
|
|---|
| 30 | ---- Uncomment the following library declaration if instantiating
|
|---|
| 31 | ---- any Xilinx primitives in this code.
|
|---|
| 32 | --library UNISIM;
|
|---|
| 33 | --use UNISIM.VComponents.all;
|
|---|
| 34 |
|
|---|
| 35 | entity FTU_rs485_interpreter is
|
|---|
| 36 | port(
|
|---|
| 37 | clk : IN std_logic;
|
|---|
| 38 | data_block : IN std_logic_vector(RS485_BLOCK_WIDTH - 1 downto 0);
|
|---|
| 39 | block_valid : IN std_logic;
|
|---|
| 40 | brd_add : IN std_logic_vector(5 downto 0);
|
|---|
| 41 | int_new_DACs : OUT std_logic := '0';
|
|---|
| 42 | int_new_enables : OUT std_logic := '0';
|
|---|
| 43 | int_new_prescaling : OUT std_logic := '0';
|
|---|
| 44 | int_read_rates : OUT std_logic := '0';
|
|---|
| 45 | int_read_DACs : OUT std_logic := '0';
|
|---|
| 46 | int_read_enables : OUT std_logic := '0';
|
|---|
| 47 | int_read_prescaling : OUT std_logic := '0';
|
|---|
| 48 | dac_array_rs485_out : OUT dac_array_type;
|
|---|
| 49 | enable_array_rs485_out : OUT enable_array_type;
|
|---|
| 50 | prescaling_rs485_out : OUT STD_LOGIC_VECTOR(7 downto 0)
|
|---|
| 51 | );
|
|---|
| 52 | end FTU_rs485_interpreter;
|
|---|
| 53 |
|
|---|
| 54 | architecture Behavioral of FTU_rs485_interpreter is
|
|---|
| 55 |
|
|---|
| 56 | signal block_valid_sr : std_logic_vector(3 downto 0) := (others => '0');
|
|---|
| 57 |
|
|---|
| 58 | signal dac_array_rs485_out_sig : dac_array_type := DEFAULT_DAC;
|
|---|
| 59 | signal enable_array_rs485_out_sig : enable_array_type := DEFAULT_ENABLE;
|
|---|
| 60 | signal prescaling_rs485_out_sig : STD_LOGIC_VECTOR(7 downto 0) := conv_std_logic_vector(DEFAULT_PRESCALING,8);
|
|---|
| 61 |
|
|---|
| 62 | type FTU_rs485_interpreter_StateType is (WAIT_FOR_DATA, CHECK_HEADER, DECODE);
|
|---|
| 63 | signal FTU_rs485_interpreter_State : FTU_rs485_interpreter_StateType;
|
|---|
| 64 |
|
|---|
| 65 | begin
|
|---|
| 66 |
|
|---|
| 67 | FTU_rs485_interpreter_FSM: process (clk)
|
|---|
| 68 | begin
|
|---|
| 69 | if Rising_edge(clk) then
|
|---|
| 70 | case FTU_rs485_interpreter_State is
|
|---|
| 71 |
|
|---|
| 72 | when WAIT_FOR_DATA => -- default state, waiting for valid 16-byte block
|
|---|
| 73 | block_valid_sr <= block_valid_sr(2 downto 0) & block_valid;
|
|---|
| 74 | int_new_DACs <= '0';
|
|---|
| 75 | int_new_enables <= '0';
|
|---|
| 76 | int_new_prescaling <= '0';
|
|---|
| 77 | int_read_rates <= '0';
|
|---|
| 78 | int_read_DACs <= '0';
|
|---|
| 79 | int_read_enables <= '0';
|
|---|
| 80 | int_read_prescaling <= '0';
|
|---|
| 81 | if (block_valid_sr(3 downto 2) = "01") then -- rising edge of valid signal
|
|---|
| 82 | FTU_rs485_interpreter_State <= CHECK_HEADER;
|
|---|
| 83 | else
|
|---|
| 84 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 85 | end if;
|
|---|
| 86 |
|
|---|
| 87 | when CHECK_HEADER => -- check start delimiter and addresses
|
|---|
| 88 | int_new_DACs <= '0';
|
|---|
| 89 | int_new_enables <= '0';
|
|---|
| 90 | int_new_prescaling <= '0';
|
|---|
| 91 | int_read_rates <= '0';
|
|---|
| 92 | int_read_DACs <= '0';
|
|---|
| 93 | int_read_enables <= '0';
|
|---|
| 94 | int_read_prescaling <= '0';
|
|---|
| 95 | if (data_block(7 downto 0) = RS485_START_DELIM) and
|
|---|
| 96 | (data_block(15 downto 8) = ("00" & brd_add)) and
|
|---|
| 97 | (data_block(23 downto 16) = FTM_ADDRESS) then
|
|---|
| 98 | FTU_rs485_interpreter_State <= DECODE;
|
|---|
| 99 | else
|
|---|
| 100 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 101 | end if;
|
|---|
| 102 |
|
|---|
| 103 | when DECODE => -- decode instruction
|
|---|
| 104 | if(data_block(31 downto 24) = "00000000") then
|
|---|
| 105 | int_new_DACs <= '1';
|
|---|
| 106 | int_new_enables <= '0';
|
|---|
| 107 | int_new_prescaling <= '0';
|
|---|
| 108 | int_read_rates <= '0';
|
|---|
| 109 | int_read_DACs <= '0';
|
|---|
| 110 | int_read_enables <= '0';
|
|---|
| 111 | int_read_prescaling <= '0';
|
|---|
| 112 | dac_array_rs485_out_sig <= (conv_integer(unsigned(data_block(47 downto 32))),
|
|---|
| 113 | conv_integer(unsigned(data_block(63 downto 48))),
|
|---|
| 114 | conv_integer(unsigned(data_block(79 downto 64))),
|
|---|
| 115 | conv_integer(unsigned(data_block(95 downto 80))),
|
|---|
| 116 | 0,0,0,
|
|---|
| 117 | conv_integer(unsigned(data_block(111 downto 96)))
|
|---|
| 118 | );
|
|---|
| 119 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 120 | elsif (data_block(31 downto 24) = "00000001") then
|
|---|
| 121 | int_new_DACs <= '0';
|
|---|
| 122 | int_new_enables <= '0';
|
|---|
| 123 | int_new_prescaling <= '0';
|
|---|
| 124 | int_read_rates <= '0';
|
|---|
| 125 | int_read_DACs <= '1';
|
|---|
| 126 | int_read_enables <= '0';
|
|---|
| 127 | int_read_prescaling <= '0';
|
|---|
| 128 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 129 | elsif (data_block(31 downto 24) = "00000010") then
|
|---|
| 130 | int_new_DACs <= '0';
|
|---|
| 131 | int_new_enables <= '0';
|
|---|
| 132 | int_new_prescaling <= '0';
|
|---|
| 133 | int_read_rates <= '1';
|
|---|
| 134 | int_read_DACs <= '0';
|
|---|
| 135 | int_read_enables <= '0';
|
|---|
| 136 | int_read_prescaling <= '0';
|
|---|
| 137 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 138 | elsif (data_block(31 downto 24) = "00000011") then
|
|---|
| 139 | int_new_DACs <= '0';
|
|---|
| 140 | int_new_enables <= '1';
|
|---|
| 141 | int_new_prescaling <= '0';
|
|---|
| 142 | int_read_rates <= '0';
|
|---|
| 143 | int_read_DACs <= '0';
|
|---|
| 144 | int_read_enables <= '0';
|
|---|
| 145 | int_read_prescaling <= '0';
|
|---|
| 146 | enable_array_rs485_out_sig <= (data_block(47 downto 32),
|
|---|
| 147 | data_block(63 downto 48),
|
|---|
| 148 | data_block(79 downto 64),
|
|---|
| 149 | data_block(95 downto 80)
|
|---|
| 150 | );
|
|---|
| 151 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 152 | elsif (data_block(31 downto 24) = "00000100") then
|
|---|
| 153 | int_new_DACs <= '0';
|
|---|
| 154 | int_new_enables <= '0';
|
|---|
| 155 | int_new_prescaling <= '0';
|
|---|
| 156 | int_read_rates <= '0';
|
|---|
| 157 | int_read_DACs <= '0';
|
|---|
| 158 | int_read_enables <= '1';
|
|---|
| 159 | int_read_prescaling <= '0';
|
|---|
| 160 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 161 | elsif (data_block(31 downto 24) = "00000110") then
|
|---|
| 162 | int_new_DACs <= '0';
|
|---|
| 163 | int_new_enables <= '0';
|
|---|
| 164 | int_new_prescaling <= '1';
|
|---|
| 165 | int_read_rates <= '0';
|
|---|
| 166 | int_read_DACs <= '0';
|
|---|
| 167 | int_read_enables <= '0';
|
|---|
| 168 | int_read_prescaling <= '0';
|
|---|
| 169 | prescaling_rs485_out_sig <= data_block(39 downto 32);
|
|---|
| 170 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 171 | elsif (data_block(31 downto 24) = "00000111") then
|
|---|
| 172 | int_new_DACs <= '0';
|
|---|
| 173 | int_new_enables <= '0';
|
|---|
| 174 | int_new_prescaling <= '0';
|
|---|
| 175 | int_read_rates <= '0';
|
|---|
| 176 | int_read_DACs <= '0';
|
|---|
| 177 | int_read_enables <= '0';
|
|---|
| 178 | int_read_prescaling <= '1';
|
|---|
| 179 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 180 | else
|
|---|
| 181 | int_new_DACs <= '0';
|
|---|
| 182 | int_new_enables <= '0';
|
|---|
| 183 | int_new_prescaling <= '0';
|
|---|
| 184 | int_read_rates <= '0';
|
|---|
| 185 | int_read_DACs <= '0';
|
|---|
| 186 | int_read_enables <= '0';
|
|---|
| 187 | int_read_prescaling <= '0';
|
|---|
| 188 | FTU_rs485_interpreter_State <= WAIT_FOR_DATA;
|
|---|
| 189 | end if;
|
|---|
| 190 |
|
|---|
| 191 | end case;
|
|---|
| 192 | end if;
|
|---|
| 193 | end process FTU_rs485_interpreter_FSM;
|
|---|
| 194 |
|
|---|
| 195 | dac_array_rs485_out <= dac_array_rs485_out_sig;
|
|---|
| 196 | enable_array_rs485_out <= enable_array_rs485_out_sig;
|
|---|
| 197 | prescaling_rs485_out <= prescaling_rs485_out_sig;
|
|---|
| 198 |
|
|---|
| 199 | end Behavioral;
|
|---|