2016-10-18 13:49:00 +00:00
|
|
|
|
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 "thread.h"
|
|
|
|
#include "bt_prf_sys.h"
|
|
|
|
#include "fixed_queue.h"
|
|
|
|
#include "bt_prf_task.h"
|
|
|
|
#include "gki.h"
|
2016-11-04 11:32:47 +00:00
|
|
|
#include "bt_trace.h"
|
2016-10-18 13:49:00 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
tBT_PRF_SYS_CB bt_prf_sys_cb;
|
|
|
|
fixed_queue_t *bt_profile_msg_queue;
|
|
|
|
|
|
|
|
|
|
|
|
static const tBT_PRF_SYS_REG bt_prf_sys_reg =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void bt_prf_sys_init(void)
|
|
|
|
{
|
2016-11-04 11:32:47 +00:00
|
|
|
LOG_ERROR("bt_prf_sys_init\n");
|
|
|
|
memset(&bt_prf_sys_cb, 0, sizeof(tBT_PRF_SYS_CB));
|
|
|
|
bt_prf_StartUp();
|
2016-10-18 13:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bt_prf_sys_event
|
|
|
|
**
|
|
|
|
** Description profile task event handler; called from task event handler.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2016-11-04 11:32:47 +00:00
|
|
|
void bt_prf_sys_event(prf_hdr_evt_t *p_msg)
|
2016-10-18 13:49:00 +00:00
|
|
|
{
|
|
|
|
UINT8 id;
|
|
|
|
BOOLEAN freebuf = TRUE;
|
|
|
|
|
2016-11-04 11:32:47 +00:00
|
|
|
LOG_ERROR("profile task got event 0x%x\n", p_msg->event);
|
2016-10-18 13:49:00 +00:00
|
|
|
|
|
|
|
/* get subsystem id from event */
|
|
|
|
id = (UINT8) (p_msg->event >> 8);
|
|
|
|
|
|
|
|
/* verify id and call subsystem event handler */
|
|
|
|
if ((id < PRF_ID_MAX) && (bt_prf_sys_cb.reg[id] != NULL))
|
|
|
|
{
|
|
|
|
freebuf = (*bt_prf_sys_cb.reg[id]->evt_hdlr)(p_msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-04 11:32:47 +00:00
|
|
|
LOG_ERROR("profile task got unregistered event id %d\n", id);
|
2016-10-18 13:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (freebuf)
|
|
|
|
{
|
|
|
|
GKI_freebuf(p_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bt_prf_sys_register
|
|
|
|
**
|
|
|
|
** Description Called by other profile subsystems to register their event
|
|
|
|
** handler.
|
|
|
|
**
|
|
|
|
** Parameters id:the Identifiers index of the profile
|
|
|
|
** p_reg:the callback event which has been register to the profile task
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bt_prf_sys_register(UINT8 id, const tBT_PRF_SYS_REG *p_reg)
|
|
|
|
{
|
|
|
|
bt_prf_sys_cb.reg[id] = (tBT_PRF_SYS_REG *) p_reg;
|
|
|
|
bt_prf_sys_cb.is_reg[id] = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bt_prf_sys_deregister
|
|
|
|
**
|
|
|
|
** Description Called by other profile subsystems to de-register
|
|
|
|
** handler.
|
|
|
|
**
|
|
|
|
** Parameters id:Identifiers index of the profile
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bt_prf_sys_deregister(UINT8 id)
|
|
|
|
{
|
2016-11-04 11:32:47 +00:00
|
|
|
bt_prf_sys_cb.reg[id] = NULL;
|
2016-10-18 13:49:00 +00:00
|
|
|
bt_prf_sys_cb.is_reg[id] = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bt_prf_sys_is_register
|
|
|
|
**
|
|
|
|
** Description Called by other profile subsystems to get registeration
|
|
|
|
** status.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN bt_prf_sys_is_register(UINT8 id)
|
|
|
|
{
|
|
|
|
return bt_prf_sys_cb.is_reg[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bt_prf_sys_sendmsg
|
|
|
|
**
|
2016-11-04 11:32:47 +00:00
|
|
|
** Description Send a message to the profile task.
|
2016-10-18 13:49:00 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bt_prf_sys_sendmsg(void *p_msg)
|
|
|
|
{
|
|
|
|
// There is a race condition that occurs if the stack is shut down while
|
|
|
|
// there is a procedure in progress that can schedule a task via this
|
2016-11-04 11:32:47 +00:00
|
|
|
// message queue. This causes |bt_profile_msg_queue| to get cleaned up before
|
2016-10-18 13:49:00 +00:00
|
|
|
// it gets used here; hence we check for NULL before using it.
|
|
|
|
if (bt_profile_msg_queue) {
|
|
|
|
fixed_queue_enqueue(bt_profile_msg_queue, p_msg);
|
|
|
|
|
|
|
|
bt_prf_task_post(SIG_PRF_WORK);
|
|
|
|
}
|
|
|
|
}
|