Optimized NPL Freertos API

This commit is contained in:
zwl
2023-01-03 14:44:46 +08:00
parent 9a3c8a6567
commit 530c07a5be
6 changed files with 36 additions and 25 deletions

View File

@@ -596,7 +596,6 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
esp_err_t ret = ESP_OK;
ble_npl_count_info_t npl_info;
memset(&npl_info, 0, sizeof(ble_npl_count_info_t));
if (ble_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "invalid controller state");
return ESP_ERR_INVALID_STATE;
@@ -630,8 +629,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
}
ble_get_npl_element_info(cfg, &npl_info);
if (npl_freertos_mempool_init(&npl_info) != 0) {
npl_freertos_set_controller_npl_info(&npl_info);
if (npl_freertos_mempool_init() != 0) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "npl mempool init failed");
ret = ESP_ERR_INVALID_ARG;
goto free_mem;

View File

@@ -613,8 +613,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
}
ble_get_npl_element_info(cfg, &npl_info);
if (npl_freertos_mempool_init(&npl_info) != 0) {
npl_freertos_set_controller_npl_info(&npl_info);
if (npl_freertos_mempool_init() != 0) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "npl mempool init failed");
ret = ESP_ERR_INVALID_ARG;
goto free_mem;

View File

@@ -35,14 +35,6 @@
extern "C" {
#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;
void nimble_port_init(void);
void nimble_port_deinit(void);

View File

@@ -35,8 +35,9 @@ 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(ble_npl_count_info_t *npl_info);
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

View File

@@ -22,6 +22,14 @@ extern "C" {
#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 {

View File

@@ -59,6 +59,13 @@ struct os_mempool ble_freertos_mutex_pool;
static os_membuf_t *ble_freertos_mutex_buf = NULL;
static uint16_t ble_freertos_total_event_cnt = 0;
static ble_npl_count_info_t g_ctrl_npl_info = {
.co_count = 0,
.evt_count = 0,
.evtq_count = 0,
.mutex_count = 0,
.sem_count = 0,
};
bool
IRAM_ATTR npl_freertos_os_started(void)
@@ -1032,8 +1039,17 @@ void npl_freertos_funcs_init(void)
memcpy(npl_funcs, &npl_funcs_ro, sizeof(struct npl_funcs_t));
}
int npl_freertos_set_controller_npl_info(ble_npl_count_info_t *ctrl_npl_info)
{
if (!ctrl_npl_info) {
return -1;
}
int npl_freertos_mempool_init(ble_npl_count_info_t *npl_info)
memcpy(&g_ctrl_npl_info, ctrl_npl_info, sizeof(ble_npl_count_info_t));
return 0;
}
int npl_freertos_mempool_init(void)
{
int rc = -1;
uint16_t ble_total_evt_count = 0;
@@ -1041,16 +1057,11 @@ int npl_freertos_mempool_init(ble_npl_count_info_t *npl_info)
uint16_t ble_total_evtq_count = 0;
uint16_t ble_total_sem_count = 0;
uint16_t ble_total_mutex_count = 0;
if (!npl_info) {
return -1;
}
ble_total_evt_count = npl_info->evt_count + BLE_HOST_EV_COUNT;
ble_total_evtq_count = npl_info->evtq_count + BLE_HOST_EVQ_COUNT;
ble_total_co_count = npl_info->co_count + BLE_HOST_CO_COUNT;
ble_total_sem_count = npl_info->sem_count + BLE_HOST_SEM_COUNT;
ble_total_mutex_count = npl_info->mutex_count + BLE_HOST_MUTEX_COUNT;
ble_total_evt_count = g_ctrl_npl_info.evt_count + BLE_HOST_EV_COUNT;
ble_total_evtq_count = g_ctrl_npl_info.evtq_count + BLE_HOST_EVQ_COUNT;
ble_total_co_count = g_ctrl_npl_info.co_count + BLE_HOST_CO_COUNT;
ble_total_sem_count = g_ctrl_npl_info.sem_count + BLE_HOST_SEM_COUNT;
ble_total_mutex_count = g_ctrl_npl_info.mutex_count + BLE_HOST_MUTEX_COUNT;
ble_freertos_total_event_cnt = ble_total_evt_count;
if (ble_total_evt_count) {