Ticker.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/Ticker.h"
  17. #include "drivers/TimerEvent.h"
  18. #include "platform/FunctionPointer.h"
  19. #include "hal/ticker_api.h"
  20. #include "platform/mbed_critical.h"
  21. namespace mbed {
  22. void Ticker::detach()
  23. {
  24. core_util_critical_section_enter();
  25. remove();
  26. // unlocked only if we were attached (we locked it) and this is not low power ticker
  27. if (_function && _lock_deepsleep) {
  28. sleep_manager_unlock_deep_sleep();
  29. }
  30. _function = 0;
  31. core_util_critical_section_exit();
  32. }
  33. void Ticker::setup(us_timestamp_t t)
  34. {
  35. core_util_critical_section_enter();
  36. remove();
  37. _delay = t;
  38. insert_absolute(_delay + ticker_read_us(_ticker_data));
  39. core_util_critical_section_exit();
  40. }
  41. void Ticker::handler()
  42. {
  43. insert_absolute(event.timestamp + _delay);
  44. if (_function) {
  45. _function();
  46. }
  47. }
  48. } // namespace mbed