123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #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 "yc11xx_bt_interface.h"
- #include "core_cm0.h"
- void SppReset();
- void Bt_SppCallback(uint8_t len,uint8_t *dataPtr);
- void Bt_SppCallback(uint8_t len,uint8_t *dataPtr)
- {
- MyPrintf("\r\n*********ssp receive ***********\r\n");
- for(int i=0;i<len;i++)
- {
- MyPrintf("%02x ", *(dataPtr+i));
- }
- Bt_SndSppData(dataPtr,len);
- }
- void SppReset()
- {
- uint8_t name[12]={"11xxBT_01"};
- uint8_t lap[6]={0x02,0xac,0x78,0x98,0x2b,0xef};
- Bt_SetSppAddr(lap);
- Bt_SetSppName(name,12);
- Bt_SndCmdSppStartDiscovery();
- }
- void Bt_EvtCallBack(uint8_t len,uint8_t *dataPtr)
- {
- switch(*dataPtr)
- {
- case IPC_EVT_LE_DISCONNECTED: //断连
- #ifdef DEBUG_DRV_BT
- MyPrintf("\r\n***************IPC_EVT_LE_DISCONNECTED***************\r\n");
- #endif
- break;
- case IPC_EVT_LE_CONNECTED: //连接
- #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;
- }
- tIPCHandleCb gTIPCHandleCb[IPC_TYPE_NUM]=
- {
- 0,
- IpcDefaultCallBack,//cmd
- Bt_EvtCallBack,//evt //evt回调函数,函数在drv_bt.c实现
- IpcDefaultCallBack,//hid
- Bt_SppCallback,//spp
- IpcDefaultCallBack,//ble //ble data回调函数,函数在drv_bt.c实现
- IpcDefaultCallBack,//24g
- IpcDefaultCallBack,//mesh
- IpcDefaultCallBack,
- IpcDefaultCallBack,//mesh
- IpcDefaultCallBack,//a2dp
- IpcDefaultCallBack,//hfp
- IpcDefaultCallBack
- };
- int main(void)
- {
- if(HREAD(mem_wake_flag)==POWERON_WAKE)
- {
- IPC_init(&gTIPCHandleCb); //蓝牙回调函数初始化
- SYS_TimerInit();
- printport_init();
- MyPrintf("SPP send and recive Demo !\r\n");
- Lpm_exit();
- SppReset();
- }
- 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;
- }
- }
- }
|