Quality RTOS & Embedded Software

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


Loading

FreeRTOS+UDP to create server application

Posted by Anand Jose on May 3, 2013
We are porting FreeRTOS on Pxa303 board, we want to establish ethernet communication between 2 pxa303 boards. We are using FreeRTOS+UDP(FreeRTOSV7.4.1\FreeRTOS-Plus\Source\FreeRTOS-Plus-UDP) for this purpose, twoechoclients.c(FreeRTOSV7.4.1\FreeRTOS-Plus\Demo\Common\FreeRTOS_Plus_UDP_Demos\EchoClients\) as a client applicaion, as mentioned at http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Common_Echo_Clients.shtml, website suggests desktop computer to use as a server, but we want another pxa303 board to be used as a server. Can any one guide us with how to program a server application for Pxa303 board?

RE: FreeRTOS+UDP to create server application

Posted by Richard on May 3, 2013
FreeRTOS+UDP uses a standard (ish) sockets interface, so the procedure is as per using any other Berkeley sockets IP stack:

1) Call FreeRTOS_socket() to create a socket - it will be created with a receive block time of portMAX_DELAY.
2) Call FreeRTOS_bind() to bind the socket to the echo port (port 7 by default).
3) Call FreeRTOS_recvfrom() on the socket. If configINCLUDE_vTaskSuspend is set to 1 the call will only return once data has been received.
4) Call FreeRTOS_sendto() to send the received data back from whence it came.
5) Go back to step 3 to wait for more data.

It would look something like this (I have not tried running this code! It is for example only)

static void prvEchoServer( void *pvParameters )
{
xSocket_t xSocket;
struct freertos_sockaddr xAddress;
/* Make sure array is large enough and that it does not overflow the
task stack. Make it static if necessary. */
int8_t cBuffer[ 25 ];
uint32_t xAddressLength = sizeof( xAddress );
long lBytes;

/* Remove compiler warning about unused parameters. */
( void ) pvParameters;

for( ;; )
{
/* Create a socket. */
xSocket = FreeRTOS_socket( FREERTOS_AF_INET,
FREERTOS_SOCK_DGRAM,
FREERTOS_IPPROTO_UDP );

/* Bind the the standard echo server port number. */
xAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
FreeRTOS_bind( xSocket, &xAddress, sizeof( xAddress ) );

/* Send a number of echo requests. */
for( ;; )
{
/* Wait for data to arrive on the echo port. */
lBytes = FreeRTOS_recvfrom( xSocket, cBuffer, sizeof( cBuffer ),
0, &xAddress, &xAddressLength );

/* Send the received data back from the originating address. */
FreeRTOS_sendto( xSocket, cBuffer, lBytes, 0,
&xAddress, xAddressLength );
}
}
}


Regards.


[ 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