Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nimble: Reduce power usage, add compatibility to LFCLK calibration #1052

Merged
merged 3 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ add_definitions(-DNRF52 -DNRF52832 -DNRF52832_XXAA -DNRF52_PAN_74 -DNRF52_PAN_64
add_definitions(-DFREERTOS)
add_definitions(-D__STACK_SIZE=1024)
add_definitions(-D__HEAP_SIZE=4096)
add_definitions(-DMYNEWT_VAL_BLE_LL_RFMGMT_ENABLE_TIME=1500)

# Note: Only use this for debugging
# Derive the low frequency clock from the main clock (SYNT)
Expand Down
5 changes: 3 additions & 2 deletions src/libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#else
#include "core_cm4.h"
#endif
#include <legacy/nrf_drv_clock.h>

#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CODED_PHY)
#if !MYNEWT_VAL_CHOICE(MCU_TARGET, nRF52840) && !MYNEWT_VAL_CHOICE(MCU_TARGET, nRF52811)
Expand Down Expand Up @@ -2101,7 +2102,7 @@ ble_phy_rfclk_enable(void)
#if MYNEWT
nrf52_clock_hfxo_request();
#else
NRF_CLOCK->TASKS_HFCLKSTART = 1;
nrf_drv_clock_hfclk_request(NULL);
#endif
}

Expand All @@ -2111,6 +2112,6 @@ ble_phy_rfclk_disable(void)
#if MYNEWT
nrf52_clock_hfxo_release();
#else
NRF_CLOCK->TASKS_HFCLKSTOP = 1;
nrf_drv_clock_hfclk_release();
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "modlog/modlog.h"
#include "log_common/log_common.h"

#define BLE_HS_LOG_DEBUG(...) IGNORE(__VA_ARGS__)
#define BLE_HS_LOG_DEBUG(...) MODLOG_DEBUG(4, __VA_ARGS__)
#define BLE_HS_LOG_INFO(...) MODLOG_INFO(4, __VA_ARGS__)
#define BLE_HS_LOG_WARN(...) MODLOG_WARN(4, __VA_ARGS__)
#define BLE_HS_LOG_ERROR(...) MODLOG_ERROR(4, __VA_ARGS__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#ifndef H_MODLOG_
#define H_MODLOG_

#include <stdio.h>
#include "SEGGER_RTT.h"
#define printf(...) SEGGER_RTT_printf(0, __VA_ARGS__)

#include "log_common/log_common.h"
#include "log/log.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down