wdog.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /****************************************************************************
  2. * sched/wdog/wdog.h
  3. *
  4. * Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __SCHED_WDOG_WDOG_H
  36. #define __SCHED_WDOG_WDOG_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <stdint.h>
  42. #include <stdbool.h>
  43. #include <nuttx/compiler.h>
  44. #include <nuttx/clock.h>
  45. #include <nuttx/wdog.h>
  46. /****************************************************************************
  47. * Pre-processor Definitions
  48. ****************************************************************************/
  49. /****************************************************************************
  50. * Name: wd_elapse
  51. *
  52. * Description:
  53. * This function is used to get time-elapse from last time wd_timer() be
  54. * called. In case of CONFIG_SCHED_TICKLESS configured, wd_timer() may
  55. * take lots of ticks, during this time, wd_start()/wd_cancel() may
  56. * called, so we need wd_elapse() to correct the delay/lag.
  57. *
  58. ****************************************************************************/
  59. #ifdef CONFIG_SCHED_TICKLESS
  60. # define wd_elapse() (clock_systimer() - g_wdtickbase)
  61. #else
  62. # define wd_elapse() (0)
  63. #endif
  64. /****************************************************************************
  65. * Public Data
  66. ****************************************************************************/
  67. #ifdef __cplusplus
  68. #define EXTERN extern "C"
  69. extern "C"
  70. {
  71. #else
  72. #define EXTERN extern
  73. #endif
  74. /* The g_wdfreelist data structure is a singly linked list of watchdogs
  75. * available to the system for delayed function use.
  76. */
  77. extern sq_queue_t g_wdfreelist;
  78. /* The g_wdactivelist data structure is a singly linked list ordered by
  79. * watchdog expiration time. When watchdog timers expire,the functions on
  80. * this linked list are removed and the function is called.
  81. */
  82. extern sq_queue_t g_wdactivelist;
  83. /* This is the number of free, pre-allocated watchdog structures in the
  84. * g_wdfreelist. This value is used to enforce a reserve for interrupt
  85. * handlers.
  86. */
  87. extern uint16_t g_wdnfree;
  88. /* This is wdog tickbase, for wd_gettime() may called many times
  89. * between 2 times of wd_timer(), we use it to update wd_gettime().
  90. */
  91. #ifdef CONFIG_SCHED_TICKLESS
  92. extern clock_t g_wdtickbase;
  93. #endif
  94. /****************************************************************************
  95. * Public Function Prototypes
  96. ****************************************************************************/
  97. /****************************************************************************
  98. * Name: wd_initialize
  99. *
  100. * Description:
  101. * This function initializes the watchdog data structures
  102. *
  103. * Input Parameters:
  104. * None
  105. *
  106. * Returned Value:
  107. * None
  108. *
  109. * Assumptions:
  110. * This function must be called early in the initialization sequence
  111. * before the timer interrupt is attached and before any watchdog
  112. * services are used.
  113. *
  114. ****************************************************************************/
  115. void weak_function wd_initialize(void);
  116. /****************************************************************************
  117. * Name: wd_timer
  118. *
  119. * Description:
  120. * This function is called from the timer interrupt handler to determine
  121. * if it is time to execute a watchdog function. If so, the watchdog
  122. * function will be executed in the context of the timer interrupt
  123. * handler.
  124. *
  125. * Input Parameters:
  126. * ticks - If CONFIG_SCHED_TICKLESS is defined then the number of ticks
  127. * in the interval that just expired is provided. Otherwise,
  128. * this function is called on each timer interrupt and a value of one
  129. * is implicit.
  130. *
  131. * Returned Value:
  132. * If CONFIG_SCHED_TICKLESS is defined then the number of ticks for the
  133. * next delay is provided (zero if no delay). Otherwise, this function
  134. * has no returned value.
  135. *
  136. * Assumptions:
  137. * Called from interrupt handler logic with interrupts disabled.
  138. *
  139. ****************************************************************************/
  140. #ifdef CONFIG_SCHED_TICKLESS
  141. unsigned int wd_timer(int ticks);
  142. #else
  143. void wd_timer(void);
  144. #endif
  145. /****************************************************************************
  146. * Name: wd_recover
  147. *
  148. * Description:
  149. * This function is called from task_recover() when a task is deleted via
  150. * task_delete() or via pthread_cancel(). It checks if the deleted task
  151. * is waiting for a timed event and if so cancels the timeout
  152. *
  153. * Input Parameters:
  154. * tcb - The TCB of the terminated task or thread
  155. *
  156. * Returned Value:
  157. * None.
  158. *
  159. * Assumptions:
  160. * This function is called from task deletion logic in a safe context.
  161. *
  162. ****************************************************************************/
  163. struct tcb_s;
  164. void wd_recover(FAR struct tcb_s *tcb);
  165. #undef EXTERN
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif /* __SCHED_WDOG_WDOG_H */