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/03/15 22:50:50 UTC

[mynewt-nimble] branch master updated: npl/riot: fix ble_npl_hw_is_in_critical()

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-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new a7b3c93  npl/riot: fix ble_npl_hw_is_in_critical()
a7b3c93 is described below

commit a7b3c939146e735b59d55bff740c906bde6f86f9
Author: Hauke Petersen <ha...@fu-berlin.de>
AuthorDate: Thu Mar 7 12:20:27 2019 +0100

    npl/riot: fix ble_npl_hw_is_in_critical()
---
 porting/npl/riot/include/nimble/nimble_npl_os.h | 14 ++++++++++++--
 porting/npl/riot/src/npl_os_riot.c              |  2 ++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/porting/npl/riot/include/nimble/nimble_npl_os.h b/porting/npl/riot/include/nimble/nimble_npl_os.h
index 806ec72..16f514b 100644
--- a/porting/npl/riot/include/nimble/nimble_npl_os.h
+++ b/porting/npl/riot/include/nimble/nimble_npl_os.h
@@ -38,6 +38,8 @@ extern "C" {
 typedef uint32_t ble_npl_time_t;
 typedef int32_t ble_npl_stime_t;
 
+extern volatile int ble_npl_in_critical;
+
 struct ble_npl_event {
     event_callback_t e;
     void *arg;
@@ -251,19 +253,27 @@ ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
 static inline uint32_t
 ble_npl_hw_enter_critical(void)
 {
-    return (uint32_t)irq_disable();
+    uint32_t ctx = irq_disable();
+    ++ble_npl_in_critical;
+    return ctx;
 }
 
 static inline void
 ble_npl_hw_exit_critical(uint32_t ctx)
 {
+    --ble_npl_in_critical;
     irq_restore((unsigned)ctx);
 }
 
 static inline bool
 ble_npl_hw_is_in_critical(void)
 {
-    return irq_is_in();
+    /*
+     * XXX Currently RIOT does not support an API for finding out if interrupts
+     *     are currently disabled, hence in a critical section in this context.
+     *     So for now, we use this global variable to keep this state for us.
+    -*/
+    return (ble_npl_in_critical > 0);
 }
 
 #ifdef __cplusplus
diff --git a/porting/npl/riot/src/npl_os_riot.c b/porting/npl/riot/src/npl_os_riot.c
index fd3db65..98a5edf 100644
--- a/porting/npl/riot/src/npl_os_riot.c
+++ b/porting/npl/riot/src/npl_os_riot.c
@@ -23,6 +23,8 @@
 #define ENABLE_DEBUG    (0)
 #include "debug.h"
 
+volatile int ble_npl_in_critical = 0;
+
 static void
 _callout_fire(void *arg)
 {