Changeset 10137 for firmware/FAD/FACT_FAD_20MHz_VAR_PS
- Timestamp:
- 02/08/11 08:17:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/w5300_modul.vhd
r10129 r10137 1 ----------------------------------------------------------------------------------2 -- Company:3 -- Engineer:4 --5 -- Create Date: 11:48:48 11/10/20096 -- Design Name:7 1 -- Module Name: w5300_modul - Behavioral 8 -- Project Name:9 -- Target Devices:10 -- Tool versions:11 -- Description:12 --13 -- Dependencies:14 --15 -- Revision:16 -- Revision 0.01 - File Created17 -- Additional Comments:18 --19 ----------------------------------------------------------------------------------20 2 library IEEE; 21 3 use IEEE.STD_LOGIC_1164.ALL; … … 24 6 library FACT_FAD_lib; 25 7 use FACT_FAD_lib.fad_definitions.ALL; 26 27 ---- Uncomment the following library declaration if instantiating28 ---- any Xilinx primitives in this code.29 --library UNISIM;30 --use UNISIM.VComponents.all;31 8 32 9 ENTITY w5300_modul IS … … 57 34 c_trigger_enable: out std_logic := '0'; 58 35 c_trigger_mult: out std_logic_vector (7 DOWNTO 0) := (OTHERS => '1'); --subject to changes 59 -- 36 37 -- FAD configuration signals: 38 ------------------------------------------------------------------------------ 39 -- start entire configuration chain 60 40 new_config : OUT std_logic := '0'; 61 41 config_started : in std_logic; 42 -- read/write configRAM 62 43 config_addr : out std_logic_vector (7 downto 0); 63 44 config_data : inout std_logic_vector (15 downto 0) := (others => 'Z'); 64 45 config_wr_en : out std_logic := '0'; 65 46 config_rd_en : out std_logic := '0'; 66 -- --67 47 config_rw_ack, config_rw_ready : in std_logic; 68 -- --69 48 config_busy : in std_logic; 49 ------------------------------------------------------------------------------ 70 50 51 -- MAC/IP calculation signals: 52 ------------------------------------------------------------------------------ 71 53 MAC_jumper : in std_logic_vector (1 downto 0); 72 54 BoardID : in std_logic_vector (3 downto 0); 73 55 CrateID : in std_logic_vector (1 downto 0); 56 ------------------------------------------------------------------------------ 74 57 58 -- user controllable enable signals 59 ------------------------------------------------------------------------------ 60 trigger_enable : out std_logic := '0'; -- default triggers are NOT accepted 75 61 denable : out std_logic := '0'; -- default domino wave off 76 62 dwrite_enable : out std_logic := '0'; -- default DWRITE low. 77 63 sclk_enable : out std_logic := '1'; -- default DWRITE HIGH. 78 ps_direction : out std_logic := '1'; -- default phase shift upwards 64 srclk_enable : out std_logic := '1'; -- default SRCLK on. 65 ------------------------------------------------------------------------------ 66 67 -- ADC CLK generator, is able to shift phase with respect to X_50M 68 -- these signals control the behavior of the digital clock manager (DCM) 69 ------------------------------------------------------------------------------ 70 ps_direction : out std_logic := '1'; -- default phase shift upwards 79 71 ps_do_phase_shift : out std_logic := '0'; --pulse this to phase shift once 80 72 ps_reset : out std_logic := '0'; -- pulse this to reset the variable phase shift 81 82 srclk_enable : out std_logic := '1'; -- default SRCLK on.83 84 trigger_enable : out std_logic := '0'; -- default triggers are NOT accepted 85 73 ------------------------------------------------------------------------------ 74 75 -- signals used to control FAD LED bahavior: 76 -- one of the three LEDs is used for com-status info 77 ------------------------------------------------------------------------------ 86 78 socks_waiting : out std_logic; 87 79 socks_connected: out std_logic 80 ------------------------------------------------------------------------------ 81 82 88 83 ); 89 90 -- Declarations91 92 84 END w5300_modul ; 93 85 … … 154 146 signal data_valid_int : std_logic := '0'; 155 147 148 149 -- signals used for MAC/IP calculation: 150 -- these 2 synch in, the jumper state. 156 151 signal FAD_in_cam : std_logic := '0'; 157 152 signal FAD_at_ETHZ : std_logic := '0'; 153 -- these 2 synch in the FMP lines encoding the FAD position in the cam. 158 154 signal bid : std_logic_vector (3 downto 0); 159 155 signal cid : std_logic_vector (1 downto 0); 160 161 162 -- only for debugging 163 --signal error_cnt : std_logic_vector (7 downto 0) := (others => '0'); 164 --signal last_trigger_id : std_logic_vector (15 downto 0) := (others => '0'); 165 166 167 -- signals for different socket modes: DN 04.01.11 168 signal socket_nr_counter : integer range 1 to 7 :=1; --used to determine which socket is used for data sending 169 signal socket_send_mode : std_logic := '0'; -- if 0 data is send via socket 0; if 1 data is send via the other sockets. 170 156 -- these are just used as local variables, to make reading easier. 171 157 signal mac_loc : mac_type; 172 158 signal ip_loc : ip_type; … … 174 160 signal netmask_loc : ip_type; 175 161 162 -- signals for synching in asynchronous input signals 163 ------------------------------------------------------------------------------ 164 signal w5300_interrupt_sr : std_logic_vector(1 downto 0); 165 ------------------------------------------------------------------------------ 166 167 168 -- only for debugging 169 --signal error_cnt : std_logic_vector (7 downto 0) := (others => '0'); 170 --signal last_trigger_id : std_logic_vector (15 downto 0) := (others => '0'); 171 172 173 -- signals for different socket modes: DN 04.01.11 174 signal socket_nr_counter : integer range 1 to 7 :=1; --used to determine which socket is used for data sending 175 signal socket_send_mode : std_logic := '0'; -- if 0 data is send via socket 0; if 1 data is send via the other sockets. 176 176 177 177 begin … … 182 182 183 183 184 w5300_ init_proc : process (clk, int)184 w5300_proc : process (clk) 185 185 begin 186 if rising_edge (clk) then 187 -- synch asynchronous input in: 188 w5300_interrupt_sr <= w5300_interrupt_sr(1) & int; 186 189 187 if rising_edge (clk) then 188 189 -- Interrupt low 190 if (int = '0') and (interrupt_ignore = '0') then 190 -- interrupt is handled synchronously 191 -- W5300 pulls low its interrpt line in case of: 192 -- ??? I don't know ... connection loss ??? 193 194 if (w5300_interrupt_sr = "01") and (interrupt_ignore = '0') then 191 195 case state_interrupt_1 is 192 196 when IR1_01 => 193 197 int_flag <= '1'; 194 198 busy <= '1'; 195 state_interrupt_1 <= IR1_02; 199 state_interrupt_1 <= IR1_02; --wait one cycle 196 200 when IR1_02 => 197 201 state_interrupt_1 <= IR1_03; … … 200 204 socket_cnt <= "000"; 201 205 ram_access <= '0'; 202 zaehler <= X"00000"; 203 count <= "000"; 206 zaehler <= X"00000"; --what is this zaehler counting? 207 count <= "000"; --what is this count counting? 204 208 int_flag <= '0'; 205 209 interrupt_ignore <= '1'; 206 state_interrupt_1 <= IR1_04; 210 state_interrupt_1 <= IR1_04; --this state is not existing? bad coding habit??? 207 211 when others => 208 212 null; … … 220 224 next_state <= INTERRUPT; 221 225 state_interrupt_2 <= IR2_02; 222 when IR2_02 => 226 227 -- check if it was a Sx Interrupt of Socket n 228 -- therfor: loop over all channel. 229 -- if the loop ended but no Sx Interrupt was found --> IR2_06 230 -- if an Sx Interrupt was found go to --> IR2_03 and check what happened. 231 when IR2_02 => 223 232 if (data_read (conv_integer(socket_cnt)) = '1') then -- Sx Interrupt 224 233 state_interrupt_2 <= IR2_03; 225 234 else 226 227 228 229 230 state_interrupt_2 <= IR2_02; 231 235 socket_cnt <= socket_cnt + 1; 236 if (socket_cnt = 7) then 237 state_interrupt_2 <= IR2_06; 238 else 239 state_interrupt_2 <= IR2_02; -- go on with loop 240 end if; 232 241 end if; 242 243 -- check the Interrupt register of the Socket, which caused the Interrupt. 233 244 when IR2_03 => 234 245 par_addr <= W5300_S0_IR + socket_cnt * W5300_S_INC; -- Sx Interrupt Register … … 236 247 next_state <= INTERRUPT; 237 248 state_interrupt_2 <= IR2_04; 249 -- before checking what happened, clear the Interrupt register, so we can proceed. 238 250 when IR2_04 => 239 251 par_addr <= W5300_S0_IR + socket_cnt * W5300_S_INC; … … 242 254 next_state <= INTERRUPT; 243 255 state_interrupt_2 <= IR2_05; 256 -- send the command to close this socket 257 -- then go back and read the main Interrupt register again, 258 -- if this was not Socket 7 ... if it was Socket 7, we're done anyway. 244 259 when IR2_05 => 245 260 par_addr <= W5300_S0_CR + socket_cnt * W5300_S_INC; … … 254 269 end if; 255 270 271 -- we go on and reset, the W5300 and this entire state machine. 256 272 when IR2_06 => 257 273 state_interrupt_1 <= IR1_01; … … 263 279 -- reset W5300 264 280 when RESET => 265 266 281 socket_send_mode <= '0'; 282 busy <= '1'; 267 283 zaehler <= zaehler + 1; 268 284 socks_waiting <= '0'; 269 270 271 --led <= X"FF";285 socks_connected <= '0'; 286 wiz_reset <= '0'; 287 --led <= X"FF"; 272 288 if (zaehler >= X"00064") then -- wait 2µs 273 289 wiz_reset <= '1'; … … 288 304 -- Init 289 305 when INIT => 290 -- status of MAC jumpers is synched in 291 -- and Board- and CrateID are synched in 292 FAD_in_cam <= MAC_jumper(1); -- see position of jumpers in FACT logbook 293 FAD_at_ETHZ <= MAC_jumper(0); -- MAC_jumper(1) is where D_T(7) was; MAC_jumper(0) is where D_T(6) was; 294 bid <= BoardID; 295 cid <= CrateID; 296 -- 306 -- status of MAC jumpers is synched in 307 -- and Board- and CrateID are synched in 308 FAD_in_cam <= MAC_jumper(1); -- see position of jumpers in FACT logbook 309 FAD_at_ETHZ <= MAC_jumper(0); -- MAC_jumper(1) is where D_T(7) was; MAC_jumper(0) is where D_T(6) was; 310 bid <= BoardID; 311 cid <= CrateID; 297 312 par_addr <= W5300_MR; 298 313 par_data <= X"0000"; 299 314 state_init <= WRITE_REG; 300 315 next_state <= LOCATE; 301 316 302 317 when LOCATE => 303 state_init <= IM; 304 305 if (FAD_in_cam = '1') then 306 -- if BID = "1111" and CID="11" then FAD is not really in cam 307 -- back to INIT !! endless loop 308 if (bid = "1111" and cid="11") then 309 -- this should never happen!!!!! 310 -- impossible to find this out, if in cam 311 state_init <= INIT; 312 else -- everything is fine 313 -- IP & MAC are calculated from BID & CID 314 -- code here 315 gateway_loc <= CAM_GATEWAY; 316 netmask_loc <= CAM_NETMASK; 317 mac_loc <= (CAM_MAC_prefix (0), CAM_MAC_prefix (1) , conv_std_logic_vector ( conv_integer(cid)*10+conv_integer(bid) , 16) ); 318 ip_loc <= ( CAM_IP_PREFIX(0) , CAM_IP_PREFIX(1) , IP_offset + conv_integer(cid) , IP_offset + conv_integer(bid) ); 319 end if; 320 else -- FAD is tested, either at ETHZ or at TUDO AND either with FMP or without. 321 if ( FAD_at_ETHZ = '0' ) then 322 -- easy FAD is at TUDO -> only one choice. 323 mac_loc <= MAC_FAD0; 324 ip_loc <= IP_TUDO; 325 gateway_loc <= TUDO_GATEWAY; 326 netmask_loc <= TUDO_NETMASK; 327 else -- FAD is at ETHZ but not in cam --> IP lookup table is needed. 328 if (bid = "1111" and cid="11") then -- FAD is not in crate 329 mac_loc <= MAC_FAD0; 330 ip_loc <= IP_ETHZ_FAD0; 331 gateway_loc <= ETHZ_GATEWAY; 332 netmask_loc <= ETHZ_NETMASK; 333 else 334 -- FAD is at ETHZ and in crate: 335 -- crate ID is not of importance. 336 -- we only have 3 MACs and IPs so far, so only the first boardIDs are allowed. 337 if ( conv_integer(bid) < MAC_LIST'length) then 338 gateway_loc <= ETHZ_GATEWAY; 339 netmask_loc <= ETHZ_NETMASK; 340 mac_loc <= MAC_LIST(conv_integer(bid)); 341 ip_loc <= IP_LIST(conv_integer(bid)); 342 end if; -- conv_integer 343 end if; -- bid=1111 & cid=11 344 end if; --FAD_at_ETHZ = 0 345 end if; --FAD_in_cam = 1 318 state_init <= IM; 319 320 if (FAD_in_cam = '1') then 321 if (bid = "1111" and cid="11") then 322 -- if BID = "1111" and CID="11" then FAD is not really in cam 323 -- I don't know what to do now. 324 -- I could wait a long time, and then just assume, I was not in cam. 325 -- this should never happen!!!!! 326 -- impossible to find this out, if in cam 327 state_init <= INIT; 328 else -- everything is fine 329 -- IP & MAC are calculated from BID & CID 330 -- code here 331 gateway_loc <= CAM_GATEWAY; 332 netmask_loc <= CAM_NETMASK; 333 mac_loc <= (CAM_MAC_prefix (0), CAM_MAC_prefix (1) , conv_std_logic_vector ( conv_integer(cid)*10+conv_integer(bid) , 16) ); 334 ip_loc <= ( CAM_IP_PREFIX(0) , CAM_IP_PREFIX(1) , IP_offset + conv_integer(cid) , IP_offset + conv_integer(bid) ); 335 end if; 336 else -- FAD is tested, either at ETHZ or at TUDO AND either with FMP or without. 337 if ( FAD_at_ETHZ = '0' ) then 338 -- easy FAD is at TUDO -> only one choice. 339 mac_loc <= MAC_FAD0; 340 ip_loc <= IP_TUDO; 341 gateway_loc <= TUDO_GATEWAY; 342 netmask_loc <= TUDO_NETMASK; 343 else -- FAD is at ETHZ but not in cam --> IP lookup table is needed. 344 if (bid = "1111" and cid="11") then -- FAD is not in crate 345 mac_loc <= MAC_FAD0; 346 ip_loc <= IP_ETHZ_FAD0; 347 gateway_loc <= ETHZ_GATEWAY; 348 netmask_loc <= ETHZ_NETMASK; 349 else 350 -- FAD is at ETHZ and in crate: 351 -- crate ID is not of importance. 352 -- we only have 3 MACs and IPs so far, so only the first boardIDs are allowed. 353 if ( conv_integer(bid) < MAC_LIST'length) then 354 gateway_loc <= ETHZ_GATEWAY; 355 netmask_loc <= ETHZ_NETMASK; 356 mac_loc <= MAC_LIST(conv_integer(bid)); 357 ip_loc <= IP_LIST(conv_integer(bid)); 358 end if; -- conv_integer 359 end if; -- bid=1111 & cid=11 360 end if; --FAD_at_ETHZ = 0 361 end if; --FAD_in_cam = 1 346 362 347 363 -- Interrupt Mask … … 1003 1019 end if; -- rising_edge (clk) 1004 1020 1005 end process w5300_ init_proc;1021 end process w5300_proc; 1006 1022 1007 1023 end Behavioral;
Note:
See TracChangeset
for help on using the changeset viewer.