fsl_rnga.h 4.2 KB

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