hal_gpt.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_gpt.h
  15. * @brief GPT Driver macros and structures.
  16. *
  17. * @addtogroup GPT
  18. * @{
  19. */
  20. #ifndef HAL_GPT_H
  21. #define HAL_GPT_H
  22. #if (HAL_USE_GPT == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /*===========================================================================*/
  27. /* Driver pre-compile time settings. */
  28. /*===========================================================================*/
  29. /*===========================================================================*/
  30. /* Derived constants and error checks. */
  31. /*===========================================================================*/
  32. /*===========================================================================*/
  33. /* Driver data structures and types. */
  34. /*===========================================================================*/
  35. /**
  36. * @brief Driver state machine possible states.
  37. */
  38. typedef enum {
  39. GPT_UNINIT = 0, /**< Not initialized. */
  40. GPT_STOP = 1, /**< Stopped. */
  41. GPT_READY = 2, /**< Ready. */
  42. GPT_CONTINUOUS = 3, /**< Active in continuous mode. */
  43. GPT_ONESHOT = 4 /**< Active in one shot mode. */
  44. } gptstate_t;
  45. /**
  46. * @brief Type of a structure representing a GPT driver.
  47. */
  48. typedef struct GPTDriver GPTDriver;
  49. /**
  50. * @brief GPT notification callback type.
  51. *
  52. * @param[in] gptp pointer to a @p GPTDriver object
  53. */
  54. typedef void (*gptcallback_t)(GPTDriver *gptp);
  55. #include "hal_gpt_lld.h"
  56. /*===========================================================================*/
  57. /* Driver macros. */
  58. /*===========================================================================*/
  59. /**
  60. * @brief Changes the interval of GPT peripheral.
  61. * @details This function changes the interval of a running GPT unit.
  62. * @pre The GPT unit must be running in continuous mode.
  63. * @post The GPT unit interval is changed to the new value.
  64. *
  65. * @param[in] gptp pointer to a @p GPTDriver object
  66. * @param[in] interval new cycle time in timer ticks
  67. *
  68. * @iclass
  69. */
  70. #define gptChangeIntervalI(gptp, interval) { \
  71. gpt_lld_change_interval(gptp, interval); \
  72. }
  73. /**
  74. * @brief Returns the interval of GPT peripheral.
  75. * @pre The GPT unit must be running in continuous mode.
  76. *
  77. * @param[in] gptp pointer to a @p GPTDriver object
  78. * @return The current interval.
  79. *
  80. * @xclass
  81. */
  82. #define gptGetIntervalX(gptp) gpt_lld_get_interval(gptp)
  83. /**
  84. * @brief Returns the counter value of GPT peripheral.
  85. * @pre The GPT unit must be running in continuous mode.
  86. * @note The nature of the counter is not defined, it may count upward
  87. * or downward, it could be continuously running or not.
  88. *
  89. * @param[in] gptp pointer to a @p GPTDriver object
  90. * @return The current counter value.
  91. *
  92. * @xclass
  93. */
  94. #define gptGetCounterX(gptp) gpt_lld_get_counter(gptp)
  95. /*===========================================================================*/
  96. /* External declarations. */
  97. /*===========================================================================*/
  98. #ifdef __cplusplus
  99. extern "C" {
  100. #endif
  101. void gptInit(void);
  102. void gptObjectInit(GPTDriver *gptp);
  103. void gptStart(GPTDriver *gptp, const GPTConfig *config);
  104. void gptStop(GPTDriver *gptp);
  105. void gptStartContinuous(GPTDriver *gptp, gptcnt_t interval);
  106. void gptStartContinuousI(GPTDriver *gptp, gptcnt_t interval);
  107. void gptChangeInterval(GPTDriver *gptp, gptcnt_t interval);
  108. void gptStartOneShot(GPTDriver *gptp, gptcnt_t interval);
  109. void gptStartOneShotI(GPTDriver *gptp, gptcnt_t interval);
  110. void gptStopTimer(GPTDriver *gptp);
  111. void gptStopTimerI(GPTDriver *gptp);
  112. void gptPolledDelay(GPTDriver *gptp, gptcnt_t interval);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif /* HAL_USE_GPT == TRUE */
  117. #endif /* HAL_GPT_H */
  118. /** @} */