下载 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_SetIPAddress()

[FreeRTOS-Plus-TCP API 引用]

FreeRTOS_IP.h

void FreeRTOS_SetIPAddress( uint32_t ulIPAddress );

可以使用此函数更新 FreeRTOS-Plus-TCP 设备使用的第一个 IPv4 端点的 IPv4 地址 ——在初始化 TCP堆栈之后 (通过调用 FreeRTOS_IPInit_Multi())。 如果找不到 IPv4 端点,则不会产生任何影响。

参数:

ulIPAddress 

设备应使用的 32 位 IPv4 地址,按网络端序排列。 FreeRTOS_htonl 可用于获取 32 位 IP 地址的网络端表示。

注意事项:

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

用法示例:

可参考下述代码片段了解如何使用 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.