rim72 wrote on Wednesday, July 11, 2018:
–> NEW problem.
Dear, Hein.
AS I said, I succeed to make my board work.
Actually, it means that my board works very well as a DHCP client.
I could check it on my DHCP server.
But problem is that below function doesn’t work (of course, it works very well in windows simulation VC2010 project ).
As you can see, “FreeRTOS_sendto” UDP function is the key function and is used in the DHCP client code too. However, it seems that this function does not work here in below function.
What will be the cause??
Thanks in advance.
////////////////// below function //////////////////////////////////////
static void prvSimpleZeroCopyUDPClientTask( void pvParameters )
{
Sockett xClientSocket;
uint8t pucUDPPayloadBuffer;
struct freertossockaddr xDestinationAddress;
BaseTypet lReturned;
uint32t ulCount = 0UL, ulIPAddress;
const uint32t ulLoopsPerSocket = 100UL;
const char pcStringToSend = "Server received (using zero copy): Message number ";
const TickTypet x150ms = 150UL / portTICKPERIODMS;
/ 15 is added to ensure the number, \r\n and terminating zero fit. /
const sizet xStringLength = strlen( pcStringToSend ) + 15;
*
/* Remove compiler warning about unused parameters. */
( void ) pvParameters;
/* It is assumed that this task is not created until the network is up,
so the IP address can be obtained immediately. store the IP address being
used in ulIPAddress. This is done so the socket can send to a different
port on the same IP address. */
//FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
/* This test sends to itself, so data sent from here is received by a server
socket on the same IP address. Setup the freertos_sockaddr structure with
this nodes IP address, and the port number being sent to. The strange
casting is to try and remove compiler warnings on 32 bit machines. */
//xDestinationAddress.sin_addr = ulIPAddress;
//xDestinationAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL;
//xDestinationAddress.sin_port = FreeRTOS_htons( xDestinationAddress.sin_port );
xDestinationAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
xDestinationAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
configECHO_SERVER_ADDR1,
configECHO_SERVER_ADDR2,
configECHO_SERVER_ADDR3 );
//for( ;; )
//{
/* Create the socket. */
xClientSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
configASSERT( xClientSocket != FREERTOS_INVALID_SOCKET );
/* The count is used to differentiate between different messages sent to
the server, and to break out of the do while loop below. */
ulCount = 0UL;
do
{
/* This task is going to send using the zero copy interface. The
data being sent is therefore written directly into a buffer that is
passed into, rather than copied into, the FreeRTOS_sendto()
function.
First obtain a buffer of adequate length from the IP stack into which
the string will be written. Although a max delay is used, the actual
delay will be capped to ipconfigMAX_SEND_BLOCK_TIME_TICKS, hence
the do while loop is used to ensure a buffer is obtained. */
do
{
} while( ( pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xStringLength, portMAX_DELAY ) ) == NULL );
/* A buffer was successfully obtained. Create the string that is
sent to the server. First the string is filled with zeros as this will
effectively be the null terminator when the string is received at the other
end. Note that the string is being written directly into the buffer
obtained from the IP stack above. */
memset( ( void * ) pucUDPPayloadBuffer, 0x00, xStringLength );
sprintf( ( char * ) pucUDPPayloadBuffer, "%s%lu\r\n", pcStringToSend, ulCount );
/* Pass the buffer into the send function. ulFlags has the
FREERTOS_ZERO_COPY bit set so the IP stack will take control of the
buffer rather than copy data out of the buffer. */
lReturned = FreeRTOS_sendto( xClientSocket, /* The socket being sent to. */
( void * ) pucUDPPayloadBuffer, /* A pointer to the the data being sent. */
strlen( ( const char * ) pucUDPPayloadBuffer ) + 1, /* The length of the data being sent - including the string's null terminator. */
FREERTOS_ZERO_COPY, /* ulFlags with the FREERTOS_ZERO_COPY bit set. */
&xDestinationAddress, /* Where the data is being sent. */
sizeof( xDestinationAddress ) );
if( lReturned == 0 )
{
/* The send operation failed, so this task is still responsible
for the buffer obtained from the IP stack. To ensure the buffer
is not lost it must either be used again, or, as in this case,
returned to the IP stack using FreeRTOS_ReleaseUDPPayloadBuffer().
pucUDPPayloadBuffer can be safely re-used after this call. */
FreeRTOS_ReleaseUDPPayloadBuffer( ( void * ) pucUDPPayloadBuffer );
}
else
{
/* The send was successful so the IP stack is now managing the
buffer pointed to by pucUDPPayloadBuffer, and the IP stack will
return the buffer once it has been sent. pucUDPPayloadBuffer can
be safely re-used. */
//vTaskDelay(1000); //rim
}
ulCount++;
vTaskDelay(4000);
} while( ( lReturned != FREERTOS_SOCKET_ERROR ) && ( ulCount < ulLoopsPerSocket ) );
FreeRTOS_closesocket( xClientSocket );
/* A short delay to prevent the messages scrolling off the screen too
quickly. */
vTaskDelay( x150ms );
//} for
}
/-----------------------------------------------------------/