41 lines
		
	
	
		
			448 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			448 B
		
	
	
	
		
			C
		
	
	
	
	
	
#include "stm32f4xx.h"
 | 
						|
#include "base.h"
 | 
						|
#include "random.h"
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
static int g_inited=0;
 | 
						|
void RANDOM_Init (void)
 | 
						|
{
 | 
						|
    if(g_inited==0)
 | 
						|
    {
 | 
						|
        RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
 | 
						|
        RNG_Cmd(ENABLE);
 | 
						|
        RANDOM_Get(); 
 | 
						|
        g_inited=1;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
u32 RANDOM_Get (void)
 | 
						|
{
 | 
						|
	if (RNG->CR & RNG_CR_RNGEN)
 | 
						|
	{
 | 
						|
		while (RNG_GetFlagStatus(RNG_FLAG_DRDY)!=SET);
 | 
						|
		return RNG_GetRandomNumber();
 | 
						|
	}
 | 
						|
	else
 | 
						|
		return 0;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |