device: add DEVICE_DECLARE()
If an init or config function needs to configure a static interrupt or otherwise do something that requires a build time reference to a device with DEVICE_GET(), there is a dependency issue that so far is usually resolved with a forward prototype of the init function. In addition, there currently isn't a good way to declare a device in a header so that DEVICE_GET() can be used in a different C file. This patch should resolve both of these problems; the data structure defined for the device is no longer static (the names have to be unique anyway), and in cases where we need a forward declaration so that DEVICE_GET() can be used, we have a new DEVICE_DECLARE() macro which does this. Change-Id: Ie8d53d0c344f61a130c735c86473562820190d70 Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
42a8032fd9
commit
14308a9621
1 changed files with 17 additions and 0 deletions
|
@ -119,6 +119,23 @@ extern "C" {
|
|||
*/
|
||||
#define DEVICE_GET(name) (&DEVICE_NAME_GET(name))
|
||||
|
||||
/** @def DEVICE_DECLARE
|
||||
*
|
||||
* @brief Declare a device object
|
||||
*
|
||||
* This macro can be used at the top-level to declare a device, such
|
||||
* that DEVICE_GET() may be used before the full declaration in
|
||||
* DEVICE_INIT(), or reference the device in another C file.
|
||||
*
|
||||
* This is often useful when configuring interrupts statically in a
|
||||
* device's init or per-instance config function, as the init function
|
||||
* itself is required by DEVICE_INIT() and use of DEVICE_GET()
|
||||
* inside it creates a circular dependeny.
|
||||
*
|
||||
* @param name Device name
|
||||
*/
|
||||
#define DEVICE_DECLARE(name) extern struct device DEVICE_NAME_GET(name)
|
||||
|
||||
/* Common Error Codes devices can provide */
|
||||
#define DEV_OK 0 /* No error */
|
||||
#define DEV_FAIL 1 /* General operation failure */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue