wdog.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /****************************************************************************
  2. * include/nuttx/wdog.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_NUTTX_WDOG_H
  21. #define __INCLUDE_NUTTX_WDOG_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <stdint.h>
  27. #include <queue.h>
  28. /****************************************************************************
  29. * Pre-processor Definitions
  30. ****************************************************************************/
  31. /* Watchdog Definitions *****************************************************/
  32. /* Flag bits for the flags field of struct wdog_s */
  33. #define WDOGF_ACTIVE (1 << 0) /* Bit 0: 1=Watchdog is actively timing */
  34. #define WDOG_SETACTIVE(w) do { (w)->flags |= WDOGF_ACTIVE; } while (0)
  35. #define WDOG_CLRACTIVE(w) do { (w)->flags &= ~WDOGF_ACTIVE; } while (0)
  36. #define WDOG_ISACTIVE(w) (((w)->flags & WDOGF_ACTIVE) != 0)
  37. /****************************************************************************
  38. * Public Type Declarations
  39. ****************************************************************************/
  40. /* The arguments are passed as scalar wdparm_t values. For systems where
  41. * the sizeof(pointer) < sizeof(uint32_t), the following union defines the
  42. * alignment of the pointer within the uint32_t. For example, the SDCC
  43. * MCS51 general pointer is 24-bits, but uint32_t is 32-bits (of course).
  44. *
  45. * We always have sizeof(pointer) <= sizeof(uintptr_t) by definition.
  46. */
  47. #if UINTPTR_MAX >= UINT32_MAX
  48. typedef uintptr_t wdparm_t;
  49. #else
  50. typedef uint32_t wdparm_t;
  51. #endif
  52. /* This is the form of the function that is called when the
  53. * watchdog function expires.
  54. */
  55. typedef CODE void (*wdentry_t)(wdparm_t arg);
  56. /* This is the internal representation of the watchdog timer structure. */
  57. struct wdog_s
  58. {
  59. FAR struct wdog_s *next; /* Support for singly linked lists. */
  60. wdentry_t func; /* Function to execute when delay expires */
  61. #ifdef CONFIG_PIC
  62. FAR void *picbase; /* PIC base address */
  63. #endif
  64. int lag; /* Timer associated with the delay */
  65. uint8_t flags; /* See WDOGF_* definitions above */
  66. wdparm_t arg; /* Callback argument */
  67. };
  68. /****************************************************************************
  69. * Pubic Function Prototypes
  70. ****************************************************************************/
  71. #ifdef __cplusplus
  72. #define EXTERN extern "C"
  73. extern "C"
  74. {
  75. #else
  76. #define EXTERN extern
  77. #endif
  78. /****************************************************************************
  79. * Name: wd_start
  80. *
  81. * Description:
  82. * This function adds a watchdog timer to the actuve timer queue. The
  83. * specified watchdog function at 'wdentry' will be called from the
  84. * interrupt level after the specified number of ticks has elapsed.
  85. * Watchdog timers may be started from the interrupt level.
  86. *
  87. * Watchdog timers execute in the address environment that was in effect
  88. * when wd_start() is called.
  89. *
  90. * Watchdog timers execute only once.
  91. *
  92. * To replace either the timeout delay or the function to be executed,
  93. * call wd_start again with the same wdog; only the most recent wdStart()
  94. * on a given watchdog ID has any effect.
  95. *
  96. * Input Parameters:
  97. * wdog - Watchdog ID
  98. * delay - Delay count in clock ticks
  99. * wdentry - Function to call on timeout
  100. * arg - Parameter to pass to wdentry.
  101. *
  102. * NOTE: The parameter must be of type wdparm_t.
  103. *
  104. * Returned Value:
  105. * Zero (OK) is returned on success; a negated errno value is return to
  106. * indicate the nature of any failure.
  107. *
  108. * Assumptions:
  109. * The watchdog routine runs in the context of the timer interrupt handler
  110. * and is subject to all ISR restrictions.
  111. *
  112. ****************************************************************************/
  113. int wd_start(FAR struct wdog_s *wdog, int32_t delay,
  114. wdentry_t wdentry, wdparm_t arg);
  115. /****************************************************************************
  116. * Name: wd_cancel
  117. *
  118. * Description:
  119. * This function cancels a currently running watchdog timer. Watchdog
  120. * timers may be cancelled from the interrupt level.
  121. *
  122. * Input Parameters:
  123. * wdog - ID of the watchdog to cancel.
  124. *
  125. * Returned Value:
  126. * Zero (OK) is returned on success; A negated errno value is returned to
  127. * indicate the nature of any failure.
  128. *
  129. ****************************************************************************/
  130. int wd_cancel(FAR struct wdog_s *wdog);
  131. /****************************************************************************
  132. * Name: wd_gettime
  133. *
  134. * Description:
  135. * This function returns the time remaining before the specified watchdog
  136. * timer expires.
  137. *
  138. * Input Parameters:
  139. * wdog - watchdog ID
  140. *
  141. * Returned Value:
  142. * The time in system ticks remaining until the watchdog time expires.
  143. * Zero means either that wdog is not valid or that the wdog has already
  144. * expired.
  145. *
  146. ****************************************************************************/
  147. int wd_gettime(FAR struct wdog_s *wdog);
  148. #undef EXTERN
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* __INCLUDE_NUTTX_WDOG_H */