mbed_lp_ticker_api.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2015 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 "hal/lp_ticker_api.h"
  17. #if DEVICE_LPTICKER
  18. void lp_ticker_set_interrupt_wrapper(timestamp_t timestamp);
  19. static ticker_event_queue_t events = { 0 };
  20. static ticker_irq_handler_type irq_handler = ticker_irq_handler;
  21. static const ticker_interface_t lp_interface = {
  22. .init = lp_ticker_init,
  23. .read = lp_ticker_read,
  24. .disable_interrupt = lp_ticker_disable_interrupt,
  25. .clear_interrupt = lp_ticker_clear_interrupt,
  26. #if LPTICKER_DELAY_TICKS > 0
  27. .set_interrupt = lp_ticker_set_interrupt_wrapper,
  28. #else
  29. .set_interrupt = lp_ticker_set_interrupt,
  30. #endif
  31. .fire_interrupt = lp_ticker_fire_interrupt,
  32. .get_info = lp_ticker_get_info,
  33. };
  34. static const ticker_data_t lp_data = {
  35. .interface = &lp_interface,
  36. .queue = &events,
  37. };
  38. const ticker_data_t *get_lp_ticker_data(void)
  39. {
  40. return &lp_data;
  41. }
  42. ticker_irq_handler_type set_lp_ticker_irq_handler(ticker_irq_handler_type ticker_irq_handler)
  43. {
  44. ticker_irq_handler_type prev_irq_handler = irq_handler;
  45. irq_handler = ticker_irq_handler;
  46. return prev_irq_handler;
  47. }
  48. void lp_ticker_irq_handler(void)
  49. {
  50. if (irq_handler) {
  51. irq_handler(&lp_data);
  52. }
  53. }
  54. #endif