From f2f719a5231f2c6250f8dc6b549d5e928320d51c Mon Sep 17 00:00:00 2001 From: Benjamin Walsh Date: Wed, 27 Jan 2016 14:40:06 -0500 Subject: [PATCH] device: move device APIs from init.h to device.h Change-Id: I7f0d489be95242fe9899a1bfc0f3565839b5ffca Signed-off-by: Benjamin Walsh --- include/device.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++ include/init.h | 82 ------------------------------------------------ 2 files changed, 81 insertions(+), 82 deletions(-) diff --git a/include/device.h b/include/device.h index 8ab8ac8f9a9..573e58465b0 100644 --- a/include/device.h +++ b/include/device.h @@ -22,6 +22,56 @@ extern "C" { #endif +/** @def DEVICE_DEFINE + * + * @brief Define device object + * + * @details This macro defines a device object that is automatically + * configured by the kernel during system initialization. + * + * @param name Device name. + * + * @param data Pointer to the device's configuration data. + * @sa DEVICE_INIT_CONFIG_DEFINE() + * + * @param level The initialization level at which configuration occurs. + * Must be one of the following symbols, which are listed in the order + * they are performed by the kernel: + * + * PRIMARY: Used for devices that have no dependencies, such as those + * that rely solely on hardware present in the processor/SOC. These devices + * cannot use any kernel services during configuration, since they are not + * yet available. + * + * SECONDARY: Used for devices that rely on the initialization of devices + * initialized as part of the PRIMARY level. These devices cannot use any + * kernel services during configuration, since they are not yet available. + * + * NANOKERNEL: Used for devices that require nanokernel services during + * configuration. + * + * MICROKERNEL: Used for devices that require microkernel services during + * configuration. + * + * APPLICATION: Used for application components (i.e. non-kernel components) + * that need automatic configuration. These devices can use all services + * provided by the kernel during configuration. + * + * @param priority The initialization priority of the device, relative to + * other devices of the same initialization level. Specified as an integer + * value in the range 0 to 99; lower values indicate earlier initialization. + * Must be a decimal integer literal without leading zeroes or sign (e.g. 32), + * or an equivalent symbolic name (e.g. #define MY_INIT_PRIO 32); symbolic + * expressions are *not* permitted + * (e.g. CONFIG_KERNEL_INIT_PRIORITY_DEFAULT + 5). + */ + +#define DEVICE_DEFINE(name, data, level, priority) \ + static struct device (__initconfig_##name) __used \ + __attribute__((__section__(".init_" #level STRINGIFY(priority)))) = { \ + .config = &(config_##name),\ + .driver_data = data} + /** @def DEVICE_INIT_CONFIG_DEFINE * * @brief Define an config object @@ -49,6 +99,37 @@ extern "C" { .config_info = (config) \ } +/** + * @def DEVICE_NAME_GET + * + * @brief Expands to the full name of a global device object + * + * @details Return the full name of a device object symbol created by + * DEVICE_DEFINE(), using the @name provided to DEVICE_DEFINE(). + * + * It is meant to be used for declaring extern symbols pointing on device + * objects before using the DEVICE_GET macro to get the device object. + * + * @param name The same name provided to DEVICE_DEFINE() + * + * @return The exanded name of the device object created by DEVICE_DEFINE() + */ +#define DEVICE_NAME_GET(name) (_CONCAT(__initconfig_, name)) + +/** + * @def DEVICE_GET + * + * @brief Obtain a pointer to a device object by name + * + * @details Return the address of a device object created by + * DEVICE_DEFINE(), using the @name provided to DEVICE_DEFINE(). + * + * @param name The same name provided to DEVICE_DEFINE() + * + * @return A pointer to the device object created by DEVICE_DEFINE() + */ +#define DEVICE_GET(name) (&DEVICE_NAME_GET(name)) + /* Common Error Codes devices can provide */ #define DEV_OK 0 /* No error */ #define DEV_FAIL 1 /* General operation failure */ diff --git a/include/init.h b/include/init.h index 44785f9a0b1..c65c8030ab6 100644 --- a/include/init.h +++ b/include/init.h @@ -38,88 +38,6 @@ extern "C" { #define _SYS_INIT_LEVEL_MICROKERNEL 3 #define _SYS_INIT_LEVEL_APPLICATION 4 - -/** @def DEVICE_DEFINE - * - * @brief Define device object - * - * @details This macro defines a device object that is automatically - * configured by the kernel during system initialization. - * - * @param name Device name. - * - * @param data Pointer to the device's configuration data. - * @sa DEVICE_INIT_CONFIG_DEFINE() - * - * @param level The initialization level at which configuration occurs. - * Must be one of the following symbols, which are listed in the order - * they are performed by the kernel: - * - * PRIMARY: Used for devices that have no dependencies, such as those - * that rely solely on hardware present in the processor/SOC. These devices - * cannot use any kernel services during configuration, since they are not - * yet available. - * - * SECONDARY: Used for devices that rely on the initialization of devices - * initialized as part of the PRIMARY level. These devices cannot use any - * kernel services during configuration, since they are not yet available. - * - * NANOKERNEL: Used for devices that require nanokernel services during - * configuration. - * - * MICROKERNEL: Used for devices that require microkernel services during - * configuration. - * - * APPLICATION: Used for application components (i.e. non-kernel components) - * that need automatic configuration. These devices can use all services - * provided by the kernel during configuration. - * - * @param priority The initialization priority of the device, relative to - * other devices of the same initialization level. Specified as an integer - * value in the range 0 to 99; lower values indicate earlier initialization. - * Must be a decimal integer literal without leading zeroes or sign (e.g. 32), - * or an equivalent symbolic name (e.g. #define MY_INIT_PRIO 32); symbolic - * expressions are *not* permitted - * (e.g. CONFIG_KERNEL_INIT_PRIORITY_DEFAULT + 5). - */ - -#define DEVICE_DEFINE(name, data, level, priority) \ - static struct device (__initconfig_##name) __used \ - __attribute__((__section__(".init_" #level STRINGIFY(priority)))) = { \ - .config = &(config_##name),\ - .driver_data = data} - -/** - * @def DEVICE_NAME_GET - * - * @brief Expands to the full name of a global device object - * - * @details Return the full name of a device object symbol created by - * DEVICE_DEFINE(), using the @name provided to DEVICE_DEFINE(). - * - * It is meant to be used for declaring extern symbols pointing on device - * objects before using the DEVICE_GET macro to get the device object. - * - * @param name The same name provided to DEVICE_DEFINE() - * - * @return The exanded name of the device object created by DEVICE_DEFINE() - */ -#define DEVICE_NAME_GET(name) (_CONCAT(__initconfig_, name)) - -/** - * @def DEVICE_GET - * - * @brief Obtain a pointer to a device object by name - * - * @details Return the address of a device object created by - * DEVICE_DEFINE(), using the @name provided to DEVICE_DEFINE(). - * - * @param name The same name provided to DEVICE_DEFINE() - * - * @return A pointer to the device object created by DEVICE_DEFINE() - */ -#define DEVICE_GET(name) (&DEVICE_NAME_GET(name)) - #ifdef __cplusplus } #endif