Lines Matching full:pipe
7 #include <zephyr/modem/pipe.h>
14 static void pipe_set_callback(struct modem_pipe *pipe, in pipe_set_callback() argument
18 K_SPINLOCK(&pipe->spinlock) { in pipe_set_callback()
19 pipe->callback = callback; in pipe_set_callback()
20 pipe->user_data = user_data; in pipe_set_callback()
24 static void pipe_call_callback(struct modem_pipe *pipe, enum modem_pipe_event event) in pipe_call_callback() argument
26 K_SPINLOCK(&pipe->spinlock) { in pipe_call_callback()
27 if (pipe->callback != NULL) { in pipe_call_callback()
28 pipe->callback(pipe, event, pipe->user_data); in pipe_call_callback()
33 static uint32_t pipe_test_events(struct modem_pipe *pipe, uint32_t events) in pipe_test_events() argument
35 return k_event_test(&pipe->event, events); in pipe_test_events()
38 static uint32_t pipe_await_events(struct modem_pipe *pipe, in pipe_await_events() argument
42 return k_event_wait(&pipe->event, events, false, timeout); in pipe_await_events()
45 static void pipe_post_events(struct modem_pipe *pipe, uint32_t events) in pipe_post_events() argument
47 k_event_post(&pipe->event, events); in pipe_post_events()
50 static void pipe_clear_events(struct modem_pipe *pipe, uint32_t events) in pipe_clear_events() argument
52 k_event_clear(&pipe->event, events); in pipe_clear_events()
55 static void pipe_set_events(struct modem_pipe *pipe, uint32_t events) in pipe_set_events() argument
57 k_event_set(&pipe->event, events); in pipe_set_events()
60 static int pipe_call_open(struct modem_pipe *pipe) in pipe_call_open() argument
62 return pipe->api->open(pipe->data); in pipe_call_open()
65 static int pipe_call_transmit(struct modem_pipe *pipe, const uint8_t *buf, size_t size) in pipe_call_transmit() argument
67 return pipe->api->transmit(pipe->data, buf, size); in pipe_call_transmit()
70 static int pipe_call_receive(struct modem_pipe *pipe, uint8_t *buf, size_t size) in pipe_call_receive() argument
72 return pipe->api->receive(pipe->data, buf, size); in pipe_call_receive()
75 static int pipe_call_close(struct modem_pipe *pipe) in pipe_call_close() argument
77 return pipe->api->close(pipe->data); in pipe_call_close()
80 void modem_pipe_init(struct modem_pipe *pipe, void *data, const struct modem_pipe_api *api) in modem_pipe_init() argument
82 __ASSERT_NO_MSG(pipe != NULL); in modem_pipe_init()
86 pipe->data = data; in modem_pipe_init()
87 pipe->api = api; in modem_pipe_init()
88 pipe->callback = NULL; in modem_pipe_init()
89 pipe->user_data = NULL; in modem_pipe_init()
90 k_event_init(&pipe->event); in modem_pipe_init()
93 int modem_pipe_open(struct modem_pipe *pipe, k_timeout_t timeout) in modem_pipe_open() argument
97 if (pipe_test_events(pipe, PIPE_EVENT_OPENED_BIT)) { in modem_pipe_open()
101 ret = pipe_call_open(pipe); in modem_pipe_open()
106 if (!pipe_await_events(pipe, PIPE_EVENT_OPENED_BIT, timeout)) { in modem_pipe_open()
113 int modem_pipe_open_async(struct modem_pipe *pipe) in modem_pipe_open_async() argument
115 if (pipe_test_events(pipe, PIPE_EVENT_OPENED_BIT)) { in modem_pipe_open_async()
116 pipe_call_callback(pipe, MODEM_PIPE_EVENT_OPENED); in modem_pipe_open_async()
120 return pipe_call_open(pipe); in modem_pipe_open_async()
123 void modem_pipe_attach(struct modem_pipe *pipe, modem_pipe_api_callback callback, void *user_data) in modem_pipe_attach() argument
125 pipe_set_callback(pipe, callback, user_data); in modem_pipe_attach()
127 if (pipe_test_events(pipe, PIPE_EVENT_RECEIVE_READY_BIT)) { in modem_pipe_attach()
128 pipe_call_callback(pipe, MODEM_PIPE_EVENT_RECEIVE_READY); in modem_pipe_attach()
131 if (pipe_test_events(pipe, PIPE_EVENT_TRANSMIT_IDLE_BIT)) { in modem_pipe_attach()
132 pipe_call_callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE); in modem_pipe_attach()
136 int modem_pipe_transmit(struct modem_pipe *pipe, const uint8_t *buf, size_t size) in modem_pipe_transmit() argument
138 if (!pipe_test_events(pipe, PIPE_EVENT_OPENED_BIT)) { in modem_pipe_transmit()
142 pipe_clear_events(pipe, PIPE_EVENT_TRANSMIT_IDLE_BIT); in modem_pipe_transmit()
143 return pipe_call_transmit(pipe, buf, size); in modem_pipe_transmit()
146 int modem_pipe_receive(struct modem_pipe *pipe, uint8_t *buf, size_t size) in modem_pipe_receive() argument
148 if (!pipe_test_events(pipe, PIPE_EVENT_OPENED_BIT)) { in modem_pipe_receive()
152 pipe_clear_events(pipe, PIPE_EVENT_RECEIVE_READY_BIT); in modem_pipe_receive()
153 return pipe_call_receive(pipe, buf, size); in modem_pipe_receive()
156 void modem_pipe_release(struct modem_pipe *pipe) in modem_pipe_release() argument
158 pipe_set_callback(pipe, NULL, NULL); in modem_pipe_release()
161 int modem_pipe_close(struct modem_pipe *pipe, k_timeout_t timeout) in modem_pipe_close() argument
165 if (pipe_test_events(pipe, PIPE_EVENT_CLOSED_BIT)) { in modem_pipe_close()
169 ret = pipe_call_close(pipe); in modem_pipe_close()
174 if (!pipe_await_events(pipe, PIPE_EVENT_CLOSED_BIT, timeout)) { in modem_pipe_close()
181 int modem_pipe_close_async(struct modem_pipe *pipe) in modem_pipe_close_async() argument
183 if (pipe_test_events(pipe, PIPE_EVENT_CLOSED_BIT)) { in modem_pipe_close_async()
184 pipe_call_callback(pipe, MODEM_PIPE_EVENT_CLOSED); in modem_pipe_close_async()
188 return pipe_call_close(pipe); in modem_pipe_close_async()
191 void modem_pipe_notify_opened(struct modem_pipe *pipe) in modem_pipe_notify_opened() argument
193 pipe_set_events(pipe, PIPE_EVENT_OPENED_BIT | PIPE_EVENT_TRANSMIT_IDLE_BIT); in modem_pipe_notify_opened()
194 pipe_call_callback(pipe, MODEM_PIPE_EVENT_OPENED); in modem_pipe_notify_opened()
195 pipe_call_callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE); in modem_pipe_notify_opened()
198 void modem_pipe_notify_closed(struct modem_pipe *pipe) in modem_pipe_notify_closed() argument
200 pipe_set_events(pipe, PIPE_EVENT_TRANSMIT_IDLE_BIT | PIPE_EVENT_CLOSED_BIT); in modem_pipe_notify_closed()
201 pipe_call_callback(pipe, MODEM_PIPE_EVENT_CLOSED); in modem_pipe_notify_closed()
204 void modem_pipe_notify_receive_ready(struct modem_pipe *pipe) in modem_pipe_notify_receive_ready() argument
206 pipe_post_events(pipe, PIPE_EVENT_RECEIVE_READY_BIT); in modem_pipe_notify_receive_ready()
207 pipe_call_callback(pipe, MODEM_PIPE_EVENT_RECEIVE_READY); in modem_pipe_notify_receive_ready()
210 void modem_pipe_notify_transmit_idle(struct modem_pipe *pipe) in modem_pipe_notify_transmit_idle() argument
212 pipe_post_events(pipe, PIPE_EVENT_TRANSMIT_IDLE_BIT); in modem_pipe_notify_transmit_idle()
213 pipe_call_callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE); in modem_pipe_notify_transmit_idle()