evtimer.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.c
  15. * @brief Events Generator Timer code.
  16. *
  17. * @addtogroup event_timer
  18. * @{
  19. */
  20. #include "ch.h"
  21. #include "evtimer.h"
  22. /*===========================================================================*/
  23. /* Module local definitions. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Module exported variables. */
  27. /*===========================================================================*/
  28. /*===========================================================================*/
  29. /* Module local types. */
  30. /*===========================================================================*/
  31. /*===========================================================================*/
  32. /* Module local variables. */
  33. /*===========================================================================*/
  34. /*===========================================================================*/
  35. /* Module local functions. */
  36. /*===========================================================================*/
  37. static void tmrcb(void *p) {
  38. event_timer_t *etp = p;
  39. chSysLockFromISR();
  40. chEvtBroadcastI(&etp->et_es);
  41. chVTDoSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
  42. chSysUnlockFromISR();
  43. }
  44. /*===========================================================================*/
  45. /* Module exported functions. */
  46. /*===========================================================================*/
  47. /**
  48. * @brief Initializes an @p event_timer_t structure.
  49. *
  50. * @param[out] etp the @p event_timer_t structure to be initialized
  51. * @param[in] time the interval in system ticks
  52. */
  53. void evtObjectInit(event_timer_t *etp, systime_t time) {
  54. chEvtObjectInit(&etp->et_es);
  55. chVTObjectInit(&etp->et_vt);
  56. etp->et_interval = time;
  57. }
  58. /**
  59. * @brief Starts the timer
  60. * @details If the timer was already running then the function has no effect.
  61. *
  62. * @param[in] etp pointer to an initialized @p event_timer_t structure.
  63. */
  64. void evtStart(event_timer_t *etp) {
  65. chVTSet(&etp->et_vt, etp->et_interval, tmrcb, etp);
  66. }
  67. /** @} */