device: move device APIs from init.h to device.h
Change-Id: I7f0d489be95242fe9899a1bfc0f3565839b5ffca Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
This commit is contained in:
parent
a740cd96a9
commit
f2f719a523
2 changed files with 81 additions and 82 deletions
|
@ -22,6 +22,56 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
/** @def DEVICE_INIT_CONFIG_DEFINE
|
||||||
*
|
*
|
||||||
* @brief Define an config object
|
* @brief Define an config object
|
||||||
|
@ -49,6 +99,37 @@ extern "C" {
|
||||||
.config_info = (config) \
|
.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 */
|
/* Common Error Codes devices can provide */
|
||||||
#define DEV_OK 0 /* No error */
|
#define DEV_OK 0 /* No error */
|
||||||
#define DEV_FAIL 1 /* General operation failure */
|
#define DEV_FAIL 1 /* General operation failure */
|
||||||
|
|
|
@ -38,88 +38,6 @@ extern "C" {
|
||||||
#define _SYS_INIT_LEVEL_MICROKERNEL 3
|
#define _SYS_INIT_LEVEL_MICROKERNEL 3
|
||||||
#define _SYS_INIT_LEVEL_APPLICATION 4
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue