Mostly tested on MBSr2, SIMs not tested, not working: PSE I2C

This commit is contained in:
matt 2020-08-01 03:43:51 +07:00
parent aed7bf198a
commit 611076ca6d
1 changed files with 183 additions and 26 deletions

View File

@ -113,6 +113,10 @@ architecture rtl of sim_switcher_top is
constant SB_CONF_UPDATE_INTERVAL : natural := 25_000_000; -- 25_000_000 = 1sec
constant DEBOUNCING_WAIT_CYCLES : natural := 3; -- Number of debouncing wait cycles
constant REPI2C_DEBOUNCING_WAIT_CYCLES : natural := 3; -- Number of debouncing wait cycles
constant EXPIO_DEBOUNCING_WAIT_CYCLES : natural := 25; -- Number of debouncing wait cycles
constant I2C_CLK : natural := 400_000; -- speed the i2c bus (scl) will run at in Hz
constant I2C_MAX_WAIT : natural := 2_500_000; -- 25_000_000 = 1sec
@ -241,36 +245,189 @@ begin
fan_o <= reg_fan_ctl;
-- PSE init
pse_rst <= reg_pse_ctl(0);
pse_vpwr_enn <= reg_pse_ctl(1);
reg_pse_status <= pse_intn&pse_vpwr_pg;
pse_rst <= reg_pse_ctl(0);
pse_vpwr_enn <= reg_pse_ctl(1);
reg_pse_status(1) <= not pse_intn;
reg_pse_status(0) <= pse_vpwr_pg;
-- Connect PSE I2C bus to main I2C bus
pse_scl_rptr: odio_repeater
generic map (
WAIT_CYCLES => DEBOUNCING_WAIT_CYCLES
)
port map (
clk => clk25_i,
rstn => s_rstn_i,
signal_n1 => i2c_scl_io,
signal_n2 => pse_i2c_scl_io
);
-- inst_i2c_master: i2c_master
-- generic map (
-- input_clk => SYSFREQ,
-- bus_clk => I2C_CLK
-- )
-- port map (
-- clk => clk25_i,
-- reset_n => s_rstn_i,
-- ena => s_i2c_txn_start,
-- addr => x"20",
-- rw => s_i2c_rw_flag,
-- data_wr => s_i2c_data_wr,
-- busy => s_i2c_busy_flag,
-- data_rd => s_i2c_data_rd,
-- ack_error => open,
-- sda => pse_i2c_sda_io,
-- scl => pse_i2c_scl_io,
-- scl_invert => '0'
-- );
pse_sda_rptr: odio_repeater
generic map (
WAIT_CYCLES => DEBOUNCING_WAIT_CYCLES
)
port map (
clk => clk25_i,
rstn => s_rstn_i,
signal_n1 => i2c_sda_io,
signal_n2 => pse_i2c_sda_io
);
-- -- PSE I2C interaction process
-- pse_i2c_proc: process (clk_i, rstn_i)
-- variable data_wr_cnt : natural := 0;
-- variable data_rd_cnt : natural := 0;
-- begin
-- if (rstn_i = '0') then
-- i2c_state <= ready;
-- i2c_core_busy <= '0';
-- i2c_busy_prev <= (others => '0');
-- i2c_ram_we <= (others => '0');
-- i2c_wr_done <= '0';
-- elsif (rising_edge(clk_i)) then
-- case i2c_state is
-- when ready =>
-- if (i2c_core_start = '1') then
-- i2c_state <= i2c_trn_start;
-- i2c_core_busy <= '1';
-- data_wr_cnt := 0;
-- data_rd_cnt := 0;
-- spi_ram_raddr <= data_wr_cnt; -- Request data from RAM
-- i2c_busy_prev <= (i2c_busy_prev'range => '0');
-- end if;
-- when i2c_trn_start =>
-- i2c_txn_start_o <= reg_i2c_mask; -- Initiate the transaction
-- i2c_slv_addr_o <= (others => reg_i2c_addr); -- Set the address of the slave
-- i2c_rw_flag_o <= (others => '0'); -- First byte is always write
-- i2c_data_wr_o <= (others => spi_ram_data_o); -- Data to be written
-- i2c_state <= i2c_trn_main;
-- when i2c_trn_main =>
-- i2c_data_wr_o <= (others => spi_ram_data_o); -- Data to be written to the I2C buses
-- i2c_busy_prev <= i2c_busy_flag_i; -- Capture the value of the previous i2c busy signal
-- if (i2c_busy_prev = (i2c_busy_prev'range => '0') and i2c_busy_flag_i = reg_i2c_mask) then -- I2C busy just went high
-- case reg_i2c_trn_dir is -- Switches to the needed transaction direction
-- when '0' => -- When write - continue to write
-- data_wr_cnt := data_wr_cnt + 1;
-- if (data_wr_cnt > 0 and data_wr_cnt < spi_command_len) then -- Keep writing if there's still data in the RAM
-- spi_ram_raddr <= data_wr_cnt;
-- i2c_state <= wait_ram;
-- else -- Else - finish the transaction
-- i2c_state <= i2c_trn_final_word_wait;
-- i2c_txn_start_o <= (others => '0');
-- end if;
-- when '1' => -- When read
-- if (data_rd_cnt = 0 and i2c_wr_done = '0') then -- Change the transaction from Write to Read after writing the first byte
-- i2c_rw_flag_o <= (others => '1');
-- i2c_state <= i2c_wr_wait; -- Switch to read
-- else
-- i2c_state <= i2c_rd_wait;
-- i2c_wr_done <= '0';
-- end if;
-- i2c_ram_we <= (others => '0');
-- when others =>
-- i2c_state <= ready;
-- end case;
-- end if;
-- when wait_ram =>
-- i2c_state <= i2c_trn_main;
-- when i2c_trn_final_word_wait =>
-- if (i2c_busy_prev = reg_i2c_mask and i2c_busy_flag_i = (i2c_busy_prev'range => '0')) then -- I2C became free
-- i2c_state <= wait_ack;
-- end if;
-- when i2c_wr_wait =>
-- if (i2c_busy_flag_i = (i2c_busy_flag_i'range => '0')) then -- Indicates data read in last command is ready
-- i2c_state <= i2c_trn_main; -- Transaction complete, go to next state in design
-- i2c_wr_done <= '1';
-- end if;
-- when i2c_rd_wait =>
-- if (i2c_busy_flag_i = (i2c_busy_flag_i'range => '0')) then -- Indicates data read in last command is ready
-- data_rd_cnt := data_rd_cnt + 1;
-- i2c_ram_waddr <= (others => data_rd_cnt-1);
-- i2c_ram_we <= reg_i2c_mask;
-- for i in 0 to I2C_NUM-1 loop
-- if (reg_i2c_mask(i) = '1') then
-- i2c_ram_data_i(i) <= i2c_data_rd_i(i); -- Store received byte
-- end if;
-- end loop;
-- if (data_rd_cnt = reg_i2c_read_len) then
-- i2c_state <= wait_ack; -- Transaction complete, go to next state in design
-- else
-- i2c_state <= i2c_trn_main; -- Transaction complete, go to next state in design
-- end if;
-- end if;
-- if (data_rd_cnt+1 = reg_i2c_read_len) then
-- i2c_txn_start_o <= (others => '0');
-- end if;
-- when wait_ack =>
-- i2c_core_busy <= '0';
-- i2c_ram_we <= (others => '0');
-- i2c_busy_prev <= (others => '0');
-- if (i2c_core_start = '0') then
-- i2c_state <= ready;
-- end if;
-- when others =>
-- i2c_state <= ready;
-- end case;
-- end if;
-- end process pse_i2c_proc;
-- s_i2c_txn_start
-- s_i2c_rw_flag
-- s_i2c_data_wr
-- s_i2c_busy_flag
-- s_i2c_data_rd
-- pse_scl_rptr: odio_repeater
-- generic map (
-- WAIT_CYCLES => REPI2C_DEBOUNCING_WAIT_CYCLES
-- )
-- port map (
-- clk => clk25_i,
-- rstn => s_rstn_i,
-- signal_n1 => i2c_scl_io,
-- signal_n2 => pse_i2c_scl_io
-- );
-- pse_sda_rptr: odio_repeater
-- generic map (
-- WAIT_CYCLES => REPI2C_DEBOUNCING_WAIT_CYCLES
-- )
-- port map (
-- clk => clk25_i,
-- rstn => s_rstn_i,
-- signal_n1 => i2c_sda_io,
-- signal_n2 => pse_i2c_sda_io
-- );
-- pse_i2c_rptr: i2c_repeater
-- generic map (
-- WAIT_CYCLES => REPI2C_DEBOUNCING_WAIT_CYCLES
-- )
-- port map (
-- clk => clk25_i,
-- rstn => s_rstn_i,
-- pr_scl => i2c_scl_io,
-- pr_sda => i2c_sda_io,
-- sec_scl => pse_i2c_scl_io,
-- sec_sda => pse_i2c_sda_io
-- );
-- POE PD init
reg_poepd_status <= poe_in_vpres&poe_in_t2p;
poe_in_enn <= reg_poepd_ctl;
reg_poepd_status(2) <= poe_in_vpres;
reg_poepd_status(1 downto 0) <= poe_in_t2p(1 downto 0);
poe_in_enn <= reg_poepd_ctl;
-- Expansion card IO control
gen_expio_dbnc: for i in 0 to 5 generate
@ -283,7 +440,7 @@ begin
expio_debounce : debounce
generic map (
WAIT_CYCLES => DEBOUNCING_WAIT_CYCLES
WAIT_CYCLES => EXPIO_DEBOUNCING_WAIT_CYCLES
)
port map (
clk => clk25_i,