2016-11-04 18:48:16 +00:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2016-10-18 13:49:00 +00:00
|
|
|
|
|
|
|
#include "bt_prf_task.h"
|
|
|
|
#include "bt_prf_sys.h"
|
|
|
|
#include "allocator.h"
|
2016-11-04 11:32:47 +00:00
|
|
|
#include "bt_trace.h"
|
2016-10-18 13:49:00 +00:00
|
|
|
#include "thread.h"
|
|
|
|
#include "gki.h"
|
|
|
|
|
|
|
|
//thread_t *bt_workqueue_thread;
|
|
|
|
//static const char *BT_WORKQUEUE_NAME = "bt_workqueue";
|
|
|
|
xTaskHandle xProfileTaskHandle = NULL;
|
|
|
|
xQueueHandle xProfileQueue = 0;
|
|
|
|
|
|
|
|
// Communication queue between bt_proflie_task and app.
|
|
|
|
extern fixed_queue_t *bt_profile_msg_queue;
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
**
|
|
|
|
** Function bt_prf_task_thread_handler
|
|
|
|
**
|
|
|
|
** Description Process profile Task Thread.
|
|
|
|
******************************************************************************/
|
|
|
|
void bt_prf_task_thread_handler(void *arg)
|
|
|
|
{
|
2016-11-05 11:57:53 +00:00
|
|
|
BtTaskEvt_t e;
|
|
|
|
|
2016-11-04 11:32:47 +00:00
|
|
|
for (;;) {
|
2016-10-18 13:49:00 +00:00
|
|
|
if (pdTRUE == xQueueReceive(xProfileQueue, &e, (portTickType)portMAX_DELAY)) {
|
|
|
|
|
2016-11-05 11:57:53 +00:00
|
|
|
if (e.sig == SIG_PRF_WORK) {
|
2016-10-18 13:49:00 +00:00
|
|
|
fixed_queue_process(bt_profile_msg_queue);
|
2016-11-04 11:32:47 +00:00
|
|
|
LOG_ERROR("bt_prf_task_thread_handler\n");
|
2016-10-18 13:49:00 +00:00
|
|
|
}
|
2016-11-05 11:57:53 +00:00
|
|
|
else if (e.sig == SIG_PRF_START_UP) {
|
2016-10-18 13:49:00 +00:00
|
|
|
bt_prf_task_start_up();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bt_prf_task_post(uint32_t sig)
|
2016-10-15 09:46:10 +00:00
|
|
|
{
|
2016-11-05 11:57:53 +00:00
|
|
|
BtTaskEvt_t evt;
|
2016-10-15 09:46:10 +00:00
|
|
|
|
2016-11-05 11:57:53 +00:00
|
|
|
evt.sig = sig;
|
|
|
|
evt.par = 0;
|
2016-10-15 09:46:10 +00:00
|
|
|
|
2016-10-18 13:49:00 +00:00
|
|
|
if (xQueueSend(xProfileQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
|
|
|
|
ets_printf("xProfileQueue failed\n");
|
2016-10-15 09:46:10 +00:00
|
|
|
}
|
2016-10-18 13:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bt_profile_msg_ready(fixed_queue_t *queue) {
|
2016-11-03 08:27:44 +00:00
|
|
|
prf_hdr_evt_t *p_msg;
|
2016-10-12 07:38:26 +00:00
|
|
|
|
|
|
|
while (!fixed_queue_is_empty(queue)) {
|
2016-11-04 11:32:47 +00:00
|
|
|
p_msg = (prf_hdr_evt_t *)fixed_queue_dequeue(queue);
|
2016-10-18 13:49:00 +00:00
|
|
|
if(p_msg != NULL)
|
|
|
|
{
|
|
|
|
bt_prf_sys_event(p_msg);
|
|
|
|
}
|
2016-10-12 07:38:26 +00:00
|
|
|
}
|
2016-10-18 13:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void bt_prf_task_start_up(void)
|
|
|
|
{
|
2016-11-04 11:32:47 +00:00
|
|
|
LOG_ERROR("bt_prf_task_start_up\n");
|
2016-10-18 13:49:00 +00:00
|
|
|
fixed_queue_register_dequeue(bt_profile_msg_queue, bt_profile_msg_ready);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bt_prf_task_shut_down(void)
|
|
|
|
{
|
|
|
|
fixed_queue_unregister_dequeue(bt_profile_msg_queue);
|
|
|
|
|
|
|
|
bt_prf_free_core();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void bt_prf_StartUp(void)
|
|
|
|
{
|
|
|
|
bt_profile_msg_queue = fixed_queue_new(SIZE_MAX);
|
|
|
|
if (bt_profile_msg_queue == NULL)
|
|
|
|
goto error_exit;
|
2016-11-04 11:32:47 +00:00
|
|
|
|
2016-11-05 11:57:53 +00:00
|
|
|
xProfileQueue = xQueueCreate(60, sizeof(BtTaskEvt_t));
|
2016-11-04 11:32:47 +00:00
|
|
|
xTaskCreate(bt_prf_task_thread_handler, "Bt_prf", 4096, NULL, configMAX_PRIORITIES - 1, &xProfileTaskHandle);
|
|
|
|
bt_prf_task_post(SIG_PRF_START_UP);
|
2016-10-18 13:49:00 +00:00
|
|
|
return;
|
|
|
|
|
2016-11-04 11:32:47 +00:00
|
|
|
error_exit:
|
2016-10-18 13:49:00 +00:00
|
|
|
LOG_ERROR("%s Unable to allocate resources for bt_workqueue\n", __func__);
|
|
|
|
bt_prf_ShutDown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void bt_prf_ShutDown(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
bt_prf_task_shut_down();
|
|
|
|
|
|
|
|
//thread_free(bt_workqueue_thread);
|
|
|
|
vTaskDelete(xProfileTaskHandle);
|
|
|
|
vQueueDelete(xProfileQueue);
|
|
|
|
|
|
|
|
bt_profile_msg_queue = NULL;
|
|
|
|
|
|
|
|
// bt_workqueue_thread = NULL;
|
|
|
|
xProfileTaskHandle = NULL;
|
|
|
|
xProfileQueue = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void bt_prf_free_core(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|