k64f: add RNG HAL implementation

Replaces old mbedtls entropy file, to use new RNG HAL API.
pull/2765/head
0xc0170 2016-09-16 11:34:43 +01:00 committed by Martin Kojtal
parent 6da5515e1c
commit 132a5bbff3
3 changed files with 28 additions and 27 deletions

View File

@ -565,7 +565,7 @@
"inherits": ["Target"], "inherits": ["Target"],
"progen": {"target": "frdm-k64f"}, "progen": {"target": "frdm-k64f"},
"detect_code": ["0240"], "detect_code": ["0240"],
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "STORAGE"], "device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "STORAGE", "RNG"],
"features": ["IPV4", "STORAGE"], "features": ["IPV4", "STORAGE"],
"release_versions": ["2", "5"] "release_versions": ["2", "5"]
}, },

View File

@ -26,6 +26,19 @@
#include "cmsis.h" #include "cmsis.h"
#include "fsl_common.h" #include "fsl_common.h"
#include "fsl_clock.h" #include "fsl_clock.h"
#include "rng_api.h"
void rng_init(rng_t *obj)
{
CLOCK_EnableClock(kCLOCK_Rnga0);
CLOCK_DisableClock(kCLOCK_Rnga0);
CLOCK_EnableClock(kCLOCK_Rnga0);
}
void rng_free(rng_t *obj)
{
CLOCK_DisableClock(kCLOCK_Rnga0);
}
/* /*
* Get one byte of entropy from the RNG, assuming it is up and running. * Get one byte of entropy from the RNG, assuming it is up and running.
@ -43,41 +56,25 @@ static void rng_get_byte( unsigned char *byte )
} }
} }
/* int rng_get_numbers(rng_t *obj, uint8_t *output, size_t length, size_t *output_length)
* Get len bytes of entropy from the hardware RNG.
*/
int mbedtls_hardware_poll( void *data,
unsigned char *output, size_t len, size_t *olen )
{ {
size_t i; size_t i;
int ret; int ret;
((void) data);
CLOCK_EnableClock( kCLOCK_Rnga0 );
CLOCK_DisableClock( kCLOCK_Rnga0 );
CLOCK_EnableClock( kCLOCK_Rnga0 );
/* Set "Interrupt Mask", "High Assurance" and "Go", /* Set "Interrupt Mask", "High Assurance" and "Go",
* unset "Clear interrupt" and "Sleep" */ * unset "Clear interrupt" and "Sleep" */
RNG->CR = RNG_CR_INTM_MASK | RNG_CR_HA_MASK | RNG_CR_GO_MASK; RNG->CR = RNG_CR_INTM_MASK | RNG_CR_HA_MASK | RNG_CR_GO_MASK;
for( i = 0; i < len; i++ ) for (i = 0; i < length; i++) {
rng_get_byte(output + i); rng_get_byte(output + i);
}
/* Just be extra sure that we didn't do it wrong */ /* Just be extra sure that we didn't do it wrong */
if( ( RNG->SR & RNG_SR_SECV_MASK ) != 0 ) if ((RNG->SR & RNG_SR_SECV_MASK) != 0) {
{ return -1;
ret = -1;
goto cleanup;
} }
*olen = len; *output_length = length;
ret = 0;
cleanup: return 0;
/* Disable clock to save power - assume we're the only users of RNG */
CLOCK_DisableClock( kCLOCK_Rnga0 );
return( ret );
} }

View File

@ -61,6 +61,10 @@ struct dac_s {
DACName dac; DACName dac;
}; };
struct rng_s {
};
#include "gpio_object.h" #include "gpio_object.h"
#ifdef __cplusplus #ifdef __cplusplus