1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2017, 2019 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 #ifndef _FSL_RNGA_DRIVER_H_ 9 #define _FSL_RNGA_DRIVER_H_ 10 11 #include "fsl_common.h" 12 13 #if defined(FSL_FEATURE_SOC_RNG_COUNT) && FSL_FEATURE_SOC_RNG_COUNT 14 /*! 15 * @addtogroup rnga 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 *******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*@{*/ 25 /*! @brief RNGA driver version 2.0.2. */ 26 #define FSL_RNGA_DRIVER_VERSION (MAKE_VERSION(2, 0, 2)) 27 /*@}*/ 28 29 /*! @brief RNGA working mode */ 30 typedef enum _rnga_mode 31 { 32 kRNGA_ModeNormal = 0U, /*!< Normal Mode. The ring-oscillator clocks are active; RNGA generates entropy 33 (randomness) from the clocks and stores it in shift registers.*/ 34 kRNGA_ModeSleep = 1U, /*!< Sleep Mode. The ring-oscillator clocks are inactive; RNGA does not generate entropy.*/ 35 } rnga_mode_t; 36 37 /******************************************************************************* 38 * API 39 *******************************************************************************/ 40 41 #if defined(__cplusplus) 42 extern "C" { 43 #endif 44 45 /*! 46 * @brief Initializes the RNGA. 47 * 48 * This function initializes the RNGA. 49 * When called, the RNGA entropy generation starts immediately. 50 * 51 * @param base RNGA base address 52 */ 53 void RNGA_Init(RNG_Type *base); 54 55 /*! 56 * @brief Shuts down the RNGA. 57 * 58 * This function shuts down the RNGA. 59 * 60 * @param base RNGA base address 61 */ 62 void RNGA_Deinit(RNG_Type *base); 63 64 /*! 65 * @brief Gets random data. 66 * 67 * This function gets random data from the RNGA. 68 * 69 * @param base RNGA base address 70 * @param data pointer to user buffer to be filled by random data 71 * @param data_size size of data in bytes 72 * @return RNGA status 73 */ 74 status_t RNGA_GetRandomData(RNG_Type *base, void *data, size_t data_size); 75 76 /*! 77 * @brief Feeds the RNGA module. 78 * 79 * This function inputs an entropy value that the RNGA uses to seed its 80 * pseudo-random algorithm. 81 * 82 * @param base RNGA base address 83 * @param seed input seed value 84 */ 85 void RNGA_Seed(RNG_Type *base, uint32_t seed); 86 87 /*! 88 * @brief Sets the RNGA in normal mode or sleep mode. 89 * 90 * This function sets the RNGA in sleep mode or normal mode. 91 * 92 * @param base RNGA base address 93 * @param mode normal mode or sleep mode 94 */ 95 void RNGA_SetMode(RNG_Type *base, rnga_mode_t mode); 96 97 /*! 98 * @brief Gets the RNGA working mode. 99 * 100 * This function gets the RNGA working mode. 101 * 102 * @param base RNGA base address 103 * @return normal mode or sleep mode 104 */ 105 rnga_mode_t RNGA_GetMode(RNG_Type *base); 106 107 #if defined(__cplusplus) 108 } 109 #endif 110 111 /*! @}*/ 112 113 #endif /* FSL_FEATURE_SOC_RNG_COUNT */ 114 #endif /* _FSL_RNGA_H_*/ 115