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 2018/12/05 14:34:35 UTC

[mynewt-core] 04/08: hw/bus: Allow to override lock timeout per-node

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 5e8f46782aede92251ecc89a2595bc6ac004e6e5
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Dec 3 16:48:49 2018 +0100

    hw/bus: Allow to override lock timeout per-node
    
    To save some space we may want to allow to disable per-node
    configuration in future, but for now let's make it always enabled since
    it only uses few extra bytes.
---
 hw/bus/include/bus/bus_driver.h |  4 ++++
 hw/bus/src/bus.c                | 11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/bus/include/bus/bus_driver.h b/hw/bus/include/bus/bus_driver.h
index 934a6b8..5ad822f 100644
--- a/hw/bus/include/bus/bus_driver.h
+++ b/hw/bus/include/bus/bus_driver.h
@@ -86,6 +86,8 @@ struct bus_node_callbacks {
 struct bus_node_cfg {
     /** Bus device name where node is attached */
     const char *bus_name;
+    /** Lock timeout [ms], 0 = default timeout */
+    uint16_t lock_timeout_ms;
 };
 
 /**
@@ -129,6 +131,8 @@ struct bus_node {
         void *init_arg;
     };
 
+    os_time_t lock_timeout;
+
 #if MYNEWT_VAL(BUS_STATS_PER_NODE)
     STATS_SECT_DECL(bus_stats_section) stats;
 #endif
diff --git a/hw/bus/src/bus.c b/hw/bus/src/bus.c
index ab808ed..6f987fb 100644
--- a/hw/bus/src/bus.c
+++ b/hw/bus/src/bus.c
@@ -167,6 +167,13 @@ bus_node_init_func(struct os_dev *odev, void *arg)
     init_arg = bnode->init_arg;
     bnode->parent_bus = (struct bus_dev *)parent_odev;
 
+    if (node_cfg->lock_timeout_ms) {
+        bnode->lock_timeout = os_time_ms_to_ticks32(node_cfg->lock_timeout_ms);
+    } else {
+        /* Use default */
+        bnode->lock_timeout = 0;
+    }
+
     odev->od_handlers.od_open = bus_node_open_func;
     odev->od_handlers.od_close = bus_node_close_func;
 
@@ -362,7 +369,9 @@ bus_node_unlock(struct os_dev *node)
 os_time_t
 bus_node_get_lock_timeout(struct os_dev *node)
 {
-    return g_bus_node_lock_timeout;
+    struct bus_node *bnode = (struct bus_node *)node;
+
+    return bnode->lock_timeout ? bnode->lock_timeout : g_bus_node_lock_timeout;
 }
 
 void