Skip to content

Commit 516af3c

Browse files
bjarki-andreasenfabiobaltieri
authored andcommitted
modem: pipe: Add TRANSMIT_IDLE event
Add transmit idle event to modem_pipe_event enum. This will allow modules to await transmit idle before trying to transmit more data, instead of blindly calling modem_pipe_transmit in a loop until all data has been accepted. This will reduce the time spent trying to transmit data while the backend is blocked. Similarly to the RECEIVE_READY event, backends will call modem_pipe_notify_transmit_idle() to indicate that transmit is idle, and the TRANSMIT_IDLE event will be reinvoked when the modem pipe is attached to synchronize the state of the pipe with the user of it. Additionally, the TRANSMIT_IDLE event is also invoked when the modem is opened to further help synchronization with the user of the pipe. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 0f95b6f commit 516af3c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

include/zephyr/modem/pipe.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
enum modem_pipe_event {
2626
MODEM_PIPE_EVENT_OPENED = 0,
2727
MODEM_PIPE_EVENT_RECEIVE_READY,
28+
MODEM_PIPE_EVENT_TRANSMIT_IDLE,
2829
MODEM_PIPE_EVENT_CLOSED,
2930
};
3031

@@ -73,7 +74,8 @@ struct modem_pipe {
7374
enum modem_pipe_state state;
7475
struct k_mutex lock;
7576
struct k_condvar condvar;
76-
bool receive_ready_pending;
77+
uint8_t receive_ready_pending : 1;
78+
uint8_t transmit_idle_pending : 1;
7779
};
7880

7981
/**
@@ -213,6 +215,15 @@ void modem_pipe_notify_closed(struct modem_pipe *pipe);
213215
*/
214216
void modem_pipe_notify_receive_ready(struct modem_pipe *pipe);
215217

218+
/**
219+
* @brief Notify user of pipe that pipe has no more data to transmit
220+
*
221+
* @param pipe Pipe instance
222+
*
223+
* @note Invoked from instance which initialized the pipe instance
224+
*/
225+
void modem_pipe_notify_transmit_idle(struct modem_pipe *pipe);
226+
216227
/**
217228
* @endcond
218229
*/

subsys/modem/modem_pipe.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void modem_pipe_init(struct modem_pipe *pipe, void *data, struct modem_pipe_api
2121
pipe->user_data = NULL;
2222
pipe->state = MODEM_PIPE_STATE_CLOSED;
2323
pipe->receive_ready_pending = false;
24+
pipe->transmit_idle_pending = true;
2425

2526
k_mutex_init(&pipe->lock);
2627
k_condvar_init(&pipe->condvar);
@@ -82,6 +83,10 @@ void modem_pipe_attach(struct modem_pipe *pipe, modem_pipe_api_callback callback
8283
pipe->callback(pipe, MODEM_PIPE_EVENT_RECEIVE_READY, pipe->user_data);
8384
}
8485

86+
if (pipe->transmit_idle_pending && (pipe->callback != NULL)) {
87+
pipe->callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE, pipe->user_data);
88+
}
89+
8590
k_mutex_unlock(&pipe->lock);
8691
}
8792

@@ -97,6 +102,7 @@ int modem_pipe_transmit(struct modem_pipe *pipe, const uint8_t *buf, size_t size
97102
}
98103

99104
ret = pipe->api->transmit(pipe->data, buf, size);
105+
pipe->transmit_idle_pending = false;
100106
k_mutex_unlock(&pipe->lock);
101107
return ret;
102108
}
@@ -179,6 +185,7 @@ void modem_pipe_notify_opened(struct modem_pipe *pipe)
179185

180186
if (pipe->callback != NULL) {
181187
pipe->callback(pipe, MODEM_PIPE_EVENT_OPENED, pipe->user_data);
188+
pipe->callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE, pipe->user_data);
182189
}
183190

184191
k_condvar_signal(&pipe->condvar);
@@ -190,6 +197,7 @@ void modem_pipe_notify_closed(struct modem_pipe *pipe)
190197
k_mutex_lock(&pipe->lock, K_FOREVER);
191198
pipe->state = MODEM_PIPE_STATE_CLOSED;
192199
pipe->receive_ready_pending = false;
200+
pipe->transmit_idle_pending = true;
193201

194202
if (pipe->callback != NULL) {
195203
pipe->callback(pipe, MODEM_PIPE_EVENT_CLOSED, pipe->user_data);
@@ -211,3 +219,16 @@ void modem_pipe_notify_receive_ready(struct modem_pipe *pipe)
211219

212220
k_mutex_unlock(&pipe->lock);
213221
}
222+
223+
void modem_pipe_notify_transmit_idle(struct modem_pipe *pipe)
224+
{
225+
k_mutex_lock(&pipe->lock, K_FOREVER);
226+
227+
pipe->transmit_idle_pending = true;
228+
229+
if (pipe->callback != NULL) {
230+
pipe->callback(pipe, MODEM_PIPE_EVENT_TRANSMIT_IDLE, pipe->user_data);
231+
}
232+
233+
k_mutex_unlock(&pipe->lock);
234+
}

0 commit comments

Comments
 (0)