1
0

watchdog.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * File : watchdog.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2012-2014, Shanghai Real-Thread Electronic Technology Co.,Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2012-09-12 heyuanjie87 first version.
  23. * 2014-03-04 Bernard code cleanup
  24. */
  25. #include <drivers/watchdog.h>
  26. /* RT-Thread Device Interface */
  27. /*
  28. * This function initializes serial
  29. */
  30. static rt_err_t rt_watchdog_init(struct rt_device *dev)
  31. {
  32. rt_watchdog_t *wtd;
  33. RT_ASSERT(dev != RT_NULL);
  34. wtd = (rt_watchdog_t *)dev;
  35. if (wtd->ops->init)
  36. {
  37. return (wtd->ops->init(wtd));
  38. }
  39. return (-RT_ENOSYS);
  40. }
  41. static rt_err_t rt_watchdog_open(struct rt_device *dev, rt_uint16_t oflag)
  42. {
  43. return (RT_EOK);
  44. }
  45. static rt_err_t rt_watchdog_close(struct rt_device *dev)
  46. {
  47. rt_watchdog_t *wtd;
  48. RT_ASSERT(dev != RT_NULL);
  49. wtd = (rt_watchdog_t *)dev;
  50. if (wtd->ops->control(wtd, RT_DEVICE_CTRL_WDT_STOP, RT_NULL) != RT_EOK)
  51. {
  52. rt_kprintf(" This watchdog can not be stoped\n");
  53. return (-RT_ERROR);
  54. }
  55. return (RT_EOK);
  56. }
  57. static rt_err_t rt_watchdog_control(struct rt_device *dev,
  58. rt_uint8_t cmd,
  59. void *args)
  60. {
  61. rt_watchdog_t *wtd;
  62. RT_ASSERT(dev != RT_NULL);
  63. wtd = (rt_watchdog_t *)dev;
  64. return (wtd->ops->control(wtd, cmd, args));
  65. }
  66. /**
  67. * This function register a watchdog device
  68. */
  69. rt_err_t rt_hw_watchdog_register(struct rt_watchdog_device *wtd,
  70. const char *name,
  71. rt_uint32_t flag,
  72. void *data)
  73. {
  74. struct rt_device *device;
  75. RT_ASSERT(wtd != RT_NULL);
  76. device = &(wtd->parent);
  77. device->type = RT_Device_Class_Miscellaneous;
  78. device->rx_indicate = RT_NULL;
  79. device->tx_complete = RT_NULL;
  80. device->init = rt_watchdog_init;
  81. device->open = rt_watchdog_open;
  82. device->close = rt_watchdog_close;
  83. device->read = RT_NULL;
  84. device->write = RT_NULL;
  85. device->control = rt_watchdog_control;
  86. device->user_data = data;
  87. /* register a character device */
  88. return rt_device_register(device, name, flag);
  89. }