Ignore:
Timestamp:
05/17/11 18:29:09 (14 years ago)
Author:
neise
Message:
 
Location:
firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/data_generator.vhd

    r10502 r10729  
    161161signal internal_roi_max : roi_max_type;
    162162
     163signal config_start_sr : std_logic_vector(1 downto 0) := "00";
     164
     165signal adc_data_sig : adc_data_array_type;
     166signal adc_otr_sig : std_logic_vector(3 downto 0) ;
     167type adc_data_16bit_t is array (3 downto 0) of sdt_logic_vector(15 downto 0);
     168signal data_16bit : adc_data_16bit_t;
     169
    163170begin
    164171drs_readout_started <= sig_drs_readout_started;
     
    166173begin
    167174        if rising_edge (clk) then
    168 
    169                 if (config_start = '1') then
     175        -- synch
     176        config_start_sr <= config_start_sr(0) & config_start;
     177
     178                if (config_start_sr(1) = '1') then
    170179                        config_start_sig <= '1';
    171180                        config_done <= '0';
     
    393402                                state_generate <= WRITE_ADC_DATA;
    394403                        end if;
     404
     405--              when CATCH_ADC_DATA =>
     406--                      adc_data_sig <= adc_data_array;
     407--                      adc_otr_sig <= adc_otr;
     408--                      state_generate <= PREPARE_ADC_DATA_01;
     409--                     
     410--              when PREPARE_ADC_DATA_01 =>
     411--                      for i in 3 downto 0 loop
     412--                              if (adc_otr_sig(i)='1') then
     413--                                      if (adc_data_sig(i)(11)='1') then
     414--                                              data_16bit(i) = X"8000" --this is decimal -1
     415--                                      else -- adc_data_sig(i)(11)='0'
     416--                                              data_16bit(i) = X"1001" --this is decimal +4097
     417--                                      end if;
     418--                              else -- no over/underflow
     419--                                      data_16bit(i) =
     420--                      end loop;
     421                       
     422               
     423                       
    395424                when WRITE_ADC_DATA =>
    396425                        if (data_cntr < roi_max_int (channel_id)) then
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/fad_board_struct.vhd

    r10567 r10729  
    33-- Created:
    44--          by - daqct3.UNKNOWN (IHP110)
    5 --          at - 15:22:10 04.05.2011
     5--          at - 17:58:44 17.05.2011
    66--
    77-- Generated by Mentor Graphics' HDL Designer(TM) 2009.1 (Build 12)
     
    7676-- Created:
    7777--          by - daqct3.UNKNOWN (IHP110)
    78 --          at - 15:22:11 04.05.2011
     78--          at - 17:58:44 17.05.2011
    7979--
    8080-- Generated by Mentor Graphics' HDL Designer(TM) 2009.1 (Build 12)
     
    105105   SIGNAL counter_result        : std_logic_vector(11 DOWNTO 0) := (others => '0');
    106106   SIGNAL crate_id              : std_logic_vector(1 DOWNTO 0);
     107   SIGNAL debug_data_ram_empty  : std_logic;
     108   SIGNAL debug_data_valid      : std_logic;
    107109   SIGNAL led                   : std_logic_vector(7 DOWNTO 0)  := (OTHERS => '0');
     110   SIGNAL w5300_state           : std_logic_vector(7 DOWNTO 0);                        -- state is encoded here ... useful for debugging.
    108111
    109112
     
    144147      counter_result        : OUT    std_logic_vector (11 DOWNTO 0);
    145148      dac_cs                : OUT    std_logic ;
     149      debug_data_ram_empty  : OUT    std_logic ;
     150      debug_data_valid      : OUT    std_logic ;
    146151      denable               : OUT    std_logic                     := '0';           -- default domino wave off
    147152      drs_channel_id        : OUT    std_logic_vector (3 DOWNTO 0) := (others => '0');
     
    154159      sensor_cs             : OUT    std_logic_vector (3 DOWNTO 0);
    155160      trigger_veto          : OUT    std_logic                     := '1';
     161      w5300_state           : OUT    std_logic_vector (7 DOWNTO 0);                  -- state is encoded here ... useful for debugging.
    156162      wiz_addr              : OUT    std_logic_vector (9 DOWNTO 0);
    157163      wiz_cs                : OUT    std_logic                     := '1';
     
    195201   
    196202   --D_T <= (others => '0');
     203   D_T <= w5300_state;
     204   D_T2(0) <= debug_data_valid;
     205   D_T2(1) <= debug_data_ram_empty;
    197206   --D_T2 <= ( others => '0' );
    198    D_T2(1) <= '0';
     207   
    199208   -- A0_T(7 downto 0) <= (others => '0');
    200209   --A1_T(7 downto 0) <= (others => '0');
    201210   
    202211   A1_T <= counter_result ( 7 downto 0);
    203    D_T(3 downto 0) <=  counter_result ( 11 downto 8);
    204    D_T(4) <= alarm_refclk_too_low;
    205    D_T(5) <= alarm_refclk_too_high;
    206    D_T(6) <= '0';
    207    D_T(7) <= '0';
     212   --D_T(3 downto 0) <=  counter_result ( 11 downto 8);
     213   --D_T(4) <= alarm_refclk_too_low;
     214   --D_T(5) <= alarm_refclk_too_high;
     215   --D_T(6) <= '0';
     216   --D_T(7) <= '0';
    208217   
    209218   -- led output is driven by w5300 modul
     
    216225   RS485_C_DO <= '0';
    217226   -- MAX3485 receiver out pit is fed out... should be HIGH-Z
    218    D_T2(0) <= RS485_C_DI;
     227   
    219228   
    220229   -- EEPROM is not used on FAD. CS is always high.
     
    258267         counter_result        => counter_result,
    259268         dac_cs                => DAC_CS,
     269         debug_data_ram_empty  => debug_data_ram_empty,
     270         debug_data_valid      => debug_data_valid,
    260271         denable               => DENABLE,
    261272         drs_channel_id        => D_A,
     
    268279         sensor_cs             => TCS,
    269280         trigger_veto          => TRG_V,
     281         w5300_state           => w5300_state,
    270282         wiz_addr              => W_A,
    271283         wiz_cs                => W_CS,
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/fad_definitions.vhd

    r10567 r10729  
    5757        --constant SUBVERSION_NUMBER : std_logic_vector (15 downto 0) := conv_std_logic_vector(str_to_int(SUBVERSION_STRING),16);
    5858        constant PACKAGE_VERSION : std_logic_vector(7 downto 0) := X"01";
    59         constant PACKAGE_SUB_VERSION : std_logic_vector(7 downto 0) := X"04";
     59        constant PACKAGE_SUB_VERSION : std_logic_vector(7 downto 0) := X"07";
    6060        constant PACKAGE_HEADER_LENGTH : integer := 36;
    6161        constant PACKAGE_HEADER_ZEROS : integer := 0; 
     
    8989  constant W5300_MTYPER : std_logic_vector (9 downto 0) := W5300_BASE_ADR + X"30";
    9090       
    91         constant W5300_S0_MR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"0";
    92         constant W5300_S0_CR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"2";
    93         constant W5300_S0_IMR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"4";
    94         constant W5300_S0_IR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"6";
    95         constant W5300_S0_SSR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"8";
    96         constant W5300_S0_PORTR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"A";
    97         constant W5300_S0_DPORTR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"12";
    98         constant W5300_S0_DIPR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"14";
    99         constant W5300_S0_TX_WRSR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"20";
    100         constant W5300_S0_TX_FSR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"24";
    101   constant W5300_S0_RX_RSR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"28";
    102         constant W5300_S0_TX_FIFOR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"2E";
    103   constant W5300_S0_RX_FIFOR : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"30";
     91        constant W5300_S0_MR            : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"0";
     92        constant W5300_S0_CR            : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"2";
     93        constant W5300_S0_IMR           : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"4";
     94        constant W5300_S0_IR            : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"6";
     95        constant W5300_S0_SSR           : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"8";
     96        constant W5300_S0_PORTR         : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"A";
     97        constant W5300_S0_DPORTR        : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"12";
     98        constant W5300_S0_DIPR          : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"14";
     99        constant W5300_S0_PORTOR        : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"1A";  -- HIGH byte is S0_KPALVTR register
     100        constant W5300_S0_TX_WRSR       : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"20";
     101        constant W5300_S0_TX_FSR        : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"24";
     102  constant W5300_S0_RX_RSR              : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"28";
     103        constant W5300_S0_TX_FIFOR      : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"2E";
     104  constant W5300_S0_RX_FIFOR    : std_logic_vector (9 downto 0) := W5300_BASE_ADR + "1000000000" + X"30";
    104105-- End W5300 registers 
    105106
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/fad_main_struct.vhd

    r10567 r10729  
    33-- Created:
    44--          by - daqct3.UNKNOWN (IHP110)
    5 --          at - 15:22:09 04.05.2011
     5--          at - 17:58:42 17.05.2011
    66--
    77-- Generated by Mentor Graphics' HDL Designer(TM) 2009.1 (Build 12)
     
    4848      counter_result        : OUT    std_logic_vector (11 DOWNTO 0);
    4949      dac_cs                : OUT    std_logic;
     50      debug_data_ram_empty  : OUT    std_logic;
     51      debug_data_valid      : OUT    std_logic;
    5052      denable               : OUT    std_logic                     := '0';              -- default domino wave off
    5153      drs_channel_id        : OUT    std_logic_vector (3 DOWNTO 0) := (others => '0');
     
    5860      sensor_cs             : OUT    std_logic_vector (3 DOWNTO 0);
    5961      trigger_veto          : OUT    std_logic                     := '1';
     62      w5300_state           : OUT    std_logic_vector (7 DOWNTO 0);                     -- state is encoded here ... useful for debugging.
    6063      wiz_addr              : OUT    std_logic_vector (9 DOWNTO 0);
    6164      wiz_cs                : OUT    std_logic                     := '1';
     
    7679-- Created:
    7780--          by - daqct3.UNKNOWN (IHP110)
    78 --          at - 15:22:10 04.05.2011
     81--          at - 17:58:43 17.05.2011
    7982--
    8083-- Generated by Mentor Graphics' HDL Designer(TM) 2009.1 (Build 12)
     
    484487   );
    485488   PORT (
     489      state                         : OUT    std_logic_vector (7 DOWNTO 0);                                  -- state is encoded here ... useful for debugging.
     490      debug_data_ram_empty          : OUT    std_logic ;
     491      debug_data_valid              : OUT    std_logic ;
    486492      clk                           : IN     std_logic ;
    487493      wiz_reset                     : OUT    std_logic                      := '1';
     
    886892      )
    887893      PORT MAP (
     894         state                         => w5300_state,
     895         debug_data_ram_empty          => debug_data_ram_empty,
     896         debug_data_valid              => debug_data_valid,
    888897         clk                           => CLK_50_internal,
    889898         wiz_reset                     => wiz_reset,
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/memory_manager_beha.vhd

    r10225 r10729  
    102102signal temp_roi : integer range 0 to 1024 := 0;
    103103
     104-- SYNCH IN INPUT SIGNALS -----------------------------------------
     105
     106        signal config_start_sr          : std_logic_vector(1 downto 0) := "00";
     107        signal ram_write_ready_sr       : std_logic_vector(1 downto 0) := "00";
     108        signal wiz_busy_sr                      : std_logic_vector(1 downto 0) := "00";
     109        signal wiz_ack_sr                       : std_logic_vector(1 downto 0) := "00";
     110                -- no shift register, but local copy.
     111        signal roi_array_local : roi_array_type;
     112
    104113BEGIN
    105114
     
    110119  begin
    111120    if rising_edge (clk) then
     121        -- here: the synchin in of asynchronous input signals takes place.
     122        config_start_sr         <= config_start_sr(0) & config_start;
     123        ram_write_ready_sr      <= ram_write_ready_sr(0) & ram_write_ready;
     124        wiz_busy_sr                     <= wiz_busy_sr(0) & wiz_busy;
     125        wiz_ack_sr                      <= wiz_ack_sr(0) & wiz_ack;
     126
     127        roi_array_local         <= roi_array;
     128       
    112129      case state_mm is
    113130   
    114131        when MM_CONFIG =>
    115           if (config_start = '1') then
     132                        -- this if clause was doubled ... already in MAIN state config_start = '1' was checked...
     133                        -- this is imho not needed and can cause trouble... DN 17.05.11
     134          --if (config_start_sr = "11") then
    116135            config_ready <= '0';
    117136            roi_max_array <= (others => 0);
     
    122141            ram_write_ea <= '0';
    123142            state_mm <= MAX_ROI;
    124           end if;
     143          --end if;
    125144       
    126145        -- calculate max ROIs and channel sizes
     
    129148          state_mm <= MAX_ROI1;
    130149        when MAX_ROI1 =>
    131           temp_roi <= roi_array (roi_index);
     150          temp_roi <= roi_array_local (roi_index);
    132151          state_mm <= MAX_ROI2;
    133152        when MAX_ROI2 =>
     
    222241        when MM_MAIN =>
    223242          state_mm <= MM_MAIN1;
    224           if (config_start = '1') then
     243          if (config_start_sr = "11") then
    225244            --config_ready <= '0';
    226245            if (events_in_ram = 0) then
     
    231250        when MM_MAIN1 =>
    232251          state_mm <= MM_MAIN2;
    233           if ((ram_write_ready = '1') and (event_ready_flag = '0')) then
     252          if ((ram_write_ready_sr = "11") and (event_ready_flag = '0')) then
    234253            ram_write_ea <= '0';
    235254            -- --
     
    248267        when MM_MAIN2 =>
    249268          state_mm <= MM_MAIN3;
    250           if ((event_ready_flag = '1') and (ram_write_ready = '0')) then
     269          if ((event_ready_flag = '1') and (ram_write_ready_sr = "00")) then
    251270            if (events_in_ram < max_events_ram) then
    252271              ram_write_ea <= '1';             
     
    261280        when MM_MAIN3 =>
    262281          state_mm <= MM_MAIN4;
    263           if ((wiz_ack = '1') and (wiz_ack_flag = '0')) then
     282          if ((wiz_ack_sr = "11") and (wiz_ack_flag = '0')) then
    264283            wiz_ack_flag <= '1';
    265284            wiz_write_ea <= '0';
     
    279298        when MM_MAIN4 =>
    280299          state_mm <= MM_MAIN;
    281           if ((events_in_ram > 0) and (wiz_busy = '0')) then
     300          if ((events_in_ram > 0) and (wiz_busy_sr = "00")) then
    282301            if (package_index < number_of_packages) then             
    283302              wiz_ram_start_addr <= conv_std_logic_vector(write_start_addr, RAM_ADDR_WIDTH_16B);
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/spi_controller_beha.vhd

    r9912 r10729  
    3939  signal data_reg      : std_logic_vector (15 downto 0) := (others => '0');
    4040 
     41  signal dac_start_sr           : std_logic_vector (1 downto 0) := "00";
     42  signal sensor_start_sr        : std_logic_vector (1 downto 0) := "00";
     43 
    4144BEGIN
    4245 
     
    4447  begin
    4548    if falling_edge(clk) then
     49                dac_start_sr    <= dac_start_sr(0)              & dac_start;
     50                sensor_start_sr <= sensor_start_sr(0)   & sensor_start;
     51               
     52       
    4653      dac_cs <= '1';
    4754      sensor_cs <= (others => '1');
     
    5158      case spi_state is
    5259        when SPI_IDLE =>
    53           if (dac_start = '1') then
     60          if (dac_start_sr(1) = '1') then
    5461            dac_ready <= '0';
    5562            spi_state <= SPI_LOAD_COMMAND;
    56           elsif (sensor_start = '1') then
     63          elsif (sensor_start_sr(1) = '1') then
    5764            sensor_valid <= '0';
    5865            spi_state <= SPI_LOAD_COMMAND;
     
    6168        when SPI_LOAD_COMMAND =>
    6269          spi_cycle_cnt <= 0;
    63             if (sensor_start = '1') then
     70            if (sensor_start_sr(1) = '1') then
    6471              shift_reg <= X"C1" & X"0000";   -- command: Temperature register read
    6572              spi_state <= SPI_GET_TEMP;
    66             elsif (dac_start = '1') then
     73            elsif (dac_start_sr(1) = '1') then
    6774              shift_reg <= "0011" & '0' & dac_id & data;
    6875              spi_state <= SPI_LOAD_DAC;
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/spi_distributor_beha.vhd

    r10225 r10729  
    5858  signal sclk_enable_override_sig : std_logic := '0';
    5959 
     60  -- synching signals
     61  signal config_start_sr                : std_logic_vector (1 downto 0) := "00";
     62 
    6063BEGIN
    6164  sclk_enable_override <= sclk_enable_override_sig;
     
    6669   
    6770    if rising_edge(clk) then
     71                -- synch in
     72                config_start_sr <= config_start_sr(0) & config_start;
     73               
    6874      data <= (others => 'Z');
    6975      case spi_distr_state is
     
    8086          data <= (others => 'Z');
    8187         -- start DAC configuration
    82           if (config_start = '1' AND int_sensor_valid = '1') then
     88          if (config_start_sr(1) = '1' AND int_sensor_valid = '1') then
    8389            config_ready <= '0';
    8490                        sclk_enable_override_sig <= '1';
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/spi_interface_struct.vhd

    r10225 r10729  
    33-- Created:
    44--          by - daqct3.UNKNOWN (IHP110)
    5 --          at - 16:52:21 02.03.2011
     5--          at - 10:39:55 17.05.2011
    66--
    77-- Generated by Mentor Graphics' HDL Designer(TM) 2009.1 (Build 12)
     
    3939-- Created:
    4040--          by - daqct3.UNKNOWN (IHP110)
    41 --          at - 16:52:21 02.03.2011
     41--          at - 10:39:56 17.05.2011
    4242--
    4343-- Generated by Mentor Graphics' HDL Designer(TM) 2009.1 (Build 12)
  • firmware/FAD/FACT_FAD_20MHz_VAR_PS/FACT_FAD_lib/hdl/w5300_modul.vhd

    r10565 r10729  
    1212  );
    1313   PORT(
     14      state          : OUT    std_logic_vector (7 DOWNTO 0);  -- state is encoded here ... useful for debugging.
     15          debug_data_ram_empty : OUT    std_logic;
     16          debug_data_valid : OUT    std_logic;
     17     
    1418      clk            : IN     std_logic;
    1519      wiz_reset      : OUT    std_logic                     := '1';
     
    3438      c_trigger_enable: out std_logic := '0';
    3539      c_trigger_mult: out std_logic_vector (15 DOWNTO 0) := conv_std_logic_vector(0 ,16); --subject to changes
     40     
     41     
    3642
    3743          -- FAD configuration signals:
     
    94100END w5300_modul ;
    95101
    96 architecture Behavioral of w5300_modul is
     102architecture Behavioral of w5300_modul is 
    97103
    98104type state_init_type is (
    99105        INTERRUPT, RESET, WRITE_REG, READ_REG, WRITE_DATA,
    100106        INIT, LOCATE, IM, MT, STX, STX1, STX2, STX3, SRX, SRX1, SRX2, SRX3, MAC, MAC1, MAC2, GW, GW1, SNM, SNM1, IP, IP1, TIMEOUT, RETRY,
    101         SI, SI1, SI2, SI3, SI4, SI5, SI6,       ESTABLISH, EST1,
     107        SI, SI1, SI1b, SI2, SI3, SI4, SI5, SI6, ESTABLISH, EST1,
    102108       
    103         CONFIG,
    104         WAIT_FOR_OLLI,
    105         WAIT_FOR_DATA_RAM_EMPTY,
     109        --CONFIG, WAIT_FOR_OLLI, WAIT_FOR_DATA_RAM_EMPTY,
    106110        CONFIG_MEMORY_MANAGER, WAIT_FOR_CONFIG_MEMORY_MANAGER,
    107111        CONFIG_DATA_GENERATOR, WAIT_FOR_CONFIG_DATA_GENERATOR,
     
    185189signal local_fifo_channels : std_logic_vector (3 downto 0);
    186190
    187 signal data_ram_empty_sr : std_logic_vector (3 downto 0) := "0000";
    188 
    189191signal config_addr : integer range 0 to 44;
    190192type config_data_type is array (0 to 46) of std_logic_vector(15 downto 0);
     
    219221
    220222        -- signals for synching in asynchronous input signals
    221         ------------------------------------------------------------------------------
    222         signal w5300_interrupt_sr : std_logic_vector(1 downto 0) := "11";
    223          --?? not sure if this init value is good
    224          -- but should be no problem, because interrupt_ignore is not true during the first 2 clock cycles.
    225          -- I hope!
    226         signal data_valid_sr : std_logic_vector(1 downto 0) := "00";
    227         ------------------------------------------------------------------------------
    228 
     223                ------------------------------------------------------------------------------
     224                signal w5300_interrupt_sr : std_logic_vector(1 downto 0) := "11";
     225                 --?? not sure if this init value is good
     226                 -- but should be no problem, because interrupt_ignore is not true during the first 2 clock cycles.
     227                 -- I hope!
     228                signal data_valid_sr : std_logic_vector(1 downto 0) := "00";
     229                ------------------------------------------------------------------------------
     230                -- synch in CONFIG inputs
     231                signal memory_manager_config_valid_i_sr         : std_logic_vector(1 downto 0) := "00";
     232                signal spi_interface_config_valid_i_sr          : std_logic_vector(1 downto 0) := "00";
     233                signal data_generator_config_valid_i_sr         : std_logic_vector(1 downto 0) := "00";
     234                signal data_ram_empty_sr                                        : std_logic_vector(1 downto 0) := (OTHERS => '0');
     235
     236
     237               
    229238
    230239-- only for debugging
     
    243252signal mod7_result : std_logic_vector(2 downto 0);
    244253
     254signal state_sig : std_logic_vector(7 downto 0) := X"FF";
    245255
    246256
     
    279289 
    280290-- output config settings as DAC and ROI arrays.
    281 
     291state <= state_sig;
     292debug_data_ram_empty <= data_ram_empty_sr(1);
     293debug_data_valid <= data_valid_sr(1);
    282294
    283295roi_mapping : for i in 0 to 35 generate
     
    296308        begin
    297309                if rising_edge (clk) then
    298                 -- synch asynchronous input in:
    299                 data_ram_empty_sr <= data_ram_empty_sr(2 downto 0) & data_ram_empty;
    300                 w5300_interrupt_sr <= w5300_interrupt_sr(1) & int;
    301                 data_valid_sr <= data_valid_sr(1) & data_valid;
     310                -- synch asynchronous inputs in:
     311                memory_manager_config_valid_i_sr        <= memory_manager_config_valid_i_sr(0)  & memory_manager_config_valid_i;
     312                spi_interface_config_valid_i_sr         <= spi_interface_config_valid_i_sr(0)   & spi_interface_config_valid_i;
     313                data_generator_config_valid_i_sr        <=      data_generator_config_valid_i_sr(0)     & data_generator_config_valid_i;
     314                data_ram_empty_sr                                       <= data_ram_empty_sr(0)                 & data_ram_empty;                               
     315               
     316                w5300_interrupt_sr <= w5300_interrupt_sr(0) & int;
     317                data_valid_sr <= data_valid_sr(0) & data_valid;
    302318               
    303319                        -- interrupt is handled synchronously
     
    393409                                        -- reset W5300
    394410                                        when RESET =>
     411                                          state_sig <= X"01";
    395412                                                socket_send_mode <= '0';
    396413                                                busy <= '1';
     
    418435                                        -- Init
    419436                                        when INIT =>
     437                                          state_sig <= X"02";
    420438                                                -- status of MAC jumpers is synched in
    421439                                                -- and Board- and CrateID are synched in
     
    429447                                                next_state <= LOCATE;
    430448                               
    431                                         when LOCATE =>                                   
     449                                        when LOCATE =>
     450                                           state_sig <= X"03";                                   
    432451                                                state_init <= IM;
    433452
     
    481500                                        -- Interrupt Mask
    482501                                        when IM =>
     502                                          state_sig <= X"04";
    483503                                                par_addr <= W5300_IMR;
    484504                                                par_data <= X"00FF"; -- S0-S7 Interrupts
     
    604624                                        -- Socket Init
    605625                                        when SI =>
     626                                          state_sig <= X"05";
    606627                                                par_addr <= W5300_S0_MR + socket_cnt * W5300_S_INC;
    607628                                                par_data <= X"0101"; -- ALIGN, TCP
     
    613634                                                par_data <= X"000A"; -- TIMEOUT, DISCON
    614635                                                state_init <= WRITE_REG;
    615                                                 next_state <= SI2;
     636                                                next_state <= SI1b;
     637                                        when SI1b =>
     638                                                par_addr <= W5300_S0_PORTOR + socket_cnt * W5300_S_INC;
     639                                                par_data <= X"0606"; -- send automatic KEEP ALIVE every 30s.
     640                                                state_init <= WRITE_REG;
     641                                                next_state <= SI2;                                             
    616642                                        when SI2 =>
    617643                                                par_addr <= W5300_S0_PORTR + socket_cnt * W5300_S_INC;
     
    668694                                                end case;
    669695                                               
    670                                         when CONFIG =>   -- Triggers are disabled here!
    671                                                 trigger_enable_storage_sig <= trigger_enable_sig;                               -- store last value of this signal.
    672                                                 trigger_enable_sig <= '0';                                                                              --no triggers must occur, while configurating.
    673                                                 state_init <= WAIT_FOR_OLLI;                                                                    -- now wait until the last event was send down..
    674                                        
    675                                         when WAIT_FOR_OLLI =>                                                                                   -- This single wait state is not needed, I guess.
    676                                                 state_init <= WAIT_FOR_DATA_RAM_EMPTY;                                          -- should be removed asap, but not now. 28.04.11 DN
    677                                        
    678                                                
    679                                         when WAIT_FOR_DATA_RAM_EMPTY =>
    680                                                 if (data_ram_empty_sr(3) = '1') then
    681                                                         state_init <= CONFIG_MEMORY_MANAGER;
    682                                                 end if;
     696--                                      when CONFIG =>   -- Triggers are disabled here!
     697--                                        state_sig <= X"06";
     698--                                              trigger_enable_storage_sig <= trigger_enable_sig;                               -- store last value of this signal.
     699--                                              trigger_enable_sig <= '0';                                                                              --no triggers must occur, while configurating.
     700--                                              state_init <= WAIT_FOR_OLLI;                                                                    -- now wait until the last event was send down..
     701--                                     
     702--                                      when WAIT_FOR_OLLI =>                                                                                   -- This single wait state is not needed, I guess.
     703--                                        state_sig <= X"16";
     704--                                              state_init <= WAIT_FOR_DATA_RAM_EMPTY;                                          -- should be removed asap, but not now. 28.04.11 DN
     705--                                     
     706--                                             
     707--                                      when WAIT_FOR_DATA_RAM_EMPTY =>
     708--                                        state_sig <= X"17";
     709--                                              if (data_ram_empty_sr(1) = '1') then
     710--                                                      state_init <= CONFIG_MEMORY_MANAGER;
     711--                                              end if;
    683712                                       
    684713                                        when CONFIG_MEMORY_MANAGER =>
     714                                          state_sig <= X"18";
    685715                                                memory_manager_config_start_o <= '1';
    686                                                 if (memory_manager_config_valid_i = '0') then
     716                                                if (memory_manager_config_valid_i_sr = "00") then
    687717                                                        state_init <= WAIT_FOR_CONFIG_MEMORY_MANAGER;
    688718                                                end if;
    689719                                       
    690720                                        when WAIT_FOR_CONFIG_MEMORY_MANAGER =>
     721                                          state_sig <= X"19";
    691722                                                memory_manager_config_start_o <= '0';
    692                                                 if (memory_manager_config_valid_i = '1') then
     723                                                if (memory_manager_config_valid_i_sr = "11") then
    693724                                                        state_init <= CONFIG_DATA_GENERATOR;
    694725                                                end if;
    695726                                       
    696727                                        when CONFIG_DATA_GENERATOR =>
     728                                          state_sig <= X"1A";
    697729                                                data_generator_config_start_o <= '1';
    698                                                 if (data_generator_config_valid_i = '0') then
     730                                                if (data_generator_config_valid_i_sr = "00") then
    699731                                                        state_init <= WAIT_FOR_CONFIG_DATA_GENERATOR;
    700732                                                end if;
    701733                                        when WAIT_FOR_CONFIG_DATA_GENERATOR =>
     734                                          state_sig <= X"1B";
    702735                                                data_generator_config_start_o <= '0';
    703                                                 if (data_generator_config_valid_i = '1') then
     736                                                if (data_generator_config_valid_i_sr ="11") then
    704737                                                        trigger_enable_sig <= trigger_enable_storage_sig; --restore value of this signal to the value it had before CONFIG
    705738                                                        state_init <= MAIN;
     
    708741                                               
    709742                                                when CONFIG_DAC_ONLY =>
     743                                                  state_sig <= X"1C";
    710744                                                        spi_interface_config_start_o <= '1';
    711                                                         if (spi_interface_config_valid_i ='0') then
     745                                                        if (spi_interface_config_valid_i_sr ="00") then
    712746                                                                state_init <= WAIT_FOR_CONFIG_DAC_ONLY;
    713747                                                        end if;
    714748                                               
    715749                                                when WAIT_FOR_CONFIG_DAC_ONLY =>
     750                                                  state_sig <= X"1D";
    716751                                                        spi_interface_config_start_o <= '0';
    717                                                         if (spi_interface_config_valid_i ='1') then
     752                                                        if (spi_interface_config_valid_i_sr ="11") then
    718753                                                                state_init <= MAIN;
    719754                                                        end if;
     
    724759         
    725760                                        when MAIN =>
     761                                        state_sig <= X"20";
     762                                        socks_waiting <= '0';
     763                                        socks_connected <= '1';
     764                                        ps_do_phase_shift <= '0';
     765                                        ps_reset <= '0';
     766                                        data_valid_ack <= '0';
    726767                                       
    727768                                               
    728                                                 if (update_of_rois = '1') then                         
    729                                                         update_of_rois <= '0';
    730                                                         state_init <= CONFIG;
     769                                                if (update_of_rois = '1') then
     770                                                        trigger_enable_storage_sig <= trigger_enable_sig;
     771                                                        trigger_enable_sig <= '0';
     772
     773                                                        if (data_ram_empty_sr(1) = '1') then
     774                                                                update_of_rois <= '0';
     775                                                                state_init <= CONFIG_MEMORY_MANAGER;
     776                                                        else
     777                                                                state_init <= MAIN2;
     778                                                        end if;
    731779                                                elsif (update_of_lessimportant = '1') then                             
    732780                                                        update_of_lessimportant <= '0';
    733781                                                        state_init <= CONFIG_DAC_ONLY;
    734782                                                elsif ( update_of_rois='0' and update_of_lessimportant='0' ) then
    735                                                         socks_waiting <= '0';
    736                                                         socks_connected <= '1';
    737                                                         ps_do_phase_shift <= '0';
    738                                                         ps_reset <= '0';
    739                                                         data_valid_ack <= '0';
    740783                                                        state_init <= MAIN1;
    741784                                                        --data_valid_int <= data_valid;
     
    743786                       
    744787                                        when MAIN1 =>
     788                                          state_sig <= X"21";
    745789                                                if (chk_recv_cntr = 1000) then
    746790                                                        chk_recv_cntr <= 0;
     
    753797                                                end if;
    754798                                        when MAIN2 =>
     799                                          state_sig <= X"22";
    755800                                                busy <= '0';
    756801                                                --if (data_valid = '1') then
    757                                                 if (data_valid_sr = "01" or data_valid_sr = "11") then
     802                                                if (data_valid_sr(1) = '1') then
    758803                                                        --data_valid_int <= '0';
    759804                                                        busy <= '1';
     
    769814                                                        state_init <= MAIN3;
    770815                                                else
    771                                                         state_init <= MAIN1;
     816                                                        state_init <= MAIN;  -- MAIN1
    772817                                                end if;
    773818                                        when MAIN3 =>
     819                                          state_sig <= X"23";
    774820                                                -- needed for the check: if there is enough space in W5300 FIFO
    775821                                                write_length_bytes <= local_write_length (15 downto 0) & '0'; -- shift left (*2)
     
    786832                                                case state_read_data is
    787833                                                when RD_1 =>
     834                                                  state_sig <= X"30";
    788835                                                        par_addr <= W5300_S0_RX_RSR;
    789836                                                        state_init <= READ_REG;
     
    791838                                                        state_read_data <= RD_2;
    792839                                                when RD_2 =>
     840                                                  state_sig <= X"31";
    793841                                                        socket_rx_received (16) <= data_read(0);
    794842                                                        par_addr <= W5300_S0_RX_RSR + X"2";
     
    797845                                                        state_read_data <= RD_3;
    798846                                                when RD_3 =>
     847                                                  state_sig <= X"32";
    799848                                                        socket_rx_received (15 downto 0) <= data_read;
    800849                                                        state_read_data <= RD_4;
    801850                                                when RD_4 =>
     851                                                  state_sig <= X"33";
    802852                                                        if (socket_rx_received (16 downto 0) > ('0' & X"000")) then
    803853                                                                rx_packets_cnt <= socket_rx_received (16 downto 1); -- socket_rx_received / 2
     
    808858                                                        end if;
    809859                                                when RD_5 =>
     860                                                  state_sig <= X"34";
    810861                                                        s_trigger <= '0';
    811862                                                        ps_do_phase_shift <= '0';
     
    823874                                                       
    824875                                                when RD_6 =>
     876                                                  state_sig <= X"35";
    825877                                                        -- The next 16bit word is assumed to contain a 'command' so it is
    826878                                                        -- beeing parsed in this state
     
    905957                               
    906958                                                when WAIT_FOR_TRIGGER_ID_RESET_1 =>
     959                                                  state_sig <= X"36";
    907960                                                        state_read_data <= WAIT_FOR_TRIGGER_ID_RESET_2;
    908961                                                when WAIT_FOR_TRIGGER_ID_RESET_2 =>
     962                                                  state_sig <= X"37";
    909963                                                        state_read_data <= RD_5;
    910964                        -- these states are beeing processed, if the 'command' was a 'write command'
    911965                        --      so it is assumed, that some data in config RAM changed, and we need full (re)config
    912966                        when READ_COMMAND_DATA_SECTION =>
     967                          state_sig <= X"38";
    913968                                if (rx_packets_cnt > 0) then
    914969                                        rx_packets_cnt <= rx_packets_cnt - '1';
     
    922977                       
    923978                        when PUT_COMMAND_DATA_SECTION =>
     979                          state_sig <= X"39";
    924980                                config_setting(config_addr) <= data_read;
    925981                                if (config_addr < 36) then
     
    934990
    935991                        when RD_END =>
     992                          state_sig <= X"3A";
    936993                                par_addr <= W5300_S0_CR;
    937994                par_data <= X"0040"; -- RECV
    938995                state_init <= WRITE_REG;
    939996                                next_state <= MAIN;
    940 
    941 
     997                               
     998      when others =>
     999        state_sig <= X"3F";
     1000     
    9421001            end case; -- state_data_read
    9431002               
     
    9481007                                                       
    9491008                                                  when WR_START =>
     1009                                                    state_sig <= X"40";
    9501010                                                    if (local_write_header_flag = '1') then
    9511011                                                      ram_addr <= local_ram_start_addr + 6; -- Address of HIGH word of Event ID
     
    9561016                                                     
    9571017                                                  when WR_GET_EVT_ID_WAIT1 =>
     1018                                                    state_sig <= X"41";
    9581019                                                    state_write <= WR_GET_EVT_ID1;
    9591020                                                  when WR_GET_EVT_ID1 =>
     1021                                                    state_sig <= X"42";
    9601022                                                                event_number(31 downto 16) <= ram_data;
    9611023                                                                ram_addr <= local_ram_start_addr + 9; -- Address of LOW word of Event ID
     
    9641026                                                                state_write <= WR_GET_EVT_ID2;
    9651027                                                  when WR_GET_EVT_ID2 =>
     1028                                                    state_sig <= X"43";
    9661029                                                                event_number(15 downto 0) <= ram_data;
    9671030                                                                mod7_start <= '1';
     
    9731036                                                               
    9741037                                                        when WR_MOD7_STARTED =>
     1038                                                          state_sig <= X"44";
    9751039                                                                if (mod7_started = '1') then
    9761040                                                                        mod7_start <= '0';
     
    9791043
    9801044                                                        when WR_WAIT_FOR_MOD7 =>
     1045                                                          state_sig <= X"45";
    9811046                                                                if (mod7_valid = '1') then
    9821047                                                                        if (socket_send_mode = '1') then -- send via all sockets
     
    9941059                                                        -- Check FIFO Size
    9951060                                                        when WR_CHECK_FOR_FIFO_SPACE_01 =>
     1061                                                          state_sig <= X"46";
    9961062                                                                par_addr <= W5300_S0_TX_FSR + local_socket_nr * W5300_S_INC;
    9971063                                                                state_init <= READ_REG;
     
    9991065                                                                state_write <= WR_CHECK_FOR_FIFO_SPACE_02;
    10001066                                                        when WR_CHECK_FOR_FIFO_SPACE_02 =>
     1067                                                          state_sig <= X"47";
    10011068                                                                socket_tx_free (16) <= data_read(0);
    10021069                                                                par_addr <= W5300_S0_TX_FSR + (local_socket_nr * W5300_S_INC) + X"2";
     
    10051072                                                                state_write <= WR_CHECK_FOR_FIFO_SPACE_03;
    10061073                                                        when WR_CHECK_FOR_FIFO_SPACE_03 =>
     1074                                                          state_sig <= X"48";
    10071075                                                                socket_tx_free (15 downto 0) <= data_read;
    10081076                                                                state_write <= WR_CHECK_FOR_FIFO_SPACE_04;
    10091077                                                        when WR_CHECK_FOR_FIFO_SPACE_04 =>
     1078                                                          state_sig <= X"49";
    10101079--                                                              if (socket_tx_free (16 downto 0) < write_length_bytes) then
    10111080                                                                if (socket_tx_free (16 downto 0) < W5300_TX_FIFO_SIZE_8B) then
     
    10231092                                                        -- Write Header
    10241093                                                        when WR_FIFO =>
     1094                                                          state_sig <= X"4A";
    10251095                                                                ram_addr <= local_ram_start_addr + local_ram_addr;
    10261096                                                                state_write <= WR_FIFO1;
    10271097                                                        when WR_FIFO1 =>
     1098                                                          state_sig <= X"4B";
    10281099                                                                data_cnt <= data_cnt + 1;
    10291100                                                                if (data_cnt < PACKAGE_HEADER_LENGTH) then --???
     
    10481119                                                        ---- Start...
    10491120                                                        when WR_ADC =>
     1121                                                          state_sig <= X"4C";
    10501122                                                                adc_data_addr <= local_ram_start_addr + local_ram_addr;
    10511123                                                                drs_cnt <= 0;
     
    10581130                                                        ---- Write Channel
    10591131                                                        when WR_ADC1 =>
     1132                                                          state_sig <= X"4D";
    10601133                                                                -- read ROI and set end of Channel-Data
    10611134                                                                if (data_cnt = POSITION_OF_ROI_IN_CHANNEL_HEADER) then
     
    11061179              -- Write End Package Flag
    11071180              when WR_ENDFLAG =>
     1181                state_sig <= X"4E";
    11081182                ram_addr <= adc_data_addr + ((conv_integer(roi_max) + CHANNEL_HEADER_SIZE) * 4);
    11091183                state_write <= WR_ENDFLAG1;
     
    11551229                                                                state_init <= next_state_tmp;
    11561230                                                                state_write <= WR_START;
     1231                                                                state_sig <= X"4F";
    11571232                                                end case;
    11581233                                                -- End WRITE_DATA
    11591234                                               
    11601235                                        when READ_REG =>
     1236                                          state_sig <= X"50";
    11611237                                                case count is
    11621238                                                        when "000" =>
     
    11861262                                       
    11871263                                        when WRITE_REG =>
     1264                                          state_sig <= X"60";
    11881265                                                case count is
    11891266                                                        when "000" =>
     
    12081285                                                                count <= "000";
    12091286                                                        when others =>
     1287                                                          state_sig <= X"E0";
    12101288                                                                null;
    12111289                                                end case;
    12121290                                       
    12131291                                        when others =>
     1292                                          state_sig <= X"F0";
    12141293                                                null;
    12151294                                end case;
Note: See TracChangeset for help on using the changeset viewer.