Line data Source code
1 0 : /*
2 : * Copyright (c) 2024 Trackunit Corporation
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #include <zephyr/modem/pipe.h>
8 : #include <zephyr/devicetree.h>
9 : #include <zephyr/sys/util.h>
10 :
11 : #ifndef ZEPHYR_MODEM_PIPELINK_
12 : #define ZEPHYR_MODEM_PIPELINK_
13 :
14 : #ifdef __cplusplus
15 : extern "C" {
16 : #endif
17 :
18 : /**
19 : * @brief Modem pipelink
20 : * @defgroup modem_pipelink Modem pipelink
21 : * @since 3.7
22 : * @version 1.0.0
23 : * @ingroup modem
24 : * @{
25 : */
26 :
27 : /** Pipelink event */
28 1 : enum modem_pipelink_event {
29 : /** Modem pipe has been connected and can be opened */
30 : MODEM_PIPELINK_EVENT_CONNECTED = 0,
31 : /** Modem pipe has been disconnected and can't be opened */
32 : MODEM_PIPELINK_EVENT_DISCONNECTED,
33 : };
34 :
35 : /** @cond INTERNAL_HIDDEN */
36 :
37 : /** Forward declaration */
38 : struct modem_pipelink;
39 :
40 : /** @endcond */
41 :
42 : /**
43 : * @brief Pipelink callback definition
44 : * @param link Modem pipelink instance
45 : * @param event Modem pipelink event
46 : * @param user_data User data passed to modem_pipelink_attach()
47 : */
48 1 : typedef void (*modem_pipelink_callback)(struct modem_pipelink *link,
49 : enum modem_pipelink_event event,
50 : void *user_data);
51 :
52 : /** @cond INTERNAL_HIDDEN */
53 :
54 : /** Pipelink structure */
55 : struct modem_pipelink {
56 : struct modem_pipe *pipe;
57 : modem_pipelink_callback callback;
58 : void *user_data;
59 : bool connected;
60 : struct k_spinlock spinlock;
61 : };
62 :
63 : /** @endcond */
64 :
65 : /**
66 : * @brief Attach callback to pipelink
67 : * @param link Pipelink instance
68 : * @param callback Pipelink callback
69 : * @param user_data User data passed to pipelink callback
70 : */
71 1 : void modem_pipelink_attach(struct modem_pipelink *link,
72 : modem_pipelink_callback callback,
73 : void *user_data);
74 :
75 : /**
76 : * @brief Check whether pipelink pipe is connected
77 : * @param link Pipelink instance
78 : * @retval true if pipe is connected
79 : * @retval false if pipe is not connected
80 : */
81 1 : bool modem_pipelink_is_connected(struct modem_pipelink *link);
82 :
83 : /**
84 : * @brief Get pipe from pipelink
85 : * @param link Pipelink instance
86 : * @retval Pointer to pipe if pipelink has been initialized
87 : * @retval NULL if pipelink has not been initialized
88 : */
89 1 : struct modem_pipe *modem_pipelink_get_pipe(struct modem_pipelink *link);
90 :
91 : /**
92 : * @brief Clear callback
93 : * @param link Pipelink instance
94 : */
95 1 : void modem_pipelink_release(struct modem_pipelink *link);
96 :
97 : /** @cond INTERNAL_HIDDEN */
98 :
99 : /** Initialize modem pipelink */
100 : void modem_pipelink_init(struct modem_pipelink *link, struct modem_pipe *pipe);
101 :
102 : /** Notify user of pipelink that pipe has been connected */
103 : void modem_pipelink_notify_connected(struct modem_pipelink *link);
104 :
105 : /** Notify user of pipelink that pipe has been disconnected */
106 : void modem_pipelink_notify_disconnected(struct modem_pipelink *link);
107 :
108 : /** @endcond */
109 :
110 : /** @cond INTERNAL_HIDDEN */
111 :
112 : /**
113 : * @brief Synthesize pipelink symbol from devicetree node identifier and name
114 : * @param node_id Devicetree node identifier
115 : * @param name Pipelink name
116 : */
117 : #define MODEM_PIPELINK_DT_SYM(node_id, name) \
118 : _CONCAT_4(__modem_pipelink_, DT_DEP_ORD(node_id), _, name)
119 :
120 : /** @endcond */
121 :
122 : /**
123 : * @brief Declare pipelink from devicetree node identifier and name
124 : * @param node_id Devicetree node identifier
125 : * @param name Pipelink name
126 : */
127 1 : #define MODEM_PIPELINK_DT_DECLARE(node_id, name) \
128 : extern struct modem_pipelink MODEM_PIPELINK_DT_SYM(node_id, name)
129 :
130 : /**
131 : * @brief Define pipelink from devicetree node identifier and name
132 : * @param node_id Devicetree node identifier
133 : * @param name Pipelink name
134 : */
135 1 : #define MODEM_PIPELINK_DT_DEFINE(node_id, name) \
136 : struct modem_pipelink MODEM_PIPELINK_DT_SYM(node_id, name)
137 :
138 : /**
139 : * @brief Get pointer to pipelink from devicetree node identifier and name
140 : * @param node_id Devicetree node identifier
141 : * @param name Pipelink name
142 : */
143 1 : #define MODEM_PIPELINK_DT_GET(node_id, name) \
144 : (&MODEM_PIPELINK_DT_SYM(node_id, name))
145 :
146 : /**
147 : * @brief Device driver instance variants of MODEM_PIPELINK_DT macros
148 : * @name MODEM_PIPELINK_DT_INST macros
149 : * @anchor MODEM_PIPELINK_DT_INST
150 : * @{
151 : */
152 :
153 0 : #define MODEM_PIPELINK_DT_INST_DECLARE(inst, name) \
154 : MODEM_PIPELINK_DT_DECLARE(DT_DRV_INST(inst), name)
155 :
156 0 : #define MODEM_PIPELINK_DT_INST_DEFINE(inst, name) \
157 : MODEM_PIPELINK_DT_DEFINE(DT_DRV_INST(inst), name)
158 :
159 0 : #define MODEM_PIPELINK_DT_INST_GET(inst, name) \
160 : MODEM_PIPELINK_DT_GET(DT_DRV_INST(inst), name)
161 :
162 : /** @} */
163 :
164 : /** @} */
165 :
166 : #ifdef __cplusplus
167 : }
168 : #endif
169 :
170 : #endif /* ZEPHYR_MODEM_PIPELINK_ */
|