Commit 583f4956 authored by Abram Early's avatar Abram Early Committed by Fabio Baltieri
Browse files

modbus: reset wait semaphore before tx

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: default avatarAbram Early <abram.early@gmail.com>
parent a3784401
Loading
Loading
Loading
Loading
+2 −0
Changes for subsys/modbus/modbus_core.c: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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) {