MCUXpresso: Fix for the TRNG HAL driver

Apply the fix from K64F TRNG HAL driver.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
pull/8437/head
Mahesh Mahadevan 2018-10-15 15:52:21 -05:00
parent a6651b868b
commit f29a597411
4 changed files with 12 additions and 14 deletions

View File

@ -22,6 +22,8 @@
* Reference: "K66 Sub-Family Reference Manual, Rev. 2", chapter 38
*/
#if defined(DEVICE_TRNG)
#include <stdlib.h>
#include "cmsis.h"
#include "fsl_common.h"
@ -48,13 +50,14 @@ void trng_free(trng_t *obj)
*/
static void trng_get_byte(unsigned char *byte)
{
*byte = 0;
size_t bit;
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */
for( bit = 0; bit < 8; bit++ )
{
while( ( RNG->SR & RNG_SR_OREG_LVL_MASK ) == 0 );
*byte |= ( RNG->OR & 1 ) << bit;
while((RNG->SR & RNG_SR_OREG_LVL_MASK) == 0 );
*byte |= (RNG->OR & 1) << bit;
}
}
@ -62,7 +65,6 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
{
(void)obj;
size_t i;
int ret;
/* Set "Interrupt Mask", "High Assurance" and "Go",
* unset "Clear interrupt" and "Sleep" */
@ -81,3 +83,5 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
return 0;
}
#endif

View File

@ -18,10 +18,6 @@
*
*/
/*
* Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
*/
#if defined(DEVICE_TRNG)
#include <stdlib.h>
@ -46,10 +42,11 @@ void trng_free(trng_t *obj)
/*
* Get one byte of entropy from the RNG, assuming it is up and running.
* As recommended (34.1.1), get only one bit of each output.
* As recommended, get only one bit of each output.
*/
static void trng_get_byte(unsigned char *byte)
{
*byte = 0;
size_t bit;
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */
@ -64,7 +61,6 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l
{
(void)obj;
size_t i;
int ret;
/* Set "Interrupt Mask", "High Assurance" and "Go",
* unset "Clear interrupt" and "Sleep" */

View File

@ -46,6 +46,7 @@ void trng_free(trng_t *obj)
*/
static void trng_get_byte(unsigned char *byte)
{
*byte = 0;
size_t bit;
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */

View File

@ -18,10 +18,6 @@
*
*/
/*
* Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
*/
#if defined(DEVICE_TRNG)
#include <stdlib.h>
@ -46,10 +42,11 @@ void trng_free(trng_t *obj)
/*
* Get one byte of entropy from the RNG, assuming it is up and running.
* As recommended (34.1.1), get only one bit of each output.
* As recommended, get only one bit of each output.
*/
static void trng_get_byte(unsigned char *byte)
{
*byte = 0;
size_t bit;
/* 34.5 Steps 3-4-5: poll SR and read from OR when ready */