Commit 722c523e authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

I2C bridge started working, the top two bytes of sending are masked.

parent 8c7ba3fa
captures/ captures/
*.bak
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -20,7 +20,7 @@ package image1_top_tb_pkg is ...@@ -20,7 +20,7 @@ package image1_top_tb_pkg is
:= work.image1_pkg.c_NUMBER_OF_CHANNELS; := work.image1_pkg.c_NUMBER_OF_CHANNELS;
component image1_top component image1_top
generic(g_NUMBER_OF_CHANNELS : NATURAL := 6); -- generic(g_NUMBER_OF_CHANNELS : NATURAL := 6);
port (RST_N : in STD_LOGIC; port (RST_N : in STD_LOGIC;
CLK20_VCXO : in STD_LOGIC; CLK20_VCXO : in STD_LOGIC;
FPGA_CLK_P : in STD_LOGIC; --Using the 125MHz clock FPGA_CLK_P : in STD_LOGIC; --Using the 125MHz clock
...@@ -37,12 +37,12 @@ package image1_top_tb_pkg is ...@@ -37,12 +37,12 @@ package image1_top_tb_pkg is
LED_WR_OK_SYSPW : out STD_LOGIC; LED_WR_OK_SYSPW : out STD_LOGIC;
LED_WR_OWNADDR_I2C : out STD_LOGIC; LED_WR_OWNADDR_I2C : out STD_LOGIC;
--! I/Os for pulses --! I/Os for pulses
PULSE_FRONT_LED_N : out STD_LOGIC_VECTOR(g_NUMBER_OF_CHANNELS downto 1); PULSE_FRONT_LED_N : out STD_LOGIC_VECTOR(6 downto 1);
PULSE_REAR_LED_N : out STD_LOGIC_VECTOR(g_NUMBER_OF_CHANNELS downto 1); PULSE_REAR_LED_N : out STD_LOGIC_VECTOR(6 downto 1);
FPGA_INPUT_TTL_N : in STD_LOGIC_VECTOR(g_NUMBER_OF_CHANNELS downto 1); FPGA_INPUT_TTL_N : in STD_LOGIC_VECTOR(6 downto 1);
FPGA_OUT_TTL : out STD_LOGIC_VECTOR(g_NUMBER_OF_CHANNELS downto 1); FPGA_OUT_TTL : out STD_LOGIC_VECTOR(6 downto 1);
FPGA_BLO_IN : in STD_LOGIC_VECTOR(g_NUMBER_OF_CHANNELS downto 1); FPGA_BLO_IN : in STD_LOGIC_VECTOR(6 downto 1);
FPGA_TRIG_BLO : out STD_LOGIC_VECTOR(g_NUMBER_OF_CHANNELS downto 1); FPGA_TRIG_BLO : out STD_LOGIC_VECTOR(6 downto 1);
INV_IN_N : in STD_LOGIC_VECTOR(4 downto 1); INV_IN_N : in STD_LOGIC_VECTOR(4 downto 1);
INV_OUT : out STD_LOGIC_VECTOR(4 downto 1); INV_OUT : out STD_LOGIC_VECTOR(4 downto 1);
--! Lines for the i2c_slave --! Lines for the i2c_slave
......
...@@ -2,7 +2,14 @@ ...@@ -2,7 +2,14 @@
1 OK READ WISHBONE HIGH 1 OK READ WISHBONE HIGH
1 OK READ WISHBONE LOW 1 OK READ WISHBONE LOW
1 OK READ [ADDRESS|0] 1 OK READ [ADDRESS|0]
2 OK READ [ADDRESS|0] 2 OK WRITE [ADDRESS|0]
2 OK READ WISHBONE HIGH 2 OK WRITE WISHBONE HIGH
2 OK READ WISHBONE LOW 2 OK WRITE WISHBONE LOW
2 OK READ [ADDRESS|0] 2 OK WRITE READ DATA 0
2 OK WRITE READ DATA 1
2 OK WRITE READ DATA 2
2 OK WRITE READ DATA 3
3 OK READ [ADDRESS|0]
3 OK READ WISHBONE HIGH
3 OK READ WISHBONE LOW
3 OK READ [ADDRESS|0]
...@@ -99,15 +99,19 @@ signal s_wb_master_we_o : STD_LOGIC; ...@@ -99,15 +99,19 @@ signal s_wb_master_we_o : STD_LOGIC;
signal s_wb_master_ack_retries : STD_LOGIC_VECTOR(c_RETRY_LENGTH - 1 downto 0) signal s_wb_master_ack_retries : STD_LOGIC_VECTOR(c_RETRY_LENGTH - 1 downto 0)
:= (others => '0'); := (others => '0');
signal s_wb_addr_rd : STD_LOGIC_VECTOR(15 downto 0) := (others => '0');
signal s_wb_addr_rd : STD_LOGIC_VECTOR(15 downto 0) := (others => '0'); attribute keep : string;
signal wbm_dat_out : std_logic_vector(31 downto 0);
attribute keep of wbm_dat_out : signal is "true";
begin begin
wb_master_we_o <= s_wb_master_we_o; wb_master_we_o <= s_wb_master_we_o;
s_wb_slave_addr <= UNSIGNED(wb_slave_addr_i); s_wb_slave_addr <= UNSIGNED(wb_slave_addr_i);
s_CTR0_slv <= f_STD_LOGIC_VECTOR(s_CTR0); s_CTR0_slv <= f_STD_LOGIC_VECTOR(s_CTR0);
s_LT <= f_LT(LT_i); s_LT <= f_LT(LT_i);
wb_master_data_o <= wbm_dat_out;
wb_slave_ack_o <= s_wb_slave_ack; wb_slave_ack_o <= s_wb_slave_ack;
wb_slave_rty_o <= s_wb_slave_rty; wb_slave_rty_o <= s_wb_slave_rty;
...@@ -161,7 +165,7 @@ begin ...@@ -161,7 +165,7 @@ begin
wb_master_stb_o <= '0'; wb_master_stb_o <= '0';
wb_master_cyc_o <= '0'; wb_master_cyc_o <= '0';
wb_master_sel_o <= (others => '0'); wb_master_sel_o <= (others => '0');
wb_master_data_o <= (others => '0'); wbm_dat_out <= (others => '0');
wb_master_addr_o <= (others => '0'); wb_master_addr_o <= (others => '0');
s_dtx <= (others => '0'); s_dtx <= (others => '0');
else else
...@@ -191,14 +195,14 @@ begin ...@@ -191,14 +195,14 @@ begin
wb_master_stb_o <= '1'; wb_master_stb_o <= '1';
s_wb_master_we_o <= '1'; s_wb_master_we_o <= '1';
wb_master_sel_o <= X"F"; wb_master_sel_o <= X"F";
wb_master_data_o <= f_ch_endian(DRXA_i); wbm_dat_out <= f_ch_endian(DRXA_i);
wb_master_addr_o <= DRXB_i(15 downto 0); wb_master_addr_o <= DRXB_i(15 downto 0);
when S2N_WB_NOOP => when S2N_WB_NOOP =>
wb_master_cyc_o <= '1'; wb_master_cyc_o <= '1';
wb_master_stb_o <= '1'; wb_master_stb_o <= '1';
s_wb_master_we_o <= '1'; s_wb_master_we_o <= '1';
wb_master_sel_o <= X"F"; wb_master_sel_o <= X"F";
wb_master_data_o <= f_ch_endian(DRXA_i); wbm_dat_out <= f_ch_endian(DRXA_i);
wb_master_addr_o <= DRXB_i(15 downto 0); wb_master_addr_o <= DRXB_i(15 downto 0);
when S3_WB_ACK => when S3_WB_ACK =>
-- null; -- null;
......
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
-- Company: CERN, BE-CO-HT -- Company: CERN, BE-CO-HT
-- Engineer: Carlos Gil Soriano -- Engineers: Carlos Gil Soriano
-- Theodor-Adrian Stana
-- --
-- Create Date: 11:29:56 10/25/2011 -- Create Date: 11:29:56 10/25/2011
-- Design Name: I2C Slave to Wishbone bridge -- Design Name: I2C Slave to Wishbone bridge
...@@ -170,15 +171,10 @@ signal s_watchdog_cnt_rst : STD_LOGIC; ...@@ -170,15 +171,10 @@ signal s_watchdog_cnt_rst : STD_LOGIC;
signal s_watchdog_cnt_slv : STD_LOGIC_VECTOR(c_WATCHDOG_WIDTH - 1 downto 0); signal s_watchdog_cnt_slv : STD_LOGIC_VECTOR(c_WATCHDOG_WIDTH - 1 downto 0);
signal s_watchdog_cnt : NATURAL; signal s_watchdog_cnt : NATURAL;
attribute keep : string; signal txsr : std_logic_vector(31 downto 0);
signal s_dummy : std_logic_vector(0 to 31);
attribute keep of s_dummy : signal is "true";
begin begin
s_dummy(0 to 31) <= f_ch_endian(s_pf_wb_data(31 downto 0));
s_CTR0 <= f_CTR0(CTR0_i); s_CTR0 <= f_CTR0(CTR0_i);
LT_o <= f_STD_LOGIC_VECTOR(s_LT); LT_o <= f_STD_LOGIC_VECTOR(s_LT);
s_pf_wb_data <= pf_wb_data_i; s_pf_wb_data <= pf_wb_data_i;
...@@ -228,8 +224,22 @@ begin ...@@ -228,8 +224,22 @@ begin
sda_o <= s_sda_o; sda_o <= s_sda_o;
p_sda_o: process(i2c_SLA_fsm, -- Process to control the TX shift register
s_bit_cnt_slv(0)) -- p_txsr: process (clk_i)
-- begin
-- if rising_edge(clk_i) then
-- if (rst_i = '1') then
-- txsr <= (others => '0');
-- elsif (i2c_sla_fsm = S5W1A_I2C_ADDR_ACK) then
-- txsr <= f_ch_endian(pf_wb_data_i);
-- elsif (i2c_sla_fsm = S5W2_WRITE_SDA) then
-- txsr <= txsr(30 downto 0) & '0';
-- end if;
-- end if;
-- end process p_txsr;
p_sda_o: process(i2c_SLA_fsm, txsr)
-- variable v_bit_inv : UNSIGNED(2 downto 0); -- variable v_bit_inv : UNSIGNED(2 downto 0);
-- variable v_bit_order : NATURAL; -- variable v_bit_order : NATURAL;
variable v_bit_un : UNSIGNED(2 downto 0); variable v_bit_un : UNSIGNED(2 downto 0);
...@@ -253,9 +263,11 @@ begin ...@@ -253,9 +263,11 @@ begin
v_pf_wb_data(0 to 31) := s_pf_wb_data(31 downto 0); -- f_ch_endian(s_pf_wb_data(31 downto 0)); -- v_pf_wb_data(0 to 31) := f_ch_endian(s_pf_wb_data(31 downto 0));
-- v_pf_wb_data := s_pf_wb_data; -- f_ch_endian(s_pf_wb_data); -- -- v_pf_wb_data := s_pf_wb_data; -- f_ch_endian(s_pf_wb_data);
s_sda_o <= v_pf_wb_data(s_byte_cnt*8 + (s_bit_cnt mod 8)); -- s_sda_o <= v_pf_wb_data(s_byte_cnt*8 + (s_bit_cnt mod 8));
s_sda_o <= txsr(31);
when others => when others =>
s_sda_o <= '1'; s_sda_o <= '1';
end case; end case;
...@@ -553,6 +565,7 @@ begin ...@@ -553,6 +565,7 @@ begin
if rst_i = '1' if rst_i = '1'
or s_watchdog_cnt >= c_WATCHDOG_END_VALUE then or s_watchdog_cnt >= c_WATCHDOG_END_VALUE then
i2c_SLA_fsm <= R0_RESET; i2c_SLA_fsm <= R0_RESET;
txsr <= (others => '0');
else else
case i2c_SLA_fsm is case i2c_SLA_fsm is
when R0_RESET => when R0_RESET =>
...@@ -634,7 +647,7 @@ begin ...@@ -634,7 +647,7 @@ begin
when S5W1_I2C_ADDR => when S5W1_I2C_ADDR =>
if s_bit_done = '1' then if s_bit_done = '1' then
if s_bit_cnt = 7 then if s_bit_cnt = 7 then
if s_DRX_slv(6 downto 0) = "0000000" if s_DRX_slv(6 downto 0) = "0000000" -- ????????????????
or s_DRX_slv(6 downto 0) = or s_DRX_slv(6 downto 0) =
STD_LOGIC_VECTOR(s_CTR0.I2C_ADDR) then STD_LOGIC_VECTOR(s_CTR0.I2C_ADDR) then
i2c_SLA_fsm <= S5W1A_I2C_ADDR_ACK; i2c_SLA_fsm <= S5W1A_I2C_ADDR_ACK;
...@@ -645,6 +658,7 @@ begin ...@@ -645,6 +658,7 @@ begin
check_start_stop; check_start_stop;
end if; end if;
when S5W1A_I2C_ADDR_ACK => when S5W1A_I2C_ADDR_ACK =>
txsr <= f_ch_endian(pf_wb_data_i);
if s_bit_done = '1' then if s_bit_done = '1' then
i2c_SLA_fsm <= S5W2_WRITE_SDA; i2c_SLA_fsm <= S5W2_WRITE_SDA;
end if; end if;
...@@ -654,8 +668,9 @@ begin ...@@ -654,8 +668,9 @@ begin
end if; end if;
when S5W2_WRITE_SDA => when S5W2_WRITE_SDA =>
if s_bit_done = '1' then if s_bit_done = '1' then
txsr <= txsr(30 downto 0) & '0';
if s_bit_cnt = 8 then if s_bit_cnt = 8 then
i2c_SLA_fsm <= S5W2A_WRITE_SDA_ACK; i2c_SLA_fsm <= S5W2A_WRITE_SDA_ACK;
end if; end if;
--! It can be removed, never reached --! It can be removed, never reached
check_start_stop; check_start_stop;
......
...@@ -17,6 +17,7 @@ entity i2c_master_driver is ...@@ -17,6 +17,7 @@ entity i2c_master_driver is
g_SCL_PERIOD : TIME := 250 us; g_SCL_PERIOD : TIME := 250 us;
g_LOG_PATH : STRING := "../test/log/i2c_master_driver.txt"); g_LOG_PATH : STRING := "../test/log/i2c_master_driver.txt");
port(tb_clk : in STD_LOGIC; port(tb_clk : in STD_LOGIC;
rst_n : in std_logic;
sda_master_i : in STD_LOGIC; sda_master_i : in STD_LOGIC;
sda_master_o : out STD_LOGIC; sda_master_o : out STD_LOGIC;
...@@ -283,13 +284,23 @@ begin ...@@ -283,13 +284,23 @@ begin
s_sda_master_o <= '0'; s_sda_master_o <= '0';
end procedure; end procedure;
variable first : boolean := true;
begin begin
if (first = true) then
wait until rst_n = '1';
first := false;
end if;
if start_i = '1' then if start_i = '1' then
assert false report "mst start" severity note;
start_I2c; start_I2c;
elsif pause_i = '1' then elsif pause_i = '1' then
assert false report "mst pause" severity note;
pause_I2C; pause_I2C;
elsif write_i = '1' then elsif write_i = '1' then
assert false report "mst write" severity note;
s_test_id <= s_test_id + 1; s_test_id <= s_test_id + 1;
v_write_data := order_write_data(wr_data_i); v_write_data := order_write_data(wr_data_i);
--! 1.- Send [ADDRESS|0] --! 1.- Send [ADDRESS|0]
...@@ -320,6 +331,7 @@ begin ...@@ -320,6 +331,7 @@ begin
wait until rising_edge(tb_clk); wait until rising_edge(tb_clk);
s_write_done <= '0'; s_write_done <= '0';
elsif read_i = '1' then elsif read_i = '1' then
assert false report "mst read" severity note;
s_test_id <= s_test_id + 1; s_test_id <= s_test_id + 1;
v_write_data := order_write_data(wr_data_i); v_write_data := order_write_data(wr_data_i);
--! 1.- Send [ADDRESS|0] --! 1.- Send [ADDRESS|0]
...@@ -357,7 +369,9 @@ begin ...@@ -357,7 +369,9 @@ begin
wait until rising_edge(tb_clk); wait until rising_edge(tb_clk);
s_read_done <= '0'; s_read_done <= '0';
end if; end if;
wait until rising_edge(tb_clk); wait until rising_edge(tb_clk);
end process; end process;
end; end;
...@@ -66,6 +66,7 @@ package i2c_tb_pkg is ...@@ -66,6 +66,7 @@ package i2c_tb_pkg is
g_SCL_PERIOD : TIME := c_SCL_I_PERIOD; g_SCL_PERIOD : TIME := c_SCL_I_PERIOD;
g_LOG_PATH : STRING := "../test/log/i2c_master_driver.txt"); g_LOG_PATH : STRING := "../test/log/i2c_master_driver.txt");
port(tb_clk : in STD_LOGIC; port(tb_clk : in STD_LOGIC;
rst_n : in std_logic;
sda_master_i : in STD_LOGIC; sda_master_i : in STD_LOGIC;
sda_master_o : out STD_LOGIC; sda_master_o : out STD_LOGIC;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment