Skip to content

Commit 22ba0cc

Browse files
committed
Correct condition for other master start detection
1 parent a60e735 commit 22ba0cc

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Implementation of Inter-IC (I2C) bus master and slave, covering almost all edge
1717
- [x] SDA
1818
- [x] Transmit
1919
- [x] Receive
20-
- [x] Arbitration (multi-master)
20+
- [x] Arbitration (multi-master) (untested)
2121
- [x] Basic Implementation
2222
- [x] Detect other masters triggering start before this master
2323
- [ ] Hotloading (not from i2c spec)
@@ -26,7 +26,7 @@ Implementation of Inter-IC (I2C) bus master and slave, covering almost all edge
2626
- listen for WAIT_TIME_END to see if the clock is driven LOW
2727
- if no: bus is free
2828
- if yes: keep listening until a STOP or START
29-
- [x] Other masters
29+
- [x] Other masters (untested)
3030
- [x] erroneous starts detected w/ start_err
3131
- [x] Port map
3232
- Slave

src/master.sv

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ logic start_by_another_master = 1'b0;
9292
always @(sda === 1'bz or sda === 1'b0)
9393
begin
9494
if (scl === 1'bz)
95+
`else
96+
always @(posedge sda or negedge sda)
97+
begin
98+
if (scl)
99+
`endif
95100
begin
96101
busy <= sda === 1'b0;
97102
if (sda === 1'b0)
@@ -100,23 +105,10 @@ begin
100105
$display("Master becomes free @ %d %d", counter, transaction_progress);
101106
// See Note 4 in Section 3.1.10
102107
// Should only trigger if a start occurs while this master was in the middle of something.
103-
if (busy && sda == 1'b0 && transaction_progress != 4'd0 && transaction_progress != 4'd11 && MULTI_MASTER)
104-
start_by_another_master <= 1'd1;
105-
end
106-
end
107-
`else
108-
always @(posedge sda or negedge sda)
109-
begin
110-
if (scl)
111-
begin
112-
busy <= !sda;
113-
// See Note 4 in Section 3.1.10
114-
// Should only trigger if a start occurs while this master was in the middle of something.
115-
if (busy && !sda && transaction_progress != 4'd0 && transaction_progress != 4'd11 && MULTI_MASTER)
108+
if (busy && !sda && !(transfer_start && (transaction_progress == 4'd1 || transaction_progress == 4'd11)) && MULTI_MASTER)
116109
start_by_another_master <= 1'd1;
117110
end
118111
end
119-
`endif
120112

121113
// Conforms to Table 10 minimum setup/hold/bus free times.
122114
localparam TLOW_MIN = MODE == 0 ? 4.7 : MODE == 1 ? 1.3 : MODE == 2 ? 0.5 : 0; // in microseconds

0 commit comments

Comments
 (0)