mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Ion::random()
Change-Id: Ib85055ab3b4bf3dfce991f9990659c744be20f39
This commit is contained in:
@@ -33,6 +33,9 @@ void reset();
|
||||
// Only accepts whole 32bit values
|
||||
uint32_t crc32(const uint32_t * data, size_t length);
|
||||
|
||||
// Provides a true random number
|
||||
uint32_t random();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,6 +41,22 @@ uint32_t Ion::crc32(const uint32_t * data, size_t length) {
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t Ion::random() {
|
||||
bool initialRNGEngineState = RCC.AHB2ENR()->getRNGEN();
|
||||
RCC.AHB2ENR()->setRNGEN(true);
|
||||
|
||||
RNG.CR()->setRNGEN(true);
|
||||
|
||||
while (RNG.SR()->getDRDY() == 0) {
|
||||
}
|
||||
uint32_t result = RNG.DR()->get();
|
||||
|
||||
RNG.CR()->setRNGEN(false);
|
||||
RCC.AHB2ENR()->setRNGEN(initialRNGEngineState);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Ion::reset() {
|
||||
CM4.AIRCR()->requestReset();
|
||||
}
|
||||
|
||||
6
ion/src/shared/random.cpp
Normal file
6
ion/src/shared/random.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <ion.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
uint32_t Ion::random() {
|
||||
return rand();
|
||||
}
|
||||
@@ -12,6 +12,7 @@ objs += $(addprefix ion/src/shared/, \
|
||||
events_keyboard.o \
|
||||
log_printf.o \
|
||||
power.o \
|
||||
random.o \
|
||||
)
|
||||
|
||||
SFLAGS += `fltk-config --cflags`
|
||||
|
||||
Reference in New Issue
Block a user