ESOS32
ESOSOn32-bitProcessors
esos_stm32l4_utils.c
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2019 J. W. Bruce ("AUTHOR(S)")"
3  * All rights reserved.
4  * (J. W. Bruce, jwbruce_AT_tntech.edu, Tennessee Tech University)
5  *
6  * Permission to use, copy, modify, and distribute this software and its
7  * documentation for any purpose, without fee, and without written agreement is
8  * hereby granted, provided that the above copyright notice, the following
9  * two paragraphs and the authors appear in all copies of this software.
10  *
11  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
12  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
13  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
14  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15  *
16  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
17  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
19  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
20  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
21  *
22  * Please maintain this header in its entirety when copying/modifying
23  * these files.
24  *
25  *
26  */
27 
28 // Documentation for this file. If the \file tag isn't present,
29 // this file won't be documented.
35 // Include any HW-specific header files to pick up the HW register
36 // definitions, macros, etc.
37 #include "esos_stm32l4.h"
38 #include "esos_stm32l4_utils.h"
39 
40 // VARIABLES
41 #ifdef STM32L452xx
42 //RNG_HandleTypeDef hrng;
43 #endif
44 
45 /***************************************************
46  *
47  * HARDWARE-specific ESOS utility functions
48  *
49  * *************************************************/
50 
51 /* ******************************************************
52 * \brief HW pseudo-random number generation...
53 *
54 * \note All hardware must implement this function.
55 *
56 * If the underlying hardware has PRNG on-board, it can
57 * implement it here and return the uint32 "random" number.
58 *
59 * If the underlying HW does not have PRNG on-board, it
60 * can call the hidden ESOS function for software RNG
61 * uint32 __esos_get_PRNG_RandomUint32(void)
62 * and return that value.
63 *
64 ********************************************************/
65 uint32_t __esos_hw_PRNG_u32(void) {
66 //#ifdef STM32L452xx
67 #if 0
68  uint32_t u32_randomNum;
69 
70  #if 1
71  rng_get_random(&u32_randomNum);
72  #else
73  // not sure why this doesn't work...... should be
74  // faster than above as we will read last RNG and then
75  // kick off the RNG hardware to make a new RNG before
76  // our next read. Need to study HAL more to figure this out.
77 
78  #endif
79  return u32_randomNum;
80 #else
81  return ( __esos_get_PRNG_RandomUint32() );
82 #endif
83 } // end __esos_hw_PRNG_u32(void)
84 
85 
86 /* *******************************************************
87 * \brief user-provided function to config the HW RNG
88 *
89 * \note All hardware must implement this function.
90 *
91 * If the underlying hardware has PRNG on-board, HW-specific code
92 * for intializing the PRNG hardware goes here.
93 *
94 * If the underlying HW does not have PRNG on-board, this
95 * function should just return.
96 *
97 ******************************************************* */
98 void __esos_hw_config_PRNG(void) {
99 #ifdef STM32L452xx
100 
101  //HAL VERSION
102  /*hrng.Instance = RNG;
103  if (HAL_RNG_Init(&hrng) != HAL_OK)
104  {
105  Error_Handler();
106  }*/
107 
109  //CM3 VERSION//
111  rng_enable();
112 
113 #endif
114 } // end __esos_hw_config_PRNG(void)
115 
116 /* *******************************************************
117 * \brief seed the HW pseudo-random number generator...
118 *
119 * \note All hardware must implement this function.
120 *
121 * If the underlying hardware has PRNG on-board, it can
122 * do what it needs to "seed" the PRNG.
123 *
124 * If the underlying HW does not have PRNG on-board, it
125 * can call the hidden ESOS function for seeding the
126 * ESOS software RNG function
127 * void __esos_setSWRNGU32Seed(uint32)
128 *
129 * \sa __esos_get_PRNG_RandomUint32
130 *
131 ********************************************************** */
132 void __esos_hw_set_PRNG_Seed(uint32_t u32_seed) {
133 #ifndef STM32L452xx
134 // RNG hardware doesn't let us set the seed
135  __esos_set_PRNG_U32Seed(u32_seed);
136 #endif
137 
138 } // end __esos_hw_setPRNG_Seed(uint32)
__esos_set_PRNG_U32Seed
void __esos_set_PRNG_U32Seed(uint32_t u32_seed)
Definition: esos_utils.c:70
__esos_get_PRNG_RandomUint32
uint32_t __esos_get_PRNG_RandomUint32(void)
Definition: esos_utils.c:80