stm32l4xx_ll_rng.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 /* USE_FULL_ASSERT */
  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. /** @defgroup RNG_LL_Private_Macros RNG 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 /* RNG_CR_CONDRST */
  52. /**
  53. * @}
  54. */
  55. #endif /* RNG_CR_CED */
  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(const RNG_TypeDef *RNGx)
  72. {
  73. ErrorStatus status = SUCCESS;
  74. /* Check the parameters */
  75. assert_param(IS_RNG_ALL_INSTANCE(RNGx));
  76. if (RNGx == RNG)
  77. {
  78. /* Enable RNG reset state */
  79. LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_RNG);
  80. /* Release RNG from reset state */
  81. LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_RNG);
  82. }
  83. else
  84. {
  85. status = ERROR;
  86. }
  87. return status;
  88. }
  89. #if defined(RNG_CR_CED)
  90. /**
  91. * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct.
  92. * @param RNGx RNG Instance
  93. * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure
  94. * that contains the configuration information for the specified RNG peripheral.
  95. * @retval An ErrorStatus enumeration value:
  96. * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content
  97. * - ERROR: not applicable
  98. */
  99. ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, const LL_RNG_InitTypeDef *RNG_InitStruct)
  100. {
  101. /* Check the parameters */
  102. assert_param(IS_RNG_ALL_INSTANCE(RNGx));
  103. assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection));
  104. #if defined(RNG_CR_CONDRST)
  105. /* Clock Error Detection Configuration when CONDRT bit is set to 1 */
  106. MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST);
  107. /* Writing bits CONDRST=0*/
  108. CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST);
  109. #else
  110. /* Clock Error Detection configuration */
  111. MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection);
  112. #endif /* RNG_CR_CONDRST */
  113. return (SUCCESS);
  114. }
  115. /**
  116. * @brief Set each @ref LL_RNG_InitTypeDef field to default value.
  117. * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure
  118. * whose fields will be set to default values.
  119. * @retval None
  120. */
  121. void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct)
  122. {
  123. /* Set RNG_InitStruct fields to default values */
  124. RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE;
  125. }
  126. #endif /* RNG_CR_CED */
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. /**
  134. * @}
  135. */
  136. #endif /* RNG */
  137. /**
  138. * @}
  139. */
  140. #endif /* USE_FULL_LL_DRIVER */