DHBKM1024I-8 Improved power_control.vhd, holdoff in i2c_master. Test improvements
This commit is contained in:
parent
a81cd9f1d5
commit
5deea65fd2
6 changed files with 63 additions and 44 deletions
|
|
@ -35,9 +35,9 @@ port (
|
|||
|
||||
power_on : in std_logic;
|
||||
power_hold : in std_logic;
|
||||
busy : out std_logic;
|
||||
configured : out std_logic;
|
||||
temperature : out std_logic_vector(11 downto 0);
|
||||
busy : out std_logic := '0';
|
||||
configured : out std_logic := '0';
|
||||
temperature : out std_logic_vector(11 downto 0) := (others => '0');
|
||||
|
||||
scl_in : in std_logic;
|
||||
scl_out : out std_logic;
|
||||
|
|
@ -108,6 +108,8 @@ architecture struct of power_control is
|
|||
signal sl_done : std_logic := '0';
|
||||
|
||||
signal adc_val : std_logic_vector(11 downto 0) := X"000";
|
||||
|
||||
signal access_2ndDAC : std_logic := '0';
|
||||
|
||||
type ms_time_t is array (boolean) of integer;
|
||||
constant ms_time_lim : ms_time_t := (true => 200, false => 100000);
|
||||
|
|
@ -117,8 +119,16 @@ architecture struct of power_control is
|
|||
|
||||
constant active_ch : std_logic_vector(21 downto 0) := "0111001111011100000100";
|
||||
|
||||
constant STM8_ADDR : std_logic_vector(7 downto 0) := X"20";
|
||||
constant DACA_ADDR : std_logic_vector(7 downto 0) := X"92";
|
||||
constant DACB_ADDR : std_logic_vector(7 downto 0) := X"94";
|
||||
|
||||
begin
|
||||
|
||||
access_2ndDAC_gen : if no_ch > 8 generate
|
||||
access_2ndDAC <= '1';
|
||||
end generate;
|
||||
|
||||
---------------------------------------------------
|
||||
-- Master I2C
|
||||
---------------------------------------------------
|
||||
|
|
@ -214,12 +224,18 @@ begin
|
|||
when set_dac_en =>
|
||||
-- If just written enables for first DAC
|
||||
if ctrl_st_d = msg_dac_wait and ch_idx = 0 then
|
||||
-- Move to write enables for second DAC
|
||||
ch_idx <= 8;
|
||||
byte_idx <= 0;
|
||||
cmd_idx <= 1;
|
||||
rtrn_st <= set_dac_en;
|
||||
ctrl_st <= msg_dac;
|
||||
-- If any top channel used then write to second DAC
|
||||
if access_2ndDAC = '1' then
|
||||
-- Move to write enables for second DAC
|
||||
ch_idx <= 8;
|
||||
byte_idx <= 0;
|
||||
cmd_idx <= 1;
|
||||
rtrn_st <= set_dac_en;
|
||||
ctrl_st <= msg_dac;
|
||||
else
|
||||
-- Move on to set the STM8
|
||||
ctrl_st <= set_adc_idle;
|
||||
end if;
|
||||
-- If just written enables for second DAC
|
||||
elsif ctrl_st_d = msg_dac_wait and ch_idx = 8 then
|
||||
-- Move on to set the STM8
|
||||
|
|
@ -380,7 +396,7 @@ begin
|
|||
-- Check I2C master can accept new command
|
||||
if i2c_cmd_rdy = '1' then
|
||||
-- Send the STM8 address without the read bit set
|
||||
i2c_byte <= X"20";
|
||||
i2c_byte <= STM8_ADDR;
|
||||
if i2c_wr = '0' then
|
||||
i2c_wr_bytes <= X"02";
|
||||
i2c_wr <= '1';
|
||||
|
|
@ -418,7 +434,7 @@ begin
|
|||
-- Check I2C master can accept new command
|
||||
if i2c_cmd_rdy = '1' then
|
||||
-- Send the STM8 address with the read bit set
|
||||
i2c_byte <= X"21";
|
||||
i2c_byte <= STM8_ADDR or X"01";
|
||||
if i2c_wr = '0' then
|
||||
i2c_rd_bytes <= X"01";
|
||||
i2c_wr_bytes <= X"01";
|
||||
|
|
@ -435,7 +451,7 @@ begin
|
|||
-- Check I2C master can accept new command
|
||||
if i2c_cmd_rdy = '1' then
|
||||
-- Send the STM8 address without the read bit set
|
||||
i2c_byte <= X"20";
|
||||
i2c_byte <= STM8_ADDR;
|
||||
if i2c_wr = '0' then
|
||||
i2c_wr_bytes <= X"02";
|
||||
i2c_wr <= '1';
|
||||
|
|
@ -473,7 +489,7 @@ begin
|
|||
-- Check I2C master can accept new command
|
||||
if i2c_cmd_rdy = '1' then
|
||||
-- Send the STM8 address with the read bit set
|
||||
i2c_byte <= X"21";
|
||||
i2c_byte <= STM8_ADDR or X"01";
|
||||
if i2c_wr = '0' then
|
||||
i2c_rd_bytes <= X"01";
|
||||
i2c_wr_bytes <= X"01";
|
||||
|
|
@ -514,7 +530,7 @@ begin
|
|||
-- Check I2C master can accept new command
|
||||
if i2c_cmd_rdy = '1' then
|
||||
-- Send the STM8 address without the read bit set
|
||||
i2c_byte <= X"20"; -- STM8
|
||||
i2c_byte <= STM8_ADDR; -- STM8
|
||||
if i2c_wr = '0' then
|
||||
i2c_wr_bytes <= X"03";
|
||||
i2c_wr <= '1';
|
||||
|
|
@ -599,10 +615,10 @@ begin
|
|||
-- if Second DAC
|
||||
if ch_idx > 7 then
|
||||
-- Set second DAC address
|
||||
i2c_byte <= X"94"; -- DAC B
|
||||
i2c_byte <= DACB_ADDR; -- DAC B
|
||||
else
|
||||
-- Set first DAC address
|
||||
i2c_byte <= X"92"; -- DAC A
|
||||
i2c_byte <= DACA_ADDR; -- DAC A
|
||||
end if;
|
||||
if i2c_wr = '0' then
|
||||
i2c_wr_bytes <= X"04";
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ reg err = 1'b0;
|
|||
reg sda_pr = 1'b1;
|
||||
reg [3:0] sda_mon = 4'b1111;
|
||||
reg [3:0] scl_mon = 4'b1111;
|
||||
reg [9:0] holdoff = 10'd0;
|
||||
wire scl_stall;
|
||||
wire wr_byte_pending;
|
||||
wire rd_byte_pending;
|
||||
|
|
@ -185,8 +186,11 @@ begin
|
|||
case (state)
|
||||
IDLE : begin
|
||||
bit_cnt <= 3'd0;
|
||||
|
||||
if (wr_dv_in) // SCL and in_byte must be disabled on entry to IDLE state.
|
||||
|
||||
if (holdoff != 10'd0)
|
||||
holdoff <= holdoff - 10'd1;
|
||||
|
||||
if ((holdoff == 10'd0) & (wr_dv_in == 1'b1)) // SCL and in_byte must be disabled on entry to IDLE state.
|
||||
begin
|
||||
in_byte <= 1'b1;
|
||||
in_cmd <= 1'b1;
|
||||
|
|
@ -199,7 +203,7 @@ begin
|
|||
if (~in_cmd) rd_cnt <= wr_data_in[0] ? cmd_rd_cnt_in : 8'd0; // If new command, and write, set read count to zero.
|
||||
end
|
||||
|
||||
if (sda_rd & bus_idle) // When we have the next byte, wait until SDA_RD before jumping state to ensure START condition operates correctly.
|
||||
if ((holdoff == 10'd0) & (sda_rd & bus_idle)) // When we have the next byte, wait until SDA_RD before jumping state to ensure START condition operates correctly.
|
||||
begin // No need to gate against in_byte sda_rd cannot occur until in_byte is set.
|
||||
state <= next_state;
|
||||
scl_en <= next_scl_en;
|
||||
|
|
@ -224,6 +228,7 @@ begin
|
|||
if ((sda_pr == 1'b1) && (sda_pr != sda_in)) begin
|
||||
err <= 1'b1;
|
||||
state <= STOP;
|
||||
holdoff <= 10'd1023;
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ architecture logic of i2c_master is
|
|||
signal ena_last : std_logic;
|
||||
|
||||
signal sda_chk : std_logic;
|
||||
|
||||
signal holdoff_cnt : integer range 0 to 1023;
|
||||
|
||||
begin
|
||||
|
|
@ -126,6 +127,10 @@ begin
|
|||
|
||||
-- Data clock rising edge
|
||||
if data_clk = '1' and data_clk_last = '0' then
|
||||
if holdoff_cnt /= 0 then
|
||||
holdoff_cnt <= holdoff_cnt - 1;
|
||||
end if;
|
||||
|
||||
case state is
|
||||
-- Idle
|
||||
when idle =>
|
||||
|
|
@ -142,8 +147,6 @@ begin
|
|||
end if;
|
||||
byte_count <= 0;
|
||||
state <= start;
|
||||
elsif holdoff_cnt /= 0 then
|
||||
holdoff_cnt <= holdoff_cnt - 1;
|
||||
end if;
|
||||
|
||||
-- Start bit of transaction
|
||||
|
|
@ -176,7 +179,7 @@ begin
|
|||
-- Read command
|
||||
else
|
||||
sda_int <= '1';
|
||||
sda_chk <= '0';
|
||||
--sda_chk <= '0';
|
||||
state <= rd_byte;
|
||||
end if;
|
||||
|
||||
|
|
@ -246,6 +249,7 @@ begin
|
|||
if byte_count /= 2 then
|
||||
byte_count <= byte_count + 1;
|
||||
sda_int <= data_wr_held(8*(byte_count+1)+bit_count);
|
||||
sda_chk <= '1';
|
||||
state <= wr_byte;
|
||||
end if;
|
||||
else
|
||||
|
|
@ -265,6 +269,13 @@ begin
|
|||
|
||||
-- Data clock falling edge
|
||||
elsif data_clk = '0' and data_clk_last = '1' then
|
||||
if sda_chk = '1' and sda_int = '1' and sda /= '1' and sda /= 'H' then
|
||||
aborted <= '1';
|
||||
holdoff_cnt <= 512;
|
||||
sda_chk <= '0';
|
||||
else
|
||||
sda_chk <= '0';
|
||||
end if;
|
||||
|
||||
case state is
|
||||
when start =>
|
||||
|
|
@ -293,16 +304,6 @@ begin
|
|||
null;
|
||||
end case;
|
||||
|
||||
if sda_chk = '1' and sda_int = '1' and sda /= '1' and sda /= 'H' then
|
||||
aborted <= '1';
|
||||
state <= stop;
|
||||
holdoff_cnt <= 512;
|
||||
sda_chk <= '0';
|
||||
sda_int <= '1';
|
||||
scl_ena <= '0';
|
||||
bit_count <= 7;
|
||||
end if;
|
||||
|
||||
end if;
|
||||
|
||||
end if;
|
||||
|
|
@ -310,9 +311,9 @@ begin
|
|||
|
||||
--set sda output
|
||||
with state select
|
||||
sda_ena_n <= data_clk_last when start, --generate start condition
|
||||
not data_clk_last when stop, --generate stop condition
|
||||
sda_int when others; --set to internal sda signal
|
||||
sda_ena_n <= data_clk_last when start, --generate start condition
|
||||
not data_clk_last when stop, --generate stop condition
|
||||
sda_int or aborted when others; --set to internal sda signal
|
||||
|
||||
--set scl and sda outputs
|
||||
scl <= '0' when (scl_ena = '1' and scl_clk = '0') else 'Z';
|
||||
|
|
|
|||
|
|
@ -2727,7 +2727,7 @@ uint32_t runTest::i2cRead(uint32_t slave_i2c_addr, uint32_t hmb_addr, uint32_t &
|
|||
while (pTestBench->pI2cStatus->GetBusy() == 1)
|
||||
usleepSim(1);
|
||||
|
||||
if (pTestBench->pI2cStatus->GetAborted() == 1)
|
||||
if ((pTestBench->pI2cStatus->GetAborted() == 1) || (pTestBench->pI2cStatus->GetAckError() == 1))
|
||||
success = false;
|
||||
|
||||
uint32_t rd_data;
|
||||
|
|
@ -2742,7 +2742,7 @@ uint32_t runTest::i2cRead(uint32_t slave_i2c_addr, uint32_t hmb_addr, uint32_t &
|
|||
while (pTestBench->pI2cStatus->GetBusy() == 1)
|
||||
usleepSim(1);
|
||||
|
||||
if (pTestBench->pI2cStatus->GetAborted() == 1)
|
||||
if ((pTestBench->pI2cStatus->GetAborted() == 1) || (pTestBench->pI2cStatus->GetAckError() == 1))
|
||||
success = false;
|
||||
|
||||
csrReadMem(CSR_TEST_I2C_MASTER | ((CMD_READ_OFFSET | slave_i2c_addr) << 2), &rd_data);
|
||||
|
|
@ -2755,7 +2755,7 @@ uint32_t runTest::i2cRead(uint32_t slave_i2c_addr, uint32_t hmb_addr, uint32_t &
|
|||
while (pTestBench->pI2cStatus->GetBusy() == 1)
|
||||
usleepSim(1);
|
||||
|
||||
if (pTestBench->pI2cStatus->GetAborted() == 1)
|
||||
if ((pTestBench->pI2cStatus->GetAborted() == 1) || (pTestBench->pI2cStatus->GetAckError() == 1))
|
||||
success = false;
|
||||
|
||||
data = rd_data;
|
||||
|
|
|
|||
|
|
@ -205,11 +205,6 @@ private:
|
|||
uint32_t clkFreqMHz;
|
||||
uint32_t i2cFreqKHz;
|
||||
|
||||
// ------------------------------------
|
||||
// Configure the FPM's pulse generator
|
||||
//
|
||||
int fpmConfig(CCoreAuto* pCore, double divRatio, uint32_t numSubPixPhases, uint32_t seq[], uint32_t seqLen);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -227,6 +227,7 @@ architecture sim of tb is
|
|||
signal i2c_stm8_rd_dv_in : std_logic := '0';
|
||||
signal i2c_short : std_logic;
|
||||
signal i2c_busy : std_logic;
|
||||
signal i2c_data : std_logic_vector(7 downto 0);
|
||||
signal i2c_busy_last : std_logic;
|
||||
signal i2c_ack_error : std_logic;
|
||||
signal i2c_aborted : std_logic;
|
||||
|
|
@ -572,7 +573,7 @@ begin
|
|||
short => i2c_short,
|
||||
data_wr => avs_csr_writedata(23 downto 0),
|
||||
busy => i2c_busy,
|
||||
data_rd => i2c_master_readdata(7 downto 0),
|
||||
data_rd => i2c_data,
|
||||
ack_error => i2c_ack_error,
|
||||
aborted => i2c_aborted,
|
||||
sda => sda,
|
||||
|
|
@ -580,6 +581,7 @@ begin
|
|||
);
|
||||
|
||||
i2c_short <= '1' when avs_csr_address(6 downto 0) = "001" & X"0" else '0';
|
||||
i2c_master_readdata(7 downto 0) <= To_X01(i2c_data);
|
||||
|
||||
-- Pullups on I2C interface
|
||||
sda <= 'H';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue