TimerEvent.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2006-2013 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MBED_TIMEREVENT_H
  17. #define MBED_TIMEREVENT_H
  18. #include "hal/ticker_api.h"
  19. #include "hal/us_ticker_api.h"
  20. #include "platform/NonCopyable.h"
  21. namespace mbed {
  22. /** \addtogroup drivers */
  23. /** Base abstraction for timer interrupts
  24. *
  25. * @note Synchronization level: Interrupt safe
  26. * @ingroup drivers
  27. */
  28. class TimerEvent : private NonCopyable<TimerEvent> {
  29. public:
  30. TimerEvent();
  31. TimerEvent(const ticker_data_t *data);
  32. /** The handler registered with the underlying timer interrupt
  33. *
  34. * @param id Timer Event ID
  35. */
  36. static void irq(uint32_t id);
  37. /** Destruction removes it...
  38. */
  39. virtual ~TimerEvent();
  40. protected:
  41. // The handler called to service the timer event of the derived class
  42. virtual void handler() = 0;
  43. /** Set relative timestamp of the internal event.
  44. * @param timestamp event's us timestamp
  45. *
  46. * @warning
  47. * Do not insert more than one timestamp.
  48. * The same @a event object is used for every @a insert/insert_absolute call.
  49. *
  50. * @warning
  51. * Ticker's present timestamp is used for reference. For timestamps
  52. * from the past the event is scheduled after ticker's overflow.
  53. * For reference @see convert_timestamp
  54. */
  55. void insert(timestamp_t timestamp);
  56. /** Set absolute timestamp of the internal event.
  57. * @param timestamp event's us timestamp
  58. *
  59. * @warning
  60. * Do not insert more than one timestamp.
  61. * The same @a event object is used for every @a insert/insert_absolute call.
  62. */
  63. void insert_absolute(us_timestamp_t timestamp);
  64. /** Remove timestamp.
  65. */
  66. void remove();
  67. ticker_event_t event;
  68. const ticker_data_t *_ticker_data;
  69. };
  70. } // namespace mbed
  71. #endif