Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement i2c ping #6

Open
guruofquality opened this issue Aug 4, 2021 · 0 comments
Open

implement i2c ping #6

guruofquality opened this issue Aug 4, 2021 · 0 comments

Comments

@guruofquality
Copy link

I wanted to be able to discover if a slave was available on the bus by using a ping. Basically a ping will only send the address, and then the stop condition. The missed_ack signal is used to determine the presence of the slave.

I made the following addition to i2c_master.v to add a s_axis_cmd_ping input signal that can cause STATE_ADDRESS_2 to transition to STATE_STOP, rather than read or write a byte.

I would like to upstream the change. Should I make a pull request? Is this a "fitting" way to add ping support to this module? Should the pull add support for ping in i2c_master_axil.v i2c_master_wbs_16.v i2c_master_wbs_8.v?

diff --git a/rtl/i2c_master.v b/rtl/i2c_master.v
index 9c69b48..caacdf2 100644
--- a/rtl/i2c_master.v
+++ b/rtl/i2c_master.v
@@ -38,6 +38,7 @@ module i2c_master (
      */
     input  wire [6:0]  s_axis_cmd_address,
     input  wire        s_axis_cmd_start,
+    input  wire        s_axis_cmd_ping,
     input  wire        s_axis_cmd_read,
     input  wire        s_axis_cmd_write,
     input  wire        s_axis_cmd_write_multiple,
@@ -232,6 +233,7 @@ reg [6:0] addr_reg = 7'd0, addr_next;
 reg [7:0] data_reg = 8'd0, data_next;
 reg last_reg = 1'b0, last_next;
 
+reg mode_ping_reg = 1'b0, mode_ping_next;
 reg mode_read_reg = 1'b0, mode_read_next;
 reg mode_write_multiple_reg = 1'b0, mode_write_multiple_next;
 reg mode_stop_reg = 1'b0, mode_stop_next;
@@ -304,6 +306,7 @@ always @* begin
     data_next = data_reg;
     last_next = last_reg;
 
+    mode_ping_next = mode_ping_reg;
     mode_read_next = mode_read_reg;
     mode_write_multiple_next = mode_write_multiple_reg;
     mode_stop_next = mode_stop_reg;
@@ -364,9 +367,10 @@ always @* begin
 
                 if (s_axis_cmd_ready & s_axis_cmd_valid) begin
                     // command valid
-                    if (s_axis_cmd_read ^ (s_axis_cmd_write | s_axis_cmd_write_multiple)) begin
+                    if (s_axis_cmd_ping ^ s_axis_cmd_read ^ (s_axis_cmd_write | s_axis_cmd_write_multiple)) begin
                         // read or write command
                         addr_next = s_axis_cmd_address;
+                        mode_ping_next = s_axis_cmd_ping;
                         mode_read_next = s_axis_cmd_read;
                         mode_write_multiple_next = s_axis_cmd_write_multiple;
                         mode_stop_next = s_axis_cmd_stop;
@@ -510,6 +514,8 @@ always @* begin
                     bit_count_next = 4'd8;
                     data_next = 1'b0;
                     state_next = STATE_READ;
+                end else if (mode_ping_reg) begin
+                    state_next = STATE_STOP;
                 end else begin
                     // start write
                     s_axis_data_tready_next = 1'b1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant