diff --git a/include/device.h b/include/device.h index 54aeec23b9f..7d7fcf3f57e 100644 --- a/include/device.h +++ b/include/device.h @@ -108,15 +108,15 @@ extern "C" { #define DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, cfg_info, \ level, prio, api) \ \ - static struct device_config __config_##dev_name __used \ + static struct device_config _CONCAT(__config_, dev_name) __used \ __attribute__((__section__(".devconfig.init"))) = { \ .name = drv_name, .init = (init_fn), \ .config_info = (cfg_info) \ }; \ \ - static struct device (__device_##dev_name) __used \ + static struct device _CONCAT(__device_, dev_name) __used \ __attribute__((__section__(".init_" #level STRINGIFY(prio)))) = { \ - .config = &(__config_##dev_name), \ + .config = &_CONCAT(__config_, dev_name), \ .driver_api = api, \ .driver_data = data \ } @@ -162,16 +162,16 @@ extern "C" { #define DEVICE_AND_API_INIT_PM(dev_name, drv_name, init_fn, device_pm_ops, \ data, cfg_info, level, prio, api) \ \ - static struct device_config __config_##dev_name __used \ + static struct device_config _CONCAT(__config_, dev_name) __used \ __attribute__((__section__(".devconfig.init"))) = { \ .name = drv_name, .init = (init_fn), \ .dev_pm_ops = (device_pm_ops), \ .config_info = (cfg_info) \ }; \ \ - static struct device (__device_##dev_name) __used \ + static struct device _CONCAT(__device_, dev_name) __used \ __attribute__((__section__(".init_" #level STRINGIFY(prio)))) = { \ - .config = &(__config_##dev_name), \ + .config = &_CONCAT(__config_, dev_name), \ .driver_api = api, \ .driver_data = data \ } @@ -191,7 +191,7 @@ extern struct device_pm_ops device_pm_ops_nop; #define DEVICE_DEFINE(dev_name, drv_name, init_fn, control_fn, \ data, cfg_info, level, prio, api) \ \ - static struct device_config __config_##dev_name __used \ + static struct device_config _CONCAT(__config_, dev_name) __used \ __attribute__((__section__(".devconfig.init"))) = { \ .name = drv_name, .init = (init_fn), \ .device_control = (control_fn), \ @@ -199,9 +199,9 @@ extern struct device_pm_ops device_pm_ops_nop; .config_info = (cfg_info) \ }; \ \ - static struct device (__device_##dev_name) __used \ + static struct device _CONCAT(__device_, dev_name) __used \ __attribute__((__section__(".init_" #level STRINGIFY(prio)))) = { \ - .config = &(__config_##dev_name), \ + .config = &_CONCAT(__config_, dev_name), \ .driver_api = api, \ .driver_data = data \ } @@ -306,7 +306,7 @@ struct device_pm_ops { * @param _resume name of the resume function */ #define DEFINE_DEVICE_PM_OPS(_name, _suspend, _resume) \ - static struct device_pm_ops _name##_dev_pm_ops = { \ + static struct device_pm_ops _CONCAT(_name, _dev_pm_ops) = { \ .suspend = _suspend, \ .resume = _resume, \ } @@ -320,8 +320,7 @@ struct device_pm_ops { * * @param _name name of the device */ -#define DEVICE_PM_OPS_GET(_name) \ - (&_name##_dev_pm_ops) +#define DEVICE_PM_OPS_GET(_name) &_CONCAT(_name, _dev_pm_ops) /** * @} diff --git a/include/init.h b/include/init.h index ee4e5eafca5..1274e43785e 100644 --- a/include/init.h +++ b/include/init.h @@ -38,6 +38,11 @@ extern "C" { #define _SYS_INIT_LEVEL_MICROKERNEL 3 #define _SYS_INIT_LEVEL_APPLICATION 4 +/* Counter use to avoid issues if two or more system devices are declared + * in the same C file with the same init function + */ +#define _SYS_NAME(init_fn) _CONCAT(_CONCAT(sys_init_, init_fn), __COUNTER__) + /** * @def SYS_INIT * @@ -53,7 +58,7 @@ extern "C" { * DEVICE_INIT for details. */ #define SYS_INIT(init_fn, level, prio) \ - DEVICE_INIT(sys_init_##init_fn, "", init_fn, NULL, NULL, level, prio) + DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio) /** * @def SYS_INIT_PM @@ -68,15 +73,15 @@ extern "C" { #ifdef CONFIG_DEVICE_POWER_MANAGEMENT #define SYS_INIT_PM(drv_name, init_fn, device_pm_ops, level, prio) \ - DEVICE_INIT_PM(sys_init_##init_fn, drv_name, init_fn, device_pm_ops, \ + DEVICE_INIT_PM(_SYS_NAME(init_fn), drv_name, init_fn, device_pm_ops, \ NULL, NULL, level, prio) #else #define SYS_INIT_PM(drv_name, init_fn, device_pm_ops, level, prio) \ - DEVICE_INIT(sys_init_##init_fn, "", init_fn, NULL, NULL, level, prio) + DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio) #endif #define SYS_DEVICE_DEFINE(drv_name, init_fn, control_fn, level, prio) \ - DEVICE_DEFINE(sys_init_##init_fn, drv_name, init_fn, control_fn, \ + DEVICE_DEFINE(_SYS_NAME(init_fn), drv_name, init_fn, control_fn, \ NULL, NULL, level, prio, NULL) #ifdef __cplusplus