component/bt : cleanup task evt

This commit is contained in:
Tian Hao 2016-11-05 19:57:53 +08:00
parent 5c3ce5b269
commit 084248e211
7 changed files with 51 additions and 75 deletions

View file

@ -91,13 +91,14 @@ static void hci_hal_env_deinit(void) {
fixed_queue_free(hci_hal_env.rx_q, hci_hal_env.allocator->free); fixed_queue_free(hci_hal_env.rx_q, hci_hal_env.allocator->free);
} }
static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) { static bool hal_open(const hci_hal_callbacks_t *upper_callbacks)
{
assert(upper_callbacks != NULL); assert(upper_callbacks != NULL);
callbacks = upper_callbacks; callbacks = upper_callbacks;
hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX); hci_hal_env_init(HCI_HAL_SERIAL_BUFFER_SIZE, SIZE_MAX);
xHciH4Queue = xQueueCreate(60, sizeof(void *)); xHciH4Queue = xQueueCreate(60, sizeof(BtTaskEvt_t));
xTaskCreate(hci_hal_h4_rx_handler, "HciH4T", 4096+2048, NULL, configMAX_PRIORITIES - 3, &xHciH4TaskHandle); xTaskCreate(hci_hal_h4_rx_handler, "HciH4T", 4096+2048, NULL, configMAX_PRIORITIES - 3, &xHciH4TaskHandle);
//register vhci host cb //register vhci host cb
@ -105,10 +106,6 @@ static bool hal_open(const hci_hal_callbacks_t *upper_callbacks) {
return true; return true;
error:
interface.close();
return false;
} }
static void hal_close() { static void hal_close() {
@ -156,27 +153,25 @@ static uint16_t transmit_data(serial_data_type_t type,
} }
// Internal functions // Internal functions
static void hci_hal_h4_rx_handler(void *arg) { static void hci_hal_h4_rx_handler(void *arg)
BtTaskEvt_t *e; {
BtTaskEvt_t e;
for (;;) { for (;;) {
if (pdTRUE == xQueueReceive(xHciH4Queue, &e, (portTickType)portMAX_DELAY)) { if (pdTRUE == xQueueReceive(xHciH4Queue, &e, (portTickType)portMAX_DELAY)) {
if (e->sig == 0xff) { if (e.sig == 0xff) {
fixed_queue_process(hci_hal_env.rx_q); fixed_queue_process(hci_hal_env.rx_q);
} }
osi_free(e);
} }
} }
} }
void hci_hal_h4_task_post(void) void hci_hal_h4_task_post(void)
{ {
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); BtTaskEvt_t evt;
if (evt == NULL)
return;
evt->sig = 0xff; evt.sig = 0xff;
evt->par = 0; evt.par = 0;
if (xQueueSend(xHciH4Queue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { if (xQueueSend(xHciH4Queue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
LOG_ERROR("xHciH4Queue failed\n"); LOG_ERROR("xHciH4Queue failed\n");

View file

@ -111,7 +111,7 @@ int hci_start_up(void) {
if (hci_layer_init_env()) if (hci_layer_init_env())
goto error; goto error;
xHciHostQueue = xQueueCreate(60, sizeof(void *)); xHciHostQueue = xQueueCreate(60, sizeof(BtTaskEvt_t));
xTaskCreate(hci_host_thread_handler, "HciHostT", (4096+2048), NULL, configMAX_PRIORITIES - 3, &xHciHostTaskHandle); xTaskCreate(hci_host_thread_handler, "HciHostT", (4096+2048), NULL, configMAX_PRIORITIES - 3, &xHciHostTaskHandle);
packet_fragmenter->init(&packet_fragmenter_callbacks); packet_fragmenter->init(&packet_fragmenter_callbacks);
@ -139,15 +139,13 @@ void hci_shut_down(void) {
void hci_host_task_post(void) void hci_host_task_post(void)
{ {
BtTaskEvt_t evt;
if (hci_host_startup_flag == false) if (hci_host_startup_flag == false)
return; return;
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); evt.sig = 0xff;
if (evt == NULL) evt.par = 0;
return;
evt->sig = 0xff;
evt->par = 0;
if (xQueueSend(xHciHostQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { if (xQueueSend(xHciHostQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
LOG_ERROR("xHciHostQueue failed\n"); LOG_ERROR("xHciHostQueue failed\n");
@ -223,12 +221,12 @@ static void hci_host_thread_handler(void *arg)
* H4 type header added (1 byte). * H4 type header added (1 byte).
*/ */
BtTaskEvt_t *e; BtTaskEvt_t e;
for (;;) { for (;;) {
if (pdTRUE == xQueueReceive(xHciHostQueue, &e, (portTickType)portMAX_DELAY)) { if (pdTRUE == xQueueReceive(xHciHostQueue, &e, (portTickType)portMAX_DELAY)) {
if (e->sig == 0xff) { if (e.sig == 0xff) {
if (API_vhci_host_check_send_available()) { if (API_vhci_host_check_send_available()) {
/*Now Target only allowed one packet per TX*/ /*Now Target only allowed one packet per TX*/
BT_HDR *pkt = packet_fragmenter->fragment_current_packet(); BT_HDR *pkt = packet_fragmenter->fragment_current_packet();
@ -243,7 +241,6 @@ static void hci_host_thread_handler(void *arg)
} }
} }
} }
osi_free(e);
} }
} }
} }

View file

@ -36,31 +36,28 @@
******************************************************************************/ ******************************************************************************/
void bt_prf_task_thread_handler(void *arg) void bt_prf_task_thread_handler(void *arg)
{ {
BtTaskEvt_t e;
BtTaskEvt_t *e;
for (;;) { for (;;) {
if (pdTRUE == xQueueReceive(xProfileQueue, &e, (portTickType)portMAX_DELAY)) { if (pdTRUE == xQueueReceive(xProfileQueue, &e, (portTickType)portMAX_DELAY)) {
if (e->sig == SIG_PRF_WORK) { if (e.sig == SIG_PRF_WORK) {
fixed_queue_process(bt_profile_msg_queue); fixed_queue_process(bt_profile_msg_queue);
LOG_ERROR("bt_prf_task_thread_handler\n"); LOG_ERROR("bt_prf_task_thread_handler\n");
} }
else if (e->sig == SIG_PRF_START_UP) { else if (e.sig == SIG_PRF_START_UP) {
bt_prf_task_start_up(); bt_prf_task_start_up();
} }
osi_free(e);
} }
} }
} }
void bt_prf_task_post(uint32_t sig) void bt_prf_task_post(uint32_t sig)
{ {
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); BtTaskEvt_t evt;
if (evt == NULL)
return;
evt->sig = sig; evt.sig = sig;
evt->par = 0; evt.par = 0;
if (xQueueSend(xProfileQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { if (xQueueSend(xProfileQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
ets_printf("xProfileQueue failed\n"); ets_printf("xProfileQueue failed\n");
@ -100,7 +97,7 @@ void bt_prf_StartUp(void)
if (bt_profile_msg_queue == NULL) if (bt_profile_msg_queue == NULL)
goto error_exit; goto error_exit;
xProfileQueue = xQueueCreate(60, sizeof(void *)); xProfileQueue = xQueueCreate(60, sizeof(BtTaskEvt_t));
xTaskCreate(bt_prf_task_thread_handler, "Bt_prf", 4096, NULL, configMAX_PRIORITIES - 1, &xProfileTaskHandle); xTaskCreate(bt_prf_task_thread_handler, "Bt_prf", 4096, NULL, configMAX_PRIORITIES - 1, &xProfileTaskHandle);
bt_prf_task_post(SIG_PRF_START_UP); bt_prf_task_post(SIG_PRF_START_UP);
return; return;

View file

@ -193,7 +193,7 @@ void BTU_StartUp(void)
if (btu_l2cap_alarm_queue == NULL) if (btu_l2cap_alarm_queue == NULL)
goto error_exit; goto error_exit;
xBtuQueue = xQueueCreate(60, sizeof(void *)); xBtuQueue = xQueueCreate(60, sizeof(BtTaskEvt_t));
xTaskCreate(btu_task_thread_handler, "BtuT", 8192, NULL, configMAX_PRIORITIES - 1, &xBtuTaskHandle); xTaskCreate(btu_task_thread_handler, "BtuT", 8192, NULL, configMAX_PRIORITIES - 1, &xBtuTaskHandle);
btu_task_post(SIG_BTU_START_UP); btu_task_post(SIG_BTU_START_UP);
/* /*

View file

@ -304,14 +304,12 @@ static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle) {
******************************************************************************/ ******************************************************************************/
void btu_task_thread_handler(void *arg) void btu_task_thread_handler(void *arg)
{ {
//ke_event_clear(KE_EVENT_BTU_TASK_THREAD); BtTaskEvt_t e;
BtTaskEvt_t *e;
for (;;) { for (;;) {
if (pdTRUE == xQueueReceive(xBtuQueue, &e, (portTickType)portMAX_DELAY)) { if (pdTRUE == xQueueReceive(xBtuQueue, &e, (portTickType)portMAX_DELAY)) {
if (e->sig == SIG_BTU_WORK) { if (e.sig == SIG_BTU_WORK) {
fixed_queue_process(btu_hci_msg_queue); fixed_queue_process(btu_hci_msg_queue);
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE) #if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
fixed_queue_process(btu_bta_msg_queue); fixed_queue_process(btu_bta_msg_queue);
@ -321,10 +319,9 @@ void btu_task_thread_handler(void *arg)
fixed_queue_process(btu_oneshot_alarm_queue); fixed_queue_process(btu_oneshot_alarm_queue);
fixed_queue_process(btu_l2cap_alarm_queue); fixed_queue_process(btu_l2cap_alarm_queue);
} }
else if (e->sig == SIG_BTU_START_UP) { else if (e.sig == SIG_BTU_START_UP) {
btu_task_start_up(); btu_task_start_up();
} }
osi_free(e);
} }
} }
} }
@ -332,12 +329,10 @@ void btu_task_thread_handler(void *arg)
void btu_task_post(uint32_t sig) void btu_task_post(uint32_t sig)
{ {
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); BtTaskEvt_t evt;
if (evt == NULL)
return;
evt->sig = sig; evt.sig = sig;
evt->par = 0; evt.par = 0;
if (xQueueSend(xBtuQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { if (xQueueSend(xBtuQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
LOG_ERROR("xBtuQueue failed\n"); LOG_ERROR("xBtuQueue failed\n");

View file

@ -73,18 +73,18 @@ extern void ble_server_test(void);
static void bt_app_task_handler(void *arg) static void bt_app_task_handler(void *arg)
{ {
BtTaskEvt_t *e; BtTaskEvt_t e;
UINT8 button_msg[2] = {0x01,0x00}; UINT8 button_msg[2] = {0x01,0x00};
for (;;) { for (;;) {
if (pdTRUE == xQueueReceive(xBtaApp1Queue, &e, (portTickType)portMAX_DELAY)) { if (pdTRUE == xQueueReceive(xBtaApp1Queue, &e, (portTickType)portMAX_DELAY)) {
if (e->sig == 0xff) { if (e.sig == 0xff) {
fixed_queue_process(bta_app_msg_queue); fixed_queue_process(bta_app_msg_queue);
fixed_queue_process(bt_app_general_alarm_queue); fixed_queue_process(bt_app_general_alarm_queue);
} }
#if (BUT_PROFILE_CFG) #if (BUT_PROFILE_CFG)
// else if(e->sig == BUTTON_PRESS_EVT){ // else if(e.sig == BUTTON_PRESS_EVT){
// LOG_ERROR("button_press_event come in,button_value=%x\n",e->par); // LOG_ERROR("button_press_event come in,button_value=%x\n",e.par);
// button_msg[1] = e->par; // button_msg[1] = e.par;
// button_msg_notify(2,button_msg); // button_msg_notify(2,button_msg);
@ -92,19 +92,15 @@ static void bt_app_task_handler(void *arg)
#endif ///BUT_PROFILE_CFG #endif ///BUT_PROFILE_CFG
} }
osi_free(e);
} }
} }
static void bt_app_task_post(void) static void bt_app_task_post(void)
{ {
BtTaskEvt_t evt;
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); evt.sig = 0xff;
if (evt == NULL) evt.par = 0;
return;
evt->sig = 0xff;
evt->par = 0;
if (xQueueSend(xBtaApp1Queue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { if (xQueueSend(xBtaApp1Queue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
ets_printf("btdm_post failed\n"); ets_printf("btdm_post failed\n");
@ -188,7 +184,7 @@ void bt_app_task_start_up(void)
goto error_exit; goto error_exit;
//ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler); //ke_event_callback_set(KE_EVENT_BT_APP_TASK, &bt_app_task_handler);
xBtaApp1Queue = xQueueCreate(3, sizeof(void *)); xBtaApp1Queue = xQueueCreate(3, sizeof(BtTaskEvt_t));
xTaskCreate(bt_app_task_handler, "BtaApp1T", 8192, NULL, configMAX_PRIORITIES - 3, xBtaApp1TaskHandle); xTaskCreate(bt_app_task_handler, "BtaApp1T", 8192, NULL, configMAX_PRIORITIES - 3, xBtaApp1TaskHandle);
fixed_queue_register_dequeue(bta_app_msg_queue, bta_app_msg_ready); fixed_queue_register_dequeue(bta_app_msg_queue, bta_app_msg_ready);

View file

@ -43,35 +43,31 @@ extern void ble_server_test(void);
static void blufi_task(void *arg) static void blufi_task(void *arg)
{ {
BtTaskEvt_t *e; BtTaskEvt_t e;
for (;;) { for (;;) {
if (pdTRUE == xQueueReceive(xBlufiTaskQueue, &e, (portTickType)portMAX_DELAY)) { if (pdTRUE == xQueueReceive(xBlufiTaskQueue, &e, (portTickType)portMAX_DELAY)) {
switch (e->sig) { switch (e.sig) {
case BLUFI_SIG_SWITCH_CONTEXT: case BLUFI_SIG_SWITCH_CONTEXT:
if (e->cb) { if (e.cb) {
((BtTaskCb_t)e->cb)(e->arg); ((BtTaskCb_t)e.cb)(e.arg);
} }
break; break;
default: default:
break; break;
} }
osi_free(e);
} }
} }
} }
static int blufi_task_post(uint32_t sig, void *par, void *cb, void *arg) static int blufi_task_post(uint32_t sig, void *par, void *cb, void *arg)
{ {
BtTaskEvt_t evt;
BtTaskEvt_t *evt = (BtTaskEvt_t *)osi_malloc(sizeof(BtTaskEvt_t)); evt.sig = sig;
if (evt == NULL) evt.par = par;
return -1; evt.cb = cb;
evt.arg = arg;
evt->sig = sig;
evt->par = par;
evt->cb = cb;
evt->arg = arg;
if (xQueueSend(xBlufiTaskQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) { if (xQueueSend(xBlufiTaskQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
LOG_ERROR("Blufi Post failed\n"); LOG_ERROR("Blufi Post failed\n");
@ -97,7 +93,7 @@ static void blufi_task_deinit(void)
static void blufi_task_init(void) static void blufi_task_init(void)
{ {
xBlufiTaskQueue = xQueueCreate(10, sizeof(void *)); xBlufiTaskQueue = xQueueCreate(10, sizeof(BtTaskEvt_t));
xTaskCreate(blufi_task, "BlUFI", 8192, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle); xTaskCreate(blufi_task, "BlUFI", 8192, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle);
} }