2014-08-21 17:45:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License v2.1. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Low-level random number generator driver test
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2014-11-19 11:53:40 +01:00
|
|
|
|
2015-09-03 21:36:13 +02:00
|
|
|
#include "xtimer.h"
|
2014-11-19 11:53:40 +01:00
|
|
|
#include "periph/random.h"
|
2014-08-21 17:45:44 +02:00
|
|
|
|
|
|
|
#define LIMIT (20U)
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
char buf[LIMIT];
|
|
|
|
|
|
|
|
puts("\nRandom number generator low-level driver test\n");
|
|
|
|
printf("This test will print from 1 to %i random bytes about every second\n\n", LIMIT);
|
|
|
|
|
|
|
|
puts("Initializing Random Number Generator driver.\n");
|
|
|
|
random_init();
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/* zero out buffer */
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
|
|
|
/* create random numbers */
|
2014-11-19 11:53:40 +01:00
|
|
|
for (unsigned i = 1; i <= LIMIT; i++) {
|
2014-11-21 15:25:56 +01:00
|
|
|
printf("generating %u random byte(s)\n", i);
|
2014-11-19 11:53:40 +01:00
|
|
|
unsigned count = random_read(buf, i);
|
2014-08-21 17:45:44 +02:00
|
|
|
|
|
|
|
if (count != i) {
|
2014-11-21 15:25:56 +01:00
|
|
|
printf("Error generating random bytes, got %u instead of %u", count, i);
|
2014-08-21 17:45:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Got:");
|
2014-11-19 11:53:40 +01:00
|
|
|
for (unsigned j = 0; j < i; j++) {
|
|
|
|
printf(" 0x%02x", (unsigned char)buf[j]);
|
2014-08-21 17:45:44 +02:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2015-09-03 21:36:13 +02:00
|
|
|
xtimer_usleep(1000 * 1000);
|
2014-08-21 17:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|