Fork ESP-IDF's bluetooth component

i want better sbc encoding, and no cla will stop me
This commit is contained in:
jacqueline
2024-03-28 14:32:49 +11:00
parent 239e6d8950
commit ee29c25b29
1761 changed files with 737738 additions and 0 deletions
@@ -0,0 +1,383 @@
/*
* SPDX-FileCopyrightText: 2015-2022 The Apache Software Foundation (ASF)
*
* SPDX-License-Identifier: Apache-2.0
*
* SPDX-FileContributor: 2019-2022 Espressif Systems (Shanghai) CO LTD
*/
#ifndef _NIMBLE_NPL_OS_H_
#define _NIMBLE_NPL_OS_H_
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "esp_timer.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) \
(sizeof(array) / sizeof((array)[0]))
#endif
extern int ets_printf(const char *fmt, ...);
#define BLE_LL_ASSERT(con) \
do{ \
if(!(con)) { \
ets_printf("assertion:%s\n",#con); \
ets_printf("line:%d,function:%s\n", __LINE__, __func__);\
assert(0); \
} \
}while(0)
#define BLE_NPL_OS_ALIGNMENT (4)/*ble_npl_get_os_alignment()*/
#define BLE_NPL_TIME_FOREVER ble_npl_get_time_forever()
/* This should be compatible with TickType_t */
typedef uint32_t ble_npl_time_t;
typedef int32_t ble_npl_stime_t;
struct ble_npl_event;
typedef void ble_npl_event_fn(struct ble_npl_event *ev);
struct ble_npl_event {
void *event;
};
struct ble_npl_eventq {
void *eventq;
};
struct ble_npl_callout {
void *co;
};
struct ble_npl_mutex {
void *mutex;
};
struct ble_npl_sem {
void *sem;
};
/*
* Simple APIs are just defined as static inline below, but some are a bit more
* complex or require some global state variables and thus are defined in .c
* file instead and static inline wrapper just calls proper implementation.
* We need declarations of these functions and they are defined in header below.
*/
#include "npl_freertos.h"
struct npl_funcs_t {
bool (*p_ble_npl_os_started)(void);
void *(*p_ble_npl_get_current_task_id)(void);
void (*p_ble_npl_eventq_init)(struct ble_npl_eventq *);
void (*p_ble_npl_eventq_deinit)(struct ble_npl_eventq *);
struct ble_npl_event * (*p_ble_npl_eventq_get)(struct ble_npl_eventq *, ble_npl_time_t);
void (*p_ble_npl_eventq_put)(struct ble_npl_eventq *, struct ble_npl_event *);
void (*p_ble_npl_eventq_remove)(struct ble_npl_eventq *, struct ble_npl_event *);
void (*p_ble_npl_event_run)(struct ble_npl_event *);
bool (*p_ble_npl_eventq_is_empty)(struct ble_npl_eventq *);
void (*p_ble_npl_event_init)(struct ble_npl_event *, ble_npl_event_fn *, void *);
void (*p_ble_npl_event_deinit)(struct ble_npl_event *);
void (*p_ble_npl_event_reset)(struct ble_npl_event *);
bool (*p_ble_npl_event_is_queued)(struct ble_npl_event *);
void * (*p_ble_npl_event_get_arg)(struct ble_npl_event *);
void (*p_ble_npl_event_set_arg)(struct ble_npl_event *, void *);
ble_npl_error_t (*p_ble_npl_mutex_init)(struct ble_npl_mutex *);
ble_npl_error_t (*p_ble_npl_mutex_deinit)(struct ble_npl_mutex *);
ble_npl_error_t (*p_ble_npl_mutex_pend)(struct ble_npl_mutex *, ble_npl_time_t);
ble_npl_error_t (*p_ble_npl_mutex_release)(struct ble_npl_mutex *);
ble_npl_error_t (*p_ble_npl_sem_init)(struct ble_npl_sem *, uint16_t);
ble_npl_error_t (*p_ble_npl_sem_deinit)(struct ble_npl_sem *);
ble_npl_error_t (*p_ble_npl_sem_pend)(struct ble_npl_sem *, ble_npl_time_t);
ble_npl_error_t (*p_ble_npl_sem_release)(struct ble_npl_sem *);
uint16_t (*p_ble_npl_sem_get_count)(struct ble_npl_sem *);
int (*p_ble_npl_callout_init)(struct ble_npl_callout *, struct ble_npl_eventq *, ble_npl_event_fn *, void *);
ble_npl_error_t (*p_ble_npl_callout_reset)(struct ble_npl_callout *, ble_npl_time_t);
void (*p_ble_npl_callout_stop)(struct ble_npl_callout *);
void (*p_ble_npl_callout_deinit)(struct ble_npl_callout *);
void (*p_ble_npl_callout_mem_reset)(struct ble_npl_callout *);
bool (*p_ble_npl_callout_is_active)(struct ble_npl_callout *);
ble_npl_time_t (*p_ble_npl_callout_get_ticks)(struct ble_npl_callout *);
uint32_t (*p_ble_npl_callout_remaining_ticks)(struct ble_npl_callout *, ble_npl_time_t);
void (*p_ble_npl_callout_set_arg)(struct ble_npl_callout *, void *);
uint32_t (*p_ble_npl_time_get)(void);
ble_npl_error_t (*p_ble_npl_time_ms_to_ticks)(uint32_t ms, ble_npl_time_t *);
ble_npl_error_t (*p_ble_npl_time_ticks_to_ms)(ble_npl_time_t, uint32_t *);
ble_npl_time_t (*p_ble_npl_time_ms_to_ticks32)(uint32_t);
uint32_t (*p_ble_npl_time_ticks_to_ms32)(ble_npl_time_t);
void (*p_ble_npl_time_delay)(ble_npl_time_t);
void (*p_ble_npl_hw_set_isr)(int, uint32_t);
uint32_t (*p_ble_npl_hw_enter_critical)(void);
void (*p_ble_npl_hw_exit_critical)(uint32_t);
uint32_t (*p_ble_npl_get_time_forever)(void);
uint8_t (*p_ble_npl_hw_is_in_critical)(void);
void (*p_ble_npl_eventq_put_to_front)(struct ble_npl_eventq *, struct ble_npl_event *);
};
extern struct npl_funcs_t *npl_funcs;
static inline bool
IRAM_ATTR ble_npl_os_started(void)
{
return npl_funcs->p_ble_npl_os_started();
}
static inline void *
IRAM_ATTR ble_npl_get_current_task_id(void)
{
return npl_funcs->p_ble_npl_get_current_task_id();
}
static inline void
IRAM_ATTR ble_npl_eventq_init(struct ble_npl_eventq *evq)
{
return npl_funcs->p_ble_npl_eventq_init(evq);
}
static inline void
IRAM_ATTR ble_npl_eventq_deinit(struct ble_npl_eventq *evq)
{
return npl_funcs->p_ble_npl_eventq_deinit(evq);
}
static inline struct ble_npl_event *
IRAM_ATTR ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
{
return npl_funcs->p_ble_npl_eventq_get(evq, tmo);
}
static inline void
IRAM_ATTR ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
{
return npl_funcs->p_ble_npl_eventq_put(evq, ev);
}
static inline void
IRAM_ATTR ble_npl_eventq_remove(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
{
return npl_funcs->p_ble_npl_eventq_remove(evq, ev);
}
static inline void
IRAM_ATTR ble_npl_event_run(struct ble_npl_event *ev)
{
return npl_funcs->p_ble_npl_event_run(ev);
}
static inline bool
IRAM_ATTR ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
{
return npl_funcs->p_ble_npl_eventq_is_empty(evq);
}
static inline void
IRAM_ATTR ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
void *arg)
{
return npl_funcs->p_ble_npl_event_init(ev, fn, arg);
}
static inline bool
IRAM_ATTR ble_npl_event_is_queued(struct ble_npl_event *ev)
{
return npl_funcs->p_ble_npl_event_is_queued(ev);
}
static inline void *
IRAM_ATTR ble_npl_event_get_arg(struct ble_npl_event *ev)
{
return npl_funcs->p_ble_npl_event_get_arg(ev);
}
static inline void
IRAM_ATTR ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg)
{
return npl_funcs->p_ble_npl_event_set_arg(ev, arg);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_mutex_init(struct ble_npl_mutex *mu)
{
return npl_funcs->p_ble_npl_mutex_init(mu);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_mutex_deinit(struct ble_npl_mutex *mu)
{
return npl_funcs->p_ble_npl_mutex_deinit(mu);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout)
{
return npl_funcs->p_ble_npl_mutex_pend(mu, timeout);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_mutex_release(struct ble_npl_mutex *mu)
{
return npl_funcs->p_ble_npl_mutex_release(mu);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
{
return npl_funcs->p_ble_npl_sem_init(sem, tokens);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_sem_deinit(struct ble_npl_sem *sem)
{
return npl_funcs->p_ble_npl_sem_deinit(sem);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
{
return npl_funcs->p_ble_npl_sem_pend(sem, timeout);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_sem_release(struct ble_npl_sem *sem)
{
return npl_funcs->p_ble_npl_sem_release(sem);
}
static inline uint16_t
IRAM_ATTR ble_npl_sem_get_count(struct ble_npl_sem *sem)
{
return npl_funcs->p_ble_npl_sem_get_count(sem);
}
static inline int
IRAM_ATTR ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
ble_npl_event_fn *ev_cb, void *ev_arg)
{
return npl_funcs->p_ble_npl_callout_init(co, evq, ev_cb, ev_arg);
}
static inline void
IRAM_ATTR ble_npl_callout_deinit(struct ble_npl_callout *co)
{
return npl_funcs->p_ble_npl_callout_deinit(co);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
{
return npl_funcs->p_ble_npl_callout_reset(co, ticks);
}
static inline void
IRAM_ATTR ble_npl_callout_stop(struct ble_npl_callout *co)
{
return npl_funcs->p_ble_npl_callout_stop(co);
}
static inline bool
IRAM_ATTR ble_npl_callout_is_active(struct ble_npl_callout *co)
{
return npl_funcs->p_ble_npl_callout_is_active(co);
}
static inline ble_npl_time_t
IRAM_ATTR ble_npl_callout_get_ticks(struct ble_npl_callout *co)
{
return npl_funcs->p_ble_npl_callout_get_ticks(co);
}
static inline ble_npl_time_t
IRAM_ATTR ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t time)
{
return npl_funcs->p_ble_npl_callout_remaining_ticks(co, time);
}
static inline void
IRAM_ATTR ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
{
return npl_funcs->p_ble_npl_callout_set_arg(co, arg);
}
static inline ble_npl_time_t
IRAM_ATTR ble_npl_time_get(void)
{
return npl_funcs->p_ble_npl_time_get();
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
{
return npl_funcs->p_ble_npl_time_ms_to_ticks(ms, out_ticks);
}
static inline ble_npl_error_t
IRAM_ATTR ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
{
return npl_funcs->p_ble_npl_time_ticks_to_ms(ticks, out_ms);
}
static inline ble_npl_time_t
IRAM_ATTR ble_npl_time_ms_to_ticks32(uint32_t ms)
{
return npl_funcs->p_ble_npl_time_ms_to_ticks32(ms);
}
static inline uint32_t
IRAM_ATTR ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
{
return npl_funcs->p_ble_npl_time_ticks_to_ms32(ticks);
}
static inline void
IRAM_ATTR ble_npl_time_delay(ble_npl_time_t ticks)
{
return npl_funcs->p_ble_npl_time_delay(ticks);
}
#if NIMBLE_CFG_CONTROLLER
static inline void
IRAM_ATTR ble_npl_hw_set_isr(int irqn, uint32_t addr)
{
return npl_funcs->p_ble_npl_hw_set_isr(irqn, addr);
}
#endif
static inline uint32_t
IRAM_ATTR ble_npl_hw_enter_critical(void)
{
return npl_funcs->p_ble_npl_hw_enter_critical();
}
static inline void
IRAM_ATTR ble_npl_hw_exit_critical(uint32_t ctx)
{
return npl_funcs->p_ble_npl_hw_exit_critical(ctx);
}
static inline bool IRAM_ATTR ble_npl_hw_is_in_critical(void)
{
return npl_funcs->p_ble_npl_hw_is_in_critical();
}
#define ble_npl_get_time_forever (*npl_funcs->p_ble_npl_get_time_forever)
#define ble_npl_callout_mem_reset (*npl_funcs->p_ble_npl_callout_mem_reset)
#define ble_npl_event_deinit (*npl_funcs->p_ble_npl_event_deinit)
#define ble_npl_event_reset (*npl_funcs->p_ble_npl_event_reset)
#ifdef __cplusplus
}
#endif
#endif /* _NPL_H_ */
@@ -0,0 +1,45 @@
/*
* SPDX-FileCopyrightText: 2015-2022 The Apache Software Foundation (ASF)
*
* SPDX-License-Identifier: Apache-2.0
*
* SPDX-FileContributor: 2019-2022 Espressif Systems (Shanghai) CO LTD
*/
#ifndef _NIMBLE_PORT_FREERTOS_H
#define _NIMBLE_PORT_FREERTOS_H
#include "nimble/nimble_npl.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief esp_nimble_enable - Initialize the NimBLE host task
*
* @param host_task
* @return esp_err_t
*/
esp_err_t esp_nimble_enable(void *host_task);
/**
* @brief esp_nimble_disable - Disable the NimBLE host task
*
* @return esp_err_t
*/
esp_err_t esp_nimble_disable(void);
void nimble_port_freertos_init(TaskFunction_t host_task_fn);
void nimble_port_freertos_deinit(void);
void npl_freertos_funcs_init(void);
void npl_freertos_funcs_deinit(void);
int npl_freertos_mempool_init(void);
struct npl_funcs_t * npl_freertos_funcs_get(void);
int npl_freertos_set_controller_npl_info(ble_npl_count_info_t *ctrl_npl_info);
#ifdef __cplusplus
}
#endif
#endif /* _NIMBLE_PORT_FREERTOS_H */
@@ -0,0 +1,125 @@
/*
* SPDX-FileCopyrightText: 2015-2022 The Apache Software Foundation (ASF)
*
* SPDX-License-Identifier: Apache-2.0
*
* SPDX-FileContributor: 2019-2022 Espressif Systems (Shanghai) CO LTD
*/
#ifndef _NPL_FREERTOS_H_
#define _NPL_FREERTOS_H_
#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;
uint16_t evtq_count;
uint16_t co_count;
uint16_t sem_count;
uint16_t mutex_count;
} ble_npl_count_info_t;
typedef void ble_npl_event_fn(struct ble_npl_event *ev);
struct ble_npl_event_freertos {
bool queued;
ble_npl_event_fn *fn;
void *arg;
};
struct ble_npl_eventq_freertos {
QueueHandle_t q;
};
struct ble_npl_callout_freertos {
#if BLE_NPL_USE_ESP_TIMER
esp_timer_handle_t handle;
#else
TimerHandle_t handle;
#endif
struct ble_npl_eventq *evq;
struct ble_npl_event ev;
};
struct ble_npl_mutex_freertos {
SemaphoreHandle_t handle;
};
struct ble_npl_sem_freertos {
SemaphoreHandle_t handle;
};
typedef void ble_npl_event_fn_freertos(struct ble_npl_event_freertos *ev);
struct ble_npl_eventq *npl_freertos_eventq_dflt_get(void);
struct ble_npl_event *npl_freertos_eventq_get(struct ble_npl_eventq *evq,
ble_npl_time_t tmo);
void npl_freertos_eventq_put(struct ble_npl_eventq *evq,
struct ble_npl_event *ev);
void npl_freertos_eventq_remove(struct ble_npl_eventq *evq,
struct ble_npl_event *ev);
ble_npl_error_t npl_freertos_mutex_init(struct ble_npl_mutex *mu);
ble_npl_error_t npl_freertos_mutex_deinit(struct ble_npl_mutex *mu);
ble_npl_error_t npl_freertos_mutex_pend(struct ble_npl_mutex *mu,
ble_npl_time_t timeout);
ble_npl_error_t 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);
ble_npl_error_t npl_freertos_sem_deinit(struct ble_npl_sem *sem);
ble_npl_error_t npl_freertos_sem_pend(struct ble_npl_sem *sem,
ble_npl_time_t timeout);
ble_npl_error_t npl_freertos_sem_release(struct ble_npl_sem *sem);
int npl_freertos_callout_init(struct ble_npl_callout *co,
struct ble_npl_eventq *evq,
ble_npl_event_fn *ev_cb, void *ev_arg);
void npl_freertos_callout_deinit(struct ble_npl_callout *co);
void npl_freertos_callout_stop(struct ble_npl_callout *co);
bool npl_freertos_callout_is_active(struct ble_npl_callout *co);
ble_npl_time_t npl_freertos_callout_get_ticks(struct ble_npl_callout *co);
ble_npl_error_t npl_freertos_callout_reset(struct ble_npl_callout *co,
ble_npl_time_t ticks);
ble_npl_time_t npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t now);
ble_npl_error_t npl_freertos_time_ms_to_ticks(uint32_t ms,
ble_npl_time_t *out_ticks);
ble_npl_error_t npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks,
uint32_t *out_ms);
uint32_t npl_freertos_hw_enter_critical(void);
void npl_freertos_hw_exit_critical(uint32_t ctx);
#ifdef __cplusplus
}
#endif
#endif /* _NPL_FREERTOS_H_ */
File diff suppressed because it is too large Load Diff