bsp_wdt.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. //extern const char *Test;
  19. void wdt_event_handler(void)
  20. {
  21. DEBUG_LOG("wdt_event_handler:%d\n",TIME_GetTicks());
  22. Except_Unkown_Reset_WDT_Set();
  23. }
  24. static void WatchDog_Process(void)
  25. {
  26. feed_watchdog();
  27. // DEBUG_LOG("WatchDog_Process:%d\n",TIME_GetTicks());
  28. }
  29. static void bsp_wdt_init_process(void)
  30. {
  31. if(Except_TxError(EXCEPT_WDT_INIT,"bsp_wdt_init_error\r\n") == 0)
  32. {
  33. Process_Stop(bsp_wdt_init_process);
  34. }
  35. }
  36. void watchdog_init(void){
  37. int ret = 0;
  38. ret_code_t errCode;
  39. nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;
  40. config.interrupt_priority = WDT_IRQ_PRIORITY;
  41. config.reload_value = WDT_RELOAD_VALUE;
  42. errCode = nrf_drv_wdt_init(&config, wdt_event_handler);
  43. if(errCode != NRF_SUCCESS)ret = -1;
  44. errCode = nrf_drv_wdt_channel_alloc(&m_channel_id);
  45. if(errCode != NRF_SUCCESS)ret = -1;
  46. nrf_drv_wdt_enable();
  47. Process_Start(1000,"WatchDog_Process",WatchDog_Process);
  48. if(ret == -1)
  49. {
  50. Process_Start(0,"bsp_wdt_init_process",bsp_wdt_init_process);
  51. }
  52. }