CC26xx Driver Library |

- Main Page
- Related Pages
- CC26xx APIs
- Register Descriptions
- Online Resources

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
trng.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: trng.h
3 * Revised: 2015-01-14 12:12:44 +0100 (on, 14 jan 2015)
4 * Revision: 42373
5 *
6 * Description: Defines and prototypes for the true random number gen.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38
39 //*****************************************************************************
40 //
43 //
44 //*****************************************************************************
45
46 #ifndef __TRNG_H__
47 #define __TRNG_H__
48
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include <inc/hw_types.h>
63 #include <inc/hw_trng.h>
64 #include <inc/hw_memmap.h>
65 #include <inc/hw_ints.h>
66 #include <driverlib/debug.h>
67 #include <driverlib/interrupt.h>
68 #include <driverlib/cpu.h>
69
70 //*****************************************************************************
71 //
72 // Support for DriverLib in ROM:
73 // This section renames all functions that are not "static inline", so that
74 // calling these functions will default to implementation in flash. At the end
75 // of this file a second renaming will change the defaults to implementation in
76 // ROM for available functions.
77 //
78 // To force use of the implementation in flash, e.g. for debugging:
79 // - Globally: Define DRIVERLIB_NOROM at project level
80 // - Per function: Use prefix "NOROM_" when calling the function
81 //
82 // Do not define DRIVERLIB_GENERATE_ROM!
83 //
84 //*****************************************************************************
85 #ifndef DRIVERLIB_GENERATE_ROM
86 #define TRNGConfigure NOROM_TRNGConfigure
87 #define TRNGNumberGet NOROM_TRNGNumberGet
88 #endif
89
90 //*****************************************************************************
91 //
92 //
93 //
94 //*****************************************************************************
95 #define TRNG_NUMBER_READY 0x00000001 //
96 #define TRNG_FRO_SHUTDOWN 0x00000002 //
97 #define TRNG_NEED_CLOCK 0x80000000 //
98
99 #define TRNG_HI_WORD 0x00000001
100 #define TRNG_LOW_WORD 0x00000002
101
102 //*****************************************************************************
103 //
104 // API Function and prototypes
105 //
106 //*****************************************************************************
107
108 //*****************************************************************************
109 //
123 //
124 //*****************************************************************************
125 extern void TRNGConfigure(uint32_t ui32MinSamplesPerCycle,
126 uint32_t ui32MaxSamplesPerCycle,
127 uint32_t ui32ClocksPerSample);
128
129 //*****************************************************************************
130 //
136 //
137 //*****************************************************************************
138 __STATIC_INLINE void
139 TRNGEnable(void)
140 {
141 //
142 // Enable the TRNG.
143 //
144 HWREG(TRNG_BASE + TRNG_O_CTL) |= TRNG_CTL_TRNG_EN;
145 }
146
147 //*****************************************************************************
148 //
152 //
153 //*****************************************************************************
154 __STATIC_INLINE void
155 TRNGDisable(void)
156 {
157 //
158 // Enable the TRNG
159 //
160 HWREG(TRNG_BASE + TRNG_O_CTL) &= ~TRNG_CTL_TRNG_EN;
161 }
162
163 //*****************************************************************************
164 //
180 //
181 //*****************************************************************************
182 extern uint32_t TRNGNumberGet(uint32_t ui32Word);
183
184 //*****************************************************************************
185 //
195 //
196 //*****************************************************************************
197 __STATIC_INLINE uint32_t
198 TRNGStatusGet(void)
199 {
200 //
201 // Return the status.
202 //
203 return (HWREG(TRNG_BASE + TRNG_O_IRQFLAGSTAT));
204 }
205
206 //*****************************************************************************
207 //
214 //
215 //*****************************************************************************
216 __STATIC_INLINE void
217 TRNGReset(void)
218 {
219 //
220 // Reset the TRNG.
221 //
222 HWREG(TRNG_BASE + TRNG_O_SWRESET) = 1;
223 }
224
225 //*****************************************************************************
226 //
239 //
240 //*****************************************************************************
241 __STATIC_INLINE void
242 TRNGIntEnable(uint32_t ui32IntFlags)
243 {
244 //
245 // Check the arguments.
246 //
247 ASSERT((ui32IntFlags & TRNG_NUMBER_READY) ||
248 (ui32IntFlags & TRNG_FRO_SHUTDOWN));
249
250 //
251 // Enable the specified interrupts.
252 //
253 HWREG(TRNG_BASE + TRNG_O_IRQFLAGMASK) |= ui32IntFlags;
254 }
255
256 //*****************************************************************************
257 //
270 //
271 //*****************************************************************************
272 __STATIC_INLINE void
273 TRNGIntDisable(uint32_t ui32IntFlags)
274 {
275 //
276 // Check the arguments.
277 //
278 ASSERT((ui32IntFlags & TRNG_NUMBER_READY) ||
279 (ui32IntFlags & TRNG_FRO_SHUTDOWN));
280
281 //
282 // Disable the specified interrupts.
283 //
284 HWREG(TRNG_BASE + TRNG_O_IRQFLAGMASK) &= ~ui32IntFlags;
285 }
286
287 //*****************************************************************************
288 //
302 //
303 //*****************************************************************************
304 __STATIC_INLINE uint32_t
305 TRNGIntStatus(bool bMasked)
306 {
307 uint32_t ui32Mask;
308
309 //
310 // Return either the interrupt status or the raw interrupt status as
311 // requested.
312 //
313 if(bMasked)
314 {
315 ui32Mask = HWREG(TRNG_BASE + TRNG_O_IRQFLAGMASK);
316 return(ui32Mask & HWREG(TRNG_BASE + TRNG_O_IRQFLAGSTAT));
317 }
318 else
319 {
320 return(HWREG(TRNG_BASE + TRNG_O_IRQFLAGSTAT) & 0x00000003);
321 }
322 }
323
324 //*****************************************************************************
325 //
347 //
348 //*****************************************************************************
349 __STATIC_INLINE void
350 TRNGIntClear(uint32_t ui32IntFlags)
351 {
352 //
353 // Check the arguments.
354 //
355 ASSERT((ui32IntFlags & TRNG_NUMBER_READY) ||
356 (ui32IntFlags & TRNG_FRO_SHUTDOWN));
357
358 //
359 // Clear the requested interrupt sources.
360 //
361 HWREG(TRNG_BASE + TRNG_O_IRQFLAGCLR) = ui32IntFlags;
362 }
363
364 //*****************************************************************************
365 //
380 //
381 //*****************************************************************************
382 __STATIC_INLINE void
383 TRNGIntRegister(void (*pfnHandler)(void))
384 {
385 //
386 // Register the interrupt handler.
387 //
388 IntRegister(INT_TRNG, pfnHandler);
389
390 //
391 // Enable the TRNG interrupt.
392 //
393 IntEnable(INT_TRNG);
394 }
395
396 //*****************************************************************************
397 //
409 //
410 //*****************************************************************************
411 __STATIC_INLINE void
412 TRNGIntUnregister(void)
413 {
414 //
415 // Disable the interrupt.
416 //
417 IntDisable(INT_TRNG);
418
419 //
420 // Unregister the interrupt handler.
421 //
422 IntUnregister(INT_TRNG);
423 }
424
425 //*****************************************************************************
426 //
427 // Support for DriverLib in ROM:
428 // Redirect to implementation in ROM when available.
429 //
430 //*****************************************************************************
431 #ifndef DRIVERLIB_NOROM
432 #include <driverlib/rom.h>
433 #ifdef ROM_TRNGConfigure
434 #undef TRNGConfigure
435 #define TRNGConfigure ROM_TRNGConfigure
436 #endif
437 #ifdef ROM_TRNGNumberGet
438 #undef TRNGNumberGet
439 #define TRNGNumberGet ROM_TRNGNumberGet
440 #endif
441 #endif
442
443 //*****************************************************************************
444 //
445 // Mark the end of the C bindings section for C++ compilers.
446 //
447 //*****************************************************************************
448 #ifdef __cplusplus
449 }
450 #endif
451
452 #endif // __TRNG_H__
453
454 //*****************************************************************************
455 //
458 //
459 //*****************************************************************************
TRNGStatusGet
__STATIC_INLINE uint32_t TRNGStatusGet(void)
Get the status of the TRNG.
Definition: trng.h:198
debug.h
TRNG_FRO_SHUTDOWN
#define TRNG_FRO_SHUTDOWN
Definition: trng.h:96
TRNGIntStatus
__STATIC_INLINE uint32_t TRNGIntStatus(bool bMasked)
Gets the current interrupt status of the TRNG module.
Definition: trng.h:305
TRNGIntRegister
__STATIC_INLINE void TRNGIntRegister(void(*pfnHandler)(void))
Registers an interrupt handler for a TRNG interrupt.
Definition: trng.h:383
ASSERT
#define ASSERT(expr)
Definition: debug.h:65
TRNGIntUnregister
__STATIC_INLINE void TRNGIntUnregister(void)
Unregisters an interrupt handler for a TRNG interrupt.
Definition: trng.h:412
TRNGNumberGet
uint32_t TRNGNumberGet(uint32_t ui32Word)
Get a random number from the generator.
Definition: trng.c:95
TRNGConfigure
void TRNGConfigure(uint32_t ui32MinSamplesPerCycle, uint32_t ui32MaxSamplesPerCycle, uint32_t ui32ClocksPerSample)
Configure the true random number generator.
Definition: trng.c:60
TRNG_NUMBER_READY
#define TRNG_NUMBER_READY
Definition: trng.h:95
TRNGReset
__STATIC_INLINE void TRNGReset(void)
Reset the TRNG.
Definition: trng.h:217
TRNGIntDisable
__STATIC_INLINE void TRNGIntDisable(uint32_t ui32IntFlags)
Disables individual TRNG interrupt sources.
Definition: trng.h:273
TRNGDisable
__STATIC_INLINE void TRNGDisable(void)
Disable the TRNG module.
Definition: trng.h:155
interrupt.h
cpu.h
IntUnregister
void IntUnregister(uint32_t ui32Interrupt)
Unregisters the function to be called when an interrupt occurs.
Definition: interrupt.c:205
TRNGEnable
__STATIC_INLINE void TRNGEnable(void)
Enable the TRNG.
Definition: trng.h:139
rom.h
TRNGIntClear
__STATIC_INLINE void TRNGIntClear(uint32_t ui32IntFlags)
Clears TRNG interrupt sources.
Definition: trng.h:350
TRNGIntEnable
__STATIC_INLINE void TRNGIntEnable(uint32_t ui32IntFlags)
Enables individual TRNG interrupt sources.
Definition: trng.h:242
IntDisable
void IntDisable(uint32_t ui32Interrupt)
Disables an interrupt.
Definition: interrupt.c:383
IntRegister
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Registers a function to be called when an interrupt occurs.
Definition: interrupt.c:157
IntEnable
void IntEnable(uint32_t ui32Interrupt)
Enables an interrupt.
Definition: interrupt.c:323