From f9417824420e4d9e09e4141094993ef644703e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlga=CC=8Ard?= Date: Tue, 9 Mar 2021 14:56:41 +0100 Subject: [PATCH] devfs: Split devfs-random into two files using submodules --- sys/fs/devfs/Makefile | 2 ++ sys/fs/devfs/{random-vfs.c => hwrng.c} | 22 --------------- sys/fs/devfs/random.c | 37 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 22 deletions(-) rename sys/fs/devfs/{random-vfs.c => hwrng.c} (62%) create mode 100644 sys/fs/devfs/random.c diff --git a/sys/fs/devfs/Makefile b/sys/fs/devfs/Makefile index 67d6ef1eb3..a218490ff0 100644 --- a/sys/fs/devfs/Makefile +++ b/sys/fs/devfs/Makefile @@ -1,2 +1,4 @@ MODULE=devfs +SRC = devfs.c auto_init_devfs.c +SUBMODULES = 1 include $(RIOTBASE)/Makefile.base diff --git a/sys/fs/devfs/random-vfs.c b/sys/fs/devfs/hwrng.c similarity index 62% rename from sys/fs/devfs/random-vfs.c rename to sys/fs/devfs/hwrng.c index d5be014193..c174e8f016 100644 --- a/sys/fs/devfs/random-vfs.c +++ b/sys/fs/devfs/hwrng.c @@ -21,8 +21,6 @@ #include "vfs.h" -#ifdef MODULE_DEVFS_HWRNG - #include "periph/hwrng.h" static ssize_t hwrng_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes); @@ -39,23 +37,3 @@ static ssize_t hwrng_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes) return nbytes; } -#endif /* MODULE_PERIPH_HWRNG */ - -#ifdef MODULE_DEVFS_RANDOM - -#include "random.h" - -static ssize_t random_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes); - -const vfs_file_ops_t random_vfs_ops = { - .read = random_vfs_read, -}; - -static ssize_t random_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes) -{ - (void)filp; - random_bytes(dest, nbytes); - - return nbytes; -} -#endif /* MODULE_RANDOM */ diff --git a/sys/fs/devfs/random.c b/sys/fs/devfs/random.c new file mode 100644 index 0000000000..3eb3be7cea --- /dev/null +++ b/sys/fs/devfs/random.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2017 OTA keys S.A. + * + * 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 sys_fs_devfs + * @{ + * + * @file + * @brief Random backends for devfs implementation + * + * @author Vincent Dupont + * + * @} + */ + +#include "vfs.h" +#include "random.h" + +static ssize_t random_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes); + +const vfs_file_ops_t random_vfs_ops = { + .read = random_vfs_read, +}; + +static ssize_t random_vfs_read(vfs_file_t *filp, void *dest, size_t nbytes) +{ + (void)filp; + random_bytes(dest, nbytes); + + return nbytes; +}