Basic details first, I am running FreeRTOS version 8.2.0 on a FRDM K64f board. I am using LWIP for an ethernet stack. I know there is FreeRTOS+TCP, but I don’t see an implementation for my MCU, and I had a demo I could work with that used LWIP/ The device recieves new data via an interrupt every 1ms. The data is put into a circular queue in the interrupt. I have one (manually created) task that runs in non interrupt time. It essentially reads the queue, if there is data, send it to a server via ethernet Shown Below
:::c
static void tcpecho_thread(void *arg)
{
for(;;)
{
err_t err;
struct netbuf *Buf = NULL;
struct netconn *xNetConn = NULL;
LWIP_UNUSED_ARG(arg);
netif_set_up(&fsl_netif0);
xNetConn = netconn_new ( NETCONN_TCP );
int rc2 = netconn_connect ( xNetConn, &fsl_netif0_gw, 7 );
while(1)
{
if(QueueTop!=QueueBottom)
{
Buf = netbuf_new();
if(QueueTop>QueueBottom)
{
if(QueueTop>QueueBottom)
{
char * testBuffer = pvPortMalloc(QueueTop-QueueBottom);
netbuf_alloc(Buf, QueueTop-QueueBottom);
memcpy(testBuffer,&Queue[QueueBottom],QueueTop-QueueBottom);
Buf->p->payload = testBuffer;
Buf->p->len = QueueTop-QueueBottom;
err = netconn_write(xNetConn, Buf->p->payload, Buf->p->len, NETCONN_COPY);
netbuf_delete(Buf);
vPortFree(testBuffer);
}else if (QueueTop<QueueBottom)
{
char * testBuffer = pvPortMalloc(QUEUESIZEMAX-QueueBottom);
netbuf_alloc(Buf, QUEUESIZEMAX-QueueBottom);
memcpy(testBuffer,&Queue[QueueBottom],QUEUESIZEMAX-QueueBottom);
Buf->p->payload = testBuffer;
Buf->p->len = QUEUESIZEMAX-QueueBottom;
err = netconn_write(xNetConn, Buf->p->payload, Buf->p->len, NETCONN_COPY);
netbuf_delete(Buf);
vPortFree(testBuffer);
}if(err==ERR_OK)
{
QueueRemove(Buf->p->len);
}
}
if (rc2 != ERR_OK || err != ERR_OK )
{
PRINTF("ERROR DELETE CONNECTION");
netconn_delete ( xNetConn );
}
}
}
}
}
After running sucessfully for a minute or so, it just stops working. When I pause the debug session to see what is going on it seems to be stuck in an infinite loop in the backgroud, as if the RTOS is preempting the task somehow. The task is initiated with a priority of three with the following code in my main function:
:::c
sys_thread_new("tcpecho_thread", tcpecho_thread, NULL, TCPECHO_STACKSIZE, TCPECHO_PRIORITY);
OSA_Start();
Any Ideas why? Also, if I should be using FreeRTOS+TCP, is there a basic configuration for my MCU somewhere? What edits would I need to make to the FreeRTOS+TCP code to get it to work?