summaryrefslogtreecommitdiff
path: root/src/libs/mynewt-nimble/porting/npl
diff options
context:
space:
mode:
authorChristoph Honal <christoph.honal@web.de>2022-03-21 14:05:49 +0100
committerJF <JF002@users.noreply.github.com>2022-07-07 11:20:56 +0200
commit118adb96cf4503fdccd974090934d18c279cc403 (patch)
treec8cc7fc8e7aade02be251febd5a46bbc4dc6e7c2 /src/libs/mynewt-nimble/porting/npl
parent9b9286175322f99ae0265565ae9b0ae49efa2c26 (diff)
Nimble: Reduce BLE power usage
This configures Nimble to enable the HFCLOCK and other Bluetooth peripherals only when needed, but 1500 us in advance. This time is recommended by the Mynewt docs.
Diffstat (limited to 'src/libs/mynewt-nimble/porting/npl')
-rw-r--r--src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h14
-rw-r--r--src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c2
2 files changed, 14 insertions, 2 deletions
diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h
index 545be0f4..3a3de40d 100644
--- a/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h
+++ b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h
@@ -37,6 +37,8 @@ extern "C" {
#define BLE_NPL_TIME_FOREVER portMAX_DELAY
+extern volatile int ble_npl_in_critical;
+
/* This should be compatible with TickType_t */
typedef uint32_t ble_npl_time_t;
typedef int32_t ble_npl_stime_t;
@@ -282,14 +284,22 @@ static inline uint32_t
ble_npl_hw_enter_critical(void)
{
//vPortEnterCritical();
- return npl_freertos_hw_enter_critical();
+ ++ble_npl_in_critical;
+ return npl_freertos_hw_enter_critical();
}
static inline void
ble_npl_hw_exit_critical(uint32_t ctx)
{
- npl_freertos_hw_exit_critical(ctx);
+ --ble_npl_in_critical;
+ npl_freertos_hw_exit_critical(ctx);
+}
+static inline bool
+ble_npl_hw_is_in_critical(void)
+{
+ // Do the same as RIOT and keep track of the critical state manually
+ return (ble_npl_in_critical > 0);
}
#ifdef __cplusplus
diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c
index 875521ab..667a751c 100644
--- a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c
+++ b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c
@@ -22,6 +22,8 @@
#include <string.h>
#include "nimble/nimble_npl.h"
+volatile int ble_npl_in_critical = 0;
+
static inline bool
in_isr(void)
{