wdt_sample.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #include <rtthread.h>
  16. #include <rtdevice.h>
  17. #ifdef RT_USING_WDT
  18. static rt_device_t wdt_dev = RT_NULL;
  19. static int wdt_sample(void)
  20. {
  21. rt_err_t ret = RT_EOK;
  22. rt_uint32_t timeout = 5;
  23. wdt_dev = rt_device_find("wdt0");
  24. if(!wdt_dev) {
  25. rt_kprintf("find wdt0 failed\n");
  26. return RT_ERROR;
  27. }
  28. ret = rt_device_control(wdt_dev, RT_DEVICE_CTRL_WDT_SET_TIMEOUT, &timeout);
  29. if(ret != RT_EOK) {
  30. rt_kprintf("set timeout fail\n");
  31. return RT_ERROR;
  32. }
  33. ret = rt_device_control(wdt_dev, RT_DEVICE_CTRL_WDT_START, RT_NULL);
  34. if(ret != RT_EOK) {
  35. rt_kprintf("start fail\n");
  36. return RT_ERROR;
  37. }
  38. return ret;
  39. }
  40. MSH_CMD_EXPORT(wdt_sample, wdt feed);
  41. static int wdt_feed(void)
  42. {
  43. rt_err_t ret = RT_EOK;
  44. if(wdt_dev == RT_NULL) {
  45. rt_kprintf("wdt0 null\n");
  46. }
  47. else {
  48. ret = rt_device_control(wdt_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, RT_NULL);
  49. if(ret != RT_EOK) {
  50. rt_kprintf("wdt keepalive fail\n");
  51. }
  52. else {
  53. rt_kprintf("keepalive\n");
  54. }
  55. }
  56. }
  57. MSH_CMD_EXPORT(wdt_feed, wdt test);
  58. #endif