CC3200 UDP 非阻塞模式下,使用sl_RecvFrom函数接收数据,每调用sl_RecvFrom函数40多次的时候,就会出现大概16ms的延时时间,请问下如何去掉这个延时时间?测试程序:修改udp_socket 例程。
int BsdUdpServer(unsigned short usPort)
{
SlSockAddrIn_t sAddr;
SlSockAddrIn_t sLocalAddr;
int iCounter;
int iAddrSize;
int iSockID;
int iStatus;
long lLoopCount = 0;
short sTestBufLen;
{
SlSockAddrIn_t sAddr;
SlSockAddrIn_t sLocalAddr;
int iCounter;
int iAddrSize;
int iSockID;
int iStatus;
long lLoopCount = 0;
short sTestBufLen;
// filling the buffer
for (iCounter=0 ; iCounter<BUF_SIZE ; iCounter++)
{
g_cBsdBuf[iCounter] = (char)(iCounter % 10);
}
for (iCounter=0 ; iCounter<BUF_SIZE ; iCounter++)
{
g_cBsdBuf[iCounter] = (char)(iCounter % 10);
}
sTestBufLen = BUF_SIZE;
//filling the UDP server socket address
sLocalAddr.sin_family = SL_AF_INET;
sLocalAddr.sin_port = sl_Htons((unsigned short)usPort);
sLocalAddr.sin_addr.s_addr = 0;
//filling the UDP server socket address
sLocalAddr.sin_family = SL_AF_INET;
sLocalAddr.sin_port = sl_Htons((unsigned short)usPort);
sLocalAddr.sin_addr.s_addr = 0;
iAddrSize = sizeof(SlSockAddrIn_t);
// creating a UDP socket
iSockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
if( iSockID < 0 )
{
// error
ASSERT_ON_ERROR(SOCKET_CREATE_ERROR);
}
iSockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
if( iSockID < 0 )
{
// error
ASSERT_ON_ERROR(SOCKET_CREATE_ERROR);
}
// binding the UDP socket to the UDP server address
iStatus = sl_Bind(iSockID, (SlSockAddr_t *)&sLocalAddr, iAddrSize);
if( iStatus < 0 )
{
// error
sl_Close(iSockID);
ASSERT_ON_ERROR(BIND_ERROR);
}
iStatus = sl_Bind(iSockID, (SlSockAddr_t *)&sLocalAddr, iAddrSize);
if( iStatus < 0 )
{
// error
sl_Close(iSockID);
ASSERT_ON_ERROR(BIND_ERROR);
}
//*************************************************************************************
udp_socket_opt_set(iSockID); //设置非阻塞模式
while (1)
{
iStatus = sl_RecvFrom(iSockID, g_cBsdBuf, sTestBufLen, 0,( SlSockAddr_t *)&sAddr, (SlSocklen_t*)&iAddrSize );
if(iStatus>0)
{
lLoopCount++;
UART_PRINT("\r\n lLoopCount = %d",lLoopCount);
}
//IO取输出 使用逻辑分析仪查看IO输出情况 5430.IO输出情况.docx
GPIO_OUT(GPIOA1_BASE, 0x2,0);
GPIO_OUT(GPIOA1_BASE, 0x2,1);
}
udp_socket_opt_set(iSockID); //设置非阻塞模式
while (1)
{
iStatus = sl_RecvFrom(iSockID, g_cBsdBuf, sTestBufLen, 0,( SlSockAddr_t *)&sAddr, (SlSocklen_t*)&iAddrSize );
if(iStatus>0)
{
lLoopCount++;
UART_PRINT("\r\n lLoopCount = %d",lLoopCount);
}
//IO取输出 使用逻辑分析仪查看IO输出情况 5430.IO输出情况.docx
GPIO_OUT(GPIOA1_BASE, 0x2,0);
GPIO_OUT(GPIOA1_BASE, 0x2,1);
}
//*************************************************************************************
UART_PRINT("Recieved %u packets successfully\n\r",g_ulPacketCount);
//closing the socket after receiving 1000 packets
sl_Close(iSockID);
sl_Close(iSockID);
return SUCCESS;
}
}
void udp_socket_opt_set(int16_t iSockID)
{
SlSockNonblocking_t enableOption;
enableOption.NonblockingEnabled = 1;
sl_SetSockOpt(iSockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (uint8_t *)&enableOption,sizeof(enableOption)); // 使能/禁止非阻塞模式,默认阻塞模式
}
{
SlSockNonblocking_t enableOption;
enableOption.NonblockingEnabled = 1;
sl_SetSockOpt(iSockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (uint8_t *)&enableOption,sizeof(enableOption)); // 使能/禁止非阻塞模式,默认阻塞模式
}
void GPIO_OUT(unsigned long GPIO_BASE,unsigned char PIN,unsigned char value)
{
switch(value)
{
//case 0: GPIOPinWrite(GPIO_BASE,PIN,0); break;
//case 1: GPIOPinWrite(GPIO_BASE,PIN,PIN); break;
case 0: HWREG(GPIO_BASE + (GPIO_O_GPIO_DATA + (PIN << 2))) = 0;break;
case 1: HWREG(GPIO_BASE + (GPIO_O_GPIO_DATA + (PIN << 2))) = PIN;break;
}
}
{
switch(value)
{
//case 0: GPIOPinWrite(GPIO_BASE,PIN,0); break;
//case 1: GPIOPinWrite(GPIO_BASE,PIN,PIN); break;
case 0: HWREG(GPIO_BASE + (GPIO_O_GPIO_DATA + (PIN << 2))) = 0;break;
case 1: HWREG(GPIO_BASE + (GPIO_O_GPIO_DATA + (PIN << 2))) = PIN;break;
}
}