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


Passing Data from custom peripheral to socket using FreeRTOS_Send

Posted by jspag on March 21, 2016

Hi folks, > I am using the FreeRTOS+TCP Demo on a Microzed board built using the Xilinx Vivado tool. As part of this build I included a custom Xilinx Peripheral which is a simple Memory mapped Register Interface. My goal is to have the PL fabric sample some data coming in on a PMOD connector, store the data in the memory mapped register and have the PS access the data. So far so good. The function which executes this is working and prints the values out to the Terminal utility. Once the data is accessed by the PS I would like to transmit the data to a remote client using the Simple TCP Echo Server application provided. The Echo Server is working fine. I have a crossover cable connected from my Development environment PC to a laptop. From the laptop I telnet to the Echo Server. When I press a key on the laptop keyboard the Echo Server transmits the character back to the client(laptop). Now my problem is transmiting back the data from my register interface instead of echoing back the data from the client. Please bear with me as I am not a Software Programmer and don't know C very well at all. The data buffer created for receiving data is "pucRxBuffer" as you can see in the code below. It is the same buffer used to echo back the data. If I create my own buffer or just use the data I read from my register interface and use that is the FreeRTOSP_Send API , I get the expected data printing to my Terminal Utility however the wrong values are displayed in the client telnet window. Could someone please show me how to pass my register data to the Socket.

The lines of code between the comments /* My Custom Peripheral Access Starts here / and / My Custom Peripheral Access Ends here */ is where I am writing a test pattern and reading back the result and printing to the Stdout as expected.

Much appreciated.

Here is the function from the SimpleTCPEchoServer.c code provided.

static void prvServerConnectionInstance( void *pvParameters ) { int32t lBytes, lSent, lTotalSent; Sockett xConnectedSocket; static const TickTypet xReceiveTimeOut = pdMSTOTICKS( 5000 ); static const TickTypet xSendTimeOut = pdMSTOTICKS( 5000 ); TickTypet xTimeOnShutdown; uint8t *pucRxBuffer;

int testdata = 05; int i = 0; int rd_data = 0;

xConnectedSocket = ( Socket_t ) pvParameters;

/* Attempt to create the buffer used to receive the string to be echoed
back.  This could be avoided using a zero copy interface that just returned
the same buffer. */
pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS );

if( pucRxBuffer != NULL )
	FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
	FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );

	for( ;; )

		/* Zero out the receive array so there is NULL at the end of the string
		when it is printed out. */
		memset( pucRxBuffer, 0x00, ipconfigTCP_MSS );

		/* Receive data on the socket. */
		lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 );

		/* If data was received, echo it back. */
		if( lBytes >= 0 )

/* My Custom Peripheral Access Starts here */

			set_ifm_test_reg(AXI_TO_REG_BASEADDR ,TESTFREQ_REGISTER1_OFFSET, (testdata + i));
			set_led_test_reg(AXI_TO_REG_LEDS ,TESTFREQ_REGISTER1_OFFSET, (testdata + i));
			rd_data = get_ifm_test_reg(AXI_TO_REG_BASEADDR , TESTFREQ_REGISTER1_OFFSET);
			   xil_printf( "AXI Register Read Data: %i\r\n", rd_data );

/* My Custom Peripheral Access Ends here */

			lSent = 0;
			lTotalSent = 0;

			/* Call send() until all the data has been sent. */
			while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) )
				/*lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 );*/
				lSent = FreeRTOS_send( xConnectedSocket, rd_data, lBytes - lTotalSent, 0 );

				lTotalSent += lSent;

			if( lSent < 0 )
				/* Socket closed? */
			/* Socket closed? */

/* Initiate a shutdown in case it has not already been initiated. */
FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR );

/* Wait for the shutdown to take effect, indicated by FreeRTOS_recv()
returning an error. */
xTimeOnShutdown = xTaskGetTickCount();
	if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 )
} while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY );

/* Finished with the socket, buffer, the task. */
vPortFree( pucRxBuffer );
FreeRTOS_closesocket( xConnectedSocket );

vTaskDelete( NULL );


Passing Data from custom peripheral to socket using FreeRTOS_Send

Posted by heinbali01 on March 22, 2016

When the function FreeRTOS_recv() returns a negative number, it says:

    /* Socket closed? */

It would be more correct to write:

else if( lBytes != -pdFREERTOS_ERRNO_EWOULDBLOCK )
    /* Socket closed? */

When sending, you might get a non-fatal return value -pdFREERTOS_ERRNO_ENOSPC

What does your function get_ifm_test_reg() return?

rd_data = get_ifm_test_reg(AXI_TO_REG_BASEADDR , TESTFREQ_REGISTER1_OFFSET);

You assign the result to an integer int rd_data

Later on, you're calling FreeRTOS_send() with rd_data as a parameter where void * is expected.

I'm afraid I do not understand the logic of your application :-(

[ 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