zephyr/samples/drivers/random/src/main.c
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00

46 lines
752 B
C

/*
* Copyright (c) 2016 ARM Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <random.h>
#include <stdio.h>
void main(void)
{
struct device *dev;
printf("Random Example! %s\n", CONFIG_ARCH);
dev = device_get_binding(CONFIG_RANDOM_NAME);
if (!dev) {
printf("error: no random device\n");
return;
}
printf("random device is %p, name is %s\n",
dev, dev->config->name);
while (1) {
#define BUFFER_LENGTH 10
uint8_t buffer[BUFFER_LENGTH];
int r;
r = random_get_entropy(dev, buffer, BUFFER_LENGTH);
if (r) {
printf("random_get_entropy failed: %d\n", r);
break;
};
for (int i = 0; i < BUFFER_LENGTH; i++) {
printf(" 0x%x", buffer[i]);
};
printf("\n");
k_sleep(1000);
}
}