evtimer.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 evtimer.h
  15. * @brief Events Generator Timer structures and macros.
  16. *
  17. * @addtogroup event_timer
  18. * @{
  19. */
  20. #ifndef EVTIMER_H
  21. #define EVTIMER_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 dependencies check.
  33. */
  34. #if !CH_CFG_USE_EVENTS
  35. #error "Event Timers require CH_CFG_USE_EVENTS"
  36. #endif
  37. /*===========================================================================*/
  38. /* Module data structures and types. */
  39. /*===========================================================================*/
  40. /**
  41. * @brief Type of a event timer structure.
  42. */
  43. typedef struct {
  44. virtual_timer_t et_vt;
  45. event_source_t et_es;
  46. systime_t et_interval;
  47. } event_timer_t;
  48. /*===========================================================================*/
  49. /* Module macros. */
  50. /*===========================================================================*/
  51. /*===========================================================================*/
  52. /* External declarations. */
  53. /*===========================================================================*/
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. void evtObjectInit(event_timer_t *etp, systime_t time);
  58. void evtStart(event_timer_t *etp);
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. /*===========================================================================*/
  63. /* Module inline functions. */
  64. /*===========================================================================*/
  65. /**
  66. * @brief Stops the timer.
  67. * @details If the timer was already stopped then the function has no effect.
  68. *
  69. * @param[in] etp pointer to an initialized @p event_timer_t structure.
  70. */
  71. static inline void evtStop(event_timer_t *etp) {
  72. chVTReset(&etp->et_vt);
  73. }
  74. #endif /* EVTIMER_H */
  75. /** @} */