123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- #include <stdarg.h>
- #include "yc11xx.h"
- #include "yc11xx_uart.h"
- #include "yc11xx_gpio.h"
- #include "yc_timer.h"
- #include "ipc.h"
- #include "yc_lpm.h"
- #include "system.h"
- #include "att.h"
- #include "yc11xx_bt_interface.h"
- #include "core_cm0.h"
- #define adv_len 30
- /*
- dataPtr: adv receive data buf;
- len: receive data len
- */
- typedef struct
- {
- uint8_t adv_type;
- uint8_t adv_rssi;
- uint8_t mac[6];
- uint8_t adv_data_len;
- uint8_t ad_tye;
- uint16_t ad_id;
- uint8_t adv_data[100];
- }ADV_ParseDef;
- #define ADV_IND 0
- #define ADV_DIRECT_IND 1
- #define ADV_NONCONN_IND 2
- #define SCAN_REQ 3
- #define SCAN_RSP 4
- #define CONNECT_REQ 5
- #define ADV_SCAN_IND 6
- //#define adv_parse
- void adv_receive_back(uint8_t len,uint8_t *dataPtr)
- {
- #ifdef adv_parse
- int adv_type= *(dataPtr);
- int rssi = *(dataPtr+1);
- uint8_t mac[6];
- printf("receive len=%d\r\n",len);
- switch(adv_type)
- {
- case 0:
- printf("\r\nadv type: ADV_IND\r\n");
- break;
- case 1:
- printf("\r\nadv type: ADV_DIRECT_IND\r\n");
- break;
- case 2:
- printf("\r\nadv type: ADV_NONCONN_IND\r\n");
- break;
- case 3:
- printf("\r\nadv type: SCAN_REQ\r\n");
- return;
- // break;
- case 4:
- printf("\r\nadv type: SCAN_RSP\r\n");
- return;
- // break;
- case 5:
- printf("\r\nadv type: CONNECT_REQ\r\n");
- return;
- // break;
- case 6:
- printf("\r\nadv type: ADV_SCAN_IND\r\n");
- break;
- }
- printf("\r\n RSSI: -%x\r\n",rssi);
- memcpy(mac,dataPtr+2,6);
-
- printf("\r\n MAC: %x %x %x %x %x %x \r\n",mac[5],mac[4],mac[3],mac[2],mac[1],mac[0]);
-
-
- printf("receive data=\r\n");
- for(int i=0;i<len-2;i++)
- printf("%02x ",*(dataPtr+i+2));
- printf("\r\n");
- #endif
- ADV_ParseDef ADV_Parse;
- memcpy(&ADV_Parse,dataPtr,len);
- switch(ADV_Parse.adv_type)
- {
- case ADV_IND:
- MyPrintf("\r\nadv type: ADV_IND\r\n");
- break;
- case ADV_DIRECT_IND:
- MyPrintf("\r\nadv type: ADV_DIRECT_IND\r\n");
- break;
- case ADV_NONCONN_IND:
- MyPrintf("\r\nadv type: ADV_NONCONN_IND\r\n");
- break;
- case SCAN_REQ:
- MyPrintf("\r\nadv type: SCAN_REQ\r\n");
- return;
- case SCAN_RSP:
- MyPrintf("\r\nadv type: SCAN_RSP\r\n");
- return;
- case CONNECT_REQ:
- MyPrintf("\r\nadv type: CONNECT_REQ\r\n");
- return;
- case ADV_SCAN_IND:
- MyPrintf("\r\nadv type: ADV_SCAN_IND\r\n");
- break;
- }
- MyPrintf("\r\n RSSI: -%x\r\n",ADV_Parse.adv_rssi);
- // printf("adv_rssi:-%02D ",ADV_Parse.ad_tye);
- MyPrintf("\r\nMAC:");
- for(int i=0;i<6;i++)
- MyPrintf("%02x ",ADV_Parse.mac[i]);
- MyPrintf("\r\n");
- MyPrintf("adv_data_len=%d\r\n",ADV_Parse.adv_data_len);
- MyPrintf("receive adv data=\r\n");
- for(int i=0;i<ADV_Parse.adv_data_len;i++)
- MyPrintf("%02x ",*(dataPtr+i+9));
- MyPrintf("\r\n");
- }
- void Bt_EvtCallBack(uint8_t len,uint8_t *dataPtr)
- {
- switch(*dataPtr)
- {
- case IPC_EVT_LE_DISCONNECTED: //断连
- Lpm_ClearLpmFlag();
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n***************IPC_EVT_LE_DISCONNECTED***************\r\n");
- #endif
- break;
- case IPC_EVT_LE_CONNECTED: //连接
- Bt_SndCmdLeUpdateAttMTU();
- IPC_TxControlCmd(IPC_CMD_UPDATE_CONN);
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n***************IPC_EVT_LE_CONNECTED***************\r\n");
- #endif
- break;
- case IPC_EVT_BB_CONNECTED:
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n****************IPC_EVT_BB_CONNECTED*****************\r\n");
- #endif
- break;
- case IPC_EVT_SETUP_COMPLETE:
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n****************IPC_EVT_SETUP_COMPLETE*****************\r\n");
- #endif
- break;
- case IPC_EVT_BT_PAIRING_SUCCESS:
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n****************IPC_EVT_BT_PAIRING_SUCCESS*****************\r\n");
- #endif
- break;
- case IPC_EVT_LINKKEY_GENERATE:
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n****************IPC_EVT_LINKKEY_GENERATE*****************\r\n");
- #endif
- break;
- case IPC_EVT_RESET: //上电
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n****************IPC_EVT_RESET*****************\r\n");
- #endif
- // Bt_Reset();
- break;
- case IPC_EVT_WAKEUP: //唤醒
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n****************IPC_EVT_WAKEUP*****************\r\n");
- #endif
- // SysTick_Config(SYSTEM_CLOCK/100); //each systick interrupt is 10ms
- OS_EXIT_CRITICAL();
- break;
- case IPC_EVT_LE_TK_GENERATE:
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n****************IPC_EVT_LE_TK_GENERATE*****************\r\n");
- #endif
- break;
-
- case IPC_EVT_LE_DISCONNECTED_ABNORMAL:
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n******************IPC_EVT_LE_DISCONNECTED_ABNORMAL******************\r\n");
- #endif
- break;
- default:
- break;
- }
- return;
- }
- void Bt_BleCallBack(uint8_t len,uint8_t *dataPtr)
- {
- uint16_t handle;
- handle = dataPtr[0] +(dataPtr[1]<<8);
- switch(handle){
-
- }
- }
- tIPCHandleCb gTIPCHandleCb[IPC_TYPE_NUM]=
- {
- 0,
- IpcDefaultCallBack,//cmd
- Bt_EvtCallBack,//evt //evt回调函数,函数在drv_bt.c实现
- IpcDefaultCallBack,//hid
- IpcDefaultCallBack,//spp
- Bt_BleCallBack,//ble //ble data回调函数,函数在drv_bt.c实现
- IpcDefaultCallBack,//24g
- IpcDefaultCallBack,//mesh
- adv_receive_back,
- IpcDefaultCallBack,//mesh
- IpcDefaultCallBack,//a2dp
- IpcDefaultCallBack,//hfp
- IpcDefaultCallBack
- };
- int main(void)
- {
- uint8_t name[11] = {'1','1','4','7','-','B','L','E'};
- uint8_t lap[6]={0x11,0x22,0x33,0x44,0x55,0x66};
- if(HREAD(mem_wake_flag)==POWERON_WAKE)
- {
- IPC_init(&gTIPCHandleCb); //蓝牙回调函数初始化
- SYS_TimerInit();
- printport_init();
- // att_list_init();
- Att_profile_Config();
- MyPrintf("********** BlueTooth scan Demo*********************!\r\n");
- Lpm_exit();
- Bt_SndCmdStartScan();
- }
- else
- {
- printport_init();
- SysTick_Config(SYSTEM_CLOCK/100);
- }
- SYS_ClkTicks();
- while(1)
- {
- switch (HREAD(IPC_MCU_STATE))
- {
- case IPC_MCU_STATE_RUNNING:
- IPC_HandleRxPacket(); //m0和bt交互数据类型判断,是evt还是ble data?并执行对应回调函数
- SYS_timerPolling();
- Lpm_unLockLpm(M0_LPM_FLAG);
- break;
- case IPC_MCU_STATE_LMP: //lpm
- if (IPC_IsTxBuffEmpty())
- {
- OS_ENTER_CRITICAL();
- Bt_ActionBeforeLpm();
- HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_STOP);
- }
- else{
- HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_RUNNING);
- }
- break;
- case IPC_MCU_STATE_HIBERNATE: // HIBERNATE
- OS_ENTER_CRITICAL();
- Bt_ActionBeforeHibernate();
- HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_STOP);
- break;
- case IPC_MCU_STATE_STOP:
- break;
- }
- }
- }
|