Passing Data from custom peripheral to socket using FreeRTOS_Send

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 ) { int32_t lBytes, lSent, lTotalSent; Socket_t xConnectedSocket; static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 ); static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 ); TickType_t xTimeOnShutdown; uint8_t *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: %irn", 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

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 🙁