Thank you, Richard. There is the code:
#include <stdio.h>
#include <pthread.h>
/* Kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
/* Local includes. */
#include "console.h"
static void prvTaskOne( void *pvParameters );
static uint8_t MACAddress[ 6 ] = { 0x40, 0x49, 0x0F, 0xC0, 0x54, 0x63 };
static const uint8_t IPAddress[ 4 ] = { 127, 0, 0, 1 };
static const uint8_t NetMask[ 4 ] = { 0, 0, 0, 255 };
static const uint8_t GatewayAddress[ 4 ] = { 192, 168, 2, 1 };
//static const uint8_t DNSServerAddress[ 4 ] = { 194, 14, 11, 200 };
static const uint8_t DNSServerAddress[ 4 ] = { 200, 11, 14, 194 };
int solution(){
FreeRTOS_IPInit( IPAddress,
NetMask,
GatewayAddress,
DNSServerAddress,
MACAddress );
vTaskStartScheduler();
return 0;
}
static void prvTaskOne(void *pvParameters){
xSocket_t xSocket;
console_print("Criando primeira task \n");
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
configASSERT(xSocket != FREERTOS_INVALID_SOCKET);
console_print("Socket criado");
uint8_t ucBuffer[ 128 ];
struct freertos_sockaddr xDestinationAddress;
int32_t iReturned;
/* Fill in the destination address and port number, which in this case is
port 1024 on IP address 192.168.0.100. */
xDestinationAddress.sin_addr = FreeRTOS_inet_addr_quick( 127, 0, 0, 1 );
xDestinationAddress.sin_port = FreeRTOS_htons( 5000 );
/* The local buffer is filled with the data to be sent, in this case it is
just filled with 0xff. */
memset( ucBuffer, 0xff, 128 );
/* Send the buffer with ulFlags set to 0, so the FREERTOS_ZERO_COPY bit
is clear. */
iReturned = FreeRTOS_sendto(
/* The socket being send to. */
xSocket,
/* The data being sent. */
ucBuffer,
/* The length of the data being sent. */
128,
/* ulFlags with the FREERTOS_ZERO_COPY bit clear. */
0,
/* Where the data is being sent. */
&xDestinationAddress,
/* Not used but should be set as shown. */
sizeof( xDestinationAddress )
);
if( iReturned == 128 )
{
/* The data was successfully queued for sending. 128 bytes will have
been copied out of ucBuffer and into a buffer inside the IP stack.
ucBuffer can be re-used now. */
console_print("Dado enviado com sucesso! \n");
}
for(;;);
}
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
char cBuffer[ 16 ];
static BaseType_t xTasksAlreadyCreated = pdFALSE;
/* If the network has just come up...*/
if( eNetworkEvent == eNetworkUp )
{
/* Create the tasks that use the IP stack if they have not already been
created. */
if( xTasksAlreadyCreated == pdFALSE )
{
/* See the comments above the definitions of these pre-processor
macros at the top of this file for a description of the individual
demo tasks. */
xTaskCreate( prvTaskOne, /* The function that implements the task. */
"Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */
configMINIMAL_STACK_SIZE*30, /* The size of the stack to allocate to the task. */
NULL, /* The parameter passed to the task - not used in this simple case. */
5,/* The priority assigned to the task. */
NULL );
xTasksAlreadyCreated = pdTRUE;
}
/* Print out the network configuration, which may have come from a DHCP
server. */
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
// FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
// FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
// FreeRTOS_printf( ( "Gateway Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
// FreeRTOS_printf( ( "DNS Server Address: %s\r\n\r\n\r\n", cBuffer ) );
}
else
{
// FreeRTOS_printf( "Application idle hook network down\n" );
}
}