Skip to content

Commit

Permalink
Fix bugs found in simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
bengineerd committed Sep 19, 2023
1 parent 1c351f6 commit 442c0aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions protocols/i2c/rtl/I2cRegMaster.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ begin
v.i2cMasterIn.wrData := regIn.regAddr(addrIndexVar+7 downto addrIndexVar);
v.i2cMasterIn.wrValid := '1';
-- Must drop txnReq as last byte is sent if reading
v.i2cMasterIn.txnReq := not toSl(slv(r.byteCount) = regIn.regAddrSize and regIn.regOp = '0');
v.i2cMasterIn.txnReq := not toSl(slv(r.byteCount) = regIn.regAddrSize and regIn.regOp = '0' and regIn.wrDataOnRd = '0');

if (i2cMasterOut.wrAck = '1') then
v.byteCount := r.byteCount + 1;
Expand Down Expand Up @@ -197,7 +197,7 @@ begin
v.state := REG_ACK_S;
else
-- Handle wrDataOnRead case
v.state := READ_TXN_S;
v.state := READ_TXN_S;
end if;

end if;
Expand All @@ -209,6 +209,7 @@ begin
v.i2cMasterIn.txnReq := '1';
v.i2cMasterIn.op := '0';
v.i2cMasterIn.stop := '1'; -- i2c stop after all bytes are read
v.byteCount := (others => '0');
v.state := READ_S;

when READ_S =>
Expand Down
7 changes: 5 additions & 2 deletions protocols/i2c/rtl/I2cRegSlave.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ entity I2cRegSlave is
-- RAM generics
ADDR_SIZE_G : natural := 2; -- in bytes
DATA_SIZE_G : positive := 1; -- in bytes
ADDR_AUTO_INC_G : boolean := true;
ENDIANNESS_G : integer range 0 to 1 := 0); -- 0=LE, 1=BE
port (
sRst : in sl := '0';
Expand Down Expand Up @@ -137,8 +138,10 @@ begin

-- Auto increment the address after each read or write
-- This enables bursts.
if (r.wrEn = '1' or r.rdEn = '1') then
v.addr := r.addr + 1;
if (ADDR_AUTO_INC_G) then
if (r.wrEn = '1' or r.rdEn = '1') then
v.addr := r.addr + 1;
end if;
end if;

-- Tx Data always valid, assigned based on byte cnt
Expand Down

0 comments on commit 442c0aa

Please sign in to comment.