|
|
@@ -0,0 +1,350 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2006-2018, RT-Thread Development Team
|
|
|
+ *
|
|
|
+ * SPDX-License-Identifier: Apache-2.0
|
|
|
+ *
|
|
|
+ * Change Logs:
|
|
|
+ * Date Author Notes
|
|
|
+ * 2020-11-21 Meco Man the first verion
|
|
|
+ */
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* uC/Modbus
|
|
|
+* The Embedded Modbus Stack
|
|
|
+*
|
|
|
+* Copyright 2003-2020 Silicon Laboratories Inc. www.silabs.com
|
|
|
+*
|
|
|
+* SPDX-License-Identifier: APACHE-2.0
|
|
|
+*
|
|
|
+* This software is subject to an open source license and is distributed by
|
|
|
+* Silicon Laboratories Inc. pursuant to the terms of the Apache License,
|
|
|
+* Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
|
|
|
+*
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+*
|
|
|
+* uC/Modbus
|
|
|
+*
|
|
|
+* MODBUS BOARD SUPPORT PACKAGE
|
|
|
+* RT-Thread UART Device
|
|
|
+*
|
|
|
+*
|
|
|
+* Filename : mb_bsp.c
|
|
|
+* Version : V2.14.00
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* INCLUDE FILES
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+#include <os.h>
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* GLOBALS
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_CommExit()
|
|
|
+*
|
|
|
+* Description : This function is called to terminate Modbus communications. All Modbus channels are close.
|
|
|
+*
|
|
|
+* Argument(s) : none
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_Exit()
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+CPU_VOID MB_CommExit (CPU_VOID)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_CommPortCfg()
|
|
|
+*
|
|
|
+* Description : This function initializes the serial port to the desired baud rate and the UART will be
|
|
|
+* configured for N, 8, 1 (No parity, 8 bits, 1 stop).
|
|
|
+*
|
|
|
+* Argument(s) : pch is a pointer to the Modbus channel
|
|
|
+* port_nbr is the desired serial port number. This argument allows you to assign a
|
|
|
+* specific serial port to a sepcific Modbus channel.
|
|
|
+* baud is the desired baud rate for the serial port.
|
|
|
+* parity is the desired parity and can be either:
|
|
|
+*
|
|
|
+* MODBUS_PARITY_NONE
|
|
|
+* MODBUS_PARITY_ODD
|
|
|
+* MODBUS_PARITY_EVEN
|
|
|
+*
|
|
|
+* bits specifies the number of bit and can be either 7 or 8.
|
|
|
+* stops specifies the number of stop bits and can either be 1 or 2
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_CfgCh()
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+CPU_VOID MB_CommPortCfg (CPU_INT08U ch,
|
|
|
+ CPU_INT08U port_nbr,
|
|
|
+ CPU_INT32U baud,
|
|
|
+ CPU_INT08U bits,
|
|
|
+ CPU_INT08U parity,
|
|
|
+ CPU_INT08U stops)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_CommRxIntDis()
|
|
|
+*
|
|
|
+* Description : This function disables Rx interrupts.
|
|
|
+*
|
|
|
+* Argument(s) : pch is a pointer to the Modbus channel
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_CommExit()
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+CPU_VOID MBS_CommRxIntDis (MODBUS_CH *pch)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_CommRxIntEn()
|
|
|
+*
|
|
|
+* Description : This function enables Rx interrupts.
|
|
|
+*
|
|
|
+* Argument(s) : pch is a pointer to the Modbus channel
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_TxByte()
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+CPU_VOID MBS_CommRxIntEn (MODBUS_CH *pch)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_CommRxTxISR_Handler()
|
|
|
+*
|
|
|
+* Description : This function is the ISR for either a received or transmitted character.
|
|
|
+*
|
|
|
+* Argument(s) : none.
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : This is a ISR
|
|
|
+*
|
|
|
+* Note(s) : (1) The pseudo-code for this function should be:
|
|
|
+*
|
|
|
+* if (Rx Byte has been received) {
|
|
|
+* c = get byte from serial port;
|
|
|
+* Clear receive interrupt;
|
|
|
+* pch->RxCtr++; Increment the number of bytes received
|
|
|
+* MB_RxByte(pch, c); Pass character to Modbus to process
|
|
|
+* }
|
|
|
+*
|
|
|
+* if (Byte has been transmitted) {
|
|
|
+* pch->TxCtr++; Increment the number of bytes transmitted
|
|
|
+* MB_TxByte(pch); Send next byte in response
|
|
|
+* Clear transmit interrupt Clear Transmit Interrupt flag
|
|
|
+* }
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+CPU_VOID MBS_CommRxTxISR_Handler (CPU_INT08U port_nbr)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* UART #0 Rx/Tx Communication handler for Modbus
|
|
|
+* (THIS IS THE START OF THE ISR!)
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+interrupt CPU_VOID MBS_CommRxTxISR_0_Handler (CPU_VOID)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_CommTx1()
|
|
|
+*
|
|
|
+* Description : This function is called to obtain the next byte to send from the transmit buffer. When
|
|
|
+* all bytes in the reply have been sent, transmit interrupts are disabled and the receiver
|
|
|
+* is enabled to accept the next Modbus request.
|
|
|
+*
|
|
|
+* Argument(s) : c is the byte to send to the serial port
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_TxByte()
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+CPU_VOID MBS_CommTx1 (MODBUS_CH *pch,
|
|
|
+ CPU_INT08U c)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_CommTxIntDis()
|
|
|
+*
|
|
|
+* Description : This function disables Tx interrupts.
|
|
|
+*
|
|
|
+* Argument(s) : pch is a pointer to the Modbus channel
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_CommExit()
|
|
|
+* MB_TxByte()
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+CPU_VOID MBS_CommTxIntDis (MODBUS_CH *pch)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_CommTxIntEn()
|
|
|
+*
|
|
|
+* Description : This function enables Tx interrupts.
|
|
|
+*
|
|
|
+* Argument(s) : pch is a pointer to the Modbus channel
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_Tx()
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+CPU_VOID MBS_CommTxIntEn (MODBUS_CH *pch)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_RTU_TmrInit()
|
|
|
+*
|
|
|
+* Description : This function is called to initialize the RTU timeout timer.
|
|
|
+*
|
|
|
+* Argument(s) : freq Is the frequency of the modbus RTU timer interrupt.
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_Init().
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+#if (MODBUS_CFG_RTU_EN == DEF_ENABLED)
|
|
|
+CPU_VOID MB_RTU_TmrInit (void)
|
|
|
+{
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_RTU_TmrExit()
|
|
|
+*
|
|
|
+* Description : This function is called to disable the RTU timeout timer.
|
|
|
+*
|
|
|
+* Argument(s) : none.
|
|
|
+*
|
|
|
+* Return(s) : none.
|
|
|
+*
|
|
|
+* Caller(s) : MB_Exit()
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/s
|
|
|
+
|
|
|
+#if (MODBUS_CFG_RTU_EN == DEF_ENABLED)
|
|
|
+CPU_VOID MB_RTU_TmrExit (CPU_VOID)
|
|
|
+{
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+*********************************************************************************************************
|
|
|
+* MB_RTU_TmrISR_Handler()
|
|
|
+*
|
|
|
+* Description : This function handles the case when the RTU timeout timer expires.
|
|
|
+*
|
|
|
+* Arguments : none.
|
|
|
+*
|
|
|
+* Returns : none.
|
|
|
+*
|
|
|
+* Caller(s) : This is a ISR.
|
|
|
+*
|
|
|
+* Note(s) : none.
|
|
|
+*********************************************************************************************************
|
|
|
+*/
|
|
|
+
|
|
|
+#if (MODBUS_CFG_RTU_EN == DEF_ENABLED)
|
|
|
+interrupt CPU_VOID MB_RTU_Tmr_Timeout (CPU_VOID)
|
|
|
+{
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|