commponent bt:1.added the bt_prf_sys_main.c file which has been process the profile task event method;

2.modified the thread.h file==> added the profile task event in it
	      3.modified bt_prf_task.c==>added the ready function in it
	      4.added the bt_prf_sys.h file
	      5.remove the profile_sys.h file
This commit is contained in:
yulong 2016-10-13 09:13:21 -04:00
parent 65445b21dd
commit af9b08d863
7 changed files with 267 additions and 36 deletions

View file

@ -224,7 +224,7 @@ BOOLEAN bta_sys_sm_execute(BT_HDR *p_msg)
UINT8 action;
int i;
APPL_TRACE_EVENT("bta_sys_sm_execute state:%d, event:0x%x", bta_sys_cb.state, p_msg->event);
APPL_TRACE_EVENT("bta_sys_sm_execute state:%d, event:0x%x\n", bta_sys_cb.state, p_msg->event);
/* look up the state table for the current state */
state_table = bta_sys_st_tbl[bta_sys_cb.state];

View file

@ -16,6 +16,8 @@ struct task_evt {
typedef struct task_evt TaskEvt_t;
enum {
SIG_PRF_START_UP = 0xfc,
SIG_PRF_WORK = 0xfd,
SIG_BTU_START_UP = 0xfe,
SIG_BTU_WORK = 0xff
};

View file

@ -0,0 +1,154 @@
/**
****************************************************************************************
*
* @file bt_prf_sys_main.c
*
* @brief Application entry point
*
* Copyright (C) Espressif 2016
* Created by Yulong at 2016/10/13
*
*
****************************************************************************************
*/
#include "thread.h"
#include "bt_prf_sys.h"
#include "fixed_queue.h"
#include "bt_prf_task.h"
#include "gki.h"
#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)
{
memset(&bt_prf_sys_cb,0,sizeof(tBT_PRF_SYS_CB));
}
/*******************************************************************************
**
** Function bt_prf_sys_event
**
** Description profile task event handler; called from task event handler.
**
**
** Returns void
**
*******************************************************************************/
void bt_prf_sys_event(BT_HDR *p_msg)
{
UINT8 id;
BOOLEAN freebuf = TRUE;
APPL_TRACE_EVENT("profile task got event 0x%x\n", p_msg->event);
/* 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
{
APPL_TRACE_WARNING("profile task got unregistered event id %d\n", id);
}
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)
{
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
**
** Description Send a GKI message to the profile task.
**
**
** 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
// message queue. This causes |btu_bta_msg_queue| to get cleaned up before
// 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);
}
}

View file

@ -13,6 +13,7 @@
*/
#include "bt_prf_task.h"
#include "bt_prf_sys.h"
#include "allocator.h"
#include "thread.h"
#include "gki.h"
@ -37,12 +38,12 @@
//ke_event_clear(KE_EVENT_BTU_TASK_THREAD);
TaskEvt_t *e;
for (;;) {
if (pdTRUE == xQueueReceive(xProfileQueue, &e, (portTickType)portMAX_DELAY)) {
if (e->sig == SIG_BTU_WORK) {
fixed_queue_process(bt_profile_msg_queue);
fixed_queue_process(bt_profile_msg_queue);
}
else if (e->sig == SIG_BTU_START_UP) {
bt_prf_task_start_up();
@ -52,11 +53,29 @@
}
}
void bt_prf_task_post(uint32_t sig)
{
TaskEvt_t *evt = (TaskEvt_t *)osi_malloc(sizeof(TaskEvt_t));
if (evt == NULL)
return;
evt->sig = sig;
evt->par = 0;
if (xQueueSend(xProfileQueue, &evt, 10/portTICK_RATE_MS) != pdTRUE) {
ets_printf("xProfileQueue failed\n");
}
}
void bt_profile_msg_ready(fixed_queue_t *queue) {
BT_HDR *p_msg;
while (!fixed_queue_is_empty(queue)) {
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
if(p_msg != NULL)
{
bt_prf_sys_event(p_msg);
}
}
}

View file

@ -0,0 +1,86 @@
/**
****************************************************************************************
*
* @file bt_prf_sys.h
*
* @brief Application entry point
*
* Copyright (C) Espressif 2016
* Created by Yulong at 2016/10/12
*
*
****************************************************************************************
*/
#ifndef _PROFILE_SYS_H__
#define _PROFILE_SYS_H__
#include "bt_types.h"
enum
{
PRF_ID_SYS,
PRF_ID_CONN,
PRF_ID_HIDD_LE,
PRF_ID_HIDH_LE,
PRF_ID_DISS_LE,
PRF_ID_DISC_LE,
PRF_ID_AIRSYNC_LE,
PRF_ID_ANCC_LE,
PRF_ID_BUT_LE,
PRF_ID_MAX
};
typedef UINT8 tBT_PRF_SYS_CONN_STATUS;
/* disable function type */
typedef void (tBT_PRF_SYS_DISABLE)(void);
/* event handler function type */
typedef BOOLEAN (tBT_PRF_SYS_EVT_HDLR)(BT_HDR *p_msg);
/* conn callback for role / low power manager*/
typedef void (tBT_PRF_SYS_CONN_CBACK)(tBT_PRF_SYS_CONN_STATUS status,
UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
/* Calculate start of event enumeration; id is top 8 bits of event */
#define BT_PRF_SYS_EVT_START(id) ((id) << 8)
/* registration structure */
typedef struct
{
tBT_PRF_SYS_EVT_HDLR *evt_hdlr;
tBT_PRF_SYS_DISABLE *disable;
} tBT_PRF_SYS_REG;
/* system manager control block */
typedef struct
{
tBT_PRF_SYS_REG *reg[PRF_ID_MAX]; /* registration structures */
BOOLEAN is_reg[PRF_ID_MAX]; /* registration structures */
tBT_PRF_SYS_CONN_CBACK *prm_cb; /* role management callback registered by DM */
tBT_PRF_SYS_CONN_CBACK *ppm_cb; /* low power management callback registered by DM */
tBT_PRF_SYS_CONN_CBACK *p_policy_cb; /* link policy change callback registered by DM */
} tBT_PRF_SYS_CB;
extern tBT_PRF_SYS_CB bt_prf_sys_cb;
extern void bt_prf_sys_init(void);
extern void bt_prf_sys_free(void);
extern void bt_prf_sys_event(BT_HDR *p_msg);
extern void bt_prf_sys_register(UINT8 id, const tBT_PRF_SYS_REG *p_reg);
extern void bt_prf_sys_deregister(UINT8 id);
extern BOOLEAN bt_prf_sys_is_register(UINT8 id);
extern void bt_prf_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
extern void bt_prf_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
#endif ///_PROFILE_SYS_H__

View file

@ -29,6 +29,9 @@ void bt_prf_task_thread_handler(void *arg);
void bt_prf_init_core(void);
void bt_prf_free_core(void);
void bt_prf_task_post(uint32_t sig);
void bt_prf_StartUp(void);
void bt_prf_ShutDown(void);

View file

@ -1,33 +0,0 @@
/**
****************************************************************************************
*
* @file profile_sys.h
*
* @brief Application entry point
*
* Copyright (C) Espressif 2016
* Created by Yulong at 2016/10/12
*
*
****************************************************************************************
*/
#ifndef _PROFILE_SYS_H__
#define _PROFILE_SYS_H__
enum
{
PRF_ID_SYS,
PRF_ID_CONN,
PRF_ID_HIDD_LE,
PRF_ID_HIDH_LE,
PRF_ID_DISS_LE,
PRF_ID_DISC_LE,
PRF_ID_AIRSYNC_LE,
PRF_ID_ANCC_LE,
PRF_ID_BUT_LE
};
#endif ///_PROFILE_SYS_H__