stm32f0xx_crs.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_crs.h
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 05-December-2014
  7. * @brief This file contains all the functions prototypes for the CRS firmware
  8. * library, applicable only for STM32F042 and STM32F072 devices.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F0XX_CRS_H
  30. #define __STM32F0XX_CRS_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /*!< Includes ----------------------------------------------------------------*/
  35. #include "stm32f0xx.h"
  36. /** @addtogroup STM32F0xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup CRS
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. /* Exported constants --------------------------------------------------------*/
  44. /** @defgroup CRS_Interrupt_Sources
  45. * @{
  46. */
  47. #define CRS_IT_SYNCOK CRS_ISR_SYNCOKF /*!< SYNC event OK */
  48. #define CRS_IT_SYNCWARN CRS_ISR_SYNCWARNF /*!< SYNC warning */
  49. #define CRS_IT_ERR CRS_ISR_ERRF /*!< error */
  50. #define CRS_IT_ESYNC CRS_ISR_ESYNCF /*!< Expected SYNC */
  51. #define CRS_IT_TRIMOVF CRS_ISR_TRIMOVF /*!< Trimming overflow or underflow */
  52. #define CRS_IT_SYNCERR CRS_ISR_SYNCERR /*!< SYNC error */
  53. #define CRS_IT_SYNCMISS CRS_ISR_SYNCMISS /*!< SYNC missed*/
  54. #define IS_CRS_IT(IT) (((IT) == CRS_IT_SYNCOK) || ((IT) == CRS_IT_SYNCWARN) || \
  55. ((IT) == CRS_IT_ERR) || ((IT) == CRS_IT_ESYNC))
  56. #define IS_CRS_GET_IT(IT) (((IT) == CRS_IT_SYNCOK) || ((IT) == CRS_IT_SYNCWARN) || \
  57. ((IT) == CRS_IT_ERR) || ((IT) == CRS_IT_ESYNC) || \
  58. ((IT) == CRS_IT_TRIMOVF) || ((IT) == CRS_IT_SYNCERR) || \
  59. ((IT) == CRS_IT_SYNCMISS))
  60. #define IS_CRS_CLEAR_IT(IT) ((IT) != 0x00)
  61. /**
  62. * @}
  63. */
  64. /** @defgroup CRS_Flags
  65. * @{
  66. */
  67. #define CRS_FLAG_SYNCOK CRS_ISR_SYNCOKF /*!< SYNC event OK */
  68. #define CRS_FLAG_SYNCWARN CRS_ISR_SYNCWARNF /*!< SYNC warning */
  69. #define CRS_FLAG_ERR CRS_ISR_ERRF /*!< error */
  70. #define CRS_FLAG_ESYNC CRS_ISR_ESYNCF /*!< Expected SYNC */
  71. #define CRS_FLAG_TRIMOVF CRS_ISR_TRIMOVF /*!< Trimming overflow or underflow */
  72. #define CRS_FLAG_SYNCERR CRS_ISR_SYNCERR /*!< SYNC error */
  73. #define CRS_FLAG_SYNCMISS CRS_ISR_SYNCMISS /*!< SYNC missed*/
  74. #define IS_CRS_FLAG(FLAG) (((FLAG) == CRS_FLAG_SYNCOK) || ((FLAG) == CRS_FLAG_SYNCWARN) || \
  75. ((FLAG) == CRS_FLAG_ERR) || ((FLAG) == CRS_FLAG_ESYNC) || \
  76. ((FLAG) == CRS_FLAG_TRIMOVF) || ((FLAG) == CRS_FLAG_SYNCERR) || \
  77. ((FLAG) == CRS_FLAG_SYNCMISS))
  78. /**
  79. * @}
  80. */
  81. /** @defgroup CRS_Synchro_Source
  82. * @{
  83. */
  84. #define CRS_SYNCSource_GPIO ((uint32_t)0x00) /*!< Synchro Signal soucre GPIO */
  85. #define CRS_SYNCSource_LSE CRS_CFGR_SYNCSRC_0 /*!< Synchro Signal source LSE */
  86. #define CRS_SYNCSource_USB CRS_CFGR_SYNCSRC_1 /*!< Synchro Signal source USB SOF */
  87. #define IS_CRS_SYNC_SOURCE(SOURCE) (((SOURCE) == CRS_SYNCSource_GPIO) || \
  88. ((SOURCE) == CRS_SYNCSource_LSE) ||\
  89. ((SOURCE) == CRS_SYNCSource_USB))
  90. /**
  91. * @}
  92. */
  93. /** @defgroup CRS_SynchroDivider
  94. * @{
  95. */
  96. #define CRS_SYNC_Div1 ((uint32_t)0x00) /*!< Synchro Signal not divided */
  97. #define CRS_SYNC_Div2 CRS_CFGR_SYNCDIV_0 /*!< Synchro Signal divided by 2 */
  98. #define CRS_SYNC_Div4 CRS_CFGR_SYNCDIV_1 /*!< Synchro Signal divided by 4 */
  99. #define CRS_SYNC_Div8 (CRS_CFGR_SYNCDIV_1 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 8 */
  100. #define CRS_SYNC_Div16 CRS_CFGR_SYNCDIV_2 /*!< Synchro Signal divided by 16 */
  101. #define CRS_SYNC_Div32 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 32 */
  102. #define CRS_SYNC_Div64 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_1) /*!< Synchro Signal divided by 64 */
  103. #define CRS_SYNC_Div128 CRS_CFGR_SYNCDIV /*!< Synchro Signal divided by 128 */
  104. #define IS_CRS_SYNC_DIV(DIV) (((DIV) == CRS_SYNC_Div1) || ((DIV) == CRS_SYNC_Div2) ||\
  105. ((DIV) == CRS_SYNC_Div4) || ((DIV) == CRS_SYNC_Div8) || \
  106. ((DIV) == CRS_SYNC_Div16) || ((DIV) == CRS_SYNC_Div32) || \
  107. ((DIV) == CRS_SYNC_Div64) || ((DIV) == CRS_SYNC_Div128))
  108. /**
  109. * @}
  110. */
  111. /** @defgroup CRS_SynchroPolarity
  112. * @{
  113. */
  114. #define CRS_SYNCPolarity_Rising ((uint32_t)0x00) /*!< Synchro Active on rising edge */
  115. #define CRS_SYNCPolarity_Falling CRS_CFGR_SYNCPOL /*!< Synchro Active on falling edge */
  116. #define IS_CRS_SYNC_POLARITY(POLARITY) (((POLARITY) == CRS_SYNCPolarity_Rising) || \
  117. ((POLARITY) == CRS_SYNCPolarity_Falling))
  118. /**
  119. * @}
  120. */
  121. /* Exported macro ------------------------------------------------------------*/
  122. /* Exported functions ------------------------------------------------------- */
  123. /* Configuration of the CRS **********************************/
  124. void CRS_DeInit(void);
  125. void CRS_AdjustHSI48CalibrationValue(uint8_t CRS_HSI48CalibrationValue);
  126. void CRS_FrequencyErrorCounterCmd(FunctionalState NewState);
  127. void CRS_AutomaticCalibrationCmd(FunctionalState NewState);
  128. void CRS_SoftwareSynchronizationGenerate(void);
  129. void CRS_FrequencyErrorCounterReload(uint32_t CRS_ReloadValue);
  130. void CRS_FrequencyErrorLimitConfig(uint8_t CRS_ErrorLimitValue);
  131. void CRS_SynchronizationPrescalerConfig(uint32_t CRS_Prescaler);
  132. void CRS_SynchronizationSourceConfig(uint32_t CRS_Source);
  133. void CRS_SynchronizationPolarityConfig(uint32_t CRS_Polarity);
  134. uint32_t CRS_GetReloadValue(void);
  135. uint32_t CRS_GetHSI48CalibrationValue(void);
  136. uint32_t CRS_GetFrequencyErrorValue(void);
  137. uint32_t CRS_GetFrequencyErrorDirection(void);
  138. /* Interrupts and flags management functions **********************************/
  139. void CRS_ITConfig(uint32_t CRS_IT, FunctionalState NewState);
  140. FlagStatus CRS_GetFlagStatus(uint32_t CRS_FLAG);
  141. void CRS_ClearFlag(uint32_t CRS_FLAG);
  142. ITStatus CRS_GetITStatus(uint32_t CRS_IT);
  143. void CRS_ClearITPendingBit(uint32_t CRS_IT);
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif /* __STM32F0XX_CRS_H */
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/