hal_icu_lld.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_icu_lld.h
  15. * @brief PLATFORM ICU subsystem low level driver header.
  16. *
  17. * @addtogroup ICU
  18. * @{
  19. */
  20. #ifndef HAL_ICU_LLD_H
  21. #define HAL_ICU_LLD_H
  22. #if (HAL_USE_ICU == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /*===========================================================================*/
  27. /* Driver pre-compile time settings. */
  28. /*===========================================================================*/
  29. /**
  30. * @name PLATFORM configuration options
  31. * @{
  32. */
  33. /**
  34. * @brief ICUD1 driver enable switch.
  35. * @details If set to @p TRUE the support for ICUD1 is included.
  36. * @note The default is @p FALSE.
  37. */
  38. #if !defined(PLATFORM_ICU_USE_ICU1) || defined(__DOXYGEN__)
  39. #define PLATFORM_ICU_USE_ICU1 FALSE
  40. #endif
  41. /** @} */
  42. /*===========================================================================*/
  43. /* Derived constants and error checks. */
  44. /*===========================================================================*/
  45. /*===========================================================================*/
  46. /* Driver data structures and types. */
  47. /*===========================================================================*/
  48. /**
  49. * @brief ICU driver mode.
  50. */
  51. typedef enum {
  52. ICU_INPUT_ACTIVE_HIGH = 0, /**< Trigger on rising edge. */
  53. ICU_INPUT_ACTIVE_LOW = 1 /**< Trigger on falling edge. */
  54. } icumode_t;
  55. /**
  56. * @brief ICU frequency type.
  57. */
  58. typedef uint32_t icufreq_t;
  59. /**
  60. * @brief ICU counter type.
  61. */
  62. typedef uint32_t icucnt_t;
  63. /**
  64. * @brief Driver configuration structure.
  65. * @note It could be empty on some architectures.
  66. */
  67. typedef struct {
  68. /**
  69. * @brief Driver mode.
  70. */
  71. icumode_t mode;
  72. /**
  73. * @brief Timer clock in Hz.
  74. * @note The low level can use assertions in order to catch invalid
  75. * frequency specifications.
  76. */
  77. icufreq_t frequency;
  78. /**
  79. * @brief Callback for pulse width measurement.
  80. */
  81. icucallback_t width_cb;
  82. /**
  83. * @brief Callback for cycle period measurement.
  84. */
  85. icucallback_t period_cb;
  86. /**
  87. * @brief Callback for timer overflow.
  88. */
  89. icucallback_t overflow_cb;
  90. /* End of the mandatory fields.*/
  91. } ICUConfig;
  92. /**
  93. * @brief Structure representing an ICU driver.
  94. */
  95. struct ICUDriver {
  96. /**
  97. * @brief Driver state.
  98. */
  99. icustate_t state;
  100. /**
  101. * @brief Current configuration data.
  102. */
  103. const ICUConfig *config;
  104. #if defined(ICU_DRIVER_EXT_FIELDS)
  105. ICU_DRIVER_EXT_FIELDS
  106. #endif
  107. /* End of the mandatory fields.*/
  108. };
  109. /*===========================================================================*/
  110. /* Driver macros. */
  111. /*===========================================================================*/
  112. /**
  113. * @brief Returns the width of the latest pulse.
  114. * @details The pulse width is defined as number of ticks between the start
  115. * edge and the stop edge.
  116. *
  117. * @param[in] icup pointer to the @p ICUDriver object
  118. * @return The number of ticks.
  119. *
  120. * @notapi
  121. */
  122. #define icu_lld_get_width(icup) 0
  123. /**
  124. * @brief Returns the width of the latest cycle.
  125. * @details The cycle width is defined as number of ticks between a start
  126. * edge and the next start edge.
  127. *
  128. * @param[in] icup pointer to the @p ICUDriver object
  129. * @return The number of ticks.
  130. *
  131. * @notapi
  132. */
  133. #define icu_lld_get_period(icup) 0
  134. /**
  135. * @brief Check on notifications status.
  136. *
  137. * @param[in] icup pointer to the @p ICUDriver object
  138. * @return The notifications status.
  139. * @retval false if notifications are not enabled.
  140. * @retval true if notifications are enabled.
  141. *
  142. * @notapi
  143. */
  144. #define icu_lld_are_notifications_enabled(icup) false
  145. /*===========================================================================*/
  146. /* External declarations. */
  147. /*===========================================================================*/
  148. #if (PLATFORM_ICU_USE_ICU1 == TRUE) && !defined(__DOXYGEN__)
  149. extern ICUDriver ICUD1;
  150. #endif
  151. #ifdef __cplusplus
  152. extern "C" {
  153. #endif
  154. void icu_lld_init(void);
  155. void icu_lld_start(ICUDriver *icup);
  156. void icu_lld_stop(ICUDriver *icup);
  157. void icu_lld_start_capture(ICUDriver *icup);
  158. bool icu_lld_wait_capture(ICUDriver *icup);
  159. void icu_lld_stop_capture(ICUDriver *icup);
  160. void icu_lld_enable_notifications(ICUDriver *icup);
  161. void icu_lld_disable_notifications(ICUDriver *icup);
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif /* HAL_USE_ICU == TRUE */
  166. #endif /* HAL_ICU_LLD_H */
  167. /** @} */