summaryrefslogtreecommitdiff
path: root/components/net
diff options
context:
space:
mode:
authorarmink <[email protected]>2019-12-17 20:11:46 +0800
committerarmink <[email protected]>2019-12-17 20:11:46 +0800
commit4875ee8a3ab95c4fbf1e09941d3f44d99a9a632b (patch)
tree15c596c04a842bac747bbcf05a703b8da76f8eac /components/net
parentfa46d6ac861f26b472d62abdf1278c445431ce4c (diff)
Sync from master (75a3f3dd3a930eab1dc58fa0258a9d1605a0ac11)
Diffstat (limited to 'components/net')
-rw-r--r--components/net/Kconfig53
-rw-r--r--components/net/at/Kconfig19
-rw-r--r--components/net/at/at_socket/at_socket.c73
-rw-r--r--components/net/at/include/at.h4
-rw-r--r--components/net/at/src/at_cli.c10
-rw-r--r--components/net/at/src/at_server.c99
-rw-r--r--components/net/freemodbus/Changelog.txt329
-rw-r--r--components/net/freemodbus/Kconfig27
-rw-r--r--components/net/freemodbus/SConscript77
-rw-r--r--components/net/freemodbus/bsd.txt25
-rw-r--r--components/net/freemodbus/gpl.txt340
-rw-r--r--components/net/freemodbus/lgpl.txt504
-rw-r--r--components/net/freemodbus/modbus/ascii/mbascii.c485
-rw-r--r--components/net/freemodbus/modbus/ascii/mbascii.h56
-rw-r--r--components/net/freemodbus/modbus/functions/mbfunccoils.c269
-rw-r--r--components/net/freemodbus/modbus/functions/mbfunccoils_m.c390
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncdiag.c29
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncdisc.c125
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncdisc_m.c162
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncholding.c308
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncholding_m.c455
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncinput.c122
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncinput_m.c148
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncother.c88
-rw-r--r--components/net/freemodbus/modbus/functions/mbutils.c141
-rw-r--r--components/net/freemodbus/modbus/include/mb.h417
-rw-r--r--components/net/freemodbus/modbus/include/mb_m.h402
-rw-r--r--components/net/freemodbus/modbus/include/mbconfig.h124
-rw-r--r--components/net/freemodbus/modbus/include/mbframe.h87
-rw-r--r--components/net/freemodbus/modbus/include/mbfunc.h80
-rw-r--r--components/net/freemodbus/modbus/include/mbport.h205
-rw-r--r--components/net/freemodbus/modbus/include/mbproto.h83
-rw-r--r--components/net/freemodbus/modbus/include/mbutils.h108
-rw-r--r--components/net/freemodbus/modbus/mb.c412
-rw-r--r--components/net/freemodbus/modbus/mb_m.c406
-rw-r--r--components/net/freemodbus/modbus/rtu/mbcrc.c98
-rw-r--r--components/net/freemodbus/modbus/rtu/mbcrc.h36
-rw-r--r--components/net/freemodbus/modbus/rtu/mbrtu.c354
-rw-r--r--components/net/freemodbus/modbus/rtu/mbrtu.h64
-rw-r--r--components/net/freemodbus/modbus/rtu/mbrtu_m.c443
-rw-r--r--components/net/freemodbus/modbus/tcp/mbtcp.c158
-rw-r--r--components/net/freemodbus/modbus/tcp/mbtcp.h53
-rw-r--r--components/net/freemodbus/port/port.c38
-rw-r--r--components/net/freemodbus/port/port.h61
-rw-r--r--components/net/freemodbus/port/portevent.c68
-rw-r--r--components/net/freemodbus/port/portevent_m.c239
-rw-r--r--components/net/freemodbus/port/portserial.c225
-rw-r--r--components/net/freemodbus/port/portserial_m.c229
-rw-r--r--components/net/freemodbus/port/porttimer.c63
-rw-r--r--components/net/freemodbus/port/porttimer_m.c107
-rw-r--r--components/net/freemodbus/port/user_mb_app.c286
-rw-r--r--components/net/freemodbus/port/user_mb_app.h46
-rw-r--r--components/net/freemodbus/port/user_mb_app_m.c294
-rw-r--r--components/net/lwip-1.4.1/src/arch/sys_arch.c8
-rw-r--r--components/net/lwip-1.4.1/src/core/dns.c7
-rw-r--r--components/net/lwip-1.4.1/src/netif/ethernetif.c39
-rw-r--r--components/net/lwip-2.0.2/src/arch/sys_arch.c4
-rw-r--r--components/net/lwip-2.0.2/src/core/dns.c7
-rw-r--r--components/net/lwip-2.0.2/src/core/netif.c15
-rw-r--r--components/net/lwip-2.0.2/src/include/netif/ethernetif.h1
-rw-r--r--components/net/lwip-2.0.2/src/netif/ethernetif.c79
-rw-r--r--components/net/lwip-2.1.0/src/arch/sys_arch.c4
-rw-r--r--components/net/lwip-2.1.0/src/core/dns.c7
-rw-r--r--components/net/lwip-2.1.0/src/core/netif.c15
-rw-r--r--components/net/lwip-2.1.0/src/include/netif/ethernetif.h1
-rw-r--r--components/net/lwip-2.1.0/src/netif/ethernetif.c76
-rw-r--r--components/net/lwip-2.1.0/src/netif/lowpan6.c2
-rw-r--r--components/net/lwip_dhcpd/SConscript2
-rw-r--r--components/net/lwip_dhcpd/dhcp_server.c10
-rw-r--r--components/net/lwip_dhcpd/dhcp_server.h1
-rw-r--r--components/net/lwip_dhcpd/dhcp_server_raw.c86
-rw-r--r--components/net/netdev/include/netdev.h15
-rw-r--r--components/net/netdev/include/netdev_ipaddr.h253
-rw-r--r--components/net/netdev/src/netdev.c284
-rw-r--r--components/net/netdev/src/netdev_ipaddr.c357
-rw-r--r--components/net/sal_socket/impl/af_inet_lwip.c12
-rw-r--r--components/net/sal_socket/include/sal_socket.h20
-rw-r--r--components/net/sal_socket/socket/net_sockets.c4
-rw-r--r--components/net/sal_socket/src/sal_socket.c200
79 files changed, 1395 insertions, 9638 deletions
diff --git a/components/net/Kconfig b/components/net/Kconfig
index 68737176ed..4436934f09 100644
--- a/components/net/Kconfig
+++ b/components/net/Kconfig
@@ -1,18 +1,17 @@
menu "Network"
menu "Socket abstraction layer"
-
+
config RT_USING_SAL
bool "Enable socket abstraction layer"
select RT_USING_NETDEV
- select RT_USING_LIBC
select RT_USING_SYSTEM_WORKQUEUE
default n
if RT_USING_SAL
if RT_USING_LWIP || AT_USING_SOCKET
-
+
menu "protocol stack implement"
config SAL_USING_LWIP
@@ -24,29 +23,30 @@ config RT_USING_SAL
bool "Support AT Commands stack"
default y
depends on AT_USING_SOCKET
-
+
config SAL_USING_TLS
bool "Support MbedTLS protocol"
default y
depends on PKG_USING_MBEDTLS
endmenu
-
+
endif
config SAL_USING_POSIX
bool "Enable BSD socket operated by file system API"
default n
select RT_USING_DFS
+ select RT_USING_LIBC
select RT_USING_POSIX
help
Let BSD socket operated by file system API, such as read/write and involveed in select/poll POSIX APIs.
-
+
if !SAL_USING_POSIX
-
+
config SAL_SOCKETS_NUM
int "the maximum number of sockets"
default 16
-
+
endif
endif
@@ -68,7 +68,7 @@ config RT_USING_NETDEV
config NETDEV_USING_PING
bool "Enable ping features"
default y
-
+
config NETDEV_USING_NETSTAT
bool "Enable netstat features"
default y
@@ -76,6 +76,25 @@ config RT_USING_NETDEV
config NETDEV_USING_AUTO_DEFAULT
bool "Enable default netdev automatic change features"
default y
+
+ config NETDEV_USING_IPV6
+ bool "Enable IPV6 protocol support"
+ default n
+
+ config NETDEV_IPV4
+ int
+ default 1
+
+ config NETDEV_IPV6
+ int
+ default 1 if NETDEV_USING_IPV6
+ default 0 if !NETDEV_USING_IPV6
+
+ config NETDEV_IPV6_SCOPES
+ bool
+ help
+ Defined to synchronize the ip6_addr structure state
+ default n
endif
endmenu
@@ -104,11 +123,11 @@ config RT_USING_LWIP
endchoice
if (RT_USING_LWIP210 || RT_USING_LWIP202)
- if (!RT_USING_NETDEV || (RT_USING_NETDEV && NETDEV_IPV6))
- config RT_USING_LWIP_IPV6
- bool "IPV6 protocol"
- default n
- endif
+ config RT_USING_LWIP_IPV6
+ bool "IPV6 protocol"
+ default n
+ select NETDEV_USING_IPV6
+ select NETDEV_IPV6_SCOPES if RT_USING_LWIP210
endif
config RT_LWIP_IGMP
@@ -258,7 +277,7 @@ config RT_USING_LWIP
config LWIP_NETIF_STATUS_CALLBACK
int "Enable netif status callback"
default 1
-
+
config LWIP_NETIF_LINK_CALLBACK
int "Enable netif link status callback"
default 1
@@ -295,7 +314,7 @@ config RT_USING_LWIP
config RT_LWIP_USING_HW_CHECKSUM
bool "Enable hardware checksum"
default n
-
+
config RT_LWIP_USING_PING
bool "Enable ping features"
default y
@@ -427,8 +446,6 @@ config RT_USING_LWIP
endmenu
-source "$RTT_DIR/components/net/freemodbus/Kconfig"
-
source "$RTT_DIR/components/net/at/Kconfig"
if RT_USING_LWIP
diff --git a/components/net/at/Kconfig b/components/net/at/Kconfig
index 5a4a644761..50de005545 100644
--- a/components/net/at/Kconfig
+++ b/components/net/at/Kconfig
@@ -9,11 +9,11 @@ if RT_USING_AT
config AT_DEBUG
bool "Enable debug log output"
default n
-
+
config AT_USING_SERVER
bool "Enable AT commands server"
default n
-
+
if AT_USING_SERVER
config AT_SERVER_DEVICE
@@ -44,33 +44,32 @@ if RT_USING_AT
endchoice
endif
-
+
config AT_USING_CLIENT
bool "Enable AT commands client"
default n
-
+
if AT_USING_CLIENT
config AT_CLIENT_NUM_MAX
int "The maximum number of supported clients"
default 1
range 1 65535
-
+
config AT_USING_SOCKET
bool "Enable BSD Socket API support by AT commnads"
- select RT_USING_LIBC
select RT_USING_SAL
default n
-
+
endif
if AT_USING_SERVER || AT_USING_CLIENT
-
+
config AT_USING_CLI
bool "Enable CLI(Command-Line Interface) for AT commands"
default y
depends on FINSH_USING_MSH
-
+
config AT_PRINT_RAW_CMD
bool "Enable print RAW format AT command communication data"
default n
@@ -78,7 +77,7 @@ if RT_USING_AT
config AT_CMD_MAX_LEN
int "The maximum lenght of AT Commonds buffer"
default 128
-
+
endif
config AT_SW_VERSION_NUM
diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c
index 993ec33506..11be4e23c0 100644
--- a/components/net/at/at_socket/at_socket.c
+++ b/components/net/at/at_socket/at_socket.c
@@ -54,7 +54,6 @@ static rt_slist_t _socket_list = RT_SLIST_OBJECT_INIT(_socket_list);
struct at_socket *at_get_socket(int socket)
{
rt_base_t level;
- size_t list_num = 0;
rt_slist_t *node = RT_NULL;
struct at_socket *at_sock = RT_NULL;
@@ -62,9 +61,9 @@ struct at_socket *at_get_socket(int socket)
rt_slist_for_each(node, &_socket_list)
{
- if (socket == (list_num++))
+ at_sock = rt_slist_entry(node, struct at_socket, list);
+ if (socket == at_sock->socket)
{
- at_sock = rt_slist_entry(node, struct at_socket, list);
if (at_sock && at_sock->magic == AT_SOCKET_MAGIC)
{
rt_hw_interrupt_enable(level);
@@ -275,6 +274,34 @@ static void at_do_event_clean(struct at_socket *sock, at_event_t event)
}
}
+static int alloc_empty_socket(rt_slist_t *l)
+{
+ rt_base_t level;
+ rt_slist_t *node = RT_NULL;
+ rt_slist_t *pre_node = &_socket_list;
+ struct at_socket *at_sock = RT_NULL;
+ int idx = 0;
+
+ level = rt_hw_interrupt_disable();
+
+ rt_slist_init(l);
+
+ rt_slist_for_each(node, &_socket_list)
+ {
+ at_sock = rt_slist_entry(node, struct at_socket, list);
+ if(at_sock->socket != idx)
+ break;
+ idx++;
+ pre_node = node;
+ }
+
+ rt_slist_insert(pre_node, l);
+
+ rt_hw_interrupt_enable(level);
+
+ return idx;
+}
+
static struct at_socket *alloc_socket_by_device(struct at_device *device)
{
static rt_mutex_t at_slock = RT_NULL;
@@ -304,21 +331,9 @@ static struct at_socket *alloc_socket_by_device(struct at_device *device)
goto __err;
}
- /* add device socket to global socket list */
- {
- rt_base_t level;
-
- level = rt_hw_interrupt_disable();
-
- rt_slist_init(&(device->sockets[idx].list));
- rt_slist_append(&_socket_list, &(device->sockets[idx].list));
-
- rt_hw_interrupt_enable(level);
- }
-
sock = &(device->sockets[idx]);
/* the socket descriptor is the number of sockte lists */
- sock->socket = rt_slist_len(&_socket_list) - 1;
+ sock->socket = alloc_empty_socket(&(sock->list));
/* the socket operations is the specify operations of the device */
sock->ops = device->class->socket_ops;
/* the user-data is the at device socket descriptor */
@@ -446,7 +461,6 @@ static int free_socket(struct at_socket *sock)
/* delect socket from socket list */
{
rt_base_t level;
- int list_num = 0;
rt_slist_t *node = RT_NULL;
struct at_socket *at_sock = RT_NULL;
@@ -454,10 +468,10 @@ static int free_socket(struct at_socket *sock)
rt_slist_for_each(node, &_socket_list)
{
- if (sock->socket == (list_num++))
+ at_sock = rt_slist_entry(node, struct at_socket, list);
+ if (sock->socket == at_sock->socket)
{
- at_sock = rt_slist_entry(node, struct at_socket, list);
- if (at_sock)
+ if (at_sock && at_sock->magic == AT_SOCKET_MAGIC)
{
rt_slist_remove(&_socket_list, &at_sock->list);
break;
@@ -540,11 +554,12 @@ static int socketaddr_to_ipaddr_port(const struct sockaddr *sockaddr, ip_addr_t
const struct sockaddr_in* sin = (const struct sockaddr_in*) (const void *) sockaddr;
#if NETDEV_IPV4 && NETDEV_IPV6
- (*addr).u_addr.ip4.addr = sin->sin_addr.s_addr;
+ addr->u_addr.ip4.addr = sin->sin_addr.s_addr;
+ addr->type = IPADDR_TYPE_V4;
#elif NETDEV_IPV4
- (*addr).addr = sin->sin_addr.s_addr;
+ addr->addr = sin->sin_addr.s_addr;
#elif NETDEV_IPV6
- LOG_E("not support IPV6.");
+#error "not support IPV6."
#endif /* NETDEV_IPV4 && NETDEV_IPV6 */
*port = (uint16_t) HTONS_PORT(sin->sin_port);
@@ -855,7 +870,7 @@ int at_recv(int s, void *mem, size_t len, int flags)
int at_sendto(int socket, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
{
struct at_socket *sock = RT_NULL;
- int len, result = 0;
+ int len = 0, result = 0;
if (data == RT_NULL || size == 0)
{
@@ -1126,10 +1141,11 @@ struct hostent *at_gethostbyname(const char *name)
#if NETDEV_IPV4 && NETDEV_IPV6
addr.u_addr.ip4.addr = ipstr_to_u32(ipstr);
+ addr.type = IPADDR_TYPE_V4;
#elif NETDEV_IPV4
addr.addr = ipstr_to_u32(ipstr);
#elif NETDEV_IPV6
- LOG_E("not support IPV6.");
+#error "not support IPV6."
#endif /* NETDEV_IPV4 && NETDEV_IPV6 */
/* fill hostent structure */
@@ -1202,7 +1218,7 @@ int at_getaddrinfo(const char *nodename, const char *servname,
if ((hints != RT_NULL) && (hints->ai_flags & AI_NUMERICHOST))
{
/* no DNS lookup, just parse for an address string */
- if (!inet_aton(nodename, (ip4_addr_t * )&addr))
+ if (!inet_aton(nodename, &addr))
{
return EAI_NONAME;
}
@@ -1240,7 +1256,7 @@ int at_getaddrinfo(const char *nodename, const char *servname,
#elif NETDEV_IPV4
addr.addr = ipstr_to_u32(ip_str);
#elif NETDEV_IPV6
- LOG_E("not support IPV6.");
+ #error "not support IPV6."
#endif /* NETDEV_IPV4 && NETDEV_IPV6 */
}
}
@@ -1275,10 +1291,11 @@ int at_getaddrinfo(const char *nodename, const char *servname,
/* set up sockaddr */
#if NETDEV_IPV4 && NETDEV_IPV6
sa4->sin_addr.s_addr = addr.u_addr.ip4.addr;
+ sa4->type = IPADDR_TYPE_V4;
#elif NETDEV_IPV4
sa4->sin_addr.s_addr = addr.addr;
#elif NETDEV_IPV6
- LOG_E("not support IPV6.");
+#error "not support IPV6."
#endif /* NETDEV_IPV4 && NETDEV_IPV6 */
sa4->sin_family = AF_INET;
sa4->sin_len = sizeof(struct sockaddr_in);
diff --git a/components/net/at/include/at.h b/components/net/at/include/at.h
index dc2abef353..a7a6aeca7a 100644
--- a/components/net/at/include/at.h
+++ b/components/net/at/include/at.h
@@ -96,7 +96,7 @@ struct at_server
rt_device_t device;
at_status_t status;
- char (*get_char)(void);
+ rt_err_t (*get_char)(struct at_server *server, char *ch, rt_int32_t timeout);
rt_bool_t echo_mode;
char recv_buffer[AT_SERVER_RECV_BUFF_LEN];
@@ -194,6 +194,8 @@ int at_server_init(void);
void at_server_printf(const char *format, ...);
void at_server_printfln(const char *format, ...);
void at_server_print_result(at_result_t result);
+rt_size_t at_server_send(at_server_t server, const char *buf, rt_size_t size);
+rt_size_t at_server_recv(at_server_t server, char *buf, rt_size_t size, rt_int32_t timeout);
/* AT server request arguments parse */
int at_req_parse_args(const char *req_args, const char *req_expr, ...);
diff --git a/components/net/at/src/at_cli.c b/components/net/at/src/at_cli.c
index 80af613fa6..e39a913357 100644
--- a/components/net/at/src/at_cli.c
+++ b/components/net/at/src/at_cli.c
@@ -100,6 +100,12 @@ void at_cli_deinit(void)
}
#ifdef AT_USING_SERVER
+static rt_err_t at_server_console_getchar(struct at_server *server, char *ch, rt_int32_t timeout)
+{
+ *ch = console_getchar();
+ return RT_EOK;
+}
+
static void server_cli_parser(void)
{
extern at_server_t at_get_server(void);
@@ -107,7 +113,7 @@ static void server_cli_parser(void)
at_server_t server = at_get_server();
rt_base_t int_lvl;
static rt_device_t device_bak;
- static char (*getchar_bak)(void);
+ static rt_err_t (*getchar_bak)(struct at_server *server, char *ch, rt_int32_t timeout);
static char endmark_back[AT_END_MARK_LEN];
/* backup server device and getchar function */
@@ -122,7 +128,7 @@ static void server_cli_parser(void)
/* setup server device as console device */
server->device = rt_console_get_device();
- server->get_char = console_getchar;
+ server->get_char = at_server_console_getchar;
memset(server->end_mark, 0x00, AT_END_MARK_LEN);
server->end_mark[0] = '\r';
diff --git a/components/net/at/src/at_server.c b/components/net/at/src/at_server.c
index 31f1bec96f..81d00951f5 100644
--- a/components/net/at/src/at_server.c
+++ b/components/net/at/src/at_server.c
@@ -167,6 +167,79 @@ void rt_at_server_print_all_cmd(void)
}
}
+/**
+ * Send data to AT Client by uart device.
+ *
+ * @param server current AT server object
+ * @param buf send data buffer
+ * @param size send fixed data size
+ *
+ * @return >0: send data size
+ * =0: send failed
+ */
+rt_size_t at_server_send(at_server_t server, const char *buf, rt_size_t size)
+{
+ RT_ASSERT(buf);
+
+ if (server == RT_NULL)
+ {
+ LOG_E("input AT Server object is NULL, please create or get AT Server object!");
+ return 0;
+ }
+
+ return rt_device_write(server->device, 0, buf, size);
+}
+
+/**
+ * AT Server receive fixed-length data.
+ *
+ * @param client current AT Server object
+ * @param buf receive data buffer
+ * @param size receive fixed data size
+ * @param timeout receive data timeout (ms)
+ *
+ * @note this function can only be used in execution function of AT commands
+ *
+ * @return >0: receive data size
+ * =0: receive failed
+ */
+rt_size_t at_server_recv(at_server_t server, char *buf, rt_size_t size, rt_int32_t timeout)
+{
+ rt_size_t read_idx = 0;
+ rt_err_t result = RT_EOK;
+ char ch = 0;
+
+ RT_ASSERT(buf);
+
+ if (server == RT_NULL)
+ {
+ LOG_E("input AT Server object is NULL, please create or get AT Server object!");
+ return 0;
+ }
+
+ while (1)
+ {
+ if (read_idx < size)
+ {
+ /* check get data value */
+ result = server->get_char(server, &ch, timeout);
+ if (result != RT_EOK)
+ {
+ LOG_E("AT Server receive failed, uart device get data error.");
+ return 0;
+ }
+
+ buf[read_idx++] = ch;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ return read_idx;
+}
+
at_server_t at_get_server(void)
{
RT_ASSERT(at_server_local);
@@ -339,17 +412,21 @@ static rt_err_t at_cmd_get_name(const char *cmd_buffer, char *cmd_name)
return -RT_ERROR;
}
-static char at_server_gerchar(void)
+static rt_err_t at_server_gerchar(at_server_t server, char *ch, rt_int32_t timeout)
{
- char ch;
+ rt_err_t result = RT_EOK;
- while (rt_device_read(at_server_local->device, 0, &ch, 1) == 0)
+ while (rt_device_read(at_server_local->device, 0, ch, 1) == 0)
{
rt_sem_control(at_server_local->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
- rt_sem_take(at_server_local->rx_notice, RT_WAITING_FOREVER);
+ result = rt_sem_take(at_server_local->rx_notice, rt_tick_from_millisecond(timeout));
+ if (result != RT_EOK)
+ {
+ return result;
+ }
}
- return ch;
+ return result;
}
static void server_parser(at_server_t server)
@@ -365,14 +442,24 @@ static void server_parser(at_server_t server)
RT_ASSERT(server);
RT_ASSERT(server->status != AT_STATUS_UNINITIALIZED);
- while (ESC_KEY != (ch = server->get_char()))
+ while (1)
{
+ server->get_char(server, &ch, RT_WAITING_FOREVER);
+ if (ESC_KEY == ch)
+ {
+ break;
+ }
+
if (server->echo_mode)
{
if (ch == AT_CMD_CR || (ch == AT_CMD_LF && last_ch != AT_CMD_CR))
{
at_server_printf("%c%c", AT_CMD_CR, AT_CMD_LF);
}
+ else if (ch == AT_CMD_LF)
+ {
+ // skip the end sign check
+ }
else if (ch == BACKSPACE_KEY || ch == DELECT_KEY)
{
if (server->cur_recv_len)
diff --git a/components/net/freemodbus/Changelog.txt b/components/net/freemodbus/Changelog.txt
deleted file mode 100644
index 2816ea30f3..0000000000
--- a/components/net/freemodbus/Changelog.txt
+++ /dev/null
@@ -1,329 +0,0 @@
-2013-10-17 (REL_1_6_0) Armink <[email protected]>
- Notes: Added modbus master.
-
-2010-05-06 (REL_1_5_0) Christian Walter <[email protected]>
- Notes: Added support for Atmel AT91SAM3S (Cortex M3) for IAR.
-
- Detailed notes:
- - FEATURES (ATSAM3S) : Added new port.
-
-2007-08-28 (REL_1_4_0) Christian Walter <[email protected]>:
- Notes: Added support for HCS08. Fixed some small bugs in the documentation
- for the porting layer.
-
- Detailed notes:
- - FEATURES (HCS08) : Added new port.
- - BUGS (ALL) : Fixed some small bugs in the porting guide.
-
-2007-07-17 (REL_1_3_0) Christian Walter <[email protected]>:
- Notes: Added ARM7/AT91SAM7X port. Added Linux/TCP port from Steven Guo.
-
- Detailed notes:
- - FEATURES (ARM7): Added ARM7/AT91SAM7x port.
- - FEATURES (LINUX): Added Linux/TCP port from Steven Guo.
- - BUGS (ALL): Fixed bug in <eMBFuncReadInputRegister> where the high
- byte of the register count was ignored. This does not have a
- practical impact because the actual number of registers is always
- lower.
-
-2007-07-17 (REL_1_3_0) Christian Walter <[email protected]>:
- Notes: Added Linux/TCP port. Fixed bug in MSP430 port.
- Detailted notes:
- - FEATURE (LINUX): Added Linux/TCP port.
- - BUGS (MSP430): Fixed bug with calculating the timer value.
-
-2007-04-25 (REL_1_2_0) Christian Walter <[email protected]>:
- Notes: Added LPC214X ARM port with Keil compiler. Added Z8Encore port for
- Z8F6422 microcontroller.
-
- Detailed notes:
- - FEATURE (ARM): Added LPC214X ARM port for Keil ARM 2.41.
- - FEATURE (Z8ENCORE): Added Z8F6422 for Z8Encore using the ZDS II - Z8
- Encore! development tools.
-
-2007-02-18 (REL_1_1_2) Christian Walter <[email protected]>:
- Notes: Fixed typo with the defined defining the supported Modbus
- functions. Fixed bug when illegal slave address was passed to eMBInit
- where the error was not detected. Fixed typo in the holding registers
- where the frame for write multiple registers was parsed with the wrong
- constants. The fix is not critical because the values matched. Fixed bug
- in discrete input registers implementation where the frame was not parsed
- correctly. Added new support for a CodeWarrior Coldfire port.
-
- Detailed notes:
- - BUG (ALL): Modbus functions are compiled into the stack conditionally
- by changing the MB_FUNC_XXX defines to either true(1) or false(0).
- The defines for MB_FUNC_READ_HOLDING and MB_FUNC_WRITE_HOLDING
- were wrong.
- - BUG (ALL): eMBInit did not correctly check for addresses. Therefore
- is was possible to start the Modbus stack with an address of 0
- or one > 247.
- - BUG (ALL): eMBFuncWriteHoldingRegister should use
- MB_PDU_FUNC_WRITE_MUL_ADDR_OFF and not MB_PDU_FUNC_READ_ADDR_OFF.
- - BUG (ALL): eMBFuncReadDiscreteInputs calculated the number of discrete
- registers to read wrong.
- - FEATURE (ALL): Fixed some warnings in the code.
-
-2006-11-19 (REL_1_1_1) Christian Walter <[email protected]>:
- Notes: Fixed bug in Read/Write Multiple Registers function where
- the registers addresses where calculated wrong.
- Fixed bug in RTU and ASCII with the resource allocation in case of
- an error.
- Changed license to BSD style licsense.
-
- Detailed notes:
- - OTHER (ALL): License is now BSD for protocol stack.
- - BUG (ALL): The registers address received in a Modbus frame
- must be converted to application addresses. The code for this
- conversion was missing and therefore has lead to error when
- this function was used (Registers of by one, Start at > 1).
- - BUG (ALL): If the serial initialization within the porting fails
- a timer is still allocated in eMBRTUInit and eMBASCIIInit. This
- can lead to a memory leak depending upon the implementation of the
- porting layer.
- - FEATURE (MCF5235): Added sample shell scripts for testing.
- - FEATURE (MSP430): Added sample shell script for testing and
- changed default values to match the other ports.
-
-2006-10-30 (REL_1_1_0) Christian Walter <[email protected]>:
- Notes: Added support for Read/Write Multiple Registers function
- (0x17). Added some tips to reduce memory requirements.
- Added MSP430 Port for GCC and Rowley Crossworks.
-
- Detailed notes:
- - FEATURE (MSP430): Added new MSP430 port.
- - FEATURE (ALL): Added support for Read/Write Multiple Registers
- function (0x17). The implementation simply makes two callbacks
- to the eMBRegHoldingCB function where first the values are
- written and then the other register values are read.
- - FEATURE (ALL): Added some tips on reducing memory requirements
- with the protocol stack.
-
-2006-10-30 (REL_1_0_5) Christian Walter <[email protected]>:
- Notes: eMBDisable and eMBClose can now be called multiple times
- which makes shutdown of the protocol stack easier.
- Fixed bug in RTU state machine where we switched from the
- error state immediately to the idle state. Correct behaviour
- would be to wait till the end of frame.
- Added new STR71X GCC port which uses only freely available tools
- like GNU ARM, OpenOCD (Wiggler) and GDB.
-
- Detailed notes:
- - FEATURE (STR71X): Added GCC standalone port which does not
- depend on the Rowley Crosswork tools.
- - FEATURE (ALL): eMBDisable can now be called multiple times
- and returns MB_ENOERR in case is was already disabled.
- eMBClose also supports beeing called multiple times in
- which pvMBFrameCloseCur( ) is called when the protocol stack
- is in state STATE_DISABLED.
- - BUG (RTU): Fixed bug in xMBRTUReceiveFSM where the error
- state is immediately left because of a missing break. Instead
- we should wait till the damaged frame is finished.
-
-2006-10-11 (REL_1_0_4) Christian Walter <[email protected]>:
- Notes: Fixed bug when more than 255 coils are requested. Fixed bug in
- Linux/Cygwin port when not all bytes could be written by the first
- call to write. Added support for removing previously registered
- function handlers.
-
- Detailed notes:
- - BUG (ALL): mbfunccoils contained a bug which limited the amount
- of coils to read to 255.
- - BUG (LINUX): prvbMBPortSerialWrite contained a bug in the loop
- which writes the RTU/ASCII frame to the serial file descriptor.
- If not all bytes where written in the first call or write was
- interrupted the sent frame is corrupted.
- - FEATURE (ALL): eMBRegisterCB now supports NULL as handler
- argument in which case a previously registered function
- handler is deregistered from the protocol stack.
-
-2006-09-27 (REL_1_0_3) Christian Walter <[email protected]>:
- Notes: Added new functions to support registering of custom callback
- handlers. This makes it possible to implement new Modbus function
- codes without touching the protocol stack.
- New port for ATMega128 added. Thanks to Richard C Sandoz Jr. for
- the patches.
-
- Detailed notes:
- - FEATURE (ALL): Added support for registering new functions handlers
- with eMBRegisterCB.
- - FEATURE (AVR): Added patches from Richard C Sandoz Jr. for ATMega128
-
-2006-09-06 (REL_1_0_2) Christian Walter <[email protected]>:
- Notes: Fixed bug in FreeRTOS porting layer for STR71X/lwIP target where
- memory is not freed in the sys_arch_thread_remove function.
- Synched MCF5235TCP port with the FreeRTOS/lwIP port for the STR71X.
-
- Detailed notes:
- - BUG (STR71XTCP): Sys_arch_thread_remove did not free the memory from
- the TCB.
- - BUG (STR71XTCP): Unnecessary call to vTaskSuspendAll removed.
- - BUG (STR71XTCP): Bug with counting variable. The first to lwIP tasks
- got the same name (lwIP0).
- - FEATURE (MCF5235TCP): Enhanced functions from the STR71X/lwIP port
- merged into the Coldfire port.
-
-2006-09-04 (REL_1_0_1) Christian Walter <[email protected]>:
- Notes: Fixed bug in serial driver for STR71x target when the ring buffer
- overflows.
-
- Detailed notes:
- - BUG (STR71XTCP): Under high load the ring buffer in the serial driver
- functions might overflow. There was an error with counting the number
- of received characters which corrupted received frames.
- Now receiver correctly recovers in case of dropped bytes.
-
-2006-09-04 (REL_1_0) Christian Walter <[email protected]>:
- Notes: Added support for ATmega8, ATmega16, ATmega32, ATmega169 and
- RS485 drivers in the AVR support. Special thanks to Tran Minh Hoang
- for his contribution.
- Added a new lwIP port for the STR71X target which uses one serial
- interface for a PPP connection. This can be used for remote Modbus/TCP
- devices in combination with a Modem (E.g. GPRS or Analog).
-
- Detailed notes:
- - FEATURES (AVR): Integrated patches from Tran Minh Hoang to support the
- ATmega8, ATmega16, ATmega32, ATmega169 controllers.
- - FEATURES (AVR): Added support for RS485 drivers in the AVR code. The
- example supports the DS76176.
- - FEATURES (STR71XTCP): implemented function in STR71X/lwIP porting layer
- to remove running tasks.
- - FEATURES (STR71XTCP): added new thread creation function in STR71X/lwIP
- porting layer which allows specifing the stack size.
- - BUGS (STR71XTCP): pppOpen defined in ppp.c does not check the return
- value of sys_thread_new. If task creation fails the system crashes.
- - BUGS (STR71XTCP): pppMain must not return - Instead it should remove
- its task from the scheduler.
-
-2006-08-30 (REL_9) Christian Walter <[email protected]>:
- Notes: Added lwIP port for the MCF5235 target. The lwIP part is
- generic and therefore FreeModbus now works on any target with
- lwIP support.
-
- Detailed notes:
- - FEATURES: Incoperated MCF5235 FreeRTOS/lwIP port done by the
- author in this project.
- - FEATURES: Added lwIP port for FreeModbus
- - FEATURES: Added demo application for FreeModbus and lwIP.
-
-2006-08-22 (REL_0_82) Christian Walter <[email protected]>
- Notes: Fixed bug with Modbus ASCII support
-
- Detailed notes:
- - BUG: During the last upgrade an error was introduced in the
- initialization code of Modbus ASCII and therefore ASCII
- support was broken. The bug is fixed now and was tested with
- the Win32 port.
-
-2006-08-22 (REL_0_81) Christian Walter <[email protected]>
- Notes: Added porting guide
-
- Detailed notes:
- - OTHER: Added a new porting guide to the documentation.
- - OTHER: Added a empty example for new ports to the project as a
- starting point.
-
-2006-08-01 (REL_0_8) Christian Walter <[email protected]>
- Notes: Added Linux RTU/ASCII port.
-
- Detailed notes:
- - FEATURES: Added a new Linux RTU/ASCII port. The port should work
- on any Linux distribution and it should be possible to run it
- on uCLinux.
-
-2006-06-26 (REL_0_7) Christian Walter <[email protected]>
- Notes: Changed the WIN32 serial port to better fit into the design.
-
- Detailed notes:
- - OTHER: Design of the WIN32 serial port changed. The polling function
- for the serial device are now called from the event loop.
- - OTHER: Debugging uses the same interface as the WIN32/TCP port.
-
-2006-06-25 Christian Walter <[email protected]>
-
- Notes: Initial work on a Modbus/TCP port is available. The port includes
- an example for a Win32 port which uses the Winsock API.
-
- Detailed notes:
- - FEATURES: added required functions to core protocol stack to support
- a Modbus/TCP implementation.
- - FEATURES: added a Win32 port for the Modbus/TCP core. The port is
- currently limited to one concurrent client.
- - OTHER: The implementation of eMBClose to shutdown the protocol stack
- was changed to unify it with the new Modbus/TCP code.
- -
-
-2006-06-18 Christian Walter <[email protected]>
-
- Detailed notes:
- - OTHER: while working on the Win32 port some line feeds got
- wrong. Also some source files used tabs instead of spaces.
- - OTHER: prototypes for xMBUtilSetBits and xMBUtilGetBits fixed.
- usNBits should be ucNBits by convention.
-
-2006-06-17 Christian Walter <[email protected]>
-
- Notes: Fixed various bugs with the Win32 port
-
- Detailed notes:
- - FEATURES: implement shutdown functionality for protocol stack.
- - FEATURES: protocol stack can be enabled and disabled during runtime.
- - FEATURES: interface functions now do more error checking. For
- example if eMBPool is called in an uninitialized state.
- - FEATURES: extended Win32 demo application to use the new features.
- - BUG: fixed bug in Win32 demo for ASCII mode.
-
-2006-06-16 Christian Walter <[email protected]>
- Notes: The new version includes a new port for the
- Win32 platform
-
- Detailed notes:
- - FEATURES: added Win32 platform
-
-2006-05-14 Christian Walter <[email protected]>
- Notes: The new version includes a new port for the
- Freescale MCF5235 processor.
-
- Detailed notes:
- - FEATURES: added new MCF5235 port.
- - OTHER: fixed some missing code headers.
-
-2006-05-01 Christian Walter <[email protected]>
- Notes: This version removes the t1.5 timers from the Modbus RTU
- implementation because no one actually uses it and the CPU
- load is very high. T
- In addition some documentation cleanups has been done and the
- ARM demo has been updated.
-
- Detailed notes:
-
- - FEATURES: the t1.5 timeout has been removed. Therefore only
- one timer is required.
- - BUG: the ARM demo project missed some files in the project
- workspace and did not compile cleanly
-
-2006-02-28 Christian Walter <[email protected]>
- Notes: This version includes support for two new command
- (write multiple coils, read discrete input)
-
- Detailed notes:
- - BUG: some function used the wrong data types
- - FEATURES: added support for write multiple coils function.
- - FEATURES: added support for read discrete input.
- - OTHER: some code cleanups with lint tool.
-
-2006-02-28 Christian Walter <[email protected]>
-
- Notes: The new version 0.31 adds support for reading and writing the
- coil registers and add some bug fixes.
-
- Detailed notes:
- - BUG: fixed bug with to small modbus requests being ignored.
- - FEATURES: added support for write single coil function.
- - FEATURES: added support for working with byte packed bit fields
- to support coils and discrete inputs better.
- - API: API for set slave id functions changed.
-
-2006-02-26 Christian Walter <[email protected]>
-
- Notes: First public release which includes an ARM and AVR port.
diff --git a/components/net/freemodbus/Kconfig b/components/net/freemodbus/Kconfig
deleted file mode 100644
index 9a84efa0c5..0000000000
--- a/components/net/freemodbus/Kconfig
+++ /dev/null
@@ -1,27 +0,0 @@
-menu "Modbus master and slave stack"
-
-config RT_USING_MODBUS
- bool "Enable Modbus stack"
- default n
-
- if RT_USING_MODBUS
- config RT_MODBUS_MASTER_RTU
- bool "RTU master mode"
- default n
-
- config RT_MODBUS_SLAVE_RTU
- bool "RTU slave mode"
- default n
- if RT_MODBUS_SLAVE_RTU
- config RT_MODBUS_SLAVE_USE_CONTROL_PIN
- bool "Use Contorl Pin"
- default n
- if RT_MODBUS_SLAVE_USE_CONTROL_PIN
- config MODBUS_SLAVE_RT_CONTROL_PIN_INDEX
- int "pin index for RS485 TX/RX select"
- default 10
- endif
- endif
- endif
-
-endmenu
diff --git a/components/net/freemodbus/SConscript b/components/net/freemodbus/SConscript
deleted file mode 100644
index d613a9f398..0000000000
--- a/components/net/freemodbus/SConscript
+++ /dev/null
@@ -1,77 +0,0 @@
-Import('RTT_ROOT')
-from building import *
-
-src = Split("""
-modbus/functions/mbfuncdiag.c
-modbus/functions/mbutils.c
-modbus/functions/mbfuncother.c
-modbus/rtu/mbcrc.c
-port/port.c
-""")
-
-master_rtu_src = Split("""
-modbus/functions/mbfunccoils_m.c
-modbus/functions/mbfuncdisc_m.c
-modbus/functions/mbfuncholding_m.c
-modbus/functions/mbfuncinput_m.c
-modbus/rtu/mbrtu_m.c
-modbus/mb_m.c
-port/portevent_m.c
-port/portserial_m.c
-port/porttimer_m.c
-port/user_mb_app_m.c
-""")
-
-slave_rtu_src = Split("""
-modbus/functions/mbfunccoils.c
-modbus/functions/mbfuncdisc.c
-modbus/functions/mbfuncholding.c
-modbus/functions/mbfuncinput.c
-modbus/rtu/mbrtu.c
-modbus/mb.c
-port/portevent.c
-port/portserial.c
-port/porttimer.c
-port/user_mb_app.c
-""")
-
-master_slave_rtu_src = Split("""
-modbus/functions/mbfunccoils.c
-modbus/functions/mbfunccoils_m.c
-modbus/functions/mbfuncdisc.c
-modbus/functions/mbfuncdisc_m.c
-modbus/functions/mbfuncholding.c
-modbus/functions/mbfuncholding_m.c
-modbus/functions/mbfuncinput.c
-modbus/functions/mbfuncinput_m.c
-modbus/rtu/mbrtu.c
-modbus/rtu/mbrtu_m.c
-modbus/mb.c
-modbus/mb_m.c
-port/portevent.c
-port/portevent_m.c
-port/portserial.c
-port/portserial_m.c
-port/porttimer.c
-port/porttimer_m.c
-port/user_mb_app.c
-port/user_mb_app_m.c
-""")
-
-# The set of source files associated with this SConscript file.
-path = [GetCurrentDir() + '/modbus/include',
- GetCurrentDir() + '/modbus/rtu',
- GetCurrentDir() + '/port']
-
-if GetDepend(['RT_MODBUS_MASTER_RTU']):
- src += master_rtu_src
-
-if GetDepend(['RT_MODBUS_SLAVE_RTU']):
- src += slave_rtu_src
-
-if GetDepend(['RT_MODBUS_MASTER_SLAVE_RTU']):
- src += master_slave_rtu_src
-
-group = DefineGroup('FreeModbus', src, depend = ['RT_USING_MODBUS'], CPPPATH = path)
-
-Return('group')
diff --git a/components/net/freemodbus/bsd.txt b/components/net/freemodbus/bsd.txt
deleted file mode 100644
index 362d3e37c8..0000000000
--- a/components/net/freemodbus/bsd.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-Copyright (c) 2006 Christian Walter <[email protected]>
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-3. The name of the author may not be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
diff --git a/components/net/freemodbus/gpl.txt b/components/net/freemodbus/gpl.txt
deleted file mode 100644
index 3912109b5c..0000000000
--- a/components/net/freemodbus/gpl.txt
+++ /dev/null
@@ -1,340 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/components/net/freemodbus/lgpl.txt b/components/net/freemodbus/lgpl.txt
deleted file mode 100644
index 8add30ad59..0000000000
--- a/components/net/freemodbus/lgpl.txt
+++ /dev/null
@@ -1,504 +0,0 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the Lesser GPL. It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
- This license, the Lesser General Public License, applies to some
-specially designated software packages--typically libraries--of the
-Free Software Foundation and other authors who decide to use it. You
-can use it too, but we suggest you first think carefully about whether
-this license or the ordinary General Public License is the better
-strategy to use in any particular case, based on the explanations below.
-
- When we speak of free software, we are referring to freedom of use,
-not price. Our General Public Licenses are designed to make sure that
-you have the freedom to distribute copies of free software (and charge
-for this service if you wish); that you receive source code or can get
-it if you want it; that you can change the software and use pieces of
-it in new free programs; and that you are informed that you can do
-these things.
-
- To protect your rights, we need to make restrictions that forbid
-distributors to deny you these rights or to ask you to surrender these
-rights. These restrictions translate to certain responsibilities for
-you if you distribute copies of the library or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you. You must make sure that they, too, receive or can get the source
-code. If you link other code with the library, you must provide
-complete object files to the recipients, so that they can relink them
-with the library after making changes to the library and recompiling
-it. And you must show them these terms so they know their rights.
-
- We protect your rights with a two-step method: (1) we copyright the
-library, and (2) we offer you this license, which gives you legal
-permission to copy, distribute and/or modify the library.
-
- To protect each distributor, we want to make it very clear that
-there is no warranty for the free library. Also, if the library is
-modified by someone else and passed on, the recipients should know
-that what they have is not the original version, so that the original
-author's reputation will not be affected by problems that might be
-introduced by others.
-
- Finally, software patents pose a constant threat to the existence of
-any free program. We wish to make sure that a company cannot
-effectively restrict the users of a free program by obtaining a
-restrictive license from a patent holder. Therefore, we insist that
-any patent license obtained for a version of the library must be
-consistent with the full freedom of use specified in this license.
-
- Most GNU software, including some libraries, is covered by the
-ordinary GNU General Public License. This license, the GNU Lesser
-General Public License, applies to certain designated libraries, and
-is quite different from the ordinary General Public License. We use
-this license for certain libraries in order to permit linking those
-libraries into non-free programs.
-
- When a program is linked with a library, whether statically or using
-a shared library, the combination of the two is legally speaking a
-combined work, a derivative of the original library. The ordinary
-General Public License therefore permits such linking only if the
-entire combination fits its criteria of freedom. The Lesser General
-Public License permits more lax criteria for linking other code with
-the library.
-
- We call this license the "Lesser" General Public License because it
-does Less to protect the user's freedom than the ordinary General
-Public License. It also provides other free software developers Less
-of an advantage over competing non-free programs. These disadvantages
-are the reason we use the ordinary General Public License for many
-libraries. However, the Lesser license provides advantages in certain
-special circumstances.
-
- For example, on rare occasions, there may be a special need to
-encourage the widest possible use of a certain library, so that it becomes
-a de-facto standard. To achieve this, non-free programs must be
-allowed to use the library. A more frequent case is that a free
-library does the same job as widely used non-free libraries. In this
-case, there is little to gain by limiting the free library to free
-software only, so we use the Lesser General Public License.
-
- In other cases, permission to use a particular library in non-free
-programs enables a greater number of people to use a large body of
-free software. For example, permission to use the GNU C Library in
-non-free programs enables many more people to use the whole GNU
-operating system, as well as its variant, the GNU/Linux operating
-system.
-
- Although the Lesser General Public License is Less protective of the
-users' freedom, it does ensure that the user of a program that is
-linked with the Library has the freedom and the wherewithal to run
-that program using a modified version of the Library.
-
- The precise terms and conditions for copying, distribution and
-modification follow. Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library". The
-former contains code derived from the library, whereas the latter must
-be combined with the library in order to run.
-
- GNU LESSER GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library or other
-program which contains a notice placed by the copyright holder or
-other authorized party saying it may be distributed under the terms of
-this Lesser General Public License (also called "this License").
-Each licensee is addressed as "you".
-
- A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work
-which has been distributed under these terms. A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language. (Hereinafter, translation is
-included without limitation in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for
-making modifications to it. For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
- Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it). Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
- You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-
- 2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices
- stating that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no
- charge to all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a
- table of data to be supplied by an application program that uses
- the facility, other than as an argument passed when the facility
- is invoked, then you must make a good faith effort to ensure that,
- in the event an application does not supply such function or
- table, the facility still operates, and performs whatever part of
- its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has
- a purpose that is entirely well-defined independent of the
- application. Therefore, Subsection 2d requires that any
- application-supplied function or table used by this function must
- be optional: if the application does not supply it, the square
- root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library. To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License. (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.) Do not make any other change in
-these notices.
-
- Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
- If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library". Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
- However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library". The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library. The
-threshold for this to be true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work. (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also combine or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
- You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License. You must supply a copy of this License. If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License. Also, you must do one
-of these things:
-
- a) Accompany the work with the complete corresponding
- machine-readable source code for the Library including whatever
- changes were used in the work (which must be distributed under
- Sections 1 and 2 above); and, if the work is an executable linked
- with the Library, with the complete machine-readable "work that
- uses the Library", as object code and/or source code, so that the
- user can modify the Library and then relink to produce a modified
- executable containing the modified Library. (It is understood
- that the user who changes the contents of definitions files in the
- Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (1) uses at run time a
- copy of the library already present on the user's computer system,
- rather than copying library functions into the executable, and (2)
- will operate properly with a modified version of the library, if
- the user installs one, as long as the modified version is
- interface-compatible with the version that the work was made with.
-
- c) Accompany the work with a written offer, valid for at
- least three years, to give the same user the materials
- specified in Subsection 6a, above, for a charge no more
- than the cost of performing this distribution.
-
- d) If distribution of the work is made by offering access to copy
- from a designated place, offer equivalent access to copy the above
- specified materials from the same place.
-
- e) Verify that the user has already received a copy of these
- materials or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it. However, as a special exception,
-the materials to be distributed need not include anything that is
-normally distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
- It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system. Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-
- 7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
- a) Accompany the combined library with a copy of the same work
- based on the Library, uncombined with any other library
- facilities. This must be distributed under the terms of the
- Sections above.
-
- b) Give prominent notice with the combined library of the fact
- that part of it is a work based on the Library, and explaining
- where to find the accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License. However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Library or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties with
-this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all. For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded. In such case, this License incorporates the limitation as if
-written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new
-versions of the Lesser General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation. If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission. For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this. Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Libraries
-
- If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change. You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
- To apply these terms, attach the following notices to the library. It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
- <one line to give the library's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the
- library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
- <signature of Ty Coon>, 1 April 1990
- Ty Coon, President of Vice
-
-That's all there is to it!
-
-
diff --git a/components/net/freemodbus/modbus/ascii/mbascii.c b/components/net/freemodbus/modbus/ascii/mbascii.c
deleted file mode 100644
index b0f3bc05d2..0000000000
--- a/components/net/freemodbus/modbus/ascii/mbascii.c
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbascii.c,v 1.15 2007/02/18 23:46:48 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbconfig.h"
-#include "mbascii.h"
-#include "mbframe.h"
-
-#include "mbcrc.h"
-#include "mbport.h"
-
-#if MB_SLAVE_ASCII_ENABLED > 0
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_ASCII_DEFAULT_CR '\r' /*!< Default CR character for Modbus ASCII. */
-#define MB_ASCII_DEFAULT_LF '\n' /*!< Default LF character for Modbus ASCII. */
-#define MB_SER_PDU_SIZE_MIN 3 /*!< Minimum size of a Modbus ASCII frame. */
-#define MB_SER_PDU_SIZE_MAX 256 /*!< Maximum size of a Modbus ASCII frame. */
-#define MB_SER_PDU_SIZE_LRC 1 /*!< Size of LRC field in PDU. */
-#define MB_SER_PDU_ADDR_OFF 0 /*!< Offset of slave address in Ser-PDU. */
-#define MB_SER_PDU_PDU_OFF 1 /*!< Offset of Modbus-PDU in Ser-PDU. */
-
-/* ----------------------- Type definitions ---------------------------------*/
-typedef enum
-{
- STATE_RX_IDLE, /*!< Receiver is in idle state. */
- STATE_RX_RCV, /*!< Frame is beeing received. */
- STATE_RX_WAIT_EOF /*!< Wait for End of Frame. */
-} eMBRcvState;
-
-typedef enum
-{
- STATE_TX_IDLE, /*!< Transmitter is in idle state. */
- STATE_TX_START, /*!< Starting transmission (':' sent). */
- STATE_TX_DATA, /*!< Sending of data (Address, Data, LRC). */
- STATE_TX_END, /*!< End of transmission. */
- STATE_TX_NOTIFY /*!< Notify sender that the frame has been sent. */
-} eMBSndState;
-
-typedef enum
-{
- BYTE_HIGH_NIBBLE, /*!< Character for high nibble of byte. */
- BYTE_LOW_NIBBLE /*!< Character for low nibble of byte. */
-} eMBBytePos;
-
-/* ----------------------- Static functions ---------------------------------*/
-static UCHAR prvucMBCHAR2BIN( UCHAR ucCharacter );
-
-static UCHAR prvucMBBIN2CHAR( UCHAR ucByte );
-
-static UCHAR prvucMBLRC( UCHAR * pucFrame, USHORT usLen );
-
-/* ----------------------- Static variables ---------------------------------*/
-static volatile eMBSndState eSndState;
-static volatile eMBRcvState eRcvState;
-
-/* We reuse the Modbus RTU buffer because only one buffer is needed and the
- * RTU buffer is bigger. */
-extern volatile UCHAR ucRTUBuf[];
-static volatile UCHAR *ucASCIIBuf = ucRTUBuf;
-
-static volatile USHORT usRcvBufferPos;
-static volatile eMBBytePos eBytePos;
-
-static volatile UCHAR *pucSndBufferCur;
-static volatile USHORT usSndBufferCount;
-
-static volatile UCHAR ucLRC;
-static volatile UCHAR ucMBLFCharacter;
-
-/* ----------------------- Start implementation -----------------------------*/
-eMBErrorCode
-eMBASCIIInit( UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- ( void )ucSlaveAddress;
-
- ENTER_CRITICAL_SECTION( );
- ucMBLFCharacter = MB_ASCII_DEFAULT_LF;
-
- if( xMBPortSerialInit( ucPort, ulBaudRate, 7, eParity ) != TRUE )
- {
- eStatus = MB_EPORTERR;
- }
- else if( xMBPortTimersInit( MB_ASCII_TIMEOUT_SEC * 20000UL ) != TRUE )
- {
- eStatus = MB_EPORTERR;
- }
-
- EXIT_CRITICAL_SECTION( );
-
- return eStatus;
-}
-
-void
-eMBASCIIStart( void )
-{
- ENTER_CRITICAL_SECTION( );
- vMBPortSerialEnable( TRUE, FALSE );
- eRcvState = STATE_RX_IDLE;
- EXIT_CRITICAL_SECTION( );
-
- /* No special startup required for ASCII. */
- ( void )xMBPortEventPost( EV_READY );
-}
-
-void
-eMBASCIIStop( void )
-{
- ENTER_CRITICAL_SECTION( );
- vMBPortSerialEnable( FALSE, FALSE );
- vMBPortTimersDisable( );
- EXIT_CRITICAL_SECTION( );
-}
-
-eMBErrorCode
-eMBASCIIReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- ENTER_CRITICAL_SECTION( );
- assert( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
-
- /* Length and CRC check */
- if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
- && ( prvucMBLRC( ( UCHAR * ) ucASCIIBuf, usRcvBufferPos ) == 0 ) )
- {
- /* Save the address field. All frames are passed to the upper layed
- * and the decision if a frame is used is done there.
- */
- *pucRcvAddress = ucASCIIBuf[MB_SER_PDU_ADDR_OFF];
-
- /* Total length of Modbus-PDU is Modbus-Serial-Line-PDU minus
- * size of address field and CRC checksum.
- */
- *pusLength = ( USHORT )( usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_LRC );
-
- /* Return the start of the Modbus PDU to the caller. */
- *pucFrame = ( UCHAR * ) & ucASCIIBuf[MB_SER_PDU_PDU_OFF];
- }
- else
- {
- eStatus = MB_EIO;
- }
- EXIT_CRITICAL_SECTION( );
- return eStatus;
-}
-
-eMBErrorCode
-eMBASCIISend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- UCHAR usLRC;
-
- ENTER_CRITICAL_SECTION( );
- /* Check if the receiver is still in idle state. If not we where to
- * slow with processing the received frame and the master sent another
- * frame on the network. We have to abort sending the frame.
- */
- if( eRcvState == STATE_RX_IDLE )
- {
- /* First byte before the Modbus-PDU is the slave address. */
- pucSndBufferCur = ( UCHAR * ) pucFrame - 1;
- usSndBufferCount = 1;
-
- /* Now copy the Modbus-PDU into the Modbus-Serial-Line-PDU. */
- pucSndBufferCur[MB_SER_PDU_ADDR_OFF] = ucSlaveAddress;
- usSndBufferCount += usLength;
-
- /* Calculate LRC checksum for Modbus-Serial-Line-PDU. */
- usLRC = prvucMBLRC( ( UCHAR * ) pucSndBufferCur, usSndBufferCount );
- ucASCIIBuf[usSndBufferCount++] = usLRC;
-
- /* Activate the transmitter. */
- eSndState = STATE_TX_START;
- vMBPortSerialEnable( FALSE, TRUE );
- }
- else
- {
- eStatus = MB_EIO;
- }
- EXIT_CRITICAL_SECTION( );
- return eStatus;
-}
-
-BOOL
-xMBASCIIReceiveFSM( void )
-{
- BOOL xNeedPoll = FALSE;
- UCHAR ucByte;
- UCHAR ucResult;
-
- assert( eSndState == STATE_TX_IDLE );
-
- ( void )xMBPortSerialGetByte( ( CHAR * ) & ucByte );
- switch ( eRcvState )
- {
- /* A new character is received. If the character is a ':' the input
- * buffer is cleared. A CR-character signals the end of the data
- * block. Other characters are part of the data block and their
- * ASCII value is converted back to a binary representation.
- */
- case STATE_RX_RCV:
- /* Enable timer for character timeout. */
- vMBPortTimersEnable( );
- if( ucByte == ':' )
- {
- /* Empty receive buffer. */
- eBytePos = BYTE_HIGH_NIBBLE;
- usRcvBufferPos = 0;
- }
- else if( ucByte == MB_ASCII_DEFAULT_CR )
- {
- eRcvState = STATE_RX_WAIT_EOF;
- }
- else
- {
- ucResult = prvucMBCHAR2BIN( ucByte );
- switch ( eBytePos )
- {
- /* High nibble of the byte comes first. We check for
- * a buffer overflow here. */
- case BYTE_HIGH_NIBBLE:
- if( usRcvBufferPos < MB_SER_PDU_SIZE_MAX )
- {
- ucASCIIBuf[usRcvBufferPos] = ( UCHAR )( ucResult << 4 );
- eBytePos = BYTE_LOW_NIBBLE;
- break;
- }
- else
- {
- /* not handled in Modbus specification but seems
- * a resonable implementation. */
- eRcvState = STATE_RX_IDLE;
- /* Disable previously activated timer because of error state. */
- vMBPortTimersDisable( );
- }
- break;
-
- case BYTE_LOW_NIBBLE:
- ucASCIIBuf[usRcvBufferPos++] |= ucResult;
- eBytePos = BYTE_HIGH_NIBBLE;
- break;
- }
- }
- break;
-
- case STATE_RX_WAIT_EOF:
- if( ucByte == ucMBLFCharacter )
- {
- /* Disable character timeout timer because all characters are
- * received. */
- vMBPortTimersDisable( );
- /* Receiver is again in idle state. */
- eRcvState = STATE_RX_IDLE;
-
- /* Notify the caller of eMBASCIIReceive that a new frame
- * was received. */
- xNeedPoll = xMBPortEventPost( EV_FRAME_RECEIVED );
- }
- else if( ucByte == ':' )
- {
- /* Empty receive buffer and back to receive state. */
- eBytePos = BYTE_HIGH_NIBBLE;
- usRcvBufferPos = 0;
- eRcvState = STATE_RX_RCV;
-
- /* Enable timer for character timeout. */
- vMBPortTimersEnable( );
- }
- else
- {
- /* Frame is not okay. Delete entire frame. */
- eRcvState = STATE_RX_IDLE;
- }
- break;
-
- case STATE_RX_IDLE:
- if( ucByte == ':' )
- {
- /* Enable timer for character timeout. */
- vMBPortTimersEnable( );
- /* Reset the input buffers to store the frame. */
- usRcvBufferPos = 0;;
- eBytePos = BYTE_HIGH_NIBBLE;
- eRcvState = STATE_RX_RCV;
- }
- break;
- }
-
- return xNeedPoll;
-}
-
-BOOL
-xMBASCIITransmitFSM( void )
-{
- BOOL xNeedPoll = FALSE;
- UCHAR ucByte;
-
- assert( eRcvState == STATE_RX_IDLE );
- switch ( eSndState )
- {
- /* Start of transmission. The start of a frame is defined by sending
- * the character ':'. */
- case STATE_TX_START:
- ucByte = ':';
- xMBPortSerialPutByte( ( CHAR )ucByte );
- eSndState = STATE_TX_DATA;
- eBytePos = BYTE_HIGH_NIBBLE;
- break;
-
- /* Send the data block. Each data byte is encoded as a character hex
- * stream with the high nibble sent first and the low nibble sent
- * last. If all data bytes are exhausted we send a '\r' character
- * to end the transmission. */
- case STATE_TX_DATA:
- if( usSndBufferCount > 0 )
- {
- switch ( eBytePos )
- {
- case BYTE_HIGH_NIBBLE:
- ucByte = prvucMBBIN2CHAR( ( UCHAR )( *pucSndBufferCur >> 4 ) );
- xMBPortSerialPutByte( ( CHAR ) ucByte );
- eBytePos = BYTE_LOW_NIBBLE;
- break;
-
- case BYTE_LOW_NIBBLE:
- ucByte = prvucMBBIN2CHAR( ( UCHAR )( *pucSndBufferCur & 0x0F ) );
- xMBPortSerialPutByte( ( CHAR )ucByte );
- pucSndBufferCur++;
- eBytePos = BYTE_HIGH_NIBBLE;
- usSndBufferCount--;
- break;
- }
- }
- else
- {
- xMBPortSerialPutByte( MB_ASCII_DEFAULT_CR );
- eSndState = STATE_TX_END;
- }
- break;
-
- /* Finish the frame by sending a LF character. */
- case STATE_TX_END:
- xMBPortSerialPutByte( ( CHAR )ucMBLFCharacter );
- /* We need another state to make sure that the CR character has
- * been sent. */
- eSndState = STATE_TX_NOTIFY;
- break;
-
- /* Notify the task which called eMBASCIISend that the frame has
- * been sent. */
- case STATE_TX_NOTIFY:
- eSndState = STATE_TX_IDLE;
- xNeedPoll = xMBPortEventPost( EV_FRAME_SENT );
-
- /* Disable transmitter. This prevents another transmit buffer
- * empty interrupt. */
- vMBPortSerialEnable( TRUE, FALSE );
- eSndState = STATE_TX_IDLE;
- break;
-
- /* We should not get a transmitter event if the transmitter is in
- * idle state. */
- case STATE_TX_IDLE:
- /* enable receiver/disable transmitter. */
- vMBPortSerialEnable( TRUE, FALSE );
- break;
- }
-
- return xNeedPoll;
-}
-
-BOOL
-xMBASCIITimerT1SExpired( void )
-{
- switch ( eRcvState )
- {
- /* If we have a timeout we go back to the idle state and wait for
- * the next frame.
- */
- case STATE_RX_RCV:
- case STATE_RX_WAIT_EOF:
- eRcvState = STATE_RX_IDLE;
- break;
-
- default:
- assert( ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_WAIT_EOF ) );
- break;
- }
- vMBPortTimersDisable( );
-
- /* no context switch required. */
- return FALSE;
-}
-
-
-static UCHAR
-prvucMBCHAR2BIN( UCHAR ucCharacter )
-{
- if( ( ucCharacter >= '0' ) && ( ucCharacter <= '9' ) )
- {
- return ( UCHAR )( ucCharacter - '0' );
- }
- else if( ( ucCharacter >= 'A' ) && ( ucCharacter <= 'F' ) )
- {
- return ( UCHAR )( ucCharacter - 'A' + 0x0A );
- }
- else
- {
- return 0xFF;
- }
-}
-
-static UCHAR
-prvucMBBIN2CHAR( UCHAR ucByte )
-{
- if( ucByte <= 0x09 )
- {
- return ( UCHAR )( '0' + ucByte );
- }
- else if( ( ucByte >= 0x0A ) && ( ucByte <= 0x0F ) )
- {
- return ( UCHAR )( ucByte - 0x0A + 'A' );
- }
- else
- {
- /* Programming error. */
- assert( 0 );
- }
- return '0';
-}
-
-
-static UCHAR
-prvucMBLRC( UCHAR * pucFrame, USHORT usLen )
-{
- UCHAR ucLRC = 0; /* LRC char initialized */
-
- while( usLen-- )
- {
- ucLRC += *pucFrame++; /* Add buffer byte without carry */
- }
-
- /* Return twos complement */
- ucLRC = ( UCHAR ) ( -( ( CHAR ) ucLRC ) );
- return ucLRC;
-}
-
-#endif
diff --git a/components/net/freemodbus/modbus/ascii/mbascii.h b/components/net/freemodbus/modbus/ascii/mbascii.h
deleted file mode 100644
index cdec83ff00..0000000000
--- a/components/net/freemodbus/modbus/ascii/mbascii.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbascii.h,v 1.8 2006/12/07 22:10:34 wolti Exp $
- */
-
-#ifndef _MB_ASCII_H
-#define _MB_ASCII_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-
-#if MB_SLAVE_ASCII_ENABLED > 0
-eMBErrorCode eMBASCIIInit( UCHAR slaveAddress, UCHAR ucPort,
- ULONG ulBaudRate, eMBParity eParity );
-void eMBASCIIStart( void );
-void eMBASCIIStop( void );
-
-eMBErrorCode eMBASCIIReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame,
- USHORT * pusLength );
-eMBErrorCode eMBASCIISend( UCHAR slaveAddress, const UCHAR * pucFrame,
- USHORT usLength );
-BOOL xMBASCIIReceiveFSM( void );
-BOOL xMBASCIITransmitFSM( void );
-BOOL xMBASCIITimerT1SExpired( void );
-#endif
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbfunccoils.c b/components/net/freemodbus/modbus/functions/mbfunccoils.c
deleted file mode 100644
index 681bd50656..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfunccoils.c
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfunccoils.c,v 1.8 2007/02/18 23:47:16 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_FUNC_READ_COILCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_COILCNT_MAX ( 0x07D0 )
-
-#define MB_PDU_FUNC_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_FUNC_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_SIZE ( 4 )
-
-#define MB_PDU_FUNC_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_FUNC_WRITE_MUL_COILCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF ( MB_PDU_DATA_OFF + 4 )
-#define MB_PDU_FUNC_WRITE_MUL_VALUES_OFF ( MB_PDU_DATA_OFF + 5 )
-#define MB_PDU_FUNC_WRITE_MUL_SIZE_MIN ( 5 )
-#define MB_PDU_FUNC_WRITE_MUL_COILCNT_MAX ( 0x07B0 )
-
-/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
-
-/* ----------------------- Start implementation -----------------------------*/
-
-#if MB_FUNC_READ_COILS_ENABLED > 0
-
-eMBException
-eMBFuncReadCoils( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- USHORT usCoilCount;
- UCHAR ucNBytes;
- UCHAR *pucFrameCur;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
- usRegAddress++;
-
- usCoilCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_COILCNT_OFF] << 8 );
- usCoilCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_COILCNT_OFF + 1] );
-
- /* Check if the number of registers to read is valid. If not
- * return Modbus illegal data value exception.
- */
- if( ( usCoilCount >= 1 ) &&
- ( usCoilCount < MB_PDU_FUNC_READ_COILCNT_MAX ) )
- {
- /* Set the current PDU data pointer to the beginning. */
- pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
- *usLen = MB_PDU_FUNC_OFF;
-
- /* First byte contains the function code. */
- *pucFrameCur++ = MB_FUNC_READ_COILS;
- *usLen += 1;
-
- /* Test if the quantity of coils is a multiple of 8. If not last
- * byte is only partially field with unused coils set to zero. */
- if( ( usCoilCount & 0x0007 ) != 0 )
- {
- ucNBytes = ( UCHAR )( usCoilCount / 8 + 1 );
- }
- else
- {
- ucNBytes = ( UCHAR )( usCoilCount / 8 );
- }
- *pucFrameCur++ = ucNBytes;
- *usLen += 1;
-
- eRegStatus =
- eMBRegCoilsCB( pucFrameCur, usRegAddress, usCoilCount,
- MB_REG_READ );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- else
- {
- /* The response contains the function code, the starting address
- * and the quantity of registers. We reuse the old values in the
- * buffer because they are still valid. */
- *usLen += ucNBytes;;
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid read coil register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-#endif
-
-#if MB_FUNC_WRITE_COIL_ENABLED > 0
-eMBException
-eMBFuncWriteCoil( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- UCHAR ucBuf[2];
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen == ( MB_PDU_FUNC_WRITE_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1] );
- usRegAddress++;
-
- if( ( pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF + 1] == 0x00 ) &&
- ( ( pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF] == 0xFF ) ||
- ( pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF] == 0x00 ) ) )
- {
- ucBuf[1] = 0;
- if( pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF] == 0xFF )
- {
- ucBuf[0] = 1;
- }
- else
- {
- ucBuf[0] = 0;
- }
- eRegStatus =
- eMBRegCoilsCB( &ucBuf[0], usRegAddress, 1, MB_REG_WRITE );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid write coil register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
-
-#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
-eMBException
-eMBFuncWriteMultipleCoils( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- USHORT usCoilCnt;
- UCHAR ucByteCount;
- UCHAR ucByteCountVerify;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen > ( MB_PDU_FUNC_WRITE_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF + 1] );
- usRegAddress++;
-
- usCoilCnt = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_COILCNT_OFF] << 8 );
- usCoilCnt |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_COILCNT_OFF + 1] );
-
- ucByteCount = pucFrame[MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF];
-
- /* Compute the number of expected bytes in the request. */
- if( ( usCoilCnt & 0x0007 ) != 0 )
- {
- ucByteCountVerify = ( UCHAR )( usCoilCnt / 8 + 1 );
- }
- else
- {
- ucByteCountVerify = ( UCHAR )( usCoilCnt / 8 );
- }
-
- if( ( usCoilCnt >= 1 ) &&
- ( usCoilCnt <= MB_PDU_FUNC_WRITE_MUL_COILCNT_MAX ) &&
- ( ucByteCountVerify == ucByteCount ) )
- {
- eRegStatus =
- eMBRegCoilsCB( &pucFrame[MB_PDU_FUNC_WRITE_MUL_VALUES_OFF],
- usRegAddress, usCoilCnt, MB_REG_WRITE );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- else
- {
- /* The response contains the function code, the starting address
- * and the quantity of registers. We reuse the old values in the
- * buffer because they are still valid. */
- *usLen = MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF;
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid write coil register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbfunccoils_m.c b/components/net/freemodbus/modbus/functions/mbfunccoils_m.c
deleted file mode 100644
index 93801de06f..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfunccoils_m.c
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (C) 2013 Armink <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfunccoils_m.c,v 1.60 2013/10/12 15:10:12 Armink Add Master Functions
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mb_m.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_REQ_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_REQ_READ_COILCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_COILCNT_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
-#define MB_PDU_FUNC_READ_SIZE_MIN ( 1 )
-
-#define MB_PDU_REQ_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_REQ_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_WRITE_SIZE ( 4 )
-#define MB_PDU_FUNC_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_FUNC_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_SIZE ( 4 )
-
-#define MB_PDU_REQ_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_REQ_WRITE_MUL_COILCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF ( MB_PDU_DATA_OFF + 4 )
-#define MB_PDU_REQ_WRITE_MUL_VALUES_OFF ( MB_PDU_DATA_OFF + 5 )
-#define MB_PDU_REQ_WRITE_MUL_SIZE_MIN ( 5 )
-#define MB_PDU_REQ_WRITE_MUL_COILCNT_MAX ( 0x07B0 )
-#define MB_PDU_FUNC_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_FUNC_WRITE_MUL_COILCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_MUL_SIZE ( 5 )
-
-/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
-
-/* ----------------------- Start implementation -----------------------------*/
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-#if MB_FUNC_READ_COILS_ENABLED > 0
-
-/**
- * This function will request read coil.
- *
- * @param ucSndAddr salve address
- * @param usCoilAddr coil start address
- * @param usNCoils coil total number
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- */
-eMBMasterReqErrCode
-eMBMasterReqReadCoils( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usNCoils ,LONG lTimeOut )
-{
- UCHAR *ucMBFrame;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_COILS;
- ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] = usCoilAddr >> 8;
- ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] = usCoilAddr;
- ucMBFrame[MB_PDU_REQ_READ_COILCNT_OFF ] = usNCoils >> 8;
- ucMBFrame[MB_PDU_REQ_READ_COILCNT_OFF + 1] = usNCoils;
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READ_SIZE );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
-
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncReadCoils( UCHAR * pucFrame, USHORT * usLen )
-{
- UCHAR *ucMBFrame;
- USHORT usRegAddress;
- USHORT usCoilCount;
- UCHAR ucByteCount;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- /* If this request is broadcast, and it's read mode. This request don't need execute. */
- if ( xMBMasterRequestIsBroadcast() )
- {
- eStatus = MB_EX_NONE;
- }
- else if ( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READ_SIZE_MIN )
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] );
- usRegAddress++;
-
- usCoilCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_COILCNT_OFF] << 8 );
- usCoilCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_COILCNT_OFF + 1] );
-
- /* Test if the quantity of coils is a multiple of 8. If not last
- * byte is only partially field with unused coils set to zero. */
- if( ( usCoilCount & 0x0007 ) != 0 )
- {
- ucByteCount = ( UCHAR )( usCoilCount / 8 + 1 );
- }
- else
- {
- ucByteCount = ( UCHAR )( usCoilCount / 8 );
- }
-
- /* Check if the number of registers to read is valid. If not
- * return Modbus illegal data value exception.
- */
- if( ( usCoilCount >= 1 ) &&
- ( ucByteCount == pucFrame[MB_PDU_FUNC_READ_COILCNT_OFF] ) )
- {
- /* Make callback to fill the buffer. */
- eRegStatus = eMBMasterRegCoilsCB( &pucFrame[MB_PDU_FUNC_READ_VALUES_OFF], usRegAddress, usCoilCount, MB_REG_READ );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid read coil register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-#endif
-
-#if MB_FUNC_WRITE_COIL_ENABLED > 0
-
-/**
- * This function will request write one coil.
- *
- * @param ucSndAddr salve address
- * @param usCoilAddr coil start address
- * @param usCoilData data to be written
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- *
- * @see eMBMasterReqWriteMultipleCoils
- */
-eMBMasterReqErrCode
-eMBMasterReqWriteCoil( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usCoilData, LONG lTimeOut )
-{
- UCHAR *ucMBFrame;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( ( usCoilData != 0xFF00 ) && ( usCoilData != 0x0000 ) ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_SINGLE_COIL;
- ucMBFrame[MB_PDU_REQ_WRITE_ADDR_OFF] = usCoilAddr >> 8;
- ucMBFrame[MB_PDU_REQ_WRITE_ADDR_OFF + 1] = usCoilAddr;
- ucMBFrame[MB_PDU_REQ_WRITE_VALUE_OFF ] = usCoilData >> 8;
- ucMBFrame[MB_PDU_REQ_WRITE_VALUE_OFF + 1] = usCoilData;
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_WRITE_SIZE );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncWriteCoil( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- UCHAR ucBuf[2];
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen == ( MB_PDU_FUNC_WRITE_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1] );
- usRegAddress++;
-
- if( ( pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF + 1] == 0x00 ) &&
- ( ( pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF] == 0xFF ) ||
- ( pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF] == 0x00 ) ) )
- {
- ucBuf[1] = 0;
- if( pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF] == 0xFF )
- {
- ucBuf[0] = 1;
- }
- else
- {
- ucBuf[0] = 0;
- }
- eRegStatus =
- eMBMasterRegCoilsCB( &ucBuf[0], usRegAddress, 1, MB_REG_WRITE );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid write coil register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
-
-#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
-
-/**
- * This function will request write multiple coils.
- *
- * @param ucSndAddr salve address
- * @param usCoilAddr coil start address
- * @param usNCoils coil total number
- * @param usCoilData data to be written
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- *
- * @see eMBMasterReqWriteCoil
- */
-eMBMasterReqErrCode
-eMBMasterReqWriteMultipleCoils( UCHAR ucSndAddr,
- USHORT usCoilAddr, USHORT usNCoils, UCHAR * pucDataBuffer, LONG lTimeOut)
-{
- UCHAR *ucMBFrame;
- USHORT usRegIndex = 0;
- UCHAR ucByteCount;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( usNCoils > MB_PDU_REQ_WRITE_MUL_COILCNT_MAX ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_MULTIPLE_COILS;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF] = usCoilAddr >> 8;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF + 1] = usCoilAddr;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_COILCNT_OFF] = usNCoils >> 8;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_COILCNT_OFF + 1] = usNCoils ;
- if( ( usNCoils & 0x0007 ) != 0 )
- {
- ucByteCount = ( UCHAR )( usNCoils / 8 + 1 );
- }
- else
- {
- ucByteCount = ( UCHAR )( usNCoils / 8 );
- }
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF] = ucByteCount;
- ucMBFrame += MB_PDU_REQ_WRITE_MUL_VALUES_OFF;
- while( ucByteCount > usRegIndex)
- {
- *ucMBFrame++ = pucDataBuffer[usRegIndex++];
- }
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_WRITE_MUL_SIZE_MIN + ucByteCount );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncWriteMultipleCoils( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- USHORT usCoilCnt;
- UCHAR ucByteCount;
- UCHAR ucByteCountVerify;
- UCHAR *ucMBFrame;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- /* If this request is broadcast, the *usLen is not need check. */
- if( ( *usLen == MB_PDU_FUNC_WRITE_MUL_SIZE ) || xMBMasterRequestIsBroadcast() )
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF + 1] );
- usRegAddress++;
-
- usCoilCnt = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_COILCNT_OFF] << 8 );
- usCoilCnt |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_COILCNT_OFF + 1] );
-
- ucByteCount = ucMBFrame[MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF];
-
- /* Compute the number of expected bytes in the request. */
- if( ( usCoilCnt & 0x0007 ) != 0 )
- {
- ucByteCountVerify = ( UCHAR )( usCoilCnt / 8 + 1 );
- }
- else
- {
- ucByteCountVerify = ( UCHAR )( usCoilCnt / 8 );
- }
-
- if( ( usCoilCnt >= 1 ) && ( ucByteCountVerify == ucByteCount ) )
- {
- eRegStatus =
- eMBMasterRegCoilsCB( &ucMBFrame[MB_PDU_REQ_WRITE_MUL_VALUES_OFF],
- usRegAddress, usCoilCnt, MB_REG_WRITE );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid write coil register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbfuncdiag.c b/components/net/freemodbus/modbus/functions/mbfuncdiag.c
deleted file mode 100644
index d75ffc0f72..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfuncdiag.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfuncdiag.c,v 1.3 2006/12/07 22:10:34 wolti Exp $
- */
diff --git a/components/net/freemodbus/modbus/functions/mbfuncdisc.c b/components/net/freemodbus/modbus/functions/mbfuncdisc.c
deleted file mode 100644
index fb378441b9..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfuncdisc.c
+++ /dev/null
@@ -1,125 +0,0 @@
- /*
- * FreeRTOS Modbus Libary: A Modbus serial implementation for FreeRTOS
- * Copyright (C) 2006 Christian Walter <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_FUNC_READ_DISCCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_DISCCNT_MAX ( 0x07D0 )
-
-/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
-
-/* ----------------------- Start implementation -----------------------------*/
-
-#if MB_FUNC_READ_COILS_ENABLED > 0
-
-eMBException
-eMBFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- USHORT usDiscreteCnt;
- UCHAR ucNBytes;
- UCHAR *pucFrameCur;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
- usRegAddress++;
-
- usDiscreteCnt = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF] << 8 );
- usDiscreteCnt |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF + 1] );
-
- /* Check if the number of registers to read is valid. If not
- * return Modbus illegal data value exception.
- */
- if( ( usDiscreteCnt >= 1 ) &&
- ( usDiscreteCnt < MB_PDU_FUNC_READ_DISCCNT_MAX ) )
- {
- /* Set the current PDU data pointer to the beginning. */
- pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
- *usLen = MB_PDU_FUNC_OFF;
-
- /* First byte contains the function code. */
- *pucFrameCur++ = MB_FUNC_READ_DISCRETE_INPUTS;
- *usLen += 1;
-
- /* Test if the quantity of coils is a multiple of 8. If not last
- * byte is only partially field with unused coils set to zero. */
- if( ( usDiscreteCnt & 0x0007 ) != 0 )
- {
- ucNBytes = ( UCHAR ) ( usDiscreteCnt / 8 + 1 );
- }
- else
- {
- ucNBytes = ( UCHAR ) ( usDiscreteCnt / 8 );
- }
- *pucFrameCur++ = ucNBytes;
- *usLen += 1;
-
- eRegStatus =
- eMBRegDiscreteCB( pucFrameCur, usRegAddress, usDiscreteCnt );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- else
- {
- /* The response contains the function code, the starting address
- * and the quantity of registers. We reuse the old values in the
- * buffer because they are still valid. */
- *usLen += ucNBytes;;
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid read coil register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbfuncdisc_m.c b/components/net/freemodbus/modbus/functions/mbfuncdisc_m.c
deleted file mode 100644
index 6c8d6c4741..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfuncdisc_m.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (C) 2013 Armink <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfuncdisc_m.c,v 1.60 2013/10/15 8:48:20 Armink Add Master Functions Exp $
- */
-
-
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mb_m.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_REQ_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_REQ_READ_DISCCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_DISCCNT_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
-#define MB_PDU_FUNC_READ_SIZE_MIN ( 1 )
-
-/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
-
-/* ----------------------- Start implementation -----------------------------*/
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
-
-/**
- * This function will request read discrete inputs.
- *
- * @param ucSndAddr salve address
- * @param usDiscreteAddr discrete start address
- * @param usNDiscreteIn discrete total number
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- */
-eMBMasterReqErrCode
-eMBMasterReqReadDiscreteInputs( UCHAR ucSndAddr, USHORT usDiscreteAddr, USHORT usNDiscreteIn, LONG lTimeOut )
-{
- UCHAR *ucMBFrame;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_DISCRETE_INPUTS;
- ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] = usDiscreteAddr >> 8;
- ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] = usDiscreteAddr;
- ucMBFrame[MB_PDU_REQ_READ_DISCCNT_OFF ] = usNDiscreteIn >> 8;
- ucMBFrame[MB_PDU_REQ_READ_DISCCNT_OFF + 1] = usNDiscreteIn;
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READ_SIZE );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- USHORT usDiscreteCnt;
- UCHAR ucNBytes;
- UCHAR *ucMBFrame;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- /* If this request is broadcast, and it's read mode. This request don't need execute. */
- if ( xMBMasterRequestIsBroadcast() )
- {
- eStatus = MB_EX_NONE;
- }
- else if( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READ_SIZE_MIN )
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] );
- usRegAddress++;
-
- usDiscreteCnt = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_DISCCNT_OFF] << 8 );
- usDiscreteCnt |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_DISCCNT_OFF + 1] );
-
- /* Test if the quantity of coils is a multiple of 8. If not last
- * byte is only partially field with unused coils set to zero. */
- if( ( usDiscreteCnt & 0x0007 ) != 0 )
- {
- ucNBytes = ( UCHAR )( usDiscreteCnt / 8 + 1 );
- }
- else
- {
- ucNBytes = ( UCHAR )( usDiscreteCnt / 8 );
- }
-
- /* Check if the number of registers to read is valid. If not
- * return Modbus illegal data value exception.
- */
- if ((usDiscreteCnt >= 1) && ucNBytes == pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF])
- {
- /* Make callback to fill the buffer. */
- eRegStatus = eMBMasterRegDiscreteCB( &pucFrame[MB_PDU_FUNC_READ_VALUES_OFF], usRegAddress, usDiscreteCnt );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid read coil register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbfuncholding.c b/components/net/freemodbus/modbus/functions/mbfuncholding.c
deleted file mode 100644
index 7921302f96..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfuncholding.c
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfuncholding.c,v 1.12 2007/02/18 23:48:22 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0)
-#define MB_PDU_FUNC_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_REGCNT_MAX ( 0x007D )
-
-#define MB_PDU_FUNC_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 0)
-#define MB_PDU_FUNC_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_SIZE ( 4 )
-
-#define MB_PDU_FUNC_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF ( MB_PDU_DATA_OFF + 4 )
-#define MB_PDU_FUNC_WRITE_MUL_VALUES_OFF ( MB_PDU_DATA_OFF + 5 )
-#define MB_PDU_FUNC_WRITE_MUL_SIZE_MIN ( 5 )
-#define MB_PDU_FUNC_WRITE_MUL_REGCNT_MAX ( 0x0078 )
-
-#define MB_PDU_FUNC_READWRITE_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 4 )
-#define MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF ( MB_PDU_DATA_OFF + 6 )
-#define MB_PDU_FUNC_READWRITE_BYTECNT_OFF ( MB_PDU_DATA_OFF + 8 )
-#define MB_PDU_FUNC_READWRITE_WRITE_VALUES_OFF ( MB_PDU_DATA_OFF + 9 )
-#define MB_PDU_FUNC_READWRITE_SIZE_MIN ( 9 )
-
-/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
-
-/* ----------------------- Start implementation -----------------------------*/
-
-#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
-
-eMBException
-eMBFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen == ( MB_PDU_FUNC_WRITE_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1] );
- usRegAddress++;
-
- /* Make callback to update the value. */
- eRegStatus = eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF],
- usRegAddress, 1, MB_REG_WRITE );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- /* Can't be a valid request because the length is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-#endif
-
-#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
-eMBException
-eMBFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- USHORT usRegCount;
- UCHAR ucRegByteCount;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen >= ( MB_PDU_FUNC_WRITE_MUL_SIZE_MIN + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_ADDR_OFF + 1] );
- usRegAddress++;
-
- usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF] << 8 );
- usRegCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF + 1] );
-
- ucRegByteCount = pucFrame[MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF];
-
- if( ( usRegCount >= 1 ) &&
- ( usRegCount <= MB_PDU_FUNC_WRITE_MUL_REGCNT_MAX ) &&
- ( ucRegByteCount == ( UCHAR ) ( 2 * usRegCount ) ) )
- {
- /* Make callback to update the register values. */
- eRegStatus =
- eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_WRITE_MUL_VALUES_OFF],
- usRegAddress, usRegCount, MB_REG_WRITE );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- else
- {
- /* The response contains the function code, the starting
- * address and the quantity of registers. We reuse the
- * old values in the buffer because they are still valid.
- */
- *usLen = MB_PDU_FUNC_WRITE_MUL_BYTECNT_OFF;
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid request because the length is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-#endif
-
-#if MB_FUNC_READ_HOLDING_ENABLED > 0
-
-eMBException
-eMBFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- USHORT usRegCount;
- UCHAR *pucFrameCur;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
- usRegAddress++;
-
- usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 );
- usRegCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] );
-
- /* Check if the number of registers to read is valid. If not
- * return Modbus illegal data value exception.
- */
- if( ( usRegCount >= 1 ) && ( usRegCount <= MB_PDU_FUNC_READ_REGCNT_MAX ) )
- {
- /* Set the current PDU data pointer to the beginning. */
- pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
- *usLen = MB_PDU_FUNC_OFF;
-
- /* First byte contains the function code. */
- *pucFrameCur++ = MB_FUNC_READ_HOLDING_REGISTER;
- *usLen += 1;
-
- /* Second byte in the response contain the number of bytes. */
- *pucFrameCur++ = ( UCHAR ) ( usRegCount * 2 );
- *usLen += 1;
-
- /* Make callback to fill the buffer. */
- eRegStatus = eMBRegHoldingCB( pucFrameCur, usRegAddress, usRegCount, MB_REG_READ );
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- else
- {
- *usLen += usRegCount * 2;
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid request because the length is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
-
-#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
-
-eMBException
-eMBFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegReadAddress;
- USHORT usRegReadCount;
- USHORT usRegWriteAddress;
- USHORT usRegWriteCount;
- UCHAR ucRegWriteByteCount;
- UCHAR *pucFrameCur;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen >= ( MB_PDU_FUNC_READWRITE_SIZE_MIN + MB_PDU_SIZE_MIN ) )
- {
- usRegReadAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF] << 8U );
- usRegReadAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READWRITE_READ_ADDR_OFF + 1] );
- usRegReadAddress++;
-
- usRegReadCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF] << 8U );
- usRegReadCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READWRITE_READ_REGCNT_OFF + 1] );
-
- usRegWriteAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF] << 8U );
- usRegWriteAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_ADDR_OFF + 1] );
- usRegWriteAddress++;
-
- usRegWriteCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF] << 8U );
- usRegWriteCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READWRITE_WRITE_REGCNT_OFF + 1] );
-
- ucRegWriteByteCount = pucFrame[MB_PDU_FUNC_READWRITE_BYTECNT_OFF];
-
- if( ( usRegReadCount >= 1 ) && ( usRegReadCount <= 0x7D ) &&
- ( usRegWriteCount >= 1 ) && ( usRegWriteCount <= 0x79 ) &&
- ( ( 2 * usRegWriteCount ) == ucRegWriteByteCount ) )
- {
- /* Make callback to update the register values. */
- eRegStatus = eMBRegHoldingCB( &pucFrame[MB_PDU_FUNC_READWRITE_WRITE_VALUES_OFF],
- usRegWriteAddress, usRegWriteCount, MB_REG_WRITE );
-
- if( eRegStatus == MB_ENOERR )
- {
- /* Set the current PDU data pointer to the beginning. */
- pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
- *usLen = MB_PDU_FUNC_OFF;
-
- /* First byte contains the function code. */
- *pucFrameCur++ = MB_FUNC_READWRITE_MULTIPLE_REGISTERS;
- *usLen += 1;
-
- /* Second byte in the response contain the number of bytes. */
- *pucFrameCur++ = ( UCHAR ) ( usRegReadCount * 2 );
- *usLen += 1;
-
- /* Make the read callback. */
- eRegStatus =
- eMBRegHoldingCB( pucFrameCur, usRegReadAddress, usRegReadCount, MB_REG_READ );
- if( eRegStatus == MB_ENOERR )
- {
- *usLen += 2 * usRegReadCount;
- }
- }
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- return eStatus;
-}
-
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbfuncholding_m.c b/components/net/freemodbus/modbus/functions/mbfuncholding_m.c
deleted file mode 100644
index e1fe69e383..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfuncholding_m.c
+++ /dev/null
@@ -1,455 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (C) 2013 Armink <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfuncholding_m.c,v 1.60 2013/09/02 14:13:40 Armink Add Master Functions Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mb_m.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_REQ_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_REQ_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_REGCNT_MAX ( 0x007D )
-#define MB_PDU_FUNC_READ_BYTECNT_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
-#define MB_PDU_FUNC_READ_SIZE_MIN ( 1 )
-
-#define MB_PDU_REQ_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 0)
-#define MB_PDU_REQ_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_WRITE_SIZE ( 4 )
-#define MB_PDU_FUNC_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 0)
-#define MB_PDU_FUNC_WRITE_VALUE_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_SIZE ( 4 )
-
-#define MB_PDU_REQ_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_REQ_WRITE_MUL_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF ( MB_PDU_DATA_OFF + 4 )
-#define MB_PDU_REQ_WRITE_MUL_VALUES_OFF ( MB_PDU_DATA_OFF + 5 )
-#define MB_PDU_REQ_WRITE_MUL_SIZE_MIN ( 5 )
-#define MB_PDU_REQ_WRITE_MUL_REGCNT_MAX ( 0x0078 )
-#define MB_PDU_FUNC_WRITE_MUL_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_WRITE_MUL_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_WRITE_MUL_SIZE ( 4 )
-
-#define MB_PDU_REQ_READWRITE_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_REQ_READWRITE_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF ( MB_PDU_DATA_OFF + 4 )
-#define MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF ( MB_PDU_DATA_OFF + 6 )
-#define MB_PDU_REQ_READWRITE_WRITE_BYTECNT_OFF ( MB_PDU_DATA_OFF + 8 )
-#define MB_PDU_REQ_READWRITE_WRITE_VALUES_OFF ( MB_PDU_DATA_OFF + 9 )
-#define MB_PDU_REQ_READWRITE_SIZE_MIN ( 9 )
-#define MB_PDU_FUNC_READWRITE_READ_BYTECNT_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_READWRITE_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
-#define MB_PDU_FUNC_READWRITE_SIZE_MIN ( 1 )
-
-/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
-
-/* ----------------------- Start implementation -----------------------------*/
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
-
-/**
- * This function will request write holding register.
- *
- * @param ucSndAddr salve address
- * @param usRegAddr register start address
- * @param usRegData register data to be written
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- */
-eMBMasterReqErrCode
-eMBMasterReqWriteHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usRegData, LONG lTimeOut )
-{
- UCHAR *ucMBFrame;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_REGISTER;
- ucMBFrame[MB_PDU_REQ_WRITE_ADDR_OFF] = usRegAddr >> 8;
- ucMBFrame[MB_PDU_REQ_WRITE_ADDR_OFF + 1] = usRegAddr;
- ucMBFrame[MB_PDU_REQ_WRITE_VALUE_OFF] = usRegData >> 8;
- ucMBFrame[MB_PDU_REQ_WRITE_VALUE_OFF + 1] = usRegData ;
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_WRITE_SIZE );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen == ( MB_PDU_SIZE_MIN + MB_PDU_FUNC_WRITE_SIZE ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_WRITE_ADDR_OFF + 1] );
- usRegAddress++;
-
- /* Make callback to update the value. */
- eRegStatus = eMBMasterRegHoldingCB( &pucFrame[MB_PDU_FUNC_WRITE_VALUE_OFF],
- usRegAddress, 1, MB_REG_WRITE );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- /* Can't be a valid request because the length is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-#endif
-
-#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
-
-/**
- * This function will request write multiple holding register.
- *
- * @param ucSndAddr salve address
- * @param usRegAddr register start address
- * @param usNRegs register total number
- * @param pusDataBuffer data to be written
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- */
-eMBMasterReqErrCode
-eMBMasterReqWriteMultipleHoldingRegister( UCHAR ucSndAddr,
- USHORT usRegAddr, USHORT usNRegs, USHORT * pusDataBuffer, LONG lTimeOut )
-{
- UCHAR *ucMBFrame;
- USHORT usRegIndex = 0;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_WRITE_MULTIPLE_REGISTERS;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF] = usRegAddr >> 8;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF + 1] = usRegAddr;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_REGCNT_OFF] = usNRegs >> 8;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_REGCNT_OFF + 1] = usNRegs ;
- ucMBFrame[MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF] = usNRegs * 2;
- ucMBFrame += MB_PDU_REQ_WRITE_MUL_VALUES_OFF;
- while( usNRegs > usRegIndex)
- {
- *ucMBFrame++ = pusDataBuffer[usRegIndex] >> 8;
- *ucMBFrame++ = pusDataBuffer[usRegIndex++] ;
- }
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_WRITE_MUL_SIZE_MIN + 2*usNRegs );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- UCHAR *ucMBFrame;
- USHORT usRegAddress;
- USHORT usRegCount;
- UCHAR ucRegByteCount;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- /* If this request is broadcast, the *usLen is not need check. */
- if( ( *usLen == MB_PDU_SIZE_MIN + MB_PDU_FUNC_WRITE_MUL_SIZE ) || xMBMasterRequestIsBroadcast() )
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_WRITE_MUL_ADDR_OFF + 1] );
- usRegAddress++;
-
- usRegCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_WRITE_MUL_REGCNT_OFF] << 8 );
- usRegCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_WRITE_MUL_REGCNT_OFF + 1] );
-
- ucRegByteCount = ucMBFrame[MB_PDU_REQ_WRITE_MUL_BYTECNT_OFF];
-
- if( ucRegByteCount == 2 * usRegCount )
- {
- /* Make callback to update the register values. */
- eRegStatus =
- eMBMasterRegHoldingCB( &ucMBFrame[MB_PDU_REQ_WRITE_MUL_VALUES_OFF],
- usRegAddress, usRegCount, MB_REG_WRITE );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid request because the length is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-#endif
-
-#if MB_FUNC_READ_HOLDING_ENABLED > 0
-
-/**
- * This function will request read holding register.
- *
- * @param ucSndAddr salve address
- * @param usRegAddr register start address
- * @param usNRegs register total number
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- */
-eMBMasterReqErrCode
-eMBMasterReqReadHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usNRegs, LONG lTimeOut )
-{
- UCHAR *ucMBFrame;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_HOLDING_REGISTER;
- ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] = usRegAddr >> 8;
- ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] = usRegAddr;
- ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF] = usNRegs >> 8;
- ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF + 1] = usNRegs;
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READ_SIZE );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- UCHAR *ucMBFrame;
- USHORT usRegAddress;
- USHORT usRegCount;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- /* If this request is broadcast, and it's read mode. This request don't need execute. */
- if ( xMBMasterRequestIsBroadcast() )
- {
- eStatus = MB_EX_NONE;
- }
- else if( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READ_SIZE_MIN )
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] );
- usRegAddress++;
-
- usRegCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF] << 8 );
- usRegCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF + 1] );
-
- /* Check if the number of registers to read is valid. If not
- * return Modbus illegal data value exception.
- */
- if( ( usRegCount >= 1 ) && ( 2 * usRegCount == pucFrame[MB_PDU_FUNC_READ_BYTECNT_OFF] ) )
- {
- /* Make callback to fill the buffer. */
- eRegStatus = eMBMasterRegHoldingCB( &pucFrame[MB_PDU_FUNC_READ_VALUES_OFF], usRegAddress, usRegCount, MB_REG_READ );
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid request because the length is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
-
-#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
-
-/**
- * This function will request read and write holding register.
- *
- * @param ucSndAddr salve address
- * @param usReadRegAddr read register start address
- * @param usNReadRegs read register total number
- * @param pusDataBuffer data to be written
- * @param usWriteRegAddr write register start address
- * @param usNWriteRegs write register total number
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- */
-eMBMasterReqErrCode
-eMBMasterReqReadWriteMultipleHoldingRegister( UCHAR ucSndAddr,
- USHORT usReadRegAddr, USHORT usNReadRegs, USHORT * pusDataBuffer,
- USHORT usWriteRegAddr, USHORT usNWriteRegs, LONG lTimeOut )
-{
- UCHAR *ucMBFrame;
- USHORT usRegIndex = 0;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READWRITE_MULTIPLE_REGISTERS;
- ucMBFrame[MB_PDU_REQ_READWRITE_READ_ADDR_OFF] = usReadRegAddr >> 8;
- ucMBFrame[MB_PDU_REQ_READWRITE_READ_ADDR_OFF + 1] = usReadRegAddr;
- ucMBFrame[MB_PDU_REQ_READWRITE_READ_REGCNT_OFF] = usNReadRegs >> 8;
- ucMBFrame[MB_PDU_REQ_READWRITE_READ_REGCNT_OFF + 1] = usNReadRegs ;
- ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF] = usWriteRegAddr >> 8;
- ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF + 1] = usWriteRegAddr;
- ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF] = usNWriteRegs >> 8;
- ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF + 1] = usNWriteRegs ;
- ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_BYTECNT_OFF] = usNWriteRegs * 2;
- ucMBFrame += MB_PDU_REQ_READWRITE_WRITE_VALUES_OFF;
- while( usNWriteRegs > usRegIndex)
- {
- *ucMBFrame++ = pusDataBuffer[usRegIndex] >> 8;
- *ucMBFrame++ = pusDataBuffer[usRegIndex++] ;
- }
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READWRITE_SIZE_MIN + 2*usNWriteRegs );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegReadAddress;
- USHORT usRegReadCount;
- USHORT usRegWriteAddress;
- USHORT usRegWriteCount;
- UCHAR *ucMBFrame;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- /* If this request is broadcast, and it's read mode. This request don't need execute. */
- if ( xMBMasterRequestIsBroadcast() )
- {
- eStatus = MB_EX_NONE;
- }
- else if( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READWRITE_SIZE_MIN )
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- usRegReadAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_READ_ADDR_OFF] << 8U );
- usRegReadAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_READ_ADDR_OFF + 1] );
- usRegReadAddress++;
-
- usRegReadCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_READ_REGCNT_OFF] << 8U );
- usRegReadCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_READ_REGCNT_OFF + 1] );
-
- usRegWriteAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF] << 8U );
- usRegWriteAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_ADDR_OFF + 1] );
- usRegWriteAddress++;
-
- usRegWriteCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF] << 8U );
- usRegWriteCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_REGCNT_OFF + 1] );
-
- if( ( 2 * usRegReadCount ) == pucFrame[MB_PDU_FUNC_READWRITE_READ_BYTECNT_OFF] )
- {
- /* Make callback to update the register values. */
- eRegStatus = eMBMasterRegHoldingCB( &ucMBFrame[MB_PDU_REQ_READWRITE_WRITE_VALUES_OFF],
- usRegWriteAddress, usRegWriteCount, MB_REG_WRITE );
-
- if( eRegStatus == MB_ENOERR )
- {
- /* Make the read callback. */
- eRegStatus = eMBMasterRegHoldingCB(&pucFrame[MB_PDU_FUNC_READWRITE_READ_VALUES_OFF],
- usRegReadAddress, usRegReadCount, MB_REG_READ);
- }
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- return eStatus;
-}
-
-#endif
-#endif
-
diff --git a/components/net/freemodbus/modbus/functions/mbfuncinput.c b/components/net/freemodbus/modbus/functions/mbfuncinput.c
deleted file mode 100644
index cceedbafea..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfuncinput.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfuncinput.c,v 1.10 2007/09/12 10:15:56 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF )
-#define MB_PDU_FUNC_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_FUNC_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_REGCNT_MAX ( 0x007D )
-
-#define MB_PDU_FUNC_READ_RSP_BYTECNT_OFF ( MB_PDU_DATA_OFF )
-
-/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
-
-/* ----------------------- Start implementation -----------------------------*/
-#if MB_FUNC_READ_INPUT_ENABLED > 0
-
-eMBException
-eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- USHORT usRegAddress;
- USHORT usRegCount;
- UCHAR *pucFrameCur;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) )
- {
- usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] );
- usRegAddress++;
-
- usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 );
- usRegCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] );
-
- /* Check if the number of registers to read is valid. If not
- * return Modbus illegal data value exception.
- */
- if( ( usRegCount >= 1 )
- && ( usRegCount < MB_PDU_FUNC_READ_REGCNT_MAX ) )
- {
- /* Set the current PDU data pointer to the beginning. */
- pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF];
- *usLen = MB_PDU_FUNC_OFF;
-
- /* First byte contains the function code. */
- *pucFrameCur++ = MB_FUNC_READ_INPUT_REGISTER;
- *usLen += 1;
-
- /* Second byte in the response contain the number of bytes. */
- *pucFrameCur++ = ( UCHAR )( usRegCount * 2 );
- *usLen += 1;
-
- eRegStatus =
- eMBRegInputCB( pucFrameCur, usRegAddress, usRegCount );
-
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- else
- {
- *usLen += usRegCount * 2;
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid read input register request because the length
- * is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbfuncinput_m.c b/components/net/freemodbus/modbus/functions/mbfuncinput_m.c
deleted file mode 100644
index 2127efef67..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfuncinput_m.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (C) 2013 Armink <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfuncinput_m.c,v 1.60 2013/10/12 14:23:40 Armink Add Master Functions Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mb_m.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_REQ_READ_ADDR_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_REQ_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 )
-#define MB_PDU_REQ_READ_SIZE ( 4 )
-#define MB_PDU_FUNC_READ_BYTECNT_OFF ( MB_PDU_DATA_OFF + 0 )
-#define MB_PDU_FUNC_READ_VALUES_OFF ( MB_PDU_DATA_OFF + 1 )
-#define MB_PDU_FUNC_READ_SIZE_MIN ( 1 )
-
-#define MB_PDU_FUNC_READ_RSP_BYTECNT_OFF ( MB_PDU_DATA_OFF )
-
-/* ----------------------- Static functions ---------------------------------*/
-eMBException prveMBError2Exception( eMBErrorCode eErrorCode );
-
-/* ----------------------- Start implementation -----------------------------*/
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-#if MB_FUNC_READ_INPUT_ENABLED > 0
-
-/**
- * This function will request read input register.
- *
- * @param ucSndAddr salve address
- * @param usRegAddr register start address
- * @param usNRegs register total number
- * @param lTimeOut timeout (-1 will waiting forever)
- *
- * @return error code
- */
-eMBMasterReqErrCode
-eMBMasterReqReadInputRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usNRegs, LONG lTimeOut )
-{
- UCHAR *ucMBFrame;
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
-
- if ( ucSndAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
- else if ( xMBMasterRunResTake( lTimeOut ) == FALSE ) eErrStatus = MB_MRE_MASTER_BUSY;
- else
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- vMBMasterSetDestAddress(ucSndAddr);
- ucMBFrame[MB_PDU_FUNC_OFF] = MB_FUNC_READ_INPUT_REGISTER;
- ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] = usRegAddr >> 8;
- ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] = usRegAddr;
- ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF] = usNRegs >> 8;
- ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF + 1] = usNRegs;
- vMBMasterSetPDUSndLength( MB_PDU_SIZE_MIN + MB_PDU_REQ_READ_SIZE );
- ( void ) xMBMasterPortEventPost( EV_MASTER_FRAME_SENT );
- eErrStatus = eMBMasterWaitRequestFinish( );
- }
- return eErrStatus;
-}
-
-eMBException
-eMBMasterFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen )
-{
- UCHAR *ucMBFrame;
- USHORT usRegAddress;
- USHORT usRegCount;
-
- eMBException eStatus = MB_EX_NONE;
- eMBErrorCode eRegStatus;
-
- /* If this request is broadcast, and it's read mode. This request don't need execute. */
- if ( xMBMasterRequestIsBroadcast() )
- {
- eStatus = MB_EX_NONE;
- }
- else if( *usLen >= MB_PDU_SIZE_MIN + MB_PDU_FUNC_READ_SIZE_MIN )
- {
- vMBMasterGetPDUSndBuf(&ucMBFrame);
- usRegAddress = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF] << 8 );
- usRegAddress |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_ADDR_OFF + 1] );
- usRegAddress++;
-
- usRegCount = ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF] << 8 );
- usRegCount |= ( USHORT )( ucMBFrame[MB_PDU_REQ_READ_REGCNT_OFF + 1] );
-
- /* Check if the number of registers to read is valid. If not
- * return Modbus illegal data value exception.
- */
- if( ( usRegCount >= 1 ) && ( 2 * usRegCount == pucFrame[MB_PDU_FUNC_READ_BYTECNT_OFF] ) )
- {
- /* Make callback to fill the buffer. */
- eRegStatus = eMBMasterRegInputCB( &pucFrame[MB_PDU_FUNC_READ_VALUES_OFF], usRegAddress, usRegCount );
- /* If an error occured convert it into a Modbus exception. */
- if( eRegStatus != MB_ENOERR )
- {
- eStatus = prveMBError2Exception( eRegStatus );
- }
- }
- else
- {
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- }
- else
- {
- /* Can't be a valid request because the length is incorrect. */
- eStatus = MB_EX_ILLEGAL_DATA_VALUE;
- }
- return eStatus;
-}
-
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbfuncother.c b/components/net/freemodbus/modbus/functions/mbfuncother.c
deleted file mode 100644
index fcee972bf8..0000000000
--- a/components/net/freemodbus/modbus/functions/mbfuncother.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfuncother.c,v 1.8 2006/12/07 22:10:34 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbconfig.h"
-
-#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
-
-/* ----------------------- Static variables ---------------------------------*/
-static UCHAR ucMBSlaveID[MB_FUNC_OTHER_REP_SLAVEID_BUF];
-static USHORT usMBSlaveIDLen;
-
-/* ----------------------- Start implementation -----------------------------*/
-
-eMBErrorCode
-eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning,
- UCHAR const *pucAdditional, USHORT usAdditionalLen )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- /* the first byte and second byte in the buffer is reserved for
- * the parameter ucSlaveID and the running flag. The rest of
- * the buffer is available for additional data. */
- if( usAdditionalLen + 2 < MB_FUNC_OTHER_REP_SLAVEID_BUF )
- {
- usMBSlaveIDLen = 0;
- ucMBSlaveID[usMBSlaveIDLen++] = ucSlaveID;
- ucMBSlaveID[usMBSlaveIDLen++] = ( UCHAR )( xIsRunning ? 0xFF : 0x00 );
- if( usAdditionalLen > 0 )
- {
- memcpy( &ucMBSlaveID[usMBSlaveIDLen], pucAdditional,
- ( size_t )usAdditionalLen );
- usMBSlaveIDLen += usAdditionalLen;
- }
- }
- else
- {
- eStatus = MB_ENORES;
- }
- return eStatus;
-}
-
-eMBException
-eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen )
-{
- memcpy( &pucFrame[MB_PDU_DATA_OFF], &ucMBSlaveID[0], ( size_t )usMBSlaveIDLen );
- *usLen = ( USHORT )( MB_PDU_DATA_OFF + usMBSlaveIDLen );
- return MB_EX_NONE;
-}
-
-#endif
diff --git a/components/net/freemodbus/modbus/functions/mbutils.c b/components/net/freemodbus/modbus/functions/mbutils.c
deleted file mode 100644
index 2afe3b84b7..0000000000
--- a/components/net/freemodbus/modbus/functions/mbutils.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbutils.c,v 1.6 2007/02/18 23:49:07 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbproto.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define BITS_UCHAR 8U
-
-/* ----------------------- Start implementation -----------------------------*/
-void
-xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits,
- UCHAR ucValue )
-{
- USHORT usWordBuf;
- USHORT usMask;
- USHORT usByteOffset;
- USHORT usNPreBits;
- USHORT usValue = ucValue;
-
- RT_ASSERT( ucNBits <= 8 );
- RT_ASSERT( ( size_t )BITS_UCHAR == sizeof( UCHAR ) * 8 );
-
- /* Calculate byte offset for first byte containing the bit values starting
- * at usBitOffset. */
- usByteOffset = ( USHORT )( ( usBitOffset ) / BITS_UCHAR );
-
- /* How many bits precede our bits to set. */
- usNPreBits = ( USHORT )( usBitOffset - usByteOffset * BITS_UCHAR );
-
- /* Move bit field into position over bits to set */
- usValue <<= usNPreBits;
-
- /* Prepare a mask for setting the new bits. */
- usMask = ( USHORT )( ( 1 << ( USHORT ) ucNBits ) - 1 );
- usMask <<= usBitOffset - usByteOffset * BITS_UCHAR;
-
- /* copy bits into temporary storage. */
- usWordBuf = ucByteBuf[usByteOffset];
- usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR;
-
- /* Zero out bit field bits and then or value bits into them. */
- usWordBuf = ( USHORT )( ( usWordBuf & ( ~usMask ) ) | usValue );
-
- /* move bits back into storage */
- ucByteBuf[usByteOffset] = ( UCHAR )( usWordBuf & 0xFF );
- ucByteBuf[usByteOffset + 1] = ( UCHAR )( usWordBuf >> BITS_UCHAR );
-}
-
-UCHAR
-xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits )
-{
- USHORT usWordBuf;
- USHORT usMask;
- USHORT usByteOffset;
- USHORT usNPreBits;
-
- /* Calculate byte offset for first byte containing the bit values starting
- * at usBitOffset. */
- usByteOffset = ( USHORT )( ( usBitOffset ) / BITS_UCHAR );
-
- /* How many bits precede our bits to set. */
- usNPreBits = ( USHORT )( usBitOffset - usByteOffset * BITS_UCHAR );
-
- /* Prepare a mask for setting the new bits. */
- usMask = ( USHORT )( ( 1 << ( USHORT ) ucNBits ) - 1 );
-
- /* copy bits into temporary storage. */
- usWordBuf = ucByteBuf[usByteOffset];
- usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR;
-
- /* throw away unneeded bits. */
- usWordBuf >>= usNPreBits;
-
- /* mask away bits above the requested bitfield. */
- usWordBuf &= usMask;
-
- return ( UCHAR ) usWordBuf;
-}
-
-eMBException
-prveMBError2Exception( eMBErrorCode eErrorCode )
-{
- eMBException eStatus;
-
- switch ( eErrorCode )
- {
- case MB_ENOERR:
- eStatus = MB_EX_NONE;
- break;
-
- case MB_ENOREG:
- eStatus = MB_EX_ILLEGAL_DATA_ADDRESS;
- break;
-
- case MB_ETIMEDOUT:
- eStatus = MB_EX_SLAVE_BUSY;
- break;
-
- default:
- eStatus = MB_EX_SLAVE_DEVICE_FAILURE;
- break;
- }
-
- return eStatus;
-}
diff --git a/components/net/freemodbus/modbus/include/mb.h b/components/net/freemodbus/modbus/include/mb.h
deleted file mode 100644
index 8d6be7b422..0000000000
--- a/components/net/freemodbus/modbus/include/mb.h
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mb.h,v 1.17 2006/12/07 22:10:34 wolti Exp $
- */
-
-#ifndef _MB_H
-#define _MB_H
-
-#include "port.h"
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-
-#include "mbport.h"
-#include "mbproto.h"
-
-/*! \defgroup modbus Modbus
- * \code #include "mb.h" \endcode
- *
- * This module defines the interface for the application. It contains
- * the basic functions and types required to use the Modbus protocol stack.
- * A typical application will want to call eMBInit() first. If the device
- * is ready to answer network requests it must then call eMBEnable() to activate
- * the protocol stack. In the main loop the function eMBPoll() must be called
- * periodically. The time interval between pooling depends on the configured
- * Modbus timeout. If an RTOS is available a separate task should be created
- * and the task should always call the function eMBPoll().
- *
- * \code
- * // Initialize protocol stack in RTU mode for a slave with address 10 = 0x0A
- * eMBInit( MB_RTU, 0x0A, 38400, MB_PAR_EVEN );
- * // Enable the Modbus Protocol Stack.
- * eMBEnable( );
- * for( ;; )
- * {
- * // Call the main polling loop of the Modbus protocol stack.
- * eMBPoll( );
- * ...
- * }
- * \endcode
- */
-
-/* ----------------------- Defines ------------------------------------------*/
-
-/*! \ingroup modbus
- * \brief Use the default Modbus TCP port (502)
- */
-#define MB_TCP_PORT_USE_DEFAULT 0
-
-/* ----------------------- Type definitions ---------------------------------*/
-
-/*! \ingroup modbus
- * \brief Modbus serial transmission modes (RTU/ASCII).
- *
- * Modbus serial supports two transmission modes. Either ASCII or RTU. RTU
- * is faster but has more hardware requirements and requires a network with
- * a low jitter. ASCII is slower and more reliable on slower links (E.g. modems)
- */
- typedef enum
-{
- MB_RTU, /*!< RTU transmission mode. */
- MB_ASCII, /*!< ASCII transmission mode. */
- MB_TCP /*!< TCP mode. */
-} eMBMode;
-
-/*! \ingroup modbus
- * \brief If register should be written or read.
- *
- * This value is passed to the callback functions which support either
- * reading or writing register values. Writing means that the application
- * registers should be updated and reading means that the modbus protocol
- * stack needs to know the current register values.
- *
- * \see eMBRegHoldingCB( ), eMBRegCoilsCB( ), eMBRegDiscreteCB( ) and
- * eMBRegInputCB( ).
- */
-typedef enum
-{
- MB_REG_READ, /*!< Read register values and pass to protocol stack. */
- MB_REG_WRITE /*!< Update register values. */
-} eMBRegisterMode;
-
-/*! \ingroup modbus
- * \brief Errorcodes used by all function in the protocol stack.
- */
-typedef enum
-{
- MB_ENOERR, /*!< no error. */
- MB_ENOREG, /*!< illegal register address. */
- MB_EINVAL, /*!< illegal argument. */
- MB_EPORTERR, /*!< porting layer error. */
- MB_ENORES, /*!< insufficient resources. */
- MB_EIO, /*!< I/O error. */
- MB_EILLSTATE, /*!< protocol stack in illegal state. */
- MB_ETIMEDOUT /*!< timeout error occurred. */
-} eMBErrorCode;
-
-
-/* ----------------------- Function prototypes ------------------------------*/
-/*! \ingroup modbus
- * \brief Initialize the Modbus protocol stack.
- *
- * This functions initializes the ASCII or RTU module and calls the
- * init functions of the porting layer to prepare the hardware. Please
- * note that the receiver is still disabled and no Modbus frames are
- * processed until eMBEnable( ) has been called.
- *
- * \param eMode If ASCII or RTU mode should be used.
- * \param ucSlaveAddress The slave address. Only frames sent to this
- * address or to the broadcast address are processed.
- * \param ucPort The port to use. E.g. 1 for COM1 on windows. This value
- * is platform dependent and some ports simply choose to ignore it.
- * \param ulBaudRate The baudrate. E.g. 19200. Supported baudrates depend
- * on the porting layer.
- * \param eParity Parity used for serial transmission.
- *
- * \return If no error occurs the function returns eMBErrorCode::MB_ENOERR.
- * The protocol is then in the disabled state and ready for activation
- * by calling eMBEnable( ). Otherwise one of the following error codes
- * is returned:
- * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
- * slave addresses are in the range 1 - 247.
- * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
- */
-eMBErrorCode eMBInit( eMBMode eMode, UCHAR ucSlaveAddress,
- UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity );
-
-/*! \ingroup modbus
- * \brief Initialize the Modbus protocol stack for Modbus TCP.
- *
- * This function initializes the Modbus TCP Module. Please note that
- * frame processing is still disabled until eMBEnable( ) is called.
- *
- * \param usTCPPort The TCP port to listen on.
- * \return If the protocol stack has been initialized correctly the function
- * returns eMBErrorCode::MB_ENOERR. Otherwise one of the following error
- * codes is returned:
- * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
- * slave addresses are in the range 1 - 247.
- * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
- */
-eMBErrorCode eMBTCPInit( USHORT usTCPPort );
-
-/*! \ingroup modbus
- * \brief Release resources used by the protocol stack.
- *
- * This function disables the Modbus protocol stack and release all
- * hardware resources. It must only be called when the protocol stack
- * is disabled.
- *
- * \note Note all ports implement this function. A port which wants to
- * get an callback must define the macro MB_PORT_HAS_CLOSE to 1.
- *
- * \return If the resources where released it return eMBErrorCode::MB_ENOERR.
- * If the protocol stack is not in the disabled state it returns
- * eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode eMBClose( void );
-
-/*! \ingroup modbus
- * \brief Enable the Modbus protocol stack.
- *
- * This function enables processing of Modbus frames. Enabling the protocol
- * stack is only possible if it is in the disabled state.
- *
- * \return If the protocol stack is now in the state enabled it returns
- * eMBErrorCode::MB_ENOERR. If it was not in the disabled state it
- * return eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode eMBEnable( void );
-
-/*! \ingroup modbus
- * \brief Disable the Modbus protocol stack.
- *
- * This function disables processing of Modbus frames.
- *
- * \return If the protocol stack has been disabled it returns
- * eMBErrorCode::MB_ENOERR. If it was not in the enabled state it returns
- * eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode eMBDisable( void );
-
-/*! \ingroup modbus
- * \brief The main pooling loop of the Modbus protocol stack.
- *
- * This function must be called periodically. The timer interval required
- * is given by the application dependent Modbus slave timeout. Internally the
- * function calls xMBPortEventGet() and waits for an event from the receiver or
- * transmitter state machines.
- *
- * \return If the protocol stack is not in the enabled state the function
- * returns eMBErrorCode::MB_EILLSTATE. Otherwise it returns
- * eMBErrorCode::MB_ENOERR.
- */
-eMBErrorCode eMBPoll( void );
-
-/*! \ingroup modbus
- * \brief Configure the slave id of the device.
- *
- * This function should be called when the Modbus function <em>Report Slave ID</em>
- * is enabled ( By defining MB_FUNC_OTHER_REP_SLAVEID_ENABLED in mbconfig.h ).
- *
- * \param ucSlaveID Values is returned in the <em>Slave ID</em> byte of the
- * <em>Report Slave ID</em> response.
- * \param xIsRunning If TRUE the <em>Run Indicator Status</em> byte is set to 0xFF.
- * otherwise the <em>Run Indicator Status</em> is 0x00.
- * \param pucAdditional Values which should be returned in the <em>Additional</em>
- * bytes of the <em> Report Slave ID</em> response.
- * \param usAdditionalLen Length of the buffer <code>pucAdditonal</code>.
- *
- * \return If the static buffer defined by MB_FUNC_OTHER_REP_SLAVEID_BUF in
- * mbconfig.h is to small it returns eMBErrorCode::MB_ENORES. Otherwise
- * it returns eMBErrorCode::MB_ENOERR.
- */
-eMBErrorCode eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning,
- UCHAR const *pucAdditional,
- USHORT usAdditionalLen );
-
-/*! \ingroup modbus
- * \brief Registers a callback handler for a given function code.
- *
- * This function registers a new callback handler for a given function code.
- * The callback handler supplied is responsible for interpreting the Modbus PDU and
- * the creation of an appropriate response. In case of an error it should return
- * one of the possible Modbus exceptions which results in a Modbus exception frame
- * sent by the protocol stack.
- *
- * \param ucFunctionCode The Modbus function code for which this handler should
- * be registers. Valid function codes are in the range 1 to 127.
- * \param pxHandler The function handler which should be called in case
- * such a frame is received. If \c NULL a previously registered function handler
- * for this function code is removed.
- *
- * \return eMBErrorCode::MB_ENOERR if the handler has been installed. If no
- * more resources are available it returns eMBErrorCode::MB_ENORES. In this
- * case the values in mbconfig.h should be adjusted. If the argument was not
- * valid it returns eMBErrorCode::MB_EINVAL.
- */
-eMBErrorCode eMBRegisterCB( UCHAR ucFunctionCode,
- pxMBFunctionHandler pxHandler );
-
-/* ----------------------- Callback -----------------------------------------*/
-
-/*! \defgroup modbus_registers Modbus Registers
- * \code #include "mb.h" \endcode
- * The protocol stack does not internally allocate any memory for the
- * registers. This makes the protocol stack very small and also usable on
- * low end targets. In addition the values don't have to be in the memory
- * and could for example be stored in a flash.<br>
- * Whenever the protocol stack requires a value it calls one of the callback
- * function with the register address and the number of registers to read
- * as an argument. The application should then read the actual register values
- * (for example the ADC voltage) and should store the result in the supplied
- * buffer.<br>
- * If the protocol stack wants to update a register value because a write
- * register function was received a buffer with the new register values is
- * passed to the callback function. The function should then use these values
- * to update the application register values.
- */
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if the value of a <em>Input Register</em>
- * is required by the protocol stack. The starting register address is given
- * by \c usAddress and the last register is given by <tt>usAddress +
- * usNRegs - 1</tt>.
- *
- * \param pucRegBuffer A buffer where the callback function should write
- * the current value of the modbus registers to.
- * \param usAddress The starting address of the register. Input registers
- * are in the range 1 - 65535.
- * \param usNRegs Number of registers the callback function must supply.
- *
- * \return The function must return one of the following error codes:
- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- * Modbus response is sent.
- * - eMBErrorCode::MB_ENOREG If the application can not supply values
- * for registers within this range. In this case a
- * <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
- * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
- * currently not available and the application dependent response
- * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
- * exception is sent as a response.
- * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
- * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
- */
-eMBErrorCode eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNRegs );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Holding Register</em> value is
- * read or written by the protocol stack. The starting register address
- * is given by \c usAddress and the last register is given by
- * <tt>usAddress + usNRegs - 1</tt>.
- *
- * \param pucRegBuffer If the application registers values should be updated the
- * buffer points to the new registers values. If the protocol stack needs
- * to now the current values the callback function should write them into
- * this buffer.
- * \param usAddress The starting address of the register.
- * \param usNRegs Number of registers to read or write.
- * \param eMode If eMBRegisterMode::MB_REG_WRITE the application register
- * values should be updated from the values in the buffer. For example
- * this would be the case when the Modbus master has issued an
- * <b>WRITE SINGLE REGISTER</b> command.
- * If the value eMBRegisterMode::MB_REG_READ the application should copy
- * the current values into the buffer \c pucRegBuffer.
- *
- * \return The function must return one of the following error codes:
- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- * Modbus response is sent.
- * - eMBErrorCode::MB_ENOREG If the application can not supply values
- * for registers within this range. In this case a
- * <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
- * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
- * currently not available and the application dependent response
- * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
- * exception is sent as a response.
- * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
- * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
- */
-eMBErrorCode eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNRegs, eMBRegisterMode eMode );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Coil Register</em> value is
- * read or written by the protocol stack. If you are going to use
- * this function you might use the functions xMBUtilSetBits( ) and
- * xMBUtilGetBits( ) for working with bitfields.
- *
- * \param pucRegBuffer The bits are packed in bytes where the first coil
- * starting at address \c usAddress is stored in the LSB of the
- * first byte in the buffer <code>pucRegBuffer</code>.
- * If the buffer should be written by the callback function unused
- * coil values (I.e. if not a multiple of eight coils is used) should be set
- * to zero.
- * \param usAddress The first coil number.
- * \param usNCoils Number of coil values requested.
- * \param eMode If eMBRegisterMode::MB_REG_WRITE the application values should
- * be updated from the values supplied in the buffer \c pucRegBuffer.
- * If eMBRegisterMode::MB_REG_READ the application should store the current
- * values in the buffer \c pucRegBuffer.
- *
- * \return The function must return one of the following error codes:
- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- * Modbus response is sent.
- * - eMBErrorCode::MB_ENOREG If the application does not map an coils
- * within the requested address range. In this case a
- * <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
- * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
- * currently not available and the application dependent response
- * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
- * exception is sent as a response.
- * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
- * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
- */
-eMBErrorCode eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNCoils, eMBRegisterMode eMode );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Input Discrete Register</em> value is
- * read by the protocol stack.
- *
- * If you are going to use his function you might use the functions
- * xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
- *
- * \param pucRegBuffer The buffer should be updated with the current
- * coil values. The first discrete input starting at \c usAddress must be
- * stored at the LSB of the first byte in the buffer. If the requested number
- * is not a multiple of eight the remaining bits should be set to zero.
- * \param usAddress The starting address of the first discrete input.
- * \param usNDiscrete Number of discrete input values.
- * \return The function must return one of the following error codes:
- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- * Modbus response is sent.
- * - eMBErrorCode::MB_ENOREG If no such discrete inputs exists.
- * In this case a <b>ILLEGAL DATA ADDRESS</b> exception frame is sent
- * as a response.
- * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
- * currently not available and the application dependent response
- * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
- * exception is sent as a response.
- * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
- * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
- */
-eMBErrorCode eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNDiscrete );
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/include/mb_m.h b/components/net/freemodbus/modbus/include/mb_m.h
deleted file mode 100644
index f6b25e2cf3..0000000000
--- a/components/net/freemodbus/modbus/include/mb_m.h
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (C) 2013 Armink <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mb_m.h,v 1.60 2013/09/03 10:20:05 Armink Add Master Functions $
- */
-
-#ifndef _MB_M_H
-#define _MB_M_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-
-/*! \defgroup modbus Modbus
- * \code #include "mb_m.h" \endcode
- *
- * This module defines the interface for the application. It contains
- * the basic functions and types required to use the Modbus Master protocol stack.
- * A typical application will want to call eMBMasterInit() first. If the device
- * is ready to answer network requests it must then call eMBEnable() to activate
- * the protocol stack. In the main loop the function eMBMasterPoll() must be called
- * periodically. The time interval between pooling depends on the configured
- * Modbus timeout. If an RTOS is available a separate task should be created
- * and the task should always call the function eMBMasterPoll().
- *
- * \code
- * // Initialize protocol stack in RTU mode for a Master
- * eMBMasterInit( MB_RTU, 38400, MB_PAR_EVEN );
- * // Enable the Modbus Protocol Stack.
- * eMBMasterEnable( );
- * for( ;; )
- * {
- * // Call the main polling loop of the Modbus Master protocol stack.
- * eMBMasterPoll( );
- * ...
- * }
- * \endcode
- */
-
-/* ----------------------- Defines ------------------------------------------*/
-
-/*! \ingroup modbus
- * \brief Use the default Modbus Master TCP port (502)
- */
-#define MB_MASTER_TCP_PORT_USE_DEFAULT 0
-
-/* ----------------------- Type definitions ---------------------------------*/
-/*! \ingroup modbus
- * \brief Errorcodes used by all function in the Master request.
- */
-typedef enum
-{
- MB_MRE_NO_ERR, /*!< no error. */
- MB_MRE_NO_REG, /*!< illegal register address. */
- MB_MRE_ILL_ARG, /*!< illegal argument. */
- MB_MRE_REV_DATA, /*!< receive data error. */
- MB_MRE_TIMEDOUT, /*!< timeout error occurred. */
- MB_MRE_MASTER_BUSY, /*!< master is busy now. */
- MB_MRE_EXE_FUN /*!< execute function error. */
-} eMBMasterReqErrCode;
-/*! \ingroup modbus
- * \brief TimerMode is Master 3 kind of Timer modes.
- */
-typedef enum
-{
- MB_TMODE_T35, /*!< Master receive frame T3.5 timeout. */
- MB_TMODE_RESPOND_TIMEOUT, /*!< Master wait respond for slave. */
- MB_TMODE_CONVERT_DELAY /*!< Master sent broadcast ,then delay sometime.*/
-}eMBMasterTimerMode;
-
-/* ----------------------- Function prototypes ------------------------------*/
-/*! \ingroup modbus
- * \brief Initialize the Modbus Master protocol stack.
- *
- * This functions initializes the ASCII or RTU module and calls the
- * init functions of the porting layer to prepare the hardware. Please
- * note that the receiver is still disabled and no Modbus frames are
- * processed until eMBMasterEnable( ) has been called.
- *
- * \param eMode If ASCII or RTU mode should be used.
- * \param ucPort The port to use. E.g. 1 for COM1 on windows. This value
- * is platform dependent and some ports simply choose to ignore it.
- * \param ulBaudRate The baudrate. E.g. 19200. Supported baudrates depend
- * on the porting layer.
- * \param eParity Parity used for serial transmission.
- *
- * \return If no error occurs the function returns eMBErrorCode::MB_ENOERR.
- * The protocol is then in the disabled state and ready for activation
- * by calling eMBMasterEnable( ). Otherwise one of the following error codes
- * is returned:
- * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
- */
-eMBErrorCode eMBMasterInit( eMBMode eMode, UCHAR ucPort,
- ULONG ulBaudRate, eMBParity eParity );
-
-/*! \ingroup modbus
- * \brief Initialize the Modbus Master protocol stack for Modbus TCP.
- *
- * This function initializes the Modbus TCP Module. Please note that
- * frame processing is still disabled until eMBEnable( ) is called.
- *
- * \param usTCPPort The TCP port to listen on.
- * \return If the protocol stack has been initialized correctly the function
- * returns eMBErrorCode::MB_ENOERR. Otherwise one of the following error
- * codes is returned:
- * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
- * slave addresses are in the range 1 - 247.
- * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
- */
-eMBErrorCode eMBMasterTCPInit( USHORT usTCPPort );
-
-/*! \ingroup modbus
- * \brief Release resources used by the protocol stack.
- *
- * This function disables the Modbus Master protocol stack and release all
- * hardware resources. It must only be called when the protocol stack
- * is disabled.
- *
- * \note Note all ports implement this function. A port which wants to
- * get an callback must define the macro MB_PORT_HAS_CLOSE to 1.
- *
- * \return If the resources where released it return eMBErrorCode::MB_ENOERR.
- * If the protocol stack is not in the disabled state it returns
- * eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode eMBMasterClose( void );
-
-/*! \ingroup modbus
- * \brief Enable the Modbus Master protocol stack.
- *
- * This function enables processing of Modbus Master frames. Enabling the protocol
- * stack is only possible if it is in the disabled state.
- *
- * \return If the protocol stack is now in the state enabled it returns
- * eMBErrorCode::MB_ENOERR. If it was not in the disabled state it
- * return eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode eMBMasterEnable( void );
-
-/*! \ingroup modbus
- * \brief Disable the Modbus Master protocol stack.
- *
- * This function disables processing of Modbus frames.
- *
- * \return If the protocol stack has been disabled it returns
- * eMBErrorCode::MB_ENOERR. If it was not in the enabled state it returns
- * eMBErrorCode::MB_EILLSTATE.
- */
-eMBErrorCode eMBMasterDisable( void );
-
-/*! \ingroup modbus
- * \brief The main pooling loop of the Modbus Master protocol stack.
- *
- * This function must be called periodically. The timer interval required
- * is given by the application dependent Modbus slave timeout. Internally the
- * function calls xMBMasterPortEventGet() and waits for an event from the receiver or
- * transmitter state machines.
- *
- * \return If the protocol stack is not in the enabled state the function
- * returns eMBErrorCode::MB_EILLSTATE. Otherwise it returns
- * eMBErrorCode::MB_ENOERR.
- */
-eMBErrorCode eMBMasterPoll( void );
-
-/*! \ingroup modbus
- * \brief Registers a callback handler for a given function code.
- *
- * This function registers a new callback handler for a given function code.
- * The callback handler supplied is responsible for interpreting the Modbus PDU and
- * the creation of an appropriate response. In case of an error it should return
- * one of the possible Modbus exceptions which results in a Modbus exception frame
- * sent by the protocol stack.
- *
- * \param ucFunctionCode The Modbus function code for which this handler should
- * be registers. Valid function codes are in the range 1 to 127.
- * \param pxHandler The function handler which should be called in case
- * such a frame is received. If \c NULL a previously registered function handler
- * for this function code is removed.
- *
- * \return eMBErrorCode::MB_ENOERR if the handler has been installed. If no
- * more resources are available it returns eMBErrorCode::MB_ENORES. In this
- * case the values in mbconfig.h should be adjusted. If the argument was not
- * valid it returns eMBErrorCode::MB_EINVAL.
- */
-eMBErrorCode eMBMasterRegisterCB( UCHAR ucFunctionCode,
- pxMBFunctionHandler pxHandler );
-
-/* ----------------------- Callback -----------------------------------------*/
-
-/*! \defgroup modbus_master registers Modbus Registers
- * \code #include "mb_m.h" \endcode
- * The protocol stack does not internally allocate any memory for the
- * registers. This makes the protocol stack very small and also usable on
- * low end targets. In addition the values don't have to be in the memory
- * and could for example be stored in a flash.<br>
- * Whenever the protocol stack requires a value it calls one of the callback
- * function with the register address and the number of registers to read
- * as an argument. The application should then read the actual register values
- * (for example the ADC voltage) and should store the result in the supplied
- * buffer.<br>
- * If the protocol stack wants to update a register value because a write
- * register function was received a buffer with the new register values is
- * passed to the callback function. The function should then use these values
- * to update the application register values.
- */
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if the value of a <em>Input Register</em>
- * is required by the protocol stack. The starting register address is given
- * by \c usAddress and the last register is given by <tt>usAddress +
- * usNRegs - 1</tt>.
- *
- * \param pucRegBuffer A buffer where the callback function should write
- * the current value of the modbus registers to.
- * \param usAddress The starting address of the register. Input registers
- * are in the range 1 - 65535.
- * \param usNRegs Number of registers the callback function must supply.
- *
- * \return The function must return one of the following error codes:
- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- * Modbus response is sent.
- * - eMBErrorCode::MB_ENOREG If the application does not map an coils
- * within the requested address range. In this case a
- * <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
- */
-eMBErrorCode eMBMasterRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNRegs );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Holding Register</em> value is
- * read or written by the protocol stack. The starting register address
- * is given by \c usAddress and the last register is given by
- * <tt>usAddress + usNRegs - 1</tt>.
- *
- * \param pucRegBuffer If the application registers values should be updated the
- * buffer points to the new registers values. If the protocol stack needs
- * to now the current values the callback function should write them into
- * this buffer.
- * \param usAddress The starting address of the register.
- * \param usNRegs Number of registers to read or write.
- * \param eMode If eMBRegisterMode::MB_REG_WRITE the application register
- * values should be updated from the values in the buffer. For example
- * this would be the case when the Modbus master has issued an
- * <b>WRITE SINGLE REGISTER</b> command.
- * If the value eMBRegisterMode::MB_REG_READ the application should copy
- * the current values into the buffer \c pucRegBuffer.
- *
- * \return The function must return one of the following error codes:
- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- * Modbus response is sent.
- * - eMBErrorCode::MB_ENOREG If the application does not map an coils
- * within the requested address range. In this case a
- * <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
- */
-eMBErrorCode eMBMasterRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNRegs, eMBRegisterMode eMode );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Coil Register</em> value is
- * read or written by the protocol stack. If you are going to use
- * this function you might use the functions xMBUtilSetBits( ) and
- * xMBUtilGetBits( ) for working with bitfields.
- *
- * \param pucRegBuffer The bits are packed in bytes where the first coil
- * starting at address \c usAddress is stored in the LSB of the
- * first byte in the buffer <code>pucRegBuffer</code>.
- * If the buffer should be written by the callback function unused
- * coil values (I.e. if not a multiple of eight coils is used) should be set
- * to zero.
- * \param usAddress The first coil number.
- * \param usNCoils Number of coil values requested.
- * \param eMode If eMBRegisterMode::MB_REG_WRITE the application values should
- * be updated from the values supplied in the buffer \c pucRegBuffer.
- * If eMBRegisterMode::MB_REG_READ the application should store the current
- * values in the buffer \c pucRegBuffer.
- *
- * \return The function must return one of the following error codes:
- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- * Modbus response is sent.
- * - eMBErrorCode::MB_ENOREG If the application does not map an coils
- * within the requested address range. In this case a
- * <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
- */
-eMBErrorCode eMBMasterRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNCoils, eMBRegisterMode eMode );
-
-/*! \ingroup modbus_registers
- * \brief Callback function used if a <em>Input Discrete Register</em> value is
- * read by the protocol stack.
- *
- * If you are going to use his function you might use the functions
- * xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
- *
- * \param pucRegBuffer The buffer should be updated with the current
- * coil values. The first discrete input starting at \c usAddress must be
- * stored at the LSB of the first byte in the buffer. If the requested number
- * is not a multiple of eight the remaining bits should be set to zero.
- * \param usAddress The starting address of the first discrete input.
- * \param usNDiscrete Number of discrete input values.
- * \return The function must return one of the following error codes:
- * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
- * Modbus response is sent.
- * - eMBErrorCode::MB_ENOREG If the application does not map an coils
- * within the requested address range. In this case a
- * <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
- */
-eMBErrorCode eMBMasterRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNDiscrete );
-
-/*! \ingroup modbus
- *\brief These Modbus functions are called for user when Modbus run in Master Mode.
- */
-eMBMasterReqErrCode
-eMBMasterReqReadInputRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usNRegs, LONG lTimeOut );
-eMBMasterReqErrCode
-eMBMasterReqWriteHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usRegData, LONG lTimeOut );
-eMBMasterReqErrCode
-eMBMasterReqWriteMultipleHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr,
- USHORT usNRegs, USHORT * pusDataBuffer, LONG lTimeOut );
-eMBMasterReqErrCode
-eMBMasterReqReadHoldingRegister( UCHAR ucSndAddr, USHORT usRegAddr, USHORT usNRegs, LONG lTimeOut );
-eMBMasterReqErrCode
-eMBMasterReqReadWriteMultipleHoldingRegister( UCHAR ucSndAddr,
- USHORT usReadRegAddr, USHORT usNReadRegs, USHORT * pusDataBuffer,
- USHORT usWriteRegAddr, USHORT usNWriteRegs, LONG lTimeOut );
-eMBMasterReqErrCode
-eMBMasterReqReadCoils( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usNCoils, LONG lTimeOut );
-eMBMasterReqErrCode
-eMBMasterReqWriteCoil( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usCoilData, LONG lTimeOut );
-eMBMasterReqErrCode
-eMBMasterReqWriteMultipleCoils( UCHAR ucSndAddr,
- USHORT usCoilAddr, USHORT usNCoils, UCHAR * pucDataBuffer, LONG lTimeOut );
-eMBMasterReqErrCode
-eMBMasterReqReadDiscreteInputs( UCHAR ucSndAddr, USHORT usDiscreteAddr, USHORT usNDiscreteIn, LONG lTimeOut );
-
-eMBException
-eMBMasterFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncReadCoils( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncWriteCoil( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncWriteMultipleCoils( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen );
-eMBException
-eMBMasterFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-
-/*�� \ingroup modbus
- *\brief These functions are interface for Modbus Master
- */
-void vMBMasterGetPDUSndBuf( UCHAR ** pucFrame );
-UCHAR ucMBMasterGetDestAddress( void );
-void vMBMasterSetDestAddress( UCHAR Address );
-BOOL xMBMasterGetCBRunInMasterMode( void );
-void vMBMasterSetCBRunInMasterMode( BOOL IsMasterMode );
-USHORT usMBMasterGetPDUSndLength( void );
-void vMBMasterSetPDUSndLength( USHORT SendPDULength );
-void vMBMasterSetCurTimerMode( eMBMasterTimerMode eMBTimerMode );
-BOOL xMBMasterRequestIsBroadcast( void );
-eMBMasterErrorEventType eMBMasterGetErrorType( void );
-void vMBMasterSetErrorType( eMBMasterErrorEventType errorType );
-eMBMasterReqErrCode eMBMasterWaitRequestFinish( void );
-
-/* ----------------------- Callback -----------------------------------------*/
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/include/mbconfig.h b/components/net/freemodbus/modbus/include/mbconfig.h
deleted file mode 100644
index 89030b7abd..0000000000
--- a/components/net/freemodbus/modbus/include/mbconfig.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbconfig.h,v 1.14 2006/12/07 22:10:34 wolti Exp $
- * $Id: mbconfig.h,v 1.60 2013/08/13 21:19:55 Armink Add Master Functions $
- */
-
-#ifndef _MB_CONFIG_H
-#define _MB_CONFIG_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-/* ----------------------- Defines ------------------------------------------*/
-/*! \defgroup modbus_cfg Modbus Configuration
- *
- * Most modules in the protocol stack are completly optional and can be
- * excluded. This is specially important if target resources are very small
- * and program memory space should be saved.<br>
- *
- * All of these settings are available in the file <code>mbconfig.h</code>
- */
-/*! \addtogroup modbus_cfg
- * @{
- */
-/*! \brief If Modbus Master ASCII support is enabled. */
-#define MB_MASTER_ASCII_ENABLED ( 0 )
-/*! \brief If Modbus Master RTU support is enabled. */
-#define MB_MASTER_RTU_ENABLED ( 1 )
-/*! \brief If Modbus Master TCP support is enabled. */
-#define MB_MASTER_TCP_ENABLED ( 0 )
-/*! \brief If Modbus Slave ASCII support is enabled. */
-#define MB_SLAVE_ASCII_ENABLED ( 0 )
-/*! \brief If Modbus Slave RTU support is enabled. */
-#define MB_SLAVE_RTU_ENABLED ( 1 )
-/*! \brief If Modbus Slave TCP support is enabled. */
-#define MB_SLAVE_TCP_ENABLED ( 0 )
-/*! \brief The character timeout value for Modbus ASCII.
- *
- * The character timeout value is not fixed for Modbus ASCII and is therefore
- * a configuration option. It should be set to the maximum expected delay
- * time of the network.
- */
-#define MB_ASCII_TIMEOUT_SEC ( 1 )
-/*! \brief Maximum number of Modbus functions codes the protocol stack
- * should support.
- *
- * The maximum number of supported Modbus functions must be greater than
- * the sum of all enabled functions in this file and custom function
- * handlers. If set to small adding more functions will fail.
- */
-#define MB_FUNC_HANDLERS_MAX ( 16 )
-/*! \brief Number of bytes which should be allocated for the <em>Report Slave ID
- * </em>command.
- *
- * This number limits the maximum size of the additional segment in the
- * report slave id function. See eMBSetSlaveID( ) for more information on
- * how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
- * is set to <code>1</code>.
- */
-#define MB_FUNC_OTHER_REP_SLAVEID_BUF ( 32 )
-/*! \brief If the <em>Report Slave ID</em> function should be enabled. */
-#define MB_FUNC_OTHER_REP_SLAVEID_ENABLED ( 1 )
-/*! \brief If the <em>Read Input Registers</em> function should be enabled. */
-#define MB_FUNC_READ_INPUT_ENABLED ( 1 )
-/*! \brief If the <em>Read Holding Registers</em> function should be enabled. */
-#define MB_FUNC_READ_HOLDING_ENABLED ( 1 )
-/*! \brief If the <em>Write Single Register</em> function should be enabled. */
-#define MB_FUNC_WRITE_HOLDING_ENABLED ( 1 )
-/*! \brief If the <em>Write Multiple registers</em> function should be enabled. */
-#define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED ( 1 )
-/*! \brief If the <em>Read Coils</em> function should be enabled. */
-#define MB_FUNC_READ_COILS_ENABLED ( 1 )
-/*! \brief If the <em>Write Coils</em> function should be enabled. */
-#define MB_FUNC_WRITE_COIL_ENABLED ( 1 )
-/*! \brief If the <em>Write Multiple Coils</em> function should be enabled. */
-#define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED ( 1 )
-/*! \brief If the <em>Read Discrete Inputs</em> function should be enabled. */
-#define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED ( 1 )
-/*! \brief If the <em>Read/Write Multiple Registers</em> function should be enabled. */
-#define MB_FUNC_READWRITE_HOLDING_ENABLED ( 1 )
-/*! @} */
-#ifdef __cplusplus
- PR_END_EXTERN_C
-#endif
-
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-/*! \brief If master send a broadcast frame,the master will wait time of convert to delay,
- * then master can send other frame */
-#define MB_MASTER_DELAY_MS_CONVERT (200 )
-/*! \brief If master send a frame which is not broadcast,the master will wait sometime for slave.
- * And if slave is not respond in this time,the master will process this timeout error.
- * Then master can send other frame */
-#define MB_MASTER_TIMEOUT_MS_RESPOND (100 )
-/*! \brief The total slaves in Modbus Master system. Default 16.
- * \note : The slave ID must be continuous from 1.*/
-#define MB_MASTER_TOTAL_SLAVE_NUM ( 16 )
-#endif
-
-#endif
diff --git a/components/net/freemodbus/modbus/include/mbframe.h b/components/net/freemodbus/modbus/include/mbframe.h
deleted file mode 100644
index 99d59c613e..0000000000
--- a/components/net/freemodbus/modbus/include/mbframe.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbframe.h,v 1.9 2006/12/07 22:10:34 wolti Exp $
- */
-
-#ifndef _MB_FRAME_H
-#define _MB_FRAME_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-
-/*!
- * Constants which defines the format of a modbus frame. The example is
- * shown for a Modbus RTU/ASCII frame. Note that the Modbus PDU is not
- * dependent on the underlying transport.
- *
- * <code>
- * <------------------------ MODBUS SERIAL LINE PDU (1) ------------------->
- * <----------- MODBUS PDU (1') ---------------->
- * +-----------+---------------+----------------------------+-------------+
- * | Address | Function Code | Data | CRC/LRC |
- * +-----------+---------------+----------------------------+-------------+
- * | | | |
- * (2) (3/2') (3') (4)
- *
- * (1) ... MB_SER_PDU_SIZE_MAX = 256
- * (2) ... MB_SER_PDU_ADDR_OFF = 0
- * (3) ... MB_SER_PDU_PDU_OFF = 1
- * (4) ... MB_SER_PDU_SIZE_CRC = 2
- *
- * (1') ... MB_PDU_SIZE_MAX = 253
- * (2') ... MB_PDU_FUNC_OFF = 0
- * (3') ... MB_PDU_DATA_OFF = 1
- * </code>
- */
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_PDU_SIZE_MAX 253 /*!< Maximum size of a PDU. */
-#define MB_PDU_SIZE_MIN 1 /*!< Function Code */
-#define MB_PDU_FUNC_OFF 0 /*!< Offset of function code in PDU. */
-#define MB_PDU_DATA_OFF 1 /*!< Offset for response data in PDU. */
-
-/* ----------------------- Prototypes 0-------------------------------------*/
-typedef void ( *pvMBFrameStart ) ( void );
-
-typedef void ( *pvMBFrameStop ) ( void );
-
-typedef eMBErrorCode( *peMBFrameReceive ) ( UCHAR * pucRcvAddress,
- UCHAR ** pucFrame,
- USHORT * pusLength );
-
-typedef eMBErrorCode( *peMBFrameSend ) ( UCHAR slaveAddress,
- const UCHAR * pucFrame,
- USHORT usLength );
-
-typedef void( *pvMBFrameClose ) ( void );
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/include/mbfunc.h b/components/net/freemodbus/modbus/include/mbfunc.h
deleted file mode 100644
index 3f9c2725a1..0000000000
--- a/components/net/freemodbus/modbus/include/mbfunc.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbfunc.h,v 1.12 2006/12/07 22:10:34 wolti Exp $
- */
-
-#ifndef _MB_FUNC_H
-#define _MB_FUNC_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-#if MB_FUNC_OTHER_REP_SLAVEID_BUF > 0
-eMBException eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READ_INPUT_ENABLED > 0
-eMBException eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READ_HOLDING_ENABLED > 0
-eMBException eMBFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
-eMBException eMBFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
-eMBException eMBFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READ_COILS_ENABLED > 0
-eMBException eMBFuncReadCoils( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_WRITE_COIL_ENABLED > 0
-eMBException eMBFuncWriteCoil( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
-eMBException eMBFuncWriteMultipleCoils( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
-eMBException eMBFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
-eMBException eMBFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
-#endif
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/include/mbport.h b/components/net/freemodbus/modbus/include/mbport.h
deleted file mode 100644
index 11794a2929..0000000000
--- a/components/net/freemodbus/modbus/include/mbport.h
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbport.h,v 1.17 2006/12/07 22:10:34 wolti Exp $
- * mbport.h,v 1.60 2013/08/17 11:42:56 Armink Add Master Functions $
- */
-
-#ifndef _MB_PORT_H
-#define _MB_PORT_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-
-/* ----------------------- Defines ------------------------------------------*/
-
-/* ----------------------- Type definitions ---------------------------------*/
-
-typedef enum
-{
- EV_READY = 1<<0, /*!< Startup finished. */
- EV_FRAME_RECEIVED = 1<<1, /*!< Frame received. */
- EV_EXECUTE = 1<<2, /*!< Execute function. */
- EV_FRAME_SENT = 1<<3 /*!< Frame sent. */
-} eMBEventType;
-
-typedef enum
-{
- EV_MASTER_READY = 1<<0, /*!< Startup finished. */
- EV_MASTER_FRAME_RECEIVED = 1<<1, /*!< Frame received. */
- EV_MASTER_EXECUTE = 1<<2, /*!< Execute function. */
- EV_MASTER_FRAME_SENT = 1<<3, /*!< Frame sent. */
- EV_MASTER_ERROR_PROCESS = 1<<4, /*!< Frame error process. */
- EV_MASTER_PROCESS_SUCESS = 1<<5, /*!< Request process success. */
- EV_MASTER_ERROR_RESPOND_TIMEOUT = 1<<6, /*!< Request respond timeout. */
- EV_MASTER_ERROR_RECEIVE_DATA = 1<<7, /*!< Request receive data error. */
- EV_MASTER_ERROR_EXECUTE_FUNCTION = 1<<8, /*!< Request execute function error. */
-} eMBMasterEventType;
-
-typedef enum
-{
- EV_ERROR_RESPOND_TIMEOUT, /*!< Slave respond timeout. */
- EV_ERROR_RECEIVE_DATA, /*!< Receive frame data erroe. */
- EV_ERROR_EXECUTE_FUNCTION, /*!< Execute function error. */
-} eMBMasterErrorEventType;
-
-/*! \ingroup modbus
- * \brief Parity used for characters in serial mode.
- *
- * The parity which should be applied to the characters sent over the serial
- * link. Please note that this values are actually passed to the porting
- * layer and therefore not all parity modes might be available.
- */
-typedef enum
-{
- MB_PAR_NONE, /*!< No parity. */
- MB_PAR_ODD, /*!< Odd parity. */
- MB_PAR_EVEN /*!< Even parity. */
-} eMBParity;
-
-/* ----------------------- Supporting functions -----------------------------*/
-BOOL xMBPortEventInit( void );
-
-BOOL xMBPortEventPost( eMBEventType eEvent );
-
-BOOL xMBPortEventGet( /*@out@ */ eMBEventType * eEvent );
-
-BOOL xMBMasterPortEventInit( void );
-
-BOOL xMBMasterPortEventPost( eMBMasterEventType eEvent );
-
-BOOL xMBMasterPortEventGet( /*@out@ */ eMBMasterEventType * eEvent );
-
-void vMBMasterOsResInit( void );
-
-BOOL xMBMasterRunResTake( int32_t time );
-
-void vMBMasterRunResRelease( void );
-
-/* ----------------------- Serial port functions ----------------------------*/
-
-BOOL xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate,
- UCHAR ucDataBits, eMBParity eParity );
-
-void vMBPortClose( void );
-
-void xMBPortSerialClose( void );
-
-void vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable );
-
-INLINE BOOL xMBPortSerialGetByte( CHAR * pucByte );
-
-INLINE BOOL xMBPortSerialPutByte( CHAR ucByte );
-
-BOOL xMBMasterPortSerialInit( UCHAR ucPort, ULONG ulBaudRate,
- UCHAR ucDataBits, eMBParity eParity );
-
-void vMBMasterPortClose( void );
-
-void xMBMasterPortSerialClose( void );
-
-void vMBMasterPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable );
-
-INLINE BOOL xMBMasterPortSerialGetByte( CHAR * pucByte );
-
-INLINE BOOL xMBMasterPortSerialPutByte( CHAR ucByte );
-
-/* ----------------------- Timers functions ---------------------------------*/
-BOOL xMBPortTimersInit( USHORT usTimeOut50us );
-
-void xMBPortTimersClose( void );
-
-INLINE void vMBPortTimersEnable( void );
-
-INLINE void vMBPortTimersDisable( void );
-
-BOOL xMBMasterPortTimersInit( USHORT usTimeOut50us );
-
-void xMBMasterPortTimersClose( void );
-
-INLINE void vMBMasterPortTimersT35Enable( void );
-
-INLINE void vMBMasterPortTimersConvertDelayEnable( void );
-
-INLINE void vMBMasterPortTimersRespondTimeoutEnable( void );
-
-INLINE void vMBMasterPortTimersDisable( void );
-
-/* ----------------- Callback for the master error process ------------------*/
-void vMBMasterErrorCBRespondTimeout( UCHAR ucDestAddress, const UCHAR* pucPDUData,
- USHORT ucPDULength );
-
-void vMBMasterErrorCBReceiveData( UCHAR ucDestAddress, const UCHAR* pucPDUData,
- USHORT ucPDULength );
-
-void vMBMasterErrorCBExecuteFunction( UCHAR ucDestAddress, const UCHAR* pucPDUData,
- USHORT ucPDULength );
-
-void vMBMasterCBRequestScuuess( void );
-
-/* ----------------------- Callback for the protocol stack ------------------*/
-
-/*!
- * \brief Callback function for the porting layer when a new byte is
- * available.
- *
- * Depending upon the mode this callback function is used by the RTU or
- * ASCII transmission layers. In any case a call to xMBPortSerialGetByte()
- * must immediately return a new character.
- *
- * \return <code>TRUE</code> if a event was posted to the queue because
- * a new byte was received. The port implementation should wake up the
- * tasks which are currently blocked on the eventqueue.
- */
-extern BOOL( *pxMBFrameCBByteReceived ) ( void );
-
-extern BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
-
-extern BOOL( *pxMBPortCBTimerExpired ) ( void );
-
-extern BOOL( *pxMBMasterFrameCBByteReceived ) ( void );
-
-extern BOOL( *pxMBMasterFrameCBTransmitterEmpty ) ( void );
-
-extern BOOL( *pxMBMasterPortCBTimerExpired ) ( void );
-
-/* ----------------------- TCP port functions -------------------------------*/
-BOOL xMBTCPPortInit( USHORT usTCPPort );
-
-void vMBTCPPortClose( void );
-
-void vMBTCPPortDisable( void );
-
-BOOL xMBTCPPortGetRequest( UCHAR **ppucMBTCPFrame, USHORT * usTCPLength );
-
-BOOL xMBTCPPortSendResponse( const UCHAR *pucMBTCPFrame, USHORT usTCPLength );
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/include/mbproto.h b/components/net/freemodbus/modbus/include/mbproto.h
deleted file mode 100644
index 786aaf4030..0000000000
--- a/components/net/freemodbus/modbus/include/mbproto.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbproto.h,v 1.14 2006/12/07 22:10:34 wolti Exp $
- */
-
-#ifndef _MB_PROTO_H
-#define _MB_PROTO_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_ADDRESS_BROADCAST ( 0 ) /*! Modbus broadcast address. */
-#define MB_ADDRESS_MIN ( 1 ) /*! Smallest possible slave address. */
-#define MB_ADDRESS_MAX ( 247 ) /*! Biggest possible slave address. */
-#define MB_FUNC_NONE ( 0 )
-#define MB_FUNC_READ_COILS ( 1 )
-#define MB_FUNC_READ_DISCRETE_INPUTS ( 2 )
-#define MB_FUNC_WRITE_SINGLE_COIL ( 5 )
-#define MB_FUNC_WRITE_MULTIPLE_COILS ( 15 )
-#define MB_FUNC_READ_HOLDING_REGISTER ( 3 )
-#define MB_FUNC_READ_INPUT_REGISTER ( 4 )
-#define MB_FUNC_WRITE_REGISTER ( 6 )
-#define MB_FUNC_WRITE_MULTIPLE_REGISTERS ( 16 )
-#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS ( 23 )
-#define MB_FUNC_DIAG_READ_EXCEPTION ( 7 )
-#define MB_FUNC_DIAG_DIAGNOSTIC ( 8 )
-#define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 )
-#define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 )
-#define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 )
-#define MB_FUNC_ERROR ( 128 )
-/* ----------------------- Type definitions ---------------------------------*/
- typedef enum
-{
- MB_EX_NONE = 0x00,
- MB_EX_ILLEGAL_FUNCTION = 0x01,
- MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
- MB_EX_ILLEGAL_DATA_VALUE = 0x03,
- MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
- MB_EX_ACKNOWLEDGE = 0x05,
- MB_EX_SLAVE_BUSY = 0x06,
- MB_EX_MEMORY_PARITY_ERROR = 0x08,
- MB_EX_GATEWAY_PATH_FAILED = 0x0A,
- MB_EX_GATEWAY_TGT_FAILED = 0x0B
-} eMBException;
-
-typedef eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength );
-
-typedef struct
-{
- UCHAR ucFunctionCode;
- pxMBFunctionHandler pxHandler;
-} xMBFunctionHandler;
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/include/mbutils.h b/components/net/freemodbus/modbus/include/mbutils.h
deleted file mode 100644
index 61495751d4..0000000000
--- a/components/net/freemodbus/modbus/include/mbutils.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbutils.h,v 1.5 2006/12/07 22:10:34 wolti Exp $
- */
-
-#ifndef _MB_UTILS_H
-#define _MB_UTILS_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-/*! \defgroup modbus_utils Utilities
- *
- * This module contains some utility functions which can be used by
- * the application. It includes some special functions for working with
- * bitfields backed by a character array buffer.
- *
- */
-/*! \addtogroup modbus_utils
- * @{
- */
-/*! \brief Function to set bits in a byte buffer.
- *
- * This function allows the efficient use of an array to implement bitfields.
- * The array used for storing the bits must always be a multiple of two
- * bytes. Up to eight bits can be set or cleared in one operation.
- *
- * \param ucByteBuf A buffer where the bit values are stored. Must be a
- * multiple of 2 bytes. No length checking is performed and if
- * usBitOffset / 8 is greater than the size of the buffer memory contents
- * is overwritten.
- * \param usBitOffset The starting address of the bits to set. The first
- * bit has the offset 0.
- * \param ucNBits Number of bits to modify. The value must always be smaller
- * than 8.
- * \param ucValues Thew new values for the bits. The value for the first bit
- * starting at <code>usBitOffset</code> is the LSB of the value
- * <code>ucValues</code>
- *
- * \code
- * ucBits[2] = {0, 0};
- *
- * // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1)
- * xMBUtilSetBits( ucBits, 4, 1, 1 );
- *
- * // Set bit 7 to 1 and bit 8 to 0.
- * xMBUtilSetBits( ucBits, 7, 2, 0x01 );
- *
- * // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A;
- * xMBUtilSetBits( ucBits, 8, 8, 0x5A);
- * \endcode
- */
-void xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset,
- UCHAR ucNBits, UCHAR ucValues );
-
-/*! \brief Function to read bits in a byte buffer.
- *
- * This function is used to extract up bit values from an array. Up to eight
- * bit values can be extracted in one step.
- *
- * \param ucByteBuf A buffer where the bit values are stored.
- * \param usBitOffset The starting address of the bits to set. The first
- * bit has the offset 0.
- * \param ucNBits Number of bits to modify. The value must always be smaller
- * than 8.
- *
- * \code
- * UCHAR ucBits[2] = {0, 0};
- * UCHAR ucResult;
- *
- * // Extract the bits 3 - 10.
- * ucResult = xMBUtilGetBits( ucBits, 3, 8 );
- * \endcode
- */
-UCHAR xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset,
- UCHAR ucNBits );
-
-/*! @} */
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/mb.c b/components/net/freemodbus/modbus/mb.c
deleted file mode 100644
index 96d693c910..0000000000
--- a/components/net/freemodbus/modbus/mb.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mb.c,v 1.27 2007/02/18 23:45:41 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-
-#include "mb.h"
-#include "mbconfig.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbfunc.h"
-
-#include "mbport.h"
-#if MB_SLAVE_RTU_ENABLED == 1
-#include "mbrtu.h"
-#endif
-#if MB_SLAVE_ASCII_ENABLED == 1
-#include "mbascii.h"
-#endif
-#if MB_SLAVE_TCP_ENABLED == 1
-#include "mbtcp.h"
-#endif
-
-#ifndef MB_PORT_HAS_CLOSE
-#define MB_PORT_HAS_CLOSE 0
-#endif
-
-/* ----------------------- Static variables ---------------------------------*/
-
-static UCHAR ucMBAddress;
-static eMBMode eMBCurrentMode;
-
-static enum
-{
- STATE_ENABLED,
- STATE_DISABLED,
- STATE_NOT_INITIALIZED
-} eMBState = STATE_NOT_INITIALIZED;
-
-/* Functions pointer which are initialized in eMBInit( ). Depending on the
- * mode (RTU or ASCII) the are set to the correct implementations.
- * Using for Modbus Slave
- */
-static peMBFrameSend peMBFrameSendCur;
-static pvMBFrameStart pvMBFrameStartCur;
-static pvMBFrameStop pvMBFrameStopCur;
-static peMBFrameReceive peMBFrameReceiveCur;
-static pvMBFrameClose pvMBFrameCloseCur;
-
-/* Callback functions required by the porting layer. They are called when
- * an external event has happend which includes a timeout or the reception
- * or transmission of a character.
- * Using for Modbus Slave
- */
-BOOL( *pxMBFrameCBByteReceived ) ( void );
-BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
-BOOL( *pxMBPortCBTimerExpired ) ( void );
-
-BOOL( *pxMBFrameCBReceiveFSMCur ) ( void );
-BOOL( *pxMBFrameCBTransmitFSMCur ) ( void );
-
-/* An array of Modbus functions handlers which associates Modbus function
- * codes with implementing functions.
- */
-static xMBFunctionHandler xFuncHandlers[MB_FUNC_HANDLERS_MAX] = {
-#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
- {MB_FUNC_OTHER_REPORT_SLAVEID, eMBFuncReportSlaveID},
-#endif
-#if MB_FUNC_READ_INPUT_ENABLED > 0
- {MB_FUNC_READ_INPUT_REGISTER, eMBFuncReadInputRegister},
-#endif
-#if MB_FUNC_READ_HOLDING_ENABLED > 0
- {MB_FUNC_READ_HOLDING_REGISTER, eMBFuncReadHoldingRegister},
-#endif
-#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
- {MB_FUNC_WRITE_MULTIPLE_REGISTERS, eMBFuncWriteMultipleHoldingRegister},
-#endif
-#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
- {MB_FUNC_WRITE_REGISTER, eMBFuncWriteHoldingRegister},
-#endif
-#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
- {MB_FUNC_READWRITE_MULTIPLE_REGISTERS, eMBFuncReadWriteMultipleHoldingRegister},
-#endif
-#if MB_FUNC_READ_COILS_ENABLED > 0
- {MB_FUNC_READ_COILS, eMBFuncReadCoils},
-#endif
-#if MB_FUNC_WRITE_COIL_ENABLED > 0
- {MB_FUNC_WRITE_SINGLE_COIL, eMBFuncWriteCoil},
-#endif
-#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
- {MB_FUNC_WRITE_MULTIPLE_COILS, eMBFuncWriteMultipleCoils},
-#endif
-#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
- {MB_FUNC_READ_DISCRETE_INPUTS, eMBFuncReadDiscreteInputs},
-#endif
-};
-
-/* ----------------------- Start implementation -----------------------------*/
-eMBErrorCode
-eMBInit( eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- /* check preconditions */
- if( ( ucSlaveAddress == MB_ADDRESS_BROADCAST ) ||
- ( ucSlaveAddress < MB_ADDRESS_MIN ) || ( ucSlaveAddress > MB_ADDRESS_MAX ) )
- {
- eStatus = MB_EINVAL;
- }
- else
- {
- ucMBAddress = ucSlaveAddress;
-
- switch ( eMode )
- {
-#if MB_SLAVE_RTU_ENABLED > 0
- case MB_RTU:
- pvMBFrameStartCur = eMBRTUStart;
- pvMBFrameStopCur = eMBRTUStop;
- peMBFrameSendCur = eMBRTUSend;
- peMBFrameReceiveCur = eMBRTUReceive;
- pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBPortClose : NULL;
- pxMBFrameCBByteReceived = xMBRTUReceiveFSM;
- pxMBFrameCBTransmitterEmpty = xMBRTUTransmitFSM;
- pxMBPortCBTimerExpired = xMBRTUTimerT35Expired;
-
- eStatus = eMBRTUInit( ucMBAddress, ucPort, ulBaudRate, eParity );
- break;
-#endif
-#if MB_SLAVE_ASCII_ENABLED > 0
- case MB_ASCII:
- pvMBFrameStartCur = eMBASCIIStart;
- pvMBFrameStopCur = eMBASCIIStop;
- peMBFrameSendCur = eMBASCIISend;
- peMBFrameReceiveCur = eMBASCIIReceive;
- pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBPortClose : NULL;
- pxMBFrameCBByteReceived = xMBASCIIReceiveFSM;
- pxMBFrameCBTransmitterEmpty = xMBASCIITransmitFSM;
- pxMBPortCBTimerExpired = xMBASCIITimerT1SExpired;
-
- eStatus = eMBASCIIInit( ucMBAddress, ucPort, ulBaudRate, eParity );
- break;
-#endif
- default:
- eStatus = MB_EINVAL;
- break;
- }
-
- if( eStatus == MB_ENOERR )
- {
- if( !xMBPortEventInit( ) )
- {
- /* port dependent event module initalization failed. */
- eStatus = MB_EPORTERR;
- }
- else
- {
- eMBCurrentMode = eMode;
- eMBState = STATE_DISABLED;
- }
- }
- }
- return eStatus;
-}
-
-#if MB_SLAVE_TCP_ENABLED > 0
-eMBErrorCode
-eMBTCPInit( USHORT ucTCPPort )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- if( ( eStatus = eMBTCPDoInit( ucTCPPort ) ) != MB_ENOERR )
- {
- eMBState = STATE_DISABLED;
- }
- else if( !xMBPortEventInit( ) )
- {
- /* Port dependent event module initalization failed. */
- eStatus = MB_EPORTERR;
- }
- else
- {
- pvMBFrameStartCur = eMBTCPStart;
- pvMBFrameStopCur = eMBTCPStop;
- peMBFrameReceiveCur = eMBTCPReceive;
- peMBFrameSendCur = eMBTCPSend;
- pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBTCPPortClose : NULL;
- ucMBAddress = MB_TCP_PSEUDO_ADDRESS;
- eMBCurrentMode = MB_TCP;
- eMBState = STATE_DISABLED;
- }
- return eStatus;
-}
-#endif
-
-eMBErrorCode
-eMBRegisterCB( UCHAR ucFunctionCode, pxMBFunctionHandler pxHandler )
-{
- int i;
- eMBErrorCode eStatus;
-
- if( ( 0 < ucFunctionCode ) && ( ucFunctionCode <= 127 ) )
- {
- ENTER_CRITICAL_SECTION( );
- if( pxHandler != NULL )
- {
- for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
- {
- if( ( xFuncHandlers[i].pxHandler == NULL ) ||
- ( xFuncHandlers[i].pxHandler == pxHandler ) )
- {
- xFuncHandlers[i].ucFunctionCode = ucFunctionCode;
- xFuncHandlers[i].pxHandler = pxHandler;
- break;
- }
- }
- eStatus = ( i != MB_FUNC_HANDLERS_MAX ) ? MB_ENOERR : MB_ENORES;
- }
- else
- {
- for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
- {
- if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
- {
- xFuncHandlers[i].ucFunctionCode = 0;
- xFuncHandlers[i].pxHandler = NULL;
- break;
- }
- }
- /* Remove can't fail. */
- eStatus = MB_ENOERR;
- }
- EXIT_CRITICAL_SECTION( );
- }
- else
- {
- eStatus = MB_EINVAL;
- }
- return eStatus;
-}
-
-
-eMBErrorCode
-eMBClose( void )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- if( eMBState == STATE_DISABLED )
- {
- if( pvMBFrameCloseCur != NULL )
- {
- pvMBFrameCloseCur( );
- }
- }
- else
- {
- eStatus = MB_EILLSTATE;
- }
- return eStatus;
-}
-
-
-eMBErrorCode
-eMBEnable( void )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- if( eMBState == STATE_DISABLED )
- {
- /* Activate the protocol stack. */
- pvMBFrameStartCur( );
- eMBState = STATE_ENABLED;
- }
- else
- {
- eStatus = MB_EILLSTATE;
- }
- return eStatus;
-}
-
-eMBErrorCode
-eMBDisable( void )
-{
- eMBErrorCode eStatus;
-
- if( eMBState == STATE_ENABLED )
- {
- pvMBFrameStopCur( );
- eMBState = STATE_DISABLED;
- eStatus = MB_ENOERR;
- }
- else if( eMBState == STATE_DISABLED )
- {
- eStatus = MB_ENOERR;
- }
- else
- {
- eStatus = MB_EILLSTATE;
- }
- return eStatus;
-}
-
-eMBErrorCode eMBPoll( void )
-{
- static UCHAR *ucMBFrame;
- static UCHAR ucRcvAddress;
- static UCHAR ucFunctionCode;
- static USHORT usLength;
- static eMBException eException;
-
- int i;
- eMBErrorCode eStatus = MB_ENOERR;
- eMBEventType eEvent;
-
- /* Check if the protocol stack is ready. */
- if( eMBState != STATE_ENABLED )
- {
- return MB_EILLSTATE;
- }
-
- /* Check if there is a event available. If not return control to caller.
- * Otherwise we will handle the event. */
- if( xMBPortEventGet( &eEvent ) == TRUE )
- {
- switch ( eEvent )
- {
- case EV_READY:
- break;
-
- case EV_FRAME_RECEIVED:
- eStatus = peMBFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
- if( eStatus == MB_ENOERR )
- {
- /* Check if the frame is for us. If not ignore the frame. */
- if( ( ucRcvAddress == ucMBAddress ) || ( ucRcvAddress == MB_ADDRESS_BROADCAST ) )
- {
- ( void )xMBPortEventPost( EV_EXECUTE );
- }
- }
- break;
-
- case EV_EXECUTE:
- ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
- eException = MB_EX_ILLEGAL_FUNCTION;
- for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
- {
- /* No more function handlers registered. Abort. */
- if( xFuncHandlers[i].ucFunctionCode == 0 )
- {
- break;
- }
- else if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
- {
- eException = xFuncHandlers[i].pxHandler( ucMBFrame, &usLength );
- break;
- }
- }
-
- /* If the request was not sent to the broadcast address we
- * return a reply. */
- if( ucRcvAddress != MB_ADDRESS_BROADCAST )
- {
- if( eException != MB_EX_NONE )
- {
- /* An exception occured. Build an error frame. */
- usLength = 0;
- ucMBFrame[usLength++] = ( UCHAR )( ucFunctionCode | MB_FUNC_ERROR );
- ucMBFrame[usLength++] = eException;
- }
- eStatus = peMBFrameSendCur( ucMBAddress, ucMBFrame, usLength );
- }
- break;
-
- case EV_FRAME_SENT:
- break;
- }
- }
- return MB_ENOERR;
-}
diff --git a/components/net/freemodbus/modbus/mb_m.c b/components/net/freemodbus/modbus/mb_m.c
deleted file mode 100644
index 4e7c4b2b74..0000000000
--- a/components/net/freemodbus/modbus/mb_m.c
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (C) 2013 Armink <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbrtu_m.c,v 1.60 2013/08/20 11:18:10 Armink Add Master Functions $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-
-#include "mb.h"
-#include "mb_m.h"
-#include "mbconfig.h"
-#include "mbframe.h"
-#include "mbproto.h"
-#include "mbfunc.h"
-
-#include "mbport.h"
-#if MB_MASTER_RTU_ENABLED == 1
-#include "mbrtu.h"
-#endif
-#if MB_MASTER_ASCII_ENABLED == 1
-#include "mbascii.h"
-#endif
-#if MB_MASTER_TCP_ENABLED == 1
-#include "mbtcp.h"
-#endif
-
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-
-#ifndef MB_PORT_HAS_CLOSE
-#define MB_PORT_HAS_CLOSE 0
-#endif
-
-/* ----------------------- Static variables ---------------------------------*/
-
-static UCHAR ucMBMasterDestAddress;
-static BOOL xMBRunInMasterMode = FALSE;
-static eMBMasterErrorEventType eMBMasterCurErrorType;
-
-static enum
-{
- STATE_ENABLED,
- STATE_DISABLED,
- STATE_NOT_INITIALIZED
-} eMBState = STATE_NOT_INITIALIZED;
-
-/* Functions pointer which are initialized in eMBInit( ). Depending on the
- * mode (RTU or ASCII) the are set to the correct implementations.
- * Using for Modbus Master,Add by Armink 20130813
- */
-static peMBFrameSend peMBMasterFrameSendCur;
-static pvMBFrameStart pvMBMasterFrameStartCur;
-static pvMBFrameStop pvMBMasterFrameStopCur;
-static peMBFrameReceive peMBMasterFrameReceiveCur;
-static pvMBFrameClose pvMBMasterFrameCloseCur;
-
-/* Callback functions required by the porting layer. They are called when
- * an external event has happend which includes a timeout or the reception
- * or transmission of a character.
- * Using for Modbus Master,Add by Armink 20130813
- */
-BOOL( *pxMBMasterFrameCBByteReceived ) ( void );
-BOOL( *pxMBMasterFrameCBTransmitterEmpty ) ( void );
-BOOL( *pxMBMasterPortCBTimerExpired ) ( void );
-
-BOOL( *pxMBMasterFrameCBReceiveFSMCur ) ( void );
-BOOL( *pxMBMasterFrameCBTransmitFSMCur ) ( void );
-
-/* An array of Modbus functions handlers which associates Modbus function
- * codes with implementing functions.
- */
-static xMBFunctionHandler xMasterFuncHandlers[MB_FUNC_HANDLERS_MAX] = {
-#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
- //TODO Add Master function define
- {MB_FUNC_OTHER_REPORT_SLAVEID, eMBFuncReportSlaveID},
-#endif
-#if MB_FUNC_READ_INPUT_ENABLED > 0
- {MB_FUNC_READ_INPUT_REGISTER, eMBMasterFuncReadInputRegister},
-#endif
-#if MB_FUNC_READ_HOLDING_ENABLED > 0
- {MB_FUNC_READ_HOLDING_REGISTER, eMBMasterFuncReadHoldingRegister},
-#endif
-#if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0
- {MB_FUNC_WRITE_MULTIPLE_REGISTERS, eMBMasterFuncWriteMultipleHoldingRegister},
-#endif
-#if MB_FUNC_WRITE_HOLDING_ENABLED > 0
- {MB_FUNC_WRITE_REGISTER, eMBMasterFuncWriteHoldingRegister},
-#endif
-#if MB_FUNC_READWRITE_HOLDING_ENABLED > 0
- {MB_FUNC_READWRITE_MULTIPLE_REGISTERS, eMBMasterFuncReadWriteMultipleHoldingRegister},
-#endif
-#if MB_FUNC_READ_COILS_ENABLED > 0
- {MB_FUNC_READ_COILS, eMBMasterFuncReadCoils},
-#endif
-#if MB_FUNC_WRITE_COIL_ENABLED > 0
- {MB_FUNC_WRITE_SINGLE_COIL, eMBMasterFuncWriteCoil},
-#endif
-#if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0
- {MB_FUNC_WRITE_MULTIPLE_COILS, eMBMasterFuncWriteMultipleCoils},
-#endif
-#if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0
- {MB_FUNC_READ_DISCRETE_INPUTS, eMBMasterFuncReadDiscreteInputs},
-#endif
-};
-
-/* ----------------------- Start implementation -----------------------------*/
-eMBErrorCode
-eMBMasterInit( eMBMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- switch (eMode)
- {
-#if MB_MASTER_RTU_ENABLED > 0
- case MB_RTU:
- pvMBMasterFrameStartCur = eMBMasterRTUStart;
- pvMBMasterFrameStopCur = eMBMasterRTUStop;
- peMBMasterFrameSendCur = eMBMasterRTUSend;
- peMBMasterFrameReceiveCur = eMBMasterRTUReceive;
- pvMBMasterFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBMasterPortClose : NULL;
- pxMBMasterFrameCBByteReceived = xMBMasterRTUReceiveFSM;
- pxMBMasterFrameCBTransmitterEmpty = xMBMasterRTUTransmitFSM;
- pxMBMasterPortCBTimerExpired = xMBMasterRTUTimerExpired;
-
- eStatus = eMBMasterRTUInit(ucPort, ulBaudRate, eParity);
- break;
-#endif
-#if MB_MASTER_ASCII_ENABLED > 0
- case MB_ASCII:
- pvMBMasterFrameStartCur = eMBMasterASCIIStart;
- pvMBMasterFrameStopCur = eMBMasterASCIIStop;
- peMBMasterFrameSendCur = eMBMasterASCIISend;
- peMBMasterFrameReceiveCur = eMBMasterASCIIReceive;
- pvMBMasterFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBMasterPortClose : NULL;
- pxMBMasterFrameCBByteReceived = xMBMasterASCIIReceiveFSM;
- pxMBMasterFrameCBTransmitterEmpty = xMBMasterASCIITransmitFSM;
- pxMBMasterPortCBTimerExpired = xMBMasterASCIITimerT1SExpired;
-
- eStatus = eMBMasterASCIIInit(ucPort, ulBaudRate, eParity );
- break;
-#endif
- default:
- eStatus = MB_EINVAL;
- break;
- }
-
- if (eStatus == MB_ENOERR)
- {
- if (!xMBMasterPortEventInit())
- {
- /* port dependent event module initalization failed. */
- eStatus = MB_EPORTERR;
- }
- else
- {
- eMBState = STATE_DISABLED;
- }
- /* initialize the OS resource for modbus master. */
- vMBMasterOsResInit();
- }
- return eStatus;
-}
-
-eMBErrorCode
-eMBMasterClose( void )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- if( eMBState == STATE_DISABLED )
- {
- if( pvMBMasterFrameCloseCur != NULL )
- {
- pvMBMasterFrameCloseCur( );
- }
- }
- else
- {
- eStatus = MB_EILLSTATE;
- }
- return eStatus;
-}
-
-eMBErrorCode
-eMBMasterEnable( void )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- if( eMBState == STATE_DISABLED )
- {
- /* Activate the protocol stack. */
- pvMBMasterFrameStartCur( );
- eMBState = STATE_ENABLED;
- }
- else
- {
- eStatus = MB_EILLSTATE;
- }
- return eStatus;
-}
-
-eMBErrorCode
-eMBMasterDisable( void )
-{
- eMBErrorCode eStatus;
-
- if( eMBState == STATE_ENABLED )
- {
- pvMBMasterFrameStopCur( );
- eMBState = STATE_DISABLED;
- eStatus = MB_ENOERR;
- }
- else if( eMBState == STATE_DISABLED )
- {
- eStatus = MB_ENOERR;
- }
- else
- {
- eStatus = MB_EILLSTATE;
- }
- return eStatus;
-}
-
-eMBErrorCode
-eMBMasterPoll( void )
-{
- static UCHAR *ucMBFrame;
- static UCHAR ucRcvAddress;
- static UCHAR ucFunctionCode;
- static USHORT usLength;
- static eMBException eException;
-
- int i , j;
- eMBErrorCode eStatus = MB_ENOERR;
- eMBMasterEventType eEvent;
- eMBMasterErrorEventType errorType;
-
- /* Check if the protocol stack is ready. */
- if( eMBState != STATE_ENABLED )
- {
- return MB_EILLSTATE;
- }
-
- /* Check if there is a event available. If not return control to caller.
- * Otherwise we will handle the event. */
- if( xMBMasterPortEventGet( &eEvent ) == TRUE )
- {
- switch ( eEvent )
- {
- case EV_MASTER_READY:
- break;
-
- case EV_MASTER_FRAME_RECEIVED:
- eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
- /* Check if the frame is for us. If not ,send an error process event. */
- if ( ( eStatus == MB_ENOERR ) && ( ucRcvAddress == ucMBMasterGetDestAddress() ) )
- {
- ( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE );
- }
- else
- {
- vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
- ( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
- }
- break;
-
- case EV_MASTER_EXECUTE:
- ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
- eException = MB_EX_ILLEGAL_FUNCTION;
- /* If receive frame has exception .The receive function code highest bit is 1.*/
- if(ucFunctionCode >> 7) {
- eException = (eMBException)ucMBFrame[MB_PDU_DATA_OFF];
- }
- else
- {
- for (i = 0; i < MB_FUNC_HANDLERS_MAX; i++)
- {
- /* No more function handlers registered. Abort. */
- if (xMasterFuncHandlers[i].ucFunctionCode == 0) {
- break;
- }
- else if (xMasterFuncHandlers[i].ucFunctionCode == ucFunctionCode) {
- vMBMasterSetCBRunInMasterMode(TRUE);
- /* If master request is broadcast,
- * the master need execute function for all slave.
- */
- if ( xMBMasterRequestIsBroadcast() ) {
- usLength = usMBMasterGetPDUSndLength();
- for(j = 1; j <= MB_MASTER_TOTAL_SLAVE_NUM; j++){
- vMBMasterSetDestAddress(j);
- eException = xMasterFuncHandlers[i].pxHandler(ucMBFrame, &usLength);
- }
- }
- else {
- eException = xMasterFuncHandlers[i].pxHandler(ucMBFrame, &usLength);
- }
- vMBMasterSetCBRunInMasterMode(FALSE);
- break;
- }
- }
- }
- /* If master has exception ,Master will send error process.Otherwise the Master is idle.*/
- if (eException != MB_EX_NONE) {
- vMBMasterSetErrorType(EV_ERROR_EXECUTE_FUNCTION);
- ( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
- }
- else {
- vMBMasterCBRequestScuuess( );
- vMBMasterRunResRelease( );
- }
- break;
-
- case EV_MASTER_FRAME_SENT:
- /* Master is busy now. */
- vMBMasterGetPDUSndBuf( &ucMBFrame );
- eStatus = peMBMasterFrameSendCur( ucMBMasterGetDestAddress(), ucMBFrame, usMBMasterGetPDUSndLength() );
- break;
-
- case EV_MASTER_ERROR_PROCESS:
- /* Execute specified error process callback function. */
- errorType = eMBMasterGetErrorType();
- vMBMasterGetPDUSndBuf( &ucMBFrame );
- switch (errorType) {
- case EV_ERROR_RESPOND_TIMEOUT:
- vMBMasterErrorCBRespondTimeout(ucMBMasterGetDestAddress(),
- ucMBFrame, usMBMasterGetPDUSndLength());
- break;
- case EV_ERROR_RECEIVE_DATA:
- vMBMasterErrorCBReceiveData(ucMBMasterGetDestAddress(),
- ucMBFrame, usMBMasterGetPDUSndLength());
- break;
- case EV_ERROR_EXECUTE_FUNCTION:
- vMBMasterErrorCBExecuteFunction(ucMBMasterGetDestAddress(),
- ucMBFrame, usMBMasterGetPDUSndLength());
- break;
- }
- vMBMasterRunResRelease();
- break;
- }
- }
- return MB_ENOERR;
-}
-
-/* Get whether the Modbus Master is run in master mode.*/
-BOOL xMBMasterGetCBRunInMasterMode( void )
-{
- return xMBRunInMasterMode;
-}
-/* Set whether the Modbus Master is run in master mode.*/
-void vMBMasterSetCBRunInMasterMode( BOOL IsMasterMode )
-{
- xMBRunInMasterMode = IsMasterMode;
-}
-/* Get Modbus Master send destination address. */
-UCHAR ucMBMasterGetDestAddress( void )
-{
- return ucMBMasterDestAddress;
-}
-/* Set Modbus Master send destination address. */
-void vMBMasterSetDestAddress( UCHAR Address )
-{
- ucMBMasterDestAddress = Address;
-}
-/* Get Modbus Master current error event type. */
-eMBMasterErrorEventType eMBMasterGetErrorType( void )
-{
- return eMBMasterCurErrorType;
-}
-/* Set Modbus Master current error event type. */
-void vMBMasterSetErrorType( eMBMasterErrorEventType errorType )
-{
- eMBMasterCurErrorType = errorType;
-}
-
-
-
-#endif
diff --git a/components/net/freemodbus/modbus/rtu/mbcrc.c b/components/net/freemodbus/modbus/rtu/mbcrc.c
deleted file mode 100644
index 29b9ea765a..0000000000
--- a/components/net/freemodbus/modbus/rtu/mbcrc.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbcrc.c,v 1.7 2007/02/18 23:50:27 wolti Exp $
- */
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-static const UCHAR aucCRCHi[] = {
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
- 0x00, 0xC1, 0x81, 0x40
-};
-
-static const UCHAR aucCRCLo[] = {
- 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7,
- 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E,
- 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9,
- 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
- 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
- 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32,
- 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D,
- 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38,
- 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF,
- 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
- 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1,
- 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4,
- 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB,
- 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA,
- 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
- 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0,
- 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97,
- 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E,
- 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89,
- 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
- 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83,
- 0x41, 0x81, 0x80, 0x40
-};
-
-USHORT
-usMBCRC16( UCHAR * pucFrame, USHORT usLen )
-{
- UCHAR ucCRCHi = 0xFF;
- UCHAR ucCRCLo = 0xFF;
- int iIndex;
-
- while( usLen-- )
- {
- iIndex = ucCRCLo ^ *( pucFrame++ );
- ucCRCLo = ( UCHAR )( ucCRCHi ^ aucCRCHi[iIndex] );
- ucCRCHi = aucCRCLo[iIndex];
- }
- return ( USHORT )( ucCRCHi << 8 | ucCRCLo );
-}
diff --git a/components/net/freemodbus/modbus/rtu/mbcrc.h b/components/net/freemodbus/modbus/rtu/mbcrc.h
deleted file mode 100644
index db227763f1..0000000000
--- a/components/net/freemodbus/modbus/rtu/mbcrc.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbcrc.h,v 1.5 2006/12/07 22:10:34 wolti Exp $
- */
-
-#ifndef _MB_CRC_H
-#define _MB_CRC_H
-
-USHORT usMBCRC16( UCHAR * pucFrame, USHORT usLen );
-
-#endif
diff --git a/components/net/freemodbus/modbus/rtu/mbrtu.c b/components/net/freemodbus/modbus/rtu/mbrtu.c
deleted file mode 100644
index 40c29348ce..0000000000
--- a/components/net/freemodbus/modbus/rtu/mbrtu.c
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbrtu.c,v 1.18 2007/09/12 10:15:56 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbrtu.h"
-#include "mbframe.h"
-
-#include "mbcrc.h"
-#include "mbport.h"
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_SER_PDU_SIZE_MIN 4 /*!< Minimum size of a Modbus RTU frame. */
-#define MB_SER_PDU_SIZE_MAX 256 /*!< Maximum size of a Modbus RTU frame. */
-#define MB_SER_PDU_SIZE_CRC 2 /*!< Size of CRC field in PDU. */
-#define MB_SER_PDU_ADDR_OFF 0 /*!< Offset of slave address in Ser-PDU. */
-#define MB_SER_PDU_PDU_OFF 1 /*!< Offset of Modbus-PDU in Ser-PDU. */
-
-/* ----------------------- Type definitions ---------------------------------*/
-typedef enum
-{
- STATE_RX_INIT, /*!< Receiver is in initial state. */
- STATE_RX_IDLE, /*!< Receiver is in idle state. */
- STATE_RX_RCV, /*!< Frame is beeing received. */
- STATE_RX_ERROR /*!< If the frame is invalid. */
-} eMBRcvState;
-
-typedef enum
-{
- STATE_TX_IDLE, /*!< Transmitter is in idle state. */
- STATE_TX_XMIT /*!< Transmitter is in transfer state. */
-} eMBSndState;
-
-/* ----------------------- Static variables ---------------------------------*/
-static volatile eMBSndState eSndState;
-static volatile eMBRcvState eRcvState;
-
-volatile UCHAR ucRTUBuf[MB_SER_PDU_SIZE_MAX];
-
-static volatile UCHAR *pucSndBufferCur;
-static volatile USHORT usSndBufferCount;
-
-static volatile USHORT usRcvBufferPos;
-
-/* ----------------------- Start implementation -----------------------------*/
-eMBErrorCode
-eMBRTUInit( UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- ULONG usTimerT35_50us;
-
- ( void )ucSlaveAddress;
- ENTER_CRITICAL_SECTION( );
-
- /* Modbus RTU uses 8 Databits. */
- if( xMBPortSerialInit( ucPort, ulBaudRate, 8, eParity ) != TRUE )
- {
- eStatus = MB_EPORTERR;
- }
- else
- {
- /* If baudrate > 19200 then we should use the fixed timer values
- * t35 = 1750us. Otherwise t35 must be 3.5 times the character time.
- */
- if( ulBaudRate > 19200 )
- {
- usTimerT35_50us = 35; /* 1800us. */
- }
- else
- {
- /* The timer reload value for a character is given by:
- *
- * ChTimeValue = Ticks_per_1s / ( Baudrate / 11 )
- * = 11 * Ticks_per_1s / Baudrate
- * = 220000 / Baudrate
- * The reload for t3.5 is 1.5 times this value and similary
- * for t3.5.
- */
- usTimerT35_50us = ( 7UL * 220000UL ) / ( 2UL * ulBaudRate );
- }
- if( xMBPortTimersInit( ( USHORT ) usTimerT35_50us ) != TRUE )
- {
- eStatus = MB_EPORTERR;
- }
- }
- EXIT_CRITICAL_SECTION( );
-
- return eStatus;
-}
-
-void
-eMBRTUStart( void )
-{
- ENTER_CRITICAL_SECTION( );
- /* Initially the receiver is in the state STATE_RX_INIT. we start
- * the timer and if no character is received within t3.5 we change
- * to STATE_RX_IDLE. This makes sure that we delay startup of the
- * modbus protocol stack until the bus is free.
- */
- eRcvState = STATE_RX_INIT;
- vMBPortSerialEnable( TRUE, FALSE );
- vMBPortTimersEnable( );
-
- EXIT_CRITICAL_SECTION( );
-}
-
-void
-eMBRTUStop( void )
-{
- ENTER_CRITICAL_SECTION( );
- vMBPortSerialEnable( FALSE, FALSE );
- vMBPortTimersDisable( );
- EXIT_CRITICAL_SECTION( );
-}
-
-eMBErrorCode
-eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- ENTER_CRITICAL_SECTION( );
- RT_ASSERT( usRcvBufferPos <= MB_SER_PDU_SIZE_MAX );
-
- /* Length and CRC check */
- if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
- && ( usMBCRC16( ( UCHAR * ) ucRTUBuf, usRcvBufferPos ) == 0 ) )
- {
- /* Save the address field. All frames are passed to the upper layed
- * and the decision if a frame is used is done there.
- */
- *pucRcvAddress = ucRTUBuf[MB_SER_PDU_ADDR_OFF];
-
- /* Total length of Modbus-PDU is Modbus-Serial-Line-PDU minus
- * size of address field and CRC checksum.
- */
- *pusLength = ( USHORT )( usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC );
-
- /* Return the start of the Modbus PDU to the caller. */
- *pucFrame = ( UCHAR * ) & ucRTUBuf[MB_SER_PDU_PDU_OFF];
- }
- else
- {
- eStatus = MB_EIO;
- }
-
- EXIT_CRITICAL_SECTION( );
- return eStatus;
-}
-
-eMBErrorCode
-eMBRTUSend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT usCRC16;
-
- ENTER_CRITICAL_SECTION( );
-
- /* Check if the receiver is still in idle state. If not we where to
- * slow with processing the received frame and the master sent another
- * frame on the network. We have to abort sending the frame.
- */
- if( eRcvState == STATE_RX_IDLE )
- {
- /* First byte before the Modbus-PDU is the slave address. */
- pucSndBufferCur = ( UCHAR * ) pucFrame - 1;
- usSndBufferCount = 1;
-
- /* Now copy the Modbus-PDU into the Modbus-Serial-Line-PDU. */
- pucSndBufferCur[MB_SER_PDU_ADDR_OFF] = ucSlaveAddress;
- usSndBufferCount += usLength;
-
- /* Calculate CRC16 checksum for Modbus-Serial-Line-PDU. */
- usCRC16 = usMBCRC16( ( UCHAR * ) pucSndBufferCur, usSndBufferCount );
- ucRTUBuf[usSndBufferCount++] = ( UCHAR )( usCRC16 & 0xFF );
- ucRTUBuf[usSndBufferCount++] = ( UCHAR )( usCRC16 >> 8 );
-
- /* Activate the transmitter. */
- eSndState = STATE_TX_XMIT;
- vMBPortSerialEnable( FALSE, TRUE );
- }
- else
- {
- eStatus = MB_EIO;
- }
- EXIT_CRITICAL_SECTION( );
- return eStatus;
-}
-
-BOOL
-xMBRTUReceiveFSM( void )
-{
- BOOL xTaskNeedSwitch = FALSE;
- UCHAR ucByte;
-
- RT_ASSERT( eSndState == STATE_TX_IDLE );
-
- /* Always read the character. */
- ( void )xMBPortSerialGetByte( ( CHAR * ) & ucByte );
-
- switch ( eRcvState )
- {
- /* If we have received a character in the init state we have to
- * wait until the frame is finished.
- */
- case STATE_RX_INIT:
- vMBPortTimersEnable( );
- break;
-
- /* In the error state we wait until all characters in the
- * damaged frame are transmitted.
- */
- case STATE_RX_ERROR:
- vMBPortTimersEnable( );
- break;
-
- /* In the idle state we wait for a new character. If a character
- * is received the t1.5 and t3.5 timers are started and the
- * receiver is in the state STATE_RX_RECEIVCE.
- */
- case STATE_RX_IDLE:
- usRcvBufferPos = 0;
- ucRTUBuf[usRcvBufferPos++] = ucByte;
- eRcvState = STATE_RX_RCV;
-
- /* Enable t3.5 timers. */
- vMBPortTimersEnable( );
- break;
-
- /* We are currently receiving a frame. Reset the timer after
- * every character received. If more than the maximum possible
- * number of bytes in a modbus frame is received the frame is
- * ignored.
- */
- case STATE_RX_RCV:
- if( usRcvBufferPos < MB_SER_PDU_SIZE_MAX )
- {
- ucRTUBuf[usRcvBufferPos++] = ucByte;
- }
- else
- {
- eRcvState = STATE_RX_ERROR;
- }
- vMBPortTimersEnable();
- break;
- }
- return xTaskNeedSwitch;
-}
-
-BOOL
-xMBRTUTransmitFSM( void )
-{
- BOOL xNeedPoll = FALSE;
-
- RT_ASSERT( eRcvState == STATE_RX_IDLE );
-
- switch ( eSndState )
- {
- /* We should not get a transmitter event if the transmitter is in
- * idle state. */
- case STATE_TX_IDLE:
- /* enable receiver/disable transmitter. */
- vMBPortSerialEnable( TRUE, FALSE );
- break;
-
- case STATE_TX_XMIT:
- /* check if we are finished. */
- if( usSndBufferCount != 0 )
- {
- xMBPortSerialPutByte( ( CHAR )*pucSndBufferCur );
- pucSndBufferCur++; /* next byte in sendbuffer. */
- usSndBufferCount--;
- }
- else
- {
- xNeedPoll = xMBPortEventPost( EV_FRAME_SENT );
- /* Disable transmitter. This prevents another transmit buffer
- * empty interrupt. */
- vMBPortSerialEnable( TRUE, FALSE );
- eSndState = STATE_TX_IDLE;
- }
- break;
- }
-
- return xNeedPoll;
-}
-
-BOOL
-xMBRTUTimerT35Expired( void )
-{
- BOOL xNeedPoll = FALSE;
-
- switch ( eRcvState )
- {
- /* Timer t35 expired. Startup phase is finished. */
- case STATE_RX_INIT:
- xNeedPoll = xMBPortEventPost( EV_READY );
- break;
-
- /* A frame was received and t35 expired. Notify the listener that
- * a new frame was received. */
- case STATE_RX_RCV:
- xNeedPoll = xMBPortEventPost( EV_FRAME_RECEIVED );
- break;
-
- /* An error occured while receiving the frame. */
- case STATE_RX_ERROR:
- break;
-
- /* Function called in an illegal state. */
- default:
- RT_ASSERT( ( eRcvState == STATE_RX_INIT ) ||
- ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
- break;
- }
-
- vMBPortTimersDisable( );
- eRcvState = STATE_RX_IDLE;
-
- return xNeedPoll;
-}
diff --git a/components/net/freemodbus/modbus/rtu/mbrtu.h b/components/net/freemodbus/modbus/rtu/mbrtu.h
deleted file mode 100644
index 98c43de4aa..0000000000
--- a/components/net/freemodbus/modbus/rtu/mbrtu.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbrtu.h,v 1.9 2006/12/07 22:10:34 wolti Exp $
- * File: $Id: mbrtu.h,v 1.60 2013/08/17 13:11:42 Armink Add Master Functions $
- */
-#include "mbconfig.h"
-
-#ifndef _MB_RTU_H
-#define _MB_RTU_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-eMBErrorCode eMBRTUInit( UCHAR slaveAddress, UCHAR ucPort, ULONG ulBaudRate,
- eMBParity eParity );
-void eMBRTUStart( void );
-void eMBRTUStop( void );
-eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength );
-eMBErrorCode eMBRTUSend( UCHAR slaveAddress, const UCHAR * pucFrame, USHORT usLength );
-BOOL xMBRTUReceiveFSM( void );
-BOOL xMBRTUTransmitFSM( void );
-BOOL xMBRTUTimerT15Expired( void );
-BOOL xMBRTUTimerT35Expired( void );
-
-#if MB_MASTER_RTU_ENABLED > 0
-eMBErrorCode eMBMasterRTUInit( UCHAR ucPort, ULONG ulBaudRate,eMBParity eParity );
-void eMBMasterRTUStart( void );
-void eMBMasterRTUStop( void );
-eMBErrorCode eMBMasterRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength );
-eMBErrorCode eMBMasterRTUSend( UCHAR slaveAddress, const UCHAR * pucFrame, USHORT usLength );
-BOOL xMBMasterRTUReceiveFSM( void );
-BOOL xMBMasterRTUTransmitFSM( void );
-BOOL xMBMasterRTUTimerExpired( void );
-#endif
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/modbus/rtu/mbrtu_m.c b/components/net/freemodbus/modbus/rtu/mbrtu_m.c
deleted file mode 100644
index 0c024e2b09..0000000000
--- a/components/net/freemodbus/modbus/rtu/mbrtu_m.c
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2013 China Beijing Armink <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbrtu_m.c,v 1.60 2013/08/17 11:42:56 Armink Add Master Functions $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mb_m.h"
-#include "mbrtu.h"
-#include "mbframe.h"
-
-#include "mbcrc.h"
-#include "mbport.h"
-
-#if MB_MASTER_RTU_ENABLED > 0
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_SER_PDU_SIZE_MIN 4 /*!< Minimum size of a Modbus RTU frame. */
-#define MB_SER_PDU_SIZE_MAX 256 /*!< Maximum size of a Modbus RTU frame. */
-#define MB_SER_PDU_SIZE_CRC 2 /*!< Size of CRC field in PDU. */
-#define MB_SER_PDU_ADDR_OFF 0 /*!< Offset of slave address in Ser-PDU. */
-#define MB_SER_PDU_PDU_OFF 1 /*!< Offset of Modbus-PDU in Ser-PDU. */
-
-/* ----------------------- Type definitions ---------------------------------*/
-typedef enum
-{
- STATE_M_RX_INIT, /*!< Receiver is in initial state. */
- STATE_M_RX_IDLE, /*!< Receiver is in idle state. */
- STATE_M_RX_RCV, /*!< Frame is beeing received. */
- STATE_M_RX_ERROR, /*!< If the frame is invalid. */
-} eMBMasterRcvState;
-
-typedef enum
-{
- STATE_M_TX_IDLE, /*!< Transmitter is in idle state. */
- STATE_M_TX_XMIT, /*!< Transmitter is in transfer state. */
- STATE_M_TX_XFWR, /*!< Transmitter is in transfer finish and wait receive state. */
-} eMBMasterSndState;
-
-/* ----------------------- Static variables ---------------------------------*/
-static volatile eMBMasterSndState eSndState;
-static volatile eMBMasterRcvState eRcvState;
-
-static volatile UCHAR ucMasterRTUSndBuf[MB_PDU_SIZE_MAX];
-static volatile UCHAR ucMasterRTURcvBuf[MB_SER_PDU_SIZE_MAX];
-static volatile USHORT usMasterSendPDULength;
-
-static volatile UCHAR *pucMasterSndBufferCur;
-static volatile USHORT usMasterSndBufferCount;
-
-static volatile USHORT usMasterRcvBufferPos;
-static volatile BOOL xFrameIsBroadcast = FALSE;
-
-static volatile eMBMasterTimerMode eMasterCurTimerMode;
-
-/* ----------------------- Start implementation -----------------------------*/
-eMBErrorCode
-eMBMasterRTUInit(UCHAR ucPort, ULONG ulBaudRate, eMBParity eParity )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- ULONG usTimerT35_50us;
-
- ENTER_CRITICAL_SECTION( );
-
- /* Modbus RTU uses 8 Databits. */
- if( xMBMasterPortSerialInit( ucPort, ulBaudRate, 8, eParity ) != TRUE )
- {
- eStatus = MB_EPORTERR;
- }
- else
- {
- /* If baudrate > 19200 then we should use the fixed timer values
- * t35 = 1750us. Otherwise t35 must be 3.5 times the character time.
- */
- if( ulBaudRate > 19200 )
- {
- usTimerT35_50us = 35; /* 1800us. */
- }
- else
- {
- /* The timer reload value for a character is given by:
- *
- * ChTimeValue = Ticks_per_1s / ( Baudrate / 11 )
- * = 11 * Ticks_per_1s / Baudrate
- * = 220000 / Baudrate
- * The reload for t3.5 is 1.5 times this value and similary
- * for t3.5.
- */
- usTimerT35_50us = ( 7UL * 220000UL ) / ( 2UL * ulBaudRate );
- }
- if( xMBMasterPortTimersInit( ( USHORT ) usTimerT35_50us ) != TRUE )
- {
- eStatus = MB_EPORTERR;
- }
- }
- EXIT_CRITICAL_SECTION( );
-
- return eStatus;
-}
-
-void
-eMBMasterRTUStart( void )
-{
- ENTER_CRITICAL_SECTION( );
- /* Initially the receiver is in the state STATE_M_RX_INIT. we start
- * the timer and if no character is received within t3.5 we change
- * to STATE_M_RX_IDLE. This makes sure that we delay startup of the
- * modbus protocol stack until the bus is free.
- */
- eRcvState = STATE_M_RX_INIT;
- vMBMasterPortSerialEnable( TRUE, FALSE );
- vMBMasterPortTimersT35Enable( );
-
- EXIT_CRITICAL_SECTION( );
-}
-
-void
-eMBMasterRTUStop( void )
-{
- ENTER_CRITICAL_SECTION( );
- vMBMasterPortSerialEnable( FALSE, FALSE );
- vMBMasterPortTimersDisable( );
- EXIT_CRITICAL_SECTION( );
-}
-
-eMBErrorCode
-eMBMasterRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- ENTER_CRITICAL_SECTION( );
- RT_ASSERT( usMasterRcvBufferPos < MB_SER_PDU_SIZE_MAX );
-
- /* Length and CRC check */
- if( ( usMasterRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
- && ( usMBCRC16( ( UCHAR * ) ucMasterRTURcvBuf, usMasterRcvBufferPos ) == 0 ) )
- {
- /* Save the address field. All frames are passed to the upper layed
- * and the decision if a frame is used is done there.
- */
- *pucRcvAddress = ucMasterRTURcvBuf[MB_SER_PDU_ADDR_OFF];
-
- /* Total length of Modbus-PDU is Modbus-Serial-Line-PDU minus
- * size of address field and CRC checksum.
- */
- *pusLength = ( USHORT )( usMasterRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC );
-
- /* Return the start of the Modbus PDU to the caller. */
- *pucFrame = ( UCHAR * ) & ucMasterRTURcvBuf[MB_SER_PDU_PDU_OFF];
- }
- else
- {
- eStatus = MB_EIO;
- }
-
- EXIT_CRITICAL_SECTION( );
- return eStatus;
-}
-
-eMBErrorCode
-eMBMasterRTUSend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT usCRC16;
-
- if ( ucSlaveAddress > MB_MASTER_TOTAL_SLAVE_NUM ) return MB_EINVAL;
-
- ENTER_CRITICAL_SECTION( );
-
- /* Check if the receiver is still in idle state. If not we where to
- * slow with processing the received frame and the master sent another
- * frame on the network. We have to abort sending the frame.
- */
- if( eRcvState == STATE_M_RX_IDLE )
- {
- /* First byte before the Modbus-PDU is the slave address. */
- pucMasterSndBufferCur = ( UCHAR * ) pucFrame - 1;
- usMasterSndBufferCount = 1;
-
- /* Now copy the Modbus-PDU into the Modbus-Serial-Line-PDU. */
- pucMasterSndBufferCur[MB_SER_PDU_ADDR_OFF] = ucSlaveAddress;
- usMasterSndBufferCount += usLength;
-
- /* Calculate CRC16 checksum for Modbus-Serial-Line-PDU. */
- usCRC16 = usMBCRC16( ( UCHAR * ) pucMasterSndBufferCur, usMasterSndBufferCount );
- ucMasterRTUSndBuf[usMasterSndBufferCount++] = ( UCHAR )( usCRC16 & 0xFF );
- ucMasterRTUSndBuf[usMasterSndBufferCount++] = ( UCHAR )( usCRC16 >> 8 );
-
- /* Activate the transmitter. */
- eSndState = STATE_M_TX_XMIT;
- vMBMasterPortSerialEnable( FALSE, TRUE );
- }
- else
- {
- eStatus = MB_EIO;
- }
- EXIT_CRITICAL_SECTION( );
- return eStatus;
-}
-
-BOOL
-xMBMasterRTUReceiveFSM( void )
-{
- BOOL xTaskNeedSwitch = FALSE;
- UCHAR ucByte;
-
- RT_ASSERT(( eSndState == STATE_M_TX_IDLE ) || ( eSndState == STATE_M_TX_XFWR ));
-
- /* Always read the character. */
- ( void )xMBMasterPortSerialGetByte( ( CHAR * ) & ucByte );
-
- switch ( eRcvState )
- {
- /* If we have received a character in the init state we have to
- * wait until the frame is finished.
- */
- case STATE_M_RX_INIT:
- vMBMasterPortTimersT35Enable( );
- break;
-
- /* In the error state we wait until all characters in the
- * damaged frame are transmitted.
- */
- case STATE_M_RX_ERROR:
- vMBMasterPortTimersT35Enable( );
- break;
-
- /* In the idle state we wait for a new character. If a character
- * is received the t1.5 and t3.5 timers are started and the
- * receiver is in the state STATE_RX_RECEIVCE and disable early
- * the timer of respond timeout .
- */
- case STATE_M_RX_IDLE:
- /* In time of respond timeout,the receiver receive a frame.
- * Disable timer of respond timeout and change the transmiter state to idle.
- */
- vMBMasterPortTimersDisable( );
- eSndState = STATE_M_TX_IDLE;
-
- usMasterRcvBufferPos = 0;
- ucMasterRTURcvBuf[usMasterRcvBufferPos++] = ucByte;
- eRcvState = STATE_M_RX_RCV;
-
- /* Enable t3.5 timers. */
- vMBMasterPortTimersT35Enable( );
- break;
-
- /* We are currently receiving a frame. Reset the timer after
- * every character received. If more than the maximum possible
- * number of bytes in a modbus frame is received the frame is
- * ignored.
- */
- case STATE_M_RX_RCV:
- if( usMasterRcvBufferPos < MB_SER_PDU_SIZE_MAX )
- {
- ucMasterRTURcvBuf[usMasterRcvBufferPos++] = ucByte;
- }
- else
- {
- eRcvState = STATE_M_RX_ERROR;
- }
- vMBMasterPortTimersT35Enable();
- break;
- }
- return xTaskNeedSwitch;
-}
-
-BOOL
-xMBMasterRTUTransmitFSM( void )
-{
- BOOL xNeedPoll = FALSE;
-
- RT_ASSERT( eRcvState == STATE_M_RX_IDLE );
-
- switch ( eSndState )
- {
- /* We should not get a transmitter event if the transmitter is in
- * idle state. */
- case STATE_M_TX_IDLE:
- /* enable receiver/disable transmitter. */
- vMBMasterPortSerialEnable( TRUE, FALSE );
- break;
-
- case STATE_M_TX_XMIT:
- /* check if we are finished. */
- if( usMasterSndBufferCount != 0 )
- {
- xMBMasterPortSerialPutByte( ( CHAR )*pucMasterSndBufferCur );
- pucMasterSndBufferCur++; /* next byte in sendbuffer. */
- usMasterSndBufferCount--;
- }
- else
- {
- xFrameIsBroadcast = ( ucMasterRTUSndBuf[MB_SER_PDU_ADDR_OFF] == MB_ADDRESS_BROADCAST ) ? TRUE : FALSE;
- /* Disable transmitter. This prevents another transmit buffer
- * empty interrupt. */
- vMBMasterPortSerialEnable( TRUE, FALSE );
- eSndState = STATE_M_TX_XFWR;
- /* If the frame is broadcast ,master will enable timer of convert delay,
- * else master will enable timer of respond timeout. */
- if ( xFrameIsBroadcast == TRUE )
- {
- vMBMasterPortTimersConvertDelayEnable( );
- }
- else
- {
- vMBMasterPortTimersRespondTimeoutEnable( );
- }
- }
- break;
- }
-
- return xNeedPoll;
-}
-
-BOOL
-xMBMasterRTUTimerExpired(void)
-{
- BOOL xNeedPoll = FALSE;
-
- switch (eRcvState)
- {
- /* Timer t35 expired. Startup phase is finished. */
- case STATE_M_RX_INIT:
- xNeedPoll = xMBMasterPortEventPost(EV_MASTER_READY);
- break;
-
- /* A frame was received and t35 expired. Notify the listener that
- * a new frame was received. */
- case STATE_M_RX_RCV:
- xNeedPoll = xMBMasterPortEventPost(EV_MASTER_FRAME_RECEIVED);
- break;
-
- /* An error occured while receiving the frame. */
- case STATE_M_RX_ERROR:
- vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
- xNeedPoll = xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
- break;
-
- /* Function called in an illegal state. */
- default:
- RT_ASSERT(
- ( eRcvState == STATE_M_RX_INIT ) || ( eRcvState == STATE_M_RX_RCV ) ||
- ( eRcvState == STATE_M_RX_ERROR ) || ( eRcvState == STATE_M_RX_IDLE ));
- break;
- }
- eRcvState = STATE_M_RX_IDLE;
-
- switch (eSndState)
- {
- /* A frame was send finish and convert delay or respond timeout expired.
- * If the frame is broadcast,The master will idle,and if the frame is not
- * broadcast.Notify the listener process error.*/
- case STATE_M_TX_XFWR:
- if ( xFrameIsBroadcast == FALSE ) {
- vMBMasterSetErrorType(EV_ERROR_RESPOND_TIMEOUT);
- xNeedPoll = xMBMasterPortEventPost(EV_MASTER_ERROR_PROCESS);
- }
- break;
- /* Function called in an illegal state. */
- default:
- RT_ASSERT(
- ( eSndState == STATE_M_TX_XFWR ) || ( eSndState == STATE_M_TX_IDLE ));
- break;
- }
- eSndState = STATE_M_TX_IDLE;
-
- vMBMasterPortTimersDisable( );
- /* If timer mode is convert delay, the master event then turns EV_MASTER_EXECUTE status. */
- if (eMasterCurTimerMode == MB_TMODE_CONVERT_DELAY) {
- xNeedPoll = xMBMasterPortEventPost( EV_MASTER_EXECUTE );
- }
-
- return xNeedPoll;
-}
-
-/* Get Modbus Master send RTU's buffer address pointer.*/
-void vMBMasterGetRTUSndBuf( UCHAR ** pucFrame )
-{
- *pucFrame = ( UCHAR * ) ucMasterRTUSndBuf;
-}
-
-/* Get Modbus Master send PDU's buffer address pointer.*/
-void vMBMasterGetPDUSndBuf( UCHAR ** pucFrame )
-{
- *pucFrame = ( UCHAR * ) &ucMasterRTUSndBuf[MB_SER_PDU_PDU_OFF];
-}
-
-/* Set Modbus Master send PDU's buffer length.*/
-void vMBMasterSetPDUSndLength( USHORT SendPDULength )
-{
- usMasterSendPDULength = SendPDULength;
-}
-
-/* Get Modbus Master send PDU's buffer length.*/
-USHORT usMBMasterGetPDUSndLength( void )
-{
- return usMasterSendPDULength;
-}
-
-/* Set Modbus Master current timer mode.*/
-void vMBMasterSetCurTimerMode( eMBMasterTimerMode eMBTimerMode )
-{
- eMasterCurTimerMode = eMBTimerMode;
-}
-
-/* The master request is broadcast? */
-BOOL xMBMasterRequestIsBroadcast( void ){
- return xFrameIsBroadcast;
-}
-#endif
-
diff --git a/components/net/freemodbus/modbus/tcp/mbtcp.c b/components/net/freemodbus/modbus/tcp/mbtcp.c
deleted file mode 100644
index 3eb3b7071f..0000000000
--- a/components/net/freemodbus/modbus/tcp/mbtcp.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbtcp.c,v 1.3 2006/12/07 22:10:34 wolti Exp $
- */
-
-/* ----------------------- System includes ----------------------------------*/
-#include "stdlib.h"
-#include "string.h"
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbconfig.h"
-#include "mbtcp.h"
-#include "mbframe.h"
-#include "mbport.h"
-
-#if MB_SLAVE_TCP_ENABLED > 0
-
-/* ----------------------- Defines ------------------------------------------*/
-
-/* ----------------------- MBAP Header --------------------------------------*/
-/*
- *
- * <------------------------ MODBUS TCP/IP ADU(1) ------------------------->
- * <----------- MODBUS PDU (1') ---------------->
- * +-----------+---------------+------------------------------------------+
- * | TID | PID | Length | UID |Code | Data |
- * +-----------+---------------+------------------------------------------+
- * | | | | |
- * (2) (3) (4) (5) (6)
- *
- * (2) ... MB_TCP_TID = 0 (Transaction Identifier - 2 Byte)
- * (3) ... MB_TCP_PID = 2 (Protocol Identifier - 2 Byte)
- * (4) ... MB_TCP_LEN = 4 (Number of bytes - 2 Byte)
- * (5) ... MB_TCP_UID = 6 (Unit Identifier - 1 Byte)
- * (6) ... MB_TCP_FUNC = 7 (Modbus Function Code)
- *
- * (1) ... Modbus TCP/IP Application Data Unit
- * (1') ... Modbus Protocol Data Unit
- */
-
-#define MB_TCP_TID 0
-#define MB_TCP_PID 2
-#define MB_TCP_LEN 4
-#define MB_TCP_UID 6
-#define MB_TCP_FUNC 7
-
-#define MB_TCP_PROTOCOL_ID 0 /* 0 = Modbus Protocol */
-
-
-/* ----------------------- Start implementation -----------------------------*/
-eMBErrorCode
-eMBTCPDoInit( USHORT ucTCPPort )
-{
- eMBErrorCode eStatus = MB_ENOERR;
-
- if( xMBTCPPortInit( ucTCPPort ) == FALSE )
- {
- eStatus = MB_EPORTERR;
- }
- return eStatus;
-}
-
-void
-eMBTCPStart( void )
-{
-}
-
-void
-eMBTCPStop( void )
-{
- /* Make sure that no more clients are connected. */
- vMBTCPPortDisable( );
-}
-
-eMBErrorCode
-eMBTCPReceive( UCHAR * pucRcvAddress, UCHAR ** ppucFrame, USHORT * pusLength )
-{
- eMBErrorCode eStatus = MB_EIO;
- UCHAR *pucMBTCPFrame;
- USHORT usLength;
- USHORT usPID;
-
- if( xMBTCPPortGetRequest( &pucMBTCPFrame, &usLength ) != FALSE )
- {
- usPID = pucMBTCPFrame[MB_TCP_PID] << 8U;
- usPID |= pucMBTCPFrame[MB_TCP_PID + 1];
-
- if( usPID == MB_TCP_PROTOCOL_ID )
- {
- *ppucFrame = &pucMBTCPFrame[MB_TCP_FUNC];
- *pusLength = usLength - MB_TCP_FUNC;
- eStatus = MB_ENOERR;
-
- /* Modbus TCP does not use any addresses. Fake the source address such
- * that the processing part deals with this frame.
- */
- *pucRcvAddress = MB_TCP_PSEUDO_ADDRESS;
- }
- }
- else
- {
- eStatus = MB_EIO;
- }
- return eStatus;
-}
-
-eMBErrorCode
-eMBTCPSend( UCHAR _unused, const UCHAR * pucFrame, USHORT usLength )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- UCHAR *pucMBTCPFrame = ( UCHAR * ) pucFrame - MB_TCP_FUNC;
- USHORT usTCPLength = usLength + MB_TCP_FUNC;
-
- /* The MBAP header is already initialized because the caller calls this
- * function with the buffer returned by the previous call. Therefore we
- * only have to update the length in the header. Note that the length
- * header includes the size of the Modbus PDU and the UID Byte. Therefore
- * the length is usLength plus one.
- */
- pucMBTCPFrame[MB_TCP_LEN] = ( usLength + 1 ) >> 8U;
- pucMBTCPFrame[MB_TCP_LEN + 1] = ( usLength + 1 ) & 0xFF;
- if( xMBTCPPortSendResponse( pucMBTCPFrame, usTCPLength ) == FALSE )
- {
- eStatus = MB_EIO;
- }
- return eStatus;
-}
-
-#endif
diff --git a/components/net/freemodbus/modbus/tcp/mbtcp.h b/components/net/freemodbus/modbus/tcp/mbtcp.h
deleted file mode 100644
index 905d113c5a..0000000000
--- a/components/net/freemodbus/modbus/tcp/mbtcp.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
- * Copyright (c) 2006 Christian Walter <[email protected]>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * File: $Id: mbtcp.h,v 1.2 2006/12/07 22:10:34 wolti Exp $
- */
-
-#ifndef _MB_TCP_H
-#define _MB_TCP_H
-
-#ifdef __cplusplus
-PR_BEGIN_EXTERN_C
-#endif
-
-/* ----------------------- Defines ------------------------------------------*/
-#define MB_TCP_PSEUDO_ADDRESS 255
-
-/* ----------------------- Function prototypes ------------------------------*/
- eMBErrorCode eMBTCPDoInit( USHORT ucTCPPort );
-void eMBTCPStart( void );
-void eMBTCPStop( void );
-eMBErrorCode eMBTCPReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame,
- USHORT * pusLength );
-eMBErrorCode eMBTCPSend( UCHAR _unused, const UCHAR * pucFrame,
- USHORT usLength );
-
-#ifdef __cplusplus
-PR_END_EXTERN_C
-#endif
-#endif
diff --git a/components/net/freemodbus/port/port.c b/components/net/freemodbus/port/port.c
deleted file mode 100644
index d01c5c9d6a..0000000000
--- a/components/net/freemodbus/port/port.c
+++ /dev/null
@@ -1,38 +0,0 @@
- /*
- * FreeModbus Libary: RT-Thread Port
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: port.c,v 1.60 2015/02/01 9:18:05 Armink $
- */
-
-/* ----------------------- System includes --------------------------------*/
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "port.h"
-/* ----------------------- Variables ----------------------------------------*/
-static rt_base_t level;
-/* ----------------------- Start implementation -----------------------------*/
-void EnterCriticalSection(void)
-{
- level = rt_hw_interrupt_disable();
-}
-
-void ExitCriticalSection(void)
-{
- rt_hw_interrupt_enable(level);
-}
-
diff --git a/components/net/freemodbus/port/port.h b/components/net/freemodbus/port/port.h
deleted file mode 100644
index 97b648a8bb..0000000000
--- a/components/net/freemodbus/port/port.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * FreeModbus Libary: BARE Port
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: port.h ,v 1.60 2013/08/13 15:07:05 Armink add Master Functions $
- */
-
-#ifndef _PORT_H
-#define _PORT_H
-
-#include "mbconfig.h"
-#include <rthw.h>
-#include <rtthread.h>
-
-#include <assert.h>
-#include <inttypes.h>
-
-#define INLINE
-#define PR_BEGIN_EXTERN_C extern "C" {
-#define PR_END_EXTERN_C }
-
-#define ENTER_CRITICAL_SECTION() EnterCriticalSection()
-#define EXIT_CRITICAL_SECTION() ExitCriticalSection()
-
-typedef uint8_t BOOL;
-
-typedef unsigned char UCHAR;
-typedef char CHAR;
-
-typedef uint16_t USHORT;
-typedef int16_t SHORT;
-
-typedef uint32_t ULONG;
-typedef int32_t LONG;
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-void EnterCriticalSection(void);
-void ExitCriticalSection(void);
-
-#endif
diff --git a/components/net/freemodbus/port/portevent.c b/components/net/freemodbus/port/portevent.c
deleted file mode 100644
index 1a881166be..0000000000
--- a/components/net/freemodbus/port/portevent.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * FreeModbus Libary: RT-Thread Port
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: portevent.c,v 1.60 2013/08/13 15:07:05 Armink $
- */
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbport.h"
-
-/* ----------------------- Variables ----------------------------------------*/
-static struct rt_event xSlaveOsEvent;
-/* ----------------------- Start implementation -----------------------------*/
-BOOL
-xMBPortEventInit( void )
-{
- rt_event_init(&xSlaveOsEvent,"slave event",RT_IPC_FLAG_PRIO);
- return TRUE;
-}
-
-BOOL
-xMBPortEventPost( eMBEventType eEvent )
-{
- rt_event_send(&xSlaveOsEvent, eEvent);
- return TRUE;
-}
-
-BOOL
-xMBPortEventGet( eMBEventType * eEvent )
-{
- rt_uint32_t recvedEvent;
- /* waiting forever OS event */
- rt_event_recv(&xSlaveOsEvent,
- EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE | EV_FRAME_SENT,
- RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
- &recvedEvent);
- switch (recvedEvent)
- {
- case EV_READY:
- *eEvent = EV_READY;
- break;
- case EV_FRAME_RECEIVED:
- *eEvent = EV_FRAME_RECEIVED;
- break;
- case EV_EXECUTE:
- *eEvent = EV_EXECUTE;
- break;
- case EV_FRAME_SENT:
- *eEvent = EV_FRAME_SENT;
- break;
- }
- return TRUE;
-}
diff --git a/components/net/freemodbus/port/portevent_m.c b/components/net/freemodbus/port/portevent_m.c
deleted file mode 100644
index 031a3b84ef..0000000000
--- a/components/net/freemodbus/port/portevent_m.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * FreeModbus Libary: RT-Thread Port
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: portevent_m.c v 1.60 2013/08/13 15:07:05 Armink add Master Functions$
- */
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mb_m.h"
-#include "mbport.h"
-#include "port.h"
-
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-/* ----------------------- Defines ------------------------------------------*/
-/* ----------------------- Variables ----------------------------------------*/
-static struct rt_semaphore xMasterRunRes;
-static struct rt_event xMasterOsEvent;
-/* ----------------------- Start implementation -----------------------------*/
-BOOL
-xMBMasterPortEventInit( void )
-{
- rt_event_init(&xMasterOsEvent,"master event",RT_IPC_FLAG_PRIO);
- return TRUE;
-}
-
-BOOL
-xMBMasterPortEventPost( eMBMasterEventType eEvent )
-{
- rt_event_send(&xMasterOsEvent, eEvent);
- return TRUE;
-}
-
-BOOL
-xMBMasterPortEventGet( eMBMasterEventType * eEvent )
-{
- rt_uint32_t recvedEvent;
- /* waiting forever OS event */
- rt_event_recv(&xMasterOsEvent,
- EV_MASTER_READY | EV_MASTER_FRAME_RECEIVED | EV_MASTER_EXECUTE |
- EV_MASTER_FRAME_SENT | EV_MASTER_ERROR_PROCESS,
- RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
- &recvedEvent);
- /* the enum type couldn't convert to int type */
- switch (recvedEvent)
- {
- case EV_MASTER_READY:
- *eEvent = EV_MASTER_READY;
- break;
- case EV_MASTER_FRAME_RECEIVED:
- *eEvent = EV_MASTER_FRAME_RECEIVED;
- break;
- case EV_MASTER_EXECUTE:
- *eEvent = EV_MASTER_EXECUTE;
- break;
- case EV_MASTER_FRAME_SENT:
- *eEvent = EV_MASTER_FRAME_SENT;
- break;
- case EV_MASTER_ERROR_PROCESS:
- *eEvent = EV_MASTER_ERROR_PROCESS;
- break;
- }
- return TRUE;
-}
-/**
- * This function is initialize the OS resource for modbus master.
- * Note:The resource is define by OS.If you not use OS this function can be empty.
- *
- */
-void vMBMasterOsResInit( void )
-{
- rt_sem_init(&xMasterRunRes, "master res", 0x01 , RT_IPC_FLAG_PRIO);
-}
-
-/**
- * This function is take Mobus Master running resource.
- * Note:The resource is define by Operating System.If you not use OS this function can be just return TRUE.
- *
- * @param lTimeOut the waiting time.
- *
- * @return resource taked result
- */
-BOOL xMBMasterRunResTake( LONG lTimeOut )
-{
- /*If waiting time is -1 .It will wait forever */
- return rt_sem_take(&xMasterRunRes, lTimeOut) ? FALSE : TRUE ;
-}
-
-/**
- * This function is release Mobus Master running resource.
- * Note:The resource is define by Operating System.If you not use OS this function can be empty.
- *
- */
-void vMBMasterRunResRelease( void )
-{
- /* release resource */
- rt_sem_release(&xMasterRunRes);
-}
-
-/**
- * This is modbus master respond timeout error process callback function.
- * @note There functions will block modbus master poll while execute OS waiting.
- * So,for real-time of system.Do not execute too much waiting process.
- *
- * @param ucDestAddress destination salve address
- * @param pucPDUData PDU buffer data
- * @param ucPDULength PDU buffer length
- *
- */
-void vMBMasterErrorCBRespondTimeout(UCHAR ucDestAddress, const UCHAR* pucPDUData,
- USHORT ucPDULength) {
- /**
- * @note This code is use OS's event mechanism for modbus master protocol stack.
- * If you don't use OS, you can change it.
- */
- rt_event_send(&xMasterOsEvent, EV_MASTER_ERROR_RESPOND_TIMEOUT);
-
- /* You can add your code under here. */
-
-}
-
-/**
- * This is modbus master receive data error process callback function.
- * @note There functions will block modbus master poll while execute OS waiting.
- * So,for real-time of system.Do not execute too much waiting process.
- *
- * @param ucDestAddress destination salve address
- * @param pucPDUData PDU buffer data
- * @param ucPDULength PDU buffer length
- *
- */
-void vMBMasterErrorCBReceiveData(UCHAR ucDestAddress, const UCHAR* pucPDUData,
- USHORT ucPDULength) {
- /**
- * @note This code is use OS's event mechanism for modbus master protocol stack.
- * If you don't use OS, you can change it.
- */
- rt_event_send(&xMasterOsEvent, EV_MASTER_ERROR_RECEIVE_DATA);
-
- /* You can add your code under here. */
-
-}
-
-/**
- * This is modbus master execute function error process callback function.
- * @note There functions will block modbus master poll while execute OS waiting.
- * So,for real-time of system.Do not execute too much waiting process.
- *
- * @param ucDestAddress destination salve address
- * @param pucPDUData PDU buffer data
- * @param ucPDULength PDU buffer length
- *
- */
-void vMBMasterErrorCBExecuteFunction(UCHAR ucDestAddress, const UCHAR* pucPDUData,
- USHORT ucPDULength) {
- /**
- * @note This code is use OS's event mechanism for modbus master protocol stack.
- * If you don't use OS, you can change it.
- */
- rt_event_send(&xMasterOsEvent, EV_MASTER_ERROR_EXECUTE_FUNCTION);
-
- /* You can add your code under here. */
-
-}
-
-/**
- * This is modbus master request process success callback function.
- * @note There functions will block modbus master poll while execute OS waiting.
- * So,for real-time of system.Do not execute too much waiting process.
- *
- */
-void vMBMasterCBRequestScuuess( void ) {
- /**
- * @note This code is use OS's event mechanism for modbus master protocol stack.
- * If you don't use OS, you can change it.
- */
- rt_event_send(&xMasterOsEvent, EV_MASTER_PROCESS_SUCESS);
-
- /* You can add your code under here. */
-
-}
-
-/**
- * This function is wait for modbus master request finish and return result.
- * Waiting result include request process success, request respond timeout,
- * receive data error and execute function error.You can use the above callback function.
- * @note If you are use OS, you can use OS's event mechanism. Otherwise you have to run
- * much user custom delay for waiting.
- *
- * @return request error code
- */
-eMBMasterReqErrCode eMBMasterWaitRequestFinish( void ) {
- eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
- rt_uint32_t recvedEvent;
- /* waiting for OS event */
- rt_event_recv(&xMasterOsEvent,
- EV_MASTER_PROCESS_SUCESS | EV_MASTER_ERROR_RESPOND_TIMEOUT
- | EV_MASTER_ERROR_RECEIVE_DATA
- | EV_MASTER_ERROR_EXECUTE_FUNCTION,
- RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,
- &recvedEvent);
- switch (recvedEvent)
- {
- case EV_MASTER_PROCESS_SUCESS:
- break;
- case EV_MASTER_ERROR_RESPOND_TIMEOUT:
- {
- eErrStatus = MB_MRE_TIMEDOUT;
- break;
- }
- case EV_MASTER_ERROR_RECEIVE_DATA:
- {
- eErrStatus = MB_MRE_REV_DATA;
- break;
- }
- case EV_MASTER_ERROR_EXECUTE_FUNCTION:
- {
- eErrStatus = MB_MRE_EXE_FUN;
- break;
- }
- }
- return eErrStatus;
-}
-
-#endif
diff --git a/components/net/freemodbus/port/portserial.c b/components/net/freemodbus/port/portserial.c
deleted file mode 100644
index cbd846d7ff..0000000000
--- a/components/net/freemodbus/port/portserial.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * FreeModbus Libary: RT-Thread Port
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: portserial.c,v 1.60 2013/08/13 15:07:05 Armink $
- */
-
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbport.h"
-#include "rtdevice.h"
-#include "board.h"
-
-/* ----------------------- Static variables ---------------------------------*/
-ALIGN(RT_ALIGN_SIZE)
-/* software simulation serial transmit IRQ handler thread stack */
-static rt_uint8_t serial_soft_trans_irq_stack[512];
-/* software simulation serial transmit IRQ handler thread */
-static struct rt_thread thread_serial_soft_trans_irq;
-/* serial event */
-static struct rt_event event_serial;
-/* modbus slave serial device */
-static rt_serial_t *serial;
-
-/* ----------------------- Defines ------------------------------------------*/
-/* serial transmit event */
-#define EVENT_SERIAL_TRANS_START (1<<0)
-
-/* ----------------------- static functions ---------------------------------*/
-static void prvvUARTTxReadyISR(void);
-static void prvvUARTRxISR(void);
-static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size);
-static void serial_soft_trans_irq(void* parameter);
-
-/* ----------------------- Start implementation -----------------------------*/
-BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
- eMBParity eParity)
-{
- rt_device_t dev = RT_NULL;
- char uart_name[20];
- /**
- * set 485 mode receive and transmit control IO
- * @note MODBUS_SLAVE_RT_CONTROL_PIN_INDEX need be defined by user
- */
-#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
- rt_pin_mode(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
-#endif
- /* set serial name */
- rt_snprintf(uart_name,sizeof(uart_name), "uart%d", ucPORT);
-
- dev = rt_device_find(uart_name);
- if(dev == RT_NULL)
- {
- /* can not find uart */
- return FALSE;
- }
- else
- {
- serial = (struct rt_serial_device*)dev;
- }
-
- /* set serial configure parameter */
- serial->config.baud_rate = ulBaudRate;
- serial->config.stop_bits = STOP_BITS_1;
- switch(eParity){
- case MB_PAR_NONE: {
- serial->config.data_bits = DATA_BITS_8;
- serial->config.parity = PARITY_NONE;
- break;
- }
- case MB_PAR_ODD: {
- serial->config.data_bits = DATA_BITS_9;
- serial->config.parity = PARITY_ODD;
- break;
- }
- case MB_PAR_EVEN: {
- serial->config.data_bits = DATA_BITS_9;
- serial->config.parity = PARITY_EVEN;
- break;
- }
- }
- /* set serial configure */
- serial->ops->configure(serial, &(serial->config));
-
- /* open serial device */
- if (!rt_device_open(&serial->parent, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX)) {
- rt_device_set_rx_indicate(&serial->parent, serial_rx_ind);
- } else {
- return FALSE;
- }
-
- /* software initialize */
- rt_event_init(&event_serial, "slave event", RT_IPC_FLAG_PRIO);
- rt_thread_init(&thread_serial_soft_trans_irq,
- "slave trans",
- serial_soft_trans_irq,
- RT_NULL,
- serial_soft_trans_irq_stack,
- sizeof(serial_soft_trans_irq_stack),
- 10, 5);
- rt_thread_startup(&thread_serial_soft_trans_irq);
-
- return TRUE;
-}
-
-void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
-{
- rt_uint32_t recved_event;
- if (xRxEnable)
- {
- /* enable RX interrupt */
- serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
- /* switch 485 to receive mode */
-#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
- rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_LOW);
-#endif
- }
- else
- {
- /* switch 485 to transmit mode */
-#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
- rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);
-#endif
- /* disable RX interrupt */
- serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
- }
- if (xTxEnable)
- {
- /* start serial transmit */
- rt_event_send(&event_serial, EVENT_SERIAL_TRANS_START);
- }
- else
- {
- /* stop serial transmit */
- rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START,
- RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 0,
- &recved_event);
- }
-}
-
-void vMBPortClose(void)
-{
- serial->parent.close(&(serial->parent));
-}
-
-BOOL xMBPortSerialPutByte(CHAR ucByte)
-{
- serial->parent.write(&(serial->parent), 0, &ucByte, 1);
- return TRUE;
-}
-
-BOOL xMBPortSerialGetByte(CHAR * pucByte)
-{
- serial->parent.read(&(serial->parent), 0, pucByte, 1);
- return TRUE;
-}
-
-/*
- * Create an interrupt handler for the transmit buffer empty interrupt
- * (or an equivalent) for your target processor. This function should then
- * call pxMBFrameCBTransmitterEmpty( ) which tells the protocol stack that
- * a new character can be sent. The protocol stack will then call
- * xMBPortSerialPutByte( ) to send the character.
- */
-void prvvUARTTxReadyISR(void)
-{
- pxMBFrameCBTransmitterEmpty();
-}
-
-/*
- * Create an interrupt handler for the receive interrupt for your target
- * processor. This function should then call pxMBFrameCBByteReceived( ). The
- * protocol stack will then call xMBPortSerialGetByte( ) to retrieve the
- * character.
- */
-void prvvUARTRxISR(void)
-{
- pxMBFrameCBByteReceived();
-}
-
-/**
- * Software simulation serial transmit IRQ handler.
- *
- * @param parameter parameter
- */
-static void serial_soft_trans_irq(void* parameter) {
- rt_uint32_t recved_event;
- while (1)
- {
- /* waiting for serial transmit start */
- rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR,
- RT_WAITING_FOREVER, &recved_event);
- /* execute modbus callback */
- prvvUARTTxReadyISR();
- }
-}
-
-/**
- * This function is serial receive callback function
- *
- * @param dev the device of serial
- * @param size the data size that receive
- *
- * @return return RT_EOK
- */
-static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size) {
- prvvUARTRxISR();
- return RT_EOK;
-}
diff --git a/components/net/freemodbus/port/portserial_m.c b/components/net/freemodbus/port/portserial_m.c
deleted file mode 100644
index 47a70dd905..0000000000
--- a/components/net/freemodbus/port/portserial_m.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * FreeModbus Libary: RT-Thread Port
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: portserial_m.c,v 1.60 2013/08/13 15:07:05 Armink add Master Functions $
- */
-
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbport.h"
-#include "rtdevice.h"
-#include "board.h"
-
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-/* ----------------------- Static variables ---------------------------------*/
-ALIGN(RT_ALIGN_SIZE)
-/* software simulation serial transmit IRQ handler thread stack */
-static rt_uint8_t serial_soft_trans_irq_stack[512];
-/* software simulation serial transmit IRQ handler thread */
-static struct rt_thread thread_serial_soft_trans_irq;
-/* serial event */
-static struct rt_event event_serial;
-/* modbus master serial device */
-static rt_serial_t *serial;
-
-/* ----------------------- Defines ------------------------------------------*/
-/* serial transmit event */
-#define EVENT_SERIAL_TRANS_START (1<<0)
-
-/* ----------------------- static functions ---------------------------------*/
-static void prvvUARTTxReadyISR(void);
-static void prvvUARTRxISR(void);
-static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size);
-static void serial_soft_trans_irq(void* parameter);
-
-/* ----------------------- Start implementation -----------------------------*/
-BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
- eMBParity eParity)
-{
- rt_device_t dev = RT_NULL;
- char uart_name[20];
-
- /**
- * set 485 mode receive and transmit control IO
- * @note MODBUS_MASTER_RT_CONTROL_PIN_INDEX need be defined by user
- */
-#if defined(RT_MODBUS_MASTER_USE_CONTROL_PIN)
- rt_pin_mode(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
-#endif
- /* set serial name */
- rt_snprintf(uart_name,sizeof(uart_name), "uart%d", ucPORT);
-
- dev = rt_device_find(uart_name);
- if(dev == RT_NULL)
- {
- /* can not find uart */
- return FALSE;
- }
- else
- {
- serial = (struct rt_serial_device*)dev;
- }
-
- /* set serial configure parameter */
- serial->config.baud_rate = ulBaudRate;
- serial->config.stop_bits = STOP_BITS_1;
- switch(eParity){
- case MB_PAR_NONE: {
- serial->config.data_bits = DATA_BITS_8;
- serial->config.parity = PARITY_NONE;
- break;
- }
- case MB_PAR_ODD: {
- serial->config.data_bits = DATA_BITS_9;
- serial->config.parity = PARITY_ODD;
- break;
- }
- case MB_PAR_EVEN: {
- serial->config.data_bits = DATA_BITS_9;
- serial->config.parity = PARITY_EVEN;
- break;
- }
- }
- /* set serial configure */
- serial->ops->configure(serial, &(serial->config));
-
- /* open serial device */
- if (!rt_device_open(&serial->parent, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX)) {
- rt_device_set_rx_indicate(&serial->parent, serial_rx_ind);
- } else {
- return FALSE;
- }
-
- /* software initialize */
- rt_event_init(&event_serial, "master event", RT_IPC_FLAG_PRIO);
- rt_thread_init(&thread_serial_soft_trans_irq,
- "master trans",
- serial_soft_trans_irq,
- RT_NULL,
- serial_soft_trans_irq_stack,
- sizeof(serial_soft_trans_irq_stack),
- 10, 5);
- rt_thread_startup(&thread_serial_soft_trans_irq);
-
- return TRUE;
-}
-
-void vMBMasterPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
-{
- rt_uint32_t recved_event;
- if (xRxEnable)
- {
- /* enable RX interrupt */
- serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
- /* switch 485 to receive mode */
-#if defined(RT_MODBUS_MASTER_USE_CONTROL_PIN)
- rt_pin_write(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_LOW);
-#endif
- }
- else
- {
- /* switch 485 to transmit mode */
-#if defined(RT_MODBUS_MASTER_USE_CONTROL_PIN)
- rt_pin_write(MODBUS_MASTER_RT_CONTROL_PIN_INDEX, PIN_HIGH);
-#endif
- /* disable RX interrupt */
- serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
- }
- if (xTxEnable)
- {
- /* start serial transmit */
- rt_event_send(&event_serial, EVENT_SERIAL_TRANS_START);
- }
- else
- {
- /* stop serial transmit */
- rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START,
- RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 0,
- &recved_event);
- }
-}
-
-void vMBMasterPortClose(void)
-{
- serial->parent.close(&(serial->parent));
-}
-
-BOOL xMBMasterPortSerialPutByte(CHAR ucByte)
-{
- serial->parent.write(&(serial->parent), 0, &ucByte, 1);
- return TRUE;
-}
-
-BOOL xMBMasterPortSerialGetByte(CHAR * pucByte)
-{
- serial->parent.read(&(serial->parent), 0, pucByte, 1);
- return TRUE;
-}
-
-/*
- * Create an interrupt handler for the transmit buffer empty interrupt
- * (or an equivalent) for your target processor. This function should then
- * call pxMBFrameCBTransmitterEmpty( ) which tells the protocol stack that
- * a new character can be sent. The protocol stack will then call
- * xMBPortSerialPutByte( ) to send the character.
- */
-void prvvUARTTxReadyISR(void)
-{
- pxMBMasterFrameCBTransmitterEmpty();
-}
-
-/*
- * Create an interrupt handler for the receive interrupt for your target
- * processor. This function should then call pxMBFrameCBByteReceived( ). The
- * protocol stack will then call xMBPortSerialGetByte( ) to retrieve the
- * character.
- */
-void prvvUARTRxISR(void)
-{
- pxMBMasterFrameCBByteReceived();
-}
-
-/**
- * Software simulation serial transmit IRQ handler.
- *
- * @param parameter parameter
- */
-static void serial_soft_trans_irq(void* parameter) {
- rt_uint32_t recved_event;
- while (1)
- {
- /* waiting for serial transmit start */
- rt_event_recv(&event_serial, EVENT_SERIAL_TRANS_START, RT_EVENT_FLAG_OR,
- RT_WAITING_FOREVER, &recved_event);
- /* execute modbus callback */
- prvvUARTTxReadyISR();
- }
-}
-
-/**
- * This function is serial receive callback function
- *
- * @param dev the device of serial
- * @param size the data size that receive
- *
- * @return return RT_EOK
- */
-static rt_err_t serial_rx_ind(rt_device_t dev, rt_size_t size) {
- prvvUARTRxISR();
- return RT_EOK;
-}
-
-#endif
diff --git a/components/net/freemodbus/port/porttimer.c b/components/net/freemodbus/port/porttimer.c
deleted file mode 100644
index 8c51ad06d5..0000000000
--- a/components/net/freemodbus/port/porttimer.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * FreeModbus Libary: RT-Thread Port
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: porttimer.c,v 1.60 2013/08/13 15:07:05 Armink $
- */
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mbport.h"
-
-/* ----------------------- static functions ---------------------------------*/
-static struct rt_timer timer;
-static void prvvTIMERExpiredISR(void);
-static void timer_timeout_ind(void* parameter);
-
-/* ----------------------- Start implementation -----------------------------*/
-BOOL xMBPortTimersInit(USHORT usTim1Timerout50us)
-{
- rt_timer_init(&timer, "slave timer",
- timer_timeout_ind, /* bind timeout callback function */
- RT_NULL,
- (50 * usTim1Timerout50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1,
- RT_TIMER_FLAG_ONE_SHOT); /* one shot */
- return TRUE;
-}
-
-void vMBPortTimersEnable()
-{
- rt_timer_start(&timer);
-}
-
-void vMBPortTimersDisable()
-{
- rt_timer_stop(&timer);
-}
-
-void prvvTIMERExpiredISR(void)
-{
- (void) pxMBPortCBTimerExpired();
-}
-
-static void timer_timeout_ind(void* parameter)
-{
- prvvTIMERExpiredISR();
-}
diff --git a/components/net/freemodbus/port/porttimer_m.c b/components/net/freemodbus/port/porttimer_m.c
deleted file mode 100644
index ebf80004d8..0000000000
--- a/components/net/freemodbus/port/porttimer_m.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * FreeModbus Libary: RT-Thread Port
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: porttimer_m.c,v 1.60 2013/08/13 15:07:05 Armink add Master Functions$
- */
-
-/* ----------------------- Platform includes --------------------------------*/
-#include "port.h"
-
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mb_m.h"
-#include "mbport.h"
-
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-/* ----------------------- Variables ----------------------------------------*/
-static USHORT usT35TimeOut50us;
-static struct rt_timer timer;
-static void prvvTIMERExpiredISR(void);
-static void timer_timeout_ind(void* parameter);
-
-/* ----------------------- static functions ---------------------------------*/
-static void prvvTIMERExpiredISR(void);
-
-/* ----------------------- Start implementation -----------------------------*/
-BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
-{
- /* backup T35 ticks */
- usT35TimeOut50us = usTimeOut50us;
-
- rt_timer_init(&timer, "master timer",
- timer_timeout_ind, /* bind timeout callback function */
- RT_NULL,
- (50 * usT35TimeOut50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1,
- RT_TIMER_FLAG_ONE_SHOT); /* one shot */
-
- return TRUE;
-}
-
-void vMBMasterPortTimersT35Enable()
-{
- rt_tick_t timer_tick = (50 * usT35TimeOut50us)
- / (1000 * 1000 / RT_TICK_PER_SECOND);
-
- /* Set current timer mode, don't change it.*/
- vMBMasterSetCurTimerMode(MB_TMODE_T35);
-
- rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
-
- rt_timer_start(&timer);
-}
-
-void vMBMasterPortTimersConvertDelayEnable()
-{
- rt_tick_t timer_tick = MB_MASTER_DELAY_MS_CONVERT * RT_TICK_PER_SECOND / 1000;
-
- /* Set current timer mode, don't change it.*/
- vMBMasterSetCurTimerMode(MB_TMODE_CONVERT_DELAY);
-
- rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
-
- rt_timer_start(&timer);
-}
-
-void vMBMasterPortTimersRespondTimeoutEnable()
-{
- rt_tick_t timer_tick = MB_MASTER_TIMEOUT_MS_RESPOND * RT_TICK_PER_SECOND / 1000;
-
- /* Set current timer mode, don't change it.*/
- vMBMasterSetCurTimerMode(MB_TMODE_RESPOND_TIMEOUT);
-
- rt_timer_control(&timer, RT_TIMER_CTRL_SET_TIME, &timer_tick);
-
- rt_timer_start(&timer);
-}
-
-void vMBMasterPortTimersDisable()
-{
- rt_timer_stop(&timer);
-}
-
-void prvvTIMERExpiredISR(void)
-{
- (void) pxMBMasterPortCBTimerExpired();
-}
-
-static void timer_timeout_ind(void* parameter)
-{
- prvvTIMERExpiredISR();
-}
-
-#endif
diff --git a/components/net/freemodbus/port/user_mb_app.c b/components/net/freemodbus/port/user_mb_app.c
deleted file mode 100644
index 8da7376336..0000000000
--- a/components/net/freemodbus/port/user_mb_app.c
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * FreeModbus Libary: user callback functions and buffer define in slave mode
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: user_mb_app.c,v 1.60 2013/11/23 11:49:05 Armink $
- */
-#include "user_mb_app.h"
-
-/*------------------------Slave mode use these variables----------------------*/
-//Slave mode:DiscreteInputs variables
-USHORT usSDiscInStart = S_DISCRETE_INPUT_START;
-#if S_DISCRETE_INPUT_NDISCRETES%8
-UCHAR ucSDiscInBuf[S_DISCRETE_INPUT_NDISCRETES/8+1];
-#else
-UCHAR ucSDiscInBuf[S_DISCRETE_INPUT_NDISCRETES/8] ;
-#endif
-//Slave mode:Coils variables
-USHORT usSCoilStart = S_COIL_START;
-#if S_COIL_NCOILS%8
-UCHAR ucSCoilBuf[S_COIL_NCOILS/8+1] ;
-#else
-UCHAR ucSCoilBuf[S_COIL_NCOILS/8] ;
-#endif
-//Slave mode:InputRegister variables
-USHORT usSRegInStart = S_REG_INPUT_START;
-USHORT usSRegInBuf[S_REG_INPUT_NREGS] ;
-//Slave mode:HoldingRegister variables
-USHORT usSRegHoldStart = S_REG_HOLDING_START;
-USHORT usSRegHoldBuf[S_REG_HOLDING_NREGS] ;
-
-/**
- * Modbus slave input register callback function.
- *
- * @param pucRegBuffer input register buffer
- * @param usAddress input register address
- * @param usNRegs input register number
- *
- * @return result
- */
-eMBErrorCode eMBRegInputCB(UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT iRegIndex;
- USHORT * pusRegInputBuf;
- USHORT REG_INPUT_START;
- USHORT REG_INPUT_NREGS;
- USHORT usRegInStart;
-
- pusRegInputBuf = usSRegInBuf;
- REG_INPUT_START = S_REG_INPUT_START;
- REG_INPUT_NREGS = S_REG_INPUT_NREGS;
- usRegInStart = usSRegInStart;
-
- /* it already plus one in modbus function method. */
- usAddress--;
-
- if ((usAddress >= REG_INPUT_START)
- && (usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS))
- {
- iRegIndex = usAddress - usRegInStart;
- while (usNRegs > 0)
- {
- *pucRegBuffer++ = (UCHAR) (pusRegInputBuf[iRegIndex] >> 8);
- *pucRegBuffer++ = (UCHAR) (pusRegInputBuf[iRegIndex] & 0xFF);
- iRegIndex++;
- usNRegs--;
- }
- }
- else
- {
- eStatus = MB_ENOREG;
- }
-
- return eStatus;
-}
-
-/**
- * Modbus slave holding register callback function.
- *
- * @param pucRegBuffer holding register buffer
- * @param usAddress holding register address
- * @param usNRegs holding register number
- * @param eMode read or write
- *
- * @return result
- */
-eMBErrorCode eMBRegHoldingCB(UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNRegs, eMBRegisterMode eMode)
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT iRegIndex;
- USHORT * pusRegHoldingBuf;
- USHORT REG_HOLDING_START;
- USHORT REG_HOLDING_NREGS;
- USHORT usRegHoldStart;
-
- pusRegHoldingBuf = usSRegHoldBuf;
- REG_HOLDING_START = S_REG_HOLDING_START;
- REG_HOLDING_NREGS = S_REG_HOLDING_NREGS;
- usRegHoldStart = usSRegHoldStart;
-
- /* it already plus one in modbus function method. */
- usAddress--;
-
- if ((usAddress >= REG_HOLDING_START)
- && (usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS))
- {
- iRegIndex = usAddress - usRegHoldStart;
- switch (eMode)
- {
- /* read current register values from the protocol stack. */
- case MB_REG_READ:
- while (usNRegs > 0)
- {
- *pucRegBuffer++ = (UCHAR) (pusRegHoldingBuf[iRegIndex] >> 8);
- *pucRegBuffer++ = (UCHAR) (pusRegHoldingBuf[iRegIndex] & 0xFF);
- iRegIndex++;
- usNRegs--;
- }
- break;
-
- /* write current register values with new values from the protocol stack. */
- case MB_REG_WRITE:
- while (usNRegs > 0)
- {
- pusRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8;
- pusRegHoldingBuf[iRegIndex] |= *pucRegBuffer++;
- iRegIndex++;
- usNRegs--;
- }
- break;
- }
- }
- else
- {
- eStatus = MB_ENOREG;
- }
- return eStatus;
-}
-
-/**
- * Modbus slave coils callback function.
- *
- * @param pucRegBuffer coils buffer
- * @param usAddress coils address
- * @param usNCoils coils number
- * @param eMode read or write
- *
- * @return result
- */
-eMBErrorCode eMBRegCoilsCB(UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNCoils, eMBRegisterMode eMode)
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT iRegIndex , iRegBitIndex , iNReg;
- UCHAR * pucCoilBuf;
- USHORT COIL_START;
- USHORT COIL_NCOILS;
- USHORT usCoilStart;
- iNReg = usNCoils / 8 + 1;
-
- pucCoilBuf = ucSCoilBuf;
- COIL_START = S_COIL_START;
- COIL_NCOILS = S_COIL_NCOILS;
- usCoilStart = usSCoilStart;
-
- /* it already plus one in modbus function method. */
- usAddress--;
-
- if( ( usAddress >= COIL_START ) &&
- ( usAddress + usNCoils <= COIL_START + COIL_NCOILS ) )
- {
- iRegIndex = (USHORT) (usAddress - usCoilStart) / 8;
- iRegBitIndex = (USHORT) (usAddress - usCoilStart) % 8;
- switch ( eMode )
- {
- /* read current coil values from the protocol stack. */
- case MB_REG_READ:
- while (iNReg > 0)
- {
- *pucRegBuffer++ = xMBUtilGetBits(&pucCoilBuf[iRegIndex++],
- iRegBitIndex, 8);
- iNReg--;
- }
- pucRegBuffer--;
- /* last coils */
- usNCoils = usNCoils % 8;
- /* filling zero to high bit */
- *pucRegBuffer = *pucRegBuffer << (8 - usNCoils);
- *pucRegBuffer = *pucRegBuffer >> (8 - usNCoils);
- break;
-
- /* write current coil values with new values from the protocol stack. */
- case MB_REG_WRITE:
- while (iNReg > 1)
- {
- xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, 8,
- *pucRegBuffer++);
- iNReg--;
- }
- /* last coils */
- usNCoils = usNCoils % 8;
- /* xMBUtilSetBits has bug when ucNBits is zero */
- if (usNCoils != 0)
- {
- xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, usNCoils,
- *pucRegBuffer++);
- }
- break;
- }
- }
- else
- {
- eStatus = MB_ENOREG;
- }
- return eStatus;
-}
-
-/**
- * Modbus slave discrete callback function.
- *
- * @param pucRegBuffer discrete buffer
- * @param usAddress discrete address
- * @param usNDiscrete discrete number
- *
- * @return result
- */
-eMBErrorCode eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT iRegIndex , iRegBitIndex , iNReg;
- UCHAR * pucDiscreteInputBuf;
- USHORT DISCRETE_INPUT_START;
- USHORT DISCRETE_INPUT_NDISCRETES;
- USHORT usDiscreteInputStart;
- iNReg = usNDiscrete / 8 + 1;
-
- pucDiscreteInputBuf = ucSDiscInBuf;
- DISCRETE_INPUT_START = S_DISCRETE_INPUT_START;
- DISCRETE_INPUT_NDISCRETES = S_DISCRETE_INPUT_NDISCRETES;
- usDiscreteInputStart = usSDiscInStart;
-
- /* it already plus one in modbus function method. */
- usAddress--;
-
- if ((usAddress >= DISCRETE_INPUT_START)
- && (usAddress + usNDiscrete <= DISCRETE_INPUT_START + DISCRETE_INPUT_NDISCRETES))
- {
- iRegIndex = (USHORT) (usAddress - usDiscreteInputStart) / 8;
- iRegBitIndex = (USHORT) (usAddress - usDiscreteInputStart) % 8;
-
- while (iNReg > 0)
- {
- *pucRegBuffer++ = xMBUtilGetBits(&pucDiscreteInputBuf[iRegIndex++],
- iRegBitIndex, 8);
- iNReg--;
- }
- pucRegBuffer--;
- /* last discrete */
- usNDiscrete = usNDiscrete % 8;
- /* filling zero to high bit */
- *pucRegBuffer = *pucRegBuffer << (8 - usNDiscrete);
- *pucRegBuffer = *pucRegBuffer >> (8 - usNDiscrete);
- }
- else
- {
- eStatus = MB_ENOREG;
- }
-
- return eStatus;
-}
-
diff --git a/components/net/freemodbus/port/user_mb_app.h b/components/net/freemodbus/port/user_mb_app.h
deleted file mode 100644
index 864c3860bf..0000000000
--- a/components/net/freemodbus/port/user_mb_app.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef USER_APP
-#define USER_APP
-/* ----------------------- Modbus includes ----------------------------------*/
-#include "mb.h"
-#include "mb_m.h"
-#include "mbconfig.h"
-#include "mbframe.h"
-#include "mbutils.h"
-
-/* -----------------------Slave Defines -------------------------------------*/
-#define S_DISCRETE_INPUT_START 0
-#define S_DISCRETE_INPUT_NDISCRETES 16
-#define S_COIL_START 0
-#define S_COIL_NCOILS 64
-#define S_REG_INPUT_START 0
-#define S_REG_INPUT_NREGS 100
-#define S_REG_HOLDING_START 0
-#define S_REG_HOLDING_NREGS 100
-/* salve mode: holding register's all address */
-#define S_HD_RESERVE 0
-/* salve mode: input register's all address */
-#define S_IN_RESERVE 0
-/* salve mode: coil's all address */
-#define S_CO_RESERVE 0
-/* salve mode: discrete's all address */
-#define S_DI_RESERVE 0
-
-/* -----------------------Master Defines -------------------------------------*/
-#define M_DISCRETE_INPUT_START 0
-#define M_DISCRETE_INPUT_NDISCRETES 16
-#define M_COIL_START 0
-#define M_COIL_NCOILS 64
-#define M_REG_INPUT_START 0
-#define M_REG_INPUT_NREGS 100
-#define M_REG_HOLDING_START 0
-#define M_REG_HOLDING_NREGS 100
-/* master mode: holding register's all address */
-#define M_HD_RESERVE 0
-/* master mode: input register's all address */
-#define M_IN_RESERVE 0
-/* master mode: coil's all address */
-#define M_CO_RESERVE 0
-/* master mode: discrete's all address */
-#define M_DI_RESERVE 0
-
-#endif
diff --git a/components/net/freemodbus/port/user_mb_app_m.c b/components/net/freemodbus/port/user_mb_app_m.c
deleted file mode 100644
index 12fabf21ac..0000000000
--- a/components/net/freemodbus/port/user_mb_app_m.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * FreeModbus Libary: user callback functions and buffer define in master mode
- * Copyright (C) 2013 Armink <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * File: $Id: user_mb_app_m.c,v 1.60 2013/11/23 11:49:05 Armink $
- */
-#include "user_mb_app.h"
-
-/*-----------------------Master mode use these variables----------------------*/
-#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
-//Master mode:DiscreteInputs variables
-USHORT usMDiscInStart = M_DISCRETE_INPUT_START;
-#if M_DISCRETE_INPUT_NDISCRETES%8
-UCHAR ucMDiscInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_DISCRETE_INPUT_NDISCRETES/8+1];
-#else
-UCHAR ucMDiscInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_DISCRETE_INPUT_NDISCRETES/8];
-#endif
-//Master mode:Coils variables
-USHORT usMCoilStart = M_COIL_START;
-#if M_COIL_NCOILS%8
-UCHAR ucMCoilBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_COIL_NCOILS/8+1];
-#else
-UCHAR ucMCoilBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_COIL_NCOILS/8];
-#endif
-//Master mode:InputRegister variables
-USHORT usMRegInStart = M_REG_INPUT_START;
-USHORT usMRegInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_INPUT_NREGS];
-//Master mode:HoldingRegister variables
-USHORT usMRegHoldStart = M_REG_HOLDING_START;
-USHORT usMRegHoldBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_HOLDING_NREGS];
-
-/**
- * Modbus master input register callback function.
- *
- * @param pucRegBuffer input register buffer
- * @param usAddress input register address
- * @param usNRegs input register number
- *
- * @return result
- */
-eMBErrorCode eMBMasterRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT iRegIndex;
- USHORT * pusRegInputBuf;
- USHORT REG_INPUT_START;
- USHORT REG_INPUT_NREGS;
- USHORT usRegInStart;
-
- pusRegInputBuf = usMRegInBuf[ucMBMasterGetDestAddress() - 1];
- REG_INPUT_START = M_REG_INPUT_START;
- REG_INPUT_NREGS = M_REG_INPUT_NREGS;
- usRegInStart = usMRegInStart;
-
- /* it already plus one in modbus function method. */
- usAddress--;
-
- if ((usAddress >= REG_INPUT_START)
- && (usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS))
- {
- iRegIndex = usAddress - usRegInStart;
- while (usNRegs > 0)
- {
- pusRegInputBuf[iRegIndex] = *pucRegBuffer++ << 8;
- pusRegInputBuf[iRegIndex] |= *pucRegBuffer++;
- iRegIndex++;
- usNRegs--;
- }
- }
- else
- {
- eStatus = MB_ENOREG;
- }
-
- return eStatus;
-}
-
-/**
- * Modbus master holding register callback function.
- *
- * @param pucRegBuffer holding register buffer
- * @param usAddress holding register address
- * @param usNRegs holding register number
- * @param eMode read or write
- *
- * @return result
- */
-eMBErrorCode eMBMasterRegHoldingCB(UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNRegs, eMBRegisterMode eMode)
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT iRegIndex;
- USHORT * pusRegHoldingBuf;
- USHORT REG_HOLDING_START;
- USHORT REG_HOLDING_NREGS;
- USHORT usRegHoldStart;
-
- pusRegHoldingBuf = usMRegHoldBuf[ucMBMasterGetDestAddress() - 1];
- REG_HOLDING_START = M_REG_HOLDING_START;
- REG_HOLDING_NREGS = M_REG_HOLDING_NREGS;
- usRegHoldStart = usMRegHoldStart;
- /* if mode is read, the master will write the received date to buffer. */
- eMode = MB_REG_WRITE;
-
- /* it already plus one in modbus function method. */
- usAddress--;
-
- if ((usAddress >= REG_HOLDING_START)
- && (usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS))
- {
- iRegIndex = usAddress - usRegHoldStart;
- switch (eMode)
- {
- /* read current register values from the protocol stack. */
- case MB_REG_READ:
- while (usNRegs > 0)
- {
- *pucRegBuffer++ = (UCHAR) (pusRegHoldingBuf[iRegIndex] >> 8);
- *pucRegBuffer++ = (UCHAR) (pusRegHoldingBuf[iRegIndex] & 0xFF);
- iRegIndex++;
- usNRegs--;
- }
- break;
- /* write current register values with new values from the protocol stack. */
- case MB_REG_WRITE:
- while (usNRegs > 0)
- {
- pusRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8;
- pusRegHoldingBuf[iRegIndex] |= *pucRegBuffer++;
- iRegIndex++;
- usNRegs--;
- }
- break;
- }
- }
- else
- {
- eStatus = MB_ENOREG;
- }
- return eStatus;
-}
-
-/**
- * Modbus master coils callback function.
- *
- * @param pucRegBuffer coils buffer
- * @param usAddress coils address
- * @param usNCoils coils number
- * @param eMode read or write
- *
- * @return result
- */
-eMBErrorCode eMBMasterRegCoilsCB(UCHAR * pucRegBuffer, USHORT usAddress,
- USHORT usNCoils, eMBRegisterMode eMode)
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT iRegIndex , iRegBitIndex , iNReg;
- UCHAR * pucCoilBuf;
- USHORT COIL_START;
- USHORT COIL_NCOILS;
- USHORT usCoilStart;
- iNReg = usNCoils / 8 + 1;
-
- pucCoilBuf = ucMCoilBuf[ucMBMasterGetDestAddress() - 1];
- COIL_START = M_COIL_START;
- COIL_NCOILS = M_COIL_NCOILS;
- usCoilStart = usMCoilStart;
-
- /* if mode is read,the master will write the received date to buffer. */
- eMode = MB_REG_WRITE;
-
- /* it already plus one in modbus function method. */
- usAddress--;
-
- if ((usAddress >= COIL_START)
- && (usAddress + usNCoils <= COIL_START + COIL_NCOILS))
- {
- iRegIndex = (USHORT) (usAddress - usCoilStart) / 8;
- iRegBitIndex = (USHORT) (usAddress - usCoilStart) % 8;
- switch (eMode)
- {
- /* read current coil values from the protocol stack. */
- case MB_REG_READ:
- while (iNReg > 0)
- {
- *pucRegBuffer++ = xMBUtilGetBits(&pucCoilBuf[iRegIndex++],
- iRegBitIndex, 8);
- iNReg--;
- }
- pucRegBuffer--;
- /* last coils */
- usNCoils = usNCoils % 8;
- /* filling zero to high bit */
- *pucRegBuffer = *pucRegBuffer << (8 - usNCoils);
- *pucRegBuffer = *pucRegBuffer >> (8 - usNCoils);
- break;
-
- /* write current coil values with new values from the protocol stack. */
- case MB_REG_WRITE:
- while (iNReg > 1)
- {
- xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, 8,
- *pucRegBuffer++);
- iNReg--;
- }
- /* last coils */
- usNCoils = usNCoils % 8;
- /* xMBUtilSetBits has bug when ucNBits is zero */
- if (usNCoils != 0)
- {
- xMBUtilSetBits(&pucCoilBuf[iRegIndex++], iRegBitIndex, usNCoils,
- *pucRegBuffer++);
- }
- break;
- }
- }
- else
- {
- eStatus = MB_ENOREG;
- }
- return eStatus;
-}
-
-/**
- * Modbus master discrete callback function.
- *
- * @param pucRegBuffer discrete buffer
- * @param usAddress discrete address
- * @param usNDiscrete discrete number
- *
- * @return result
- */
-eMBErrorCode eMBMasterRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
-{
- eMBErrorCode eStatus = MB_ENOERR;
- USHORT iRegIndex , iRegBitIndex , iNReg;
- UCHAR * pucDiscreteInputBuf;
- USHORT DISCRETE_INPUT_START;
- USHORT DISCRETE_INPUT_NDISCRETES;
- USHORT usDiscreteInputStart;
- iNReg = usNDiscrete / 8 + 1;
-
- pucDiscreteInputBuf = ucMDiscInBuf[ucMBMasterGetDestAddress() - 1];
- DISCRETE_INPUT_START = M_DISCRETE_INPUT_START;
- DISCRETE_INPUT_NDISCRETES = M_DISCRETE_INPUT_NDISCRETES;
- usDiscreteInputStart = usMDiscInStart;
-
- /* it already plus one in modbus function method. */
- usAddress--;
-
- if ((usAddress >= DISCRETE_INPUT_START)
- && (usAddress + usNDiscrete <= DISCRETE_INPUT_START + DISCRETE_INPUT_NDISCRETES))
- {
- iRegIndex = (USHORT) (usAddress - usDiscreteInputStart) / 8;
- iRegBitIndex = (USHORT) (usAddress - usDiscreteInputStart) % 8;
-
- /* write current discrete values with new values from the protocol stack. */
- while (iNReg > 1)
- {
- xMBUtilSetBits(&pucDiscreteInputBuf[iRegIndex++], iRegBitIndex, 8,
- *pucRegBuffer++);
- iNReg--;
- }
- /* last discrete */
- usNDiscrete = usNDiscrete % 8;
- /* xMBUtilSetBits has bug when ucNBits is zero */
- if (usNDiscrete != 0)
- {
- xMBUtilSetBits(&pucDiscreteInputBuf[iRegIndex++], iRegBitIndex,
- usNDiscrete, *pucRegBuffer++);
- }
- }
- else
- {
- eStatus = MB_ENOREG;
- }
-
- return eStatus;
-}
-#endif
diff --git a/components/net/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip-1.4.1/src/arch/sys_arch.c
index dc20ee97a1..c31bd59c1d 100644
--- a/components/net/lwip-1.4.1/src/arch/sys_arch.c
+++ b/components/net/lwip-1.4.1/src/arch/sys_arch.c
@@ -198,7 +198,7 @@ int lwip_system_init(void)
return 0;
}
-INIT_COMPONENT_EXPORT(lwip_system_init);
+INIT_PREV_EXPORT(lwip_system_init);
void sys_init(void)
{
@@ -497,8 +497,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
t = timeout / (1000/RT_TICK_PER_SECOND);
}
- ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, t);
-
+ ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, t);
if(ret == -RT_ETIMEOUT)
{
return SYS_ARCH_TIMEOUT;
@@ -530,8 +529,7 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
{
int ret;
- ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, 0);
-
+ ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, 0);
if(ret == -RT_ETIMEOUT)
{
return SYS_ARCH_TIMEOUT;
diff --git a/components/net/lwip-1.4.1/src/core/dns.c b/components/net/lwip-1.4.1/src/core/dns.c
index 18c73d0a8c..2e1356ca97 100644
--- a/components/net/lwip-1.4.1/src/core/dns.c
+++ b/components/net/lwip-1.4.1/src/core/dns.c
@@ -279,13 +279,14 @@ dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
dns_servers[numdns] = (*dnsserver);
#ifdef RT_USING_NETDEV
- extern struct netif *netif_default;
+ extern struct netif *netif_list;
extern struct netdev *netdev_get_by_name(const char *name);
extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
+ struct netif *netif = NULL;
/* set network interface device DNS server address */
- if (netif_default) {
- netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver);
+ for (netif = netif_list; netif != NULL; netif = netif->next) {
+ netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
}
#endif /* RT_USING_NETDEV */
}
diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c
index 10bcaa0c95..9d8fa650a4 100644
--- a/components/net/lwip-1.4.1/src/netif/ethernetif.c
+++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c
@@ -146,8 +146,8 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
#ifdef RT_LWIP_DNS
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
{
- extern void set_dns(uint8_t dns_num, char* dns_server);
- set_dns(dns_num, ipaddr_ntoa(dns_server));
+ extern void dns_setserver(uint8_t dns_num, ip_addr_t *dns_server);
+ dns_setserver(dns_num, dns_server);
return ERR_OK;
}
#endif /* RT_LWIP_DNS */
@@ -160,6 +160,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
}
#endif /* RT_LWIP_DHCP */
+#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
extern int lwip_ping_recv(int s, int *ttl);
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
@@ -250,6 +251,13 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
}
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
+#endif /* RT_USING_FINSH */
+
+static int lwip_netdev_set_default(struct netdev *netif)
+{
+ netif_set_default((struct netif *)netif->user_data);
+ return ERR_OK;
+}
const struct netdev_ops lwip_netdev_ops =
{
@@ -269,6 +277,7 @@ const struct netdev_ops lwip_netdev_ops =
NULL,
#endif /* RT_LWIP_DHCP */
+#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
lwip_netdev_ping,
#else
@@ -278,6 +287,9 @@ const struct netdev_ops lwip_netdev_ops =
#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP)
lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
+#endif /* RT_USING_FINSH */
+
+ lwip_netdev_set_default,
};
static int netdev_add(struct netif *lwip_netif)
@@ -295,12 +307,6 @@ static int netdev_add(struct netif *lwip_netif)
return -ERR_IF;
}
- netdev->flags = lwip_netif->flags;
- netdev->mtu = lwip_netif->mtu;
- netdev->ops = &lwip_netdev_ops;
- netdev->hwaddr_len = lwip_netif->hwaddr_len;
- rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
-
#ifdef SAL_USING_LWIP
extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev);
/* set the lwIP network interface device protocol family information */
@@ -309,7 +315,17 @@ static int netdev_add(struct netif *lwip_netif)
rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN);
result = netdev_register(netdev, name, (void *)lwip_netif);
-
+
+ /* Update netdev info after registered */
+ netdev->flags = lwip_netif->flags;
+ netdev->mtu = lwip_netif->mtu;
+ netdev->ops = &lwip_netdev_ops;
+ netdev->hwaddr_len = lwip_netif->hwaddr_len;
+ rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
+ netdev->ip_addr = lwip_netif->ip_addr;
+ netdev->gw = lwip_netif->gw;
+ netdev->netmask = lwip_netif->netmask;
+
#ifdef RT_LWIP_DHCP
netdev_low_level_set_dhcp_status(netdev, RT_TRUE);
#endif
@@ -678,8 +694,6 @@ int eth_system_device_init(void)
}
INIT_PREV_EXPORT(eth_system_device_init);
-#ifdef RT_USING_FINSH
-#include <finsh.h>
void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
{
struct ip_addr *ip;
@@ -725,6 +739,9 @@ void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
netif_set_netmask(netif, ip);
}
}
+
+#ifdef RT_USING_FINSH
+#include <finsh.h>
FINSH_FUNCTION_EXPORT(set_if, set network interface address);
#if LWIP_DNS
diff --git a/components/net/lwip-2.0.2/src/arch/sys_arch.c b/components/net/lwip-2.0.2/src/arch/sys_arch.c
index 7a92170886..b2abaeab54 100644
--- a/components/net/lwip-2.0.2/src/arch/sys_arch.c
+++ b/components/net/lwip-2.0.2/src/arch/sys_arch.c
@@ -508,7 +508,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
t = timeout / (1000/RT_TICK_PER_SECOND);
}
- ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, t);
+ ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, t);
if(ret == -RT_ETIMEOUT)
return SYS_ARCH_TIMEOUT;
@@ -539,7 +539,7 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
{
int ret;
- ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, 0);
+ ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, 0);
if(ret == -RT_ETIMEOUT)
return SYS_ARCH_TIMEOUT;
diff --git a/components/net/lwip-2.0.2/src/core/dns.c b/components/net/lwip-2.0.2/src/core/dns.c
index c793b320a4..cd4de06229 100644
--- a/components/net/lwip-2.0.2/src/core/dns.c
+++ b/components/net/lwip-2.0.2/src/core/dns.c
@@ -370,13 +370,14 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
dns_servers[numdns] = (*dnsserver);
#ifdef RT_USING_NETDEV
- extern struct netif *netif_default;
+ extern struct netif *netif_list;
extern struct netdev *netdev_get_by_name(const char *name);
extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
+ struct netif *netif = NULL;
/* set network interface device DNS server address */
- if (netif_default) {
- netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver);
+ for (netif = netif_list; netif != NULL; netif = netif->next) {
+ netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
}
#endif /* RT_USING_NETDEV */
} else {
diff --git a/components/net/lwip-2.0.2/src/core/netif.c b/components/net/lwip-2.0.2/src/core/netif.c
index 01e83676da..ee57bb9a9d 100644
--- a/components/net/lwip-2.0.2/src/core/netif.c
+++ b/components/net/lwip-2.0.2/src/core/netif.c
@@ -544,7 +544,7 @@ netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr)
#ifdef RT_USING_NETDEV
/* rt-thread sal network interface device set IP address operations */
- netdev_low_level_set_ipaddr(netdev_get_by_name(netif->name), (ip_addr_t *)ipaddr);
+ netdev_low_level_set_ipaddr(netdev_get_by_name(netif->name), &netif->ip_addr);
#endif /* RT_USING_NETDEV */
}
@@ -579,7 +579,7 @@ netif_set_gw(struct netif *netif, const ip4_addr_t *gw)
#ifdef RT_USING_NETDEV
/* rt_thread network interface device set gateway address */
- netdev_low_level_set_gw(netdev_get_by_name(netif->name), (ip_addr_t *)gw);
+ netdev_low_level_set_gw(netdev_get_by_name(netif->name), &netif->gw);
#endif /* RT_USING_NETDEV */
}
@@ -610,7 +610,7 @@ netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask)
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set netmask address */
- netdev_low_level_set_netmask(netdev_get_by_name(netif->name), (ip_addr_t *)netmask);
+ netdev_low_level_set_netmask(netdev_get_by_name(netif->name), &netif->netmask);
#endif /* RT_USING_NETDEV */
}
#endif /* LWIP_IPV4 */
@@ -1241,6 +1241,11 @@ netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
}
}
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set ipv6 address */
+ ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[0], netif->ip6_addr[0]);
+#endif /* RT_USING_NETDEV */
+
/* Set address state. */
#if LWIP_IPV6_DUP_DETECT_ATTEMPTS
/* Will perform duplicate address detection (DAD). */
@@ -1279,6 +1284,10 @@ netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chos
for (i = 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) {
ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr);
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set ipv6 address */
+ ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[i], netif->ip6_addr[i]);
+#endif /* RT_USING_NETDEV */
netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
if (chosen_idx != NULL) {
*chosen_idx = i;
diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h
index 1c969e6e25..244bafdd1b 100644
--- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h
+++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h
@@ -41,6 +41,7 @@ extern "C" {
rt_err_t eth_device_init(struct eth_device * dev, const char *name);
rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flag);
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up);
+ void eth_device_deinit(struct eth_device *dev);
int eth_system_device_init(void);
diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c
index f19ec094fa..a7bed3065f 100644
--- a/components/net/lwip-2.0.2/src/netif/ethernetif.c
+++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c
@@ -128,23 +128,23 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
{
if (ip_addr && netmask && gw)
{
- netif_set_addr((struct netif *)netif->user_data, ip_addr, netmask, gw);
+ netif_set_addr((struct netif *)netif->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
}
else
{
if (ip_addr)
{
- netif_set_ipaddr((struct netif *)netif->user_data, ip_addr);
+ netif_set_ipaddr((struct netif *)netif->user_data, ip_2_ip4(ip_addr));
}
if (netmask)
{
- netif_set_netmask((struct netif *)netif->user_data, netmask);
+ netif_set_netmask((struct netif *)netif->user_data, ip_2_ip4(netmask));
}
if (gw)
{
- netif_set_gw((struct netif *)netif->user_data, gw);
+ netif_set_gw((struct netif *)netif->user_data, ip_2_ip4(gw));
}
}
@@ -154,8 +154,8 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
#ifdef RT_LWIP_DNS
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
{
- extern void set_dns(uint8_t dns_num, char* dns_server);
- set_dns(dns_num, ipaddr_ntoa(dns_server));
+ extern void dns_setserver(uint8_t dns_num, const ip_addr_t *dns_server);
+ dns_setserver(dns_num, dns_server);
return ERR_OK;
}
#endif /* RT_LWIP_DNS */
@@ -168,6 +168,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
}
#endif /* RT_LWIP_DHCP */
+#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
extern int lwip_ping_recv(int s, int *ttl);
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
@@ -258,6 +259,13 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
}
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
+#endif /* RT_USING_FINSH */
+
+static int lwip_netdev_set_default(struct netdev *netif)
+{
+ netif_set_default((struct netif *)netif->user_data);
+ return ERR_OK;
+}
const struct netdev_ops lwip_netdev_ops =
{
@@ -277,6 +285,7 @@ const struct netdev_ops lwip_netdev_ops =
NULL,
#endif /* RT_LWIP_DHCP */
+#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
lwip_netdev_ping,
#else
@@ -286,6 +295,9 @@ const struct netdev_ops lwip_netdev_ops =
#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP)
lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
+#endif /* RT_USING_FINSH */
+
+ lwip_netdev_set_default,
};
static int netdev_add(struct netif *lwip_netif)
@@ -303,12 +315,6 @@ static int netdev_add(struct netif *lwip_netif)
return -ERR_IF;
}
- netdev->flags = lwip_netif->flags;
- netdev->mtu = lwip_netif->mtu;
- netdev->ops = &lwip_netdev_ops;
- netdev->hwaddr_len = lwip_netif->hwaddr_len;
- rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
-
#ifdef SAL_USING_LWIP
extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev);
/* set the lwIP network interface device protocol family information */
@@ -317,7 +323,17 @@ static int netdev_add(struct netif *lwip_netif)
rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN);
result = netdev_register(netdev, name, (void *)lwip_netif);
-
+
+ /* Update netdev info after registered */
+ netdev->flags = lwip_netif->flags;
+ netdev->mtu = lwip_netif->mtu;
+ netdev->ops = &lwip_netdev_ops;
+ netdev->hwaddr_len = lwip_netif->hwaddr_len;
+ rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
+ netdev->ip_addr = lwip_netif->ip_addr;
+ netdev->gw = lwip_netif->gw;
+ netdev->netmask = lwip_netif->netmask;
+
#ifdef RT_LWIP_DHCP
netdev_low_level_set_dhcp_status(netdev, RT_TRUE);
#endif
@@ -325,6 +341,19 @@ static int netdev_add(struct netif *lwip_netif)
return result;
}
+static void netdev_del(struct netif *lwip_netif)
+{
+ char name[LWIP_NETIF_NAME_LEN + 1];
+ struct netdev *netdev;
+
+ RT_ASSERT(lwip_netif);
+
+ rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN);
+ netdev = netdev_get_by_name(name);
+ netdev_unregister(netdev);
+ rt_free(netdev);
+}
+
/* synchronize lwIP network interface device and network interface device flags */
static int netdev_flags_sync(struct netif *lwip_netif)
{
@@ -530,6 +559,25 @@ rt_err_t eth_device_init(struct eth_device * dev, const char *name)
return eth_device_init_with_flag(dev, name, flags);
}
+void eth_device_deinit(struct eth_device *dev)
+{
+ struct netif* netif = dev->netif;
+
+#if LWIP_DHCP
+ dhcp_stop(netif);
+ dhcp_cleanup(netif);
+#endif
+ netif_set_down(netif);
+ netif_remove(netif);
+#ifdef RT_USING_NETDEV
+ netdev_del(netif);
+#endif
+ rt_device_close(&(dev->parent));
+ rt_device_unregister(&(dev->parent));
+ rt_sem_detach(&(dev->tx_ack));
+ rt_free(netif);
+}
+
#ifndef LWIP_NO_RX_THREAD
rt_err_t eth_device_ready(struct eth_device* dev)
{
@@ -707,8 +755,6 @@ int eth_system_device_init_private(void)
return (int)result;
}
-#ifdef RT_USING_FINSH
-#include <finsh.h>
void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
{
ip4_addr_t *ip;
@@ -754,6 +800,9 @@ void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
netif_set_netmask(netif, ip);
}
}
+
+#ifdef RT_USING_FINSH
+#include <finsh.h>
FINSH_FUNCTION_EXPORT(set_if, set network interface address);
#if LWIP_DNS
diff --git a/components/net/lwip-2.1.0/src/arch/sys_arch.c b/components/net/lwip-2.1.0/src/arch/sys_arch.c
index 17ebdfbacf..dc08715ecc 100644
--- a/components/net/lwip-2.1.0/src/arch/sys_arch.c
+++ b/components/net/lwip-2.1.0/src/arch/sys_arch.c
@@ -522,7 +522,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
t = timeout / (1000/RT_TICK_PER_SECOND);
}
- ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, t);
+ ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, t);
if(ret == -RT_ETIMEOUT)
return SYS_ARCH_TIMEOUT;
@@ -553,7 +553,7 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
{
int ret;
- ret = rt_mb_recv(*mbox, (rt_uint32_t *)msg, 0);
+ ret = rt_mb_recv(*mbox, (rt_ubase_t *)msg, 0);
if(ret == -RT_ETIMEOUT)
return SYS_ARCH_TIMEOUT;
diff --git a/components/net/lwip-2.1.0/src/core/dns.c b/components/net/lwip-2.1.0/src/core/dns.c
index 5129b7f3bc..c688cb2205 100644
--- a/components/net/lwip-2.1.0/src/core/dns.c
+++ b/components/net/lwip-2.1.0/src/core/dns.c
@@ -367,13 +367,14 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
dns_servers[numdns] = (*dnsserver);
#ifdef RT_USING_NETDEV
- extern struct netif *netif_default;
+ extern struct netif *netif_list;
extern struct netdev *netdev_get_by_name(const char *name);
extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
+ struct netif *netif = NULL;
/* set network interface device DNS server address */
- if (netif_default) {
- netdev_low_level_set_dns_server(netdev_get_by_name(netif_default->name), numdns, dnsserver);
+ for (netif = netif_list; netif != NULL; netif = netif->next) {
+ netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
}
#endif /* RT_USING_NETDEV */
} else {
diff --git a/components/net/lwip-2.1.0/src/core/netif.c b/components/net/lwip-2.1.0/src/core/netif.c
index 5b31c627e9..b2b4adf85b 100644
--- a/components/net/lwip-2.1.0/src/core/netif.c
+++ b/components/net/lwip-2.1.0/src/core/netif.c
@@ -491,7 +491,7 @@ netif_do_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr, ip_addr_t *ol
#ifdef RT_USING_NETDEV
/* rt-thread sal network interface device set IP address operations */
- netdev_low_level_set_ipaddr(netdev_get_by_name(netif->name), (ip_addr_t *)ipaddr);
+ netdev_low_level_set_ipaddr(netdev_get_by_name(netif->name), &netif->ip_addr);
#endif /* RT_USING_NETDEV */
return 1; /* address changed */
@@ -557,7 +557,7 @@ netif_do_set_netmask(struct netif *netif, const ip4_addr_t *netmask, ip_addr_t *
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set netmask address */
- netdev_low_level_set_netmask(netdev_get_by_name(netif->name), (ip_addr_t *)netmask);
+ netdev_low_level_set_netmask(netdev_get_by_name(netif->name), &netif->netmask);
#endif /* RT_USING_NETDEV */
return 1; /* netmask changed */
@@ -625,7 +625,7 @@ netif_do_set_gw(struct netif *netif, const ip4_addr_t *gw, ip_addr_t *old_gw)
#ifdef RT_USING_NETDEV
/* rt_thread network interface device set gateway address */
- netdev_low_level_set_gw(netdev_get_by_name(netif->name), (ip_addr_t *)gw);
+ netdev_low_level_set_gw(netdev_get_by_name(netif->name), &netif->gw);
#endif /* RT_USING_NETDEV */
return 1; /* gateway changed */
@@ -1586,6 +1586,11 @@ netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
* zone field, so this should not create any compatibility problems. */
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[0]), IP6_UNICAST, netif);
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set ipv6 address */
+ ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[0], netif->ip6_addr[0]);
+#endif /* RT_USING_NETDEV */
+
/* Set address state. */
#if LWIP_IPV6_DUP_DETECT_ATTEMPTS
/* Will perform duplicate address detection (DAD). */
@@ -1629,6 +1634,10 @@ netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chos
for (i = ip6_addr_islinklocal(ip6addr) ? 0 : 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) {
ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr);
+#ifdef RT_USING_NETDEV
+ /* rt-thread network interface device set ipv6 address */
+ ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[i], netif->ip6_addr[i]);
+#endif /* RT_USING_NETDEV */
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[i]), IP6_UNICAST, netif);
netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
if (chosen_idx != NULL) {
diff --git a/components/net/lwip-2.1.0/src/include/netif/ethernetif.h b/components/net/lwip-2.1.0/src/include/netif/ethernetif.h
index 1c969e6e25..244bafdd1b 100644
--- a/components/net/lwip-2.1.0/src/include/netif/ethernetif.h
+++ b/components/net/lwip-2.1.0/src/include/netif/ethernetif.h
@@ -41,6 +41,7 @@ extern "C" {
rt_err_t eth_device_init(struct eth_device * dev, const char *name);
rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_uint16_t flag);
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up);
+ void eth_device_deinit(struct eth_device *dev);
int eth_system_device_init(void);
diff --git a/components/net/lwip-2.1.0/src/netif/ethernetif.c b/components/net/lwip-2.1.0/src/netif/ethernetif.c
index db28a4a55b..66ea1d2376 100644
--- a/components/net/lwip-2.1.0/src/netif/ethernetif.c
+++ b/components/net/lwip-2.1.0/src/netif/ethernetif.c
@@ -129,23 +129,23 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
{
if (ip_addr && netmask && gw)
{
- netif_set_addr((struct netif *)netif->user_data, ip_addr, netmask, gw);
+ netif_set_addr((struct netif *)netif->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
}
else
{
if (ip_addr)
{
- netif_set_ipaddr((struct netif *)netif->user_data, ip_addr);
+ netif_set_ipaddr((struct netif *)netif->user_data, ip_2_ip4(ip_addr));
}
if (netmask)
{
- netif_set_netmask((struct netif *)netif->user_data, netmask);
+ netif_set_netmask((struct netif *)netif->user_data, ip_2_ip4(netmask));
}
if (gw)
{
- netif_set_gw((struct netif *)netif->user_data, gw);
+ netif_set_gw((struct netif *)netif->user_data, ip_2_ip4(gw));
}
}
@@ -155,8 +155,8 @@ static int lwip_netdev_set_addr_info(struct netdev *netif, ip_addr_t *ip_addr, i
#ifdef RT_LWIP_DNS
static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_addr_t *dns_server)
{
- extern void set_dns(uint8_t dns_num, char* dns_server);
- set_dns(dns_num, ipaddr_ntoa(dns_server));
+ extern void dns_setserver(uint8_t dns_num, const ip_addr_t *dns_server);
+ dns_setserver(dns_num, dns_server);
return ERR_OK;
}
#endif /* RT_LWIP_DNS */
@@ -169,6 +169,7 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled)
}
#endif /* RT_LWIP_DHCP */
+#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
extern int lwip_ping_recv(int s, int *ttl);
extern err_t lwip_ping_send(int s, ip_addr_t *addr, int size);
@@ -259,6 +260,13 @@ void lwip_netdev_netstat(struct netdev *netif)
#endif
}
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
+#endif /* RT_USING_FINSH */
+
+static int lwip_netdev_set_default(struct netdev *netif)
+{
+ netif_set_default((struct netif *)netif->user_data);
+ return ERR_OK;
+}
const struct netdev_ops lwip_netdev_ops =
{
@@ -278,6 +286,7 @@ const struct netdev_ops lwip_netdev_ops =
NULL,
#endif /* RT_LWIP_DHCP */
+#ifdef RT_USING_FINSH
#ifdef RT_LWIP_USING_PING
lwip_netdev_ping,
#else
@@ -287,6 +296,9 @@ const struct netdev_ops lwip_netdev_ops =
#if defined (RT_LWIP_TCP) || defined (RT_LWIP_UDP)
lwip_netdev_netstat,
#endif /* RT_LWIP_TCP || RT_LWIP_UDP */
+#endif /* RT_USING_FINSH */
+
+ lwip_netdev_set_default,
};
static int netdev_add(struct netif *lwip_netif)
@@ -303,11 +315,6 @@ static int netdev_add(struct netif *lwip_netif)
{
return -ERR_IF;
}
-
- netdev->flags = lwip_netif->flags;
- netdev->ops = &lwip_netdev_ops;
- netdev->hwaddr_len = lwip_netif->hwaddr_len;
- rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
#ifdef SAL_USING_LWIP
extern int sal_lwip_netdev_set_pf_info(struct netdev *netdev);
@@ -317,6 +324,16 @@ static int netdev_add(struct netif *lwip_netif)
rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN);
result = netdev_register(netdev, name, (void *)lwip_netif);
+
+ /* Update netdev info after registered */
+ netdev->flags = lwip_netif->flags;
+ netdev->mtu = lwip_netif->mtu;
+ netdev->ops = &lwip_netdev_ops;
+ netdev->hwaddr_len = lwip_netif->hwaddr_len;
+ rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
+ netdev->ip_addr = lwip_netif->ip_addr;
+ netdev->gw = lwip_netif->gw;
+ netdev->netmask = lwip_netif->netmask;
#ifdef RT_LWIP_DHCP
netdev_low_level_set_dhcp_status(netdev, RT_TRUE);
@@ -325,6 +342,19 @@ static int netdev_add(struct netif *lwip_netif)
return result;
}
+static void netdev_del(struct netif *lwip_netif)
+{
+ char name[LWIP_NETIF_NAME_LEN + 1];
+ struct netdev *netdev;
+
+ RT_ASSERT(lwip_netif);
+
+ rt_strncpy(name, lwip_netif->name, LWIP_NETIF_NAME_LEN);
+ netdev = netdev_get_by_name(name);
+ netdev_unregister(netdev);
+ rt_free(netdev);
+}
+
/* synchronize lwIP network interface device and network interface device flags */
static int netdev_flags_sync(struct netif *lwip_netif)
{
@@ -534,6 +564,25 @@ rt_err_t eth_device_init(struct eth_device * dev, const char *name)
return eth_device_init_with_flag(dev, name, flags);
}
+void eth_device_deinit(struct eth_device *dev)
+{
+ struct netif* netif = dev->netif;
+
+#if LWIP_DHCP
+ dhcp_stop(netif);
+ dhcp_cleanup(netif);
+#endif
+ netif_set_down(netif);
+ netif_remove(netif);
+#ifdef RT_USING_NETDEV
+ netdev_del(netif);
+#endif
+ rt_device_close(&(dev->parent));
+ rt_device_unregister(&(dev->parent));
+ rt_sem_detach(&(dev->tx_ack));
+ rt_free(netif);
+}
+
#ifndef LWIP_NO_RX_THREAD
rt_err_t eth_device_ready(struct eth_device* dev)
{
@@ -711,8 +760,6 @@ int eth_system_device_init_private(void)
return (int)result;
}
-#ifdef RT_USING_FINSH
-#include <finsh.h>
void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
{
ip4_addr_t *ip;
@@ -758,6 +805,9 @@ void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr)
netif_set_netmask(netif, ip);
}
}
+
+#ifdef RT_USING_FINSH
+#include <finsh.h>
FINSH_FUNCTION_EXPORT(set_if, set network interface address);
#if LWIP_DNS
diff --git a/components/net/lwip-2.1.0/src/netif/lowpan6.c b/components/net/lwip-2.1.0/src/netif/lowpan6.c
index 5769522d5e..6397b0cb5d 100644
--- a/components/net/lwip-2.1.0/src/netif/lowpan6.c
+++ b/components/net/lwip-2.1.0/src/netif/lowpan6.c
@@ -50,7 +50,7 @@
#include "netif/lowpan6.h"
-#if LWIP_IPV6
+#if LWIP_IPV6 && LWIP_6LOWPAN
#include "lwip/ip.h"
#include "lwip/pbuf.h"
diff --git a/components/net/lwip_dhcpd/SConscript b/components/net/lwip_dhcpd/SConscript
index f7513cb0e3..16c673036a 100644
--- a/components/net/lwip_dhcpd/SConscript
+++ b/components/net/lwip_dhcpd/SConscript
@@ -2,7 +2,7 @@ from building import *
cwd = GetCurrentDir()
-if GetDepend('RT_USING_LWIP202'):
+if GetDepend('RT_USING_LWIP202') or GetDepend('RT_USING_LWIP210') :
src = ['dhcp_server_raw.c']
else:
src = ['dhcp_server.c']
diff --git a/components/net/lwip_dhcpd/dhcp_server.c b/components/net/lwip_dhcpd/dhcp_server.c
index c548ecfa98..93b4ad16f0 100644
--- a/components/net/lwip_dhcpd/dhcp_server.c
+++ b/components/net/lwip_dhcpd/dhcp_server.c
@@ -279,6 +279,7 @@ static void dhcpd_thread_entry(void *parameter)
{
/* bind failed. */
DEBUG_PRINTF("bind server address failed, errno=%d\n", errno);
+ closesocket(sock);
rt_free(recv_data);
return;
}
@@ -290,7 +291,13 @@ static void dhcpd_thread_entry(void *parameter)
{
bytes_read = recvfrom(sock, recv_data, BUFSZ - 1, 0,
(struct sockaddr *)&client_addr, &addr_len);
- if (bytes_read < DHCP_MSG_LEN)
+ if (bytes_read <= 0)
+ {
+ closesocket(sock);
+ rt_free(recv_data);
+ return;
+ }
+ else if (bytes_read < DHCP_MSG_LEN)
{
DEBUG_PRINTF("packet too short, wait for next!\n");
continue;
@@ -546,4 +553,3 @@ void dhcpd_start(const char *netif_name)
rt_thread_startup(thread);
}
}
-
diff --git a/components/net/lwip_dhcpd/dhcp_server.h b/components/net/lwip_dhcpd/dhcp_server.h
index a8056540ec..ea68d6b8ec 100644
--- a/components/net/lwip_dhcpd/dhcp_server.h
+++ b/components/net/lwip_dhcpd/dhcp_server.h
@@ -44,6 +44,7 @@ extern "C" {
#endif
void dhcpd_start(const char *netif_name);
+void dhcpd_stop(const char *netif_name);
#ifdef __cplusplus
}
diff --git a/components/net/lwip_dhcpd/dhcp_server_raw.c b/components/net/lwip_dhcpd/dhcp_server_raw.c
index 6b359eea4e..6c786301be 100644
--- a/components/net/lwip_dhcpd/dhcp_server_raw.c
+++ b/components/net/lwip_dhcpd/dhcp_server_raw.c
@@ -97,6 +97,10 @@
#define LWIP_NETIF_LOCK(...)
#define LWIP_NETIF_UNLOCK(...)
+#ifndef DHCP_SERVER_PORT
+#define DHCP_SERVER_PORT 67
+#endif
+
/**
* The dhcp client node struct.
*/
@@ -662,6 +666,7 @@ dhcp_server_start(struct netif *netif, ip4_addr_t *start, ip4_addr_t *end)
return ERR_OK;
}
+extern void set_if(const char *netif_name, const char *ip_addr, const char *gw_addr, const char *nm_addr);
void dhcpd_start(const char *netif_name)
{
@@ -697,8 +702,6 @@ void dhcpd_start(const char *netif_name)
if (1)
{
- extern void set_if(const char *netif_name, const char *ip_addr, const char *gw_addr, const char *nm_addr);
-
dhcp_stop(netif);
set_if(netif_name, DHCPD_SERVER_IP, "0.0.0.0", "255.255.255.0");
@@ -746,4 +749,83 @@ _exit:
return;
}
+void dhcpd_stop(const char *netif_name)
+{
+ struct dhcp_server *dhcp_server, *server_node;
+ struct netif *netif = netif_list;
+ struct dhcp_client_node *node, *next;
+
+ DEBUG_PRINTF("%s: %s\r\n", __FUNCTION__, netif_name);
+
+ LWIP_NETIF_LOCK();
+ if (strlen(netif_name) > sizeof(netif->name))
+ {
+ DEBUG_PRINTF("network interface name too long!\r\n");
+ goto _exit;
+ }
+ while (netif != RT_NULL)
+ {
+ if (strncmp(netif_name, netif->name, sizeof(netif->name)) == 0)
+ break;
+
+ netif = netif->next;
+ if (netif == RT_NULL)
+ {
+ DEBUG_PRINTF("network interface: %s not found!\r\n", netif_name);
+ break;
+ }
+ }
+
+ if (netif == RT_NULL)
+ {
+ goto _exit;
+ }
+
+ /* If this netif alreday use the dhcp server. */
+ for (dhcp_server = lw_dhcp_server; dhcp_server != NULL; dhcp_server = dhcp_server->next)
+ {
+ if (dhcp_server->netif == netif)
+ {
+ break;
+ }
+ }
+ if (dhcp_server == RT_NULL)
+ {
+ goto _exit;
+ }
+
+ /* remove dhcp server */
+ if (dhcp_server == lw_dhcp_server)
+ {
+ lw_dhcp_server = lw_dhcp_server->next;
+ }
+ else
+ {
+ server_node = lw_dhcp_server;
+ while (server_node->next && server_node->next != dhcp_server)
+ {
+ server_node = server_node->next;
+ }
+ if (server_node->next != RT_NULL)
+ {
+ server_node->next = server_node->next->next;
+ }
+ }
+
+ udp_disconnect(dhcp_server->pcb);
+ udp_remove(dhcp_server->pcb);
+
+ /* remove all client node */
+ for (node = dhcp_server->node_list; node != NULL; node = next)
+ {
+ next = node->next;
+ mem_free(node);
+ }
+
+ mem_free(dhcp_server);
+ set_if(netif_name, "0.0.0.0", "0.0.0.0", "0.0.0.0");
+
+_exit:
+ LWIP_NETIF_UNLOCK();
+}
diff --git a/components/net/netdev/include/netdev.h b/components/net/netdev/include/netdev.h
index 0be2a2bda3..e11a8929b0 100644
--- a/components/net/netdev/include/netdev.h
+++ b/components/net/netdev/include/netdev.h
@@ -27,6 +27,13 @@ extern "C" {
#define NETDEV_DNS_SERVERS_NUM 2U
#endif
+#if NETDEV_IPV6
+/* the maximum of dns server number supported */
+#ifndef NETDEV_IPV6_NUM_ADDRESSES
+#define NETDEV_IPV6_NUM_ADDRESSES 3U
+#endif
+#endif /* NETDEV_IPV6 */
+
/* whether the network interface device is 'up' (set by the network interface driver or application) */
#define NETDEV_FLAG_UP 0x01U
/* if set, the network interface device has broadcast capability, only supported in the 'lwIP' stack */
@@ -78,6 +85,9 @@ struct netdev
ip_addr_t ip_addr; /* IP address */
ip_addr_t netmask; /* subnet mask */
ip_addr_t gw; /* gateway */
+#if NETDEV_IPV6
+ ip_addr_t ip6_addr[NETDEV_IPV6_NUM_ADDRESSES]; /* array of IPv6 addresses */
+#endif /* NETDEV_IPV6 */
ip_addr_t dns_servers[NETDEV_DNS_SERVERS_NUM]; /* DNS server */
uint8_t hwaddr_len; /* hardware address length */
uint8_t hwaddr[NETDEV_HWADDR_MAX_LEN]; /* hardware address */
@@ -122,10 +132,14 @@ struct netdev_ops
int (*set_dns_server)(struct netdev *netdev, uint8_t dns_num, ip_addr_t *dns_server);
int (*set_dhcp)(struct netdev *netdev, rt_bool_t is_enabled);
+#ifdef RT_USING_FINSH
/* set network interface device common network interface device operations */
int (*ping)(struct netdev *netdev, const char *host, size_t data_len, uint32_t timeout, struct netdev_ping_resp *ping_resp);
void (*netstat)(struct netdev *netdev);
+#endif
+ /* set default network interface device in current network stack*/
+ int (*set_default)(struct netdev *netdev);
};
/* The network interface device registered and unregistered*/
@@ -163,6 +177,7 @@ int netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_
/* Set network interface device callback, it can be called when the status or address changed */
void netdev_set_status_callback(struct netdev *netdev, netdev_callback_fn status_callback);
+void netdev_set_addr_callback(struct netdev *netdev, netdev_callback_fn addr_callback);
/* Set network interface device status and address, this function can only be called in the network interface device driver */
void netdev_low_level_set_ipaddr(struct netdev *netdev, const ip_addr_t *ipaddr);
diff --git a/components/net/netdev/include/netdev_ipaddr.h b/components/net/netdev/include/netdev_ipaddr.h
index c2e13cd118..65970ec5b7 100644
--- a/components/net/netdev/include/netdev_ipaddr.h
+++ b/components/net/netdev/include/netdev_ipaddr.h
@@ -12,21 +12,53 @@
#define __NETDEV_IPADDR_H__
#include <stdint.h>
+#include <rtconfig.h>
#ifdef __cplusplus
extern "C" {
#endif
-/* Only supports the IPV4 protocol */
-#ifndef NETDEV_IPV4
-#define NETDEV_IPV4 1
-#endif
+/*
+ * Definitions of bits in internet address integers.
+ * On subnets, the decomposition of addresses to host and net parts
+ * is done according to subnet mask, not the masks here.
+ */
+#define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
+#define IN_CLASSA_NET 0xff000000
+#define IN_CLASSA_NSHIFT 24
+#define IN_CLASSA_HOST 0x00ffffff
+#define IN_CLASSA_MAX 128
-#ifndef NETDEV_IPV6
-#define NETDEV_IPV6 0
-#endif
+#define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
+#define IN_CLASSB_NET 0xffff0000
+#define IN_CLASSB_NSHIFT 16
+#define IN_CLASSB_HOST 0x0000ffff
+#define IN_CLASSB_MAX 65536
+
+#define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
+#define IN_CLASSC_NET 0xffffff00
+#define IN_CLASSC_NSHIFT 8
+#define IN_CLASSC_HOST 0x000000ff
+
+#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
+#define IN_MULTICAST(i) IN_CLASSD(i)
-#ifdef NETDEV_IPV4
+#define IN_EXPERIMENTAL(i) (((long)(i) & 0xe0000000) == 0xe0000000)
+#define IN_BADCLASS(i) (((long)(i) & 0xf0000000) == 0xf0000000)
+
+#define IN_LOOPBACKNET 127 /* official! */
+
+/* IP address types for use in ip_addr_t.type member */
+enum netdev_ip_addr_type {
+ /** IPv4 */
+ IPADDR_TYPE_V4 = 0U,
+ /** IPv6 */
+ IPADDR_TYPE_V6 = 6U,
+ /** IPv4+IPv6 ("dual-stack") */
+ IPADDR_TYPE_ANY = 46U
+};
+
+#if NETDEV_IPV4
/** IPv4 only: set the IP address given as an u32_t */
#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
/** IPv4 only: get the IP address as an u32_t */
@@ -68,7 +100,42 @@ typedef struct ip4_addr
uint32_t addr;
} ip4_addr_t;
-typedef ip4_addr_t ip_addr_t;
+/** 255.255.255.255 */
+#define IPADDR_NONE ((uint32_t)0xffffffffUL)
+/** 127.0.0.1 */
+#define IPADDR_LOOPBACK ((uint32_t)0x7f000001UL)
+/** 0.0.0.0 */
+#define IPADDR_ANY ((uint32_t)0x00000000UL)
+/** 255.255.255.255 */
+#define IPADDR_BROADCAST ((uint32_t)0xffffffffUL)
+
+/** 255.255.255.255 */
+#define INADDR_NONE IPADDR_NONE
+/** 127.0.0.1 */
+#define INADDR_LOOPBACK IPADDR_LOOPBACK
+/** 0.0.0.0 */
+#define INADDR_ANY IPADDR_ANY
+/** 255.255.255.255 */
+#define INADDR_BROADCAST IPADDR_BROADCAST
+
+#define IPADDR_BROADCAST_STRING "255.255.255.255"
+
+/** Copy IP address - faster than ip4_addr_set: no NULL check */
+#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
+#define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
+/** Safely copy one IP address to another (src may be NULL) */
+#define ip4_addr_set(dest, src) ((dest)->addr = ((src) == NULL ? 0 : (src)->addr))
+/** Set complete address to zero */
+#define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
+/** Set address to IPADDR_ANY (no need for htonl()) */
+#define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
+#define ip4_addr_isany_val(ipaddr) ((ipaddr).addr == IPADDR_ANY)
+#define ip4_addr_isany(ipaddr) ((ipaddr) == NULL || ip4_addr_isany_val(*(ipaddr)))
+
+in_addr_t netdev_ipaddr_addr(const char *cp);
+int netdev_ip4addr_aton(const char *cp, ip4_addr_t *addr);
+char *netdev_ip4addr_ntoa(const ip4_addr_t *addr);
+char *netdev_ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen);
#endif /* NETIF_IPV4 */
#if NETDEV_IPV6
@@ -85,23 +152,55 @@ struct in6_addr
typedef struct ip6_addr
{
uint32_t addr[4];
+#ifdef NETDEV_IPV6_SCOPES
+ uint8_t zone;
+#endif /* NETDEV_IPV6_SCOPES */
} ip6_addr_t;
-typedef ip6_addr ip_addr_t
+/** This macro can be used to initialize a variable of type struct in6_addr
+ to the IPv6 wildcard address. */
+#define IN6ADDR_ANY_INIT {{{0,0,0,0}}}
+/** This macro can be used to initialize a variable of type struct in6_addr
+ to the IPv6 loopback address. */
+#define IN6ADDR_LOOPBACK_INIT {{{0,0,0,PP_HTONL(1)}}}
+
+/** This variable is initialized by the system to contain the wildcard IPv6 address.
+ */
+extern const struct in6_addr in6addr_any;
+
+#define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
+ ((addr1)->addr[1] == (addr2)->addr[1]) && \
+ ((addr1)->addr[2] == (addr2)->addr[2]) && \
+ ((addr1)->addr[3] == (addr2)->addr[3]))
+/** Copy IPv6 address - faster than ip6_addr_set: no NULL check */
+#define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
+ (dest).addr[1] = (src).addr[1]; \
+ (dest).addr[2] = (src).addr[2]; \
+ (dest).addr[3] = (src).addr[3];}while(0)
+/** Safely copy one IPv6 address to another (src may be NULL) */
+#define ip6_addr_set(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : (src)->addr[0]; \
+ (dest)->addr[1] = (src) == NULL ? 0 : (src)->addr[1]; \
+ (dest)->addr[2] = (src) == NULL ? 0 : (src)->addr[2]; \
+ (dest)->addr[3] = (src) == NULL ? 0 : (src)->addr[3];}while(0)
+/** Set complete address to zero */
+#define ip6_addr_set_zero(ip6addr) do{(ip6addr)->addr[0] = 0; \
+ (ip6addr)->addr[1] = 0; \
+ (ip6addr)->addr[2] = 0; \
+ (ip6addr)->addr[3] = 0;}while(0)
+/** Set address to ipv6 'any' (no need for lwip_htonl()) */
+#define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr)
+#define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \
+ ((ip6addr).addr[1] == 0) && \
+ ((ip6addr).addr[2] == 0) && \
+ ((ip6addr).addr[3] == 0))
+#define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr)))
+
+int netdev_ip6addr_aton(const char *cp, ip6_addr_t *addr);
+char *netdev_ip6addr_ntoa(const ip6_addr_t *addr);
+char *netdev_ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen);
#endif /* NETIF_IPV6 */
#if NETDEV_IPV4 && NETDEV_IPV6
-/* IP address types for use in ip_addr_t.type member */
-enum netdev_ip_addr_type
-{
- /** IPv4 */
- IPADDR_TYPE_V4 = 0U,
- /** IPv6 */
- IPADDR_TYPE_V6 = 6U,
- /** IPv4+IPv6 ("dual-stack") */
- IPADDR_TYPE_ANY = 46U
-};
-
/* A union struct for both IP version's addresses */
typedef struct _ip_addr
{
@@ -113,54 +212,102 @@ typedef struct _ip_addr
/** @ref netdev_ip_addr_type */
uint8_t type;
} ip_addr_t;
-#endif /* NETIF_IPV4 && NETIF_IPV6 */
-/** 255.255.255.255 */
-#define IPADDR_NONE ((uint32_t)0xffffffffUL)
-/** 127.0.0.1 */
-#define IPADDR_LOOPBACK ((uint32_t)0x7f000001UL)
-/** 0.0.0.0 */
-#define IPADDR_ANY ((uint32_t)0x00000000UL)
-/** 255.255.255.255 */
-#define IPADDR_BROADCAST ((uint32_t)0xffffffffUL)
+#define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
+#define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_VAL(*(ipaddr), iptype); }}while(0)
+#define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
-/** 255.255.255.255 */
-#define INADDR_NONE IPADDR_NONE
-/** 127.0.0.1 */
-#define INADDR_LOOPBACK IPADDR_LOOPBACK
-/** 0.0.0.0 */
-#define INADDR_ANY IPADDR_ANY
-/** 255.255.255.255 */
-#define INADDR_BROADCAST IPADDR_BROADCAST
+#define IP_IS_V4_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4)
+#define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6)
+#define IP_IS_V4(ipaddr) (((ipaddr) == NULL) || IP_IS_V4_VAL(*(ipaddr)))
+#define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_VAL(*(ipaddr)))
-#define IPADDR_BROADCAST_STRING "255.255.255.255"
+/** Convert generic ip address to specific protocol version */
+#define ip_2_ip6(ipaddr) (&((ipaddr)->u_addr.ip6))
+/** Convert generic ip address to specific protocol version */
+#define ip_2_ip4(ipaddr) (&((ipaddr)->u_addr.ip4))
-#ifdef NETDEV_IPV4
+#define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \
+ ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \
+ ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); }}while(0)
+#define ip_addr_cmp(addr1, addr2) ((IP_GET_TYPE(addr1) != IP_GET_TYPE(addr2)) ? 0 : (IP_IS_V6_VAL(*(addr1)) ? \
+ ip6_addr_cmp(ip_2_ip6(addr1), ip_2_ip6(addr2)) : \
+ ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2))))
+#define ip_addr_set(dest, src) do{ IP_SET_TYPE(dest, IP_GET_TYPE(src)); if(IP_IS_V6(src)){ \
+ ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); }else{ \
+ ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); }}while(0)
+#define ip_addr_set_zero(ipaddr) do{ ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, 0); }while(0)
+#define ip_addr_set_any(is_ipv6, ipaddr) do{ if(is_ipv6){ \
+ ip6_addr_set_any(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
+ ip4_addr_set_any(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
-/** Copy IP address - faster than ip4_addr_set: no NULL check */
-#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
-#define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
-/** Set complete address to zero */
-#define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
-#define ip4_addr_isany_val(ipaddr) ((ipaddr).addr == IPADDR_ANY)
-#define ip4_addr_isany(ipaddr) ((ipaddr) == NULL || ip4_addr_isany_val(*(ipaddr)))
+#define ip_addr_isany_val(ipaddr) ((IP_IS_V6_VAL(ipaddr)) ? \
+ ip6_addr_isany_val(*ip_2_ip6(&(ipaddr))) : \
+ ip4_addr_isany_val(*ip_2_ip4(&(ipaddr))))
+#define ip_addr_isany(ipaddr) ((IP_IS_V6(ipaddr)) ? \
+ ip6_addr_isany(ip_2_ip6(ipaddr)) : \
+ ip4_addr_isany(ip_2_ip4(ipaddr)))
+
+/* directly map this to the lwip internal functions */
+#define inet_addr(cp) netdev_ipaddr_addr(cp)
+#define inet_aton(cp, addr) ((IP_IS_V6_VAL(*addr)) ? \
+ netdev_ip6addr_aton(cp, ip_2_ip6(addr)) : \
+ netdev_ip4addr_aton(cp, ip_2_ip4(addr)))
+#define inet_ntoa(addr) ((IP_IS_V6_VAL(addr)) ? \
+ netdev_ip6addr_ntoa(ip_2_ip6(&addr)) : \
+ netdev_ip4addr_ntoa(ip_2_ip4(&addr)))
+#define inet_ntoa_r(addr, buf, buflen) ((IP_IS_V6_VAL(addr)) ? \
+ netdev_ip6addr_ntoa_r(ip_2_ip6(&addr), buf, buflen) : \
+ netdev_ip4addr_ntoa_r(ip_2_ip4(&addr), buf, buflen))
+#elif NETDEV_IPV4 /* NETDEV_IPV4 */
+
+typedef ip4_addr_t ip_addr_t;
+
+#define IP_SET_TYPE_VAL(ipaddr, iptype)
+#define IP_SET_TYPE(ipaddr, iptype)
+#define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V4
#define ip_addr_copy(dest, src) ip4_addr_copy(dest, src)
#define ip_addr_cmp(addr1, addr2) ip4_addr_cmp(addr1, addr2)
+#define ip_addr_set(dest, src) ip4_addr_set(dest, src)
#define ip_addr_set_zero(ipaddr) ip4_addr_set_zero(ipaddr)
+#define ip_addr_set_any(is_ipv6, ipaddr) ip4_addr_set_any(ipaddr)
+#define ip_addr_isany_val(ipaddr) ip4_addr_isany_val(ipaddr)
#define ip_addr_isany(ipaddr) ip4_addr_isany(ipaddr)
-in_addr_t netdev_ipaddr_addr(const char *cp);
-int netdev_ip4addr_aton(const char *cp, ip4_addr_t *addr);
-char *netdev_ip4addr_ntoa(const ip4_addr_t *addr);
-char *netdev_ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen);
-
+/* directly map this to the lwip internal functions */
#define inet_addr(cp) netdev_ipaddr_addr(cp)
#define inet_aton(cp, addr) netdev_ip4addr_aton(cp,(ip4_addr_t*)addr)
#define inet_ntoa(addr) netdev_ip4addr_ntoa((const ip4_addr_t*)&(addr))
#define inet_ntoa_r(addr, buf, buflen) netdev_ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
+#else /* NETDEV_IPV6 */
+
+typedef ip6_addr_t ip_addr_t;
+
+#define IP_SET_TYPE_VAL(ipaddr, iptype)
+#define IP_SET_TYPE(ipaddr, iptype)
+#define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V6
+
+#define ip_addr_copy(dest, src) ip6_addr_copy(dest, src)
+#define ip_addr_cmp(addr1, addr2) ip6_addr_cmp(addr1, addr2)
+#define ip_addr_set(dest, src) ip6_addr_set(dest, src)
+#define ip_addr_set_zero(ipaddr) ip6_addr_set_zero(ipaddr)
+#define ip_addr_set_any(is_ipv6, ipaddr) ip6_addr_set_any(ipaddr)
+#define ip_addr_isany_val(ipaddr) ip6_addr_isany_val(ipaddr)
+#define ip_addr_isany(ipaddr) ip6_addr_isany(ipaddr)
+
+/* directly map this to the lwip internal functions */
+#define inet_aton(cp, addr) netdev_ip6addr_aton(cp, (ip6_addr_t*)addr)
+#define inet_ntoa(addr) netdev_ip6addr_ntoa((const ip6_addr_t*)&(addr))
+#define inet_ntoa_r(addr, buf, buflen) netdev_ip6addr_ntoa_r((const ip6_addr_t*)&(addr), buf, buflen)
+#endif /* NTDEV_IPV4 && NTDEV_IPV6 */
+
+
+const char *netdev_inet_ntop(int af, const void *src, char *dst, int32_t size);
+int netdev_inet_pton(int af, const char *src, void *dst);
-#endif /* NETDEV_IPV4 */
+#define inet_ntop(af, src, dst, size) netdev_inet_ntop(af, src, dst, size)
+#define inet_pton(af, src, dst) netdev_inet_pton(af, src, dst)
#ifdef __cplusplus
}
diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c
index 5f49a46f17..68e5364a9e 100644
--- a/components/net/netdev/src/netdev.c
+++ b/components/net/netdev/src/netdev.c
@@ -34,11 +34,11 @@ struct netdev *netdev_default;
/**
* This function will register network interface device and
* add it to network interface device list.
- *
+ *
* @param netdev the network interface device object
* @param name the network interface device name
* @param user_data user-specific data
- *
+ *
* @return 0: registered successfully
* -1: registered failed
*/
@@ -58,9 +58,21 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
ip_addr_set_zero(&(netdev->ip_addr));
ip_addr_set_zero(&(netdev->netmask));
ip_addr_set_zero(&(netdev->gw));
+
+ IP_SET_TYPE_VAL(netdev->ip_addr, IPADDR_TYPE_V4);
+ IP_SET_TYPE_VAL(netdev->netmask, IPADDR_TYPE_V4);
+ IP_SET_TYPE_VAL(netdev->gw, IPADDR_TYPE_V4);
+#if NETDEV_IPV6
+ for (index = 0; index < NETDEV_IPV6_NUM_ADDRESSES; index++)
+ {
+ ip_addr_set_zero(&(netdev->ip6_addr[index]));
+ IP_SET_TYPE_VAL(netdev->ip_addr, IPADDR_TYPE_V6);
+ }
+#endif /* NETDEV_IPV6 */
for (index = 0; index < NETDEV_DNS_SERVERS_NUM; index++)
{
ip_addr_set_zero(&(netdev->dns_servers[index]));
+ IP_SET_TYPE_VAL(netdev->ip_addr, IPADDR_TYPE_V4);
}
netdev->status_callback = RT_NULL;
netdev->addr_callback = RT_NULL;
@@ -87,15 +99,15 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
rt_hw_interrupt_enable(level);
- return RT_EOK;
+ return RT_EOK;
}
/**
* This function will unregister network interface device and
* delete it from network interface device list.
- *
+ *
* @param netdev the network interface device object
- *
+ *
* @return 0: unregistered successfully
* -1: unregistered failed
*/
@@ -106,7 +118,7 @@ int netdev_unregister(struct netdev *netdev)
struct netdev *cur_netdev = RT_NULL;
RT_ASSERT(netdev);
-
+
if (netdev_list == RT_NULL)
{
return -RT_ERROR;
@@ -117,29 +129,46 @@ int netdev_unregister(struct netdev *netdev)
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
cur_netdev = rt_slist_entry(node, struct netdev, list);
- if (cur_netdev && (rt_memcpy(cur_netdev, netdev, sizeof(struct netdev)) == 0))
+ if (cur_netdev == netdev)
{
- rt_slist_remove(&(netdev_list->list), &(cur_netdev->list));
- rt_hw_interrupt_enable(level);
-
- return RT_EOK;
+ /* find this network interface device in network interface device list */
+ if (netdev_list == netdev && rt_slist_next(&netdev_list->list) == RT_NULL)
+ {
+ netdev_list = RT_NULL;
+ }
+ else
+ {
+ rt_slist_remove(&(netdev_list->list), &(cur_netdev->list));
+ }
+ if (netdev_default == netdev)
+ {
+ netdev_default = netdev_list;
+ }
+ break;
}
}
-
rt_hw_interrupt_enable(level);
- /* not find this network interface device in network interface device list */
+ if (cur_netdev == netdev)
+ {
+#ifdef RT_USING_SAL
+ extern int sal_netdev_cleanup(struct netdev *netdev);
+ sal_netdev_cleanup(netdev);
+#endif
+ rt_memset(netdev, 0, sizeof(*netdev));
+ }
+
return -RT_ERROR;
}
/**
* This function will get the first network interface device
* with the flags in network interface device list.
- *
+ *
* @param flags the network interface device flags
- *
+ *
* @return != NULL: network interface device object
- * NULL: get failed
+ * NULL: get failed
*/
struct netdev *netdev_get_first_by_flags(uint16_t flags)
{
@@ -172,11 +201,11 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
/**
* This function will get the first network interface device
* in network interface device list by IP address.
- *
+ *
* @param addr the network interface device IP address
- *
+ *
* @return != NULL: network interface device object
- * NULL: get failed
+ * NULL: get failed
*/
struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
{
@@ -209,11 +238,11 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
/**
* This function will get network interface device
* in network interface device list by netdev name.
- *
+ *
* @param name the network interface device name
- *
+ *
* @return != NULL: network interface device object
- * NULL: get failed
+ * NULL: get failed
*/
struct netdev *netdev_get_by_name(const char *name)
{
@@ -247,11 +276,11 @@ struct netdev *netdev_get_by_name(const char *name)
/**
* This function will get the first network interface device
* in network interface device list by protocol family type.
- *
+ *
* @param family the network interface device protocol family type
- *
+ *
* @return != NULL: network interface device object
- * NULL: get failed
+ * NULL: get failed
*/
struct netdev *netdev_get_by_family(int family)
{
@@ -296,15 +325,15 @@ struct netdev *netdev_get_by_family(int family)
/**
* This function will get the family type from network interface device
- *
+ *
* @param netdev network interface device object
- *
+ *
* @return the network interface device family type
*/
int netdev_family_get(struct netdev *netdev)
{
- RT_ASSERT(netdev);
-
+ RT_ASSERT(netdev);
+
return ((struct sal_proto_family *)netdev->sal_user_data)->family;
}
@@ -312,7 +341,7 @@ int netdev_family_get(struct netdev *netdev)
/**
* This function will set default network interface device.
- *
+ *
* @param netdev the network interface device to change
*/
void netdev_set_default(struct netdev *netdev)
@@ -320,15 +349,21 @@ void netdev_set_default(struct netdev *netdev)
if (netdev)
{
netdev_default = netdev;
- LOG_D("Setting default network interface device name(%s) successfully.", netdev->name);
+
+ if (netdev->ops->set_default)
+ {
+ /* set default network interface device in the current network stack */
+ netdev->ops->set_default(netdev);
+ }
+ LOG_D("Setting default network interface device name(%s) successfully.", netdev->name);
}
}
/**
* This function will enable network interface device .
- *
+ *
* @param netdev the network interface device to change
- *
+ *
* @return 0: set status successfully
* -1: set status failed
*/
@@ -341,7 +376,7 @@ int netdev_set_up(struct netdev *netdev)
LOG_E("The network interface device(%s) not support to set status.", netdev->name);
return -RT_ERROR;
}
-
+
/* network interface device status flags check */
if (netdev_is_up(netdev))
{
@@ -353,9 +388,9 @@ int netdev_set_up(struct netdev *netdev)
}
/**
* This function will disable network interface device.
- *
+ *
* @param netdev the network interface device to change
- *
+ *
* @return 0: set status successfully
* -1: set sttaus failed
*/
@@ -368,7 +403,7 @@ int netdev_set_down(struct netdev *netdev)
LOG_E("The network interface device(%s) not support to set status.", netdev->name);
return -RT_ERROR;
}
-
+
/* network interface device status flags check */
if (!netdev_is_up(netdev))
{
@@ -381,10 +416,10 @@ int netdev_set_down(struct netdev *netdev)
/**
* This function will control network interface device DHCP capability enable or disable.
- *
+ *
* @param netdev the network interface device device to change
* @param is_enable the new DHCP status
- *
+ *
* @return 0: set DHCP status successfully
* -1: set DHCP status failed
*/
@@ -403,17 +438,17 @@ int netdev_dhcp_enabled(struct netdev *netdev, rt_bool_t is_enabled)
{
return RT_EOK;
}
-
+
/* execute network interface device DHCP capability control operations */
return netdev->ops->set_dhcp(netdev, is_enabled);
}
/**
* This function will set network interface device IP address.
- *
+ *
* @param netdev the network interface device to change
* @param ipaddr the new IP address
- *
+ *
* @return 0: set IP address successfully
* -1: set IP address failed
*/
@@ -427,7 +462,7 @@ int netdev_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr)
LOG_E("The network interface device(%s) not support to set IP address.", netdev->name);
return -RT_ERROR;
}
-
+
if (netdev_is_dhcp_enabled(netdev))
{
LOG_E("The network interface device(%s) DHCP capability is enable, not support set IP address.", netdev->name);
@@ -440,10 +475,10 @@ int netdev_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr)
/**
* This function will set network interface device netmask address.
- *
+ *
* @param netdev the network interface device to change
* @param netmask the new netmask address
- *
+ *
* @return 0: set netmask address successfully
* -1: set netmask address failed
*/
@@ -457,7 +492,7 @@ int netdev_set_netmask(struct netdev *netdev, const ip_addr_t *netmask)
LOG_E("The network interface device(%s) not support to set netmask address.", netdev->name);
return -RT_ERROR;
}
-
+
if (netdev_is_dhcp_enabled(netdev))
{
LOG_E("The network interface device(%s) DHCP capability is enable, not support set netmask address.", netdev->name);
@@ -470,10 +505,10 @@ int netdev_set_netmask(struct netdev *netdev, const ip_addr_t *netmask)
/**
* This function will set network interface device gateway address.
- *
+ *
* @param netdev the network interface device to change
- * @param gateway the new gateway address
- *
+ * @param gateway the new gateway address
+ *
* @return 0: set gateway address successfully
* -1: set gateway address failed
*/
@@ -487,7 +522,7 @@ int netdev_set_gw(struct netdev *netdev, const ip_addr_t *gw)
LOG_E("The network interface device(%s) not support to set gateway address.", netdev->name);
return -RT_ERROR;
}
-
+
if (netdev_is_dhcp_enabled(netdev))
{
LOG_E("The network interface device(%s) DHCP capability is enable, not support set gateway address.", netdev->name);
@@ -500,10 +535,10 @@ int netdev_set_gw(struct netdev *netdev, const ip_addr_t *gw)
/**
* This function will set network interface device DNS server address.
- *
+ *
* @param netdev the network interface device to change
* @param dns_server the new DNS server address
- *
+ *
* @return 0: set netmask address successfully
* -1: set netmask address failed
*/
@@ -530,7 +565,7 @@ int netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_
/**
* This function will set callback to be called when the network interface device status has been changed.
- *
+ *
* @param netdev the network interface device to change
* @param status_callback the callback be called when the status has been changed.
*/
@@ -544,7 +579,7 @@ void netdev_set_status_callback(struct netdev *netdev, netdev_callback_fn status
/**
* This function will set callback to be called when the network interface device address has been changed.
- *
+ *
* @param netdev the network interface device to change
* @param addr_callback the callback be called when the address has been changed.
*/
@@ -560,7 +595,7 @@ void netdev_set_addr_callback(struct netdev *netdev, netdev_callback_fn addr_cal
/**
* This function will set network interface device IP address.
* @NOTE it can only be called in the network interface device driver.
- *
+ *
* @param netdev the network interface device to change
* @param ipaddr the new IP address
*/
@@ -591,7 +626,7 @@ void netdev_low_level_set_ipaddr(struct netdev *netdev, const ip_addr_t *ip_addr
/**
* This function will set network interface device netmask address.
* @NOTE it can only be called in the network interface device driver.
- *
+ *
* @param netdev the network interface device to change
* @param netmask the new netmask address
*/
@@ -605,7 +640,7 @@ void netdev_low_level_set_netmask(struct netdev *netdev, const ip_addr_t *netmas
#ifdef RT_USING_SAL
/* set network interface device flags to internet up */
- if (netdev_is_up(netdev) && netdev_is_link_up(netdev) &&
+ if (netdev_is_up(netdev) && netdev_is_link_up(netdev) &&
!ip_addr_isany(&(netdev->ip_addr)))
{
sal_check_netdev_internet_up(netdev);
@@ -623,7 +658,7 @@ void netdev_low_level_set_netmask(struct netdev *netdev, const ip_addr_t *netmas
/**
* This function will set network interface device gateway address.
* @NOTE it can only be called in the network interface device driver.
- *
+ *
* @param netdev the network interface device to change
* @param gateway the new gateway address
*/
@@ -637,7 +672,7 @@ void netdev_low_level_set_gw(struct netdev *netdev, const ip_addr_t *gw)
#ifdef RT_USING_SAL
/* set network interface device flags to internet up */
- if (netdev_is_up(netdev) && netdev_is_link_up(netdev) &&
+ if (netdev_is_up(netdev) && netdev_is_link_up(netdev) &&
!ip_addr_isany(&(netdev->ip_addr)))
{
sal_check_netdev_internet_up(netdev);
@@ -655,10 +690,10 @@ void netdev_low_level_set_gw(struct netdev *netdev, const ip_addr_t *gw)
/**
* This function will set network interface device DNS server address.
* @NOTE it can only be called in the network interface device driver.
- *
+ *
* @param netdev the network interface device to change
* @param dns_server the new DNS server address
- *
+ *
*/
void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server)
{
@@ -666,6 +701,10 @@ void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, con
RT_ASSERT(dns_server);
+ if (netdev == RT_NULL)
+ {
+ return;
+ }
/* check DNS servers is exist */
for (index = 0; index < NETDEV_DNS_SERVERS_NUM; index++)
{
@@ -675,7 +714,7 @@ void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, con
}
}
- if (netdev && dns_num < NETDEV_DNS_SERVERS_NUM)
+ if (dns_num < NETDEV_DNS_SERVERS_NUM)
{
ip_addr_copy(netdev->dns_servers[dns_num], *dns_server);
@@ -707,7 +746,7 @@ static void netdev_auto_change_default(struct netdev *netdev)
/**
* This function will set network interface device status.
* @NOTE it can only be called in the network interface device driver.
- *
+ *
* @param netdev the network interface device to change
* @param is_up the new status
*/
@@ -740,14 +779,14 @@ void netdev_low_level_set_status(struct netdev *netdev, rt_bool_t is_up)
/**
* This function will set network interface device active link status.
* @NOTE it can only be called in the network interface device driver.
- *
+ *
* @param netdev the network interface device to change
* @param is_up the new link status
*/
void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
{
if (netdev && netdev_is_link_up(netdev) != is_up)
- {
+ {
if (is_up)
{
netdev->flags |= NETDEV_FLAG_LINK_UP;
@@ -763,7 +802,7 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
else
{
netdev->flags &= ~NETDEV_FLAG_LINK_UP;
-
+
/* set network interface device flags to internet down */
netdev->flags &= ~NETDEV_FLAG_INTERNET_UP;
@@ -784,7 +823,7 @@ void netdev_low_level_set_link_status(struct netdev *netdev, rt_bool_t is_up)
/**
* This function will set network interface device DHCP status.
* @NOTE it can only be called in the network interface device driver.
- *
+ *
* @param netdev the network interface device to change
* @param is_up the new DHCP status
*/
@@ -809,7 +848,7 @@ void netdev_low_level_set_dhcp_status(struct netdev *netdev, rt_bool_t is_enable
}
}
-#ifdef FINSH_USING_MSH
+#ifdef RT_USING_FINSH
#include <finsh.h>
@@ -820,7 +859,6 @@ static void netdev_list_if(void)
#define NETDEV_IFCONFIG_IEMI_MAX_LEN 8
rt_ubase_t index;
- rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
struct netdev *cur_netdev_list = netdev_list;
@@ -831,15 +869,13 @@ static void netdev_list_if(void)
return;
}
- level = rt_hw_interrupt_disable();
-
for (node = &(cur_netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_list_entry(node, struct netdev, list);
- rt_kprintf("network interface device: %s%s\n",
- netdev->name,
- (netdev == netdev_default)?" (Default)":"");
+ rt_kprintf("network interface device: %.*s%s\n",
+ RT_NAME_MAX, netdev->name,
+ (netdev == netdev_default) ? " (Default)" : "");
rt_kprintf("MTU: %d\n", netdev->mtu);
/* 6 - MAC address, 8 - IEMI */
@@ -853,13 +889,13 @@ static void netdev_list_if(void)
}
else if (netdev->hwaddr_len == NETDEV_IFCONFIG_IEMI_MAX_LEN)
{
- rt_kprintf("IEMI: ");
+ rt_kprintf("IMEI: ");
for (index = 0; index < netdev->hwaddr_len; index++)
{
/* two numbers are displayed at one time*/
if (netdev->hwaddr[index] < 10 && index != netdev->hwaddr_len - 1)
rt_kprintf("0");
-
+
rt_kprintf("%d", netdev->hwaddr[index]);
}
}
@@ -881,18 +917,38 @@ static void netdev_list_if(void)
rt_kprintf("gw address: %s\n", inet_ntoa(netdev->gw));
rt_kprintf("net mask : %s\n", inet_ntoa(netdev->netmask));
+#if NETDEV_IPV6
+ {
+ ip_addr_t *addr;
+ int i;
+
+ addr = &netdev->ip6_addr[0];
+
+ if (!ip_addr_isany(addr))
+ {
+ rt_kprintf("ipv6 link-local: %s %s\n", inet_ntoa(*addr),
+ !ip_addr_isany(addr) ? "VALID" : "INVALID");
+
+ for (i = 1; i < NETDEV_IPV6_NUM_ADDRESSES; i++)
+ {
+ addr = &netdev->ip6_addr[i];
+ rt_kprintf("ipv6[%d] address: %s %s\n", i, inet_ntoa(*addr),
+ !ip_addr_isany(addr) ? "VALID" : "INVALID");
+ }
+ }
+ }
+#endif /* NETDEV_IPV6 */
+
for (index = 0; index < NETDEV_DNS_SERVERS_NUM; index++)
{
rt_kprintf("dns server #%d: %s\n", index, inet_ntoa(netdev->dns_servers[index]));
}
-
+
if (rt_slist_next(node))
{
rt_kprintf("\n");
}
}
-
- rt_hw_interrupt_enable(level);
}
static void netdev_set_if(char* netdev_name, char* ip_addr, char* gw_addr, char* nm_addr)
@@ -951,7 +1007,7 @@ FINSH_FUNCTION_EXPORT_ALIAS(netdev_ifconfig, __cmd_ifconfig, list the informatio
#endif /* NETDEV_USING_IFCONFIG */
#ifdef NETDEV_USING_PING
-static int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
+int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
{
#define NETDEV_PING_DATA_SIZE 32
/** ping receive timeout - in milliseconds */
@@ -966,7 +1022,7 @@ static int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
struct netdev *netdev = RT_NULL;
struct netdev_ping_resp ping_resp;
int index, ret = 0;
-
+
if (size == 0)
{
size = NETDEV_PING_DATA_SIZE;
@@ -981,20 +1037,34 @@ static int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
{
/* using first internet up status network interface device */
netdev = netdev_get_first_by_flags(NETDEV_FLAG_LINK_UP);
- if (netdev == RT_NULL || NETDEV_PING_IS_COMMONICABLE(netdev) == 0)
+ if (netdev == RT_NULL)
+ {
+ rt_kprintf("ping: not found available network interface device.\n");
+ return -RT_ERROR;
+ }
+ else if (netdev->ops == RT_NULL || netdev->ops->ping == RT_NULL)
+ {
+ rt_kprintf("ping: network interface device(%s) not support ping feature.\n", netdev->name);
+ return -RT_ERROR;
+ }
+ else if (!netdev_is_up(netdev) || !netdev_is_link_up(netdev))
{
- rt_kprintf("ping: network interface device get error.\n");
+ rt_kprintf("ping: network interface device(%s) status error.\n", netdev->name);
return -RT_ERROR;
}
}
for (index = 0; index < times; index++)
{
+ int delay_tick = 0;
+ rt_tick_t start_tick = 0;
+
rt_memset(&ping_resp, 0x00, sizeof(struct netdev_ping_resp));
+ start_tick = rt_tick_get();
ret = netdev->ops->ping(netdev, (const char *)target_name, size, NETDEV_PING_RECV_TIMEO, &ping_resp);
if (ret == -RT_ETIMEOUT)
{
- rt_kprintf("ping: from %s icmp_seq=%d timeout\n",
+ rt_kprintf("ping: from %s icmp_seq=%d timeout\n",
(ip_addr_isany(&(ping_resp.ip_addr))) ? target_name : inet_ntoa(ping_resp.ip_addr), index);
}
else if (ret == -RT_ERROR)
@@ -1007,17 +1077,19 @@ static int netdev_cmd_ping(char* target_name, rt_uint32_t times, rt_size_t size)
{
if (ping_resp.ttl == 0)
{
- rt_kprintf("%d bytes from %s icmp_seq=%d time=%d ms\n",
+ rt_kprintf("%d bytes from %s icmp_seq=%d time=%d ms\n",
ping_resp.data_len, inet_ntoa(ping_resp.ip_addr), index, ping_resp.ticks);
}
else
{
- rt_kprintf("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms\n",
+ rt_kprintf("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms\n",
ping_resp.data_len, inet_ntoa(ping_resp.ip_addr), index, ping_resp.ttl, ping_resp.ticks);
}
}
-
- rt_thread_mdelay(NETDEV_PING_DELAY);
+
+ /* if the response time is more than NETDEV_PING_DELAY, no nead to delay */
+ delay_tick = ((rt_tick_get() - start_tick) > NETDEV_PING_DELAY) || (index == times) ? 0 : NETDEV_PING_DELAY;
+ rt_thread_delay(delay_tick);
}
return RT_EOK;
@@ -1041,33 +1113,28 @@ FINSH_FUNCTION_EXPORT_ALIAS(netdev_ping, __cmd_ping, ping network host);
static void netdev_list_dns(void)
{
- rt_base_t level;
int index = 0;
struct netdev *netdev = RT_NULL;
rt_slist_t *node = RT_NULL;
- level = rt_hw_interrupt_disable();
-
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_list_entry(node, struct netdev, list);
- rt_kprintf("network interface device: %s%s\n",
- netdev->name,
+ rt_kprintf("network interface device: %.*s%s\n",
+ RT_NAME_MAX, netdev->name,
(netdev == netdev_default)?" (Default)":"");
for(index = 0; index < NETDEV_DNS_SERVERS_NUM; index++)
{
rt_kprintf("dns server #%d: %s\n", index, inet_ntoa(netdev->dns_servers[index]));
}
-
+
if (rt_slist_next(node))
{
rt_kprintf("\n");
}
}
-
- rt_hw_interrupt_enable(level);
}
static void netdev_set_dns(char *netdev_name, uint8_t dns_num, char *dns_server)
@@ -1083,9 +1150,10 @@ static void netdev_set_dns(char *netdev_name, uint8_t dns_num, char *dns_server)
}
inet_aton(dns_server, &dns_addr);
- netdev_set_dns_server(netdev, dns_num, &dns_addr);
-
- rt_kprintf("set network interface device(%s) dns server #0: %s\n", netdev_name, dns_server);
+ if (netdev_set_dns_server(netdev, dns_num, &dns_addr) == RT_EOK)
+ {
+ rt_kprintf("set network interface device(%s) dns server #%d: %s\n", netdev_name, dns_num, dns_server);
+ }
}
int netdev_dns(int argc, char **argv)
@@ -1115,7 +1183,6 @@ FINSH_FUNCTION_EXPORT_ALIAS(netdev_dns, __cmd_dns, list and set the information
#ifdef NETDEV_USING_NETSTAT
static void netdev_cmd_netstat(void)
{
- rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
struct netdev *cur_netdev_list = netdev_list;
@@ -1126,8 +1193,6 @@ static void netdev_cmd_netstat(void)
return;
}
- level = rt_hw_interrupt_disable();
-
for (node = &(cur_netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_list_entry(node, struct netdev, list);
@@ -1138,9 +1203,14 @@ static void netdev_cmd_netstat(void)
}
}
- rt_hw_interrupt_enable(level);
-
- netdev->ops->netstat(netdev);
+ if (netdev->ops->netstat != RT_NULL)
+ {
+ netdev->ops->netstat(netdev);
+ }
+ else
+ {
+ rt_kprintf("netstat: this command is not supported!\n");
+ }
}
int netdev_netstat(int argc, char **argv)
@@ -1149,7 +1219,7 @@ int netdev_netstat(int argc, char **argv)
{
rt_kprintf("Please input: netstat \n");
}
- else
+ else
{
netdev_cmd_netstat();
}
@@ -1159,4 +1229,4 @@ int netdev_netstat(int argc, char **argv)
FINSH_FUNCTION_EXPORT_ALIAS(netdev_netstat, __cmd_netstat, list the information of TCP / IP);
#endif /* NETDEV_USING_NETSTAT */
-#endif /* FINSH_USING_MSH */
+#endif /* RT_USING_FINSH */
diff --git a/components/net/netdev/src/netdev_ipaddr.c b/components/net/netdev/src/netdev_ipaddr.c
index 988bd50eb7..8d83937da9 100644
--- a/components/net/netdev/src/netdev_ipaddr.c
+++ b/components/net/netdev/src/netdev_ipaddr.c
@@ -19,8 +19,10 @@
#define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F'))
#define islower(c) in_range(c, 'a', 'z')
#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v')
+#define xchar(i) ((i) < 10 ? '0' + (i) : 'A' + (i) - 10)
#endif
+#if NETDEV_IPV4
/**
* Check whether "cp" is a valid ascii representation
@@ -255,3 +257,358 @@ in_addr_t netdev_ipaddr_addr(const char *cp)
}
return (IPADDR_NONE);
}
+
+#endif /* NETDEV_IPV4 */
+
+
+#if NETDEV_IPV6
+
+RT_WEAK const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
+
+/**
+ * Check whether "cp" is a valid ascii representation
+ * of an IPv6 address and convert to a binary address.
+ * Returns 1 if the address is valid, 0 if not.
+ *
+ * @param cp IPv6 address in ascii representation (e.g. "FF01::1")
+ * @param addr pointer to which to save the ip address in network order
+ * @return 1 if cp could be converted to addr, 0 on failure
+ */
+int
+netdev_ip6addr_aton(const char *cp, ip6_addr_t *addr)
+{
+ uint32_t addr_index, zero_blocks, current_block_index, current_block_value;
+ const char *s;
+
+ /* Count the number of colons, to count the number of blocks in a "::" sequence
+ zero_blocks may be 1 even if there are no :: sequences */
+ zero_blocks = 8;
+ for (s = cp; *s != 0; s++)
+ {
+ if (*s == ':')
+ {
+ zero_blocks--;
+ }
+ else if (!isxdigit(*s))
+ {
+ break;
+ }
+ }
+
+ /* parse each block */
+ addr_index = 0;
+ current_block_index = 0;
+ current_block_value = 0;
+ for (s = cp; *s != 0; s++)
+ {
+ if (*s == ':')
+ {
+ if (addr)
+ {
+ if (current_block_index & 0x1)
+ {
+ addr->addr[addr_index++] |= current_block_value;
+ }
+ else
+ {
+ addr->addr[addr_index] = current_block_value << 16;
+ }
+ }
+ current_block_index++;
+ current_block_value = 0;
+ if (current_block_index > 7)
+ {
+ /* address too long! */
+ return 0;
+ }
+ if (s[1] == ':')
+ {
+ if (s[2] == ':')
+ {
+ /* invalid format: three successive colons */
+ return 0;
+ }
+ s++;
+ /* "::" found, set zeros */
+ while (zero_blocks > 0)
+ {
+ zero_blocks--;
+ if (current_block_index & 0x1)
+ {
+ addr_index++;
+ }
+ else
+ {
+ if (addr)
+ {
+ addr->addr[addr_index] = 0;
+ }
+ }
+ current_block_index++;
+ if (current_block_index > 7)
+ {
+ /* address too long! */
+ return 0;
+ }
+ }
+ }
+ }
+ else if (isxdigit(*s))
+ {
+ /* add current digit */
+ current_block_value = (current_block_value << 4) +
+ (isdigit(*s) ? (uint32_t)(*s - '0') : (uint32_t)(10 + (islower(*s) ? *s - 'a' : *s - 'A')));
+ }
+ else
+ {
+ /* unexpected digit, space? CRLF? */
+ break;
+ }
+ }
+
+ if (addr)
+ {
+ if (current_block_index & 0x1)
+ {
+ addr->addr[addr_index++] |= current_block_value;
+ }
+ else
+ {
+ addr->addr[addr_index] = current_block_value << 16;
+ }
+ }
+
+ /* convert to network byte order. */
+ if (addr)
+ {
+ for (addr_index = 0; addr_index < 4; addr_index++)
+ {
+ addr->addr[addr_index] = htonl(addr->addr[addr_index]);
+ }
+ }
+
+ if (current_block_index != 7)
+ {
+ return 0;
+ }
+
+ return 1;
+}
+
+/**
+ * Same as ipaddr_ntoa, but reentrant since a user-supplied buffer is used.
+ *
+ * @param addr ip6 address in network order to convert
+ * @param buf target buffer where the string is stored
+ * @param buflen length of buf
+ * @return either pointer to buf which now holds the ASCII
+ * representation of addr or NULL if buf was too small
+ */
+char *
+netdev_ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen)
+{
+ uint32_t current_block_index, current_block_value, next_block_value;
+ int32_t i;
+ uint8_t zero_flag, empty_block_flag;
+
+ i = 0;
+ empty_block_flag = 0; /* used to indicate a zero chain for "::' */
+
+ for (current_block_index = 0; current_block_index < 8; current_block_index++)
+ {
+ /* get the current 16-bit block */
+ current_block_value = htonl(addr->addr[current_block_index >> 1]);
+ if ((current_block_index & 0x1) == 0)
+ {
+ current_block_value = current_block_value >> 16;
+ }
+ current_block_value &= 0xffff;
+
+ /* Check for empty block. */
+ if (current_block_value == 0)
+ {
+ if (current_block_index == 7 && empty_block_flag == 1)
+ {
+ /* special case, we must render a ':' for the last block. */
+ buf[i++] = ':';
+ if (i >= buflen)
+ {
+ return NULL;
+ }
+ break;
+ }
+ if (empty_block_flag == 0)
+ {
+ /* generate empty block "::", but only if more than one contiguous zero block,
+ * according to current formatting suggestions RFC 5952. */
+ next_block_value = htonl(addr->addr[(current_block_index + 1) >> 1]);
+ if ((current_block_index & 0x1) == 0x01)
+ {
+ next_block_value = next_block_value >> 16;
+ }
+ next_block_value &= 0xffff;
+ if (next_block_value == 0)
+ {
+ empty_block_flag = 1;
+ buf[i++] = ':';
+ if (i >= buflen)
+ {
+ return NULL;
+ }
+ continue; /* move on to next block. */
+ }
+ }
+ else if (empty_block_flag == 1)
+ {
+ /* move on to next block. */
+ continue;
+ }
+ }
+ else if (empty_block_flag == 1)
+ {
+ /* Set this flag value so we don't produce multiple empty blocks. */
+ empty_block_flag = 2;
+ }
+
+ if (current_block_index > 0)
+ {
+ buf[i++] = ':';
+ if (i >= buflen)
+ {
+ return NULL;
+ }
+ }
+
+ if ((current_block_value & 0xf000) == 0)
+ {
+ zero_flag = 1;
+ }
+ else
+ {
+ buf[i++] = xchar(((current_block_value & 0xf000) >> 12));
+ zero_flag = 0;
+ if (i >= buflen)
+ {
+ return NULL;
+ }
+ }
+
+ if (((current_block_value & 0xf00) == 0) && (zero_flag))
+ {
+ /* do nothing */
+ }
+ else
+ {
+ buf[i++] = xchar(((current_block_value & 0xf00) >> 8));
+ zero_flag = 0;
+ if (i >= buflen)
+ {
+ return NULL;
+ }
+ }
+
+ if (((current_block_value & 0xf0) == 0) && (zero_flag))
+ {
+ /* do nothing */
+ }
+ else
+ {
+ buf[i++] = xchar(((current_block_value & 0xf0) >> 4));
+ zero_flag = 0;
+ if (i >= buflen)
+ {
+ return NULL;
+ }
+ }
+
+ buf[i++] = xchar((current_block_value & 0xf));
+ if (i >= buflen)
+ {
+ return NULL;
+ }
+ }
+
+ buf[i] = 0;
+
+ return buf;
+}
+
+/**
+ * Convert numeric IPv6 address into ASCII representation.
+ * returns ptr to static buffer; not reentrant!
+ *
+ * @param addr ip6 address in network order to convert
+ * @return pointer to a global static (!) buffer that holds the ASCII
+ * representation of addr
+ */
+char *
+netdev_ip6addr_ntoa(const ip6_addr_t *addr)
+{
+ static char str[40];
+ return netdev_ip6addr_ntoa_r(addr, str, 40);
+}
+
+#endif /* NETDEV_IPV6 */
+
+const char *
+netdev_inet_ntop(int af, const void *src, char *dst, int32_t size)
+{
+#define AF_INET 2
+#define AF_INET6 10
+
+ const char *ret = NULL;
+ int size_int = (int)size;
+ if (size_int < 0)
+ {
+ return NULL;
+ }
+ switch (af)
+ {
+#if NTEDEV_IPV4
+ case AF_INET:
+ return netdev_ip4addr_ntoa_r((const ip4_addr_t *)src, dst, size_int);
+#endif
+#if NETDEV_IPV6
+ case AF_INET6:
+ return netdev_ip6addr_ntoa_r((const ip6_addr_t *)src, dst, size_int);
+#endif
+ default:
+ break;
+ }
+ return ret;
+}
+
+int
+netdev_inet_pton(int af, const char *src, void *dst)
+{
+#define AF_INET 2
+#define AF_INET6 10
+
+ int err;
+ switch (af)
+ {
+#if NETDEV_IPV4
+ case AF_INET:
+ err = netdev_ip4addr_aton(src, (ip4_addr_t *)dst);
+ break;
+#endif
+#if NETDEV_IPV6
+ case AF_INET6:
+ {
+ /* convert into temporary variable since ip6_addr_t might be larger
+ than in6_addr when scopes are enabled */
+ ip6_addr_t addr;
+ err = netdev_ip6addr_aton(src, &addr);
+ if (err)
+ {
+ rt_memcpy(dst, &addr.addr, sizeof(addr.addr));
+ }
+ break;
+ }
+#endif
+ default:
+ err = -1;
+ break;
+ }
+ return err;
+}
diff --git a/components/net/sal_socket/impl/af_inet_lwip.c b/components/net/sal_socket/impl/af_inet_lwip.c
index 95e7633635..56df735ab9 100644
--- a/components/net/sal_socket/impl/af_inet_lwip.c
+++ b/components/net/sal_socket/impl/af_inet_lwip.c
@@ -25,6 +25,12 @@
#include <netdev.h>
+#if (LWIP_VERSION < 0x2000000) && NETDEV_IPV6
+#error "The lwIP version is not support IPV6, please disable netdev IPV6 configuration "
+#elif (LWIP_VERSION > 0x2000000) && (NETDEV_IPV6 != LWIP_IPV6)
+#error "IPV6 configuration error, Please check and synchronize netdev and lwip IPV6 configuration."
+#endif
+
#if LWIP_VERSION < 0x2000000
#define SELWAIT_T int
#else
@@ -267,6 +273,8 @@ static int inet_poll(struct dfs_fd *file, struct rt_pollreq *req)
if (sock->errevent)
{
mask |= POLLERR;
+ /* clean error event */
+ sock->errevent = 0;
}
rt_hw_interrupt_enable(level);
}
@@ -308,7 +316,11 @@ static const struct sal_netdb_ops lwip_netdb_ops =
static const struct sal_proto_family lwip_inet_family =
{
AF_INET,
+#if LWIP_VERSION > 0x2000000
+ AF_INET6,
+#else
AF_INET,
+#endif
&lwip_socket_ops,
&lwip_netdb_ops,
};
diff --git a/components/net/sal_socket/include/sal_socket.h b/components/net/sal_socket/include/sal_socket.h
index d72f1e4c3c..b620bbe23c 100644
--- a/components/net/sal_socket/include/sal_socket.h
+++ b/components/net/sal_socket/include/sal_socket.h
@@ -157,6 +157,7 @@ struct sockaddr
char sa_data[14];
};
+#if NETDEV_IPV4
/* members are in network byte order */
struct sockaddr_in
{
@@ -167,6 +168,19 @@ struct sockaddr_in
#define SIN_ZERO_LEN 8
char sin_zero[SIN_ZERO_LEN];
};
+#endif /* NETDEV_IPV4 */
+
+#if NETDEV_IPV6
+struct sockaddr_in6
+{
+ uint8_t sin6_len; /* length of this structure */
+ sa_family_t sin6_family; /* AF_INET6 */
+ in_port_t sin6_port; /* Transport layer port # */
+ uint32_t sin6_flowinfo; /* IPv6 flow information */
+ struct in6_addr sin6_addr; /* IPv6 address */
+ uint32_t sin6_scope_id; /* Set of interfaces for scope */
+};
+#endif /* NETDEV_IPV6 */
struct sockaddr_storage
{
@@ -174,9 +188,9 @@ struct sockaddr_storage
sa_family_t ss_family;
char s2_data1[2];
uint32_t s2_data2[3];
-#if SAL_IPV6
- u32_t s2_data3[3];
-#endif /* SAL_IPV6 */
+#if NETDEV_IPV6
+ uint32_t s2_data3[3];
+#endif /* NETDEV_IPV6 */
};
int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen);
diff --git a/components/net/sal_socket/socket/net_sockets.c b/components/net/sal_socket/socket/net_sockets.c
index 12024c8173..a53b2f1f9c 100644
--- a/components/net/sal_socket/socket/net_sockets.c
+++ b/components/net/sal_socket/socket/net_sockets.c
@@ -105,9 +105,7 @@ int shutdown(int s, int how)
rt_set_errno(-ENOTSOCK);
error = -1;
}
-
- /* socket has been closed, delete it from file system fd */
- fd_put(d);
+
fd_put(d);
return error;
diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c
index 8f3149abd5..e5c55f8bf8 100644
--- a/components/net/sal_socket/src/sal_socket.c
+++ b/components/net/sal_socket/src/sal_socket.c
@@ -94,12 +94,12 @@ do {
* SAL (Socket Abstraction Layer) initialize.
*
* @return result 0: initialize success
- * -1: initialize failed
+ * -1: initialize failed
*/
int sal_init(void)
{
int cn;
-
+
if (init_ok)
{
LOG_D("Socket Abstraction Layer is already initialized.");
@@ -115,7 +115,7 @@ int sal_init(void)
LOG_E("No memory for socket table.\n");
return -1;
}
-
+
/* create sal socket lock */
rt_mutex_init(&sal_core_lock, "sal_lock", RT_IPC_FLAG_FIFO);
@@ -131,7 +131,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
{
#define SAL_INTERNET_VERSION 0x00
#define SAL_INTERNET_BUFF_LEN 12
-#define SAL_INTERNET_TIMEOUT (2 * RT_TICK_PER_SECOND)
+#define SAL_INTERNET_TIMEOUT (2)
#define SAL_INTERNET_HOST "link.rt-thread.org"
#define SAL_INTERNET_PORT 8101
@@ -148,7 +148,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
char send_data[SAL_INTERNET_BUFF_LEN], recv_data = 0;
struct rt_delayed_work *delay_work = (struct rt_delayed_work *)work;
- const char month[][SAL_INTERNET_MONTH_LEN] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
+ const char month[][SAL_INTERNET_MONTH_LEN] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char date[SAL_INTERNET_DATE_LEN];
int moth_num = 0;
@@ -175,7 +175,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
}
skt_ops = pf->skt_ops;
- if((sockfd = skt_ops->socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ if ((sockfd = skt_ops->socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
result = -RT_ERROR;
goto __exit;
@@ -224,7 +224,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
send_data[11] = RT_REVISION;
skt_ops->sendto(sockfd, send_data, SAL_INTERNET_BUFF_LEN, 0,
- (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
+ (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
result = skt_ops->recvfrom(sockfd, &recv_data, sizeof(recv_data), 0, (struct sockaddr *)&server_addr, &addr_len);
if (result < 0)
@@ -242,7 +242,7 @@ __exit:
if (result > 0)
{
LOG_D("Set network interface device(%s) internet status up.", netdev->name);
- netdev->flags |= NETDEV_FLAG_INTERNET_UP;
+ netdev->flags |= NETDEV_FLAG_INTERNET_UP;
}
else
{
@@ -277,7 +277,7 @@ int sal_check_netdev_internet_up(struct netdev *netdev)
rt_delayed_work_init(net_work, check_netdev_internet_up_work, (void *)netdev);
rt_work_submit(&(net_work->work), RT_TICK_PER_SECOND);
-
+
return 0;
}
@@ -316,10 +316,7 @@ struct sal_socket *sal_get_socket(int socket)
socket = socket - SAL_SOCKET_OFFSET;
/* check socket structure valid or not */
- if (st->sockets[socket]->magic != SAL_SOCKET_MAGIC)
- {
- return RT_NULL;
- }
+ RT_ASSERT(st->sockets[socket]->magic == SAL_SOCKET_MAGIC);
return st->sockets[socket];
}
@@ -351,6 +348,38 @@ static void sal_unlock(void)
}
/**
+ * This function will clean the netdev.
+ *
+ * @note please don't invoke it on ISR.
+ */
+int sal_netdev_cleanup(struct netdev *netdev)
+{
+ int idx = 0, find_dev;
+
+ do
+ {
+ find_dev = 0;
+ sal_lock();
+ for (idx = 0; idx < socket_table.max_socket; idx++)
+ {
+ if (socket_table.sockets[idx] && socket_table.sockets[idx]->netdev == netdev)
+ {
+ find_dev = 1;
+ break;
+ }
+ }
+ sal_unlock();
+ if (find_dev)
+ {
+ rt_thread_mdelay(100);
+ }
+ }
+ while (find_dev);
+
+ return 0;
+}
+
+/**
* This function will initialize sal socket object and set socket options
*
* @param family protocol family
@@ -397,7 +426,7 @@ static int socket_init(int family, int type, int protocol, struct sal_socket **r
flag = RT_TRUE;
}
}
-
+
if (flag == RT_FALSE)
{
/* get network interface device by protocol family */
@@ -421,8 +450,7 @@ static int socket_alloc(struct sal_socket_table *st, int f_socket)
/* find an empty socket entry */
for (idx = f_socket; idx < (int) st->max_socket; idx++)
{
- if (st->sockets[idx] == RT_NULL ||
- st->sockets[idx]->netdev == RT_NULL)
+ if (st->sockets[idx] == RT_NULL)
{
break;
}
@@ -466,6 +494,15 @@ __result:
return idx;
}
+static void socket_free(struct sal_socket_table *st, int idx)
+{
+ struct sal_socket *sock;
+
+ sock = st->sockets[idx];
+ st->sockets[idx] = RT_NULL;
+ rt_free(sock);
+}
+
static int socket_new(void)
{
struct sal_socket *sock;
@@ -498,18 +535,38 @@ __result:
return idx + SAL_SOCKET_OFFSET;
}
+static void socket_delete(int socket)
+{
+ struct sal_socket *sock;
+ struct sal_socket_table *st = &socket_table;
+ int idx;
+
+ idx = socket - SAL_SOCKET_OFFSET;
+ if (idx < 0 || idx >= (int) st->max_socket)
+ {
+ return;
+ }
+ sal_lock();
+ sock = sal_get_socket(socket);
+ RT_ASSERT(sock != RT_NULL);
+ sock->magic = 0;
+ sock->netdev = RT_NULL;
+ socket_free(st, idx);
+ sal_unlock();
+}
+
int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
{
int new_socket;
struct sal_socket *sock;
- struct sal_proto_family *pf;
+ struct sal_proto_family *pf;
/* get the socket object by socket descriptor */
SAL_SOCKET_OBJ_GET(sock, socket);
/* check the network interface socket operations */
SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, accept);
-
+
new_socket = pf->skt_ops->accept((int) sock->user_data, addr, addrlen);
if (new_socket != -1)
{
@@ -519,18 +576,20 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
/* allocate a new socket structure and registered socket options */
new_sal_socket = socket_new();
- if (new_sal_socket < 0)
+ new_sock = sal_get_socket(new_sal_socket);
+ if (new_sock == RT_NULL)
{
pf->skt_ops->closesocket(new_socket);
return -1;
}
- new_sock = sal_get_socket(new_sal_socket);
retval = socket_init(sock->domain, sock->type, sock->protocol, &new_sock);
if (retval < 0)
{
pf->skt_ops->closesocket(new_socket);
rt_memset(new_sock, 0x00, sizeof(struct sal_socket));
+ /* socket init failed, delete socket */
+ socket_delete(new_sal_socket);
LOG_E("New socket registered failed, return error %d.", retval);
return -1;
}
@@ -549,20 +608,20 @@ static void sal_sockaddr_to_ipaddr(const struct sockaddr *name, ip_addr_t *local
const struct sockaddr_in *svr_addr = (const struct sockaddr_in *) name;
#if NETDEV_IPV4 && NETDEV_IPV6
- (*local_ipaddr).u_addr.ip4.addr = svr_addr->sin_addr.s_addr;
+ local_ipaddr->u_addr.ip4.addr = svr_addr->sin_addr.s_addr;
+ local_ipaddr->type = IPADDR_TYPE_V4;
#elif NETDEV_IPV4
- (*local_ipaddr).addr = svr_addr->sin_addr.s_addr;
+ local_ipaddr->addr = svr_addr->sin_addr.s_addr;
#elif NETDEV_IPV6
- LOG_E("not support IPV6");
-#endif /* SAL_IPV4 && SAL_IPV6*/
-}
+#error "not only support IPV6"
+#endif /* NETDEV_IPV4 && NETDEV_IPV6*/
+}
int sal_bind(int socket, const struct sockaddr *name, socklen_t namelen)
{
struct sal_socket *sock;
struct sal_proto_family *pf;
- struct netdev *new_netdev;
- ip_addr_t local_addr;
+ ip_addr_t input_ipaddr;
RT_ASSERT(name);
@@ -570,44 +629,43 @@ int sal_bind(int socket, const struct sockaddr *name, socklen_t namelen)
SAL_SOCKET_OBJ_GET(sock, socket);
/* bind network interface by ip address */
- sal_sockaddr_to_ipaddr(name, &local_addr);
+ sal_sockaddr_to_ipaddr(name, &input_ipaddr);
/* check input ipaddr is default netdev ipaddr */
- if (local_addr.addr == INADDR_ANY)
+ if (!ip_addr_isany_val(input_ipaddr))
{
- SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, bind);
- return pf->skt_ops->bind((int) sock->user_data, name, namelen);
- }
-
- new_netdev = netdev_get_by_ipaddr(&local_addr);
- if (new_netdev == RT_NULL)
- {
- LOG_E("Not find network interface device ipaddr(%s).", inet_ntoa(local_addr));
- return -1;
- }
+ struct sal_proto_family *input_pf = RT_NULL, *local_pf = RT_NULL;
+ struct netdev *new_netdev = RT_NULL;
- /* change network interface device parameter in sal socket object */
- if (sock->netdev != new_netdev)
- {
- struct sal_proto_family *old_pf, *new_pf;
- int new_socket = 0;
+ new_netdev = netdev_get_by_ipaddr(&input_ipaddr);
+ if (new_netdev == RT_NULL)
+ {
+ return -1;
+ }
- /* close old netdev socket */
- SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, old_pf, closesocket);
- old_pf->skt_ops->closesocket(socket);
+ /* get input and local ip address proto_family */
+ SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, local_pf, bind);
+ SAL_NETDEV_SOCKETOPS_VALID(new_netdev, input_pf, bind);
- /* open new netdev socket */
- SAL_NETDEV_SOCKETOPS_VALID(new_netdev, new_pf, socket);
- new_socket = new_pf->skt_ops->socket(sock->domain, sock->type, sock->protocol);
- if (new_socket < 0)
+ /* check the network interface protocol family type */
+ if (input_pf->family != local_pf->family)
{
- return -1;
+ int new_socket = -1;
+
+ /* protocol family is different, close old socket and create new socket by input ip address */
+ local_pf->skt_ops->closesocket(socket);
+
+ new_socket = input_pf->skt_ops->socket(input_pf->family, sock->type, sock->protocol);
+ if (new_socket < 0)
+ {
+ return -1;
+ }
+ sock->netdev = new_netdev;
+ sock->user_data = (void *) new_socket;
}
- sock->netdev = new_netdev;
- sock->user_data = (void *) new_socket;
}
- /* check the network interface socket opreation */
+ /* check and get protocol families by the network interface device */
SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, bind);
return pf->skt_ops->bind((int) sock->user_data, name, namelen);
}
@@ -643,9 +701,6 @@ int sal_shutdown(int socket, int how)
error = -1;
}
- /* free socket */
- rt_free(sock);
- socket_table.sockets[socket] = RT_NULL;
return error;
}
@@ -761,7 +816,7 @@ int sal_connect(int socket, const struct sockaddr *name, socklen_t namelen)
{
return -1;
}
-
+
return ret;
}
#endif
@@ -784,7 +839,7 @@ int sal_listen(int socket, int backlog)
}
int sal_recvfrom(int socket, void *mem, size_t len, int flags,
- struct sockaddr *from, socklen_t *fromlen)
+ struct sockaddr *from, socklen_t *fromlen)
{
struct sal_socket *sock;
struct sal_proto_family *pf;
@@ -801,11 +856,11 @@ int sal_recvfrom(int socket, void *mem, size_t len, int flags,
if (SAL_SOCKOPS_PROTO_TLS_VALID(sock, recv))
{
int ret;
-
+
if ((ret = proto_tls->ops->recv(sock->user_data_tls, mem, len)) < 0)
{
return -1;
- }
+ }
return ret;
}
else
@@ -818,7 +873,7 @@ int sal_recvfrom(int socket, void *mem, size_t len, int flags,
}
int sal_sendto(int socket, const void *dataptr, size_t size, int flags,
- const struct sockaddr *to, socklen_t tolen)
+ const struct sockaddr *to, socklen_t tolen)
{
struct sal_socket *sock;
struct sal_proto_family *pf;
@@ -835,11 +890,11 @@ int sal_sendto(int socket, const void *dataptr, size_t size, int flags,
if (SAL_SOCKOPS_PROTO_TLS_VALID(sock, send))
{
int ret;
-
+
if ((ret = proto_tls->ops->send(sock->user_data_tls, dataptr, size)) < 0)
{
return -1;
- }
+ }
return ret;
}
else
@@ -877,6 +932,7 @@ int sal_socket(int domain, int type, int protocol)
if (retval < 0)
{
LOG_E("SAL socket protocol family input failed, return error %d.", retval);
+ socket_delete(socket);
return -1;
}
@@ -892,6 +948,7 @@ int sal_socket(int domain, int type, int protocol)
sock->user_data_tls = proto_tls->ops->socket(socket);
if (sock->user_data_tls == RT_NULL)
{
+ socket_delete(socket);
return -1;
}
}
@@ -934,9 +991,8 @@ int sal_closesocket(int socket)
error = -1;
}
- /* free socket */
- rt_free(sock);
- socket_table.sockets[socket] = RT_NULL;
+ /* delete socket */
+ socket_delete(socket);
return error;
}
@@ -997,7 +1053,7 @@ struct hostent *sal_gethostbyname(const char *name)
}
int sal_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
- size_t buflen, struct hostent **result, int *h_errnop)
+ size_t buflen, struct hostent **result, int *h_errnop)
{
struct netdev *netdev = netdev_default;
struct sal_proto_family *pf;
@@ -1020,9 +1076,9 @@ int sal_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
}
int sal_getaddrinfo(const char *nodename,
- const char *servname,
- const struct addrinfo *hints,
- struct addrinfo **res)
+ const char *servname,
+ const struct addrinfo *hints,
+ struct addrinfo **res)
{
struct netdev *netdev = netdev_default;
struct sal_proto_family *pf;