蓝牙4.0 BLE协议
BLE协议分层
Application 应用层
int
{
osal_init_system();
return 0;
}
uint8 osal_init_system(void)
{
osal_mem_init(); // 内存初始化
osal_qHead = NULL;
osalTimerInit();
osal_pwrinit();
osalInitTasks();
osal_mem_kick();
return (SUCCESS);
}
OSAL_SimpleBLEPeripheral.c
void osalInitTasks(void)
{
uint8 taskID = 0;
SimpleBLEPeripheral_Init();
}
simpleBLEPeripheral.c
void SimpleBLEPeripheral_Init(uint8 task_id)
{
simple
osal_set_event(simpleBLEPeripheral_TaskID, SBP_START_DEVICE_EVT); //设置任务事件
}
uint16 SimpleBLEPeripheral_ProcessEvent(uint8 task_id, uint16 events)
{
if()
{
if()
{
}
return ();
}
if( events & SBP_START_DEVICE_EVT)
{
VOID GAPRole_StatrtDevice(&simpleBLEPeripheral_PeripheralCBs); //启动设备
VOID GAPBondMgr_Register(&simpleBLEPeripheral_BoodMgrCBs); //
osal_start_timerEx(simpleBLEPeripheral_TsakID,
SBP_PERIODIC_EVT,
SBP_PERIODIC_EVT_PERIOD);
return ( events ^ SBP_START_DEVICE_EVT);
}
}
static gapRolesCBs_t simpleBLEPeripheral_PeripheralCBs=
{
peripheralStateNotificationCB
NULL
}
static void peripheralStateNotificationCB(gaprole_States_t newState)
{
switch(newState)
{
case GAPROLE_STARTED:
{
uint8
}
}
}
peripheral.h
typedef enum
{
GAPROLE_INIT = 0,
GAPROLE_STARTED,
}gaprole_States_t;
//npi.c
void NPI_InitTransport(npi)
{
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE; // 是否配置
uartConfig.baudRate = NPI_UART_BR; // 波特率
uartConfig.flowControl = NPI_UART_FC; // 流控制
uartConfig.flowControlThreshold = NPI_UART_FC_THRESHOLD;
uartConfig.rx.maxBufSize = NPI_UART_RX_BUF_SIZE; // 接收缓存大小
uartConfig.tx.maxBufSize = NPI_UART_TX_BUF_SIZE; // 发送缓存大小
uartConfig.idleTimeout = NPI_UART_IDLE_TIMEOUT; // 超时时间
uartConfig.intEnable = NPI_UART_INT_ENABLE; // 中断使能
uartConfig.callBackFunc = (halUARTCBack_t)npiCBack; // 回调函数
(void)HalUARTOpen(NPI_UART_PORT, &uartConfig); // 串口配置使能
return ;
}
npi.h
#defind NPI_UART_FC_THRESHOLD 48
#defind NPI_UART_RX_BUF_SIZE 128
#defind NPI_UART_TX_BUF_SIZE 128
#defind NPI_UART_IDLE_TIMEOUT 6
#defind NPI_UART_INT_ENABLE TRUE
#if !defind(NPI_UART_BR)
#defined NPI_UART_BR HAL_UART_BR_115200
#endif1