apm32f0xx_crs.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*!
  2. * @file apm32f0xx_crs.h
  3. *
  4. * @brief This file contains all the functions prototypes for the CRS firmware library
  5. *
  6. * @note It's only for APM32F072 and APM32F091 devices
  7. *
  8. * @version V1.0.3
  9. *
  10. * @date 2022-09-20
  11. *
  12. * @attention
  13. *
  14. * Copyright (C) 2020-2022 Geehy Semiconductor
  15. *
  16. * You may not use this file except in compliance with the
  17. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  18. *
  19. * The program is only for reference, which is distributed in the hope
  20. * that it will be useful and instructional for customers to develop
  21. * their software. Unless required by applicable law or agreed to in
  22. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  23. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  24. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  25. * and limitations under the License.
  26. */
  27. /* Define to prevent recursive inclusion */
  28. #ifndef __APM32F0XX_CRS_H
  29. #define __APM32F0XX_CRS_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* Includes */
  34. #include "apm32f0xx.h"
  35. /** @addtogroup APM32F0xx_StdPeriphDriver
  36. @{
  37. */
  38. /** @addtogroup CRS_Driver
  39. @{
  40. */
  41. /** @defgroup CRS_Macros Macros
  42. @{
  43. */
  44. /**@} end of group CRS_Macros */
  45. /** @defgroup CRS_Enumerations Enumerations
  46. @{
  47. */
  48. /**
  49. * @brief CRS_Interrupt_Sources
  50. */
  51. typedef enum
  52. {
  53. CRS_INT_SYNCOK = ((uint32_t)0x00000001), /*!<SYNC event OK interrupt */
  54. CRS_INT_SYNCWARN = ((uint32_t)0x00000002), /*!<SYNC warning interrupt */
  55. CRS_INT_ERR = ((uint32_t)0x00000004), /*!<Synchronization or trimming error interrupt */
  56. CRS_INT_ESYNC = ((uint32_t)0x00000008), /*!<Expected SYNC interrupt */
  57. CRS_INT_SYNCERR = ((uint32_t)0x00000100), /*!<SYNC error */
  58. CRS_INT_SYNCMISS = ((uint32_t)0x00000200), /*!<SYNC missed */
  59. CRS_INT_TRIMOVF = ((uint32_t)0x00000400), /*!<Trimming overflow or underflow */
  60. } CRS_INT_T;
  61. /**
  62. * @brief CRS_Flags
  63. */
  64. typedef enum
  65. {
  66. CRS_FLAG_SYNCOK = ((uint32_t)0x00000001), /*!<SYNC event OK flag */
  67. CRS_FLAG_SYNCWARN = ((uint32_t)0x00000002), /*!<SYNC warning flag */
  68. CRS_FLAG_ERR = ((uint32_t)0x00000004), /*!<Synchronization or trimming error flag */
  69. CRS_FLAG_ESYNC = ((uint32_t)0x00000008), /*!<Expected SYNC flag */
  70. CRS_FLAG_SYNCERR = ((uint32_t)0x00000100), /*!<SYNC error flag */
  71. CRS_FLAG_SYNCMISS = ((uint32_t)0x00000200), /*!<SYNC missed flag */
  72. CRS_FLAG_TRIMOVF = ((uint32_t)0x00000400), /*!<Trimming overflow or underflow falg */
  73. } CRS_FLAG_T;
  74. /**
  75. * @brief CRS_Synchro_Source
  76. */
  77. typedef enum
  78. {
  79. CRS_SYNC_SOURCE_GPIO = 0x00, /*!<GPIO selected as SYNC signal source */
  80. CRS_SYNC_SOURCE_LSE = 0x01, /*!<LSE selected as SYNC signal source */
  81. CRS_SYNC_SOURCE_USB = 0x02, /*!<USB SNFLG selected as SYNC signal source (default) */
  82. } CRS_SYNC_SOURCE_T;
  83. /**
  84. * @brief CRS_Synchro_Source
  85. */
  86. typedef enum
  87. {
  88. CRS_SYNC_DIV1 = 0x00, /*!<Synchro Signal not divided (default) */
  89. CRS_SYNC_DIV2 = 0x01, /*!<Synchro Signal divided by 2 */
  90. CRS_SYNC_DIV4 = 0x02, /*!<Synchro Signal divided by 4 */
  91. CRS_SYNC_DIV8 = 0x03, /*!<Synchro Signal divided by 8 */
  92. CRS_SYNC_DIV16 = 0x04, /*!<Synchro Signal divided by 16 */
  93. CRS_SYNC_DIV32 = 0x05, /*!<Synchro Signal divided by 32 */
  94. CRS_SYNC_DIV64 = 0x06, /*!<Synchro Signal divided by 64 */
  95. CRS_SYNC_DIV128 = 0x07, /*!<Synchro Signal divided by 128 */
  96. } CRS_SYNC_DIV_T;
  97. /**@} end of group CRS_Enumerations */
  98. /** @defgroup CRS_Structures Structures
  99. @{
  100. */
  101. /**
  102. * @brief CRS_SynchroPolarity
  103. */
  104. typedef enum
  105. {
  106. CRS_SYNC_POL_RISING, /*!<Synchro active on rising edge */
  107. CRS_SYNC_POL_FALLING /*!<Synchro active on falling edge */
  108. } CRS_SYNC_POL_T;
  109. /**@} end of group CRS_Structures */
  110. /** @defgroup CRS_Variables Variables
  111. @{
  112. */
  113. /**@} end of group CRS_Variables */
  114. /** @defgroup CRS_Functions Functions
  115. @{
  116. */
  117. /* Configuration of the CRS */
  118. void CRS_Reset(void);
  119. void CRS_AdjustHSI48CalibrationValue(uint8_t calibrationVal);
  120. void CRS_EnableFrequencyErrorCounter(void);
  121. void CRS_DisableFrequencyErrorCounter(void);
  122. void CRS_EnableAutomaticCalibration(void);
  123. void CRS_DisableAutomaticCalibration(void);
  124. void CRS_GenerateSoftwareSynchronization(void);
  125. void CRS_FrequencyErrorCounterReloadValue(uint16_t reloadVal);
  126. void CRS_ConfigFrequencyErrorLimit(uint8_t errLimitVal);
  127. void CRS_ConfigSynchronizationPrescaler(CRS_SYNC_DIV_T div);
  128. void CRS_ConfigSynchronizationSource(CRS_SYNC_SOURCE_T source);
  129. void CRS_ConfigSynchronizationPolarity(CRS_SYNC_POL_T polarity);
  130. uint32_t CRS_ReadReloadValue(void);
  131. uint32_t CRS_ReadHSI48CalibrationValue(void);
  132. uint32_t CRS_ReadFrequencyErrorValue(void);
  133. uint32_t CRS_ReadFrequencyErrorDirection(void);
  134. /* Interrupts and flags management functions */
  135. void CRS_EnableInterrupt(CRS_INT_T interrupt);
  136. void CRS_DisableInterrupt(CRS_INT_T interrupt);
  137. uint8_t CRS_ReadStatusFlag(CRS_FLAG_T flag);
  138. void CRS_ClearStatusFlag(CRS_FLAG_T flag);
  139. uint8_t CRS_ReadIntFlag(CRS_INT_T flag);
  140. void CRS_ClearIntFlag(CRS_INT_T intFlag);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif /* __APM32F0XX_CRS_H */
  145. /**@} end of group CRS_Functions */
  146. /**@} end of group CRS_Driver */
  147. /**@} end of group APM32F0xx_StdPeriphDriver */