|
从机广播使用Simple GATT Profile关闭广播后无法进入PM3
[复制链接]
如题,启动后广播30s然后关闭广播,只能进入PM2,电流还有150uA左右,请问还有什么事件没关闭吗?另外连接时功耗500uA左右,用官网的keyfobdemo连接时能做到10uA以下,源码如下:
- //从机初始化
- void SimpleBLEPeripheral_Init( uint8 task_id )
- {
- simpleBLETaskId = task_id;
-
- // 设置GAP
- VOID GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL );
- // 设置GAP外围设备
- {
- uint8 initial_advertising_enable = TRUE;//开启广播
- uint16 gapRole_AdvertOffTime = 0;
- uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;
- uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
- uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
- uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY;
- uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT;
- // Set the GAP Role Parameters
- GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );//广播开启
- GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime );
- #if 0
- GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData );
- #else
- {
- uint8 AttDeviceNameLen = osal_strlen((char*)simpleBle_GetAttDeviceName());
- uint8 pSscanRspDataLen = ( 11 + AttDeviceNameLen);
- uint8 *pSscanRspData = osal_mem_alloc(pSscanRspDataLen);
- if(pSscanRspData)
- {
- uint8 index = 0;
- pSscanRspData[0] = AttDeviceNameLen + 1;
- pSscanRspData[1] = GAP_ADTYPE_LOCAL_NAME_COMPLETE;
- osal_memcpy(&pSscanRspData[2], simpleBle_GetAttDeviceName(), AttDeviceNameLen);//设备名
-
- index = 2 + AttDeviceNameLen;
-
- pSscanRspData[index+0] = 0x05;
- pSscanRspData[index+1] = GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE;
- pSscanRspData[index+2] = LO_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ); // 100ms
- pSscanRspData[index+3] = HI_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL );
- pSscanRspData[index+4] = LO_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ); // 1s
- pSscanRspData[index+5] = HI_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL );
- // Tx power level
- pSscanRspData[index+6] = 0x02; // length of this data
- pSscanRspData[index+7] = GAP_ADTYPE_POWER_LEVEL;
- pSscanRspData[index+8] = 0; // 0dBm
- GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, pSscanRspDataLen, pSscanRspData );
- osal_mem_free(pSscanRspData);
- }
- }
- #endif
- GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );
- GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );
- GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );
- GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );
- GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency );
- GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout );
- }
- // Set the GAP Characteristics
- GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, simpleBle_GetAttDeviceName() );//设备名称
- {
- // 设置rssi 参数更新速率
- uint16 rssi_read_rate_1ms = 500; //一秒更新2次
- GAPRole_SetParameter(GAPROLE_RSSI_READ_RATE, sizeof( uint16 ), &rssi_read_rate_1ms);
- }
- // 广播时间段
- {
- uint16 advInt = DEFAULT_ADVERTISING_INTERVAL;
- GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
- GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
- GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
- GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
- }
- //下面是与配对相关的设置
- {
- uint32 passkey = simpleBle_GetPassword();
- uint8 pairMode = GAPBOND_PAIRING_MODE_INITIATE;//配对模式,置配成等待主机的配对请求
- uint8 mitm = TRUE;
- uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY; //显示密码, 以便主机输入配对的密码
- uint8 bonding = FALSE;//FALSE:每次连接都需要密码;TRUE:第一次连接需要密码
- GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey );
- GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode );
- GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm );
- GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap );
- GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding );
- }
- //GATT总协定属性初始化
- GGS_AddService( GATT_ALL_SERVICES ); // GAP
- GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes
- DevInfo_AddService(); // Device Information Service
- SimpleProfile_AddService( GATT_ALL_SERVICES ); // Simple GATT Profile
- // 设置simpleprofile特征值
- {
- uint8 charValue1 = 1;
- uint8 charValue2 = 2;
- uint8 charValue3 = 3;
- uint8 charValue4 = 4;
- uint8 charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 };
- // uint8 charValue6[SIMPLEPROFILE_CHAR6_LEN] = { 1, 2, 3, 4, 5 };
- // uint8 charValue7[SIMPLEPROFILE_CHAR7_LEN] = { 1, 2, 3, 4, 5 };
- SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR1, sizeof ( uint8 ), &charValue1 );
- SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR2, sizeof ( uint8 ), &charValue2 );
- SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR3, sizeof ( uint8 ), &charValue3 );
- SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof ( uint8 ), &charValue4 );
- SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5 );
- // SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR6, SIMPLEPROFILE_CHAR6_LEN, charValue6 );
- // SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR7, SIMPLEPROFILE_CHAR7_LEN, charValue7 );
- }
-
- // Register for all key events - This app will handle all key events
- RegisterForKeys( simpleBLETaskId );
-
- // Register callback with SimpleGATTprofile
- VOID SimpleProfile_RegisterAppCBs( &simpleBLEPeripheral_SimpleProfileCBs );//主机修改特征值,接收来自主机的信息
- // 使时钟停止分裂
- // 这减少了有功电流当无线电主动CC254x单片机
- // 停止
- // 需要关闭的CLK自动分频,在初始化中加入HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_DISABLE_CLK_DIVIDE_ON_HALT )? // 如果开启,会导致频率自动切换,DMA工作受到影响,小范围丢数。
- // 这里把他关闭, 如果想降低功耗, 这个应该要开启的, 这里矛盾了
- HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_DISABLE_CLK_DIVIDE_ON_HALT );
- //HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_ENABLE_CLK_DIVIDE_ON_HALT );
-
- // 信号发射强度
- HCI_EXT_SetTxPowerCmd(sys_config.txPower);
-
- // Setup a delayed profile startup
- osal_set_event( simpleBLETaskId, START_DEVICE_EVT );
- }
- //从机执行
- uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
- {
- VOID task_id; // OSAL required parameter that isn't used in this function
- if ( events & SYS_EVENT_MSG )
- {//按键及消息类
- uint8 *pMsg;
-
- if ( (pMsg = osal_msg_receive( simpleBLETaskId )) != NULL )
- {
- simpleBLEPeripheral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );
- // Release the OSAL message
- VOID osal_msg_deallocate( pMsg );
- }
- return (events ^ SYS_EVENT_MSG);
- }
- if ( events & START_DEVICE_EVT )
- {
- // 启动设备
- VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );
- // 开始设备连接
- VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs );
-
- // Set timer for first periodic event
- osal_start_timerEx( simpleBLETaskId, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
-
- // 延时400ms后唤醒, 不然会继续睡眠,原因不明
- //osal_start_timerEx( simpleBLETaskId, SBP_WAKE_EVT, 500 );
- return ( events ^ START_DEVICE_EVT );
- }
-
- if ( events & SBP_WAKE_EVT )
- {//500ms防睡眠
- osal_pwrmgr_device( PWRMGR_ALWAYS_ON); // 不睡眠,功耗很高的
- return ( events ^ SBP_WAKE_EVT );
- }
-
- if ( events & SBP_DATA_EVT )
- {//发送数据
- SimpleBLE_SendData();
- if(qq_total() > 0)
- {
- timerIsOn = TRUE;
- osal_start_timerEx( simpleBLETaskId, SBP_DATA_EVT, 8);
- }
- else
- {
- timerIsOn = FALSE;
- }
- return ( events ^ SBP_DATA_EVT );
- }
- if ( events & SBP_UART_EVT )
- {//8ms定时器,发送数据
- if(FALSE == timerIsOn)
- {
- osal_start_timerEx( simpleBLETaskId, SBP_DATA_EVT, 8);
- }
- return ( events ^ SBP_UART_EVT );
- }
-
- if ( events & SBP_PERIODIC_EVT )
- {//定时器轮询
- // Restart timer
- if ( SBP_PERIODIC_EVT_PERIOD)
- {//100ms
- //osal_start_timerEx( simpleBLETaskId, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
- }
- osal_stop_timerEx( simpleBLETaskId, SBP_PERIODIC_EVT);
- // Perform periodic application task
- SimpleBLE_TimerISR();
- return (events ^ SBP_PERIODIC_EVT);
- }
-
- // Discard unknown events
- return 0;
- }
复制代码
|
|