下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。
注意:此 API 已从 FreeRTOS V4.0.0 起弃用 。请参阅 FreeRTOS_SetEndPointConfiguration 了解支持 IPv6、多个端点和多个接口的新 API。如需使用已弃用的 API ,请将 FreeRTOSIPConfig.h 头文件中的 ipconfigIPv4_BACKWARD_COMPATIBLE 设置为 1。

FreeRTOS_SetAddressConfiguration()

[FreeRTOS-Plus-TCP API 引用]

FreeRTOS_IP.h

void FreeRTOS_SetAddressConfiguration( const uint32_t * pulIPAddress,
                                       const uint32_t * pulNetMask,
                                       const uint32_t * pulGatewayAddress,
                                       const uint32_t * pulDNSServerAddress );

这个函数可以用来更新 IPv4 地址和网络掩码、网关地址和 DNS 服务器地址 (由 FreeRTOS-Plus-TCP 设备使用)——在调用 FreeRTOS_IPInit() 初始化 TCP 堆栈之后 FreeRTOS_IPInit_Multi() 设置。 如果找不到 IPv4 端点,则不会产生任何影响。

参数:

pulIPAddress  指向设备应该使用的 32 位 IPv4 地址的指针,此地址按网络端序排列。 如需保持 IP 地址不变,该指针可以为 NULL。
pulNetMask  指向设备应该使用的 32 位 IPv4 网络掩码的指针,此掩码按网络字节序排列。 如需保持 IP 网络掩码不变,该指针可以为 NULL。
pulGatewayAddress  指向设备应该使用的 32 位 IPv4 网关 地址的指针, 按照网络 endian 顺序。如果您想不改变设备的网关地址, 这个指针可以是 NULL。
pulDNSServerAddress  指向设备应使用的 32 位 IPv4 DNS 服务器地址的指针。如果您想让使用中的 DNS 服务器 IP 地址保持不变,这个指针可以是 NULL。

注意事项:

此函数不是线程安全的,应与 taskENTER_CRITICAL/taskEXIT_CRITICAL 对一起使用。只有在没有活动连接(UDP 或 TCP)时才应调用此函数,否则 连接可能被切断。

用法示例:


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 );
/* 32-bit representation of OpenDNS server address 208.67.222.222 */
uint32_t ulHostEndianDNSServerAddress = 0xD043DEDE;
uint32_t ulNetworkEndianDNSServerAddress = FreeRTOS_htonl( ulHostEndianDNSServerAddress );
BaseType_t xUserWantsToUpdateConfiguration = 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( xUserWantsToUpdateConfiguration == pdTRUE )
{
/* Make sure that no other task can the current task while the

* IP-address is being set. */

taskENTER_CRITICAL();
{
/* Update the IP address, gateway address and the DNS server address of

* this device but leave the netmask unchanged by passing NULL. */

FreeRTOS_SetAddressConfiguration( &ulNetworkEndianIPAddress ,
NULL,
&ulNetworkEndianGatewayAddress,
&ulNetworkEndianDNSServerAddress );
}
/* Exit critical section. */
taskEXIT_CRITICAL();
}
}
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.