[riot-notifications] [RIOT-OS/RIOT] periph/hwrng: Introduce generic hwrng_read(), allow for leaner HWRNG implementations (#11924)

benpicco notifications at github.com
Fri Jul 26 13:48:17 CEST 2019


### Contribution description
Most HWRNGs are pretty simple. They provide a register that contains random data. Some HWRNG implementations already expose this single register by providing a `hwrand(void)` function that returns a 32 bit value.

The `hwrng_read()` API function expects a buffer, so currently all implementations invent (or copy & paste) their way to fill a buffer of arbitrary size with 32 bit values.

This PR does the following things:
 - add the `hwrand(void)` function to the hwrng API. Not only is it often more convenient, it also allows for a generic `hwrng_read()` implementation.
 - implement `hwrand()` for all drivers that didn't have it yet
 - implement a generic `hwrng_read()` that uses `hwrand()` and is a bit more efficient than the current implementation
 - Introduce `HWRNG_HAS_INIT` & `HWRNG_HAS_POWERONOFF` analogous to the watchdog API so we don't have to call empty functions if they are not needed.

### Testing procedure

All platforms should still build & run `tests/rng` and `tests/periph_hwrng` as they did before.

On same54 a small speedup can be observed using the `speed` test in `tests/rng` (set `source 2` to select the HWRNG):

before: `Collected 11009147 samples in 10.000008 seconds (4300 KiB/s).`
after: `Collected 12244868 samples in 10.000009 seconds (4783 KiB/s).`


### Issues/PRs references

<!--
Examples: Fixes #1234. See also #5678. Depends on PR #9876.

Please use keywords (e.g., fixes, resolve) with the links to the issues you
resolved, this way they will be automatically closed when your pull request
is merged. See https://help.github.com/articles/closing-issues-using-keywords/.
-->

You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/11924

-- Commit Summary --

  * periph/hwrng: add hwrand() to the API
  * cpu/kinetis/hwrng: Implement hwrand()
  * cpu/nrf5x_common/hwrng: Implement hwrand()
  * cpu/stm32_common/hwrng: Implement hwrand()
  * cpu/efm32/hwrng: Implement hwrand()
  * cpu/cc2538/hwrng: Implement hwrand()
  * cpu/native/hwrng: Implement hwrand()
  * cpu/sam3/hwrng: Implement hwrand()
  * cpu/mips_pic32/hwrng: Implement hwrand()
  * cpu/esp8266/hwrng: Implement hwrand()
  * drivers/periph_common/hwrng: provide generic hwrng_read() function
  * drivers/periph_common/hwrng: introduce HWRNG_HAS_INIT
  * cpu/esp32: use generic hwrng_read()
  * cpu/kinetis: use generic hwrng_read()
  * pu/kinetis/hwrng: no need for hwrng_init()
  * cpu/esp32: use generic hwrng_read()
  * cpu/efm32: use generic hwrng_read()
  * cpu/cc2538: add config for HWRNG
  * cpu/native: add config for HWRNG
  * cpu/sam3: use generic hwrng_read()
  * cpu/mips_pic32_common: add config for HWRNG
  * cpu/esp8266: use generic hwrng_read()

-- File Changes --

    M cpu/cc2538/include/periph_cpu.h (6)
    M cpu/cc2538/periph/hwrng.c (18)
    M cpu/efm32/include/periph_cpu.h (7)
    M cpu/efm32/periph/hwrng.c (17)
    M cpu/esp32/include/periph_cpu.h (6)
    M cpu/esp32/periph/hwrng.c (30)
    M cpu/esp8266/include/periph_cpu.h (6)
    M cpu/esp8266/periph/hwrng.c (28)
    M cpu/kinetis/include/periph_cpu.h (7)
    M cpu/kinetis/periph/hwrng.c (36)
    M cpu/mips_pic32_common/include/periph_cpu_common.h (6)
    M cpu/mips_pic32_common/periph/hwrng.c (12)
    M cpu/native/include/periph_cpu.h (6)
    M cpu/native/periph/hwrng.c (7)
    M cpu/nrf5x_common/periph/hwrng.c (43)
    M cpu/sam3/include/periph_cpu.h (7)
    M cpu/sam3/periph/hwrng.c (32)
    M cpu/stm32_common/include/periph_cpu_common.h (7)
    M cpu/stm32_common/periph/hwrng.c (33)
    M drivers/include/periph/hwrng.h (57)
    A drivers/periph_common/hwrng.c (64)
    M drivers/periph_common/init.c (2)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/11924.patch
https://github.com/RIOT-OS/RIOT/pull/11924.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11924
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190726/76aa2334/attachment.htm>


More information about the notifications mailing list