hal_mt.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /************************ º¯ÊýÉùÃ÷ ***********************************/
  9. void MT_process(void);
  10. /************************ ±äÁ¿ ***********************************/
  11. /************************ º¯Êý¶¨Òå ***********************************/
  12. static uint32_t mt_time = 0;
  13. void MT_Run(uint32_t tim)
  14. {
  15. SEGGER_RTT_printf(0,"MT MT_Run:%d \n",tim);
  16. if(tim>0){
  17. mt_time = tim;
  18. nrf_gpio_pin_write(PIN_MT_EN,1);
  19. Process_SetHoldOn(MT_process,1);
  20. }
  21. }
  22. void gpio_mt_run(uint32_t tim)
  23. {
  24. MT_Run(tim);
  25. }
  26. void MT_process(void)
  27. {
  28. }
  29. void MT_TimerCounter(void* t)
  30. {
  31. if(mt_time>0){
  32. if(mt_time >=HeartTime_Interval)mt_time -=HeartTime_Interval;
  33. else mt_time=0;;
  34. if(mt_time==0){
  35. nrf_gpio_pin_write(PIN_MT_EN,0);
  36. Process_SetHoldOn(MT_process,0);
  37. }
  38. }
  39. }
  40. void cb_BLE_Client_R_SHOCK(void* handle)
  41. {
  42. BLE_Client_Rx_t *target = handle;
  43. BLE_Host_Tx_Send(0,BLE_SHOCK,target->pDat,target->datLen);
  44. uint16_t t = ((uint16_t)(target->pDat[0])<<8) | ((uint16_t)(target->pDat[0])<<0);
  45. MT_Run(t);
  46. SEGGER_RTT_printf(0,"MT RUN:%d \n",t);
  47. }
  48. void MT_Init(void)
  49. {
  50. nrf_gpio_cfg_output(PIN_MT_EN); nrf_gpio_pin_write(PIN_MT_EN,0); MT_Run(100);
  51. TIME_Regist(MT_TimerCounter);
  52. Process_Start(0,"MT_process",MT_process);
  53. BLE_Client_Rx_Regist(BLE_SHOCK,cb_BLE_Client_R_SHOCK);
  54. }