Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1
8
9#ifndef INFUSE_SDK_INCLUDE_INFUSE_SHARED_DEVICE_H_
10#define INFUSE_SDK_INCLUDE_INFUSE_SHARED_DEVICE_H_
11
12#include <stdint.h>
13#include <stdbool.h>
14
15#include <zephyr/device.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
27
41 const struct device *shared;
43 uint8_t state;
45 uint8_t priority;
46};
47
79#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx) \
80 { \
81 .shared = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \
82 .state = DT_PHA_BY_IDX(node_id, prop, idx, state), \
83 .priority = DT_PHA_BY_IDX(node_id, prop, idx, priority), \
84 }
85
103#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
104 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
105 (SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), (default_value))
106
115#define SHARED_DEVICE_DT_SPEC_GET(node_id, prop) SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
116
127#define SHARED_DEVICE_DT_SPEC_GET_OR(node_id, prop, default_value) \
128 SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
129
140#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) \
141 SHARED_DEVICE_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
142
154#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value) \
155 SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)
156
165#define SHARED_DEVICE_DT_SPEC_INST_GET(inst, prop) \
166 SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
167
178#define SHARED_DEVICE_DT_SPEC_INST_GET_OR(inst, prop, default_value) \
179 SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
180
184 int (*request)(const struct device *dev, uint8_t state_priority, uint8_t state);
186 int (*release)(const struct device *dev, uint8_t state_priority);
187};
188
197static inline bool shared_device_is_ready_dt(const struct shared_device_dt_spec *spec)
198{
199 if (spec->shared == NULL) {
200 return true;
201 }
202 return device_is_ready(spec->shared);
203}
204
219static inline int shared_device_request(const struct device *dev, uint8_t state_priority,
220 uint8_t state)
221{
222 const struct shared_device_api *api = dev->api;
223
224 return api->request(dev, state_priority, state);
225}
226
238static inline int shared_device_request_dt(const struct shared_device_dt_spec *spec)
239{
240 if (spec->shared == NULL) {
241 return 0;
242 }
243 return shared_device_request(spec->shared, spec->priority, spec->state);
244}
245
255static inline int shared_device_release(const struct device *dev, uint8_t state_priority)
256{
257 const struct shared_device_api *api = dev->api;
258
259 return api->release(dev, state_priority);
260}
261
273static inline int shared_device_release_dt(const struct shared_device_dt_spec *spec)
274{
275 if (spec->shared == NULL) {
276 return 0;
277 }
278 return shared_device_release(spec->shared, spec->priority);
279}
280
284
285#ifdef __cplusplus
286}
287#endif
288
289#endif /* INFUSE_SDK_INCLUDE_INFUSE_SHARED_DEVICE_H_ */
static bool shared_device_is_ready_dt(const struct shared_device_dt_spec *spec)
Validate that the shared device is ready.
Definition device.h:197
static int shared_device_release_dt(const struct shared_device_dt_spec *spec)
Release a shared device from a shared_device_dt_spec.
Definition device.h:273
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.
Definition device.h:219
static int shared_device_request_dt(const struct shared_device_dt_spec *spec)
Request a shared device from a shared_device_dt_spec.
Definition device.h:238
static int shared_device_release(const struct device *dev, uint8_t state_priority)
Release a previous request for a given state.
Definition device.h:255
Shared device driver API.
Definition device.h:182
int(* release)(const struct device *dev, uint8_t state_priority)
Implementation of shared_device_release.
Definition device.h:186
int(* request)(const struct device *dev, uint8_t state_priority, uint8_t state)
Implementation of shared_device_request.
Definition device.h:184
Container for shared device information specified in devicetree.
Definition device.h:39
const struct device * shared
Pointer to the shared device.
Definition device.h:41
uint8_t priority
Priority of the state request.
Definition device.h:45
uint8_t state
State that is being requested.
Definition device.h:43