mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
components/bt: Combine A2DP sink task and A2DP source task into btc task
This commit is contained in:
parent
930c304a57
commit
485c896740
@ -55,7 +55,7 @@
|
|||||||
#define BTC_TASK_NAME "btcT"
|
#define BTC_TASK_NAME "btcT"
|
||||||
#define BTC_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 6)
|
#define BTC_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 6)
|
||||||
|
|
||||||
static osi_thread_t *btc_thread;
|
osi_thread_t *btc_thread;
|
||||||
|
|
||||||
static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||||
[BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL },
|
[BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL },
|
||||||
@ -135,7 +135,7 @@ static bt_status_t btc_task_post(btc_msg_t *msg, osi_thread_blocking_t blocking)
|
|||||||
|
|
||||||
memcpy(lmsg, msg, sizeof(btc_msg_t));
|
memcpy(lmsg, msg, sizeof(btc_msg_t));
|
||||||
|
|
||||||
if (osi_thread_post(btc_thread, btc_thread_handler, lmsg, 0, blocking) == false) {
|
if (osi_thread_post(btc_thread, btc_thread_handler, lmsg, 2, blocking) == false) {
|
||||||
return BT_STATUS_BUSY;
|
return BT_STATUS_BUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ static void btc_deinit_mem(void) {
|
|||||||
|
|
||||||
int btc_init(void)
|
int btc_init(void)
|
||||||
{
|
{
|
||||||
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 1);
|
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 3);
|
||||||
if (btc_thread == NULL) {
|
if (btc_thread == NULL) {
|
||||||
return BT_STATUS_NOMEM;
|
return BT_STATUS_NOMEM;
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@ void btc_deinit(void)
|
|||||||
|
|
||||||
bool btc_check_queue_is_congest(void)
|
bool btc_check_queue_is_congest(void)
|
||||||
{
|
{
|
||||||
if (osi_thread_queue_wait_size(btc_thread, 0) >= QUEUE_CONGEST_SIZE) {
|
if (osi_thread_queue_wait_size(btc_thread, 2) >= QUEUE_CONGEST_SIZE) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,12 +45,7 @@
|
|||||||
|
|
||||||
#if (BTC_AV_SINK_INCLUDED == TRUE)
|
#if (BTC_AV_SINK_INCLUDED == TRUE)
|
||||||
|
|
||||||
/* Macro */
|
extern osi_thread_t *btc_thread;
|
||||||
#define BTC_A2DP_SINK_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
|
|
||||||
#define BTC_A2DP_SINK_TASK_STACK_SIZE (A2DP_SINK_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) // by menuconfig
|
|
||||||
#define BTC_A2DP_SINK_TASK_NAME "BtA2dSinkT"
|
|
||||||
#define BTC_A2DP_SINK_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 3)
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
** Constants
|
** Constants
|
||||||
@ -242,10 +237,7 @@ bool btc_a2dp_sink_startup(void)
|
|||||||
|
|
||||||
APPL_TRACE_EVENT("## A2DP SINK START MEDIA THREAD ##");
|
APPL_TRACE_EVENT("## A2DP SINK START MEDIA THREAD ##");
|
||||||
|
|
||||||
a2dp_sink_local_param.btc_aa_snk_task_hdl = osi_thread_create(BTC_A2DP_SINK_TASK_NAME, BTC_A2DP_SINK_TASK_STACK_SIZE, BTC_A2DP_SINK_TASK_PRIO, BTC_A2DP_SINK_TASK_PINNED_TO_CORE, 2);
|
a2dp_sink_local_param.btc_aa_snk_task_hdl = btc_thread;
|
||||||
if (a2dp_sink_local_param.btc_aa_snk_task_hdl == NULL) {
|
|
||||||
goto error_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_INIT, NULL) == false) {
|
if (btc_a2dp_sink_ctrl_post(BTC_MEDIA_TASK_SINK_INIT, NULL) == false) {
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
@ -257,10 +249,7 @@ bool btc_a2dp_sink_startup(void)
|
|||||||
|
|
||||||
error_exit:;
|
error_exit:;
|
||||||
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__);
|
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__);
|
||||||
if (a2dp_sink_local_param.btc_aa_snk_task_hdl != NULL) {
|
a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL;
|
||||||
osi_thread_free(a2dp_sink_local_param.btc_aa_snk_task_hdl);
|
|
||||||
a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if A2D_DYNAMIC_MEMORY == TRUE
|
#if A2D_DYNAMIC_MEMORY == TRUE
|
||||||
osi_free(a2dp_sink_local_param_ptr);
|
osi_free(a2dp_sink_local_param_ptr);
|
||||||
@ -282,7 +271,6 @@ void btc_a2dp_sink_shutdown(void)
|
|||||||
future_await(a2dp_sink_local_param.btc_a2dp_sink_future);
|
future_await(a2dp_sink_local_param.btc_a2dp_sink_future);
|
||||||
a2dp_sink_local_param.btc_a2dp_sink_future = NULL;
|
a2dp_sink_local_param.btc_a2dp_sink_future = NULL;
|
||||||
|
|
||||||
osi_thread_free(a2dp_sink_local_param.btc_aa_snk_task_hdl);
|
|
||||||
a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL;
|
a2dp_sink_local_param.btc_aa_snk_task_hdl = NULL;
|
||||||
|
|
||||||
#if A2D_DYNAMIC_MEMORY == TRUE
|
#if A2D_DYNAMIC_MEMORY == TRUE
|
||||||
|
@ -50,12 +50,7 @@
|
|||||||
|
|
||||||
#if BTC_AV_SRC_INCLUDED
|
#if BTC_AV_SRC_INCLUDED
|
||||||
|
|
||||||
/* Macro */
|
extern osi_thread_t *btc_thread;
|
||||||
#define BTC_A2DP_SOURCE_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
|
|
||||||
#define BTC_A2DP_SOURCE_TASK_STACK_SIZE (A2DP_SOURCE_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) // by menuconfig
|
|
||||||
#define BTC_A2DP_SOURCE_TASK_NAME "BtA2dSourceT"
|
|
||||||
#define BTC_A2DP_SOURCE_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 3)
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
** Constants
|
** Constants
|
||||||
@ -243,18 +238,18 @@ bool btc_a2dp_source_is_task_shutting_down(void)
|
|||||||
return btc_a2dp_source_state == BTC_A2DP_SOURCE_STATE_SHUTTING_DOWN;
|
return btc_a2dp_source_state == BTC_A2DP_SOURCE_STATE_SHUTTING_DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btc_a2dp_source_ctrl_post(uint32_t sig, void *param)
|
static bool btc_a2dp_source_ctrl_post(uint32_t sig, void *param)
|
||||||
{
|
{
|
||||||
a2dp_src_task_evt_t *evt = (a2dp_src_task_evt_t *)osi_malloc(sizeof(a2dp_src_task_evt_t));
|
a2dp_src_task_evt_t *evt = (a2dp_src_task_evt_t *)osi_malloc(sizeof(a2dp_src_task_evt_t));
|
||||||
|
|
||||||
if (evt == NULL) {
|
if (evt == NULL) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
evt->sig = sig;
|
evt->sig = sig;
|
||||||
evt->param = param;
|
evt->param = param;
|
||||||
|
|
||||||
osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_ctrl_handler, evt, 0, OSI_THREAD_BLOCKING);
|
return osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_ctrl_handler, evt, 0, OSI_THREAD_BLOCKING);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btc_a2dp_source_ctrl_handler(void *arg)
|
static void btc_a2dp_source_ctrl_handler(void *arg)
|
||||||
@ -318,19 +313,18 @@ bool btc_a2dp_source_startup(void)
|
|||||||
|
|
||||||
APPL_TRACE_EVENT("## A2DP SOURCE START MEDIA THREAD ##");
|
APPL_TRACE_EVENT("## A2DP SOURCE START MEDIA THREAD ##");
|
||||||
|
|
||||||
a2dp_source_local_param.btc_aa_src_task_hdl = osi_thread_create(BTC_A2DP_SOURCE_TASK_NAME, BTC_A2DP_SOURCE_TASK_STACK_SIZE, BTC_A2DP_SOURCE_TASK_PRIO, BTC_A2DP_SOURCE_TASK_PINNED_TO_CORE, 2);
|
a2dp_source_local_param.btc_aa_src_task_hdl = btc_thread;
|
||||||
if (a2dp_source_local_param.btc_aa_src_task_hdl == NULL) {
|
|
||||||
|
if (btc_a2dp_source_ctrl_post(BTC_MEDIA_TASK_INIT, NULL) == false) {
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
btc_a2dp_source_ctrl_post(BTC_MEDIA_TASK_INIT, NULL);
|
|
||||||
APPL_TRACE_EVENT("## A2DP SOURCE MEDIA THREAD STARTED ##\n");
|
APPL_TRACE_EVENT("## A2DP SOURCE MEDIA THREAD STARTED ##\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error_exit:;
|
error_exit:;
|
||||||
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__);
|
APPL_TRACE_ERROR("%s unable to start up media thread\n", __func__);
|
||||||
osi_thread_free(a2dp_source_local_param.btc_aa_src_task_hdl);
|
|
||||||
a2dp_source_local_param.btc_aa_src_task_hdl = NULL;
|
a2dp_source_local_param.btc_aa_src_task_hdl = NULL;
|
||||||
|
|
||||||
#if A2D_DYNAMIC_MEMORY == TRUE
|
#if A2D_DYNAMIC_MEMORY == TRUE
|
||||||
@ -353,7 +347,6 @@ void btc_a2dp_source_shutdown(void)
|
|||||||
future_await(a2dp_source_local_param.btc_a2dp_source_future);
|
future_await(a2dp_source_local_param.btc_a2dp_source_future);
|
||||||
a2dp_source_local_param.btc_a2dp_source_future = NULL;
|
a2dp_source_local_param.btc_a2dp_source_future = NULL;
|
||||||
|
|
||||||
osi_thread_free(a2dp_source_local_param.btc_aa_src_task_hdl);
|
|
||||||
a2dp_source_local_param.btc_aa_src_task_hdl = NULL;
|
a2dp_source_local_param.btc_aa_src_task_hdl = NULL;
|
||||||
|
|
||||||
#if A2D_DYNAMIC_MEMORY == TRUE
|
#if A2D_DYNAMIC_MEMORY == TRUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user