From 49abcb3fffd6d1414174bf75c6531947ef1ce66e Mon Sep 17 00:00:00 2001 From: Fabien Chereau Date: Tue, 12 Jan 2016 13:53:39 +0100 Subject: [PATCH] device: add a new macro to obtain the device object symbol name The new SYS_GET_DEVICE_NAME macro can be used in combination with SYS_GET_DEVICE to obtain an external reference to a static device object, e.g.: extern struct device SYS_GET_DEVICE_NAME(my_device_name); struct device* dev = SYS_GET_DEVICE(my_device_name); dev is here set at compile time. Change-Id: I9094925c685177f01e0cef194ec382ad49658f9d Signed-off-by: Fabien Chereau --- include/init.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/include/init.h b/include/init.h index fe3ed29b7dd..41c2966134a 100644 --- a/include/init.h +++ b/include/init.h @@ -85,6 +85,23 @@ .config = &(config_##name),\ .driver_data = data} +/** + * @def SYS_GET_DEVICE_NAME + * + * @brief Expands to the full name of a global device object + * + * @details Return the full name of a device object symbol created by + * SYS_DEFINE_DEVICE(), using the @name provided to SYS_DEFINE_DEVICE(). + * + * It is meant to be used for declaring extern symbols pointing on device + * objects before using the SYS_GET_DEVICE macro to get the device object. + * + * @param name The same name provided to SYS_DEFINE_DEVICE() + * + * @return The exanded name of the device object created by SYS_DEFINE_DEVICE() + */ +#define SYS_GET_DEVICE_NAME(name) (_CONCAT(__initconfig_, name)) + /** * @def SYS_GET_DEVICE * @@ -97,6 +114,6 @@ * * @return A pointer to the device object created by SYS_DEFINE_DEVICE() */ -#define SYS_GET_DEVICE(name) (&(_CONCAT(__initconfig_, name))) +#define SYS_GET_DEVICE(name) (&SYS_GET_DEVICE_NAME(name)) #endif /* _INIT_H_ */