mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cpu/esp*: move periph/hwrng to cpu/esp_common
This commit is contained in:
parent
d90164b19a
commit
0292f8b6a3
@ -382,6 +382,17 @@ typedef struct {
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name RNG configuration
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief The address of the register for accessing the hardware RNG.
|
||||
*/
|
||||
#define RNG_DATA_REG_ADDR (0x3ff75144)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name SPI configuration
|
||||
*
|
||||
|
@ -206,6 +206,17 @@ typedef struct {
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name RNG configuration
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief The address of the register for accessing the hardware RNG.
|
||||
*/
|
||||
#define RNG_DATA_REG_ADDR (0x3ff20e44)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name SPI configuration
|
||||
*
|
||||
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Gunar Schorcht
|
||||
*
|
||||
* 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_esp8266
|
||||
* @ingroup drivers_periph_hwrng
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Low-level random number generator driver implementation
|
||||
*
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "cpu.h"
|
||||
#include "periph_conf.h"
|
||||
#include "periph/hwrng.h"
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
static const uint32_t* RNG_DATA_REG = (uint32_t*)0x3ff75144;
|
||||
#else
|
||||
static const uint32_t* RNG_DATA_REG = (uint32_t*)0x3ff20e44;
|
||||
#endif
|
||||
|
||||
void hwrng_init(void)
|
||||
{
|
||||
/* no need for initialization */
|
||||
}
|
||||
|
||||
void hwrng_read(void *buf, unsigned int num)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
uint8_t *b = (uint8_t *)buf;
|
||||
|
||||
while (count < num) {
|
||||
/* read next 4 bytes of random data */
|
||||
uint32_t tmp = *RNG_DATA_REG;
|
||||
|
||||
/* copy data into result vector */
|
||||
for (int i = 0; i < 4 && count < num; i++) {
|
||||
b[count++] = (uint8_t)tmp;
|
||||
tmp = tmp >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t hwrand (void)
|
||||
{
|
||||
uint32_t _tmp;
|
||||
hwrng_read(&_tmp, sizeof(uint32_t));
|
||||
return _tmp;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Gunar Schorcht
|
||||
* Copyright (C) 2019 Gunar Schorcht
|
||||
*
|
||||
* 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
|
||||
@ -7,12 +7,12 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup cpu_esp32
|
||||
* @ingroup cpu_esp_common
|
||||
* @ingroup drivers_periph_hwrng
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Low-level random number generator driver implementation
|
||||
* @brief Low-level random number generator driver implementation for ESP SoCs
|
||||
*
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*
|
||||
@ -23,13 +23,13 @@
|
||||
#include "periph_conf.h"
|
||||
#include "periph/hwrng.h"
|
||||
|
||||
static const uint32_t* RNG_DATA_REG = (uint32_t*)0x3ff75144;
|
||||
#define RNG_DATA_REG (*(volatile uint32_t *)RNG_DATA_REG_ADDR)
|
||||
|
||||
void hwrng_init(void)
|
||||
{
|
||||
/* no need for initialization */
|
||||
}
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
void hwrng_read(void *buf, unsigned int num)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
@ -37,7 +37,7 @@ void hwrng_read(void *buf, unsigned int num)
|
||||
|
||||
while (count < num) {
|
||||
/* read next 4 bytes of random data */
|
||||
uint32_t tmp = *RNG_DATA_REG;
|
||||
uint32_t tmp = RNG_DATA_REG;
|
||||
|
||||
/* copy data into result vector */
|
||||
for (int i = 0; i < 4 && count < num; i++) {
|
||||
@ -47,7 +47,7 @@ void hwrng_read(void *buf, unsigned int num)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t hwrand (void)
|
||||
uint32_t hwrand(void)
|
||||
{
|
||||
uint32_t _tmp;
|
||||
hwrng_read(&_tmp, sizeof(uint32_t));
|
Loading…
Reference in New Issue
Block a user