为了区别于485模式的传输速度(那个是以9600波特率传输的,每秒1200个字节,然后一个包算12字节,就是10ms左右,感觉有点长……)
这里刚移植完基于以太网的freemodbus,顺便测一波速度
main函数这样写先
TIM3_Int_Init(65535,72-1);
while(1) /*循环执行的函数*/
{
TIM3->CNT=0;
eMBPoll();
time=TIM3->CNT;
printf("time:%d\r\n",time);
delay_ms(100);
// do_tcp_server(); /*TCP_Client 数据回环测试程序*/
}
用定时器3测时间,CNT单位是us。
eMBErrorCode
eMBPoll( void )
{
static UCHAR *ucMBFrame;
static UCHAR ucRcvAddress;
static UCHAR ucFunctionCode;
static USHORT usLength;
static eMBException eException;
int i;
eMBErrorCode eStatus = MB_ENOERR;
eMBEventType eEvent;
/* Check if the protocol stack is ready. */
if( eMBState != STATE_ENABLED )
{
return MB_EILLSTATE;
}
/* Check if there is a event available. If not return control to caller.
* Otherwise we will handle the event. */
if( xMBPortEventGet( &eEvent ) == TRUE )
{
printf("type:%d\r\n",eEvent);
switch ( eEvent )
{
......
这里在eMBPoll中检查到事件的情况下输出下事件类型,后面的代码就省略了。
typedef enum
{
EV_READY, /*!< Startup finished. */
EV_FRAME_RECEIVED, /*!< Frame received. */
EV_EXECUTE, /*!< Execute function. */
EV_FRAME_SENT /*!< Frame sent. */
} eMBEventType;
串口助手打印时间如下,可以看出,在有数据的同时,两次poll会先接收,再执行函数并回复结果。
time:45
time:45
time:46
time:45
time:45
time:46
time:46
time:212
type:1
time:670
type:2
time:945
time:45
time:46
time:45
time:45
time:45
time:45
time:45
time:212
type:1
time:671
type:2
time:945
time:46
time:46
time:45
time:46
为了精确点测时间,我们把poll中的printf删去,再看看串口打印时间:
time:45
time:45
time:46
time:212
time:4
time:280
time:46
time:45
time:45
time:45
time:46
time:45
time:45
time:213
time:4
time:279
time:45
time:46
time:46
time:45
time:45
time:46
time:46
time:212
time:4
time:280
time:45
time:45
time:45
time:45
time:45
time:45
time:46
time:213
timg:4
time:280
time:45
time:46
spi接收+协议处理大概要212us,发送需要280us,整个过程不超过0.5ms,至于中间为什么会出现一个4us的操作……
emm……即使没有事件也会有45us的执行时间呀,难道说eMBState 连接失败了?
但是运行过程中并没有函数去修改过eMBState 呀……
一脸懵逼等待网友研究这个bug……