Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

lwIP: Blocking on queues and sockets

Posted by Marcel van Lieshout on August 5, 2013
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.

RE: lwIP: Blocking on queues and sockets

Posted by Marcel van Lieshout on August 5, 2013
(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);
}


RE: lwIP: Blocking on queues and sockets

Posted by Richard on August 5, 2013
Thanks for the input.

Unfortunately there is no edit button!

Regards.

RE: lwIP: Blocking on queues and sockets

Posted by Marcel van Lieshout on August 6, 2013
“Thanks for the input.”
Well, it was a long time ago since I wrote the pic18/wizC port. Now I'm all into PIC32.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner