[PATCH] Added Getentropy() support to beagle BSP
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Mar 15 05:59:37 UTC 2018
On 15/03/18 05:56, Udit agarwal wrote:
> c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
> b/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
> index 11e24dc..b26b6a8 100644
> --- a/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
> +++ b/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
> @@ -17,6 +17,8 @@
> #include <string.h>
> #include <rtems/sysinit.h>
>
> +static rtems_mutex atsam_trng_reg =
> RTEMS_MUTEX_INITIALIZER("atsam_trng_reg");
Is this a register or a mutex?
> +
> static void atsam_trng_enable(void)
> {
> PMC_EnablePeripheral(ID_TRNG);
> @@ -29,9 +31,12 @@ int getentropy(void *ptr, size_t n)
> uint32_t random;
> size_t copy;
>
> + rtems_mutex_lock(&atsam_trng_reg);
> while ((TRNG_GetStatus() & TRNG_ISR_DATRDY) == 0) {
> /* wait */
> }
> +
> + rtems_mutex_unlock(&atsam_trng_reg);
Now the status register read is protected by a mutex.
> random = TRNG_GetRandData();
Can you ensure that this read is correct in a multi-threaded application
(the status register has the right value during the read)?
>
> /*
> @@ -51,6 +56,7 @@ int getentropy(void *ptr, size_t n)
> ptr += copy;
> }
>
> + rtems_mutex_destroy(&atsam_trng_reg);
Here you destroy the mutex. What happens if you call getentropy() a
second time?
> return 0;
> }
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber at embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
More information about the devel
mailing list