bsp_wdt.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "system.h"
  7. #include "bsp_time.h"
  8. #include "nrf_delay.h"
  9. #include "exception.h"
  10. nrf_drv_wdt_channel_id m_channel_id;
  11. void feed_watchdog(void)
  12. {
  13. nrf_drv_wdt_channel_feed(m_channel_id);
  14. }
  15. /**
  16. * @brief WDT events handler.
  17. */
  18. void wdt_event_handler(void)
  19. {
  20. DEBUG_LOG("wdt_event_handler:%d\n",TIME_GetTicks());
  21. Except_Unkown_Reset_WDT_Set();
  22. }
  23. static void WatchDog_Process(void)
  24. {
  25. feed_watchdog();
  26. // DEBUG_LOG("WatchDog_Process:%d\n",TIME_GetTicks());
  27. }
  28. static void bsp_wdt_init_process(void)
  29. {
  30. if(Except_TxError(EXCEPT_WDT_INIT,"bsp_wdt_init_error\r\n") == 0)
  31. {
  32. Process_Stop(bsp_wdt_init_process);
  33. }
  34. }
  35. void watchdog_init(void){
  36. int ret = 0;
  37. ret_code_t errCode;
  38. nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;
  39. config.interrupt_priority = WDT_IRQ_PRIORITY;
  40. config.reload_value = WDT_RELOAD_VALUE;
  41. errCode = nrf_drv_wdt_init(&config, wdt_event_handler);
  42. if(errCode != NRF_SUCCESS)ret = -1;
  43. errCode = nrf_drv_wdt_channel_alloc(&m_channel_id);
  44. if(errCode != NRF_SUCCESS)ret = -1;
  45. nrf_drv_wdt_enable();
  46. Process_Start(1000,"WatchDog",WatchDog_Process);
  47. if(ret == -1)
  48. {
  49. Process_Start(0,"bsp_wdt_init",bsp_wdt_init_process);
  50. }
  51. }