Skip to content

Commit

Permalink
Merge branch 'feature/modify_bt_sdkconfig_to_support_bluedroid_on_esp…
Browse files Browse the repository at this point in the history
…32c6' into 'master'

modify bt sdkconfig to support bluedroid examples for esp32c6

Closes IDF-6525 and BT-3113

See merge request espressif/esp-idf!21928
  • Loading branch information
Isl2017 committed Jan 16, 2023
2 parents 1bf040e + 923378a commit 1157657
Show file tree
Hide file tree
Showing 69 changed files with 340 additions and 137 deletions.
11 changes: 9 additions & 2 deletions components/bt/controller/esp32c2/Kconfig.in
Expand Up @@ -207,13 +207,13 @@ menu "Memory Settings"

config BT_LE_ACL_BUF_COUNT
int "ACL Buffer count"
default 24
default 10
help
The number of ACL data buffers.

config BT_LE_ACL_BUF_SIZE
int "ACL Buffer size"
default 255
default 517
help
This is the maximum size of the data portion of HCI ACL data packets.
It does not include the HCI data header (of 4 bytes)
Expand Down Expand Up @@ -387,3 +387,10 @@ choice BT_LE_WAKEUP_SOURCE
help
Use BLE rtc timer to wakeup CPU
endchoice

config BT_LE_USE_ESP_TIMER
bool "Use Esp Timer for callout"
depends on !BT_NIMBLE_ENABLED
default y
help
Set this option to use Esp Timer which has higher priority timer instead of FreeRTOS timer
18 changes: 13 additions & 5 deletions components/bt/controller/esp32c6/Kconfig.in
Expand Up @@ -159,7 +159,7 @@ config BT_LE_MAX_PERIODIC_SYNCS
int "Maximum number of periodic advertising syncs"
depends on BT_LE_50_FEATURE_SUPPORT && !BT_NIMBLE_ENABLED

range 0 3
range 0 8
default 1 if BT_LE_ENABLE_PERIODIC_ADV
default 0
help
Expand Down Expand Up @@ -207,13 +207,13 @@ menu "Memory Settings"

config BT_LE_ACL_BUF_COUNT
int "ACL Buffer count"
default 24
default 10
help
The number of ACL data buffers.

config BT_LE_ACL_BUF_SIZE
int "ACL Buffer size"
default 255
default 517
help
This is the maximum size of the data portion of HCI ACL data packets.
It does not include the HCI data header (of 4 bytes)
Expand Down Expand Up @@ -333,8 +333,8 @@ config BT_LE_LL_SCA
config BT_LE_MAX_CONNECTIONS
int "Maximum number of concurrent connections"
depends on !BT_NIMBLE_ENABLED
range 1 2
default 2
range 1 9
default 3
help
Defines maximum number of concurrent BLE connections. For ESP32, user
is expected to configure BTDM_CTRL_BLE_MAX_CONN from controller menu
Expand Down Expand Up @@ -387,3 +387,11 @@ choice BT_LE_WAKEUP_SOURCE
help
Use BLE rtc timer to wakeup CPU
endchoice

config BT_LE_USE_ESP_TIMER
bool "Enable Esp Timer for Callout"
depends on !BT_NIMBLE_ENABLED
default y
help
Set this option to use Esp Timer which has higher priority timer
instead of FreeRTOS timer
17 changes: 12 additions & 5 deletions components/bt/controller/esp32h4/Kconfig.in
Expand Up @@ -159,7 +159,7 @@ config BT_LE_MAX_PERIODIC_SYNCS
int "Maximum number of periodic advertising syncs"
depends on BT_LE_50_FEATURE_SUPPORT && !BT_NIMBLE_ENABLED

range 0 3
range 0 8
default 1 if BT_LE_ENABLE_PERIODIC_ADV
default 0
help
Expand Down Expand Up @@ -207,13 +207,13 @@ menu "Memory Settings"

config BT_LE_ACL_BUF_COUNT
int "ACL Buffer count"
default 24
default 10
help
The number of ACL data buffers.

config BT_LE_ACL_BUF_SIZE
int "ACL Buffer size"
default 255
default 517
help
This is the maximum size of the data portion of HCI ACL data packets.
It does not include the HCI data header (of 4 bytes)
Expand Down Expand Up @@ -333,7 +333,7 @@ config BT_LE_LL_SCA
config BT_LE_MAX_CONNECTIONS
int "Maximum number of concurrent connections"
depends on !BT_NIMBLE_ENABLED
range 1 8
range 1 9
default 3
help
Defines maximum number of concurrent BLE connections. For ESP32, user
Expand Down Expand Up @@ -381,5 +381,12 @@ choice BT_LE_WAKEUP_SOURCE
bool "Use ESP timer to wakeup CPU"
help
Use esp timer to wakeup CPU

endchoice

config BT_LE_USE_ESP_TIMER
bool "Use Esp Timer for callout"
depends on !BT_NIMBLE_ENABLED
default y
help
Set this option to use Esp Timer which has higher priority timer
instead of FreeRTOS timer
11 changes: 10 additions & 1 deletion components/bt/porting/npl/freertos/include/nimble/npl_freertos.h
Expand Up @@ -12,6 +12,15 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "sdkconfig.h"

#if ((defined(CONFIG_BT_NIMBLE_USE_ESP_TIMER) && CONFIG_BT_NIMBLE_USE_ESP_TIMER) || \
(defined(CONFIG_BT_LE_USE_ESP_TIMER) && CONFIG_BT_LE_USE_ESP_TIMER))
/* Use esp timer instead of FreeRTOS timer to implement the callout. */
#define BLE_NPL_USE_ESP_TIMER (1)
#else
#define BLE_NPL_USE_ESP_TIMER (0)
#endif

typedef struct {
uint16_t evt_count;
Expand All @@ -34,7 +43,7 @@ struct ble_npl_eventq_freertos {
};

struct ble_npl_callout_freertos {
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
esp_timer_handle_t handle;
#else
TimerHandle_t handle;
Expand Down
38 changes: 19 additions & 19 deletions components/bt/porting/npl/freertos/src/npl_os_freertos.c
Expand Up @@ -27,7 +27,7 @@

portMUX_TYPE ble_port_mutex = portMUX_INITIALIZER_UNLOCKED;

#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
static const char *TAG = "Timer";
#endif

Expand Down Expand Up @@ -547,7 +547,7 @@ IRAM_ATTR npl_freertos_sem_release(struct ble_npl_sem *sem)
return BLE_NPL_OK;
}

#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
static void
IRAM_ATTR ble_npl_event_fn_wrapper(void *arg)
{
Expand Down Expand Up @@ -613,7 +613,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
memset(callout, 0, sizeof(*callout));
ble_npl_event_init(&callout->ev, ev_cb, ev_arg);

#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
callout->evq = evq;

esp_timer_create_args_t create_args = {
Expand All @@ -637,7 +637,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
co->co = NULL;
return -1;
}
#endif // CONFIG_BT_NIMBLE_USE_ESP_TIMER
#endif // BLE_NPL_USE_ESP_TIMER
} else {
callout = (struct ble_npl_callout_freertos *)co->co;
BLE_LL_ASSERT(callout);
Expand All @@ -656,7 +656,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
memset(callout, 0, sizeof(*callout));
ble_npl_event_init(&callout->ev, ev_cb, ev_arg);

#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
callout->evq = evq;

esp_timer_create_args_t create_args = {
Expand All @@ -680,7 +680,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
co->co = NULL;
return -1;
}
#endif // CONFIG_BT_NIMBLE_USE_ESP_TIMER
#endif // BLE_NPL_USE_ESP_TIMER
}
else {
callout = (struct ble_npl_callout_freertos *)co->co;
Expand All @@ -707,7 +707,7 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
}

ble_npl_event_deinit(&callout->ev);
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
esp_err_t err = esp_timer_stop(callout->handle);
if(err != ESP_OK) {
if (err != ESP_ERR_INVALID_STATE) { // ESP_ERR_INVALID_STATE is expected when timer is already stopped
Expand All @@ -725,7 +725,7 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
#else
free((void *)callout);
#endif // OS_MEM_ALLOC
#endif // CONFIG_BT_NIMBLE_USE_ESP_TIMER
#endif // BLE_NPL_USE_ESP_TIMER
co->co = NULL;
memset(co, 0, sizeof(struct ble_npl_callout));
}
Expand All @@ -742,7 +742,7 @@ ble_npl_error_t
IRAM_ATTR npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
{
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
esp_timer_stop(callout->handle);

return esp_err_to_npl_error(esp_timer_start_once(callout->handle, ticks*1000));
Expand Down Expand Up @@ -780,7 +780,7 @@ IRAM_ATTR npl_freertos_callout_stop(struct ble_npl_callout *co)
return;
}

#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
esp_timer_stop(callout->handle);
#else
xTimerStop(callout->handle, portMAX_DELAY);
Expand All @@ -791,7 +791,7 @@ bool
IRAM_ATTR npl_freertos_callout_is_active(struct ble_npl_callout *co)
{
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
return esp_timer_is_active(callout->handle);
#else
return xTimerIsTimerActive(callout->handle) == pdTRUE;
Expand All @@ -801,7 +801,7 @@ IRAM_ATTR npl_freertos_callout_is_active(struct ble_npl_callout *co)
ble_npl_time_t
IRAM_ATTR npl_freertos_callout_get_ticks(struct ble_npl_callout *co)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
/* Currently, esp_timer does not support an API which gets the expiry time for
* current timer.
* Returning 0 from here should not cause any effect.
Expand All @@ -826,7 +826,7 @@ IRAM_ATTR npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co,

struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;

#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uint64_t expiry = 0;
esp_err_t err;
Expand Down Expand Up @@ -869,7 +869,7 @@ IRAM_ATTR npl_freertos_callout_set_arg(struct ble_npl_callout *co, void *arg)
uint32_t
IRAM_ATTR npl_freertos_time_get(void)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
return esp_timer_get_time() / 1000;
#else
return xTaskGetTickCountFromISR();
Expand All @@ -880,7 +880,7 @@ ble_npl_error_t
IRAM_ATTR npl_freertos_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
{
uint64_t ticks;
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
ticks = (uint64_t)ms;
#else
ticks = ((uint64_t)ms * configTICK_RATE_HZ) / 1000;
Expand All @@ -898,7 +898,7 @@ ble_npl_error_t
IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
{
uint64_t ms;
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
ms = ((uint64_t)ticks);
#else
ms = ((uint64_t)ticks * 1000) / configTICK_RATE_HZ;
Expand All @@ -915,7 +915,7 @@ IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
ble_npl_time_t
IRAM_ATTR npl_freertos_time_ms_to_ticks32(uint32_t ms)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
return ms;
#else
return ms * configTICK_RATE_HZ / 1000;
Expand All @@ -925,7 +925,7 @@ IRAM_ATTR npl_freertos_time_ms_to_ticks32(uint32_t ms)
uint32_t
IRAM_ATTR npl_freertos_time_ticks_to_ms32(ble_npl_time_t ticks)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
return ticks;
#else
return ticks * 1000 / configTICK_RATE_HZ;
Expand All @@ -935,7 +935,7 @@ IRAM_ATTR npl_freertos_time_ticks_to_ms32(ble_npl_time_t ticks)
void
IRAM_ATTR npl_freertos_time_delay(ble_npl_time_t ticks)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
#if BLE_NPL_USE_ESP_TIMER
vTaskDelay(ticks / portTICK_PERIOD_MS);
#else
vTaskDelay(ticks);
Expand Down

0 comments on commit 1157657

Please sign in to comment.