fix: address maximum api blocking time

This commit is contained in:
aleks
2026-05-04 08:58:09 +02:00
parent db0cc168e9
commit 2cff3ac0ee
3 changed files with 34 additions and 6 deletions
+12 -1
View File
@@ -71,12 +71,23 @@ menu "Modbus configuration"
config FMB_MASTER_TIMEOUT_MS_RESPOND
int "Slave respond timeout (Milliseconds)"
default 10000
default 5000
range 150 30000
help
If master sends a frame which is not broadcast, it has to wait some time for slave response.
if slave is not respond in this time, the master will process timeout error.
config FMB_MASTER_MAX_API_BLOCKING_TIME_MS
int "Modbus TCP master API blocking threshold (ms)"
range 3000 200000
default 6000
help
This option represents the maximum API blocking time used by controller API calls.
The master uses timer to handle slave response timeout as defined by FMB_MASTER_TIMEOUT_MS_RESPOND
or overridden by corresponded master configuration field. The actual API blocking time is determined
as a shortest time between these two values. This API blocking time is separated with
FMB_MASTER_TIMEOUT_MS_RESPOND intentionally to prevent possible misconfiguration and must not be less than it.
config FMB_MASTER_DELAY_MS_CONVERT
int "Slave conversion delay (Milliseconds)"
default 200
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2016-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -203,6 +203,13 @@ esp_err_t mbc_master_start(void *ctx)
MB_RETURN_ON_FALSE(ctx, ESP_ERR_INVALID_STATE, TAG,
"Master interface is not correctly initialized.");
mbm_controller_iface_t *mbm_controller = MB_MASTER_GET_IFACE(ctx);
if ((mbm_controller->opts.comm_opts.common_opts.response_tout_ms > 0) &&
(mbm_controller->opts.comm_opts.common_opts.response_tout_ms > CONFIG_FMB_MASTER_MAX_API_BLOCKING_TIME_MS)) {
mbm_controller->opts.comm_opts.common_opts.response_tout_ms = CONFIG_FMB_MASTER_MAX_API_BLOCKING_TIME_MS + 500;
ESP_LOGW(TAG, "Slave response time option in master is incorrect, setting to max value.");
}
MB_RETURN_ON_FALSE(mbm_controller->start, ESP_ERR_INVALID_STATE, TAG,
"Master interface is not correctly initialized.");
error = mbm_controller->start(ctx);
+14 -4
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2016-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -22,16 +22,26 @@
#include "mb_utils.h"
#include "mb_master.h"
#include "sdkconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ----------------------- Defines ------------------------------------------*/
#define MB_MIN_RESP_DELAY_MS (300)
// Set the maximum resource waiting time, the actual time of resource release
// will be dependent on response time set by timer + conversion time if the command is received
#define MB_MAX_RESP_DELAY_MS (3000)
#define MB_MIN_RESP_DELAY_MS (300)
// will be dependent on response time set by timer + conversion time if the command is received.
#if defined(CONFIG_FMB_MASTER_MAX_API_BLOCKING_TIME_MS)
#define MB_MAX_RESP_DELAY_MS (CONFIG_FMB_MASTER_MAX_API_BLOCKING_TIME_MS)
_Static_assert(
(CONFIG_FMB_MASTER_MAX_API_BLOCKING_TIME_MS) >= (CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND),
"CONFIG_FMB_MASTER_MAX_API_BLOCKING_TIME_MS must be >= CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND"
);
#else
#define MB_MAX_RESP_DELAY_MS (CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND)
#endif
/**
* @brief Modbus controller handler structure