stm32l4xx_ll_rng.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_rng.c
  4. * @author MCD Application Team
  5. * @brief RNG LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. #if defined(USE_FULL_LL_DRIVER)
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32l4xx_ll_rng.h"
  21. #include "stm32l4xx_ll_bus.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif
  27. /** @addtogroup STM32L4xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (RNG)
  31. /** @addtogroup RNG_LL
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. #if defined(RNG_CR_CED)
  39. /** @addtogroup RNG_LL_Private_Macros
  40. * @{
  41. */
  42. #define IS_LL_RNG_CED(__MODE__) (((__MODE__) == LL_RNG_CED_ENABLE) || \
  43. ((__MODE__) == LL_RNG_CED_DISABLE))
  44. #if defined(RNG_CR_CONDRST)
  45. #define IS_LL_RNG_CLOCK_DIVIDER(__CLOCK_DIV__) ((__CLOCK_DIV__) <=0x0Fu)
  46. #define IS_LL_RNG_NIST_COMPLIANCE(__NIST_COMPLIANCE__) (((__NIST_COMPLIANCE__) == LL_RNG_NIST_COMPLIANT) || \
  47. ((__NIST_COMPLIANCE__) == LL_RNG_NOTNIST_COMPLIANT))
  48. #define IS_LL_RNG_CONFIG1 (__CONFIG1__) ((__CONFIG1__) <= 0x3FUL)
  49. #define IS_LL_RNG_CONFIG2 (__CONFIG2__) ((__CONFIG2__) <= 0x07UL)
  50. #define IS_LL_RNG_CONFIG3 (__CONFIG3__) ((__CONFIG3__) <= 0xFUL)
  51. #endif /* end of RNG_CR_CONDRST*/
  52. /**
  53. * @}
  54. */
  55. #endif
  56. /* Private function prototypes -----------------------------------------------*/
  57. /* Exported functions --------------------------------------------------------*/
  58. /** @addtogroup RNG_LL_Exported_Functions
  59. * @{
  60. */
  61. /** @addtogroup RNG_LL_EF_Init
  62. * @{
  63. */
  64. /**
  65. * @brief De-initialize RNG registers (Registers restored to their default values).
  66. * @param RNGx RNG Instance
  67. * @retval An ErrorStatus enumeration value:
  68. * - SUCCESS: RNG registers are de-initialized
  69. * - ERROR: not applicable
  70. */
  71. ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx)
  72. {
  73. /* Check the parameters */
  74. assert_param(IS_RNG_ALL_INSTANCE(RNGx));
  75. /* Enable RNG reset state */
  76. LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_RNG);
  77. /* Release RNG from reset state */
  78. LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_RNG);
  79. return (SUCCESS);
  80. }
  81. #if defined(RNG_CR_CED)
  82. /**
  83. * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct.
  84. * @param RNGx RNG Instance
  85. * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure
  86. * that contains the configuration information for the specified RNG peripheral.
  87. * @retval An ErrorStatus enumeration value:
  88. * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content
  89. * - ERROR: not applicable
  90. */
  91. ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct)
  92. {
  93. /* Check the parameters */
  94. assert_param(IS_RNG_ALL_INSTANCE(RNGx));
  95. assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection));
  96. #if defined(RNG_CR_CONDRST)
  97. /* Clock Error Detection Configuration when CONDRT bit is set to 1 */
  98. MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST);
  99. /* Writing bits CONDRST=0*/
  100. CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST);
  101. #else
  102. /* Clock Error Detection configuration */
  103. MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection);
  104. #endif
  105. return (SUCCESS);
  106. }
  107. /**
  108. * @brief Set each @ref LL_RNG_InitTypeDef field to default value.
  109. * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure
  110. * whose fields will be set to default values.
  111. * @retval None
  112. */
  113. void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct)
  114. {
  115. /* Set RNG_InitStruct fields to default values */
  116. RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE;
  117. }
  118. #endif
  119. /**
  120. * @}
  121. */
  122. /**
  123. * @}
  124. */
  125. /**
  126. * @}
  127. */
  128. #endif /* RNG */
  129. /**
  130. * @}
  131. */
  132. #endif /* USE_FULL_LL_DRIVER */