Skip to content

Commit 27b0d4e

Browse files
bjarki-andreasencarlescufi
authored andcommitted
modem: chat: remove receive and transmit timeouts
Remove receive and transmit timeouts which are no longer useful as the RECEIVE_READY and TRANSMIT_IDLE events will be used to efficiently manage timeouts between transmit/receive calls. Then update the the in-tree drivers using the modem_chat module to omit the process timeout parameter. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 62809d7 commit 27b0d4e

File tree

6 files changed

+14
-24
lines changed

6 files changed

+14
-24
lines changed

drivers/gnss/gnss_nmea_generic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static int gnss_nmea_generic_init_chat(const struct device *dev)
127127
.argv_size = ARRAY_SIZE(data->chat_argv),
128128
.unsol_matches = unsol_matches,
129129
.unsol_matches_size = ARRAY_SIZE(unsol_matches),
130-
.process_timeout = K_MSEC(2),
131130
};
132131

133132
return modem_chat_init(&data->chat, &chat_config);

drivers/gnss/gnss_quectel_lcx6g.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ static int quectel_lcx6g_init_chat(const struct device *dev)
686686
.argv_size = ARRAY_SIZE(data->chat_argv),
687687
.unsol_matches = unsol_matches,
688688
.unsol_matches_size = ARRAY_SIZE(unsol_matches),
689-
.process_timeout = K_MSEC(2),
690689
};
691690

692691
return modem_chat_init(&data->chat, &chat_config);

drivers/modem/modem_cellular.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,6 @@ static int modem_cellular_init(const struct device *dev)
15201520
.argv_size = ARRAY_SIZE(data->chat_argv),
15211521
.unsol_matches = unsol_matches,
15221522
.unsol_matches_size = ARRAY_SIZE(unsol_matches),
1523-
.process_timeout = K_MSEC(2),
15241523
};
15251524

15261525
modem_chat_init(&data->chat, &chat_config);

include/zephyr/modem/chat.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ struct modem_chat {
242242
/* Script sending */
243243
uint16_t script_send_request_pos;
244244
uint16_t script_send_delimiter_pos;
245-
struct k_work_delayable script_send_work;
245+
struct k_work script_send_work;
246246
struct k_work_delayable script_send_timeout_work;
247247

248248
/* Match parsing */
@@ -252,8 +252,7 @@ struct modem_chat {
252252
uint16_t parse_match_type;
253253

254254
/* Process received data */
255-
struct k_work_delayable process_work;
256-
k_timeout_t process_timeout;
255+
struct k_work receive_work;
257256
};
258257

259258
/**
@@ -282,8 +281,6 @@ struct modem_chat_config {
282281
const struct modem_chat_match *unsol_matches;
283282
/** Elements in array of unsolicited matches */
284283
uint16_t unsol_matches_size;
285-
/** Delay from receive ready event to pipe receive occurs */
286-
k_timeout_t process_timeout;
287284
};
288285

289286
/**

subsys/modem/modem_chat.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void modem_chat_script_stop(struct modem_chat *chat, enum modem_chat_scri
9797

9898
/* Cancel work */
9999
k_work_cancel_delayable(&chat->script_timeout_work);
100-
k_work_cancel_delayable(&chat->script_send_work);
100+
k_work_cancel(&chat->script_send_work);
101101
k_work_cancel_delayable(&chat->script_send_timeout_work);
102102

103103
/* Clear script running state */
@@ -117,7 +117,7 @@ static void modem_chat_script_send(struct modem_chat *chat)
117117
chat->script_send_delimiter_pos = 0;
118118

119119
/* Schedule script send work */
120-
k_work_schedule(&chat->script_send_work, K_NO_WAIT);
120+
k_work_submit(&chat->script_send_work);
121121
}
122122

123123
static void modem_chat_script_set_response_matches(struct modem_chat *chat)
@@ -308,8 +308,7 @@ static uint16_t modem_chat_script_chat_get_send_timeout(struct modem_chat *chat)
308308

309309
static void modem_chat_script_send_handler(struct k_work *item)
310310
{
311-
struct k_work_delayable *dwork = k_work_delayable_from_work(item);
312-
struct modem_chat *chat = CONTAINER_OF(dwork, struct modem_chat, script_send_work);
311+
struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, script_send_work);
313312
uint16_t timeout;
314313

315314
/* Validate script running */
@@ -319,13 +318,13 @@ static void modem_chat_script_send_handler(struct k_work *item)
319318

320319
/* Send request */
321320
if (modem_chat_script_send_request(chat) == false) {
322-
k_work_schedule(&chat->script_send_work, chat->process_timeout);
321+
k_work_submit(&chat->script_send_work);
323322
return;
324323
}
325324

326325
/* Send delimiter */
327326
if (modem_chat_script_send_delimiter(chat) == false) {
328-
k_work_schedule(&chat->script_send_work, chat->process_timeout);
327+
k_work_submit(&chat->script_send_work);
329328
return;
330329
}
331330

@@ -687,8 +686,7 @@ static void modem_chat_process_bytes(struct modem_chat *chat)
687686

688687
static void modem_chat_process_handler(struct k_work *item)
689688
{
690-
struct k_work_delayable *dwork = k_work_delayable_from_work(item);
691-
struct modem_chat *chat = CONTAINER_OF(dwork, struct modem_chat, process_work);
689+
struct modem_chat *chat = CONTAINER_OF(item, struct modem_chat, receive_work);
692690
int ret;
693691

694692
/* Fill work buffer */
@@ -702,7 +700,7 @@ static void modem_chat_process_handler(struct k_work *item)
702700

703701
/* Process data */
704702
modem_chat_process_bytes(chat);
705-
k_work_schedule(&chat->process_work, K_NO_WAIT);
703+
k_work_submit(&chat->receive_work);
706704
}
707705

708706
static void modem_chat_pipe_callback(struct modem_pipe *pipe, enum modem_pipe_event event,
@@ -711,7 +709,7 @@ static void modem_chat_pipe_callback(struct modem_pipe *pipe, enum modem_pipe_ev
711709
struct modem_chat *chat = (struct modem_chat *)user_data;
712710

713711
if (event == MODEM_PIPE_EVENT_RECEIVE_READY) {
714-
k_work_schedule(&chat->process_work, chat->process_timeout);
712+
k_work_submit(&chat->receive_work);
715713
}
716714
}
717715

@@ -741,14 +739,13 @@ int modem_chat_init(struct modem_chat *chat, const struct modem_chat_config *con
741739
chat->filter_size = config->filter_size;
742740
chat->matches[MODEM_CHAT_MATCHES_INDEX_UNSOL] = config->unsol_matches;
743741
chat->matches_size[MODEM_CHAT_MATCHES_INDEX_UNSOL] = config->unsol_matches_size;
744-
chat->process_timeout = config->process_timeout;
745742
atomic_set(&chat->script_state, 0);
746743
k_sem_init(&chat->script_stopped_sem, 0, 1);
747-
k_work_init_delayable(&chat->process_work, modem_chat_process_handler);
744+
k_work_init(&chat->receive_work, modem_chat_process_handler);
748745
k_work_init(&chat->script_run_work, modem_chat_script_run_handler);
749746
k_work_init_delayable(&chat->script_timeout_work, modem_chat_script_timeout_handler);
750747
k_work_init(&chat->script_abort_work, modem_chat_script_abort_handler);
751-
k_work_init_delayable(&chat->script_send_work, modem_chat_script_send_handler);
748+
k_work_init(&chat->script_send_work, modem_chat_script_send_handler);
752749
k_work_init_delayable(&chat->script_send_timeout_work,
753750
modem_chat_script_send_timeout_handler);
754751

@@ -831,8 +828,8 @@ void modem_chat_release(struct modem_chat *chat)
831828

832829
k_work_cancel_sync(&chat->script_run_work, &sync);
833830
k_work_cancel_sync(&chat->script_abort_work, &sync);
834-
k_work_cancel_delayable_sync(&chat->process_work, &sync);
835-
k_work_cancel_delayable_sync(&chat->script_send_work, &sync);
831+
k_work_cancel_sync(&chat->receive_work, &sync);
832+
k_work_cancel_sync(&chat->script_send_work, &sync);
836833

837834
chat->pipe = NULL;
838835
chat->receive_buf_len = 0;

tests/subsys/modem/modem_chat/src/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ static void *test_modem_chat_setup(void)
254254
.argv_size = ARRAY_SIZE(cmd_argv),
255255
.unsol_matches = unsol_matches,
256256
.unsol_matches_size = ARRAY_SIZE(unsol_matches),
257-
.process_timeout = K_MSEC(2),
258257
};
259258

260259
zassert(modem_chat_init(&cmd, &cmd_config) == 0, "Failed to init modem CMD");

0 commit comments

Comments
 (0)