Add RNG module

This commit is contained in:
iabdalkader 2014-03-01 13:33:01 +02:00
parent 36bfe95829
commit d29dc4db7f
5 changed files with 24 additions and 0 deletions

19
src/rng.c Normal file
View File

@ -0,0 +1,19 @@
#include <stm32f4xx_rng.h>
#include <stm32f4xx_rcc.h>
#include "rng.h"
void rng_init()
{
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
RNG_Cmd(ENABLE);
}
uint32_t rng_randint(uint32_t min, uint32_t max)
{
uint32_t rand;
if (min==max) {
return 0;
}
rand = RNG_GetRandomNumber();
return (rand%(max-min))+min;
}

5
src/rng.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef __RNG_H__
#define __RNG_H__
void rng_init();
uint32_t rng_randint(uint32_t min, uint32_t max);
#endif /* __RNG_H__ */