You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2021/06/30 13:01:27 UTC

[mynewt-core] branch master updated (77fdc6f -> 595a074)

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

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


    from 77fdc6f  flash_test: Add flash area list
     new 0a96ba7  hw/bus: Add write_read function to bus_dev_ops
     new 595a074  hw/bus/spi_hal: Add bus_spi_write_read

The 2 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/bus/drivers/spi_hal/src/spi_hal.c | 61 ++++++++++++++++++++++++++++++++++++
 hw/bus/include/bus/bus_driver.h      |  5 +++
 hw/bus/src/bus.c                     | 44 ++++++++++++++++----------
 3 files changed, 93 insertions(+), 17 deletions(-)

[mynewt-core] 02/02: hw/bus/spi_hal: Add bus_spi_write_read

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

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

commit 595a074aec88de2dc50688990debedb3c228e89c
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu May 27 16:13:34 2021 +0200

    hw/bus/spi_hal: Add bus_spi_write_read
    
    This implements new bus driver write_read function for
    spi_hal bus driver implementation.
    
    For short transactions (up to 16) bytes, function performs
    single SPI transfer that can reduce transaction time by half
    or more depending on hal_spi MCU  implementation.
---
 hw/bus/drivers/spi_hal/src/spi_hal.c | 61 ++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/hw/bus/drivers/spi_hal/src/spi_hal.c b/hw/bus/drivers/spi_hal/src/spi_hal.c
index 26c6db7..26e30a2 100644
--- a/hw/bus/drivers/spi_hal/src/spi_hal.c
+++ b/hw/bus/drivers/spi_hal/src/spi_hal.c
@@ -191,6 +191,66 @@ bus_spi_write(struct bus_dev *bdev, struct bus_node *bnode, const uint8_t *buf,
     return rc;
 }
 
+static int
+bus_spi_write_read(struct bus_dev *bdev, struct bus_node *bnode,
+                   const uint8_t *wbuf, uint16_t wlength,
+                   uint8_t *rbuf, uint16_t rlength,
+                   os_time_t timeout, uint16_t flags)
+{
+    struct bus_spi_hal_dev *dev = (struct bus_spi_hal_dev *)bdev;
+    struct bus_spi_node *node = (struct bus_spi_node *)bnode;
+    int rc;
+    uint8_t buf[16];
+
+    BUS_DEBUG_VERIFY_DEV(&dev->spi_dev);
+    BUS_DEBUG_VERIFY_NODE(node);
+
+    hal_gpio_write(node->pin_cs, 0);
+
+    /* XXX update HAL to accept const instead */
+
+#if MYNEWT_VAL(SPI_HAL_USE_NOBLOCK)
+    if (wlength + rlength <= sizeof(buf)) {
+        memcpy(buf, wbuf, wlength);
+        memset(buf + wlength, 0, rlength);
+        rc = hal_spi_txrx_noblock(dev->spi_dev.cfg.spi_num, buf, buf, wlength + rlength);
+        if (rc == 0) {
+            os_sem_pend(&dev->sem, OS_TIMEOUT_NEVER);
+            memcpy(rbuf, buf + wlength, rlength);
+        }
+    } else {
+        rc = hal_spi_txrx_noblock(dev->spi_dev.cfg.spi_num, (uint8_t *)wbuf, NULL, wlength);
+        if (rc == 0) {
+            os_sem_pend(&dev->sem, OS_TIMEOUT_NEVER);
+            memset(rbuf, 0, rlength);
+            rc = hal_spi_txrx_noblock(dev->spi_dev.cfg.spi_num, rbuf, rbuf, rlength);
+            if (rc == 0) {
+                os_sem_pend(&dev->sem, OS_TIMEOUT_NEVER);
+            }
+        }
+    }
+#else
+    if (wlength + rlength <= sizeof(buf)) {
+        memcpy(buf, wbuf, wlength);
+        rc = hal_spi_txrx(dev->spi_dev.cfg.spi_num, buf, buf, wlength + rlength);
+        if (rc == 0) {
+            memcpy(rbuf, buf + wlength, rlength);
+        }
+    } else {
+        rc = hal_spi_txrx(dev->spi_dev.cfg.spi_num, (uint8_t *)wbuf, NULL, wlength);
+        if (rc == 0) {
+            rc = hal_spi_txrx(dev->spi_dev.cfg.spi_num, NULL, rbuf, rlength);
+        }
+    }
+#endif
+
+    if (!(flags & BUS_F_NOSTOP)) {
+        hal_gpio_write(node->pin_cs, 1);
+    }
+
+    return rc;
+}
+
 static int bus_spi_disable(struct bus_dev *bdev)
 {
     struct bus_spi_dev *spi_dev = (struct bus_spi_dev *)bdev;
@@ -213,6 +273,7 @@ static const struct bus_dev_ops bus_spi_ops = {
     .read = bus_spi_read,
     .write = bus_spi_write,
     .disable = bus_spi_disable,
+    .write_read = bus_spi_write_read,
 };
 
 int

[mynewt-core] 01/02: hw/bus: Add write_read function to bus_dev_ops

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

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

commit 0a96ba7a48b76041138f86984119be553f89dff7
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu May 27 16:07:50 2021 +0200

    hw/bus: Add write_read function to bus_dev_ops
    
    Bus driver is often used to access devices when
    short writes are followed by short reads.
    
    Function to use in such a case bus_node_write_read_transact()
    can benefit in same cases about 50% when underlying driver
    also supports those write read transactions.
    
    This introduces optional function that allow to build more
    robust SPI and I2C transactions.
---
 hw/bus/include/bus/bus_driver.h |  5 +++++
 hw/bus/src/bus.c                | 44 +++++++++++++++++++++++++----------------
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/hw/bus/include/bus/bus_driver.h b/hw/bus/include/bus/bus_driver.h
index c3c77d3..8429ab6 100644
--- a/hw/bus/include/bus/bus_driver.h
+++ b/hw/bus/include/bus/bus_driver.h
@@ -63,6 +63,11 @@ struct bus_dev_ops {
                   uint16_t length, os_time_t timeout,  uint16_t flags);
     /* Disable bus device */
     int (* disable)(struct bus_dev *bus);
+    /* Write data to node */
+    int (* write_read)(struct bus_dev *dev, struct bus_node *node,
+                       const uint8_t *wbuf, uint16_t wlength,
+                       uint8_t *rbuf, uint16_t rlength,
+                       os_time_t timeout,  uint16_t flags);
 };
 
 /**
diff --git a/hw/bus/src/bus.c b/hw/bus/src/bus.c
index b7619fc..2998754 100644
--- a/hw/bus/src/bus.c
+++ b/hw/bus/src/bus.c
@@ -420,24 +420,34 @@ bus_node_write_read_transact(struct os_dev *node, const void *wbuf,
         goto done;
     }
 
-    /*
-     * XXX we probably should pass flags here but with some of them stripped,
-     * e.g. BUS_F_NOSTOP should not be present here, but since we do not have
-     * too many flags now (like we literally have only one flag) let's just pass
-     * no flags for now
-     */
-    BUS_STATS_INC(bdev, bnode, write_ops);
-    rc = bdev->dops->write(bdev, bnode, wbuf, wlength, timeout, BUS_F_NOSTOP);
-    if (rc) {
-        BUS_STATS_INC(bdev, bnode, write_errors);
-        goto done;
-    }
+    if (bdev->dops->write_read) {
+        BUS_STATS_INC(bdev, bnode, write_ops);
+        BUS_STATS_INC(bdev, bnode, read_ops);
+        rc = bdev->dops->write_read(bdev, bnode, wbuf, wlength, rbuf, rlength, timeout, flags);
+        if (rc) {
+            BUS_STATS_INC(bdev, bnode, write_errors);
+            BUS_STATS_INC(bdev, bnode, read_errors);
+        }
+    } else {
+        /*
+         * XXX we probably should pass flags here but with some of them stripped,
+         * e.g. BUS_F_NOSTOP should not be present here, but since we do not have
+         * too many flags now (like we literally have only one flag) let's just pass
+         * no flags for now
+         */
+        BUS_STATS_INC(bdev, bnode, write_ops);
+        rc = bdev->dops->write(bdev, bnode, wbuf, wlength, timeout, BUS_F_NOSTOP);
+        if (rc) {
+            BUS_STATS_INC(bdev, bnode, write_errors);
+            goto done;
+        }
 
-    BUS_STATS_INC(bdev, bnode, read_ops);
-    rc = bdev->dops->read(bdev, bnode, rbuf, rlength, timeout, flags);
-    if (rc) {
-        BUS_STATS_INC(bdev, bnode, read_errors);
-        goto done;
+        BUS_STATS_INC(bdev, bnode, read_ops);
+        rc = bdev->dops->read(bdev, bnode, rbuf, rlength, timeout, flags);
+        if (rc) {
+            BUS_STATS_INC(bdev, bnode, read_errors);
+            goto done;
+        }
     }
 
 done: