osal_vt.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file osal_vt.h
  15. * @brief OSAL Virtual Timers module header.
  16. *
  17. * @addtogroup OSAL_VT
  18. * @{
  19. */
  20. #ifndef _OSAL_VT_H_
  21. #define _OSAL_VT_H_
  22. /*===========================================================================*/
  23. /* Module constants. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Module pre-compile time settings. */
  27. /*===========================================================================*/
  28. /*===========================================================================*/
  29. /* Derived constants and error checks. */
  30. /*===========================================================================*/
  31. /*===========================================================================*/
  32. /* Module data structures and types. */
  33. /*===========================================================================*/
  34. /**
  35. * @brief Type of a Virtual Timer callback function.
  36. */
  37. typedef void (*vtfunc_t)(void *);
  38. /**
  39. * @brief Type of a Virtual Timer structure.
  40. */
  41. typedef struct virtual_timer virtual_timer_t;
  42. /**
  43. * @brief Virtual timers list header.
  44. * @note The content of this structure is not part of the API and should
  45. * not be relied upon. Implementers may define this structure in
  46. * an entirely different way.
  47. * @note The delta list is implemented as a double link bidirectional list
  48. * in order to make the unlink time constant, the reset of a virtual
  49. * timer is often used in the code.
  50. */
  51. typedef struct {
  52. virtual_timer_t *vt_next; /**< @brief Next timer in the timers
  53. list. */
  54. virtual_timer_t *vt_prev; /**< @brief Last timer in the timers
  55. list. */
  56. sysinterval_t vt_delta; /**< @brief Must be initialized to -1. */
  57. volatile systime_t vt_systime; /**< @brief System Time counter. */
  58. } virtual_timers_list_t;
  59. /**
  60. * @extends virtual_timers_list_t
  61. *
  62. * @brief Virtual Timer descriptor structure.
  63. * @note The content of this structure is not part of the API and should
  64. * not be relied upon. Implementers may define this structure in
  65. * an entirely different way.
  66. */
  67. struct virtual_timer {
  68. virtual_timer_t *vt_next; /**< @brief Next timer in the timers
  69. list. */
  70. virtual_timer_t *vt_prev; /**< @brief Previous timer in the timers
  71. list. */
  72. sysinterval_t vt_delta; /**< @brief Time delta before timeout. */
  73. vtfunc_t vt_func; /**< @brief Timer callback function
  74. pointer. */
  75. void *vt_par; /**< @brief Timer callback function
  76. parameter. */
  77. };
  78. /*===========================================================================*/
  79. /* Module macros. */
  80. /*===========================================================================*/
  81. /*===========================================================================*/
  82. /* External declarations. */
  83. /*===========================================================================*/
  84. #if !defined(__DOXYGEN__)
  85. extern virtual_timers_list_t vtlist;
  86. #endif
  87. #ifdef __cplusplus
  88. extern "C" {
  89. #endif
  90. void vtInit(void);
  91. bool vtIsArmedI(virtual_timer_t *vtp);
  92. void vtDoTickI(void);
  93. void vtSetI(virtual_timer_t *vtp, sysinterval_t timeout,
  94. vtfunc_t vtfunc, void *par);
  95. void vtResetI(virtual_timer_t *vtp);
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. /*===========================================================================*/
  100. /* Module inline functions. */
  101. /*===========================================================================*/
  102. #endif /* _OSAL_VT_H_ */
  103. /** @} */