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

janc 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 006174842 port: add ble_npl_hw_is_in_critical implementation
006174842 is described below

commit 0061748426d18f8fe13767986c186ec543716afa
Author: Victor Luque <vlu...@inbrain-neuroelectronics.com>
AuthorDate: Thu Apr 24 11:09:19 2025 +0200

    port: add ble_npl_hw_is_in_critical implementation
---
 porting/npl/freertos/include/nimble/nimble_npl_os.h | 11 +++++++++++
 porting/npl/freertos/src/npl_os_freertos.c          |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/porting/npl/freertos/include/nimble/nimble_npl_os.h 
b/porting/npl/freertos/include/nimble/nimble_npl_os.h
index 00f64ba2d..44d216c87 100644
--- a/porting/npl/freertos/include/nimble/nimble_npl_os.h
+++ b/porting/npl/freertos/include/nimble/nimble_npl_os.h
@@ -65,6 +65,8 @@ struct ble_npl_sem {
     SemaphoreHandle_t handle;
 };
 
+extern volatile uint32_t s_critical_nesting;
+
 /*
  * Simple APIs are just defined as static inline below, but some are a bit more
  * complex or require some global state variables and thus are defined in .c
@@ -282,14 +284,23 @@ static inline uint32_t
 ble_npl_hw_enter_critical(void)
 {
     vPortEnterCritical();
+    s_critical_nesting++;
     return 0;
 }
 
 static inline void
 ble_npl_hw_exit_critical(uint32_t ctx)
 {
+    if (s_critical_nesting > 0) {
+        s_critical_nesting--;
+    }
     vPortExitCritical();
+}
 
+static inline bool
+ble_npl_hw_is_in_critical(void)
+{
+    return (s_critical_nesting > 0);
 }
 
 #ifdef __cplusplus
diff --git a/porting/npl/freertos/src/npl_os_freertos.c 
b/porting/npl/freertos/src/npl_os_freertos.c
index a671a80ea..584333c31 100644
--- a/porting/npl/freertos/src/npl_os_freertos.c
+++ b/porting/npl/freertos/src/npl_os_freertos.c
@@ -27,6 +27,8 @@
 #include NIMBLE_NPL_OS_EXTRA_INCLUDE
 #endif
 
+volatile uint32_t s_critical_nesting = 0;
+
 static inline bool
 in_isr(void)
 {

Reply via email to