wdt_feed.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-02-22 airm2m first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. static char device_name[] = "wdt";
  13. static rt_device_t wdg_dev;
  14. static struct rt_work wdt_feed;
  15. static void wdt_feed_func(struct rt_work *work, void *work_data)
  16. {
  17. rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, RT_NULL);
  18. rt_work_submit(&wdt_feed, 1200);
  19. }
  20. static int wdt_feed_init(void)
  21. {
  22. rt_err_t ret = RT_EOK;
  23. rt_uint32_t timeout = 2;
  24. wdg_dev = rt_device_find(device_name);
  25. if (!wdg_dev)
  26. {
  27. rt_kprintf("find %s failed!\n", device_name);
  28. return RT_ERROR;
  29. }
  30. ret = rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_SET_TIMEOUT, &timeout);
  31. if (ret != RT_EOK)
  32. {
  33. rt_kprintf("set %s timeout failed!\n", device_name);
  34. return RT_ERROR;
  35. }
  36. ret = rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_START, RT_NULL);
  37. if (ret != RT_EOK)
  38. {
  39. rt_kprintf("start %s failed!\n", device_name);
  40. return -RT_ERROR;
  41. }
  42. rt_work_init(&wdt_feed, wdt_feed_func, RT_NULL);
  43. rt_work_submit(&wdt_feed, 1200);
  44. return RT_EOK;
  45. }
  46. INIT_COMPONENT_EXPORT(wdt_feed_init);