Skip to content

Commit 7fe491c

Browse files
Bjarki Arge Andreasenfabiobaltieri
authored andcommitted
modem: modem_cmux: Make async connect/disconnect stateful
This commit adds a check to the async connect and disconnect functions to validate the CMUX is not already connected or disconnected respectively. This was already part of the sync connect and disconnect functions, so the sync functions now simply wrap the async functions to avoid duplicate code. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 7ea95b0 commit 7fe491c

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

subsys/modem/modem_cmux.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -941,14 +941,11 @@ int modem_cmux_attach(struct modem_cmux *cmux, struct modem_pipe *pipe)
941941

942942
int modem_cmux_connect(struct modem_cmux *cmux)
943943
{
944-
__ASSERT_NO_MSG(cmux->pipe != NULL);
945-
946-
if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT, false, K_NO_WAIT)) {
947-
return -EALREADY;
948-
}
944+
int ret;
949945

950-
if (k_work_delayable_is_pending(&cmux->connect_work) == false) {
951-
k_work_schedule(&cmux->connect_work, K_NO_WAIT);
946+
ret = modem_cmux_connect_async(cmux);
947+
if (ret < 0) {
948+
return ret;
952949
}
953950

954951
if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT, false,
@@ -963,22 +960,24 @@ int modem_cmux_connect_async(struct modem_cmux *cmux)
963960
{
964961
__ASSERT_NO_MSG(cmux->pipe != NULL);
965962

966-
if (k_work_delayable_is_pending(&cmux->connect_work) == true) {
967-
return -EBUSY;
963+
if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_CONNECTED_BIT, false, K_NO_WAIT)) {
964+
return -EALREADY;
965+
}
966+
967+
if (k_work_delayable_is_pending(&cmux->connect_work) == false) {
968+
k_work_schedule(&cmux->connect_work, K_NO_WAIT);
968969
}
969970

970-
k_work_schedule(&cmux->connect_work, K_NO_WAIT);
971971
return 0;
972972
}
973973

974974
int modem_cmux_disconnect(struct modem_cmux *cmux)
975975
{
976-
if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT, false, K_NO_WAIT)) {
977-
return -EALREADY;
978-
}
976+
int ret;
979977

980-
if (k_work_delayable_is_pending(&cmux->disconnect_work) == false) {
981-
k_work_schedule(&cmux->disconnect_work, K_NO_WAIT);
978+
ret = modem_cmux_disconnect_async(cmux);
979+
if (ret < 0) {
980+
return ret;
982981
}
983982

984983
if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT, false,
@@ -991,11 +990,16 @@ int modem_cmux_disconnect(struct modem_cmux *cmux)
991990

992991
int modem_cmux_disconnect_async(struct modem_cmux *cmux)
993992
{
994-
if (k_work_delayable_is_pending(&cmux->disconnect_work) == true) {
995-
return -EBUSY;
993+
__ASSERT_NO_MSG(cmux->pipe != NULL);
994+
995+
if (k_event_wait(&cmux->event, MODEM_CMUX_EVENT_DISCONNECTED_BIT, false, K_NO_WAIT)) {
996+
return -EALREADY;
997+
}
998+
999+
if (k_work_delayable_is_pending(&cmux->disconnect_work) == false) {
1000+
k_work_schedule(&cmux->disconnect_work, K_NO_WAIT);
9961001
}
9971002

998-
k_work_schedule(&cmux->disconnect_work, K_NO_WAIT);
9991003
return 0;
10001004
}
10011005

0 commit comments

Comments
 (0)