1、【优化】FreeModbus主机轮训业务逻辑

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2013-08-20 18:32:28 +08:00
parent c1520d3634
commit 33eec6ff56
5 changed files with 168 additions and 34 deletions

View File

@ -25,7 +25,7 @@ struct rt_thread thread_ModbusSlavePoll;
//函数定义: void thread_entry_SysRunLed(void* parameter)
//入口参数:无
//出口参数:无
//备 注EditorLiuqiuhu 2013-1-30 Company: BXXJS
//备 注EditorArmink 2013-08-02 Company: BXXJS
//******************************************************************
void thread_entry_SysMonitor(void* parameter)
{

View File

@ -62,8 +62,9 @@
/* ----------------------- Static variables ---------------------------------*/
static UCHAR ucMBAddress;
static UCHAR ucMBSendSlaveAddress;
static eMBMode eMBCurrentMode;
static UCHAR pucMasterRTUBuf[MB_PDU_SIZE_MAX];
static enum
{
@ -97,7 +98,7 @@ BOOL( *pxMBMasterFrameCBTransmitFSMCur ) ( void );
/* An array of Modbus functions handlers which associates Modbus function
* codes with implementing functions.
*/
static xMBFunctionHandler xFuncHandlers[MB_FUNC_HANDLERS_MAX] = {
static xMBFunctionHandler xMasterFuncHandlers[MB_FUNC_HANDLERS_MAX] = {
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0
{MB_FUNC_OTHER_REPORT_SLAVEID, eMBFuncReportSlaveID},
#endif
@ -248,7 +249,6 @@ eMBMasterDisable( void )
eMBErrorCode eMBMasterPoll( void )
{
static UCHAR *ucMBFrame;
static UCHAR ucRcvAddress;
static UCHAR ucFunctionCode;
static USHORT usLength;
@ -274,51 +274,38 @@ eMBErrorCode eMBMasterPoll( void )
break;
case EV_MASTER_FRAME_RECEIVED:
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
if( eStatus == MB_ENOERR )
{
/* Check if the frame is for us. If not ignore the frame. */
if( ( ucRcvAddress == ucMBAddress ) || ( ucRcvAddress == MB_ADDRESS_BROADCAST ) )
{
( void )xMBMasterPortEventPost( EV_MASTER_EXECUTE );
}
}
else ( void )xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
break;
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, (UCHAR **)(pucMasterRTUBuf + 1), &usLength );
/* Check if the frame is for us. If not ,send an error process event. */
if ( ( eStatus == MB_ENOERR ) && ( ucRcvAddress == ucMBSendSlaveAddress ) )
{
( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE );
}
else
{
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
}
break;
case EV_MASTER_EXECUTE:
ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
ucFunctionCode = (pucMasterRTUBuf + 1)[MB_PDU_FUNC_OFF];
eException = MB_EX_ILLEGAL_FUNCTION;
for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
{
/* No more function handlers registered. Abort. */
if( xFuncHandlers[i].ucFunctionCode == 0 )
if( xMasterFuncHandlers[i].ucFunctionCode == 0 )
{
break;
}
else if( xFuncHandlers[i].ucFunctionCode == ucFunctionCode )
else if( xMasterFuncHandlers[i].ucFunctionCode == ucFunctionCode )
{
eException = xFuncHandlers[i].pxHandler( ucMBFrame, &usLength );
eException = xMasterFuncHandlers[i].pxHandler( pucMasterRTUBuf + 1, &usLength );
break;
}
}
/* If the request was not sent to the broadcast address we
* return a reply. */
if( ucRcvAddress != MB_ADDRESS_BROADCAST )
{
if( eException != MB_EX_NONE )
{
/* An exception occured. Build an error frame. */
usLength = 0;
ucMBFrame[usLength++] = ( UCHAR )( ucFunctionCode | MB_FUNC_ERROR );
ucMBFrame[usLength++] = eException;
}
eStatus = peMBMasterFrameSendCur( ucMBAddress, ucMBFrame, usLength );
}
break;
case EV_MASTER_FRAME_SENT:
eStatus = peMBMasterFrameSendCur( ucMBSendSlaveAddress, pucMasterRTUBuf + 1, usLength );
break;
case EV_MASTER_ERROR_PROCESS:
@ -327,4 +314,5 @@ eMBErrorCode eMBMasterPoll( void )
}
return MB_ENOERR;
}
#endif

View File

@ -71,7 +71,7 @@ typedef enum
static volatile eMBMasterSndState eSndState;
static volatile eMBMasterRcvState eRcvState;
volatile UCHAR ucMasterRTUBuf[MB_SER_PDU_SIZE_MAX];
static volatile UCHAR ucMasterRTUBuf[MB_SER_PDU_SIZE_MAX];
static volatile UCHAR *pucMasterSndBufferCur;
static volatile USHORT usMasterSndBufferCount;

View File

@ -0,0 +1,115 @@
[Stack]
FillEnabled=0
OverflowWarningsEnabled=1
WarningThreshold=90
SpWarningsEnabled=1
WarnLogOnly=1
UseTrigger=1
TriggerName=main
LimitSize=0
ByteLimit=50
[Interrupts]
Enabled=1
[MemoryMap]
Enabled=0
Base=0
UseAuto=0
TypeViolation=1
UnspecRange=1
ActionState=1
[CallStack]
ShowArgs=0
[Disassembly]
MixedMode=1
[Trace1]
Enabled=0
ShowSource=1
[Exceptions]
StopOnUncaught=_ 0
StopOnThrow=_ 0
[JLinkDriver]
CStepIntDis=_ 0
[SWOTraceHWSettings]
OverrideDefaultClocks=0
CpuClock=72000000
ClockAutoDetect=0
ClockWanted=2000000
JtagSpeed=2000000
Prescaler=36
TimeStampPrescIndex=0
TimeStampPrescData=0
PcSampCYCTAP=1
PcSampPOSTCNT=15
PcSampIndex=0
DataLogMode=0
ITMportsEnable=0
ITMportsTermIO=0
ITMportsLogFile=0
ITMlogFile=$PROJ_DIR$\ITM.log
[PowerLog]
LogEnabled=0
GraphEnabled=0
ShowTimeLog=1
ShowTimeSum=0
Title0=I0
Symbol0=0 4
LiveEnabled=0
LiveFile=PowerLogLive.log
[DataLog]
LogEnabled=0
SumEnabled=0
GraphEnabled=0
ShowTimeLog=1
ShowTimeSum=1
[EventLog]
LogEnabled=0
SumEnabled=0
GraphEnabled=0
ShowTimeLog=1
ShowTimeSum=1
Title0=Ch0
Symbol0=0 4
Title1=Ch1
Symbol1=0 4
Title2=Ch2
Symbol2=0 4
Title3=Ch3
Symbol3=0 4
SumSortOrder=0
Event0=1 1 1
Event1=1 1 1
Event2=1 1 1
Event3=1 1 1
[InterruptLog]
LogEnabled=0
SumEnabled=0
GraphEnabled=0
ShowTimeLog=1
ShowTimeSum=1
SumSortOrder=0
[Breakpoints2]
Count=0
[Trace2]
Enabled=0
ShowSource=0
[SWOTraceWindow]
PcSampling=0
InterruptLogs=0
ForcedTimeStamps=0
EventCPI=0
EventEXC=0
EventFOLD=0
EventLSU=0
EventSLEEP=0
[PowerProbe]
Frequency=10000
Probe0=I0
ProbeSetup0=2 1 1 2 0 0
[CallStackLog]
Enabled=0
[DriverProfiling]
Enabled=0
Mode=3
Graph=0
Symbiont=0
Exclusions=

View File

@ -0,0 +1,31 @@
[BREAKPOINTS]
ShowInfoWin = 1
EnableFlashBP = 2
BPDuringExecution = 0
[CFI]
CFISize = 0x00
CFIAddr = 0x00
[CPU]
OverrideMemMap = 0
AllowSimulation = 1
ScriptFile=""
[FLASH]
MinNumBytesFlashDL = 0
SkipProgOnCRCMatch = 1
VerifyDownload = 1
AllowCaching = 1
EnableFlashDL = 2
Override = 0
Device="UNSPECIFIED"
[GENERAL]
WorkRAMSize = 0x00
WorkRAMAddr = 0x00
[SWO]
SWOLogFile=""
[MEM]
RdOverrideOrMask = 0x00
RdOverrideAndMask = 0xFFFFFFFF
RdOverrideAddr = 0xFFFFFFFF
WrOverrideOrMask = 0x00
WrOverrideAndMask = 0xFFFFFFFF
WrOverrideAddr = 0xFFFFFFFF