From 925a908d957f11e40d2935130232322109cedd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Thu, 9 Nov 2017 08:01:43 +0100 Subject: [PATCH] kinetis: Update RNGA driver configuration to automatically detect the module --- boards/frdm-k22f/include/periph_conf.h | 9 --------- boards/frdm-k64f/include/periph_conf.h | 9 --------- boards/mulle/include/periph_conf.h | 9 --------- boards/pba-d-01-kw2x/include/periph_conf.h | 10 ---------- cpu/kinetis/include/cpu_conf_kinetis.h | 16 ++++++++++++++++ cpu/kinetis/periph/hwrng.c | 3 ++- 6 files changed, 18 insertions(+), 38 deletions(-) diff --git a/boards/frdm-k22f/include/periph_conf.h b/boards/frdm-k22f/include/periph_conf.h index 937399c377..2fbdf8c2c1 100644 --- a/boards/frdm-k22f/include/periph_conf.h +++ b/boards/frdm-k22f/include/periph_conf.h @@ -269,15 +269,6 @@ static const spi_conf_t spi_config[] = { #define RTT_MAX_VALUE (0xffffffff) /** @} */ -/** - * @name Random Number Generator configuration - * @{ - */ -#define KINETIS_RNGA RNG -#define HWRNG_CLKEN() (SIM->SCGC6 |= (1 << 9)) -#define HWRNG_CLKDIS() (SIM->SCGC6 &= ~(1 << 9)) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/frdm-k64f/include/periph_conf.h b/boards/frdm-k64f/include/periph_conf.h index f99f67e4f4..2e01656a61 100644 --- a/boards/frdm-k64f/include/periph_conf.h +++ b/boards/frdm-k64f/include/periph_conf.h @@ -264,15 +264,6 @@ static const spi_conf_t spi_config[] = { #define RTT_MAX_VALUE (0xffffffff) /** @} */ -/** - * @name Random Number Generator configuration - * @{ - */ -#define KINETIS_RNGA RNG -#define HWRNG_CLKEN() (SIM->SCGC6 |= (1 << 9)) -#define HWRNG_CLKDIS() (SIM->SCGC6 &= ~(1 << 9)) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/mulle/include/periph_conf.h b/boards/mulle/include/periph_conf.h index d9a3dd0c45..87dc49346c 100644 --- a/boards/mulle/include/periph_conf.h +++ b/boards/mulle/include/periph_conf.h @@ -392,15 +392,6 @@ static const spi_conf_t spi_config[] = { /** @} */ - -/** - * @name Random Number Generator configuration - * @{ - */ -#define HWRNG_CLKEN() (BITBAND_REG32(SIM->SCGC3, SIM_SCGC3_RNGA_SHIFT) = 1) -#define HWRNG_CLKDIS() (BITBAND_REG32(SIM->SCGC3, SIM_SCGC3_RNGA_SHIFT) = 0) -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/pba-d-01-kw2x/include/periph_conf.h b/boards/pba-d-01-kw2x/include/periph_conf.h index 1e11edfe90..461569f538 100644 --- a/boards/pba-d-01-kw2x/include/periph_conf.h +++ b/boards/pba-d-01-kw2x/include/periph_conf.h @@ -295,16 +295,6 @@ static const spi_conf_t spi_config[] = { #define RTT_MAX_VALUE (0xffffffff) /** @} */ -/** - * @name Random Number Generator configuration - * @{ - */ -#define KINETIS_RNGA RNG -#define HWRNG_CLKEN() (SIM->SCGC6 |= (1 << 9)) -#define HWRNG_CLKDIS() (SIM->SCGC6 &= ~(1 << 9)) - -/** @} */ - #ifdef __cplusplus } #endif diff --git a/cpu/kinetis/include/cpu_conf_kinetis.h b/cpu/kinetis/include/cpu_conf_kinetis.h index dd5ef1da83..135bdc9d09 100644 --- a/cpu/kinetis/include/cpu_conf_kinetis.h +++ b/cpu/kinetis/include/cpu_conf_kinetis.h @@ -112,6 +112,22 @@ extern "C" #endif /** @} */ +/** + * @name Hardware random number generator module configuration + * @{ + */ +#if !defined(HWRNG_CLKEN) && defined(RNG) && !defined(RNG_CMD_ST_MASK) +#define KINETIS_RNGA RNG +#if defined(SIM_SCGC3_RNGA_SHIFT) +#define HWRNG_CLKEN() (bit_set32(&SIM->SCGC3, SIM_SCGC3_RNGA_SHIFT)) +#define HWRNG_CLKDIS() (bit_clear32(&SIM->SCGC3, SIM_SCGC3_RNGA_SHIFT)) +#elif defined(SIM_SCGC6_RNGA_SHIFT) +#define HWRNG_CLKEN() (bit_set32(&SIM->SCGC6, SIM_SCGC6_RNGA_SHIFT)) +#define HWRNG_CLKDIS() (bit_clear32(&SIM->SCGC6, SIM_SCGC6_RNGA_SHIFT)) +#endif +#endif /* KINETIS_RNGA */ +/** @} */ + #ifdef __cplusplus } #endif diff --git a/cpu/kinetis/periph/hwrng.c b/cpu/kinetis/periph/hwrng.c index 0348102b59..3e409e040e 100644 --- a/cpu/kinetis/periph/hwrng.c +++ b/cpu/kinetis/periph/hwrng.c @@ -25,6 +25,7 @@ #include "cpu.h" #include "periph/hwrng.h" #include "periph_conf.h" +#include "bit.h" #ifdef KINETIS_RNGA @@ -60,7 +61,7 @@ void hwrng_read(void *buf, unsigned int num) } } - /* power of the device */ + /* power off the device */ KINETIS_RNGA->CR = 0; HWRNG_CLKDIS(); }