modbus: move some RX/TX ADU related code to the core
Let the core call the modbus_tx_adu() to make the process more comprehensible. Move tx-wait-for-rx handling outside of client code. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
e3c630d25f
commit
0bf4916efd
4 changed files with 43 additions and 43 deletions
|
@ -80,18 +80,20 @@ static void modbus_rx_handler(struct k_work *item)
|
|||
|
||||
if (ctx->client == true) {
|
||||
k_sem_give(&ctx->client_wait_sem);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_MODBUS_SERVER)) {
|
||||
} else if (IS_ENABLED(CONFIG_MODBUS_SERVER)) {
|
||||
bool respond = modbus_server_handler(ctx);
|
||||
|
||||
if (respond) {
|
||||
modbus_tx_adu(ctx);
|
||||
} else {
|
||||
LOG_DBG("Server has dropped frame");
|
||||
}
|
||||
|
||||
switch (ctx->mode) {
|
||||
case MODBUS_MODE_RTU:
|
||||
case MODBUS_MODE_ASCII:
|
||||
if (IS_ENABLED(CONFIG_MODBUS_SERIAL) &&
|
||||
respond == false) {
|
||||
LOG_DBG("Server has dropped frame");
|
||||
modbus_serial_rx_enable(ctx);
|
||||
}
|
||||
break;
|
||||
|
@ -116,6 +118,18 @@ void modbus_tx_adu(struct modbus_context *ctx)
|
|||
}
|
||||
}
|
||||
|
||||
int modbus_tx_wait_rx_adu(struct modbus_context *ctx)
|
||||
{
|
||||
modbus_tx_adu(ctx);
|
||||
|
||||
if (k_sem_take(&ctx->client_wait_sem, K_USEC(ctx->rxwait_to)) != 0) {
|
||||
LOG_WRN("Client wait-for-RX timeout");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return ctx->rx_adu_err;
|
||||
}
|
||||
|
||||
struct modbus_context *modbus_get_context(const uint8_t iface)
|
||||
{
|
||||
struct modbus_context *ctx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue