-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modbus: reset wait semaphore before tx #79345
modbus: reset wait semaphore before tx #79345
Conversation
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>
1b2060a
to
add7c4c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to add a test case to catch this in the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I get some leeway at work, I'll get an nucleo board working and submit a test case. I think the easiest way to do it would be to artificially delay the server response past the timeout. But I'm not sure when I'll get to it.
Tagged this merge with a bug report for tracking purposes, and the backports. |
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.
Ideally, I'd like to have the modbus test check for this edge case, but I don't have an frdm-k64f board, or the time to figure out how to configure a new board for the test to develop one. That said, I'm hoping this is simple and straightforward enough to get the point across. I've been running this modification on our boards for several days now and it's only improved behavior. But anecdotes only go so far.
Fixes #79518