Преглед на файлове

Merge pull request #1596 from liquanqing/inc_modbus

[Components][modbus]add 485 controller pin to Kconfig | 在Kconfig中添加485控制引脚
朱天龙 (Armink) преди 6 години
родител
ревизия
1d588c7475

+ 10 - 0
components/net/freemodbus/Kconfig

@@ -12,6 +12,16 @@ config RT_USING_MODBUS
 		config RT_MODBUS_SLAVE_RTU
 		config RT_MODBUS_SLAVE_RTU
 			bool "RTU slave mode"
 			bool "RTU slave mode"
 			default n
 			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
 	endif
 
 
 endmenu
 endmenu

+ 2 - 2
components/net/freemodbus/modbus/functions/mbutils.c

@@ -53,8 +53,8 @@ xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits,
     USHORT          usNPreBits;
     USHORT          usNPreBits;
     USHORT          usValue = ucValue;
     USHORT          usValue = ucValue;
 
 
-    assert_param( ucNBits <= 8 );
-    assert_param( ( size_t )BITS_UCHAR == sizeof( UCHAR ) * 8 );
+    RT_ASSERT( ucNBits <= 8 );
+    RT_ASSERT( ( size_t )BITS_UCHAR == sizeof( UCHAR ) * 8 );
 
 
     /* Calculate byte offset for first byte containing the bit values starting
     /* Calculate byte offset for first byte containing the bit values starting
      * at usBitOffset. */
      * at usBitOffset. */

+ 4 - 4
components/net/freemodbus/modbus/rtu/mbrtu.c

@@ -153,7 +153,7 @@ eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength )
     eMBErrorCode    eStatus = MB_ENOERR;
     eMBErrorCode    eStatus = MB_ENOERR;
 
 
     ENTER_CRITICAL_SECTION(  );
     ENTER_CRITICAL_SECTION(  );
-    assert_param( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
+    RT_ASSERT( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
 
 
     /* Length and CRC check */
     /* Length and CRC check */
     if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
     if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN )
@@ -226,7 +226,7 @@ xMBRTUReceiveFSM( void )
     BOOL            xTaskNeedSwitch = FALSE;
     BOOL            xTaskNeedSwitch = FALSE;
     UCHAR           ucByte;
     UCHAR           ucByte;
 
 
-    assert_param( eSndState == STATE_TX_IDLE );
+    RT_ASSERT( eSndState == STATE_TX_IDLE );
 
 
     /* Always read the character. */
     /* Always read the character. */
     ( void )xMBPortSerialGetByte( ( CHAR * ) & ucByte );
     ( void )xMBPortSerialGetByte( ( CHAR * ) & ucByte );
@@ -285,7 +285,7 @@ xMBRTUTransmitFSM( void )
 {
 {
     BOOL            xNeedPoll = FALSE;
     BOOL            xNeedPoll = FALSE;
 
 
-    assert_param( eRcvState == STATE_RX_IDLE );
+    RT_ASSERT( eRcvState == STATE_RX_IDLE );
 
 
     switch ( eSndState )
     switch ( eSndState )
     {
     {
@@ -342,7 +342,7 @@ xMBRTUTimerT35Expired( void )
 
 
         /* Function called in an illegal state. */
         /* Function called in an illegal state. */
     default:
     default:
-        assert_param( ( eRcvState == STATE_RX_INIT ) ||
+        RT_ASSERT( ( eRcvState == STATE_RX_INIT ) ||
                 ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
                 ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
          break;
          break;
     }
     }

+ 6 - 1
components/net/freemodbus/port/portserial.c

@@ -56,8 +56,9 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
      * set 485 mode receive and transmit control IO
      * set 485 mode receive and transmit control IO
      * @note MODBUS_SLAVE_RT_CONTROL_PIN_INDEX need be defined by user
      * @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);
     rt_pin_mode(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT);
-
+#endif
     /* set serial name */
     /* set serial name */
     if (ucPORT == 1) {
     if (ucPORT == 1) {
 #if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1)
 #if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1)
@@ -127,12 +128,16 @@ void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
         /* enable RX interrupt */
         /* enable RX interrupt */
         serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
         serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX);
         /* switch 485 to receive mode */
         /* switch 485 to receive mode */
+#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
         rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_LOW);
         rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_LOW);
+#endif
     }
     }
     else
     else
     {
     {
         /* switch 485 to transmit mode */
         /* switch 485 to transmit mode */
+#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN)
         rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);
         rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH);
+#endif
         /* disable RX interrupt */
         /* disable RX interrupt */
         serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
         serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX);
     }
     }