wdg.c 918 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <stdio.h>
  2. #include "nrf.h"
  3. #include "nrf_drv_wdt.h"
  4. #include "app_error.h"
  5. #include "wdg.h"
  6. #include "nrf_drv_clock.h"
  7. #include "app_util_platform.h"
  8. #include "app_timer.h"
  9. #include "timer.h"
  10. #define WDT_RELOAD_TIME 5000
  11. #define WDT_FEED_INTERVAL 2000
  12. static nrf_drv_wdt_channel_id m_channel_id;
  13. static void wdt_event_handler(void)
  14. {
  15. }
  16. static void watchdog_feed_timer_callback(void)
  17. {
  18. nrf_drv_wdt_channel_feed(m_channel_id);
  19. }
  20. void wdg_feed(void)
  21. {
  22. timer_register(watchdog_feed_timer_callback, WDT_FEED_INTERVAL);
  23. }
  24. void wdg_init(void)
  25. {
  26. ret_code_t err_code;
  27. nrf_drv_wdt_config_t config = NRF_DRV_WDT_DEAFULT_CONFIG;
  28. config.reload_value = WDT_RELOAD_TIME;
  29. err_code = nrf_drv_wdt_init(&config, wdt_event_handler);
  30. APP_ERROR_CHECK(err_code);
  31. err_code = nrf_drv_wdt_channel_alloc(&m_channel_id);
  32. APP_ERROR_CHECK(err_code);
  33. nrf_drv_wdt_enable();
  34. }