watchdog_hal.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief watchdog hal interface
  9. */
  10. #include <kernel.h>
  11. #include <os_common_api.h>
  12. #include <drivers/watchdog.h>
  13. #include <watchdog_hal.h>
  14. #include <soc.h>
  15. const struct device *system_wdg_dev;
  16. #ifndef CONFIG_WDT_MODE_RESET
  17. void watchdog_overflow(const struct device *wdt_dev, int channel_id)
  18. {
  19. printk("watchdog overflow");
  20. k_panic();
  21. }
  22. #endif
  23. void watchdog_start(int timeout_ms)
  24. {
  25. int err;
  26. struct wdt_timeout_cfg m_cfg_wdt0 = { 0 };
  27. system_wdg_dev = device_get_binding(CONFIG_WDT_ACTS_NAME);
  28. if (!system_wdg_dev) {
  29. SYS_LOG_ERR("cannot found watchdog device");
  30. return;
  31. }
  32. #ifdef CONFIG_WDT_MODE_RESET
  33. m_cfg_wdt0.callback = NULL;
  34. #else
  35. m_cfg_wdt0.callback = watchdog_overflow;
  36. #endif
  37. m_cfg_wdt0.flags = WDT_FLAG_RESET_SOC;
  38. m_cfg_wdt0.window.max = timeout_ms;
  39. wdt_install_timeout(system_wdg_dev, &m_cfg_wdt0);
  40. err = wdt_setup(system_wdg_dev, 0);
  41. if (err < 0) {
  42. SYS_LOG_ERR("Watchdog setup error\n");
  43. return;
  44. }
  45. SYS_LOG_INF("enable watchdog (%d ms)", m_cfg_wdt0.window.max);
  46. }
  47. void watchdog_clear(void)
  48. {
  49. if (system_wdg_dev) {
  50. wdt_feed(system_wdg_dev, 0);
  51. } else {
  52. soc_watchdog_clear();
  53. }
  54. }
  55. void watchdog_stop(void)
  56. {
  57. SYS_LOG_INF("disable watchdog");
  58. if (system_wdg_dev) {
  59. wdt_disable(system_wdg_dev);
  60. system_wdg_dev = NULL;
  61. }
  62. }