Naze32 clone with Frysky receiver
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ticker_api.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifndef MBED_TICKER_API_H
  17. #define MBED_TICKER_API_H
  18. #include "device.h"
  19. typedef uint32_t timestamp_t;
  20. /** Ticker's event structure
  21. */
  22. typedef struct ticker_event_s {
  23. timestamp_t timestamp; /**< Event's timestamp */
  24. uint32_t id; /**< TimerEvent object */
  25. struct ticker_event_s *next; /**< Next event in the queue */
  26. } ticker_event_t;
  27. typedef void (*ticker_event_handler)(uint32_t id);
  28. /** Ticker's interface structure - required API for a ticker
  29. */
  30. typedef struct {
  31. void (*init)(void); /**< Init function */
  32. uint32_t (*read)(void); /**< Read function */
  33. void (*disable_interrupt)(void); /**< Disable interrupt function */
  34. void (*clear_interrupt)(void); /**< Clear interrupt function */
  35. void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */
  36. } ticker_interface_t;
  37. /** Tickers events queue structure
  38. */
  39. typedef struct {
  40. ticker_event_handler event_handler; /**< Event handler */
  41. ticker_event_t *head; /**< A pointer to head */
  42. } ticker_event_queue_t;
  43. /** Tickers data structure
  44. */
  45. typedef struct {
  46. const ticker_interface_t *interface; /**< Ticker's interface */
  47. ticker_event_queue_t *queue; /**< Ticker's events queue */
  48. } ticker_data_t;
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. /** Initialize a ticker and sets the event handler
  53. *
  54. * @param data The ticker's data
  55. * @param handler A handler to be set
  56. */
  57. void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler);
  58. /** Irq handler which goes through the events to trigger events in the past.
  59. *
  60. * @param data The ticker's data
  61. */
  62. void ticker_irq_handler(const ticker_data_t *const data);
  63. /** Remove an event from the queue
  64. *
  65. * @param data The ticker's data
  66. * @param obj The event's queue to be removed
  67. */
  68. void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj);
  69. /** Insert an event from the queue
  70. *
  71. * @param data The ticker's data
  72. * @param obj The event's queue to be removed
  73. * @param timestamp The event's timestamp
  74. * @param id The event object
  75. */
  76. void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id);
  77. /** Read the current ticker's timestamp
  78. *
  79. * @param data The ticker's data
  80. * @return The current timestamp
  81. */
  82. timestamp_t ticker_read(const ticker_data_t *const data);
  83. /** Read the next event's timestamp
  84. *
  85. * @param data The ticker's data
  86. * @return 1 if timestamp is pending event, 0 if there's no event pending
  87. */
  88. int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp);
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif