main.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include <stdarg.h>
  2. #include "yc11xx.h"
  3. #include "yc11xx_uart.h"
  4. #include "yc11xx_gpio.h"
  5. #include "yc_timer.h"
  6. #include "ipc.h"
  7. #include "yc_lpm.h"
  8. #include "system.h"
  9. #include "yc11xx_bt_interface.h"
  10. #include "core_cm0.h"
  11. void SppReset();
  12. void Bt_SppCallback(uint8_t len,uint8_t *dataPtr);
  13. void Bt_SppCallback(uint8_t len,uint8_t *dataPtr)
  14. {
  15. MyPrintf("\r\n*********ssp receive ***********\r\n");
  16. for(int i=0;i<len;i++)
  17. {
  18. MyPrintf("%02x ", *(dataPtr+i));
  19. }
  20. Bt_SndSppData(dataPtr,len);
  21. }
  22. void SppReset()
  23. {
  24. uint8_t name[12]={"11xxBT_01"};
  25. uint8_t lap[6]={0x02,0xac,0x78,0x98,0x2b,0xef};
  26. Bt_SetSppAddr(lap);
  27. Bt_SetSppName(name,12);
  28. Bt_SndCmdSppStartDiscovery();
  29. }
  30. void Bt_EvtCallBack(uint8_t len,uint8_t *dataPtr)
  31. {
  32. switch(*dataPtr)
  33. {
  34. case IPC_EVT_LE_DISCONNECTED: //断连
  35. #ifdef DEBUG_DRV_BT
  36. MyPrintf("\r\n***************IPC_EVT_LE_DISCONNECTED***************\r\n");
  37. #endif
  38. break;
  39. case IPC_EVT_LE_CONNECTED: //连接
  40. #ifdef DEBUG_DRV_BT
  41. MyPrintf("\r\n***************IPC_EVT_LE_CONNECTED***************\r\n");
  42. #endif
  43. break;
  44. case IPC_EVT_BB_CONNECTED:
  45. #ifdef DEBUG_DRV_BT
  46. MyPrintf("\r\n****************IPC_EVT_BB_CONNECTED*****************\r\n");
  47. #endif
  48. break;
  49. case IPC_EVT_SETUP_COMPLETE:
  50. #ifdef DEBUG_DRV_BT
  51. MyPrintf("\r\n****************IPC_EVT_SETUP_COMPLETE*****************\r\n");
  52. #endif
  53. break;
  54. case IPC_EVT_BT_PAIRING_SUCCESS:
  55. #ifdef DEBUG_DRV_BT
  56. MyPrintf("\r\n****************IPC_EVT_BT_PAIRING_SUCCESS*****************\r\n");
  57. #endif
  58. break;
  59. case IPC_EVT_LINKKEY_GENERATE:
  60. #ifdef DEBUG_DRV_BT
  61. MyPrintf("\r\n****************IPC_EVT_LINKKEY_GENERATE*****************\r\n");
  62. #endif
  63. break;
  64. case IPC_EVT_RESET: //上电
  65. #ifdef DEBUG_DRV_BT
  66. MyPrintf("\r\n****************IPC_EVT_RESET*****************\r\n");
  67. #endif
  68. // Bt_Reset();
  69. break;
  70. case IPC_EVT_WAKEUP: //唤醒
  71. #ifdef DEBUG_DRV_BT
  72. MyPrintf("\r\n****************IPC_EVT_WAKEUP*****************\r\n");
  73. #endif
  74. // SysTick_Config(SYSTEM_CLOCK/100); //each systick interrupt is 10ms
  75. OS_EXIT_CRITICAL();
  76. break;
  77. case IPC_EVT_LE_TK_GENERATE:
  78. #ifdef DEBUG_DRV_BT
  79. MyPrintf("\r\n****************IPC_EVT_LE_TK_GENERATE*****************\r\n");
  80. #endif
  81. break;
  82. case IPC_EVT_LE_DISCONNECTED_ABNORMAL:
  83. #ifdef DEBUG_DRV_BT
  84. MyPrintf("\r\n******************IPC_EVT_LE_DISCONNECTED_ABNORMAL******************\r\n");
  85. #endif
  86. break;
  87. default:
  88. break;
  89. }
  90. return;
  91. }
  92. tIPCHandleCb gTIPCHandleCb[IPC_TYPE_NUM]=
  93. {
  94. 0,
  95. IpcDefaultCallBack,//cmd
  96. Bt_EvtCallBack,//evt //evt回调函数,函数在drv_bt.c实现
  97. IpcDefaultCallBack,//hid
  98. Bt_SppCallback,//spp
  99. IpcDefaultCallBack,//ble //ble data回调函数,函数在drv_bt.c实现
  100. IpcDefaultCallBack,//24g
  101. IpcDefaultCallBack,//mesh
  102. IpcDefaultCallBack,
  103. IpcDefaultCallBack,//mesh
  104. IpcDefaultCallBack,//a2dp
  105. IpcDefaultCallBack,//hfp
  106. IpcDefaultCallBack
  107. };
  108. int main(void)
  109. {
  110. if(HREAD(mem_wake_flag)==POWERON_WAKE)
  111. {
  112. IPC_init(&gTIPCHandleCb); //蓝牙回调函数初始化
  113. SYS_TimerInit();
  114. printport_init();
  115. MyPrintf("SPP send and recive Demo !\r\n");
  116. Lpm_exit();
  117. SppReset();
  118. }
  119. else
  120. {
  121. printport_init();
  122. SysTick_Config(SYSTEM_CLOCK/100);
  123. }
  124. SYS_ClkTicks();
  125. while(1)
  126. {
  127. switch (HREAD(IPC_MCU_STATE))
  128. {
  129. case IPC_MCU_STATE_RUNNING:
  130. IPC_HandleRxPacket(); //m0和bt交互数据类型判断,是evt还是ble data?并执行对应回调函数
  131. SYS_timerPolling();
  132. Lpm_unLockLpm(M0_LPM_FLAG);
  133. break;
  134. case IPC_MCU_STATE_LMP: //lpm
  135. if (IPC_IsTxBuffEmpty())
  136. {
  137. OS_ENTER_CRITICAL();
  138. Bt_ActionBeforeLpm();
  139. HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_STOP);
  140. }
  141. else{
  142. HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_RUNNING);
  143. }
  144. break;
  145. case IPC_MCU_STATE_HIBERNATE: // HIBERNATE
  146. OS_ENTER_CRITICAL();
  147. Bt_ActionBeforeHibernate();
  148. HWRITE(IPC_MCU_STATE,IPC_MCU_STATE_STOP);
  149. break;
  150. case IPC_MCU_STATE_STOP:
  151. break;
  152. }
  153. }
  154. }