1、【修改】FreeModbu分析图使其内容更加完整

2、【增加】FreeModbus源码中关于主机模式的宏定义
3、【优化】FreeModbus中port文件的命名格式,在MB后面直接增加Master字样
4、【增加】FreeModbus中与主机相关的帧处理函数指针及相关回调函数,具体实现及调用逻辑后期实现

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2013-08-13 21:54:54 +08:00
parent d4ee095afa
commit 7c952c0623
9 changed files with 57 additions and 30 deletions

Binary file not shown.

View File

@ -44,7 +44,7 @@
#include "mbcrc.h"
#include "mbport.h"
#if MB_ASCII_ENABLED > 0
#if MB_SLAVER_ASCII_ENABLED > 0
/* ----------------------- Defines ------------------------------------------*/
#define MB_ASCII_DEFAULT_CR '\r' /*!< Default CR character for Modbus ASCII. */

View File

@ -35,7 +35,7 @@
PR_BEGIN_EXTERN_C
#endif
#if MB_ASCII_ENABLED > 0
#if MB_SLAVER_ASCII_ENABLED > 0
eMBErrorCode eMBASCIIInit( UCHAR slaveAddress, UCHAR ucPort,
ULONG ulBaudRate, eMBParity eParity );
void eMBASCIIStart( void );

View File

@ -26,6 +26,7 @@
* 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.15 2013/08/13 21:19:55 Armink Add Master Functions $
*/
#ifndef _MB_CONFIG_H
@ -46,12 +47,18 @@ PR_BEGIN_EXTERN_C
/*! \addtogroup modbus_cfg
* @{
*/
/*! \brief If Modbus ASCII support is enabled. */
#define MB_ASCII_ENABLED ( 0 )
/*! \brief If Modbus RTU support is enabled. */
#define MB_RTU_ENABLED ( 1 )
/*! \brief If Modbus TCP support is enabled. */
#define MB_TCP_ENABLED ( 0 )
/*! \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 Slaver ASCII support is enabled. */
#define MB_SLAVER_ASCII_ENABLED ( 0 )
/*! \brief If Modbus Slaver RTU support is enabled. */
#define MB_SLAVER_RTU_ENABLED ( 1 )
/*! \brief If Modbus Slaver TCP support is enabled. */
#define MB_SLAVER_TCP_ENABLED ( 0 )
/*! \brief The character timeout value for Modbus ASCII.
*
* The character timeout value is not fixed for Modbus ASCII and is therefore

View File

@ -44,13 +44,13 @@
#include "mbfunc.h"
#include "mbport.h"
#if MB_RTU_ENABLED == 1
#if MB_SLAVER_RTU_ENABLED == 1
#include "mbrtu.h"
#endif
#if MB_ASCII_ENABLED == 1
#if MB_SLAVER_ASCII_ENABLED == 1
#include "mbascii.h"
#endif
#if MB_TCP_ENABLED == 1
#if MB_SLAVER_TCP_ENABLED == 1
#include "mbtcp.h"
#endif
@ -72,6 +72,7 @@ static enum
/* Functions pointer which are initialized in eMBInit( ). Depending on the
* mode (RTU or ASCII) the are set to the correct implementations.
* Using for Modbus Slaver
*/
static peMBFrameSend peMBFrameSendCur;
static pvMBFrameStart pvMBFrameStartCur;
@ -79,9 +80,20 @@ static pvMBFrameStop pvMBFrameStopCur;
static peMBFrameReceive peMBFrameReceiveCur;
static pvMBFrameClose pvMBFrameCloseCur;
/* 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 Slaver
*/
BOOL( *pxMBFrameCBByteReceived ) ( void );
BOOL( *pxMBFrameCBTransmitterEmpty ) ( void );
@ -90,6 +102,18 @@ BOOL( *pxMBPortCBTimerExpired ) ( void );
BOOL( *pxMBFrameCBReceiveFSMCur ) ( void );
BOOL( *pxMBFrameCBTransmitFSMCur ) ( void );
/* 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.
*/
@ -144,7 +168,7 @@ eMBInit( eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eM
switch ( eMode )
{
#if MB_RTU_ENABLED > 0
#if MB_SLAVER_RTU_ENABLED > 0
case MB_RTU:
pvMBFrameStartCur = eMBRTUStart;
pvMBFrameStopCur = eMBRTUStop;
@ -158,7 +182,7 @@ eMBInit( eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eM
eStatus = eMBRTUInit( ucMBAddress, ucPort, ulBaudRate, eParity );
break;
#endif
#if MB_ASCII_ENABLED > 0
#if MB_SLAVER_ASCII_ENABLED > 0
case MB_ASCII:
pvMBFrameStartCur = eMBASCIIStart;
pvMBFrameStopCur = eMBASCIIStop;
@ -193,7 +217,7 @@ eMBInit( eMBMode eMode, UCHAR ucSlaveAddress, UCHAR ucPort, ULONG ulBaudRate, eM
return eStatus;
}
#if MB_TCP_ENABLED > 0
#if MB_SLAVER_TCP_ENABLED > 0
eMBErrorCode
eMBTCPInit( USHORT ucTCPPort )
{

View File

@ -42,7 +42,7 @@
#include "mbframe.h"
#include "mbport.h"
#if MB_TCP_ENABLED > 0
#if MB_SLAVER_TCP_ENABLED > 0
/* ----------------------- Defines ------------------------------------------*/

View File

@ -39,9 +39,6 @@
#define MASTER_RS485_SEND_MODE GPIO_SetBits(GPIOB,GPIO_Pin_13)
#define MASTER_RS485_RECEIVE_MODE GPIO_ResetBits(GPIOB,GPIO_Pin_13)
//void USART1_IRQHandler(void);
//void TIM3_IRQHandler(void);
#define ENTER_CRITICAL_SECTION() EnterCriticalSection()
#define EXIT_CRITICAL_SECTION() ExitCriticalSection()

View File

@ -29,7 +29,7 @@ static void prvvUARTTxReadyISR(void);
static void prvvUARTRxISR(void);
/* ----------------------- Start implementation -----------------------------*/
void vMBPortMasterSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
void vMBMasterPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
{
if (xRxEnable)
{
@ -51,13 +51,13 @@ void vMBPortMasterSerialEnable(BOOL xRxEnable, BOOL xTxEnable)
}
}
void vMBPortMasterClose(void)
void vMBMasterPortClose(void)
{
USART_ITConfig(USART2, USART_IT_TXE | USART_IT_RXNE, DISABLE);
USART_Cmd(USART2, DISABLE);
}
//默认一个从机 串口2 波特率可设置 奇偶检验可设置
BOOL xMBPortMasterSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
BOOL xMBMasterPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
eMBParity eParity)
{
GPIO_InitTypeDef GPIO_InitStructure;
@ -130,13 +130,13 @@ BOOL xMBPortMasterSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits,
return TRUE;
}
BOOL xMBPortMasterSerialPutByte(CHAR ucByte)
BOOL xMBMasterPortSerialPutByte(CHAR ucByte)
{
USART_SendData(USART2, ucByte);
return TRUE;
}
BOOL xMBPortMasterSerialGetByte(CHAR * pucByte)
BOOL xMBMasterPortSerialGetByte(CHAR * pucByte)
{
*pucByte = USART_ReceiveData(USART2);
return TRUE;
@ -151,7 +151,7 @@ BOOL xMBPortMasterSerialGetByte(CHAR * pucByte)
*/
void prvvUARTTxReadyISR(void)
{
pxMBFrameCBTransmitterEmpty();
pxMBMasterFrameCBTransmitterEmpty();
}
/*
@ -162,7 +162,7 @@ void prvvUARTTxReadyISR(void)
*/
void prvvUARTRxISR(void)
{
pxMBFrameCBByteReceived();
pxMBMasterFrameCBByteReceived();
}
/*******************************************************************************
* Function Name : USART2_IRQHandler

View File

@ -30,7 +30,7 @@
static void prvvTIMERExpiredISR(void);
/* ----------------------- Start implementation -----------------------------*/
BOOL xMBPortMasterTimersInit(USHORT usTim1Timerout50us)
BOOL xMBMasterPortTimersInit(USHORT usTim1Timerout50us)
{
uint16_t PrescalerValue = 0;
@ -72,7 +72,7 @@ BOOL xMBPortMasterTimersInit(USHORT usTim1Timerout50us)
return TRUE;
}
void vMBPortMasterTimersEnable()
void vMBMasterPortTimersEnable()
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
@ -80,7 +80,7 @@ void vMBPortMasterTimersEnable()
TIM_Cmd(TIM2, ENABLE);
}
void vMBPortMasterTimersDisable()
void vMBMasterPortTimersDisable()
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
TIM_ITConfig(TIM2, TIM_IT_Update, DISABLE);
@ -90,8 +90,7 @@ void vMBPortMasterTimersDisable()
void prvvTIMERExpiredISR(void)
{
//TODO 修改以适合主机
(void) pxMBPortCBTimerExpired();
(void) pxMBMasterPortCBTimerExpired();
}
void TIM2_IRQHandler(void)