K70 - HW Random Number Generator Example

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

K70 - HW Random Number Generator Example

2,576 次查看
chrisc
Contributor II

Hi,

Is there a code example of how to obtain a seed from the hardware random number generator accelerator on the Kinetis K70 board?  I've found Chapter 37 (Random Number Generator Accelerator) from the following document, but wasn't able to find an example of this being used anywhere.

http://cache.freescale.com/files/microcontrollers/doc/ref_manual/K70P256M150SF3RM.pdf

Thanks,

Chris

标签 (1)
标记 (4)
0 项奖励
回复
1 回复

1,240 次查看
mjbcswitzerland
Specialist V

Hi Chris

The following code is from the uTasker project:

Initialisation:

POWER_UP(3, SIM_SCGC3_RNGB);     // power up the RNG   

RNG_CR = (RNG_CR_FUFMODE_TE | RNG_CR_AR);   // automatic reseed mode and generate a bus error on FIFO underrun  

RNG_CMD = (RNG_CMD_GS | RNG_CMD_CI | RNG_CMD_CE);    // start the initial seed process // the initial seeding takes some time but we don't wait for it to complete here - if it hasn't completed when we first need a value we will wait for it then

Getting a random number:

  

while (RNG_SR & RNG_SR_BUSY) {}    // wait for the RNG to become ready (it may be seeding)    

while ((RNG_SR & RNG_SR_FIFO_LVL_MASK) == 0) { }  // wait for at least one output word to become available

return RNG_OUT;            // read from the FIFO and return 32 bits of output


Regards

Mark

http://www.uTasker.com