35use ieee.std_logic_1164.
all;
36use ieee.numeric_std.
all;
70 sdata : inout std_logic
99 signal wr_dout : std_logic_vector(15 downto 0);
116 signal rd_din : std_logic_vector(15 downto 0) := (others => '0');
124 ST_START_0, ST_START_1, ST_START_2, ST_START_3,
126 ST_TX_0, ST_TX_1, ST_TX_2, ST_TX_3,
127 ST_RACK_0, ST_RACK_1, ST_RACK_2, ST_RACK_3,
129 ST_RX_0, ST_RX_1, ST_RX_2, ST_RX_3,
130 ST_MACK_0, ST_MACK_1, ST_MACK_2, ST_MACK_3,
132 ST_DECIDE_AFTER_ADDR_WR,
133 ST_DECIDE_AFTER_REG_ADDR,
135 ST_DECIDE_AFTER_DATA_H,
136 ST_DECIDE_AFTER_DATA_L,
139 ST_DECIDE_AFTER_ADDR_RD,
140 ST_DECIDE_AFTER_RX_H,
141 ST_DECIDE_AFTER_RX_L,
143 ST_STOP_0, ST_STOP_1, ST_STOP_2, ST_STOP_3,
155 signal r_rw : std_logic := '0';
156 signal r_addr_dev : std_logic_vector(6 downto 0) := (others => '0');
157 signal r_addr_reg : std_logic_vector(7 downto 0) := (others => '0');
165 signal tx_byte : std_logic_vector(7 downto 0) := (others => '0');
166 signal rx_byte : std_logic_vector(7 downto 0) := (others => '0');
172 signal wr_word : std_logic_vector(15 downto 0) := (others => '0');
175 signal rx_high : std_logic_vector(7 downto 0) := (others => '0');
215 variable do_push : boolean;
216 variable do_pop : boolean;
218 if rising_edge(clk) then
236 end process p_wr_fifo;
248 variable do_push : boolean;
249 variable do_pop : boolean;
251 if rising_edge(clk) then
269 end process p_rd_fifo;
276 if rising_edge(clk) then
295 if rising_edge(clk) then
307 rd_din <= (others => '0');
376 seq_next <= ST_DECIDE_AFTER_ADDR_WR;
379 seq_next <= ST_DECIDE_AFTER_ADDR_RD;
434 state <= ST_ERROR_STOP;
448 when ST_DECIDE_AFTER_ADDR_WR =>
451 seq_next <= ST_DECIDE_AFTER_REG_ADDR;
459 when ST_DECIDE_AFTER_REG_ADDR =>
464 state <= ST_LOAD_DATA_H;
475 when ST_LOAD_DATA_H =>
484 when ST_DECIDE_AFTER_DATA_H =>
493 when ST_DECIDE_AFTER_DATA_L =>
502 state <= ST_LOAD_NEXT_DATA_H;
511 when ST_LOAD_NEXT_DATA_H =>
520 when ST_DECIDE_AFTER_ADDR_RD =>
530 when ST_DECIDE_AFTER_RX_H =>
544 when ST_DECIDE_AFTER_RX_L =>
558 state <= ST_ERROR_STOP;
649 when ST_ERROR_STOP =>
std_logic_vector( 7 downto 0) :=( others => '0') rx_high
std_logic := '0' phase_tick
std_logic rd_full_i
Indicador de RD FIFO llena (combinacional)
std_logic_vector( 6 downto 0) :=( others => '0') r_addr_dev
integer range 0 to FIFO_DEPTH- 1:= 0 rd_rd_ptr
Puntero de lectura de la RD FIFO.
std_logic_vector( 7 downto 0) :=( others => '0') tx_byte
integer range 0 to 7:= 7 bit_cnt
integer := CLK_FREQ_HZ/( I2C_FREQ_HZ* 4) CLKS_PER_PHASE
( 0 to FIFO_DEPTH- 1) std_logic_vector( 15 downto 0) fifo_mem_t
std_logic_vector( 7 downto 0) :=( others => '0') rx_byte
std_logic_vector( 15 downto 0) :=( others => '0') wr_word
integer range 0 to FIFO_DEPTH- 1:= 0 rd_wr_ptr
Puntero de escritura de la RD FIFO.
state_t := ST_IDLE seq_next
(ST_IDLE,ST_START_0,ST_START_1,ST_START_2,ST_START_3,ST_TX_0,ST_TX_1,ST_TX_2,ST_TX_3,ST_RACK_0,ST_RACK_1,ST_RACK_2,ST_RACK_3,ST_RX_0,ST_RX_1,ST_RX_2,ST_RX_3,ST_MACK_0,ST_MACK_1,ST_MACK_2,ST_MACK_3,ST_DECIDE_AFTER_ADDR_WR,ST_DECIDE_AFTER_REG_ADDR,ST_LOAD_DATA_H,ST_DECIDE_AFTER_DATA_H,ST_DECIDE_AFTER_DATA_L,ST_LOAD_NEXT_DATA_H,ST_DECIDE_AFTER_ADDR_RD,ST_DECIDE_AFTER_RX_H,ST_DECIDE_AFTER_RX_L,ST_STOP_0,ST_STOP_1,ST_STOP_2,ST_STOP_3,ST_DONE,ST_ERROR_STOP,ST_ERROR) state_t
integer range 0 to FIFO_DEPTH- 1:= 0 wr_rd_ptr
Puntero de lectura de la WR FIFO.
fifo_mem_t :=( others =>( others => '0')) wr_mem
Memoria de la FIFO de escritura (FIFO_DEPTH entradas de 16 bits)
std_logic := '1' sda_out_r
std_logic wr_full_i
Indicador de WR FIFO llena (combinacional)
std_logic := '0' start_rd_mode
std_logic := '0' send_nack
std_logic := '0' wr_pop
Pulso de pop interno de la WR FIFO (generado por la FSM)
integer range 0 to FIFO_DEPTH:= 0 rd_count
Número de entradas ocupadas en la RD FIFO.
std_logic wr_empty_i
Indicador de WR FIFO vacía (combinacional)
std_logic rd_empty_i
Indicador de RD FIFO vacía (combinacional)
integer range 1 to FIFO_DEPTH:= 1 r_num_regs
integer range 0 to FIFO_DEPTH- 1:= 0 wr_wr_ptr
Puntero de escritura de la WR FIFO.
fifo_mem_t :=( others =>( others => '0')) rd_mem
Memoria de la FIFO de lectura (FIFO_DEPTH entradas de 16 bits)
integer range 0 to CLKS_PER_PHASE- 1:= 0 phase_cnt
integer range 0 to FIFO_DEPTH:= 0 reg_cnt
std_logic_vector( 15 downto 0) wr_dout
Dato en la cabeza de la WR FIFO (combinacional sobre wr_rd_ptr)
integer range 0 to FIFO_DEPTH:= 0 wr_count
Número de entradas ocupadas en la WR FIFO.
std_logic_vector( 7 downto 0) :=( others => '0') r_addr_reg
std_logic_vector( 15 downto 0) :=( others => '0') rd_din
Dato a escribir en la RD FIFO (rx_high & rx_byte)
std_logic := '0' rd_push
Pulso de push interno de la RD FIFO (generado por la FSM tras recibir un registro)
out rd_fifo_empty std_logic
in addr_reg std_logic_vector( 7 downto 0)
CLK_FREQ_HZ integer := 50_000_000
I2C_FREQ_HZ integer := 400_000
out wr_fifo_empty std_logic
in wr_fifo_data std_logic_vector( 15 downto 0)
in addr_dev std_logic_vector( 6 downto 0)
in wr_fifo_push std_logic
out rd_fifo_full std_logic
out wr_fifo_full std_logic
out rd_fifo_data std_logic_vector( 15 downto 0)
in num_regs integer range 1 to FIFO_DEPTH