Skip to content

MCUXpresso: Fix for the TRNG HAL driver #8437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -48,21 +50,21 @@ 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;
}
}

int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
{
(void)obj;
size_t i;
int ret;

/* Set "Interrupt Mask", "High Assurance" and "Go",
* unset "Clear interrupt" and "Sleep" */
Expand All @@ -81,3 +83,5 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_l

return 0;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*
*/

/*
* Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
*/

#if defined(DEVICE_TRNG)

#include <stdlib.h>
Expand All @@ -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 */
Expand All @@ -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" */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*
*/

/*
* Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
*/

#if defined(DEVICE_TRNG)

#include <stdlib.h>
Expand All @@ -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 */
Expand Down