Quality RTOS & Embedded Software

LIBRARIES
WHAT'S NEW
FreeRTOS:
FreeRTOS LTS:
FreeRTOS:
FreeRTOS:
AWS Reference Integrations:

FreeRTOS_SetIPAddress()

[FreeRTOS+TCP API Reference]

FreeRTOS_IP.h

void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );

This function can be used to update the IPv4 address used by the FreeRTOS+TCP device after the TCP stack has already been initialized with a call to FreeRTOS_IPInit().

Parameters:

ulIPAddress 

The 32-bit IPv4 address, in network endian order, which the device should use. FreeRTOS_htonl can be used to get the network endian representation of the 32-bit IP address.

Caution:

This function is not thread safe and should be used with the taskENTER_CRITICAL/taskEXIT_CRITICAL pair. A call to this function should be made only when there is no active connection (either UDP or TCP), or else that connection will be severed.

Example usage:

The following code snippet shows how to use FreeRTOS_SetIPAddress.


void vUserTask( void *pvParameters )
{
/* 32-bit representation of 192.168.1.12. */
uint32_t ulHostEndianIPAddress = 0xC0A8010C;
uint32_t ulNetworkEndianIPAddress = FreeRTOS_htonl( ulHostEndianIPAddress );
/* 32-bit representation of 192.168.1.1. */
uint32_t ulHostEndianGatewayAddress = 0xC0A80101;
uint32_t ulNetworkEndianGatewayAddress = FreeRTOS_htonl( ulHostEndianGatewayAddress );
uint32_t ulHostEndianNetmask = 0xFFFFFF00;
uint32_t ulNetworkEndianNetmask = FreeRTOS_htonl( ulHostEndianNetmask );
BaseType_t xUserWantsToUpdateIP = pdFALSE;
BaseType_t xUserWantsToUpdateNetmask = pdFALSE;
BaseType_t xUserWantsToUpdateGateway = pdFALSE;

/* Ignore compiler warnings about unused variables. */
( void ) pvParameters;

for( ; ; )
{
/* Execute some code. */
/*

* .

* .

*/


/* Note: Make sure that there are no active UDP/TCP conenctions. */

/* Check whether the user wants to update the IP address. */
if( xUserWantsToUpdateIP == pdTRUE )
{
/* Make sure that no other task can the current task while the

* IP-address is being set. */

taskENTER_CRITICAL();
{
/* Set the IP address of this device. */
FreeRTOS_SetIPAddress( ulNetworkEndianIPAddress );
}
/* Exit critical section. */
taskEXIT_CRITICAL();
}

/* Check whether the user wants to update the IP netmask. */
if( xUserWantsToUpdateNetmask == pdTRUE )
{
/* Make sure that no other task can the current task while the

* IP-address is being set. */

taskENTER_CRITICAL();
{
/* Set the IP netmask of this device. */
FreeRTOS_SetNetmask( ulNetworkEndianNetmask );
}
/* Exit critical section. */
taskEXIT_CRITICAL();
}

/* Check whether the user wants to update the gateway address. */
if( xUserWantsToUpdateGateway == pdTRUE )
{
/* Make sure that no other task can the current task while the

* IP-address is being set. */

taskENTER_CRITICAL();
{
/* Set the IP netmask of this device. */
FreeRTOS_SetGetwayAddress( ulNetworkEndianGatewayAddress );
}
/* Exit critical section. */
taskEXIT_CRITICAL();
}
}
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.