Ignore:
Timestamp:
06/01/11 08:09:24 (13 years ago)
Author:
neise
Message:
completed w5300_interface implementation.
needs testing now
File:
1 edited

Legend:

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

    r10888 r10891  
    88
    99ENTITY w5300_modul2 IS
    10   generic(
    11     RAM_ADDR_WIDTH : integer := 14
    12   );
     10
    1311   PORT(
    1412      state          : OUT    std_logic_vector (7 DOWNTO 0);  -- state is encoded here ... useful for debugging.
     
    1614          debug_data_valid : OUT    std_logic;
    1715          data_generator_idle_i : IN std_logic;
    18           socket_tx_free_out : out std_logic_vector (16 DOWNTO 0);  -- 17bit value .. that's true
    1916     
    2017      clk            : IN     std_logic;
     
    2724          rd             : OUT    std_logic                     := '1';
    2825         
    29       led            : OUT    std_logic_vector (7 DOWNTO 0) := (OTHERS => '0');
    3026     
    3127      int            : IN     std_logic;
    3228      write_length   : IN     std_logic_vector (16 DOWNTO 0);
    33       ram_start_addr : IN     std_logic_vector (RAM_ADDR_WIDTH-1 DOWNTO 0);
     29      ram_start_addr : IN     std_logic_vector (W5300_RAM_ADDR_WIDTH-1 DOWNTO 0);
    3430      ram_data       : IN     std_logic_vector (15 DOWNTO 0);
    35       ram_addr       : OUT    std_logic_vector (RAM_ADDR_WIDTH-1 DOWNTO 0);
     31      ram_addr       : OUT    std_logic_vector (W5300_RAM_ADDR_WIDTH-1 DOWNTO 0);
    3632      data_valid     : IN     std_logic;
    3733      data_valid_ack : OUT    std_logic := '0';
     
    123119        SI, SI1, SI1b, SI2, SI3, SI4, SI5, SI6, ESTABLISH, EST1,
    124120       
    125         CONFIG, WAIT_100NS, WAIT_UNTIL_DG_IDLE, WAIT_FOR_DATA_RAM_EMPTY,  -- <-- this is THE deadlock state
     121        CONFIG, WAIT_100NS, WAIT_UNTIL_DG_IDLE,
    126122        CONFIG_MEMORY_MANAGER, WAIT_FOR_CONFIG_MEMORY_MANAGER,
    127123        CONFIG_DATA_GENERATOR, WAIT_FOR_CONFIG_DATA_GENERATOR,
     
    130126        MAIN, MAIN1, MAIN2, MAIN3, CHK_RECEIVED, READ_DATA
    131127);
     128
    132129type state_write_type is (
    133130        WR_START,
     
    135132        WR_MOD7_STARTED, WR_WAIT_FOR_MOD7,
    136133        WR_CHECK_FOR_FIFO_SPACE_01, WR_CHECK_FOR_FIFO_SPACE_02, WR_CHECK_FOR_FIFO_SPACE_03, WR_CHECK_FOR_FIFO_SPACE_04,
    137         WR_05, WR_05_PREPARE_LENGTH_INFO, WR_05_POSTPREPARE_LENGTH_INFO,
    138         WR_05a, WR_05b, WR_06, WR_07,
     134        WR_05_PREPARE_LENGTH_INFO, WR_05_POSTPREPARE_LENGTH_INFO,
     135        WR_STRANGE_WAIT,
    139136        WR_ACK, WR_WAIT_FOR_ACK,
    140137        WR_HEADER_FETCH, WR_HEADER_WAIT, WR_HEADER,
    141        
    142138        WR_FIFO, WR_FIFO1, WR_ADC, WR_ADC1, WR_ADC2,
    143         WR_ENDFLAG, WR_ENDFLAG1, WR_ENDFLAG2, WR_ENDFLAG3
     139        WR_ENDFLAG, WR_ENDFLAG1, WR_ENDFLAG2
    144140);
    145141type state_interrupt_1_type is (IR1_01, IR1_02, IR1_03, IR1_04);
    146 type state_interrupt_2_type is (IR2_01, IR2_02, IR2_03, IR2_04, IR2_05, IR2_06);
     142type state_interrupt_2_type is (
     143        IR2_GET_IR,
     144        IR2_CHECK_WHICH_SN_IRQ,
     145        IR2_GET_SN_IR,
     146        IR2_CLEAR_SN_IR,
     147        IR2_SEND_DISCON,
     148        IR2_GET_SOCKn_STATUS,
     149        IR2_WAIT_SOCKn_CLOSED,
     150        IR2_GOTO_RESET);
    147151type state_read_data_type is (
    148152        RD_1,
     
    157161        RD_END
    158162);
    159 
    160 signal RST_TIME : std_logic_vector(19 downto 0) := X"7A120";
    161 
    162 signal par_addr : std_logic_vector (9 downto 0) := (OTHERS => '0');
    163 signal par_data : std_logic_vector (15 downto 0) := (OTHERS => '0');
    164 signal data_read : std_logic_vector (15 downto 0) := (OTHERS => '0');
    165 signal adc_data_addr : std_logic_vector (RAM_ADDR_WIDTH-1 DOWNTO 0);
    166 
    167 signal state_init, next_state , next_state_tmp : state_init_type := RESET;
    168 signal count : std_logic_vector (2 downto 0) := "000";
     163signal state_init : state_init_type := RESET;
    169164signal state_write : state_write_type := WR_START;
    170165signal state_interrupt_1 : state_interrupt_1_type := IR1_01;
    171 signal state_interrupt_2 : state_interrupt_2_type := IR2_01;
     166signal state_interrupt_2 : state_interrupt_2_type := IR2_GET_IR;
    172167signal state_read_data : state_read_data_type := RD_1;
     168
     169signal RST_TIME : std_logic_vector(19 downto 0) := X"7A120";    -- 0x7A120=500000 @50MHz --> 10ms
     170
     171signal wiz_addr : std_logic_vector (9 downto 0) := (OTHERS => '0');
     172signal wiz_data : std_logic_vector (15 downto 0) := (OTHERS => '0');
     173signal data_read : std_logic_vector (15 downto 0) := (OTHERS => '0');
     174signal adc_data_addr : std_logic_vector (W5300_RAM_ADDR_WIDTH-1 DOWNTO 0);
    173175
    174176signal interrupt_ignore : std_logic := '1';
    175177signal int_flag : std_logic := '0';
    176 signal ram_access : std_logic := '0';
    177 
    178 signal zaehler : std_logic_vector (19 downto 0) := (OTHERS => '0');
    179 signal data_cnt : integer := 0;
    180 signal drs_cnt : integer :=0;
     178
     179signal data_cnt : integer range 0 to 7680 := 0;
     180signal data_end : integer range 0 to 7680 := 0;
     181signal drs_cnt : integer range 0 to 3 := 0;
    181182signal channel_cnt : integer range 0 to 9 :=0;
    182 signal socket_cnt : std_logic_vector (2 downto 0) := "000";
    183 signal roi_max : std_logic_vector (10 downto 0);
    184 signal data_end : integer := 0;
     183signal socket_cnt : integer range 0 to 7 := 0;
     184signal roi_max : std_logic_vector (10 downto 0) := (others => '0');
     185
    185186
    186187signal socket_tx_free : std_logic_vector (16 downto 0) := (others => '0');
     
    204205
    205206signal local_write_length   : std_logic_vector (16 DOWNTO 0);
    206 signal local_ram_start_addr : std_logic_vector (RAM_ADDR_WIDTH-1 DOWNTO 0);
    207 signal local_ram_addr       : std_logic_vector (RAM_ADDR_WIDTH-1 downto 0);
     207signal local_ram_start_addr : std_logic_vector (W5300_RAM_ADDR_WIDTH-1 DOWNTO 0);
     208signal local_ram_addr       : std_logic_vector (W5300_RAM_ADDR_WIDTH-1 downto 0);
    208209signal local_socket_nr      : std_logic_vector (2 DOWNTO 0);
    209210signal local_write_header_flag, local_write_end_flag : std_logic;
     
    352353                read_i                  => read_wi,
    353354                write_i                 => write_wi,
    354                 addr_i                  => par_addr,
     355                addr_i                  => wiz_addr,
    355356                data_o                  => data_read,
    356                 data_i                  => par_data,
     357                data_i                  => wiz_data,
    357358                ready_o                 => ready_wi,
    358359                reset_i                 => reset_wi
     
    390391                write_wi <= '0';
    391392                read_wi <= '0';
    392                 --socket_tx_free_out <= socket_tx_free;
    393393               
    394                
    395                 -- synch asynchronous inputs in:
     394       
    396395                memory_manager_config_valid_i_sr        <= memory_manager_config_valid_i_sr(0)  & memory_manager_config_valid_i;
    397396                spi_interface_config_valid_i_sr         <= spi_interface_config_valid_i_sr(0)   & spi_interface_config_valid_i;
    398                 --data_generator_config_valid_i_sr      <=      data_generator_config_valid_i_sr(0)     & data_generator_config_valid_i;
    399397                data_ram_empty_sr                                       <= data_ram_empty_sr(0)                 & data_ram_empty;               
    400398                data_generator_idle_sr                          <= data_generator_idle_sr( 1 downto 0 ) & data_generator_idle_i;
     
    413411                                case state_interrupt_1 is
    414412                                        when IR1_01 =>
    415                                         state_sig <= X"FF";
    416413                                                int_flag <= '1';
    417                                                 busy <= '1';
    418414                                                state_interrupt_1 <= IR1_02;  --wait one cycle
    419415                                        when IR1_02 =>
    420                                         state_sig <= X"FE";
    421416                                                state_interrupt_1 <= IR1_03;
    422417                                        when IR1_03 =>
    423                                         state_sig <= X"FD";
    424418                                                state_init <= INTERRUPT;
    425                                                 socket_cnt <= "000";
    426                                                 ram_access <= '0';
    427                                                 zaehler <= X"00000";    --what is this zaehler counting?
    428                                                 count <= "000";                 --what is this count counting?
     419                                                socket_cnt <= 0;
    429420                                                int_flag <= '0';
    430421                                                interrupt_ignore <= '1';
    431422                                                state_interrupt_1 <= IR1_04;  --this state is not existing? bad coding habit???
    432423                                        when others =>
    433                                                 state_sig <= X"FC";
    434424                                                null;
    435425                                end case;
     
    441431                                        when INTERRUPT =>
    442432                                                case state_interrupt_2 is
    443                                                         when IR2_01 =>
    444                                                         state_sig <= X"FB";
    445                                                                 par_addr <= W5300_IR;
    446                                                                 state_init <= READ_REG;
    447                                                                 next_state <= INTERRUPT;
    448                                                                 state_interrupt_2 <= IR2_02;
     433                                                        when IR2_GET_IR =>
     434                                                                if (ready_wi = '1') then
     435                                                                        wiz_addr <= W5300_IR;
     436                                                                        read_wi <= '1';
     437                                                                        state_interrupt_2 <= IR2_CHECK_WHICH_SN_IRQ;
     438                                                                end if;
    449439                                                               
    450440                                                        -- check if it was a Sx Interrupt of Socket n
    451441                                                        -- therfor: loop over all channel.
    452                                                         -- if the loop ended but no Sx Interrupt was found --> IR2_06
    453                                                         -- if an Sx Interrupt was found go to --> IR2_03 and check what happened.
    454                                                         when IR2_02 =>
    455                                                         state_sig <= X"FA";
    456                                                                 if (data_read (conv_integer(socket_cnt)) = '1') then -- Sx Interrupt
    457                                                                         state_interrupt_2 <= IR2_03;
    458                                                                 else
     442                                                        -- if the loop ended but no Sx Interrupt was found --> IR2_GOTO_RESET
     443                                                        -- if an Sx Interrupt was found go to --> IR2_GET_SN_IR and check what happened.
     444                                                        when IR2_CHECK_WHICH_SN_IRQ =>
     445                                                                if (ready_wi = '1') then
     446                                                                        if (data_read(socket_cnt) = '1') then -- Sx Interrupt
     447                                                                                state_interrupt_2 <= IR2_GET_SN_IR;
     448                                                                        else
     449                                                                                socket_cnt <= socket_cnt + 1;
     450                                                                                if (socket_cnt = 7) then
     451                                                                                        state_interrupt_2 <= IR2_GOTO_RESET;
     452                                                                                else
     453                                                                                        state_interrupt_2 <= IR2_CHECK_WHICH_SN_IRQ;  -- go on with loop
     454                                                                                end if;
     455                                                                        end if;
     456                                                                end if;
     457                                                               
     458                                                        -- check the Interrupt register of the Socket to be able to clear them
     459                                                        when IR2_GET_SN_IR =>
     460                                                                if (ready_wi = '1') then
     461                                                                        wiz_addr <= W5300_S0_IR + socket_cnt * W5300_S_INC; -- Sx Interrupt Register
     462                                                                        read_wi <= '1';
     463                                                                        state_interrupt_2 <= IR2_CLEAR_SN_IR;
     464                                                                end if;
     465                                                        -- clear IRQs by writing ones.
     466                                                        when IR2_CLEAR_SN_IR =>
     467                                                                if (ready_wi = '1') then
     468                                                                        wiz_addr <= W5300_S0_IR + socket_cnt * W5300_S_INC;
     469                                                                        wiz_data <= data_read; -- clear Interrupts
     470                                                                        write_wi <= '1';
     471                                                                        state_interrupt_2 <= IR2_SEND_DISCON;
     472                                                                end if;
     473                                                               
     474                                                        -- send the command to close this socket
     475                                                        -- then go back and read the main Interrupt register again,
     476                                                        -- if this was not Socket 7 ... if it was Socket 7, we're done anyway.
     477                                                        when IR2_SEND_DISCON =>
     478                                                                if (ready_wi = '1') then
     479                                                                        wiz_addr <= W5300_S0_CR + socket_cnt * W5300_S_INC;
     480                                                                        wiz_data <= X"0008"; -- DISCON  --> W5300 wil send FIN packet
     481                                                                        write_wi <= '1';
    459482                                                                        socket_cnt <= socket_cnt + 1;
     483                                                               
    460484                                                                        if (socket_cnt = 7) then
    461                                                                                 state_interrupt_2 <= IR2_06;
     485                                                                                socket_cnt = 0;
     486                                                                                state_interrupt_2 <= IR2_WAIT_UNTIL_SOCKS_CLOSED;
    462487                                                                        else
    463                                                                                 state_interrupt_2 <= IR2_02;  -- go on with loop
     488                                                                                state_interrupt_2 <= IR2_GET_IR;
    464489                                                                        end if;
    465490                                                                end if;
    466491                                                               
    467                                                         -- check the Interrupt register of the Socket, which caused the Interrupt.
    468                                                         when IR2_03 =>
    469                                                         state_sig <= X"F9";
    470                                                                 par_addr <= W5300_S0_IR + socket_cnt * W5300_S_INC; -- Sx Interrupt Register
    471                                                                 state_init <= READ_REG;
    472                                                                 next_state <= INTERRUPT;
    473                                                                 state_interrupt_2 <= IR2_04;
    474                                                         -- before checking what happened, clear the Interrupt register, so we can proceed.
    475                                                         when IR2_04 =>
    476                                                         state_sig <= X"F8";
    477                                                                 par_addr <= W5300_S0_IR + socket_cnt * W5300_S_INC;
    478                                                                 par_data <= data_read; -- clear Interrupts
    479                                                                 state_init <= WRITE_REG;
    480                                                                 next_state <= INTERRUPT;
    481                                                                 state_interrupt_2 <= IR2_05;
    482                                                         -- send the command to close this socket
    483                                                         -- then go back and read the main Interrupt register again,
    484                                                         -- if this was not Socket 7 ... if it was Socket 7, we're done anyway.
    485                                                         when IR2_05 =>
    486                                                         state_sig <= X"F7";
    487                                                                 par_addr <= W5300_S0_CR + socket_cnt * W5300_S_INC;
    488                                                                 par_data <= X"0010"; -- CLOSE
    489                                                                 state_init <= WRITE_REG;
    490                                                                 next_state <= INTERRUPT;
    491                                                                 socket_cnt <= socket_cnt + 1;
    492                                                                 if (socket_cnt = 7) then
    493                                                                   state_interrupt_2 <= IR2_06;
    494                                                                 else
    495                                                                   state_interrupt_2 <= IR2_01;
    496                                                                 end if;
    497 
    498                                                         -- we go on and reset, the W5300 and this entire state machine.
    499                                                         when IR2_06 =>
     492                                                        when IR2_GET_SOCKn_STATUS =>
     493                                                                if (ready_wi = '1') then
     494                                                                        wiz_addr <= W5300_S0_CR + socket_cnt * W5300_S_INC;
     495                                                                        read_wi = '1';
     496                                                                        state_interrupt_2 <= IR2_WAIT_SOCKn_CLOSED;
     497                                                                end if;
     498                                                               
     499                                                        when IR2_WAIT_SOCKn_CLOSED =>
     500                                                                if (ready_wi = '1') then
     501                                                                        if (data_read = X"0000") then --closed
     502                                                                                if (socket_cnt = 7) then
     503                                                                                        socket_cnt <= 0;
     504                                                                                        state_interrupt_2 <= IR2_GOTO_RESET;
     505                                                                                else
     506                                                                                        socket_cnt <= socket_cnt + 1;
     507                                                                                        state_interrupt_2 <= IR2_GET_SOCKn_STATUS;
     508                                                                                end if;
     509                                                                        end if;
     510                                                                end if;
     511                                                       
     512                                                               
     513                                                       
     514                                                        when IR2_GOTO_RESET =>
    500515                                                        state_sig <= X"F6";
    501516                                                                state_interrupt_1 <= IR1_01;
    502                                                                 state_interrupt_2 <= IR2_01;
    503                                                                 socket_cnt <= "000";
     517                                                                state_interrupt_2 <= IR2_GET_IR;
     518                                                                socket_cnt <= 0;
    504519                                                                state_init <= RESET;
    505520                                                        when others =>
    506                                                                 state_interrupt_1 <= IR1_01;
    507                                                                 state_interrupt_2 <= IR2_01;
    508                                                                 socket_cnt <= "000";
    509                                                                 state_init <= RESET;
    510                                                 end case;
     521                                                                null;
     522                                                        end case;
    511523                                               
    512524                                        -- reset W5300
     
    518530                                                socks_waiting <= '0';
    519531                                                socks_connected <= '0';
    520                                                 socket_cnt <= "000";
    521                                                 count <= "000";
    522                                                 ram_access <= '0';
     532                                                socket_cnt <= 0;
    523533                                                interrupt_ignore <= '0';
    524534                                               
     
    544554                                                cid <= CrateID;
    545555                                               
    546                                                 par_addr <= W5300_MR;
    547                                                 par_data <= X"0000";
     556                                                wiz_addr <= W5300_MR;
     557                                                wiz_data <= X"0000";
    548558                                                if (ready_wi = '1') then
    549559                                                        write_wi <= '1';
     
    606616                                        when IM =>
    607617                                                state_sig <= X"04";
    608                                                 par_addr <= W5300_IMR;
    609                                                 par_data <= X"00FF"; -- S0-S7 Interrupts
     618                                                wiz_addr <= W5300_IMR;
     619                                                wiz_data <= X"00FF"; -- S0-S7 Interrupts
    610620                                                if (ready_wi = '1') then
    611621                                                        write_wi <= '1';
     
    616626                                        -- Memory Type
    617627                                        when MT =>
    618                                                 par_addr <=     W5300_MTYPER;
    619                                                 par_data <= X"7FFF"; -- 8K RX, 120K TX-Buffer
     628                                                wiz_addr <=     W5300_MTYPER;
     629                                                wiz_data <= X"7FFF"; -- 8K RX, 120K TX-Buffer
    620630                                                if (ready_wi = '1') then
    621631                                                        write_wi <= '1';
     
    625635                                        -- Socket TX Memory Size
    626636                                        when STX0 =>
    627                                                 par_addr <= W5300_TMS01R;
    628                                                 par_data <= X"0F0F"; -- 15K TX
     637                                                wiz_addr <= W5300_TMS01R;
     638                                                wiz_data <= X"0F0F"; -- 15K TX
    629639                                                if (ready_wi = '1') then
    630640                                                        write_wi <= '1';
     
    632642                                                end if;
    633643                                        when STX1 =>
    634                                                 par_addr <= W5300_TMS23R;
    635                                                 par_data <= X"0F0F"; -- 15K TX
     644                                                wiz_addr <= W5300_TMS23R;
     645                                                wiz_data <= X"0F0F"; -- 15K TX
    636646                                                if (ready_wi = '1') then
    637647                                                        write_wi <= '1';
     
    640650                                                                               
    641651                                        when STX2 =>
    642                                                 par_addr <= W5300_TMS45R;
    643                                                 par_data <= X"0F0F"; -- 15K TX
     652                                                wiz_addr <= W5300_TMS45R;
     653                                                wiz_data <= X"0F0F"; -- 15K TX
    644654                                                if (ready_wi = '1') then
    645655                                                        write_wi <= '1';
     
    648658
    649659                                        when STX3 =>
    650                                                 par_addr <= W5300_TMS67R;
    651                                                 par_data <= X"0F0F"; -- 15K TX
     660                                                wiz_addr <= W5300_TMS67R;
     661                                                wiz_data <= X"0F0F"; -- 15K TX
    652662                                                if (ready_wi = '1') then
    653663                                                        write_wi <= '1';
     
    657667                                        -- Socket RX Memory Size
    658668                                        when SRX0 =>
    659                                                 par_data <= X"0101"; -- 1K RX
    660                                                 par_addr <= W5300_RMS01R;
     669                                                wiz_data <= X"0101"; -- 1K RX
     670                                                wiz_addr <= W5300_RMS01R;
    661671                                                if (ready_wi = '1') then
    662672                                                        write_wi <= '1';
     
    664674                                                end if;
    665675                                        when SRX1 =>
    666                                                 par_data <= X"0101"; -- 1K RX
    667                                                 par_addr <= W5300_RMS23R;
     676                                                wiz_data <= X"0101"; -- 1K RX
     677                                                wiz_addr <= W5300_RMS23R;
    668678                                                if (ready_wi = '1') then
    669679                                                        write_wi <= '1';
     
    671681                                                end if;
    672682                                        when SRX2 =>
    673                                                 par_data <= X"0101"; -- 1K RX
    674                                                 par_addr <= W5300_RMS45R;
     683                                                wiz_data <= X"0101"; -- 1K RX
     684                                                wiz_addr <= W5300_RMS45R;
    675685                                                if (ready_wi = '1') then
    676686                                                        write_wi <= '1';
     
    678688                                                end if;
    679689                                        when SRX3 =>
    680                                                 par_data <= X"0101"; -- 1K RX
    681                                                 par_addr <= W5300_RMS67R;
     690                                                wiz_data <= X"0101"; -- 1K RX
     691                                                wiz_addr <= W5300_RMS67R;
    682692                                                if (ready_wi = '1') then
    683693                                                        write_wi <= '1';
     
    687697                                        -- MAC
    688698                                        when MAC0 =>
    689                                                 par_addr <= W5300_SHAR;
    690                                                 par_data <= mac_loc(0);
     699                                                wiz_addr <= W5300_SHAR;
     700                                                wiz_data <= mac_loc(0);
    691701                                                if (ready_wi = '1') then
    692702                                                        write_wi <= '1';
     
    695705
    696706                                        when MAC1 =>
    697                                                 par_addr <= W5300_SHAR + 2;
    698                                                 par_data <= mac_loc(1);
     707                                                wiz_addr <= W5300_SHAR + 2;
     708                                                wiz_data <= mac_loc(1);
    699709                                                if (ready_wi = '1') then
    700710                                                        write_wi <= '1';
     
    702712                                                end if;
    703713                                        when MAC2 =>
    704                                                 par_addr <= W5300_SHAR + 4;
    705                                                 par_data <= mac_loc(2);
     714                                                wiz_addr <= W5300_SHAR + 4;
     715                                                wiz_data <= mac_loc(2);
    706716                                                if (ready_wi = '1') then
    707717                                                        write_wi <= '1';
     
    711721                                        -- Gateway
    712722                                        when GW0 =>
    713                                                 par_addr <= W5300_GAR;
    714                                                 par_data (15 downto 8) <= conv_std_logic_vector(gateway_loc(0),8);
    715                                                 par_data (7 downto 0) <= conv_std_logic_vector(gateway_loc(1),8);
     723                                                wiz_addr <= W5300_GAR;
     724                                                wiz_data (15 downto 8) <= conv_std_logic_vector(gateway_loc(0),8);
     725                                                wiz_data (7 downto 0) <= conv_std_logic_vector(gateway_loc(1),8);
    716726                                                if (ready_wi = '1') then
    717727                                                        write_wi <= '1';
     
    720730                                               
    721731                                        when GW1 =>
    722                                                 par_addr <= W5300_GAR + 2;
    723                                                 par_data (15 downto 8) <= conv_std_logic_vector(gateway_loc(2),8);
    724                                                 par_data (7 downto 0) <= conv_std_logic_vector(gateway_loc(3),8);
     732                                                wiz_addr <= W5300_GAR + 2;
     733                                                wiz_data (15 downto 8) <= conv_std_logic_vector(gateway_loc(2),8);
     734                                                wiz_data (7 downto 0) <= conv_std_logic_vector(gateway_loc(3),8);
    725735                                                if (ready_wi = '1') then
    726736                                                        write_wi <= '1';
     
    730740                                        -- Subnet Mask
    731741                                        when SNM0 =>
    732                                                 par_addr <= W5300_SUBR;
    733                                                 par_data (15 downto 8) <= conv_std_logic_vector(netmask_loc(0),8);
    734                                                 par_data (7 downto 0) <= conv_std_logic_vector(netmask_loc(1),8);
     742                                                wiz_addr <= W5300_SUBR;
     743                                                wiz_data (15 downto 8) <= conv_std_logic_vector(netmask_loc(0),8);
     744                                                wiz_data (7 downto 0) <= conv_std_logic_vector(netmask_loc(1),8);
    735745                                                if (ready_wi = '1') then
    736746                                                        write_wi <= '1';
     
    738748                                                end if;
    739749                                        when SNM1 =>
    740                                                 par_addr <= W5300_SUBR + 2;
    741                                                 par_data (15 downto 8) <= conv_std_logic_vector(netmask_loc(2),8);
    742                                                 par_data (7 downto 0) <= conv_std_logic_vector(netmask_loc(3),8);
     750                                                wiz_addr <= W5300_SUBR + 2;
     751                                                wiz_data (15 downto 8) <= conv_std_logic_vector(netmask_loc(2),8);
     752                                                wiz_data (7 downto 0) <= conv_std_logic_vector(netmask_loc(3),8);
    743753                                                if (ready_wi = '1') then
    744754                                                        write_wi <= '1';
     
    747757                                        -- Own IP-Address
    748758                                        when IP0 =>
    749                                                 par_addr <= W5300_SIPR;
    750                                                 par_data (15 downto 8) <= conv_std_logic_vector(ip_loc(0),8);
    751                                                 par_data (7 downto 0) <= conv_std_logic_vector(ip_loc(1),8);
     759                                                wiz_addr <= W5300_SIPR;
     760                                                wiz_data (15 downto 8) <= conv_std_logic_vector(ip_loc(0),8);
     761                                                wiz_data (7 downto 0) <= conv_std_logic_vector(ip_loc(1),8);
    752762                                                if (ready_wi = '1') then
    753763                                                        write_wi <= '1';
     
    755765                                                end if;
    756766                                        when IP1 =>
    757                                                 par_addr <= W5300_SIPR + 2;
    758                                                 par_data (15 downto 8) <= conv_std_logic_vector(ip_loc(2),8);
    759                                                 par_data (7 downto 0) <= conv_std_logic_vector(ip_loc(3),8);
     767                                                wiz_addr <= W5300_SIPR + 2;
     768                                                wiz_data (15 downto 8) <= conv_std_logic_vector(ip_loc(2),8);
     769                                                wiz_data (7 downto 0) <= conv_std_logic_vector(ip_loc(3),8);
    760770                                                if (ready_wi = '1') then
    761771                                                        write_wi <= '1';
     
    766776                                        when SI_MR =>
    767777                                          state_sig <= X"05";
    768                                                 par_addr <= W5300_S0_MR + socket_cnt * W5300_S_INC;
    769                                                 par_data <= X"0101"; -- ALIGN, TCP
     778                                                wiz_addr <= W5300_S0_MR + socket_cnt * W5300_S_INC;
     779                                                wiz_data <= X"0101"; -- ALIGN, TCP
    770780                                                if (ready_wi = '1') then
    771781                                                        write_wi <= '1';
     
    774784                                        -- Sx Interrupt Mask
    775785                                        when SI_IMR =>
    776                                                 par_addr <= W5300_S0_IMR + socket_cnt * W5300_S_INC;
    777                                                 par_data <= X"000A"; -- TIMEOUT, DISCON
     786                                                wiz_addr <= W5300_S0_IMR + socket_cnt * W5300_S_INC;
     787                                                wiz_data <= X"000A"; -- TIMEOUT, DISCON
    778788                                                if (ready_wi = '1') then
    779789                                                        write_wi <= '1';
     
    781791                                                end if;
    782792                                        when SI_PORTOR =>
    783                                                 par_addr <= W5300_S0_PORTOR + socket_cnt * W5300_S_INC;
    784                                                 par_data <= X"0606"; -- send automatic KEEP ALIVE every 30s.
     793                                                wiz_addr <= W5300_S0_PORTOR + socket_cnt * W5300_S_INC;
     794                                                wiz_data <= X"0606"; -- send automatic KEEP ALIVE every 30s.
    785795                                                if (ready_wi = '1') then
    786796                                                        write_wi <= '1';
     
    788798                                                end if;
    789799                                        when SI_PORT =>
    790                                                 par_addr <= W5300_S0_PORTR + socket_cnt * W5300_S_INC;
    791                                                 par_data <= conv_std_logic_vector(FIRST_PORT + unsigned (socket_cnt), 16);
     800                                                wiz_addr <= W5300_S0_PORTR + socket_cnt * W5300_S_INC;
     801                                                wiz_data <= conv_std_logic_vector(FIRST_PORT + socket_cnt, 16);
    792802                                                if (ready_wi = '1') then
    793803                                                        write_wi <= '1';
     
    795805                                                end if;
    796806                                        when SI_CR_OPEN =>
    797                                                 par_addr <= W5300_S0_CR + socket_cnt * W5300_S_INC;
    798                                                 par_data <= X"0001"; -- OPEN
     807                                                wiz_addr <= W5300_S0_CR + socket_cnt * W5300_S_INC;
     808                                                wiz_data <= X"0001"; -- OPEN
    799809                                                if (ready_wi = '1') then
    800810                                                        write_wi <= '1';
     
    802812                                                end if;
    803813                                        when SI_SSR =>
    804                                                 par_addr <= W5300_S0_SSR + socket_cnt * W5300_S_INC;
     814                                                wiz_addr <= W5300_S0_SSR + socket_cnt * W5300_S_INC;
    805815                                                if (ready_wi = '1') then
    806816                                                        read_wi <= '1';
     
    816826                                                end if;
    817827                                        when SI_CR_LISTEN =>
    818                                                 par_addr <= W5300_S0_CR + socket_cnt * W5300_S_INC;
    819                                                 par_data <= X"0002"; -- LISTEN
     828                                                wiz_addr <= W5300_S0_CR + socket_cnt * W5300_S_INC;
     829                                                wiz_data <= X"0002"; -- LISTEN
    820830                                                if (ready_wi = '1') then
    821831                                                        write_wi <= '1';
    822832                                                        socket_cnt <= socket_cnt + 1;
    823833                                                        if (socket_cnt = 7) then
    824                                                                 socket_cnt <= "000";
     834                                                                socket_cnt <= 0;
    825835                                                                state_init <= ESTABLISH;
    826836                                                        else
     
    836846                                                socks_waiting <= '1';
    837847                                                socks_connected <= '0';
    838                                                 par_addr <= W5300_S0_SSR + socket_cnt * W5300_S_INC;
     848                                                wiz_addr <= W5300_S0_SSR + socket_cnt * W5300_S_INC;
    839849                                                if (ready_wi = '1') then
    840850                                                        read_wi <= '1';
     
    847857                                                                when X"17" => -- established
    848858                                                                        if (socket_cnt = 7) then
    849                                                                           socket_cnt <= "000";
     859                                                                          socket_cnt <= 0;
    850860                                                                          busy <= '0';
    851861                                                                          state_init <= MAIN;
     
    866876                                                state_init <= WAIT_100NS;                                                                               
    867877                                               
    868                                         when WAIT_100NS =>
     878                                        -- this wait for 100ns is not entirely understood, maybe it is not even
     879                                        -- necessary, but I guess under certain circumstances
     880                                        -- DG might be triggered, just when I pull the trigger enable line low.
     881                                        -- when I check no immediatly, if DG is in IDLE, it might *just* be.
     882                                        -- but about to go into another state.
     883                                        -- DG and WM live in different clock domains.
     884                                        -- so I wait 100ns .. in order to let DG make one last transition out of IDLE
     885                                        -- then in the next state I wait until Dg returns.
     886                                        -- this must always happen, there is no way for DG to stay for a long time in any other state.
     887                                                        -- in order to ensure this, the DG MM 'data was just written into RAM' handshake was tweaked!
     888                                        when WAIT_100NS =>   
    869889                                                state_sig <= X"15";
    870890                                                wait_100ns_sig <= wait_100ns_sig + 1;
     
    892912                                                memory_manager_config_start_o <= '0';
    893913                                                if (memory_manager_config_valid_i_sr(1) = '1') then
    894                                                         --state_init <= CONFIG_DATA_GENERATOR;
     914                                                        trigger_enable_sig <= trigger_enable_storage_sig;
    895915                                                        state_init <= MAIN;
    896916                                                end if;
     
    978998                                                -- needed for the check: if there is enough space in W5300 FIFO
    979999                                                write_length_bytes <= (local_write_length (15 downto 0) & '0')   ; -- shift left (*2)
    980                                                
    981                                                 next_state <= MAIN;
    9821000                                                state_init <= WRITE_DATA;
    9831001                                               
     
    9931011                                                  state_sig <= X"30";
    9941012                                                        if (ready_wi = '1') then
    995                                                                 par_addr <= W5300_S0_RX_RSR;
     1013                                                                wiz_addr <= W5300_S0_RX_RSR;
    9961014                                                                read_wi <= '1';
    9971015                                                                state_read_data <= RD_2;
     
    10011019                                                  state_sig <= X"31";
    10021020                                                        if (ready_wi = '1') then
    1003                                                                 par_addr <= W5300_S0_RX_RSR + X"2";
     1021                                                                wiz_addr <= W5300_S0_RX_RSR + X"2";
    10041022                                                                read_wi <= '1';
    10051023                                                                socket_rx_received (16) <= data_read(0);
     
    10321050                                                        if (rx_packets_cnt > 0) then
    10331051                                                                if (ready_wi = '1') then
    1034                                                                         par_addr <= W5300_S0_RX_FIFOR;
     1052                                                                        wiz_addr <= W5300_S0_RX_FIFOR;
    10351053                                                                        read_wi <= '1';
    10361054                                                                        rx_packets_cnt <= rx_packets_cnt - '1';
     
    11381156                                                                if (ready_wi = '1') then
    11391157                                                                        rx_packets_cnt <= rx_packets_cnt - '1';
    1140                                                                         par_addr <= W5300_S0_RX_FIFOR;
     1158                                                                        wiz_addr <= W5300_S0_RX_FIFOR;
    11411159                                                                        state_read_data <= PUT_COMMAND_DATA_SECTION;
    11421160                                                                end if;
     
    11631181                                                       
    11641182                                                        if (ready_wi = '1') then
    1165                                                                 par_addr <= W5300_S0_CR;
    1166                                                                 par_data <= X"0040"; -- RECV
     1183                                                                wiz_addr <= W5300_S0_CR;
     1184                                                                wiz_data <= X"0040"; -- RECV
    11671185                                                                write_wi <= '1';
    11681186                                                                state_read_data <= RD_1;
     
    12191237                                                when WR_WAIT_FOR_MOD7 =>
    12201238                                                        state_sig <= X"45";
    1221                                                         next_state_tmp <= next_state;
    12221239                                                        if (mod7_valid = '1') then
    12231240                                                                if (socket_send_mode = '1') then -- send via all sockets
     
    12261243                                                                        local_socket_nr <= "000";
    12271244                                                                end if;
    1228                                                                         data_cnt <= 0;
    1229                                                                         state_write <= WR_CHECK_FOR_FIFO_SPACE_01; 
     1245                                                                data_cnt <= 0;
     1246                                                                state_write <= WR_CHECK_FOR_FIFO_SPACE_01; 
    12301247                                                        else
    12311248                                                                state_write <= WR_WAIT_FOR_MOD7;
     
    12361253                                                        state_sig <= X"46";
    12371254                                                        if (ready_wi = '1') then
    1238                                                                 par_addr <= W5300_S0_TX_FSR + local_socket_nr * W5300_S_INC;
     1255                                                                wiz_addr <= W5300_S0_TX_FSR + local_socket_nr * W5300_S_INC;
    12391256                                                                read_wi <= '1';
    12401257                                                                state_write <= WR_CHECK_FOR_FIFO_SPACE_02;
     
    12451262                                                        if (ready_wi = '1') then
    12461263                                                                socket_tx_free (16) <= data_read(0);
    1247                                                                 par_addr <= W5300_S0_TX_FSR + (local_socket_nr * W5300_S_INC) + X"2";
     1264                                                                wiz_addr <= W5300_S0_TX_FSR + (local_socket_nr * W5300_S_INC) + X"2";
    12481265                                                                state_write <= WR_CHECK_FOR_FIFO_SPACE_03;
    12491266                                                                read_wi <= '1';
     
    12591276                                                when WR_CHECK_FOR_FIFO_SPACE_04 =>
    12601277                                                        state_sig <= X"49";
    1261                                                         socket_tx_free_out <= socket_tx_free;
    12621278--                                                              if (socket_tx_free (16 downto 0) < write_length_bytes) then
    12631279                                                        if (socket_tx_free (16 downto 0) < W5300_TX_FIFO_SIZE_8B) then
     
    12941310                                                        state_sig <= X"4B";
    12951311                                                        if (ready_wi = '1') then
    1296                                                                 par_addr <= W5300_S0_TX_FIFOR + local_socket_nr * W5300_S_INC;
    1297                                                                 par_data <= ram_data;
     1312                                                                wiz_addr <= W5300_S0_TX_FIFOR + local_socket_nr * W5300_S_INC;
     1313                                                                wiz_data <= ram_data;
    12981314                                                                number_of_words_written_to_fifo <= number_of_words_written_to_fifo + 1;
    12991315                                                                data_cnt <= data_cnt + 1;
     
    13121328                                                -- Write ADC
    13131329                                                ------------------------------------------------
     1330                                                -- Writing of ADC data is performed in a manner such that, groups of DRS channels
     1331                                                -- with equal channel indices fit completely into W5300 FIFO
     1332                                                -- note:
     1333                                                        -- drs index            : counts from 0 to 3
     1334                                                        -- channel index        : counts from 0 to 9
     1335                                                -- e.g. when the ROI is large, not the whole event data fits completly
     1336                                                -- into the FIFO
     1337                                                -- in this case the Header is written first,
     1338                                                -- followed by the channels with index = 0 of all 4 DRS chips.
     1339                                                -- and further followed by the channels, having index = 1 of all DRS chips.
     1340                                                -- the channels are written 'side-by-side' into the data ram, using the 64bit input.
     1341                                                -- but they are read out 'as if written consecutivly'
     1342                                                -- so the address needs to be calculated like this
     1343                                                -- addr(n+1) = addr(n) + 4; instead of
     1344                                                -- addr(n+1) = addr(n) + 1 in case of the header.
     1345                                               
    13141346                                                when WR_ADC =>
    13151347                                                        state_sig <= X"4C";
     1348                                                       
     1349                                                        -- when this line is executed for the first time adc_data_address points
     1350                                                        -- to the beginning of a channel header. e.g. to 0x0000 or 0x0039
    13161351                                                        adc_data_addr <= local_ram_start_addr + local_ram_addr;
    1317                                                         drs_cnt <= 0;
    1318                                                         channel_cnt <= 1;
    1319                                                         data_cnt <= 0;
     1352                                                       
     1353                                                        drs_cnt <= 0;           -- counts the chis form 0..3
     1354                                                        data_cnt <= 0;          -- counts the words in the ADC data channel group
     1355                                                        channel_cnt <= 1;       -- counts the number of channels which fit into W5300 FIFO at once.
     1356                                                       
    13201357                                                        roi_max <= (others => '0');
    13211358                                                        data_end <= POSITION_OF_ROI_IN_CHANNEL_HEADER;
    13221359                                                        state_write <= WR_ADC1;
    13231360
    1324                                                         ---- Write Channel
     1361                                                ---- Write Channel
    13251362                                                when WR_ADC1 =>
    13261363                                                        state_sig <= X"4D";
    13271364                                                        -- read ROI and set end of Channel-Data
     1365                                                       
     1366                                                        -- when this line is executed for the first time it points to
     1367                                                        -- the beginning of a channel header, as well.
     1368                                                        ram_addr <= adc_data_addr + drs_cnt + (data_cnt * 4);
    13281369                                                        if (data_cnt = POSITION_OF_ROI_IN_CHANNEL_HEADER) then
    13291370                                                                data_end <= conv_integer (ram_data) + CHANNEL_HEADER_SIZE;
     
    13321373                                                                end if;
    13331374                                                        end if;
    1334                                                         ram_addr <= adc_data_addr + drs_cnt + (data_cnt * 4);
    13351375                                                        state_write <= WR_ADC2;
     1376                                                       
    13361377                                                when WR_ADC2 =>
    13371378                                                        if (data_cnt < data_end) then
    1338                                                                 par_addr <= W5300_S0_TX_FIFOR + local_socket_nr * W5300_S_INC;
    1339                                                                 ram_access <= '1';
    1340                                                                 state_init <= WRITE_REG;
    1341                                                                 number_of_words_written_to_fifo <= number_of_words_written_to_fifo + 1;
    1342                                                                 next_state <= WRITE_DATA;
    1343                                                                 data_cnt <= data_cnt + 1;
    1344                                                                 state_write <= WR_ADC1;
     1379                                                                if (ready_wi = '1') then
     1380                                                                        wiz_addr <= W5300_S0_TX_FIFOR + local_socket_nr * W5300_S_INC;
     1381                                                                        wiz_data <= ram_data;
     1382                                                                        write_wi = '1';
     1383                                                                        number_of_words_written_to_fifo <= number_of_words_written_to_fifo + 1;
     1384                                                                        data_cnt <= data_cnt + 1;
     1385                                                                        state_write <= WR_ADC1;
     1386                                                                end if;
    13451387                                                        else
    13461388                                                                -- Next DRS
     
    13631405                                                                                -- Ready
    13641406                                                                                if (local_write_end_flag = '1') then
    1365                                                                                         state_write <= WR_ENDFLAG;
     1407                                                                                        ram_addr <= adc_data_addr + ((conv_integer(roi_max) + CHANNEL_HEADER_SIZE) * 4);
     1408                                                                                        state_write <= WR_ENDFLAG_WAIT;
    13661409                                                                                else
    1367                                                                                         state_write <= WR_05a;
     1410                                                                                        state_write <= WR_STRANGE_WAIT;
    13681411                                                                                end if;
    13691412                                                                        end if;
     
    13721415                                                        -- End Write ADC-Data
    13731416
    1374               -- Write End Package Flag
    1375               when WR_ENDFLAG =>
    1376                 state_sig <= X"4F";
    1377                 ram_addr <= adc_data_addr + ((conv_integer(roi_max) + CHANNEL_HEADER_SIZE) * 4);
    1378                 state_write <= WR_ENDFLAG1;
    1379               when WR_ENDFLAG1 =>
    1380                 par_addr <= W5300_S0_TX_FIFOR + local_socket_nr * W5300_S_INC;
    1381                 ram_access <= '1';
    1382                 state_init <= WRITE_REG;
    1383                                 number_of_words_written_to_fifo <= number_of_words_written_to_fifo + 1;
    1384                 next_state <= WRITE_DATA;
    1385                 state_write <= WR_ENDFLAG2;
    1386               when WR_ENDFLAG2 =>
    1387                 ram_addr <= adc_data_addr + ((conv_integer(roi_max) + CHANNEL_HEADER_SIZE) * 4) + 1;
    1388                 state_write <= WR_ENDFLAG3;
    1389               when WR_ENDFLAG3 =>
    1390                 state_init <= WRITE_REG;
    1391                 next_state <= WRITE_DATA;
    1392                                 number_of_words_written_to_fifo <= number_of_words_written_to_fifo + 1;
    1393                 state_write <= WR_05a;
     1417                                                -- Write End Package Flag
     1418                                                when WR_ENDFLAG_WAIT =>
     1419                                                        state_write <= WR_ENDFLAG;
     1420                                                when WR_ENDFLAG =>                             
     1421                                                        if (ready_wi = '1') then
     1422                                                                wiz_addr <= W5300_S0_TX_FIFOR + local_socket_nr * W5300_S_INC;
     1423                                                                wiz_data <= ram_data;
     1424                                                                write_wi = '1';
     1425                                                                number_of_words_written_to_fifo <= number_of_words_written_to_fifo + 1;                                 
     1426                                                                ram_addr <= adc_data_addr + ((conv_integer(roi_max) + CHANNEL_HEADER_SIZE) * 4) + 1;
     1427                                                                state_write <= WR_ENDFLAG2_WAIT;
     1428                                                        end if;
     1429                                                when WR_ENDFLAG2_WAIT =>
     1430                                                        state_write <= WR_ENDFLAG2;
     1431                               
     1432                                                when WR_ENDFLAG2 =>
     1433                                                        if (ready_wi = '1') then
     1434                                                                wiz_addr <= W5300_S0_TX_FIFOR + local_socket_nr * W5300_S_INC;
     1435                                                                wiz_data <= ram_data;
     1436                                                                write_wi = '1';
     1437                                                                number_of_words_written_to_fifo <= number_of_words_written_to_fifo + 1;
     1438                                                                state_write <= WR_STRANGE_WAIT;
     1439                                                        end if;
    13941440             
    1395               -- End Write End Package Flag
    1396              
    1397               -- Wait????
    1398               when WR_05a =>
    1399                                 state_sig <= X"4E";
    1400                 if (wait_cntr < 10) then -- 3000 works???
    1401                   wait_cntr <= wait_cntr + 1;
    1402                 else
    1403                   wait_cntr <= 0;
    1404                   state_write <= WR_05b;
    1405                 end if;
    1406               when WR_05b =>
    1407                 state_write <= WR_05_PREPARE_LENGTH_INFO;
    1408 
    1409               --Send FIFO       
    1410                                                         when WR_05_PREPARE_LENGTH_INFO =>
    1411                                                                 --number_of_words_written_to_fifo <= number_of_words_written_to_fifo - 1;
    1412                                                                 state_init <= WRITE_DATA;
    1413                                                                 state_write <= WR_05_POSTPREPARE_LENGTH_INFO;
     1441                                                when WR_STRANGE_WAIT =>
     1442                                                        if (wait_cntr < 10) then -- 3000 works???
     1443                                                                wait_cntr <= wait_cntr + 1;
     1444                                                        else
     1445                                                                wait_cntr <= 0;
     1446                                                                state_write <= WR_05_PREPARE_LENGTH_INFO;
     1447                                                        end if;
     1448                                                --Send FIFO     
     1449                                                when WR_05_PREPARE_LENGTH_INFO =>
     1450                                                        --number_of_words_written_to_fifo <= number_of_words_written_to_fifo - 1;
     1451                                                        state_write <= WR_05_POSTPREPARE_LENGTH_INFO;
     1452                                                when WR_05_POSTPREPARE_LENGTH_INFO =>
     1453                                                        number_of_bytes_written_to_fifo <= number_of_words_written_to_fifo(15 downto 0) & '0';   
     1454                                                        state_write <= WR_MESSAGE_LEN_HIGH_WORD;
     1455                                                       
     1456                                                when WR_MESSAGE_LEN_HIGH_WORD =>
     1457                                                        if (ready_i = '1') then
     1458                                                                wiz_addr <= W5300_S0_TX_WRSR + local_socket_nr * W5300_S_INC;
     1459                                                                wiz_data <= (0 => write_length_bytes (16), others => '0');
     1460                                                                --wiz_data <= (0 => number_of_bytes_written_to_fifo(16), others => '0');
     1461                                                                state_write <= WR_MESSAGE_LEN_LOW_WORD;
     1462                                                        end if;
    14141463                                                               
    1415                                                        
    1416                                                         when WR_05_POSTPREPARE_LENGTH_INFO =>
    1417                                                                 number_of_bytes_written_to_fifo <= number_of_words_written_to_fifo(15 downto 0) & '0';   
    1418                                                                 state_init <= WRITE_DATA;
    1419                                                                 state_write <= WR_05;
    1420                                                        
    1421                                                        
    1422                                                         when WR_05 =>
    1423                                                           ram_access <= '0';
    1424                                                                 state_sig <= X"50";
    1425                                                                 par_addr <= W5300_S0_TX_WRSR + local_socket_nr * W5300_S_INC;
    1426                                                                 par_data <= (0 => write_length_bytes (16), others => '0');
    1427                                                                 --par_data <= (0 => number_of_bytes_written_to_fifo(16), others => '0');
    1428                                                                 state_init <= WRITE_REG;
    1429                                                                 state_write <= WR_06;
    1430                                                         when WR_06 =>
    1431                                                                 par_addr <= W5300_S0_TX_WRSR + (local_socket_nr * W5300_S_INC) + X"2";
    1432                                                                 par_data <= write_length_bytes (15 downto 0);
    1433                                                                 --par_data <= number_of_bytes_written_to_fifo(15 downto 0);
     1464                                                when WR_MESSAGE_LEN_LOW_WORD =>
     1465                                                        if (ready_wi= '1') then
     1466                                                                wiz_addr <= W5300_S0_TX_WRSR + (local_socket_nr * W5300_S_INC) + X"2";
     1467                                                                wiz_data <= write_length_bytes (15 downto 0);
     1468                                                                --wiz_data <= number_of_bytes_written_to_fifo(15 downto 0);
     1469                                                                state_write <= WR_SEND_COMMAND;
     1470                                                        end if;
     1471
     1472                                                when WR_SEND_COMMAND =>
     1473                                                        number_of_words_written_to_fifo <= (others => '0');
     1474                                                        if (ready_wi <= '1') then
     1475                                                                wiz_addr <= W5300_S0_CR + local_socket_nr * W5300_S_INC;
     1476                                                                wiz_data <= X"0020"; -- Send
     1477                                                                write_wi <= '1';
     1478                                                        end if
     1479                                                        state_write <= WR_ACK;
     1480                                               
     1481                                                when WR_ACK =>
     1482                                                        data_valid_ack <= '1';
     1483                                                        state_write <= WR_WAIT_FOR_ACK;
     1484                                               
     1485                                                when WR_WAIT_FOR_ACK =>
     1486                                                        state_write <= WR_WAIT_FOR_ACK;
     1487                                                        if (data_valid_sr(1) = '0') then
     1488                                                                data_valid_ack <= '0';
    14341489                                                               
    1435                                                                 state_init <= WRITE_REG;
    1436                                                                 state_write <= WR_07;
    1437                                                         when WR_07 =>
    1438                                                                 number_of_words_written_to_fifo <= (others => '0');
    1439                                                                 state_sig <= X"51";
    1440                                                                 par_addr <= W5300_S0_CR + local_socket_nr * W5300_S_INC;
    1441                                                                 par_data <= X"0020"; -- Send
    1442                                                                 state_init <= WRITE_REG;
    1443                                                                 state_write <= WR_ACK;
    1444                                                         when WR_ACK =>
    1445                                                                 data_valid_ack <= '1';
    1446                                                                 state_write <= WR_WAIT_FOR_ACK;
    1447                                                         when WR_WAIT_FOR_ACK =>
    1448                                                                 state_write <= WR_WAIT_FOR_ACK;
    1449                                                                 if (data_valid_sr(1) = '0') then
    1450                                                                         data_valid_ack <= '0';
    1451                                                                         state_init <= next_state_tmp;
    1452                                                                         state_write <= WR_START;
    1453                                                                 end if;
    1454                                                                
    1455                                                        
    1456                                                         when others =>
    1457                                                                 state_sig <= X"4F";
     1490                                                                state_write <= WR_START;
     1491                                                                state_init <= MAIN;
     1492                                                                -- maybe MAIN1 is better ?!
     1493                                                        end if;
     1494                                                       
     1495                                               
     1496                                                when others =>
     1497                                                        null;
    14581498                                                end case;
    14591499                                                -- End WRITE_DATA
     
    14611501                               
    14621502                                        when others =>
    1463                                           state_sig <= X"F0";
    14641503                                                null;
    14651504                                end case;
Note: See TracChangeset for help on using the changeset viewer.