From 7a1e221733398bf6b24110f5ce35104b80597f01 Mon Sep 17 00:00:00 2001 From: Dirk Brandewie Date: Thu, 15 Oct 2015 08:23:03 -0700 Subject: [PATCH] init: add SYS_GET_DEVICE() macro to bury &__initconfig_* names usage. Add a macro to retrieve the device structure for a config structure by name. This avoids the very error prone activity of the developer having to *know* the way the internal object is named. Change-Id: I1d7857d5aad6dfd4b1b46f63b946aad1ae3a6dc4 Signed-off-by: Dirk Brandewie --- include/init.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/init.h b/include/init.h index 298d5e886fa..2f09eeb9023 100644 --- a/include/init.h +++ b/include/init.h @@ -83,6 +83,24 @@ .config = &(config_##name),\ .driver_data = data} +/** + * @def SYS_GET_DEVICE + * + * @brief Obtain a pointer to a device object by name + * + * @details Return the address of a device object created by + * SYS_DEFINE_DEVICE(), using the @name provided to SYS_DEFINE_DEVICE(). + * + * @param name The same name provided to SYS_DEFINE_DEVICE() + * + * @return A pointer to the device object created by SYS_DEFINE_DEVICE() + */ + +#define _PASTE2(a, b) a##b +#define _PASTE(a, b) _PASTE2(a, b) + +#define SYS_GET_DEVICE(name) (&(_PASTE(__initconfig_, name))) + /* The following legacy APIs are provided for backwards compatibility */ #define pre_kernel_core_init(cfg, data) \