hal_gpt_lld.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_lld.h
  15. * @brief PLATFORM GPT subsystem low level driver header.
  16. *
  17. * @addtogroup GPT
  18. * @{
  19. */
  20. #ifndef HAL_GPT_LLD_H
  21. #define HAL_GPT_LLD_H
  22. #if (HAL_USE_GPT == 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 GPTD1 driver enable switch.
  35. * @details If set to @p TRUE the support for GPTD1 is included.
  36. * @note The default is @p FALSE.
  37. */
  38. #if !defined(PLATFORM_GPT_USE_GPT1) || defined(__DOXYGEN__)
  39. #define PLATFORM_GPT_USE_GPT1 FALSE
  40. #endif
  41. /** @} */
  42. /*===========================================================================*/
  43. /* Derived constants and error checks. */
  44. /*===========================================================================*/
  45. /*===========================================================================*/
  46. /* Driver data structures and types. */
  47. /*===========================================================================*/
  48. /**
  49. * @brief GPT frequency type.
  50. */
  51. typedef uint32_t gptfreq_t;
  52. /**
  53. * @brief GPT counter type.
  54. */
  55. typedef uint16_t gptcnt_t;
  56. /**
  57. * @brief Driver configuration structure.
  58. * @note It could be empty on some architectures.
  59. */
  60. typedef struct {
  61. /**
  62. * @brief Timer clock in Hz.
  63. * @note The low level can use assertions in order to catch invalid
  64. * frequency specifications.
  65. */
  66. gptfreq_t frequency;
  67. /**
  68. * @brief Timer callback pointer.
  69. * @note This callback is invoked on GPT counter events.
  70. */
  71. gptcallback_t callback;
  72. /* End of the mandatory fields.*/
  73. } GPTConfig;
  74. /**
  75. * @brief Structure representing a GPT driver.
  76. */
  77. struct GPTDriver {
  78. /**
  79. * @brief Driver state.
  80. */
  81. gptstate_t state;
  82. /**
  83. * @brief Current configuration data.
  84. */
  85. const GPTConfig *config;
  86. #if defined(GPT_DRIVER_EXT_FIELDS)
  87. GPT_DRIVER_EXT_FIELDS
  88. #endif
  89. /* End of the mandatory fields.*/
  90. };
  91. /*===========================================================================*/
  92. /* Driver macros. */
  93. /*===========================================================================*/
  94. /**
  95. * @brief Changes the interval of GPT peripheral.
  96. * @details This function changes the interval of a running GPT unit.
  97. * @pre The GPT unit must have been activated using @p gptStart().
  98. * @pre The GPT unit must have been running in continuous mode using
  99. * @p gptStartContinuous().
  100. * @post The GPT unit interval is changed to the new value.
  101. * @note The function has effect at the next cycle start.
  102. *
  103. * @param[in] gptp pointer to a @p GPTDriver object
  104. * @param[in] interval new cycle time in timer ticks
  105. * @notapi
  106. */
  107. #define gpt_lld_change_interval(gptp, interval) { \
  108. (void)gptp; \
  109. (void)interval; \
  110. }
  111. /*===========================================================================*/
  112. /* External declarations. */
  113. /*===========================================================================*/
  114. #if (PLATFORM_GPT_USE_GPT1 == TRUE) && !defined(__DOXYGEN__)
  115. extern GPTDriver GPTD1;
  116. #endif
  117. #ifdef __cplusplus
  118. extern "C" {
  119. #endif
  120. void gpt_lld_init(void);
  121. void gpt_lld_start(GPTDriver *gptp);
  122. void gpt_lld_stop(GPTDriver *gptp);
  123. void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval);
  124. void gpt_lld_stop_timer(GPTDriver *gptp);
  125. void gpt_lld_polled_delay(GPTDriver *gptp, gptcnt_t interval);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif /* HAL_USE_GPT == TRUE */
  130. #endif /* HAL_GPT_LLD_H */
  131. /** @} */