diff --git a/examples/default/Makefile b/examples/default/Makefile index 4dd2c77759..372aeb2a0f 100644 --- a/examples/default/Makefile +++ b/examples/default/Makefile @@ -66,6 +66,7 @@ ifneq (,$(findstring msba2,$(BOARD))) USEMODULE += mci USEMODULE += cc110x_ng USEMODULE += config + USEMODULE += random export INCLUDES += -I$(RIOTBASE)/drivers/cc110x_ng/include endif ifneq (,$(findstring native,$(BOARD))) @@ -74,6 +75,7 @@ ifneq (,$(findstring native,$(BOARD))) USEMODULE += nativenet USEMODULE += transceiver USEMODULE += config + USEMODULE += random endif export INCLUDES += -I${RIOTBASE}/core/include/ -I${RIOTBASE}/sys/include/ -I${RIOTBASE}/drivers/include/ diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index 7b7ccb7ae0..8f222df247 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -34,6 +34,9 @@ endif ifneq (,$(findstring lpc_common,$(USEMODULE))) SRC += sc_heap.c endif +ifneq (,$(findstring random,$(USEMODULE))) + SRC += sc_mersenne.c +endif OBJ = $(SRC:%.c=$(BINDIR)%.o) DEP = $(SRC:%.c=$(BINDIR)%.d) diff --git a/sys/shell/commands/sc_mersenne.c b/sys/shell/commands/sc_mersenne.c new file mode 100644 index 0000000000..8cfdcc91fd --- /dev/null +++ b/sys/shell/commands/sc_mersenne.c @@ -0,0 +1,48 @@ +/** + * Shell commands for mersenne twister + * + * Copyright (C) 2013 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + * + * @ingroup shell_commands + * @{ + * @file sc_mersenne.c + * @brief initializes the PRNG + * @author Christian Mehlis + * @} + */ + +#include +#include +#include +#include + +#include "hwtimer.h" +#include "random.h" + +void _mersenne_init(char *str) +{ + int initval; + char *toc_str = strtok(str, " "); + + toc_str = strtok(NULL, " "); + if (!toc_str) { + initval = hwtimer_now(); + printf("PRNG inizialized to current time: %d\n", initval); + } else { + initval = atoi(toc_str); + printf("PRNG inizialized given value: %d\n", initval); + } + + genrand_init(initval); +} + +void _mersenne_get(char *str) +{ + (void) str; + + printf("%" PRIu32 "\n", genrand_uint32()); +} diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index 45a8e4a3e0..cd8749baf0 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -92,6 +92,11 @@ extern void _read_sector(char *sector); extern void _read_bytes(char *bytes); #endif +#ifdef MODULE_RANDOM +extern void _mersenne_init(char *str); +extern void _mersenne_get(char *str); +#endif + const shell_command_t _shell_command_list[] = { {"id", "Gets or sets the node's id.", _id_handler}, #ifdef MODULE_LPC_COMMON @@ -154,6 +159,10 @@ const shell_command_t _shell_command_list[] = { {DISK_GET_SECTOR_SIZE, "Get the sector size of inserted memory card", _get_sectorsize}, {DISK_GET_SECTOR_COUNT, "Get the sector count of inserted memory card", _get_sectorcount}, {DISK_GET_BLOCK_SIZE, "Get the block size of inserted memory card", _get_blocksize}, +#endif +#ifdef MODULE_RANDOM + { "mersenne_init", "initializes the PRNG", _mersenne_init }, + { "mersenne_get", "returns 32 bit of pseudo randomness", _mersenne_get }, #endif {NULL, NULL, NULL} };