Changeset 10174 for firmware/FAD/FACT_FAD_20MHz_VAR_PS
- Timestamp:
- 02/24/11 10:17:16 (14 years ago)
- Location:
- firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/data_generator.vhd
r10172 r10174 21 21 22 22 entity data_generator is 23 generic( 24 RAM_ADDR_WIDTH : integer := 12 25 ); 26 port( 27 -- led : OUT std_logic_vector (7 DOWNTO 0) := (OTHERS => '0'); 28 29 clk : in std_logic; 30 data_out : out std_logic_vector (63 downto 0); 31 addr_out : out std_logic_vector (RAM_ADDR_WIDTH-1 downto 0); 32 write_ea : out std_logic_vector (0 downto 0) := "0"; 33 ram_start_addr : in std_logic_vector (RAM_ADDR_WIDTH-1 downto 0); 34 ram_write_ea : in std_logic; 35 ram_write_ready : out std_logic := '0'; 36 -- -- 37 ram_write_ready_ack : IN std_logic; 38 -- -- 39 config_start_mm, config_start_cm, config_start_spi : out std_logic := '0'; 40 config_ready_mm, config_ready_cm, config_ready_spi : in std_logic; 41 config_started_mm, config_started_cm, config_started_spi : in std_logic; 42 roi_array : in roi_array_type; 43 roi_max : in roi_max_type; 44 sensor_array : in sensor_array_type; 45 sensor_ready : in std_logic; 46 dac_array : in dac_array_type; 47 48 -- EVT HEADER - part 1 49 package_length : in std_logic_vector (15 downto 0); 50 pll_lock : in std_logic_vector ( 3 downto 0); 51 -- 52 53 -- EVT HEADER - part 2 --> FTM trigger informaton, comes in late ... 54 -- during EVT header wrinting, this field is left out ... and only written into event header, 55 -- when the DRS chip were read out already. 56 FTM_RS485_ready : in std_logic; 57 FTM_trigger_info : in std_logic_vector (55 downto 0); --7 byte 58 -- 59 60 -- EVT HEADER - part 3 61 fad_event_counter : in std_logic_vector (31 downto 0); 62 refclk_counter : in std_logic_vector (11 downto 0); 63 refclk_too_high: in std_logic; 64 refclk_too_low : in std_logic; 65 -- 66 67 -- EVT HEADER - part 4 68 board_id : in std_logic_vector (3 downto 0); 69 crate_id : in std_logic_vector (1 downto 0); 70 DCM_PS_status : in std_logic_vector (7 downto 0); 71 TRG_GEN_div : in std_logic_vector (15 downto 0); 72 -- 73 74 -- EVT HEADER - part 5 75 dna : in std_logic_vector (63 downto 0); 76 -- 77 78 -- EVT HEADER - part 6 79 timer_value : in std_logic_vector (31 downto 0); -- time in units of 100us 80 -- 81 82 trigger : in std_logic; 83 -- s_trigger : in std_logic; 84 new_config : in std_logic; 85 config_started : out std_logic := '0'; 86 adc_data_array : in adc_data_array_type; 87 adc_oeb : out std_logic := '1'; 88 adc_clk_en : out std_logic := '0'; 89 adc_otr : in std_logic_vector (3 downto 0); 90 drs_channel_id : out std_logic_vector (3 downto 0) := (others => '0'); 91 -- -- 92 -- drs_dwrite : out std_logic := '1'; 93 drs_readout_ready : out std_logic := '0'; 94 drs_readout_ready_ack : in std_logic; 95 -- -- 96 drs_clk_en, drs_read_s_cell : out std_logic := '0'; 97 98 drs_srin_write_8b : out std_logic := '0'; 99 drs_srin_write_ack : in std_logic; 100 drs_srin_data : out std_logic_vector (7 downto 0) := (others => '0'); 101 drs_srin_write_ready : in std_logic; 102 103 drs_read_s_cell_ready : in std_logic; 104 drs_s_cell_array : in drs_s_cell_array_type; 105 106 drs_readout_started : out std_logic := '0' 107 ); 23 generic( 24 RAM_ADDR_WIDTH : integer := 12 25 ); 26 port( 27 clk : in std_logic; -- CLK_25. 28 data_out : out std_logic_vector (63 downto 0); 29 addr_out : out std_logic_vector (RAM_ADDR_WIDTH-1 downto 0); 30 dataRAM_write_ea_o : out std_logic_vector (0 downto 0) := "0"; 31 ram_start_addr : in std_logic_vector (RAM_ADDR_WIDTH-1 downto 0); 32 ram_write_ea : in std_logic; 33 ram_write_ready : out std_logic := '0'; 34 35 ram_write_ready_ack : IN std_logic; 36 37 config_start_mm : out std_logic := '0'; 38 config_start_cm : out std_logic := '0'; 39 config_start_spi : out std_logic := '0'; 40 config_ready_mm : in std_logic; 41 config_ready_cm : in std_logic; 42 config_ready_spi : in std_logic; 43 config_started_mm : in std_logic; 44 config_started_cm : in std_logic; 45 config_started_spi : in std_logic; 46 roi_array : in roi_array_type; 47 roi_max : in roi_max_type; 48 sensor_array : in sensor_array_type; 49 sensor_ready : in std_logic; 50 dac_array : in dac_array_type; 51 52 -- EVT HEADER - part 1 53 package_length : in std_logic_vector (15 downto 0); 54 pll_lock : in std_logic_vector ( 3 downto 0); 55 56 -- EVT HEADER - part 2 --> FTM trigger informaton, comes in late ... 57 -- during EVT header wrinting, this field is left out ... and only written into event header, 58 -- when the DRS chip were read out already. 59 FTM_RS485_ready : in std_logic; 60 FTM_trigger_info : in std_logic_vector (55 downto 0); --7 byte 61 62 -- EVT HEADER - part 3 63 fad_event_counter : in std_logic_vector (31 downto 0); 64 refclk_counter : in std_logic_vector (11 downto 0); 65 refclk_too_high : in std_logic; 66 refclk_too_low : in std_logic; 67 68 -- EVT HEADER - part 4 69 board_id : in std_logic_vector (3 downto 0); 70 crate_id : in std_logic_vector (1 downto 0); 71 DCM_PS_status : in std_logic_vector (7 downto 0); 72 TRG_GEN_div : in std_logic_vector (15 downto 0); 73 74 -- EVT HEADER - part 5 75 dna : in std_logic_vector (63 downto 0); 76 77 -- EVT HEADER - part 6 78 timer_value : in std_logic_vector (31 downto 0); -- time in units of 100us 79 80 trigger : in std_logic; 81 start_config_chain : in std_logic; -- here W5300_MODUL can start the whole config chain 82 config_chain_done : out std_logic; 83 84 adc_data_array : in adc_data_array_type; 85 adc_output_enable_inverted : out std_logic := '1'; 86 adc_clk_en : out std_logic := '0'; 87 adc_otr : in std_logic_vector (3 downto 0); 88 drs_channel_id : out std_logic_vector (3 downto 0) := (others => '0'); 89 90 --drs_dwrite : out std_logic := '1'; 91 drs_readout_ready : out std_logic := '0'; 92 drs_readout_ready_ack : in std_logic; 93 drs_clk_en : out std_logic := '0'; 94 start_read_drs_stop_cell: out std_logic := '0'; 95 96 drs_srin_write_8b : out std_logic := '0'; 97 drs_srin_write_ack : in std_logic; 98 drs_srin_data : out std_logic_vector (7 downto 0) := (others => '0'); 99 drs_srin_write_ready : in std_logic; 100 101 drs_read_s_cell_ready : in std_logic; 102 drs_s_cell_array : in drs_s_cell_array_type; 103 104 drs_readout_started : out std_logic := '0' 105 ); 108 106 end data_generator ; 109 107 110 108 architecture Behavioral of data_generator is 111 109 112 type state_generate_type is (INIT, CONFIG, CONFIG1, CONFIG2,CONFIG3, CONFIG4, CONFIG5, CONFIG6, CONFIG7, 113 WRITE_DATA_IDLE, 114 WRITE_HEADER, WRITE_FTM_INFO, WRITE_EVENTCOUNTER_AND_REFCLK_COUNTER, WRITE_BOARD_ID, 115 WRITE_DNA, WRITE_TIMER, WRITE_TEMPERATURES, 116 WRITE_DAC1, WRITE_DAC2, 117 WAIT_FOR_STOP_CELL, 118 START_DRS_READING, 119 WRITE_CHANNEL_ID, WRITE_START_CELL, WRITE_ROI, WRITE_FILLING, 120 WAIT_FOR_ADC, WRITE_ADC_DATA, 121 WRITE_EXTERNAL_TRIGGER, 122 WRITE_END_FLAG, 123 WRITE_DATA_END, WRITE_DATA_END_WAIT, 124 WRITE_DATA_STOP, WRITE_DATA_STOP1); 125 126 signal state_generate : state_generate_type := INIT; 110 type state_generate_type is ( 111 CONFIG_CHAIN_START, -- WRITE_DATA_IDLE branches into this state, if needed. 112 CONFIG_MEMORY_MANAGER, 113 CONFIG_SPI_INTERFACE, 114 WAIT_FOR_CONFIG_SPI_INTERFACE, 115 CONFIG_DRS_01, -- these four states configure the DRS shift registers, 116 CONFIG_DRS_02, -- the make great use of the drs_pulser entity. 117 CONFIG_DRS_03, -- maybe they should be moved into the drs_pulser entity. 118 WAIT_FOR_DRS_CONFIG_READY, 119 120 WRITE_DATA_IDLE, 121 WRITE_HEADER, WRITE_FTM_INFO, WRITE_EVENTCOUNTER_AND_REFCLK_COUNTER, WRITE_BOARD_ID, 122 WRITE_DNA, WRITE_TIMER, WRITE_TEMPERATURES, 123 WRITE_DAC1, WRITE_DAC2, 124 WAIT_FOR_STOP_CELL, 125 START_DRS_READING, 126 WRITE_CHANNEL_ID, WRITE_START_CELL, WRITE_ROI, WRITE_FILLING, 127 WAIT_FOR_ADC, WRITE_ADC_DATA, 128 WRITE_EXTERNAL_TRIGGER, 129 WRITE_END_FLAG, 130 WRITE_DATA_END, WRITE_DATA_END_WAIT, 131 WRITE_DATA_STOP, WRITE_DATA_STOP1 132 ); 133 134 -- configuration stuff: 135 -- this flag is set, when ever a rising edge on 'start_config_chain' is detected. 136 -- this flag is cleared only, when a configuration chain was successfully processed 137 signal start_config_chain_flag : std_logic; 138 signal start_config_chain_sr : std_logic_vector(1 downto 0); 139 140 signal state_generate : state_generate_type := CONFIG; 127 141 signal start_addr : std_logic_vector (RAM_ADDR_WIDTH-1 downto 0) := (others => '0'); 128 142 129 143 signal data_cntr : integer range 0 to 1024 := 0; 130 signal evnt_cntr : std_logic_vector (31 downto 0) := (others => '0');131 144 signal addr_cntr : integer range 0 to RAM_SIZE_64B := 0; -- counts 64 bit words 132 145 signal channel_id : integer range 0 to 9 := 0; 133 146 signal adc_wait_cnt : integer range 0 to 7 := 0; 134 147 135 signal trigger_ flag :std_logic := '0';148 signal trigger_sr :std_logic_vector(1 downto 0) := "00"; 136 149 signal ram_write_ea_flag : std_logic := '0'; 137 150 signal new_config_int : std_logic := '0'; 138 151 152 -- internal signal: to be sampled once and used instead of inputs! 139 153 signal roi_max_int : roi_max_type; 140 154 … … 147 161 begin 148 162 if rising_edge (clk) then 149 trigger_flag <= trigger; 163 start_config_chain_sr <= start_config_chain_sr(0) & start_config_chain; 164 if (start_config_chain_sr = "01") then 165 start_config_chain_flag <= '1'; 166 config_chain_done = '0'; 167 end if; 168 trigger_sr <= trigger_sr(0) & trigger; --synching in of asynchrounous trigger signal. 150 169 addr_out <= start_addr + conv_std_logic_vector(addr_cntr, RAM_ADDR_WIDTH); 170 151 171 case state_generate is 152 when INIT => 153 state_generate <= CONFIG; 154 when CONFIG => 155 config_started <= '1'; 156 if (new_config = '0') then 157 config_started <= '0'; 158 -- config config manager 159 config_start_cm <= '1'; 160 if (config_started_cm = '1') then 161 config_start_cm <= '0'; 162 state_generate <= CONFIG1; 163 end if; 164 end if; 165 when CONFIG1 => 172 173 when CONFIG_CHAIN_START => -- CONFIG_CONTROL_MANAGER 174 config_start_cm <= '1'; 175 if (config_started_cm = '1') then 176 config_start_cm <= '0'; 177 state_generate <= CONFIG_MEMORY_MANAGER; 178 end if; 179 when CONFIG_MEMORY_MANAGER => -- CONFIG_MEMORY_MANAGER 166 180 if (config_ready_cm = '1') then 167 181 config_start_mm <= '1'; … … 169 183 if (config_started_mm = '1') then 170 184 config_start_mm <= '0'; 171 state_generate <= CONFIG2; 172 end if; 173 when CONFIG2 => 174 if (config_ready_mm = '1') then 175 config_start_spi <= '1'; 176 end if; 177 if (config_started_spi = '1') then 178 config_start_spi <= '0'; 179 state_generate <= CONFIG3; 180 end if; 181 when CONFIG3 => 182 if (config_ready_spi = '1') then 183 state_generate <= CONFIG4; 184 -- state_generate <= WRITE_DATA_IDLE; 185 end if; 186 -- configure DRS 187 when CONFIG4 => 188 drs_channel_id <= DRS_WRITE_SHIFT_REG; 189 drs_srin_data <= "11111111"; 190 drs_srin_write_8b <= '1'; 191 if (drs_srin_write_ack = '1') then 192 drs_srin_write_8b <= '0'; 193 state_generate <= CONFIG5; 194 end if; 195 when CONFIG5 => 196 if (drs_srin_write_ready = '1') then 197 roi_max_int <= roi_max; 198 state_generate <= CONFIG6; 199 end if; 200 when CONFIG6 => 201 drs_channel_id <= DRS_WRITE_CONFIG_REG; 202 drs_srin_data <= "11111111"; 203 drs_srin_write_8b <= '1'; 204 if (drs_srin_write_ack = '1') then 205 drs_srin_write_8b <= '0'; 206 state_generate <= CONFIG7; 207 end if; 208 when CONFIG7 => 209 if (drs_srin_write_ready = '1') then 210 drs_channel_id <= DRS_ADDR_IDLE; -- to make sure not to write accidentally into DRS shift registers 211 roi_max_int <= roi_max; 212 state_generate <= WRITE_DATA_IDLE; 213 end if; 214 -- end configure DRS 215 216 when WRITE_DATA_IDLE => 217 if (new_config = '1') then 218 state_generate <= CONFIG; 219 end if; 220 -- if (ram_write_ea = '1' and (trigger_flag = '1' or s_trigger = '1')) then 221 if (ram_write_ea = '1' and trigger_flag = '1') then 222 sig_drs_readout_started <= '1'; -- is set to '0' in state WRITE_DAC1 223 -- stop drs, dwrite low 224 -- drs_dwrite <= '0'; 225 -- start reading of drs stop cell 226 drs_read_s_cell <= '1'; 227 -- enable adc output 228 adc_oeb <= '0'; 229 -- switch on ADC_CLK 230 adc_clk_en <= '1'; 231 start_addr <= ram_start_addr; 232 state_generate <= WRITE_HEADER; 233 evnt_cntr <= evnt_cntr + 1; 234 end if; 235 when WRITE_HEADER => 236 write_ea <= "1"; 237 data_out <= X"000" & pll_lock & PACKAGE_VERSION & PACKAGE_SUB_VERSION & package_length & X"FB01"; 238 addr_cntr <= addr_cntr + 1; 239 state_generate <= WRITE_FTM_INFO; 185 state_generate <= CONFIG_SPI_INTERFACE; 186 end if; 187 when CONFIG_SPI_INTERFACE => -- CONFIG_SPI_INTERFACE 188 if (config_ready_mm = '1') then 189 config_start_spi <= '1'; 190 end if; 191 if (config_started_spi = '1') then 192 config_start_spi <= '0'; 193 state_generate <= WAIT_FOR_CONFIG_SPI_INTERFACE; 194 end if; 195 when WAIT_FOR_CONFIG_SPI_INTERFACE => 196 if (config_ready_spi = '1') then 197 state_generate <= CONFIG_DRS_01; 198 end if; 199 -- configure DRS 200 -- all this might be done in the drs_pulser entity 201 when CONFIG_DRS_01 => -- BEGIN CONFIG DRS 202 drs_channel_id <= DRS_WRITE_SHIFT_REG; 203 drs_srin_data <= "11111111"; 204 drs_srin_write_8b <= '1'; 205 if (drs_srin_write_ack = '1') then 206 drs_srin_write_8b <= '0'; 207 state_generate <= CONFIG_DRS_02; 208 end if; 209 when CONFIG_DRS_02 => 210 if (drs_srin_write_ready = '1') then 211 state_generate <= CONFIG_DRS_03; 212 end if; 213 when CONFIG_DRS_03 => 214 drs_channel_id <= DRS_WRITE_CONFIG_REG; 215 drs_srin_data <= "11111111"; 216 drs_srin_write_8b <= '1'; 217 if (drs_srin_write_ack = '1') then 218 drs_srin_write_8b <= '0'; 219 state_generate <= WAIT_FOR_DRS_CONFIG_READY; 220 end if; 221 222 -- last state of CONFIG CHAIN: 223 -- here the input roi_max is sampled 224 -- all other interesting input signals should be sampled here as well! 225 when WAIT_FOR_DRS_CONFIG_READY => -- END OF CONFIG CHAIN 226 if (drs_srin_write_ready = '1') then 227 drs_channel_id <= DRS_ADDR_IDLE; -- to make sure not to write accidentally into DRS shift registers 228 roi_max_int <= roi_max; 229 config_chain_done = '1'; 230 state_generate <= WRITE_DATA_IDLE; 231 end if; 232 -- end configure DRS 233 234 235 when WRITE_DATA_IDLE => 236 if (start_config_chain_flag = '1') then 237 start_config_chain_flag = '0'; 238 state_generate <= CONFIG_CHAIN_START; 239 end if; 240 if (ram_write_ea = '1' and trigger_sr = "01") then 241 sig_drs_readout_started <= '1'; -- is set to '0' in next state ... just a pulse. 242 start_read_drs_stop_cell <= '1'; 243 adc_output_enable_inverted <= '0'; 244 -- at this moment the ADC ist beeing clocked. 245 -- this is not the start of the readout. 246 -- the DRS needs to be clocked as well. 247 adc_clk_en <= '1'; 248 start_addr <= ram_start_addr; 249 state_generate <= WRITE_HEADER; 250 end if; 251 when WRITE_HEADER => 252 sig_drs_readout_started <= '0'; -- is set to '1' in state WRITE_DATA_IDLE 253 dataRAM_write_ea_o <= "1"; 254 data_out <= X"000" & pll_lock & PACKAGE_VERSION & PACKAGE_SUB_VERSION & package_length & X"FB01"; 255 addr_cntr <= addr_cntr + 1; 256 state_generate <= WRITE_FTM_INFO; 240 257 241 when WRITE_FTM_INFO => 242 -- here we do not write the FTM info ... just jump over it. 243 addr_cntr <= addr_cntr + 1; 244 state_generate <= WRITE_EVENTCOUNTER_AND_REFCLK_COUNTER; 258 when WRITE_FTM_INFO => 259 -- THIS is just a dummy STATE just to make reading easier. 260 -- at this point normally the FTM RS485 data would be written .. but we do not know it 261 -- so here we do not write the FTM info ... just jump over it. 262 addr_cntr <= addr_cntr + 1; 263 state_generate <= WRITE_EVENTCOUNTER_AND_REFCLK_COUNTER; 245 264 246 when WRITE_EVENTCOUNTER_AND_REFCLK_COUNTER => 247 data_out <= X"0000" & 248 refclk_too_high & refclk_too_low & "00" & refclk_counter & 249 fad_event_counter(15 downto 0) & 250 fad_event_counter(31 downto 16) ; 251 addr_cntr <= addr_cntr + 1; 252 state_generate <= WRITE_BOARD_ID; 253 -- crate ID & board ID 254 -- and a lot more... 255 -- info about the phase shifter 256 -- status of the trigger generator 257 when WRITE_BOARD_ID => 258 data_out <= TRG_GEN_div & X"0000" & X"00" & DCM_PS_status & "000000" & crate_id & "1000" & board_id; 259 addr_cntr <= addr_cntr + 1; 260 state_generate <= WRITE_DNA; 261 262 when WRITE_DNA => 263 data_out <= X"00" & dna(55 downto 0); 264 addr_cntr <= addr_cntr + 1; 265 state_generate <= WRITE_TIMER; 266 267 when WRITE_TIMER => 268 data_out <= X"0000" & X"0000" & timer_value; -- 2times 16bit reserved for additional status info 269 addr_cntr <= addr_cntr + 1; 270 state_generate <= WRITE_TEMPERATURES; 271 272 when WRITE_TEMPERATURES => -- temperatures 273 if (sensor_ready = '1') then 274 data_out <= conv_std_logic_vector (sensor_array (3), 16) 275 & conv_std_logic_vector (sensor_array (2), 16) 276 & conv_std_logic_vector (sensor_array (1), 16) 277 & conv_std_logic_vector (sensor_array (0), 16); 278 addr_cntr <= addr_cntr + 1; 279 state_generate <= WRITE_DAC1; 280 end if; 281 282 when WRITE_DAC1 => 283 sig_drs_readout_started <= '0'; -- is set to '1' in state WRITE_DATA_IDLE 284 data_out <= conv_std_logic_vector (dac_array (3), 16) 285 & conv_std_logic_vector (dac_array (2), 16) 286 & conv_std_logic_vector (dac_array (1), 16) 287 & conv_std_logic_vector (dac_array (0), 16); 288 addr_cntr <= addr_cntr + 1; 289 state_generate <= WRITE_DAC2; 290 when WRITE_DAC2 => 291 data_out <= conv_std_logic_vector (dac_array (7), 16) 292 & conv_std_logic_vector (dac_array (6), 16) 293 & conv_std_logic_vector (dac_array (5), 16) 294 & conv_std_logic_vector (dac_array (4), 16); 295 addr_cntr <= addr_cntr + 1; 296 state_generate <= WAIT_FOR_STOP_CELL; 297 298 when WAIT_FOR_STOP_CELL => 299 drs_read_s_cell <= '0'; 300 if (drs_read_s_cell_ready = '1') then 301 state_generate <= START_DRS_READING; 302 end if; 303 304 when START_DRS_READING => 305 --drs channel number 306 drs_channel_id <= conv_std_logic_vector (channel_id, 4); 307 --starte drs-clocking 308 --adc_oeb <= '0'; -- nur für Emulator 309 drs_clk_en <= '1'; 310 adc_wait_cnt <= 0; 311 state_generate <= WRITE_CHANNEL_ID; 312 313 when WRITE_CHANNEL_ID => -- write DRS and Channel IDs 314 data_out <= conv_std_logic_vector(3,12) & conv_std_logic_vector(channel_id,4) 315 & conv_std_logic_vector(2,12) & conv_std_logic_vector(channel_id,4) 316 & conv_std_logic_vector(1,12) & conv_std_logic_vector(channel_id,4) 317 & conv_std_logic_vector(0,12) & conv_std_logic_vector(channel_id,4); 318 addr_cntr <= addr_cntr + 1; 319 state_generate <= WRITE_START_CELL; 320 when WRITE_START_CELL => -- write start cells 321 data_out <= "000000" & drs_s_cell_array (3) 322 & "000000" & drs_s_cell_array (2) 323 & "000000" & drs_s_cell_array (1) 324 & "000000" & drs_s_cell_array (0); 325 addr_cntr <= addr_cntr + 1; 326 state_generate <= WRITE_ROI; 327 when WRITE_ROI => -- write ROI 328 data_out <= "00000" & conv_std_logic_vector (roi_array((3) * 9 + channel_id), 11) 329 & "00000" & conv_std_logic_vector (roi_array((2) * 9 + channel_id), 11) 330 & "00000" & conv_std_logic_vector (roi_array((1) * 9 + channel_id), 11) 331 & "00000" & conv_std_logic_vector (roi_array((0) * 9 + channel_id), 11); 332 addr_cntr <= addr_cntr + 1; 333 state_generate <= WRITE_FILLING; 334 335 when WRITE_FILLING => -- write FILLING 336 data_out <= conv_std_logic_vector(0,64); -- filling 337 addr_cntr <= addr_cntr + 1; 338 state_generate <= WAIT_FOR_ADC; 339 340 when WAIT_FOR_ADC => 341 -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 342 if (adc_wait_cnt < (4 + 3)) then -- anpassen!!!! -- 3 für Simulation, 4 für FPGA??? 343 adc_wait_cnt <= adc_wait_cnt + 1; 344 else 345 state_generate <= WRITE_ADC_DATA; 346 end if; 347 when WRITE_ADC_DATA => 348 if (data_cntr < roi_max (channel_id)) then 349 data_out <= "000" & adc_otr(3) & adc_data_array(3) 350 & "000" & adc_otr(2) & adc_data_array(2) 351 & "000" & adc_otr(1) & adc_data_array(1) 352 & "000" & adc_otr(0) & adc_data_array(0); 353 -- data_out <= "00000" & conv_std_logic_vector (data_cntr, 11) 354 -- & "00010" & conv_std_logic_vector (data_cntr, 11) 355 -- & "00100" & conv_std_logic_vector (data_cntr, 11) 356 -- & "00110" & conv_std_logic_vector (data_cntr, 11) ; 357 addr_cntr <= addr_cntr + 1; 358 state_generate <= WRITE_ADC_DATA; 359 data_cntr <= data_cntr + 1; 360 else 361 drs_clk_en <= '0'; 362 --adc_oeb <= '1'; -- nur für Emulator 363 if (channel_id = 8) then 364 state_generate <= WRITE_EXTERNAL_TRIGGER; 365 adc_oeb <= '1'; 366 -- switch off ADC_CLK 367 adc_clk_en <= '0'; 368 else 369 channel_id <= channel_id + 1; -- increment channel_id 370 state_generate <= START_DRS_READING; 371 data_cntr <= 0; 372 end if; 373 end if; 374 375 when WRITE_EXTERNAL_TRIGGER => -- external trigger ID 376 addr_out <= start_addr + conv_std_logic_vector(1, RAM_ADDR_WIDTH); 377 data_out <= FTM_trigger_info(15 downto 0) 378 & FTM_trigger_info(31 downto 16) 379 & FTM_trigger_info(47 downto 32) 380 & X"00" & FTM_trigger_info(55 downto 48); 381 state_generate <= WRITE_END_FLAG; 382 383 when WRITE_END_FLAG => 384 data_out <= (63 downto 32 => '0') & X"04FE" & X"4242"; 385 addr_cntr <= addr_cntr + 1; 386 state_generate <= WRITE_DATA_END; 387 when WRITE_DATA_END => 388 write_ea <= "0"; 389 ram_write_ready <= '1'; 390 state_generate <= WRITE_DATA_END_WAIT; 391 when WRITE_DATA_END_WAIT => 392 -- -- 393 if (ram_write_ready_ack = '1') then 394 state_generate <= WRITE_DATA_STOP; 395 -- -- 396 ram_write_ready <= '0'; 397 -- -- 398 end if; 399 -- -- 400 when WRITE_DATA_STOP => 401 -- -- 402 if (ram_write_ready_ack = '0') then 403 -- -- 404 -- drs_dwrite <= '1'; 405 drs_readout_ready <= '1'; 406 data_cntr <= 0; 407 addr_cntr <= 0; 408 channel_id <= 0; 409 state_generate <= WRITE_DATA_STOP1; 410 -- -- 411 end if; 412 -- -- 413 when WRITE_DATA_STOP1 => 414 if (drs_readout_ready_ack = '1') then 415 drs_readout_ready <= '0'; 416 state_generate <= WRITE_DATA_IDLE; 417 end if; 418 when others => 419 null; 420 421 end case; -- state_generate 422 end if; -- rising_edge (clk) 423 end process generate_data; 424 265 when WRITE_EVENTCOUNTER_AND_REFCLK_COUNTER => 266 data_out <= X"0000" & 267 refclk_too_high & refclk_too_low & "00" & refclk_counter & 268 fad_event_counter(15 downto 0) & 269 fad_event_counter(31 downto 16) ; 270 addr_cntr <= addr_cntr + 1; 271 state_generate <= WRITE_BOARD_ID; 272 273 when WRITE_BOARD_ID => 274 data_out <= TRG_GEN_div & -- this is a kind of prescaler for the continouus trigger generator 275 X"0000" & -- this might be the number of soft triggers beeing generated in a 'burst' not implemented yet 276 X"00" & DCM_PS_status & "000000" & -- number of steps, the phase shifter was shifted... 277 crate_id & "1000" & board_id; -- position of the board inside the camera 278 addr_cntr <= addr_cntr + 1; 279 state_generate <= WRITE_DNA; 280 281 when WRITE_DNA => 282 data_out <= X"00" & dna(55 downto 0); 283 addr_cntr <= addr_cntr + 1; 284 state_generate <= WRITE_TIMER; 285 286 when WRITE_TIMER => 287 data_out <= X"0000" & X"0000" & timer_value; -- 2times 16bit reserved for additional status info 288 addr_cntr <= addr_cntr + 1; 289 state_generate <= WRITE_TEMPERATURES; 290 291 -- DANGER: thist state can wait endlessly, if somethings wrong. 292 when WRITE_TEMPERATURES => -- temperatures 293 if (sensor_ready = '1') then 294 data_out <= conv_std_logic_vector (sensor_array (3), 16) & 295 conv_std_logic_vector (sensor_array (2), 16) & 296 conv_std_logic_vector (sensor_array (1), 16) & 297 conv_std_logic_vector (sensor_array (0), 16); 298 addr_cntr <= addr_cntr + 1; 299 state_generate <= WRITE_DAC1; 300 end if; 301 302 when WRITE_DAC1 => 303 data_out <= conv_std_logic_vector (dac_array (3), 16) & 304 conv_std_logic_vector (dac_array (2), 16) & 305 conv_std_logic_vector (dac_array (1), 16) & 306 conv_std_logic_vector (dac_array (0), 16); 307 addr_cntr <= addr_cntr + 1; 308 state_generate <= WRITE_DAC2; 309 when WRITE_DAC2 => 310 data_out <= conv_std_logic_vector (dac_array (7), 16) & 311 conv_std_logic_vector (dac_array (6), 16) & 312 conv_std_logic_vector (dac_array (5), 16) & 313 conv_std_logic_vector (dac_array (4), 16); 314 addr_cntr <= addr_cntr + 1; 315 state_generate <= WAIT_FOR_STOP_CELL; 316 317 when WAIT_FOR_STOP_CELL => 318 start_read_drs_stop_cell <= '0'; 319 if (drs_read_s_cell_ready = '1') then 320 state_generate <= START_DRS_READING; 321 end if; 322 323 when START_DRS_READING => 324 --drs channel number 325 drs_channel_id <= conv_std_logic_vector (channel_id, 4); 326 327 --adc_output_enable_inverted <= '0'; -- nur für Emulator ?????????????????? 328 -- this has been done earlier already ... why does it need to be repeated? 329 330 --starte drs-clocking 331 -- this is an interesting point: 332 -- here the DRS clock starts to tick. but only some states later 333 -- the ADC data is actually read out. 334 -- the reason is, that the ADC has a latency of 7 clock cycles, which means, 335 -- when the next rising edge of the DRS clock is produced. 336 -- an analog value is put out. 337 -- when the next rising edge of the ADC clock is produced. 338 -- this very analog value is sampled. 339 -- but only seven clock ticks later, the degital result is available. 340 -- from that point on, every clock tick produces a valid digital result. 341 drs_clk_en <= '1'; 342 adc_wait_cnt <= 0; 343 state_generate <= WRITE_CHANNEL_ID; 344 345 when WRITE_CHANNEL_ID => -- write DRS and Channel IDs 346 data_out <= conv_std_logic_vector(3,12) & conv_std_logic_vector(channel_id,4) & 347 conv_std_logic_vector(2,12) & conv_std_logic_vector(channel_id,4) & 348 conv_std_logic_vector(1,12) & conv_std_logic_vector(channel_id,4) & 349 conv_std_logic_vector(0,12) & conv_std_logic_vector(channel_id,4); 350 addr_cntr <= addr_cntr + 1; 351 state_generate <= WRITE_START_CELL; 352 when WRITE_START_CELL => -- write start cells 353 data_out <= "000000" & drs_s_cell_array (3) & 354 "000000" & drs_s_cell_array (2) & 355 "000000" & drs_s_cell_array (1) & 356 "000000" & drs_s_cell_array (0); 357 addr_cntr <= addr_cntr + 1; 358 state_generate <= WRITE_ROI; 359 360 when WRITE_ROI => -- write ROI 361 data_out <= "00000" & conv_std_logic_vector (roi_array((3) * 9 + channel_id), 11) & 362 "00000" & conv_std_logic_vector (roi_array((2) * 9 + channel_id), 11) & 363 "00000" & conv_std_logic_vector (roi_array((1) * 9 + channel_id), 11) & 364 "00000" & conv_std_logic_vector (roi_array((0) * 9 + channel_id), 11); 365 addr_cntr <= addr_cntr + 1; 366 state_generate <= WRITE_FILLING; 367 368 when WRITE_FILLING => -- write FILLING 369 data_out <= conv_std_logic_vector(0,64); -- filling 370 addr_cntr <= addr_cntr + 1; 371 state_generate <= WAIT_FOR_ADC; 372 373 when WAIT_FOR_ADC => 374 -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 375 if (adc_wait_cnt < 4 ) then -- anpassen!!!! -- 3 für Simulation, 4 für FPGA??? 376 adc_wait_cnt <= adc_wait_cnt + 1; 377 else 378 state_generate <= WRITE_ADC_DATA; 379 end if; 380 when WRITE_ADC_DATA => 381 if (data_cntr < roi_max_int (channel_id)) then 382 data_out <= "000" & adc_otr(3) & adc_data_array(3) & --exchange ... with data_cntr when testbenching. 383 "000" & adc_otr(2) & adc_data_array(2) & 384 "000" & adc_otr(1) & adc_data_array(1) & 385 "000" & adc_otr(0) & adc_data_array(0); 386 addr_cntr <= addr_cntr + 1; 387 state_generate <= WRITE_ADC_DATA; 388 data_cntr <= data_cntr + 1; 389 else 390 drs_clk_en <= '0'; 391 --adc_output_enable_inverted <= '1'; -- nur für Emulator 392 if (channel_id = 8) then 393 state_generate <= WRITE_EXTERNAL_TRIGGER; 394 adc_output_enable_inverted <= '1'; 395 -- switch off ADC_CLK 396 adc_clk_en <= '0'; 397 else 398 channel_id <= channel_id + 1; -- increment channel_id 399 state_generate <= START_DRS_READING; 400 data_cntr <= 0; 401 end if; 402 end if; 403 404 when WRITE_EXTERNAL_TRIGGER => -- external trigger ID 405 addr_out <= start_addr + conv_std_logic_vector(1, RAM_ADDR_WIDTH); 406 data_out <= FTM_trigger_info(15 downto 0) & 407 FTM_trigger_info(31 downto 16) & 408 FTM_trigger_info(47 downto 32) & 409 X"00" & FTM_trigger_info(55 downto 48); 410 state_generate <= WRITE_END_FLAG; 411 412 when WRITE_END_FLAG => 413 data_out <= conv_std_logic_vector(0, 32) & X"04FE" & X"4242"; 414 addr_cntr <= addr_cntr + 1; 415 state_generate <= WRITE_DATA_END; 416 when WRITE_DATA_END => 417 dataRAM_write_ea_o <= "0"; 418 --information to: memory manager. 419 -- one Event was completely written into dataRAM. 420 ram_write_ready <= '1'; 421 state_generate <= WRITE_DATA_END_WAIT; 422 when WRITE_DATA_END_WAIT => 423 -- check if memory manager received the formaer information. 424 -- go on to next state. 425 if (ram_write_ready_ack = '1') then 426 state_generate <= WRITE_DATA_STOP; 427 ram_write_ready <= '0'; 428 end if; 429 when WRITE_DATA_STOP => 430 if (ram_write_ready_ack = '0') then 431 drs_readout_ready <= '1'; --info to: trigger manager. 432 data_cntr <= 0; 433 addr_cntr <= 0; 434 channel_id <= 0; 435 state_generate <= WRITE_DATA_STOP1; 436 end if; 437 when WRITE_DATA_STOP1 => 438 if (drs_readout_ready_ack = '1') then 439 drs_readout_ready <= '0'; 440 state_generate <= WRITE_DATA_IDLE; 441 end if; 442 when others => 443 null; 444 end case; -- state_generate 445 end if; -- rising_edge (clk) 446 end process generate_data; 425 447 end Behavioral; 426 427 -
firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/drs_pulser.vhd
r9912 r10174 9 9 10 10 ENTITY drs_pulser is 11 port ( 12 -- input CLK; RSRLOAD and SRCLK are derived from this signal 13 CLK : in std_logic; 14 -- async reset; 15 reset : in std_logic; 16 17 start_endless_mode : in std_logic; 18 start_read_stop_pos_mode : in std_logic; 19 20 SROUT_in_0 : in std_logic; 21 SROUT_in_1 : in std_logic; 22 SROUT_in_2 : in std_logic; 23 SROUT_in_3 : in std_logic; 24 25 -- stop_pos_0 : out std_logic_vector(9 downto 0); 26 -- stop_pos_1 : out std_logic_vector(9 downto 0); 27 -- stop_pos_2 : out std_logic_vector(9 downto 0); 28 -- stop_pos_3 : out std_logic_vector(9 downto 0); 29 stop_pos : out drs_s_cell_array_type; 30 stop_pos_valid : out std_logic; 31 32 RSRLOAD : out std_logic; 33 SRCLK : out std_logic; 34 busy :out std_logic 35 ); 11 port ( 12 -- input CLK; RSRLOAD and SRCLK are derived from this signal 13 CLK : in std_logic; 14 -- async reset; 15 reset : in std_logic; 16 17 start_endless_mode : in std_logic; 18 start_read_stop_pos_mode : in std_logic; 19 20 SROUT_in_0 : in std_logic; 21 SROUT_in_1 : in std_logic; 22 SROUT_in_2 : in std_logic; 23 SROUT_in_3 : in std_logic; 24 25 stop_pos : out drs_s_cell_array_type; 26 stop_pos_valid : out std_logic; 27 28 RSRLOAD : out std_logic; 29 SRCLK : out std_logic; 30 busy :out std_logic 31 ); 36 32 end drs_pulser; 37 33 -
firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/memory_manager_beha.vhd
r10172 r10174 51 51 wiz_write_end : OUT std_logic := '0'; 52 52 wiz_busy : IN std_logic; 53 54 53 wiz_ack : IN std_logic; 54 buffer_ram_empty : out std_logic; 55 55 ram_start_addr : OUT std_logic_vector (RAM_ADDR_WIDTH_64B-1 DOWNTO 0) := (others => '0') 56 56 ); -
firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/w5300_modul.vhd
r10172 r10174 39 39 -- start entire configuration chain 40 40 new_config : OUT std_logic := '0'; 41 config_chain_done : IN std_logic; 41 42 config_started : in std_logic; 42 43 -- read/write configRAM … … 599 600 600 601 when CONFIG => 601 -- led <= X"F0"; 602 new_config <= '1'; 603 if (config_started = '1') then 604 -- led <= X"0F"; 605 new_config <= '0'; 606 state_init <= MAIN; 607 end if; 602 new_config <= '1'; 603 state_init <= WAIT_FOR_CONFIG_DONE; 604 when WAIT_FOR_CONFIG_DONE => 605 new_config <= '0'; 606 if (config_chain_done ='1') then 607 state_init <= MAIN; 608 end if; 609 608 610 ----------------------------------------- 609 611 -- MAIN "loop" --------------------------
Note:
See TracChangeset
for help on using the changeset viewer.