CC3100使用非阻塞UDP sl_RecvFrom会卡死
static _i32 BsdUdpServer(_u16 Port)
{
SlSockAddrIn_t Addr;
SlSockAddrIn_t LocalAddr;
_u16 idx = 0;
_u16 AddrSize = 0;
_i16 SockID = 0;
_i16 SockTXID = 0;
_i16 TXSockID = 0;
_i16 Status = 0;
_u16 LoopCount = 0;
_u16 recvSize = 0;
u8 RxAggrEnable = 0;
SlSockNonblocking_t lNonBlocking ;
for (idx=0 ; idx<70 ; idx++)
{
uBuft.BsdBuf[idx] = (_u8)(idx % 10);
}
sl_NetCfgSet(SL_SET_HOST_RX_AGGR, 0, sizeof(RxAggrEnable), (_u8 *) &RxAggrEnable);
LocalAddr.sin_family = SL_AF_INET;
LocalAddr.sin_port = sl_Htons((_u16)Port);
LocalAddr.sin_addr.s_addr = 0;
lNonBlocking.NonblockingEnabled=1;
AddrSize = sizeof(SlSockAddrIn_t);
SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
if( SockID < 0 )
{
ASSERT_ON_ERROR(SockID);
}
Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
if( Status < 0 )
{
Status = sl_Close(SockID);
ASSERT_ON_ERROR(Status);
}
sl_SetSockOpt(SockID, SL_SOL_SOCKET , SL_SO_NONBLOCKING, &lNonBlocking, sizeof(lNonBlocking));
while (1)
{
Status = sl_RecvFrom(SockID, uBuft.BsdBuf, 70, 0,
(SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize );
if(Status>0)
{
Status = sl_SendTo(SockID, uBuft.BsdBuf, 70, 0,
(SlSockAddr_t *)&Addr, AddrSize);
}
Delay_ms(10);
}
Status = sl_Close(SockID);
ASSERT_ON_ERROR(Status);
return SUCCESS;
}
使用官方例程一般收几分钟就挂死了。SP都是最新的,难道没有人遇到吗?大家到要收数据的吧?难道都跑系统?
有没有API可以检测是否有数据再去读呢?
你可以用Select去做,cc3100是遵循BSD SOCKET的。
hi 你这个问题解决了吗,使用的是ti rtos还是freertos
hi ,我使用的CC3200芯片,设置UDP为非阻塞像楼主一样,使用freertos 每50ms sl_RecvFrom,发现运行一段时间会出现调用任务被阻塞,无法唤醒,请问该怎么处理?