Changeset 10256 for firmware/FTM/ftu_control
- Timestamp:
- 03/24/11 14:42:34 (14 years ago)
- Location:
- firmware/FTM/ftu_control
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FTM/ftu_control/FTM_ftu_control.vhd
r10227 r10256 109 109 -- list of active FTUs, read out from static RAM before starting to contact FTUs 110 110 signal active_FTU_array_sig : active_FTU_array_type := ((others => '0'), (others => '0'), (others => '0'), (others => '0')); 111 111 --signal active_FTU_array_sig : active_FTU_array_type := ("0000000000000001", (others => '0'), (others => '0'), (others => '0')); 112 112 113 -- signals to count the number of responding FTUs (per crate and total) in case of a ping 113 114 signal FTU_answer_array_sig : FTU_answer_array_type := (0,0,0,0); … … 129 130 130 131 -- global signals after multiplexer 131 signal rx_en_sig : std_logic := '0'; 132 signal tx_en_sig : std_logic := '0'; 133 signal rx_valid_sig : std_logic := '0'; 134 signal tx_busy_sig : std_logic := '0'; 135 signal tx_start_sig : std_logic := '0'; 136 signal tx_data_sig : std_logic_vector (7 DOWNTO 0) := (others => '0'); 132 signal rx_en_sig : std_logic := '0'; 133 signal tx_en_sig : std_logic := '0'; 134 signal rx_valid_sig : std_logic := '0'; 135 signal tx_busy_sig : std_logic := '0'; 136 signal tx_start_sig : std_logic := '0'; 137 signal tx_data_sig : std_logic_vector (7 DOWNTO 0) := (others => '0'); 138 signal rx_busy_sig : std_logic := '0'; 139 signal start_int_sig : std_logic := '0'; 137 140 138 141 -- signals for interpreter of FTU communication … … 163 166 signal rx_valid_0_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_0 164 167 signal rx_data_0_sig : std_logic_vector (7 DOWNTO 0); -- initialized in FTM_ftu_rs485_interface_0 168 signal rx_busy_0_sig : std_logic; -- initialized in FTU_rs485_interface_0 165 169 166 170 signal tx_start_1_sig : std_logic := '0'; … … 169 173 signal rx_valid_1_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_1 170 174 signal rx_data_1_sig : std_logic_vector (7 DOWNTO 0); -- initialized in FTM_ftu_rs485_interface_1 171 175 signal rx_busy_1_sig : std_logic; -- initialized in FTU_rs485_interface_1 176 172 177 signal tx_start_2_sig : std_logic := '0'; 173 178 signal tx_data_2_sig : std_logic_vector (7 DOWNTO 0) := (others => '0'); … … 175 180 signal rx_valid_2_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_2 176 181 signal rx_data_2_sig : std_logic_vector (7 DOWNTO 0); -- initialized in FTM_ftu_rs485_interface_2 177 182 signal rx_busy_2_sig : std_logic; -- initialized in FTU_rs485_interface_2 183 178 184 signal tx_start_3_sig : std_logic := '0'; 179 185 signal tx_data_3_sig : std_logic_vector (7 DOWNTO 0) := (others => '0'); … … 181 187 signal rx_valid_3_sig : std_logic; -- initialized in FTM_ftu_rs485_interface_3 182 188 signal rx_data_3_sig : std_logic_vector (7 DOWNTO 0); -- initialized in FTM_ftu_rs485_interface_3 183 189 signal rx_busy_3_sig : std_logic; -- initialized in FTU_rs485_interface_3 190 184 191 -- signals to control and read out CRC 185 192 signal sel_crc_input_source_sig : std_logic := '0'; -- 0 -> FSM, 1 -> interpreter … … 219 226 -- FPGA 220 227 rx_data : OUT std_logic_vector (7 DOWNTO 0); 221 --rx_busy : OUT std_logic := '0';228 rx_busy : OUT std_logic := '0'; 222 229 rx_valid : OUT std_logic := '0'; 223 230 tx_data : IN std_logic_vector (7 DOWNTO 0); … … 277 284 278 285 type FTM_ftu_rs485_control_StateType is (INIT, IDLE, ACTIVE_LIST, READ_CONFIG, TRANSMIT_CONFIG, 279 PING, PING_END, FTU_LIST, RATES, 286 PING, PING_END, FTU_LIST, 287 RATES, RATES_1, RATES_2, RATES_3, 280 288 READ_CONFIG_1, READ_CONFIG_2, READ_CONFIG_3, 281 289 TRANSMIT_CONFIG_1, TRANSMIT_CONFIG_2, TRANSMIT_CONFIG_3, … … 285 293 286 294 begin 287 295 288 296 Inst_FTM_fTU_rs485_interface_0 : FTM_ftu_rs485_interface -- crate 0 289 297 port map( … … 296 304 -- FPGA 297 305 rx_data => rx_data_0_sig, 298 --rx_busy =>,306 rx_busy => rx_busy_0_sig, 299 307 rx_valid => rx_valid_0_sig, 300 308 tx_data => tx_data_0_sig, … … 313 321 -- FPGA 314 322 rx_data => rx_data_1_sig, 315 --rx_busy =>,323 rx_busy => rx_busy_1_sig, 316 324 rx_valid => rx_valid_1_sig, 317 325 tx_data => tx_data_1_sig, … … 330 338 -- FPGA 331 339 rx_data => rx_data_2_sig, 332 --rx_busy =>,340 rx_busy => rx_busy_2_sig, 333 341 rx_valid => rx_valid_2_sig, 334 342 tx_data => tx_data_2_sig, … … 347 355 -- FPGA 348 356 rx_data => rx_data_3_sig, 349 --rx_busy =>,357 rx_busy => rx_busy_3_sig, 350 358 rx_valid => rx_valid_3_sig, 351 359 tx_data => tx_data_3_sig, … … 369 377 clk => clk_50MHz, 370 378 data_block => rec_block_sig, 371 block_valid => rec_valid_sig,379 block_valid => start_int_sig, 372 380 crc => crc_sig, 373 381 FTU_brd_add => FTU_brd_add_sig, … … 427 435 ping_all_started <= '1'; 428 436 read_rates_started <= '0'; 437 rec_reset_sig <= '1'; 429 438 FTM_ftu_rs485_control_State <= PING; 430 439 elsif (new_config = '0' and ping_all = '0' and read_rates = '1') then … … 486 495 FTU_register_cnt <= 0; 487 496 if (active_FTU_array_sig(crate_cnt)(FTU_cnt) = '1') then 497 rec_reset_sig <= '1'; 488 498 FTM_ftu_rs485_control_State <= TRANSMIT_CONFIG; 489 499 else … … 644 654 end if; 645 655 end if; 646 656 647 657 when PING => -- ping all FTUs 648 658 rec_reset_sig <= '0'; … … 679 689 when PING_1 => -- wait one cycle for CRC calculation 680 690 enable_crc_from_FSM_sig <= '0'; 691 rec_reset_sig <= '1'; 681 692 FTM_ftu_rs485_control_State <= PING_2; 682 693 683 694 when PING_2 => -- transmit byte by byte 695 rec_reset_sig <= '0'; 684 696 if (tx_busy_sig = '0') then 685 697 if (frame_cnt < 27) then … … 789 801 ping_all_done <= '1'; 790 802 sel_crate_sig <= "111"; 803 FTU_answer_array_sig(0) <= 0; 804 FTU_answer_array_sig(1) <= 0; 805 FTU_answer_array_sig(2) <= 0; 806 FTU_answer_array_sig(3) <= 0; 807 no_of_FTU_answer_sig <= 0; 791 808 FTM_ftu_rs485_control_State <= IDLE; 792 809 end if; … … 818 835 819 836 when RATES => -- read all FTU rates 820 FTM_ftu_rs485_control_State <= IDLE; 821 837 rec_reset_sig <= '0'; 838 if (crate_cnt < NO_OF_CRATES) then 839 sel_crate_sig <= conv_std_logic_vector(crate_cnt, 3); 840 if (FTU_cnt < NO_OF_FTUS_PER_CRATE) then 841 FTU_cnt <= FTU_cnt + 1; 842 if (active_FTU_array_sig(crate_cnt)(FTU_cnt) = '1') then 843 enable_crc_from_FSM_sig <= '1'; 844 crc_data_from_FSM_sig <= "00000000" 845 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000" 846 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000" 847 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000" 848 & "00000000" & "00000000" & "00000000" & "00000000" & "00000000" & "00000000" 849 & "00000010" & FIRMWARE_ID & FTM_ADDRESS 850 & "00" & conv_std_logic_vector(FTU_cnt,4) & conv_std_logic_vector(crate_cnt,2) 851 & FTU_RS485_START_DELIM; 852 FTU_brd_add_sig <= conv_std_logic_vector(FTU_cnt,4) & conv_std_logic_vector(crate_cnt,2); 853 FTU_command_sig <= "00000010"; 854 FTM_ftu_rs485_control_State <= RATES_1; 855 else 856 FTM_ftu_rs485_control_State <= RATES; 857 end if; 858 else 859 crate_cnt <= crate_cnt + 1; 860 FTU_cnt <= 0; 861 FTM_ftu_rs485_control_State <= RATES; 862 end if; 863 else 864 crate_cnt <= 0; 865 read_rates_started <= '0'; 866 read_rates_done <= '1'; 867 sel_crate_sig <= "111"; 868 FTM_ftu_rs485_control_State <= IDLE; 869 end if; 870 871 when RATES_1 => -- wait one cycle for CRC calculation 872 enable_crc_from_FSM_sig <= '0'; 873 FTM_ftu_rs485_control_State <= RATES_2; 874 875 when RATES_2 => -- transmit byte by byte 876 if (tx_busy_sig = '0') then 877 if (frame_cnt < 27) then 878 frame_cnt <= frame_cnt + 1; 879 tx_data_sig <= crc_data_from_FSM_sig (7 downto 0); 880 crc_data_from_FSM_sig <= "00000000" & crc_data_from_FSM_sig ((FTU_RS485_BLOCK_WIDTH - 9) downto 8); 881 tx_start_sig <= '1'; 882 FTM_ftu_rs485_control_State <= RATES_2; 883 elsif (frame_cnt = 27) then 884 frame_cnt <= frame_cnt + 1; 885 tx_data_sig <= crc_sig; 886 tx_start_sig <= '1'; 887 FTM_ftu_rs485_control_State <= RATES_2; 888 else 889 frame_cnt <= 0; 890 reset_crc_from_FSM_sig <= '1'; 891 FTM_ftu_rs485_control_State <= RATES_3; 892 end if; 893 else 894 tx_start_sig <= '0'; 895 FTM_ftu_rs485_control_State <= RATES_2; 896 end if; 897 898 when RATES_3 => -- wait for FTU answer 899 reset_crc_from_FSM_sig <= '0'; 900 if (FTU_answer_ok_sig = '1') then 901 timeout_cnt <= 0; 902 sel_crc_input_source_sig <= '0'; 903 FTM_ftu_rs485_control_State <= RATES; 904 else 905 if (timeout_cnt < FTU_RS485_TIMEOUT) then 906 timeout_cnt <= timeout_cnt + 1; 907 sel_crc_input_source_sig <= '1'; 908 FTM_ftu_rs485_control_State <= RATES_3; 909 else 910 timeout_cnt <= 0; 911 sel_crc_input_source_sig <= '0'; 912 rec_reset_sig <= '1'; 913 if (retry_cnt < FTU_RS485_NO_OF_RETRY) then 914 retry_cnt <= retry_cnt + 1; 915 FTU_cnt <= FTU_cnt - 1; -- repeat this FTU 916 FTM_ftu_rs485_control_State <= RATES; 917 else 918 FTU_cnt <= FTU_cnt; -- move on 919 FTM_ftu_rs485_control_State <= RATES; 920 end if; 921 end if; 922 end if; 923 822 924 end case; 823 925 end if; … … 831 933 rx_data_0_sig, rx_data_1_sig, rx_data_2_sig, rx_data_3_sig, 832 934 tx_busy_0_sig, tx_busy_1_sig, tx_busy_2_sig, tx_busy_3_sig, 935 rx_busy_0_sig, rx_busy_1_sig, rx_busy_2_sig, rx_busy_3_sig, 833 936 tx_start_sig, tx_data_sig) 834 937 begin … … 840 943 rec_data_sig <= rx_data_0_sig; 841 944 tx_busy_sig <= tx_busy_0_sig; 945 rx_busy_sig <= rx_busy_0_sig; 842 946 tx_start_0_sig <= tx_start_sig; 843 947 tx_start_1_sig <= '0'; … … 854 958 rec_data_sig <= rx_data_1_sig; 855 959 tx_busy_sig <= tx_busy_1_sig; 960 rx_busy_sig <= rx_busy_1_sig; 856 961 tx_start_0_sig <= '0'; 857 962 tx_start_1_sig <= tx_start_sig; … … 868 973 rec_data_sig <= rx_data_2_sig; 869 974 tx_busy_sig <= tx_busy_2_sig; 975 rx_busy_sig <= rx_busy_2_sig; 870 976 tx_start_0_sig <= '0'; 871 977 tx_start_1_sig <= '0'; … … 882 988 rec_data_sig <= rx_data_3_sig; 883 989 tx_busy_sig <= tx_busy_3_sig; 990 rx_busy_sig <= rx_busy_3_sig; 884 991 tx_start_0_sig <= '0'; 885 992 tx_start_1_sig <= '0'; … … 896 1003 rec_data_sig <= (others => '0'); 897 1004 tx_busy_sig <= '0'; 1005 rx_busy_sig <= '0'; 898 1006 tx_start_0_sig <= '0'; 899 1007 tx_start_1_sig <= '0'; … … 933 1041 934 1042 crc_sig <= crc_sig_inv(0) & crc_sig_inv(1) & crc_sig_inv(2) & crc_sig_inv(3) & crc_sig_inv(4) & crc_sig_inv(5) & crc_sig_inv(6) & crc_sig_inv(7); 1043 start_int_sig <= rec_valid_sig and (not rx_busy_sig); -- avoid continuing to early after FTU answer 935 1044 936 1045 end Behavioral; -
firmware/FTM/ftu_control/FTM_ftu_rs485_interface.vhd
r10175 r10256 17 17 18 18 library ftm_definitions; 19 --USE ftm_definitions.ftm_array_types.all;19 USE ftm_definitions.ftm_array_types.all; 20 20 USE ftm_definitions.ftm_constants.all; 21 21 … … 34 34 -- FPGA 35 35 rx_data : OUT std_logic_vector (7 DOWNTO 0); 36 --rx_busy : OUT std_logic := '0';36 rx_busy : OUT std_logic := '0'; 37 37 rx_valid : OUT std_logic := '0'; 38 38 tx_data : IN std_logic_vector (7 DOWNTO 0); … … 122 122 rx_en <= flow_ctrl; 123 123 rx_data <= rx_sr; 124 --rx_busy <= '1' when (rx_bitcnt < 11) else '0';124 rx_busy <= '1' when (rx_bitcnt < 11) else '0'; 125 125 126 126 END ARCHITECTURE beha;
Note:
See TracChangeset
for help on using the changeset viewer.