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