Skip to content

Commit 3c1857d

Browse files
committed
Merge branch 'feature/add_modbus_tcp_function' into 'master'
feat(modbus): add modbus tcp function See merge request sdk/ESP8266_RTOS_SDK!1489
2 parents aa769c9 + c2e915b commit 3c1857d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+15060
-2
lines changed

components/freemodbus/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# The following five lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
set(srcs
4+
"common/esp_modbus_master.c"
5+
"common/esp_modbus_slave.c"
6+
"modbus/mb.c"
7+
"modbus/mb_m.c"
8+
"modbus/tcp/mbtcp.c"
9+
"modbus/tcp/mbtcp_m.c"
10+
"port/port.c"
11+
"port/portevent.c"
12+
"port/portevent_m.c"
13+
"port/portother.c"
14+
"port/portother_m.c"
15+
"port/porttimer.c"
16+
"port/porttimer_m.c"
17+
"modbus/functions/mbfunccoils.c"
18+
"modbus/functions/mbfunccoils_m.c"
19+
"modbus/functions/mbfuncdiag.c"
20+
"modbus/functions/mbfuncdisc.c"
21+
"modbus/functions/mbfuncdisc_m.c"
22+
"modbus/functions/mbfuncholding.c"
23+
"modbus/functions/mbfuncholding_m.c"
24+
"modbus/functions/mbfuncinput.c"
25+
"modbus/functions/mbfuncinput_m.c"
26+
"modbus/functions/mbfuncother.c"
27+
"modbus/functions/mbutils.c"
28+
"tcp_slave/port/port_tcp_slave.c"
29+
"tcp_slave/modbus_controller/mbc_tcp_slave.c"
30+
"tcp_master/modbus_controller/mbc_tcp_master.c"
31+
"tcp_master/port/port_tcp_master.c"
32+
"common/esp_modbus_master_tcp.c"
33+
"common/esp_modbus_slave_tcp.c")
34+
35+
set(include_dirs common/include)
36+
37+
set(priv_include_dirs common port modbus modbus/ascii modbus/functions
38+
modbus/rtu modbus/tcp modbus/include)
39+
40+
list(APPEND priv_include_dirs tcp_slave/port tcp_slave/modbus_controller
41+
tcp_master/port tcp_master/modbus_controller)
42+
43+
idf_component_register(SRCS "${srcs}"
44+
INCLUDE_DIRS "${include_dirs}"
45+
PRIV_INCLUDE_DIRS "${priv_include_dirs}")

components/freemodbus/Kconfig

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
menu "Modbus configuration"
2+
3+
config FMB_COMM_MODE_TCP_EN
4+
bool "Enable Modbus stack support for TCP communication mode"
5+
default y
6+
help
7+
Enable Modbus TCP option for stack.
8+
9+
config FMB_TCP_PORT_DEFAULT
10+
int "Modbus TCP port number"
11+
range 0 65535
12+
default 502
13+
depends on FMB_COMM_MODE_TCP_EN
14+
help
15+
Modbus default port number used by Modbus TCP stack
16+
17+
config FMB_TCP_PORT_MAX_CONN
18+
int "Maximum allowed connections for TCP stack"
19+
range 1 6
20+
default 5
21+
depends on FMB_COMM_MODE_TCP_EN
22+
help
23+
Maximum allowed connections number for Modbus TCP stack.
24+
This is used by Modbus master and slave port layer to establish connections.
25+
This parameter may decrease performance of Modbus stack and can cause
26+
increasing of processing time (increase only if absolutely necessary).
27+
28+
config FMB_TCP_CONNECTION_TOUT_SEC
29+
int "Modbus TCP connection timeout"
30+
range 1 3600
31+
default 20
32+
depends on FMB_COMM_MODE_TCP_EN
33+
help
34+
Modbus TCP connection timeout in seconds.
35+
Once expired the current connection with the client will be closed
36+
and Modbus slave will be waiting for new connection to accept.
37+
38+
config FMB_MASTER_TIMEOUT_MS_RESPOND
39+
int "Slave respond timeout (Milliseconds)"
40+
default 150
41+
range 50 3000
42+
help
43+
If master sends a frame which is not broadcast, it has to wait sometime for slave response.
44+
if slave is not respond in this time, the master will process timeout error.
45+
46+
config FMB_MASTER_DELAY_MS_CONVERT
47+
int "Slave conversion delay (Milliseconds)"
48+
default 200
49+
range 50 400
50+
help
51+
If master sends a broadcast frame, it has to wait conversion time to delay,
52+
then master can send next frame.
53+
54+
config FMB_QUEUE_LENGTH
55+
int "Modbus serial task queue length"
56+
range 0 200
57+
default 20
58+
help
59+
Modbus serial driver queue length. It is used by event queue task.
60+
See the serial driver API for more information.
61+
62+
config FMB_PORT_TASK_STACK_SIZE
63+
int "Modbus port task stack size"
64+
range 2048 8192
65+
default 4096
66+
help
67+
Modbus port task stack size for rx/tx event processing.
68+
It may be adjusted when debugging is enabled (for example).
69+
70+
config FMB_SERIAL_BUF_SIZE
71+
int "Modbus serial task RX/TX buffer size"
72+
range 0 2048
73+
default 256
74+
help
75+
Modbus serial task RX and TX buffer size for UART driver initialization.
76+
This buffer is used for modbus frame transfer. The Modbus protocol maximum
77+
frame size is 256 bytes. Bigger size can be used for non standard implementations.
78+
79+
config FMB_PORT_TASK_PRIO
80+
int "Modbus port task priority"
81+
range 3 10
82+
default 10
83+
help
84+
Modbus port data processing task priority.
85+
The priority of Modbus controller task is equal to (CONFIG_FMB_PORT_TASK_PRIO - 1).
86+
87+
config FMB_CONTROLLER_SLAVE_ID_SUPPORT
88+
bool "Modbus controller slave ID support"
89+
default y
90+
help
91+
Modbus slave ID support enable.
92+
When enabled the Modbus <Report Slave ID> command is supported by stack.
93+
94+
config FMB_CONTROLLER_SLAVE_ID
95+
hex "Modbus controller slave ID"
96+
range 0 4294967295
97+
default 0x00112233
98+
depends on FMB_CONTROLLER_SLAVE_ID_SUPPORT
99+
help
100+
Modbus slave ID value to identify modbus device
101+
in the network using <Report Slave ID> command.
102+
Most significant byte of ID is used as short device ID and
103+
other three bytes used as long ID.
104+
105+
config FMB_CONTROLLER_NOTIFY_TIMEOUT
106+
int "Modbus controller notification timeout (ms)"
107+
range 0 200
108+
default 20
109+
help
110+
Modbus controller notification timeout in milliseconds.
111+
This timeout is used to send notification about accessed parameters.
112+
113+
config FMB_CONTROLLER_NOTIFY_QUEUE_SIZE
114+
int "Modbus controller notification queue size"
115+
range 0 200
116+
default 20
117+
help
118+
Modbus controller notification queue size.
119+
The notification queue is used to get information about accessed parameters.
120+
121+
config FMB_CONTROLLER_STACK_SIZE
122+
int "Modbus controller stack size"
123+
range 0 8192
124+
default 4096
125+
help
126+
Modbus controller task stack size. The Stack size may be adjusted when
127+
debug mode is used which requires more stack size (for example).
128+
129+
config FMB_EVENT_QUEUE_TIMEOUT
130+
int "Modbus stack event queue timeout (ms)"
131+
range 0 500
132+
default 20
133+
help
134+
Modbus stack event queue timeout in milliseconds. This may help to optimize
135+
Modbus stack event processing time.
136+
137+
config FMB_TIMER_GROUP
138+
int "Modbus Timer group number"
139+
range 0 1
140+
default 0
141+
help
142+
Modbus Timer group number that is used for timeout measurement.
143+
144+
config FMB_TIMER_INDEX
145+
int "Modbus Timer index in the group"
146+
range 0 1
147+
default 0
148+
help
149+
Modbus Timer Index in the group that is used for timeout measurement.
150+
151+
config FMB_TIMER_ISR_IN_IRAM
152+
bool "Place timer interrupt handler into IRAM"
153+
default n
154+
select UART_ISR_IN_IRAM
155+
help
156+
This option places Modbus timer IRQ handler into IRAM.
157+
This allows to avoid delays related to processing of non-IRAM-safe interrupts
158+
during a flash write operation (NVS updating a value, or some other
159+
flash API which has to perform an read/write operation and disable CPU cache).
160+
This option has dependency with the UART_ISR_IN_IRAM option which places UART interrupt
161+
handler into IRAM to prevent delays related to processing of UART events.
162+
163+
endmenu
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// Stack callback functions prototypes
17+
18+
#ifndef _ESP_MODBUS_CALLBACKS_H_
19+
#define _ESP_MODBUS_CALLBACKS_H_
20+
21+
#include "mb.h"
22+
#include "mb_m.h"
23+
24+
typedef eMBErrorCode (*reg_input_cb)(UCHAR*, USHORT, USHORT);
25+
typedef eMBErrorCode (*reg_holding_cb)(UCHAR*, USHORT, USHORT, eMBRegisterMode);
26+
typedef eMBErrorCode (*reg_coils_cb)(UCHAR*, USHORT, USHORT, eMBRegisterMode);
27+
typedef eMBErrorCode (*reg_discrete_cb)(UCHAR*, USHORT, USHORT);
28+
29+
#endif /* _ESP_MODBUS_CALLBACKS_H_ */

0 commit comments

Comments
 (0)