From 2f9e3c89e1cd6e3b76b1a51bb10ddc6cdd0472e3 Mon Sep 17 00:00:00 2001
From: Hauke Petersen <hauke.petersen@fu-berlin.de>
Date: Tue, 7 Feb 2017 13:20:39 +0100
Subject: [PATCH] periph/hwrng: use void* buf for hwrng_read()

---
 cpu/cc2538/periph/hwrng.c              | 8 +++++---
 cpu/kinetis_common/periph/hwrng_rnga.c | 5 +++--
 cpu/kinetis_common/periph/hwrng_rngb.c | 5 +++--
 cpu/native/periph/hwrng.c              | 8 +++++---
 cpu/nrf5x_common/periph/hwrng.c        | 5 +++--
 cpu/sam3/periph/hwrng.c                | 5 +++--
 cpu/stm32f2/periph/hwrng.c             | 5 +++--
 cpu/stm32f4/periph/hwrng.c             | 5 +++--
 drivers/include/periph/hwrng.h         | 2 +-
 9 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/cpu/cc2538/periph/hwrng.c b/cpu/cc2538/periph/hwrng.c
index 705e0d2a0a..7505674052 100644
--- a/cpu/cc2538/periph/hwrng.c
+++ b/cpu/cc2538/periph/hwrng.c
@@ -69,16 +69,18 @@ void hwrng_init(void)
     RFCORE_SFR_RFST = ISRFOFF;
 }
 
-void hwrng_read(uint8_t *buf, unsigned int num)
+void hwrng_read(void *buf, unsigned int num)
 {
     unsigned count;
+    uint8_t *b = (uint8_t *)buf;
+
     for (count = 0; count < num; ) {
         /* Clock the RNG LSFR once: */
         SOC_ADC->cc2538_adc_adccon1.ADCCON1bits.RCTRL = 1;
 
         /* Read up to 2 bytes of hwrng data: */
-        buf[count++] = SOC_ADC_RNDL;
+        b[count++] = SOC_ADC_RNDL;
         if (count >= num) break;
-        buf[count++] = SOC_ADC_RNDH;
+        b[count++] = SOC_ADC_RNDH;
     }
 }
diff --git a/cpu/kinetis_common/periph/hwrng_rnga.c b/cpu/kinetis_common/periph/hwrng_rnga.c
index ed2ddbd694..9adf07d110 100644
--- a/cpu/kinetis_common/periph/hwrng_rnga.c
+++ b/cpu/kinetis_common/periph/hwrng_rnga.c
@@ -32,9 +32,10 @@ void hwrng_init(void)
     /* nothing to do here */
 }
 
-void hwrng_read(uint8_t *buf, unsigned int num)
+void hwrng_read(void *buf, unsigned int num)
 {
     unsigned int count = 0;
+    uint8_t *b = (uint8_t *)buf;
 
     /* power on and enable the device */
     HWRNG_CLKEN();
@@ -53,7 +54,7 @@ void hwrng_read(uint8_t *buf, unsigned int num)
 
         /* copy data into result vector */
         for (int i = 0; i < 4 && count < num; i++) {
-            buf[count++] = (uint8_t)tmp;
+            b[count++] = (uint8_t)tmp;
             tmp = tmp >> 8;
         }
     }
diff --git a/cpu/kinetis_common/periph/hwrng_rngb.c b/cpu/kinetis_common/periph/hwrng_rngb.c
index 7f105ca989..865c204e76 100644
--- a/cpu/kinetis_common/periph/hwrng_rngb.c
+++ b/cpu/kinetis_common/periph/hwrng_rngb.c
@@ -33,9 +33,10 @@ void hwrng_init(void)
     /* nothing to be done here */
 }
 
-void hwrng_read(uint8_t *buf, unsigned int num)
+void hwrng_read(void *buf, unsigned int num)
 {
     unsigned int count = 0;
+    uint8_t *b = (uint8_t *)buf;
 
     HWRNG_CLKEN();
 
@@ -59,7 +60,7 @@ void hwrng_read(uint8_t *buf, unsigned int num)
 
         /* copy data into result vector */
         for (int i = 0; i < 4 && count < num; i++) {
-            buf[count++] = (uint8_t)tmp;
+            b[count++] = (uint8_t)tmp;
             tmp = tmp >> 8;
         }
     }
diff --git a/cpu/native/periph/hwrng.c b/cpu/native/periph/hwrng.c
index 3ce70dac94..553acd282b 100644
--- a/cpu/native/periph/hwrng.c
+++ b/cpu/native/periph/hwrng.c
@@ -70,8 +70,10 @@ void hwrng_init(void)
     initialized = 1;
 }
 
-void hwrng_read(uint8_t *buf, unsigned int num)
+void hwrng_read(void *buf, unsigned int num)
 {
+    uint8_t *b = (uint8_t *)buf;
+
     if (!initialized) {
         warnx("hwrng_read: random device not initialized, failing\n");
         return;
@@ -80,10 +82,10 @@ void hwrng_read(uint8_t *buf, unsigned int num)
     DEBUG("hwrng_read: writing %u bytes\n", num);
     switch (_native_rng_mode) {
         case 0:
-            _native_rng_read_hq(buf, num);
+            _native_rng_read_hq(b, num);
             break;
         case 1:
-            _native_rng_read_det(buf, num);
+            _native_rng_read_det(b, num);
             break;
         default:
             err(EXIT_FAILURE, "hwrng_read: _native_rng_mode is in invalid state %i\n",
diff --git a/cpu/nrf5x_common/periph/hwrng.c b/cpu/nrf5x_common/periph/hwrng.c
index 832d1378b7..ab3eb3ee2e 100644
--- a/cpu/nrf5x_common/periph/hwrng.c
+++ b/cpu/nrf5x_common/periph/hwrng.c
@@ -29,9 +29,10 @@ void hwrng_init(void)
     /* nothing to do here */
 }
 
-void hwrng_read(uint8_t *buf, unsigned int num)
+void hwrng_read(void *buf, unsigned int num)
 {
     unsigned int count = 0;
+    uint8_t *b = (uint8_t *)buf;
 
     /* power on RNG */
 #ifdef CPU_FAM_NRF51
@@ -46,7 +47,7 @@ void hwrng_read(uint8_t *buf, unsigned int num)
             cpu_sleep_until_event();
         }
 
-        buf[count++] = (uint8_t)NRF_RNG->VALUE;
+        b[count++] = (uint8_t)NRF_RNG->VALUE;
         /* NRF51 PAN #21 -> read value before clearing VALRDY */
         NRF_RNG->EVENTS_VALRDY = 0;
     }
diff --git a/cpu/sam3/periph/hwrng.c b/cpu/sam3/periph/hwrng.c
index 41e02bc336..15b40e15ec 100644
--- a/cpu/sam3/periph/hwrng.c
+++ b/cpu/sam3/periph/hwrng.c
@@ -32,9 +32,10 @@ void hwrng_init(void)
     /* no need for initialization */
 }
 
-void hwrng_read(uint8_t *buf, unsigned int num)
+void hwrng_read(void *buf, unsigned int num)
 {
     unsigned count = 0;
+    uint8_t *b = (uint8_t *)buf;
 
     /* enable clock signal for TRNG module */
     PMC->PMC_PCER1 |= PMC_PCER1_PID41;
@@ -48,7 +49,7 @@ void hwrng_read(uint8_t *buf, unsigned int num)
         uint32_t tmp = TRNG->TRNG_ODATA;
         /* extract copy bytes to result */
         for (int i = 0; i < 4 && count < num; i++) {
-            buf[count++] = (uint8_t)tmp;
+            b[count++] = (uint8_t)tmp;
             tmp = tmp >> 8;
         }
     }
diff --git a/cpu/stm32f2/periph/hwrng.c b/cpu/stm32f2/periph/hwrng.c
index 6412c1e672..52bf752ac4 100644
--- a/cpu/stm32f2/periph/hwrng.c
+++ b/cpu/stm32f2/periph/hwrng.c
@@ -36,11 +36,12 @@ void hwrng_init(void)
 }
 
 
-void hwrng_read(uint8_t *buf, unsigned int num)
+void hwrng_read(void *buf, unsigned int num)
 {
     /* cppcheck-suppress variableScope */
     uint32_t tmp;
     unsigned int count = 0;
+    uint8_t *b = (uint8_t *)buf;
 
     /* enable RNG reset state */
     periph_clk_en(AHB2, RCC_AHB2ENR_RNGEN);
@@ -54,7 +55,7 @@ void hwrng_read(uint8_t *buf, unsigned int num)
         tmp = RNG->DR;
         /* copy data into result vector */
         for (int i = 0; i < 4 && count < num; i++) {
-            buf[count++] = (uint8_t)tmp;
+            b[count++] = (uint8_t)tmp;
             tmp = tmp >> 8;
         }
     }
diff --git a/cpu/stm32f4/periph/hwrng.c b/cpu/stm32f4/periph/hwrng.c
index e54deeedd7..38f1543b62 100644
--- a/cpu/stm32f4/periph/hwrng.c
+++ b/cpu/stm32f4/periph/hwrng.c
@@ -30,9 +30,10 @@ void hwrng_init(void)
     /* no need for initialization */
 }
 
-void hwrng_read(uint8_t *buf, unsigned int num)
+void hwrng_read(void *buf, unsigned int num)
 {
     unsigned int count = 0;
+    uint8_t *b = (uint8_t *)buf;
 
     /* power on and enable the device */
     periph_clk_en(AHB2, RCC_AHB2ENR_RNGEN);
@@ -46,7 +47,7 @@ void hwrng_read(uint8_t *buf, unsigned int num)
         uint32_t tmp = RNG->DR;
         /* copy data into result vector */
         for (int i = 0; i < 4 && count < num; i++) {
-            buf[count++] = (uint8_t)tmp;
+            b[count++] = (uint8_t)tmp;
             tmp = tmp >> 8;
         }
     }
diff --git a/drivers/include/periph/hwrng.h b/drivers/include/periph/hwrng.h
index e3c693143d..8c106f5ee5 100644
--- a/drivers/include/periph/hwrng.h
+++ b/drivers/include/periph/hwrng.h
@@ -57,7 +57,7 @@ void hwrng_init(void);
  * @param[in] buf   destination buffer to write the bytes to
  * @param[in] num   number of bytes to get from device
  */
-void hwrng_read(uint8_t *buf, unsigned int num);
+void hwrng_read(void *buf, unsigned int num);
 
 #ifdef __cplusplus
 }
-- 
GitLab