TimerEvent.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "drivers/TimerEvent.h"
  17. #include "cmsis.h"
  18. #include <stddef.h>
  19. #include "hal/ticker_api.h"
  20. #include "hal/us_ticker_api.h"
  21. namespace mbed {
  22. TimerEvent::TimerEvent() : event(), _ticker_data(get_us_ticker_data())
  23. {
  24. ticker_set_handler(_ticker_data, (&TimerEvent::irq));
  25. }
  26. TimerEvent::TimerEvent(const ticker_data_t *data) : event(), _ticker_data(data)
  27. {
  28. ticker_set_handler(_ticker_data, (&TimerEvent::irq));
  29. }
  30. void TimerEvent::irq(uint32_t id)
  31. {
  32. TimerEvent *timer_event = (TimerEvent *)id;
  33. timer_event->handler();
  34. }
  35. TimerEvent::~TimerEvent()
  36. {
  37. remove();
  38. }
  39. // insert in to linked list
  40. void TimerEvent::insert(timestamp_t timestamp)
  41. {
  42. ticker_insert_event(_ticker_data, &event, timestamp, (uint32_t)this);
  43. }
  44. void TimerEvent::insert_absolute(us_timestamp_t timestamp)
  45. {
  46. ticker_insert_event_us(_ticker_data, &event, timestamp, (uint32_t)this);
  47. }
  48. void TimerEvent::remove()
  49. {
  50. ticker_remove_event(_ticker_data, &event);
  51. }
  52. } // namespace mbed