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
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
39 /* Pointer to the shared device */
40 const struct device *shared;
41 /* State that is being requested */
42 uint8_t state;
43 /* Priority of the state request */
44 uint8_t priority;
45};
46
78#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx) \
79 { \
80 .shared = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \
81 .state = DT_PHA_BY_IDX(node_id, prop, idx, state), \
82 .priority = DT_PHA_BY_IDX(node_id, prop, idx, priority), \
83 }
84
102#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
103 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
104 (SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), (default_value))
105
114#define SHARED_DEVICE_DT_SPEC_GET(node_id, prop) SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
115
126#define SHARED_DEVICE_DT_SPEC_GET_OR(node_id, prop, default_value) \
127 SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
128
139#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) \
140 SHARED_DEVICE_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
141
153#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value) \
154 SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)
155
164#define SHARED_DEVICE_DT_SPEC_INST_GET(inst, prop) \
165 SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
166
177#define SHARED_DEVICE_DT_SPEC_INST_GET_OR(inst, prop, default_value) \
178 SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
179
181 int (*request)(const struct device *dev, uint8_t state_priority, uint8_t state);
182 int (*release)(const struct device *dev, uint8_t state_priority);
183};
184
193static inline bool shared_device_is_ready_dt(const struct shared_device_dt_spec *spec)
194{
195 if (spec->shared == NULL) {
196 return true;
197 }
198 return device_is_ready(spec->shared);
199}
200
215static inline int shared_device_request(const struct device *dev, uint8_t state_priority,
216 uint8_t state)
217{
218 const struct shared_device_api *api = dev->api;
219
220 return api->request(dev, state_priority, state);
221}
222
234static inline int shared_device_request_dt(const struct shared_device_dt_spec *spec)
235{
236 if (spec->shared == NULL) {
237 return 0;
238 }
239 return shared_device_request(spec->shared, spec->priority, spec->state);
240}
241
251static inline int shared_device_release(const struct device *dev, uint8_t state_priority)
252{
253 const struct shared_device_api *api = dev->api;
254
255 return api->release(dev, state_priority);
256}
257
269static inline int shared_device_release_dt(const struct shared_device_dt_spec *spec)
270{
271 if (spec->shared == NULL) {
272 return 0;
273 }
274 return shared_device_release(spec->shared, spec->priority);
275}
276
281#ifdef __cplusplus
282}
283#endif
284
285#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:193
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:269
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:215
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:234
static int shared_device_release(const struct device *dev, uint8_t state_priority)
Release a previous request for a given state.
Definition device.h:251
Definition device.h:180
int(* release)(const struct device *dev, uint8_t state_priority)
Definition device.h:182
int(* request)(const struct device *dev, uint8_t state_priority, uint8_t state)
Definition device.h:181
Container for shared device information specified in devicetree.
Definition device.h:38
const struct device * shared
Definition device.h:40
uint8_t priority
Definition device.h:44
uint8_t state
Definition device.h:42