diff --git a/nimble/include/nimble/nimble_npl.h b/nimble/include/nimble/nimble_npl.h index 49505958d..5935b740f 100644 --- a/nimble/include/nimble/nimble_npl.h +++ b/nimble/include/nimble/nimble_npl.h @@ -165,6 +165,8 @@ uint32_t ble_npl_hw_enter_critical(void); void ble_npl_hw_exit_critical(uint32_t ctx); +bool ble_npl_hw_is_in_critical(void); + #ifdef __cplusplus } #endif diff --git a/porting/nimble/include/os/os.h b/porting/nimble/include/os/os.h index 04a62a3a2..6dc304b7a 100644 --- a/porting/nimble/include/os/os.h +++ b/porting/nimble/include/os/os.h @@ -45,6 +45,7 @@ extern "C" { typedef uint32_t os_sr_t; #define OS_ENTER_CRITICAL(_sr) (_sr = ble_npl_hw_enter_critical()) #define OS_EXIT_CRITICAL(_sr) (ble_npl_hw_exit_critical(_sr)) +#define OS_ASSERT_CRITICAL() (assert(ble_npl_hw_is_in_critical())) /* Mynewt components (not abstracted in NPL) */ #include "os/endian.h" diff --git a/porting/npl/riot/include/nimble/nimble_npl_os.h b/porting/npl/riot/include/nimble/nimble_npl_os.h index b07b1145b..1faabe937 100644 --- a/porting/npl/riot/include/nimble/nimble_npl_os.h +++ b/porting/npl/riot/include/nimble/nimble_npl_os.h @@ -256,6 +256,12 @@ ble_npl_hw_exit_critical(uint32_t ctx) irq_restore((unsigned)ctx); } +static inline bool +ble_npl_hw_is_in_critical(void) +{ + return irq_is_in(); +} + #ifdef __cplusplus } #endif