1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

shell: added a handler for mersenne twister

This commit is contained in:
Christian Mehlis 2014-01-20 11:08:42 +01:00
parent 1d3f185d7d
commit d0680e7bac
4 changed files with 62 additions and 0 deletions

View File

@ -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/

View File

@ -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)

View File

@ -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 <mehlis@inf.fu-berlin.de>
* @}
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#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());
}

View File

@ -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}
};