Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Shared device APIs

Shared device API . More...

Data Structures

struct  shared_device_dt_spec
 Container for shared device information specified in devicetree. More...
 
struct  shared_device_api
 

Macros

#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)
 Static initializer for a shared_device_dt_spec.
 
#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value)
 Like SHARED_DEVICE_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.
 
#define SHARED_DEVICE_DT_SPEC_GET(node_id, prop)
 Equivalent to SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, 0).
 
#define SHARED_DEVICE_DT_SPEC_GET_OR(node_id, prop, default_value)
 Equivalent to SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value).
 
#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx)
 Static initializer for a shared_device_dt_spec from a DT_DRV_COMPAT instance's shared device property at an index.
 
#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value)
 Static initializer for a shared_device_dt_spec from a DT_DRV_COMPAT instance's shared device property at an index, with fallback.
 
#define SHARED_DEVICE_DT_SPEC_INST_GET(inst, prop)
 Equivalent to SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0).
 
#define SHARED_DEVICE_DT_SPEC_INST_GET_OR(inst, prop, default_value)
 Equivalent to SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value).
 

Functions

static bool shared_device_is_ready_dt (const struct shared_device_dt_spec *spec)
 Validate that the shared device is ready.
 
static int shared_device_request (const struct device *dev, uint8_t state_priority, uint8_t state)
 Request a device to be in a given state.
 
static int shared_device_request_dt (const struct shared_device_dt_spec *spec)
 Request a shared device from a shared_device_dt_spec.
 
static int shared_device_release (const struct device *dev, uint8_t state_priority)
 Release a previous request for a given state.
 
static int shared_device_release_dt (const struct shared_device_dt_spec *spec)
 Release a shared device from a shared_device_dt_spec.
 

Detailed Description

Shared device API .

Macro Definition Documentation

◆ SHARED_DEVICE_DT_SPEC_GET

#define SHARED_DEVICE_DT_SPEC_GET ( node_id,
prop )

#include <infuse/shared/device.h>

Value:
#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)
Static initializer for a shared_device_dt_spec.
Definition device.h:78

Equivalent to SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, 0).

Parameters
node_iddevicetree node identifier
proplowercase-and-underscores property name
Returns
static initializer for a struct shared_device_dt_spec for the property
See also
SHARED_DEVICE_DT_SPEC_GET_BY_IDX()

◆ SHARED_DEVICE_DT_SPEC_GET_BY_IDX

#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX ( node_id,
prop,
idx )

#include <infuse/shared/device.h>

Value:
{ \
.shared = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \
.state = DT_PHA_BY_IDX(node_id, prop, idx, state), \
.priority = DT_PHA_BY_IDX(node_id, prop, idx, priority), \
}

Static initializer for a shared_device_dt_spec.

  • Example devicetree fragment:

    n: node { rf-switch = <&ant_switch 0 100>, <&ant_switch 1 50>; }

Example usage:

 const struct shared_device_dt_spec spec = GPIO_DT_SPEC_GET_BY_IDX(DT_NODELABEL(n),
                                                              rf-switch, 1);
 // Initializes 'spec' to:
 // {
 //         .shared = DEVICE_DT_GET(DT_NODELABEL(ant_switch)),
 //         .state = 1,
 //         .priority = 50
 // }

The 'shared' field must still be checked for readiness, e.g. using device_is_ready(). It is an error to use this macro unless the node exists, has the given property, and that property specifies a shared device, requested state, and state priority as shown above.

Parameters
node_iddevicetree node identifier
proplowercase-and-underscores property name
idxlogical index into "prop"
Returns
static initializer for a struct shared_device_dt_spec for the property

◆ SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR

#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR ( node_id,
prop,
idx,
default_value )

#include <infuse/shared/device.h>

Value:
COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
(SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), (default_value))

Like SHARED_DEVICE_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.

If the devicetree node identifier 'node_id' refers to a node with a property 'prop', this expands to SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx). The default_value parameter is not expanded in this case.

Otherwise, this expands to default_value.

Parameters
node_iddevicetree node identifier
proplowercase-and-underscores property name
idxlogical index into "prop"
default_valuefallback value to expand to
Returns
static initializer for a struct shared_device_dt_spec for the property, or default_value if the node or property do not exist

◆ SHARED_DEVICE_DT_SPEC_GET_OR

#define SHARED_DEVICE_DT_SPEC_GET_OR ( node_id,
prop,
default_value )

#include <infuse/shared/device.h>

Value:
SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value)
Like SHARED_DEVICE_DT_SPEC_GET_BY_IDX(), with a fallback to a default value.
Definition device.h:102

Equivalent to SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value).

Parameters
node_iddevicetree node identifier
proplowercase-and-underscores property name
default_valuefallback value to expand to
Returns
static initializer for a struct shared_device_dt_spec for the property
See also
SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR()

◆ SHARED_DEVICE_DT_SPEC_INST_GET

#define SHARED_DEVICE_DT_SPEC_INST_GET ( inst,
prop )

#include <infuse/shared/device.h>

Value:
#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx)
Static initializer for a shared_device_dt_spec from a DT_DRV_COMPAT instance's shared device property...
Definition device.h:139

Equivalent to SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0).

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
Returns
static initializer for a struct shared_device_dt_spec for the property
See also
SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX()

◆ SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX

#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX ( inst,
prop,
idx )

#include <infuse/shared/device.h>

Value:
SHARED_DEVICE_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)

Static initializer for a shared_device_dt_spec from a DT_DRV_COMPAT instance's shared device property at an index.

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
idxlogical index into "prop"
Returns
static initializer for a struct shared_device_dt_spec for the property
See also
SHARED_DEVICE_DT_SPEC_GET_BY_IDX()

◆ SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR

#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR ( inst,
prop,
idx,
default_value )

#include <infuse/shared/device.h>

Value:
SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)

Static initializer for a shared_device_dt_spec from a DT_DRV_COMPAT instance's shared device property at an index, with fallback.

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
idxlogical index into "prop"
default_valuefallback value to expand to
Returns
static initializer for a struct shared_device_dt_spec for the property
See also
SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR()

◆ SHARED_DEVICE_DT_SPEC_INST_GET_OR

#define SHARED_DEVICE_DT_SPEC_INST_GET_OR ( inst,
prop,
default_value )

#include <infuse/shared/device.h>

Value:
SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value)
Static initializer for a shared_device_dt_spec from a DT_DRV_COMPAT instance's shared device property...
Definition device.h:153

Equivalent to SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value).

Parameters
instDT_DRV_COMPAT instance number
proplowercase-and-underscores property name
default_valuefallback value to expand to
Returns
static initializer for a struct shared_device_dt_spec for the property
See also
SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR()

Function Documentation

◆ shared_device_is_ready_dt()

static bool shared_device_is_ready_dt ( const struct shared_device_dt_spec * spec)
inlinestatic

#include <infuse/shared/device.h>

Validate that the shared device is ready.

Parameters
specShared device specification from devicetree
Return values
trueif the shared device is ready for use.
falseif the shared device is not ready for use.

◆ shared_device_release()

static int shared_device_release ( const struct device * dev,
uint8_t state_priority )
inlinestatic

#include <infuse/shared/device.h>

Release a previous request for a given state.

Parameters
devSwitch to release
state_priorityPriority of the request provided to shared_device_request
Return values
0request has been released
-EINVALno request was previously received

◆ shared_device_release_dt()

static int shared_device_release_dt ( const struct shared_device_dt_spec * spec)
inlinestatic

#include <infuse/shared/device.h>

Release a shared device from a shared_device_dt_spec.

This is equivalent to:

shared_device_release(spec->shared, spec->priority);
Parameters
specShared device specification from devicetree
Returns
a value from shared_device_release()

◆ shared_device_request()

static int shared_device_request ( const struct device * dev,
uint8_t state_priority,
uint8_t state )
inlinestatic

#include <infuse/shared/device.h>

Request a device to be in a given state.

The state with the highest requested priority is the one active. The behaviour when no state is selected is implementation-defined.

Parameters
devShared device to request to be in a certain state
state_priorityPriority of the request, each state must have a single associated priority
stateState that is being requested for a device
Return values
0request has been submitted
-EALREADYa request for the given state already exists
-EINVALstate is invalid for this device

◆ shared_device_request_dt()

static int shared_device_request_dt ( const struct shared_device_dt_spec * spec)
inlinestatic

#include <infuse/shared/device.h>

Request a shared device from a shared_device_dt_spec.

This is equivalent to:

shared_device_request(spec->shared, spec->priority, spec->state);
Parameters
specShared device specification from devicetree
Returns
a value from shared_device_request()