mbed_us_ticker_api.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/us_ticker_api.h"
  17. static ticker_event_queue_t events = { 0 };
  18. static ticker_irq_handler_type irq_handler = ticker_irq_handler;
  19. static const ticker_interface_t us_interface = {
  20. .init = us_ticker_init,
  21. .read = us_ticker_read,
  22. .disable_interrupt = us_ticker_disable_interrupt,
  23. .clear_interrupt = us_ticker_clear_interrupt,
  24. .set_interrupt = us_ticker_set_interrupt,
  25. .fire_interrupt = us_ticker_fire_interrupt,
  26. .get_info = us_ticker_get_info,
  27. };
  28. static const ticker_data_t us_data = {
  29. .interface = &us_interface,
  30. .queue = &events
  31. };
  32. const ticker_data_t *get_us_ticker_data(void)
  33. {
  34. return &us_data;
  35. }
  36. ticker_irq_handler_type set_us_ticker_irq_handler(ticker_irq_handler_type ticker_irq_handler)
  37. {
  38. ticker_irq_handler_type prev_irq_handler = irq_handler;
  39. irq_handler = ticker_irq_handler;
  40. return prev_irq_handler;
  41. }
  42. void us_ticker_irq_handler(void)
  43. {
  44. if (irq_handler) {
  45. irq_handler(&us_data);
  46. }
  47. }