Quality RTOS & Embedded Software

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


Loading

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));
			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? */
				break;
			}
		}
		else
		{
			/* Socket closed? */
			break;
		}
	}
}

/* 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();
do
{
	if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 )
	{
		break;
	}
} 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:

else
{
    /* Socket closed? */
    break;
}

It would be more correct to write:

else if( lBytes != -pdFREERTOS_ERRNO_EWOULDBLOCK )
{
    /* Socket closed? */
    break;
}

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