fsl_rnga.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_RNGA_DRIVER_H_
  35. #define _FSL_RNGA_DRIVER_H_
  36. #include "fsl_common.h"
  37. #if defined(FSL_FEATURE_SOC_RNG_COUNT) && FSL_FEATURE_SOC_RNG_COUNT
  38. /*!
  39. * @addtogroup rnga
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. *******************************************************************************/
  45. /*! @name Driver version */
  46. /*@{*/
  47. /*! @brief RNGA driver version 2.0.1. */
  48. #define FSL_RNGA_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
  49. /*@}*/
  50. /*! @brief RNGA working mode */
  51. typedef enum _rnga_mode
  52. {
  53. kRNGA_ModeNormal = 0U, /*!< Normal Mode. The ring-oscillator clocks are active; RNGA generates entropy
  54. (randomness) from the clocks and stores it in shift registers.*/
  55. kRNGA_ModeSleep = 1U, /*!< Sleep Mode. The ring-oscillator clocks are inactive; RNGA does not generate entropy.*/
  56. } rnga_mode_t;
  57. /*******************************************************************************
  58. * API
  59. *******************************************************************************/
  60. #if defined(__cplusplus)
  61. extern "C" {
  62. #endif
  63. /*!
  64. * @brief Initializes the RNGA.
  65. *
  66. * This function initializes the RNGA.
  67. * When called, the RNGA entropy generation starts immediately.
  68. *
  69. * @param base RNGA base address
  70. */
  71. void RNGA_Init(RNG_Type *base);
  72. /*!
  73. * @brief Shuts down the RNGA.
  74. *
  75. * This function shuts down the RNGA.
  76. *
  77. * @param base RNGA base address
  78. */
  79. void RNGA_Deinit(RNG_Type *base);
  80. /*!
  81. * @brief Gets random data.
  82. *
  83. * This function gets random data from the RNGA.
  84. *
  85. * @param base RNGA base address
  86. * @param data pointer to user buffer to be filled by random data
  87. * @param data_size size of data in bytes
  88. * @return RNGA status
  89. */
  90. status_t RNGA_GetRandomData(RNG_Type *base, void *data, size_t data_size);
  91. /*!
  92. * @brief Feeds the RNGA module.
  93. *
  94. * This function inputs an entropy value that the RNGA uses to seed its
  95. * pseudo-random algorithm.
  96. *
  97. * @param base RNGA base address
  98. * @param seed input seed value
  99. */
  100. void RNGA_Seed(RNG_Type *base, uint32_t seed);
  101. /*!
  102. * @brief Sets the RNGA in normal mode or sleep mode.
  103. *
  104. * This function sets the RNGA in sleep mode or normal mode.
  105. *
  106. * @param base RNGA base address
  107. * @param mode normal mode or sleep mode
  108. */
  109. void RNGA_SetMode(RNG_Type *base, rnga_mode_t mode);
  110. /*!
  111. * @brief Gets the RNGA working mode.
  112. *
  113. * This function gets the RNGA working mode.
  114. *
  115. * @param base RNGA base address
  116. * @return normal mode or sleep mode
  117. */
  118. rnga_mode_t RNGA_GetMode(RNG_Type *base);
  119. #if defined(__cplusplus)
  120. }
  121. #endif
  122. /*! @}*/
  123. #endif /* FSL_FEATURE_SOC_RNG_COUNT */
  124. #endif /* _FSL_RNGA_H_*/