hal_mt.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. if(tim>0){
  16. mt_time = tim;
  17. nrf_gpio_pin_write(PIN_MT_EN,1);
  18. Process_SetHoldOn(MT_process,1);
  19. }
  20. }
  21. void gpio_mt_run(uint32_t tim)
  22. {
  23. MT_Run(tim);
  24. }
  25. void MT_process(void)
  26. {
  27. }
  28. void MT_TimerCounter(void* t)
  29. {
  30. if(mt_time>0){
  31. if(mt_time >=10)mt_time -=10;
  32. else mt_time=0;;
  33. if(mt_time==0){
  34. nrf_gpio_pin_write(PIN_MT_EN,0);
  35. Process_SetHoldOn(MT_process,0);
  36. }
  37. }
  38. }
  39. void cb_BLE_Client_R_SHOCK(void* handle)
  40. {
  41. BLE_Client_Rx_t *target = handle;
  42. BLE_Host_Tx_Send(0,BLE_Host_T_SHOCK,target->pDat,target->datLen);
  43. uint16_t t = ((uint16_t)(target->pDat[0])<<8) | ((uint16_t)(target->pDat[0])<<0);
  44. MT_Run(t);
  45. SEGGER_RTT_printf(0,"MT RUN:%d \n",t);
  46. }
  47. void MT_Init(void)
  48. {
  49. nrf_gpio_cfg_output(PIN_MT_EN); nrf_gpio_pin_write(PIN_MT_EN,0); MT_Run(100);
  50. TIME_Regist(MT_TimerCounter);
  51. Process_Start(0,"MT_process",MT_process);
  52. BLE_Client_Rx_Regist(BLE_Client_R_SHOCK,cb_BLE_Client_R_SHOCK);
  53. }