Update bt fork to be based on v5.3

This commit is contained in:
jacqueline
2024-08-13 06:02:54 +00:00
committed by cooljqln
parent be9725c1c7
commit 5a02f34ed9
508 changed files with 42429 additions and 5168 deletions
@@ -0,0 +1,167 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _NIMBLE_NPL_H_
#define _NIMBLE_NPL_H_
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct ble_npl_event;
typedef void ble_npl_event_fn(struct ble_npl_event *ev);
enum ble_npl_error {
BLE_NPL_OK = 0,
BLE_NPL_ENOMEM = 1,
BLE_NPL_EINVAL = 2,
BLE_NPL_INVALID_PARAM = 3,
BLE_NPL_MEM_NOT_ALIGNED = 4,
BLE_NPL_BAD_MUTEX = 5,
BLE_NPL_TIMEOUT = 6,
BLE_NPL_ERR_IN_ISR = 7,
BLE_NPL_ERR_PRIV = 8,
BLE_NPL_OS_NOT_STARTED = 9,
BLE_NPL_ENOENT = 10,
BLE_NPL_EBUSY = 11,
BLE_NPL_ERROR = 12,
};
typedef enum ble_npl_error ble_npl_error_t;
/* Include OS-specific definitions */
#include "nimble/nimble_npl_os.h"
/*
* Generic
*/
bool ble_npl_os_started(void);
void *ble_npl_get_current_task_id(void);
/*
* Event queue
*/
void ble_npl_eventq_init(struct ble_npl_eventq *evq);
void ble_npl_eventq_deinit(struct ble_npl_eventq *evq);
struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq,
ble_npl_time_t tmo);
void ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev);
void ble_npl_eventq_remove(struct ble_npl_eventq *evq,
struct ble_npl_event *ev);
void ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
void *arg);
bool ble_npl_event_is_queued(struct ble_npl_event *ev);
void *ble_npl_event_get_arg(struct ble_npl_event *ev);
void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg);
bool ble_npl_eventq_is_empty(struct ble_npl_eventq *evq);
void ble_npl_event_run(struct ble_npl_event *ev);
/*
* Mutexes
*/
ble_npl_error_t ble_npl_mutex_init(struct ble_npl_mutex *mu);
ble_npl_error_t ble_npl_mutex_pend(struct ble_npl_mutex *mu,
ble_npl_time_t timeout);
ble_npl_error_t ble_npl_mutex_release(struct ble_npl_mutex *mu);
ble_npl_error_t ble_npl_mutex_deinit(struct ble_npl_mutex *mu);
/*
* Semaphores
*/
ble_npl_error_t ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens);
ble_npl_error_t ble_npl_sem_pend(struct ble_npl_sem *sem,
ble_npl_time_t timeout);
ble_npl_error_t ble_npl_sem_release(struct ble_npl_sem *sem);
ble_npl_error_t ble_npl_sem_deinit(struct ble_npl_sem *sem);
uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem);
/*
* Callouts
*/
int ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
ble_npl_event_fn *ev_cb, void *ev_arg);
ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *co,
ble_npl_time_t ticks);
void ble_npl_callout_stop(struct ble_npl_callout *co);
bool ble_npl_callout_is_active(struct ble_npl_callout *co);
ble_npl_time_t ble_npl_callout_get_ticks(struct ble_npl_callout *co);
ble_npl_time_t ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t time);
void ble_npl_callout_set_arg(struct ble_npl_callout *co,
void *arg);
/*
* Time functions
*/
ble_npl_time_t ble_npl_time_get(void);
ble_npl_error_t ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks);
ble_npl_error_t ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms);
ble_npl_time_t ble_npl_time_ms_to_ticks32(uint32_t ms);
uint32_t ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks);
void ble_npl_time_delay(ble_npl_time_t ticks);
/*
* Hardware-specific
*
* These symbols should be most likely defined by application since they are
* specific to hardware, not to OS.
*/
#if NIMBLE_CFG_CONTROLLER
void ble_npl_hw_set_isr(int irqn, uint32_t addr);
#endif
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
#endif /* _NIMBLE_NPL_H_ */
@@ -1,9 +1,7 @@
/*
* SPDX-FileCopyrightText: 2019-2023 The Apache Software Foundation (ASF)
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*
* SPDX-FileContributor: 2019-2023 Espressif Systems (Shanghai) CO LTD
*/
#include <assert.h>
@@ -18,7 +16,6 @@
#include "freertos/timers.h"
#include "freertos/portable.h"
#include "nimble/npl_freertos.h"
#include "nimble/nimble_port.h"
#include "os/os_mempool.h"
#include "esp_log.h"
@@ -481,32 +478,32 @@ IRAM_ATTR npl_freertos_mutex_release(struct ble_npl_mutex *mu)
ble_npl_error_t
npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
{
struct ble_npl_sem_freertos *semaphor = NULL;
struct ble_npl_sem_freertos *semaphore = NULL;
#if OS_MEM_ALLOC
if (!os_memblock_from(&ble_freertos_sem_pool,sem->sem)) {
sem->sem = os_memblock_get(&ble_freertos_sem_pool);
semaphor = (struct ble_npl_sem_freertos *)sem->sem;
semaphore = (struct ble_npl_sem_freertos *)sem->sem;
if (!semaphor) {
if (!semaphore) {
return BLE_NPL_INVALID_PARAM;
}
memset(semaphor, 0, sizeof(*semaphor));
semaphor->handle = xSemaphoreCreateCounting(128, tokens);
BLE_LL_ASSERT(semaphor->handle);
memset(semaphore, 0, sizeof(*semaphore));
semaphore->handle = xSemaphoreCreateCounting(128, tokens);
BLE_LL_ASSERT(semaphore->handle);
}
#else
if(!sem->sem) {
sem->sem = malloc(sizeof(struct ble_npl_sem_freertos));
semaphor = (struct ble_npl_sem_freertos *)sem->sem;
semaphore = (struct ble_npl_sem_freertos *)sem->sem;
if (!semaphor) {
if (!semaphore) {
return BLE_NPL_INVALID_PARAM;
}
memset(semaphor, 0, sizeof(*semaphor));
semaphor->handle = xSemaphoreCreateCounting(128, tokens);
BLE_LL_ASSERT(semaphor->handle);
memset(semaphore, 0, sizeof(*semaphore));
semaphore->handle = xSemaphoreCreateCounting(128, tokens);
BLE_LL_ASSERT(semaphore->handle);
}
#endif
@@ -516,19 +513,19 @@ npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
ble_npl_error_t
npl_freertos_sem_deinit(struct ble_npl_sem *sem)
{
struct ble_npl_sem_freertos *semaphor = (struct ble_npl_sem_freertos *)sem->sem;
struct ble_npl_sem_freertos *semaphore = (struct ble_npl_sem_freertos *)sem->sem;
if (!semaphor) {
if (!semaphore) {
return BLE_NPL_INVALID_PARAM;
}
BLE_LL_ASSERT(semaphor->handle);
vSemaphoreDelete(semaphor->handle);
BLE_LL_ASSERT(semaphore->handle);
vSemaphoreDelete(semaphore->handle);
#if OS_MEM_ALLOC
os_memblock_put(&ble_freertos_sem_pool,semaphor);
os_memblock_put(&ble_freertos_sem_pool,semaphore);
#else
free((void *)semaphor);
free((void *)semaphore);
#endif
sem->sem = NULL;
@@ -540,22 +537,22 @@ IRAM_ATTR npl_freertos_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
{
BaseType_t woken;
BaseType_t ret;
struct ble_npl_sem_freertos *semaphor = (struct ble_npl_sem_freertos *)sem->sem;
struct ble_npl_sem_freertos *semaphore = (struct ble_npl_sem_freertos *)sem->sem;
if (!semaphor) {
if (!semaphore) {
return BLE_NPL_INVALID_PARAM;
}
BLE_LL_ASSERT(semaphor->handle);
BLE_LL_ASSERT(semaphore->handle);
if (in_isr()) {
BLE_LL_ASSERT(timeout == 0);
ret = xSemaphoreTakeFromISR(semaphor->handle, &woken);
ret = xSemaphoreTakeFromISR(semaphore->handle, &woken);
if( woken == pdTRUE ) {
portYIELD_FROM_ISR();
}
} else {
ret = xSemaphoreTake(semaphor->handle, timeout);
ret = xSemaphoreTake(semaphore->handle, timeout);
}
return ret == pdPASS ? BLE_NPL_OK : BLE_NPL_TIMEOUT;
@@ -566,21 +563,21 @@ IRAM_ATTR npl_freertos_sem_release(struct ble_npl_sem *sem)
{
BaseType_t ret;
BaseType_t woken;
struct ble_npl_sem_freertos *semaphor = (struct ble_npl_sem_freertos *)sem->sem;
struct ble_npl_sem_freertos *semaphore = (struct ble_npl_sem_freertos *)sem->sem;
if (!semaphor) {
if (!semaphore) {
return BLE_NPL_INVALID_PARAM;
}
BLE_LL_ASSERT(semaphor->handle);
BLE_LL_ASSERT(semaphore->handle);
if (in_isr()) {
ret = xSemaphoreGiveFromISR(semaphor->handle, &woken);
ret = xSemaphoreGiveFromISR(semaphore->handle, &woken);
if( woken == pdTRUE ) {
portYIELD_FROM_ISR();
}
} else {
ret = xSemaphoreGive(semaphor->handle);
ret = xSemaphoreGive(semaphore->handle);
}
BLE_LL_ASSERT(ret == pdPASS);
@@ -773,8 +770,8 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
uint16_t
IRAM_ATTR npl_freertos_sem_get_count(struct ble_npl_sem *sem)
{
struct ble_npl_sem_freertos *semaphor = (struct ble_npl_sem_freertos *)sem->sem;
return uxSemaphoreGetCount(semaphor->handle);
struct ble_npl_sem_freertos *semaphore = (struct ble_npl_sem_freertos *)sem->sem;
return uxSemaphoreGetCount(semaphore->handle);
}
@@ -842,15 +839,35 @@ ble_npl_time_t
IRAM_ATTR npl_freertos_callout_get_ticks(struct ble_npl_callout *co)
{
#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.
uint32_t exp = 0;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uint64_t expiry = 0;
esp_err_t err;
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
//Fetch expiry time in microseconds
err = esp_timer_get_expiry_time((esp_timer_handle_t)(callout->handle), &expiry);
if (err != ESP_OK) {
//Error. Could not fetch the expiry time
return 0;
}
//Convert microseconds to ticks
npl_freertos_time_ms_to_ticks((uint32_t)(expiry / 1000), &exp);
#else
//esp_timer_get_expiry_time() is only available from IDF 5.0 onwards
/* Returning 0 from here should not cause any effect.
* Drawback of this approach is that existing code to reset timer would be called
* more often (since the if condition to invoke reset timer would always succeed if
* timer is active).
*/
exp = 0;
#endif //ESP_IDF_VERSION
return 0;
return exp;
#else
struct ble_npl_callout_freertos *callout = (struct ble_npl_callout_freertos *)co->co;
return xTimerGetExpiryTime(callout->handle);