Skip to content

Commit

Permalink
implement failing I2C write tests #798
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Gardner-Stephen committed Apr 6, 2024
1 parent 2bfe33f commit 3003f4e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/vhdl/keypad_i2c.vhdl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ entity keypad_i2c is
sda : inout std_logic;
scl : inout std_logic;

debug_write_pending_count : inout integer := 0;
debug_write_count : inout integer := 0;

-- FastIO interface
cs : in std_logic;
fastio_read : in std_logic;
Expand Down Expand Up @@ -696,6 +699,7 @@ begin
i2c1_wdata <= write_reg;

write_count <= write_count + 1;
debug_write_count <= debug_write_count + 1;
when max_state+2 =>
-- Second, write the actual value into the register
if last_busy_count /= busy_count then
Expand Down
48 changes: 48 additions & 0 deletions src/vhdl/tb_keypad_i2c.vhdl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ architecture test_arch of tb_keypad_i2c is
signal fastio_rdata : unsigned(7 downto 0);
signal fastio_wdata : unsigned(7 downto 0) := to_unsigned(0,8);
signal fastio_addr : unsigned(19 downto 0) := x"00000";

signal debug_write_count : integer;
signal debug_write_pending_count : integer;

signal port0 : unsigned(7 downto 0) := x"00";
signal port1 : unsigned(7 downto 0) := x"50";
Expand All @@ -51,6 +54,9 @@ begin
sda => sda,
scl => scl,

debug_write_pending_count => debug_write_pending_count,
debug_write_count => debug_write_count,

cs => cs,
fastio_read => fastio_read,
fastio_write => fastio_write,
Expand Down Expand Up @@ -121,6 +127,48 @@ begin
clock_tick;
end loop;

elsif run("Writing to I2C expander triggers write_job_pending") then

reset_high <= '1'; clock_tick;clock_tick;clock_tick;clock_tick;
reset_high <= '0'; clock_tick;clock_tick;clock_tick;clock_tick;

POKE(x"7506",x"91");

for i in 1 to 100000 loop
clock_tick;
if debug_write_pending_count /= 0 then
exit;
end if;
end loop;

if debug_write_pending_count = 0 then
assert false report "write job was never marked pending";
end if;

elsif run("Writing to I2C causes write to occur") then

reset_high <= '1'; clock_tick;clock_tick;clock_tick;clock_tick;
reset_high <= '0'; clock_tick;clock_tick;clock_tick;clock_tick;

POKE(x"7506",x"91");

for i in 1 to 100000 loop
clock_tick;
if debug_write_count /= 0 then
exit;
end if;
end loop;

if debug_write_pending_count = 0 then
assert false report "write job was never marked pending";
end if;
if debug_write_count = 0 then
assert false report "write job was never completed";
end if;

report "debug_write_pending_count = " & integer'image(debug_write_pending_count);
assert false report "debug_write_count = " & integer'image(debug_write_count);

end if;
end loop;
test_runner_cleanup(runner);
Expand Down

0 comments on commit 3003f4e

Please sign in to comment.