Skip to content

Commit 421180e

Browse files
committed
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.
1 parent d39b916 commit 421180e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ add_definitions(-DNRF52 -DNRF52832 -DNRF52832_XXAA -DNRF52_PAN_74 -DNRF52_PAN_64
817817
add_definitions(-DFREERTOS)
818818
add_definitions(-D__STACK_SIZE=1024)
819819
add_definitions(-D__HEAP_SIZE=4096)
820+
add_definitions(-DMYNEWT_VAL_BLE_LL_RFMGMT_ENABLE_TIME=1500)
820821

821822
# Target hardware configuration options
822823
add_definitions(-DTARGET_DEVICE_${TARGET_DEVICE})

src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extern "C" {
3737

3838
#define BLE_NPL_TIME_FOREVER portMAX_DELAY
3939

40+
extern volatile int ble_npl_in_critical;
41+
4042
/* This should be compatible with TickType_t */
4143
typedef uint32_t ble_npl_time_t;
4244
typedef int32_t ble_npl_stime_t;
@@ -282,14 +284,22 @@ static inline uint32_t
282284
ble_npl_hw_enter_critical(void)
283285
{
284286
//vPortEnterCritical();
285-
return npl_freertos_hw_enter_critical();
287+
++ble_npl_in_critical;
288+
return npl_freertos_hw_enter_critical();
286289
}
287290

288291
static inline void
289292
ble_npl_hw_exit_critical(uint32_t ctx)
290293
{
291-
npl_freertos_hw_exit_critical(ctx);
294+
--ble_npl_in_critical;
295+
npl_freertos_hw_exit_critical(ctx);
296+
}
292297

298+
static inline bool
299+
ble_npl_hw_is_in_critical(void)
300+
{
301+
// Do the same as RIOT and keep track of the critical state manually
302+
return (ble_npl_in_critical > 0);
293303
}
294304

295305
#ifdef __cplusplus

src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <string.h>
2323
#include "nimble/nimble_npl.h"
2424

25+
volatile int ble_npl_in_critical = 0;
26+
2527
static inline bool
2628
in_isr(void)
2729
{

0 commit comments

Comments
 (0)