bsp_wdt.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "sdk_common.h"
  2. #include "SEGGER_RTT.h"
  3. #include "nrf_drv_pwm.h"
  4. #include "usr_config.h"
  5. #include "nrf_drv_wdt.h"
  6. #include "nrf_delay.h"
  7. #include "exception.h"
  8. #include "system.h"
  9. #include "bsp_time.h"
  10. #include "bsp_wdt.h"
  11. static uint32_t feed_dog_time = 0;
  12. nrf_drv_wdt_channel_id m_channel_id;
  13. uint32_t Get_FeedWatchDogTime(void)
  14. {
  15. return feed_dog_time;
  16. }
  17. void feed_watchdog(void)
  18. {
  19. feed_dog_time = NRF_RTC0->COUNTER;
  20. nrf_drv_wdt_channel_feed(m_channel_id);
  21. }
  22. /**
  23. * @brief WDT events handler.
  24. */
  25. void wdt_event_handler(void)
  26. {
  27. DEBUG_LOG("wdt_event_handler:%d\n",TIME_GetTicks());
  28. Except_Unkown_Reset_WDT_Set();
  29. }
  30. static void WatchDog_Process(void)
  31. {
  32. feed_watchdog();
  33. // DEBUG_LOG("WatchDog_Process:%d\n",TIME_GetTicks());
  34. }
  35. static void bsp_wdt_init_process(void)
  36. {
  37. if(Except_TxError(EXCEPT_WDT_INIT,"bsp_wdt_init_error\r\n") == 0)
  38. {
  39. Process_Stop(bsp_wdt_init_process);
  40. }
  41. }
  42. void watchdog_init(void){
  43. int ret = 0;
  44. ret_code_t errCode;
  45. nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;
  46. config.interrupt_priority = WDT_IRQ_PRIORITY;
  47. config.reload_value = WDT_RELOAD_VALUE;
  48. errCode = nrf_drv_wdt_init(&config, wdt_event_handler);
  49. if(errCode != NRF_SUCCESS)ret = -1;
  50. errCode = nrf_drv_wdt_channel_alloc(&m_channel_id);
  51. if(errCode != NRF_SUCCESS)ret = -1;
  52. nrf_drv_wdt_enable();
  53. Process_Start(1000,"WatchDog",WatchDog_Process);
  54. if(ret == -1)
  55. {
  56. Process_Start(0,"bsp_wdt_init",bsp_wdt_init_process);
  57. }
  58. }