You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2019/01/08 13:11:15 UTC

[mynewt-core] branch master updated (c7afece -> cb9ece0)

This is an automated email from the ASF dual-hosted git repository.

andk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


    from c7afece  pins on P1 need to be properly configured
     new e80df7c  hw/util/i2cn: Fix functions descriptions
     new 1547d95  hw/util/i2cn: Fix parameter type
     new e8f3ed1  hw/util/i2cn: Add write_read_transact helper
     new 6472042  hw/drivers/lps33xhw: Fix sensor register read
     new b378268  hw/drivers/ms5840: Fix sensor register read
     new cb9ece0  hw/drivers/lps33thw: Restore read error stats

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/drivers/sensors/lps33hw/src/lps33hw.c   | 28 ++++++++-------------
 hw/drivers/sensors/lps33thw/src/lps33thw.c | 30 ++++++++--------------
 hw/drivers/sensors/ms5840/src/ms5840.c     | 35 ++++++++------------------
 hw/util/i2cn/include/i2cn/i2cn.h           | 40 +++++++++++++++++++++++++-----
 hw/util/i2cn/src/i2cn.c                    | 34 +++++++++++++++++++++++--
 5 files changed, 97 insertions(+), 70 deletions(-)


[mynewt-core] 01/06: hw/util/i2cn: Fix functions descriptions

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit e80df7c4a08437bc2df7a0eb511838abfc2e4482
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Jan 7 11:14:53 2019 +0100

    hw/util/i2cn: Fix functions descriptions
---
 hw/util/i2cn/include/i2cn/i2cn.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/util/i2cn/include/i2cn/i2cn.h b/hw/util/i2cn/include/i2cn/i2cn.h
index d6caaae..78d76ef 100644
--- a/hw/util/i2cn/include/i2cn/i2cn.h
+++ b/hw/util/i2cn/include/i2cn/i2cn.h
@@ -35,8 +35,8 @@ extern "C" {
  * @param i2c_num               The index of the I2C interface to read from.
  * @param pdata                 Additional parameters describing the read
  *                                  operation.
- * @param timeout               The time, in OS ticks, to wait for the MCU to
- *                                  indicate completion of each clocked byte.
+ * @param timeout               The time, in OS ticks, to wait for operation
+ *                                  completion.
  * @param last_op               1 if this is the final message in the
  *                                  transaction.
  *
@@ -53,8 +53,8 @@ int i2cn_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
  * @param i2c_num               The index of the I2C interface to write to.
  * @param pdata                 Additional parameters describing the write
  *                                  operation.
- * @param timeout               The time, in OS ticks, to wait for the MCU to
- *                                  indicate completion of each clocked byte.
+ * @param timeout               The time, in OS ticks, to wait for operation
+ *                                  completion.
  * @param last_op               1 if this is the final message in the
  *                                  transaction.
  *


[mynewt-core] 05/06: hw/drivers/ms5840: Fix sensor register read

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit b378268598fef3d53a283ac23099e888947d8721
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Jan 7 12:00:09 2019 +0100

    hw/drivers/ms5840: Fix sensor register read
    
    With i2cn, we need to make sure that before retrying read we also
    perform write as otherwise we may read subsequent registers instead of
    those we wanted to read thus invalid values will be reported.
---
 hw/drivers/sensors/ms5840/src/ms5840.c | 35 ++++++++++------------------------
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/hw/drivers/sensors/ms5840/src/ms5840.c b/hw/drivers/sensors/ms5840/src/ms5840.c
index 7892601..0038a08 100644
--- a/hw/drivers/sensors/ms5840/src/ms5840.c
+++ b/hw/drivers/sensors/ms5840/src/ms5840.c
@@ -379,12 +379,15 @@ ms5840_readlen(struct sensor_itf *itf, uint8_t addr, uint8_t *buffer,
 #if MYNEWT_VAL(BUS_DRIVER_PRESENT)
     rc = bus_node_simple_write_read_transact(itf->si_dev, &addr, 1, buffer, len);
 #else
-    uint8_t payload[3] = {addr, 0, 0};
-
-    struct hal_i2c_master_data data_struct = {
+    struct hal_i2c_master_data wdata = {
         .address = itf->si_addr,
         .len = 1,
-        .buffer = payload
+        .buffer = &addr,
+    };
+    struct hal_i2c_master_data rdata = {
+        .address = itf->si_addr,
+        .len = len,
+        .buffer = buffer,
     };
 
     /* Clear the supplied buffer */
@@ -395,32 +398,14 @@ ms5840_readlen(struct sensor_itf *itf, uint8_t addr, uint8_t *buffer,
         return rc;
     }
 
-    /* Command write */
-    rc = i2cn_master_write(itf->si_num, &data_struct, MYNEWT_VAL(MS5840_I2C_TIMEOUT_TICKS), 1,
-                           MYNEWT_VAL(MS5840_I2C_RETRIES));
-    if (rc) {
-        MS5840_LOG(ERROR, "I2C read command write failed at address 0x%02X\n",
-                   data_struct.address);
-        STATS_INC(g_ms5840stats, write_errors);
-        goto err;
-    }
-
-    /* Read len bytes back */
-    memset(payload, 0, sizeof(payload));
-    data_struct.len = len;
-    rc = i2cn_master_read(itf->si_num, &data_struct, MYNEWT_VAL(MS5840_I2C_TIMEOUT_TICKS), 1,
-                          MYNEWT_VAL(MS5840_I2C_RETRIES));
+    rc = i2cn_master_write_read_transact(itf->si_num, &wdata, &rdata, MYNEWT_VAL(MS5840_I2C_TIMEOUT_TICKS) * 2,
+                                         1, MYNEWT_VAL(MS5840_I2C_RETRIES));
     if (rc) {
         MS5840_LOG(ERROR, "Failed to read from 0x%02X:0x%02X\n",
-                   data_struct.address, addr);
+                   itf->si_addr, addr);
         STATS_INC(g_ms5840stats, read_errors);
-        goto err;
     }
 
-    /* Copy the I2C results into the supplied buffer */
-    memcpy(buffer, payload, len);
-
-err:
     sensor_itf_unlock(itf);
 #endif
 


[mynewt-core] 03/06: hw/util/i2cn: Add write_read_transact helper

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit e8f3ed12476873eb92274d7c9ba33a3653cc73d1
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Jan 7 11:16:24 2019 +0100

    hw/util/i2cn: Add write_read_transact helper
    
    This ensures that failed read will be followed by proper write each time
    to avoid isses when read stopped, but is incomplete (i.e. read some
    bytes, but not all of them). In such scenario retrying read only may
    lead to reading invalid data from device if it uses common pattern for
    accessing data, i.e. write register address and then increment register
    address after each read byte.
---
 hw/util/i2cn/include/i2cn/i2cn.h | 28 ++++++++++++++++++++++++++++
 hw/util/i2cn/src/i2cn.c          | 30 ++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/hw/util/i2cn/include/i2cn/i2cn.h b/hw/util/i2cn/include/i2cn/i2cn.h
index 9e7aa08..16072b0 100644
--- a/hw/util/i2cn/include/i2cn/i2cn.h
+++ b/hw/util/i2cn/include/i2cn/i2cn.h
@@ -64,6 +64,34 @@ int i2cn_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
 int i2cn_master_write(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
                       os_time_t timeout, uint8_t last_op, int retries);
 
+/**
+ * @brief Writes to and then read from an I2C slave, retrying the specified
+ * number of times on failure.
+ *
+ * This should be used whenever sequence of write (e.g. register address on
+ * sensor) and read (e.g. data from that register) is required in favor of
+ * separate write and read as it guaranteed that in case of failed read, write
+ * will be performed once more to guarantee read is handled properly by device.
+ *
+ * @param i2c_num               The index of the I2C interface to write to.
+ * @param wdata                 Additional parameters describing the write
+ *                                  operation.
+ * @param rdata                 Additional parameters describing the read
+ *                                  operation.
+ * @param timeout               The time, in OS ticks, to wait for either read
+ *                                  or write operation completion.
+ * @param last_op               1 if read is the final message in the
+ *                                  transaction.
+ *
+ * @return                      0 on success;
+ *                              HAL_I2C_ERR_[...] code on failure.
+ */
+int i2cn_master_write_read_transact(uint8_t i2c_num,
+                                    struct hal_i2c_master_data *wdata,
+                                    struct hal_i2c_master_data *rdata,
+                                    os_time_t timeout, uint8_t last_op,
+                                    int retries);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/util/i2cn/src/i2cn.c b/hw/util/i2cn/src/i2cn.c
index 2ec1113..cd350c4 100644
--- a/hw/util/i2cn/src/i2cn.c
+++ b/hw/util/i2cn/src/i2cn.c
@@ -63,3 +63,33 @@ i2cn_master_write(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
 
     return rc;
 }
+
+int
+i2cn_master_write_read_transact(uint8_t i2c_num,
+                                struct hal_i2c_master_data *wdata,
+                                struct hal_i2c_master_data *rdata,
+                                os_time_t timeout, uint8_t last_op, int retries)
+{
+    int rc = 0;
+    int i;
+
+    /* Ensure at least one try. */
+    if (retries < 0) {
+        retries = 0;
+    }
+
+    for (i = 0; i <= retries; i++) {
+        rc = hal_i2c_master_write(i2c_num, wdata, timeout, 0);
+        if (rc != 0) {
+            continue;
+        }
+
+        rc = hal_i2c_master_read(i2c_num, rdata, timeout, last_op);
+        if (rc == 0) {
+            break;
+        }
+    }
+
+    return rc;
+
+}


[mynewt-core] 02/06: hw/util/i2cn: Fix parameter type

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 1547d9519d516aa32789fe7add52dfa0e2815de0
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Jan 7 11:16:14 2019 +0100

    hw/util/i2cn: Fix parameter type
    
    OS ticks should be always os_time_t to avoid confusion.
---
 hw/util/i2cn/include/i2cn/i2cn.h | 4 ++--
 hw/util/i2cn/src/i2cn.c          | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/util/i2cn/include/i2cn/i2cn.h b/hw/util/i2cn/include/i2cn/i2cn.h
index 78d76ef..9e7aa08 100644
--- a/hw/util/i2cn/include/i2cn/i2cn.h
+++ b/hw/util/i2cn/include/i2cn/i2cn.h
@@ -44,7 +44,7 @@ extern "C" {
  *                              HAL_I2C_ERR_[...] code on failure.
  */
 int i2cn_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
-                     uint32_t timeout, uint8_t last_op, int retries);
+                     os_time_t timeout, uint8_t last_op, int retries);
 
 /**
  * @brief Writes to an I2C slave, retrying the specified number of times on
@@ -62,7 +62,7 @@ int i2cn_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
  *                              HAL_I2C_ERR_[...] code on failure.
  */
 int i2cn_master_write(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
-                      uint32_t timeout, uint8_t last_op, int retries);
+                      os_time_t timeout, uint8_t last_op, int retries);
 
 #ifdef __cplusplus
 }
diff --git a/hw/util/i2cn/src/i2cn.c b/hw/util/i2cn/src/i2cn.c
index 2322e1f..2ec1113 100644
--- a/hw/util/i2cn/src/i2cn.c
+++ b/hw/util/i2cn/src/i2cn.c
@@ -22,7 +22,7 @@
 
 int
 i2cn_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
-                 uint32_t timeout, uint8_t last_op, int retries)
+                 os_time_t timeout, uint8_t last_op, int retries)
 {
     int rc = 0;
     int i;
@@ -44,7 +44,7 @@ i2cn_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
 
 int
 i2cn_master_write(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
-                  uint32_t timeout, uint8_t last_op, int retries)
+                  os_time_t timeout, uint8_t last_op, int retries)
 {
     int rc = 0;
     int i;


[mynewt-core] 04/06: hw/drivers/lps33xhw: Fix sensor register read

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 64720421f25669f4d08c3561f377a730d152506e
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Jan 7 12:00:09 2019 +0100

    hw/drivers/lps33xhw: Fix sensor register read
    
    With i2cn, we need to make sure that before retrying read we also
    perform write as otherwise we may read subsequent registers instead of
    those we wanted to read thus invalid values will be reported.
---
 hw/drivers/sensors/lps33hw/src/lps33hw.c   | 28 ++++++++++----------------
 hw/drivers/sensors/lps33thw/src/lps33thw.c | 32 +++++++++---------------------
 2 files changed, 19 insertions(+), 41 deletions(-)

diff --git a/hw/drivers/sensors/lps33hw/src/lps33hw.c b/hw/drivers/sensors/lps33hw/src/lps33hw.c
index a55a7a6..b54527b 100644
--- a/hw/drivers/sensors/lps33hw/src/lps33hw.c
+++ b/hw/drivers/sensors/lps33hw/src/lps33hw.c
@@ -354,35 +354,27 @@ lps33hw_i2c_get_regs(struct sensor_itf *itf, uint8_t reg, uint8_t size,
     uint8_t *buffer)
 {
     int rc;
-
-    struct hal_i2c_master_data data_struct = {
+    struct hal_i2c_master_data wdata = {
         .address = itf->si_addr,
         .len = 1,
         .buffer = &reg
     };
+    struct hal_i2c_master_data rdata = {
+        .address = itf->si_addr,
+        .len = size,
+        .buffer = buffer,
+    };
 
-    /* Register write */
-    rc = i2cn_master_write(itf->si_num, &data_struct, MYNEWT_VAL(LPS33HW_I2C_TIMEOUT_TICKS), 0,
-                           MYNEWT_VAL(LPS33HW_I2C_RETRIES));
+    rc = i2cn_master_write_read_transact(itf->si_num, &wdata, &rdata,
+                                         MYNEWT_VAL(LPS33HW_I2C_TIMEOUT_TICKS) * (size + 1),
+                                         1, MYNEWT_VAL(LPS33HW_I2C_RETRIES));
     if (rc) {
         LPS33HW_LOG(ERROR, "I2C access failed at address 0x%02X\n",
                     itf->si_addr);
-        STATS_INC(g_lps33hwstats, write_errors);
+        STATS_INC(g_lps33hwstats, read_errors);
         return rc;
     }
 
-    /* Read */
-    data_struct.len = size;
-    data_struct.buffer = buffer;
-    rc = i2cn_master_read(itf->si_num, &data_struct,
-                          (MYNEWT_VAL(LPS33HW_I2C_TIMEOUT_TICKS)) * size, 1,
-                          MYNEWT_VAL(LPS33HW_I2C_RETRIES));
-
-    if (rc) {
-        LPS33HW_LOG(ERROR, "Failed to read from 0x%02X:0x%02X\n",
-                    itf->si_addr, reg);
-        STATS_INC(g_lps33hwstats, read_errors);
-    }
     return rc;
 }
 #endif
diff --git a/hw/drivers/sensors/lps33thw/src/lps33thw.c b/hw/drivers/sensors/lps33thw/src/lps33thw.c
index f80f050..9919929 100644
--- a/hw/drivers/sensors/lps33thw/src/lps33thw.c
+++ b/hw/drivers/sensors/lps33thw/src/lps33thw.c
@@ -361,34 +361,20 @@ lps33thw_i2c_get_regs(struct sensor_itf *itf, uint8_t reg, uint8_t size,
 
     rc = bus_node_simple_write_read_transact(odev, &reg, 1, buffer, size);
 #else
-    struct hal_i2c_master_data data_struct = {
+    struct hal_i2c_master_data wdata = {
         .address = itf->si_addr,
         .len = 1,
         .buffer = &reg
     };
+    struct hal_i2c_master_data rdata = {
+        .address = itf->si_addr,
+        .len = size,
+        .buffer = buffer,
+    };
 
-    /* Register write */
-    rc = i2cn_master_write(itf->si_num, &data_struct, MYNEWT_VAL(LPS33THW_I2C_TIMEOUT_TICKS), 0,
-                           MYNEWT_VAL(LPS33THW_I2C_RETRIES));
-    if (rc) {
-        LPS33THW_LOG(ERROR, "I2C access failed at address 0x%02X\n",
-                    itf->si_addr);
-        STATS_INC(g_lps33thwstats, write_errors);
-        return rc;
-    }
-
-    /* Read */
-    data_struct.len = size;
-    data_struct.buffer = buffer;
-    rc = i2cn_master_read(itf->si_num, &data_struct,
-                          (MYNEWT_VAL(LPS33THW_I2C_TIMEOUT_TICKS)) * size, 1,
-                          MYNEWT_VAL(LPS33THW_I2C_RETRIES));
-
-    if (rc) {
-        LPS33THW_LOG(ERROR, "Failed to read from 0x%02X:0x%02X\n",
-                    itf->si_addr, reg);
-        STATS_INC(g_lps33thwstats, read_errors);
-    }
+    rc = i2cn_master_write_read_transact(itf->si_num, &wdata, &rdata,
+                                         MYNEWT_VAL(LPS33THW_I2C_TIMEOUT_TICKS) * (size + 1),
+                                         1, MYNEWT_VAL(LPS33THW_I2C_RETRIES));
 #endif
 
     return rc;


[mynewt-core] 06/06: hw/drivers/lps33thw: Restore read error stats

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit cb9ece042bb2b1491f405d8e83e7c2f39dea4a4d
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Jan 8 14:01:56 2019 +0100

    hw/drivers/lps33thw: Restore read error stats
---
 hw/drivers/sensors/lps33thw/src/lps33thw.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/drivers/sensors/lps33thw/src/lps33thw.c b/hw/drivers/sensors/lps33thw/src/lps33thw.c
index 9919929..d3d44cb 100644
--- a/hw/drivers/sensors/lps33thw/src/lps33thw.c
+++ b/hw/drivers/sensors/lps33thw/src/lps33thw.c
@@ -375,6 +375,12 @@ lps33thw_i2c_get_regs(struct sensor_itf *itf, uint8_t reg, uint8_t size,
     rc = i2cn_master_write_read_transact(itf->si_num, &wdata, &rdata,
                                          MYNEWT_VAL(LPS33THW_I2C_TIMEOUT_TICKS) * (size + 1),
                                          1, MYNEWT_VAL(LPS33THW_I2C_RETRIES));
+    if (rc) {
+        LPS33THW_LOG(ERROR, "I2C access failed at address 0x%02X\n",
+                     itf->si_addr);
+        STATS_INC(g_lps33thwstats, read_errors);
+        return rc;
+    }
 #endif
 
     return rc;