Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists