Merge pull request #717 from armink/modbus_update
[net] Modbus update KConfig.
This commit is contained in:
commit
56fbe947be
|
@ -122,4 +122,6 @@ config RT_USING_LWIP
|
|||
|
||||
endmenu
|
||||
|
||||
source "$RTT_DIR/components/net/freemodbus/KConfig"
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue