mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #1607 from haukepetersen/add_nrf_random
cpu/nrf51822: added random number generator driver
This commit is contained in:
commit
6f83609107
@ -85,6 +85,13 @@
|
||||
#define UART_0_PIN_CTS 10
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Random Number Generator configuration
|
||||
* @{
|
||||
*/
|
||||
#define RANDOM_NUMOF (1U)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name GPIO configuration
|
||||
* @{
|
||||
|
@ -70,6 +70,13 @@
|
||||
#define UART_0_PIN_TX 9
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name Random Number Generator configuration
|
||||
* @{
|
||||
*/
|
||||
#define RANDOM_NUMOF (1U)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @name GPIO configuration
|
||||
|
57
cpu/nrf51822/periph/random.c
Normal file
57
cpu/nrf51822/periph/random.c
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 cpu_nrf51822
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Driver for the NRF51822 random number generator
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "cpu.h"
|
||||
#include "periph_conf.h"
|
||||
#include "periph/random.h"
|
||||
|
||||
/* guard file in case no random device was specified */
|
||||
#if RANDOM_NUMOF
|
||||
|
||||
void random_init(void)
|
||||
{
|
||||
NRF_RNG->POWER = 1;
|
||||
NRF_RNG->TASKS_START = 1;
|
||||
}
|
||||
|
||||
int random_read(char *buf, unsigned int num)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
|
||||
while (count < num) {
|
||||
while (NRF_RNG->EVENTS_VALRDY == 0);
|
||||
NRF_RNG->EVENTS_VALRDY = 0;
|
||||
buf[count++] = (char)NRF_RNG->VALUE;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void random_poweron(void)
|
||||
{
|
||||
NRF_RNG->POWER = 1;
|
||||
}
|
||||
|
||||
void random_poweroff(void)
|
||||
{
|
||||
NRF_RNG->POWER = 0;
|
||||
}
|
||||
|
||||
#endif /* RANDOM_NUMOF */
|
Loading…
Reference in New Issue
Block a user