FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2013 Threads]
After asking some questions on this forum, I felt it was time to contribute a little.
I am running lwIP on FreeRTOS and was building an application that should block on a combination of FreeRTOS queues and lwIP sockets. After realizing that the lwIP socket-api is based on FreeRTOS queues, I came up with the following.
xQueueHandle lwip_GetAcceptQ(int s)
// Add these functions to the end of lwIP's sockets.c
{
// Get FreeRTOS handle of accept queue
xQueueHandle xQueue = NULL;
struct lwip_sock *sock;
sock = tryget_socket(s);
if((sock != NULL) && (sock->conn != NULL))
{
xQueue = sock->conn->acceptmbox;
}
return(xQueue);
}
xQueueHandle lwip_GetRecvQ(int s)
{
// Get FreeRTOS handle of receive queue
xQueueHandle xQueue = NULL;
struct lwip_sock *sock;
sock = tryget_socket(s);
if((sock != NULL) && (sock->conn != NULL))
{
xQueue = sock->conn->recvmbox;
}
return(xQueue);
}
int lwip_DataInRecvQ(int s)
{
// Return 1 (TRUE) if there is data in the socket receive pbuf(s),
// 0 (FALSE) otherwise
int iReturn = 0;
struct lwip_sock *sock;
sock = tryget_socket(s);
if((sock != NULL) && (sock->conn != NULL))
{
iReturn = (sock->lastdata != NULL);
}
return(iReturn);
}
These functions return the queue handles that are (exclusively) used by lwIP for the given socket. Having the queue-id, one can simply add it to a queue set.
One note: use the lwip_DataInRecvQ(s) function to check is there is data available in the local socket buffers. This data must be read before attempting to block on the socket receive queue.
(tidied up a little. Is there no preview on the forum? Or an edit button?)
// Add these functions to the end of lwIP's sockets.c
xQueueHandle lwip_GetAcceptQ(int s)
{
// Get FreeRTOS handle of accept queue
xQueueHandle xQueue = NULL;
struct lwip_sock *sock;
sock = tryget_socket(s);
if((sock != NULL) && (sock->conn != NULL))
{
xQueue = sock->conn->acceptmbox;
}
return(xQueue);
}
xQueueHandle lwip_GetRecvQ(int s)
{
// Get FreeRTOS handle of receive queue
xQueueHandle xQueue = NULL;
struct lwip_sock *sock;
sock = tryget_socket(s);
if((sock != NULL) && (sock->conn != NULL))
{
xQueue = sock->conn->recvmbox;
}
return(xQueue);
}
int lwip_DataInRecvQ(int s)
{
// Return 1 (TRUE) if there is data in the socket receive pbuf(s),
// 0 (FALSE) otherwise
int iReturn = 0;
struct lwip_sock *sock;
sock = tryget_socket(s);
if((sock != NULL) && (sock->conn != NULL))
{
iReturn = (sock->lastdata != NULL);
}
return(iReturn);
}
Thanks for the input.
Unfortunately there is no edit button!
Regards.
“Thanks for the input.”
Well, it was a long time ago since I wrote the pic18/wizC port. Now I'm all into PIC32.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.