Skip to content

Commit

Permalink
modbus: reset wait semaphore before tx
Browse files Browse the repository at this point in the history
A response returned after a request times out would increment the
semaphore and stay until the next request is made which will immediately
return when k_sem_take is called even before a response is returned. This
will once again have the same problem when the actual response arrives.
So the wait semaphore just needs to be reset before transmitting.

Signed-off-by: Abram Early <abram.early@gmail.com>
(cherry picked from commit 583f495)
  • Loading branch information
legoabram authored and github-actions[bot] committed Oct 7, 2024
1 parent 6937dab commit e8d02ef
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions subsys/modbus/modbus_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ void modbus_tx_adu(struct modbus_context *ctx)

int modbus_tx_wait_rx_adu(struct modbus_context *ctx)
{
k_sem_reset(&ctx->client_wait_sem);

modbus_tx_adu(ctx);

if (k_sem_take(&ctx->client_wait_sem, K_USEC(ctx->rxwait_to)) != 0) {
Expand Down

0 comments on commit e8d02ef

Please sign in to comment.