hal_mt.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "hal_mt.h"
  2. #include "nrf_gpio.h"
  3. #include "usr_config.h"
  4. #include "bsp_time.h"
  5. #include "system.h"
  6. #include "hal_ble_client.h"
  7. #include "hal_ble_host.h"
  8. #include "app_flash.h"
  9. /************************ º¯ÊýÉùÃ÷ ***********************************/
  10. void MT_process(void);
  11. /************************ ±äÁ¿ ***********************************/
  12. /************************ º¯Êý¶¨Òå ***********************************/
  13. static uint32_t mt_time = 0;
  14. void MT_Run(uint32_t tim)
  15. {
  16. SEGGER_RTT_printf(0,"MT MT_Run:%d \n",tim);
  17. if(tim>0){
  18. mt_time = tim;
  19. nrf_gpio_pin_write(PIN_MT_EN,1);
  20. Process_SetHoldOn(MT_process,1);
  21. }
  22. }
  23. void gpio_mt_run(uint32_t tim)
  24. {
  25. MT_Run(tim);
  26. }
  27. void MT_process(void)
  28. {
  29. }
  30. void MT_TimerCounter(void* t)
  31. {
  32. if(mt_time>0){
  33. if(mt_time >=HeartTime_Interval)mt_time -=HeartTime_Interval;
  34. else mt_time=0;;
  35. if(mt_time==0){
  36. nrf_gpio_pin_write(PIN_MT_EN,0);
  37. Process_SetHoldOn(MT_process,0);
  38. }
  39. }
  40. }
  41. void cb_BLE_Client_R_SHOCK(void* handle)
  42. {
  43. BLE_Client_Rx_t *target = handle;
  44. uint16_t t = ((uint16_t)(target->pDat[0])<<8) | ((uint16_t)(target->pDat[1])<<0);
  45. if(mFlash.isHost)
  46. {
  47. if(target->pDat[2]==1)
  48. {
  49. MT_Run(t);
  50. }
  51. else if(target->pDat[2]==0)
  52. {
  53. MT_Run(t);
  54. BLE_Host_Tx_Send(0,BLE_SHOCK,target->pDat,target->datLen);
  55. }
  56. else
  57. {
  58. BLE_Host_Tx_Send(0,BLE_SHOCK,target->pDat,target->datLen);
  59. }
  60. }
  61. else
  62. {
  63. if((target->pDat[2]==2)||(target->pDat[2]==0))
  64. {
  65. MT_Run(t);
  66. }
  67. }
  68. SEGGER_RTT_printf(0,"MT RUN:%d \n",t);
  69. }
  70. void MT_Init(void)
  71. {
  72. nrf_gpio_cfg_output(PIN_MT_EN); nrf_gpio_pin_write(PIN_MT_EN,0); MT_Run(100);
  73. TIME_Regist(MT_TimerCounter);
  74. Process_Start(0,"MT_process",MT_process);
  75. BLE_Client_Rx_Regist(BLE_SHOCK,cb_BLE_Client_R_SHOCK);
  76. }