summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2017-04-14 13:48:54 +0800
committerGitHub <[email protected]>2017-04-14 13:48:54 +0800
commit56fbe947be2de05be8f4bca976373e78dad0749a (patch)
tree1eaad44b544a19cbd0224424b7f15579744af0af
parentcb0a4962e20baec771c77844644b84d02708be70 (diff)
parentc8ae11c428fc3a887dd57723d4ab0f925c17d399 (diff)
Merge pull request #717 from armink/modbus_update
[net] Modbus update KConfig.
-rw-r--r--components/net/KConfig2
-rw-r--r--components/net/freemodbus/KConfig17
-rw-r--r--components/net/freemodbus/modbus/functions/mbfunccoils_m.c2
-rw-r--r--components/net/freemodbus/modbus/functions/mbfuncholding.c2
-rw-r--r--components/net/freemodbus/port/portserial.c7
-rw-r--r--components/net/freemodbus/port/portserial_m.c11
-rw-r--r--components/net/freemodbus/port/porttimer.c2
-rw-r--r--components/net/freemodbus/port/porttimer_m.c2
8 files changed, 31 insertions, 14 deletions
diff --git a/components/net/KConfig b/components/net/KConfig
index d6c2c2101a..5b9c46a4be 100644
--- a/components/net/KConfig
+++ b/components/net/KConfig
@@ -122,4 +122,6 @@ config RT_USING_LWIP
endmenu
+source "$RTT_DIR/components/net/freemodbus/KConfig"
+
endmenu
diff --git a/components/net/freemodbus/KConfig b/components/net/freemodbus/KConfig
new file mode 100644
index 0000000000..9321c61a0e
--- /dev/null
+++ b/components/net/freemodbus/KConfig
@@ -0,0 +1,17 @@
+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
+ endif
+
+endmenu
diff --git a/components/net/freemodbus/modbus/functions/mbfunccoils_m.c b/components/net/freemodbus/modbus/functions/mbfunccoils_m.c
index f6bb51cdf6..93801de06f 100644
--- a/components/net/freemodbus/modbus/functions/mbfunccoils_m.c
+++ b/components/net/freemodbus/modbus/functions/mbfunccoils_m.c
@@ -196,7 +196,7 @@ eMBMasterReqWriteCoil( UCHAR ucSndAddr, USHORT usCoilAddr, USHORT usCoilData, LO
UCHAR *ucMBFrame;
eMBMasterReqErrCode eErrStatus = MB_MRE_NO_ERR;
- if ( usCoilAddr > MB_MASTER_TOTAL_SLAVE_NUM ) eErrStatus = MB_MRE_ILL_ARG;
+ 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
diff --git a/components/net/freemodbus/modbus/functions/mbfuncholding.c b/components/net/freemodbus/modbus/functions/mbfuncholding.c
index e74a0624dc..7921302f96 100644
--- a/components/net/freemodbus/modbus/functions/mbfuncholding.c
+++ b/components/net/freemodbus/modbus/functions/mbfuncholding.c
@@ -183,7 +183,7 @@ eMBFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen )
usRegAddress++;
usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 );
- usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] );
+ 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.
diff --git a/components/net/freemodbus/port/portserial.c b/components/net/freemodbus/port/portserial.c
index 317c7f4605..11173579ad 100644
--- a/components/net/freemodbus/port/portserial.c
+++ b/components/net/freemodbus/port/portserial.c
@@ -99,14 +99,14 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
serial->ops->configure(serial, &(serial->config));
/* open serial device */
- if (!serial->parent.open(&serial->parent,
- RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX )) {
- serial->parent.rx_indicate = serial_rx_ind;
+ 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,
@@ -115,7 +115,6 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
sizeof(serial_soft_trans_irq_stack),
10, 5);
rt_thread_startup(&thread_serial_soft_trans_irq);
- rt_event_init(&event_serial, "slave event", RT_IPC_FLAG_PRIO);
return TRUE;
}
diff --git a/components/net/freemodbus/port/portserial_m.c b/components/net/freemodbus/port/portserial_m.c
index 8ec0d081f1..366dc79983 100644
--- a/components/net/freemodbus/port/portserial_m.c
+++ b/components/net/freemodbus/port/portserial_m.c
@@ -36,7 +36,7 @@ static rt_uint8_t serial_soft_trans_irq_stack[512];
static struct rt_thread thread_serial_soft_trans_irq;
/* serial event */
static struct rt_event event_serial;
-/* modbus slave serial device */
+/* modbus master serial device */
static rt_serial_t *serial;
/* ----------------------- Defines ------------------------------------------*/
@@ -100,23 +100,22 @@ BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
serial->ops->configure(serial, &(serial->config));
/* open serial device */
- if (!serial->parent.open(&serial->parent,
- RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX )) {
- serial->parent.rx_indicate = serial_rx_ind;
+ 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,
- "slave trans",
+ "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);
- rt_event_init(&event_serial, "slave event", RT_IPC_FLAG_PRIO);
return TRUE;
}
diff --git a/components/net/freemodbus/port/porttimer.c b/components/net/freemodbus/port/porttimer.c
index 6f017d8759..8c51ad06d5 100644
--- a/components/net/freemodbus/port/porttimer.c
+++ b/components/net/freemodbus/port/porttimer.c
@@ -37,7 +37,7 @@ 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),
+ (50 * usTim1Timerout50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1,
RT_TIMER_FLAG_ONE_SHOT); /* one shot */
return TRUE;
}
diff --git a/components/net/freemodbus/port/porttimer_m.c b/components/net/freemodbus/port/porttimer_m.c
index 00441bfd1c..ebf80004d8 100644
--- a/components/net/freemodbus/port/porttimer_m.c
+++ b/components/net/freemodbus/port/porttimer_m.c
@@ -46,7 +46,7 @@ BOOL xMBMasterPortTimersInit(USHORT usTimeOut50us)
rt_timer_init(&timer, "master timer",
timer_timeout_ind, /* bind timeout callback function */
RT_NULL,
- (50 * usT35TimeOut50us) / (1000 * 1000 / RT_TICK_PER_SECOND),
+ (50 * usT35TimeOut50us) / (1000 * 1000 / RT_TICK_PER_SECOND) + 1,
RT_TIMER_FLAG_ONE_SHOT); /* one shot */
return TRUE;