freemodbus函数调用关系
2020-08-07 10:02:54 26 举报
AI智能生成
freemodbus的函数调用
作者其他创作
大纲/内容
freemodbus RTU
运行
MB_RTU
pvMBFrameStartCur = eMBRTUStart
pvMBFrameStopCur = eMBRTUStop
peMBFrameSendCur = eMBRTUSend
peMBFrameReceiveCur = eMBRTUReceive
pvMBFrameCloseCur = MB_PORT_HAS_CLOSE ? vMBPortClose : NULL;
pxMBFrameCBByteReceived = xMBRTUReceiveFSM;
pxMBFrameCBTransmitterEmpty = xMBRTUTransmitFSM;
pxMBPortCBTimerExpired = xMBRTUTimerT35Expired;
xMBPortEventInit( )
xEventInQueue = FALSE;
return TRUE;
eMBCurrentMode = eMode;
eMBState = STATE_DISABLED;
eMBEnable()
pvMBFrameStartCur( );
eMBRTUStart
eRcvState = STATE_RX_INIT;
vMBPortTimersEnable( );
HAL_TIM_Base_Start_IT(&htim4);
eMBState = STATE_ENABLED;
eMBPoll()
xMBPortEventGet( &eEvent )
xEventHappened = FALSE; if( xEventInQueue ) *eEvent = eQueuedEvent; xEventInQueue = FALSE; xEventHappened = TRUE; return xEventHappened;
if(xMBPortEventGet== TRUE))
case EV_READY:
break;
case EV_FRAME_RECEIVED:
eStatus = peMBFrameReceiveCur()
eMBRTUReceive
BOOL xFrameReceived = FALSE;
eMBErrorCode eStatus = MB_ENOERR;
assert( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
*pucRcvAddress = ucRTUBuf[MB_SER_PDU_ADDR_OFF];
*pusLength = ( USHORT )( usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC );
*pucFrame = ( UCHAR * ) & ucRTUBuf[MB_SER_PDU_PDU_OFF];
xFrameReceived = TRUE;
else
eStatus = MB_EIO;
return eStatus;
if( eStatus == MB_ENOERR )
( void )xMBPortEventPost( EV_EXECUTE );
case EV_EXECUTE:
ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
eException = MB_EX_ILLEGAL_FUNCTION;
for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
if( xFuncHandlers[i].ucFunctionCode == 0 )
break;
else if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
if( ucRcvAddress != MB_ADDRESS_BROADCAST )
if( eException != MB_EX_NONE )
eException != MB_EX_NONE
usLength = 0;
ucMBFrame[usLength++] = ( UCHAR )( ucFunctionCode | MB_FUNC_ERROR );
ucMBFrame[usLength++] = eException;
if( ( eMBCurrentMode == MB_ASCII ) && MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS )
vMBPortTimersDelay( MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS );
eMBRTUSend
if( eRcvState == STATE_RX_IDLE )
/* Activate the transmitter. */ eSndState = STATE_TX_XMIT;
case EV_FRAME_SENT:
return MB_ENOERR;
定时器中断处理
HAL_TIM_PeriodElapsedCallback
prvvTIMERExpiredISR();
pxMBPortCBTimerExpired
xMBRTUTimerT35Expired;
BOOL xNeedPoll = FALSE;
switch ( eRcvState )
case STATE_RX_INIT:
xNeedPoll = xMBPortEventPost( EV_READY );
case STATE_RX_RCV:
xNeedPoll = xMBPortEventPost( EV_FRAME_RECEIVED );
case STATE_RX_ERROR:
default:
assert( ( eRcvState == STATE_RX_INIT ) || ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR ) );
vMBPortTimersDisable( );
eRcvState = STATE_RX_IDLE;
return xNeedPoll;
串口中断处理
HAL_UART_RxCpltCallback
prvvUARTRxISR();
pxMBFrameCBByteReceived( );
xMBRTUReceiveFSM;
BOOL xTaskNeedSwitch = FALSE;
UCHAR ucByte;
assert( eSndState == STATE_TX_IDLE );
( void )xMBPortSerialGetByte( ( CHAR * ) & ucByte );
case STATE_RX_ERROR:
case STATE_RX_IDLE:
usRcvBufferPos = 0;
ucRTUBuf[usRcvBufferPos++] = ucByte;
eRcvState = STATE_RX_RCV;
if( usRcvBufferPos < MB_SER_PDU_SIZE_MAX )
eRcvState = STATE_RX_ERROR;
vMBPortTimersEnable( );
return xTaskNeedSwitch;
HAL_UART_TxCpltCallback
prvvUARTTxReadyISR();
pxMBFrameCBTransmitterEmpty();
xMBRTUTransmitFSM;
assert( eRcvState == STATE_RX_IDLE );
switch ( eSndState )
case STATE_TX_IDLE:
case STATE_TX_XMIT:
if( usSndBufferCount != 0 )
xMBPortSerialPutByte( ( CHAR )*pucSndBufferCur );
pucSndBufferCur++; /* next byte in sendbuffer. */
usSndBufferCount--;
xNeedPoll = xMBPortEventPost( EV_FRAME_SENT );
eSndState = STATE_TX_IDLE;
return xNeedPoll;
0 条评论
回复 删除
下一页