mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #2324 from LudwigOrtmann/native-random-warnings
cpu/native: warn about uninitialized random module
This commit is contained in:
commit
e03596f9d6
@ -30,6 +30,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
static int powered = 0;
|
static int powered = 0;
|
||||||
|
static int initialized = 0;
|
||||||
static int dev_random = -1;
|
static int dev_random = -1;
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
@ -63,12 +64,20 @@ void random_init(void)
|
|||||||
_native_rng_mode);
|
_native_rng_mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialized = 1;
|
||||||
|
|
||||||
DEBUG("random_init: powering on\n");
|
DEBUG("random_init: powering on\n");
|
||||||
random_poweron();
|
random_poweron();
|
||||||
}
|
}
|
||||||
|
|
||||||
int random_read(char *buf, unsigned int num)
|
int random_read(char *buf, unsigned int num)
|
||||||
{
|
{
|
||||||
|
if (!initialized) {
|
||||||
|
warnx("random_read: random device not initialized, failing\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!powered) {
|
if (!powered) {
|
||||||
warnx("random_read: random device not powered, failing\n");
|
warnx("random_read: random device not powered, failing\n");
|
||||||
return 0;
|
return 0;
|
||||||
@ -94,12 +103,22 @@ int random_read(char *buf, unsigned int num)
|
|||||||
void random_poweron(void)
|
void random_poweron(void)
|
||||||
{
|
{
|
||||||
DEBUG("random_poweron: power on\n");
|
DEBUG("random_poweron: power on\n");
|
||||||
|
|
||||||
|
if (!initialized) {
|
||||||
|
warnx("random_poweron: not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
powered = 1;
|
powered = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void random_poweroff(void)
|
void random_poweroff(void)
|
||||||
{
|
{
|
||||||
DEBUG("random_poweroff: power off\n");
|
DEBUG("random_poweroff: power off\n");
|
||||||
|
|
||||||
|
if (!initialized) {
|
||||||
|
warnx("random_poweroff: not initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
powered = 0;
|
powered = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user