Hi folks,
Am new to this forum, Am working on Renesas RA6M5 controller… i have implemented ethernet … Assigned the IP Address using FreeRTOS_IPInit API… But i dont know how to change the IP address during runtime… I have tried using FreeRTOS_SetAddressConfiguration … by passing only the IP address and sending NULL on other parameters… here is the code for reference
#include "new_thread0.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "NetworkInterface.h"
#include "FreeRTOS_DHCP.h"
#define USR_TEST_PING_IP "192.168.1.123" //"172.217.160.174"
volatile bool network_up = false;
uint8_t ucIPAddress[4] = {192,168,1,125};
uint8_t ucMACAddress[6] = {0x00,0x11,0x22,0x33,0x44,0x55};
const uint8_t ucNetMask[4] = {255,255,255,0};
const uint8_t ucGatewayAddress[4] = {192,168,1,1};
const uint8_t ucDNSServerAddress[4] = {8,8,8,8};
uint8_t change_ip_address_value[4] = {192,168,1,21};
uint8_t ping_data_received = 0;
uint8_t ping_data_lost = 0;
uint8_t *gp_remote_ip_address = (uint8_t *)USR_TEST_PING_IP;
BaseType_t vSendPing( const char *pcIPAddress);
bool change_ip_address();
uint32_t convert_ip_address(uint8_t ip_address[4]);
static bool is_ping_successful = false;
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
if(eNetworkEvent == eNetworkUp)
{
network_up = true;
}
}
void new_thread0_entry(void *pvParameters)
{
FSP_PARAMETER_NOT_USED (pvParameters);
BaseType_t status;
status = FreeRTOS_IPInit(ucIPAddress, ucNetMask,ucGatewayAddress,ucDNSServerAddress,ucMACAddress);
if( status == pdFALSE)
{
__BKPT(0);
}
while (false == network_up)
{
;
}
while (true)
{
if(is_ping_successful){
break;
}
status = vSendPing((char *)gp_remote_ip_address);
vTaskDelay (10);
}
// Now Change the IP Address
change_ip_address();
while(true){
__NOP();
}
}
BaseType_t vSendPing( const char *pcIPAddress)
{
uint32_t ulIPAddress = 0;
ulIPAddress = FreeRTOS_inet_addr(pcIPAddress);
return(FreeRTOS_SendPingRequest(ulIPAddress, 8, 100 / portTICK_PERIOD_MS));
}
void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
{
(void) usIdentifier;
switch( eStatus )
{
/* A valid ping reply has been received */
case eSuccess :
ping_data_received++;
is_ping_successful = true;
break;
/* A reply was received but it was not valid. */
case eInvalidData :
ping_data_lost++;
break;
default:
ping_data_lost++;
break;
}
}
bool change_ip_address(){
bool return_status = false;
uint32_t changed_ip_address = 0;
uint32_t get_ip_address = 0;
network_up = false;
changed_ip_address = convert_ip_address(change_ip_address_value);
taskENTER_CRITICAL();
FreeRTOS_SetAddressConfiguration(&changed_ip_address,NULL,NULL,NULL);
taskEXIT_CRITICAL();
xDefaultAddressing.ulDefaultIPAddress = changed_ip_address;
FreeRTOS_NetworkDown( );
R_BSP_SoftwareDelay(2000, BSP_DELAY_UNITS_MILLISECONDS);
while (!network_up) {
vTaskDelay(pdMS_TO_TICKS(100));
}
get_ip_address = FreeRTOS_GetIPAddress();
if(get_ip_address == changed_ip_address){
__NOP();
}
return return_status;
}
uint32_t convert_ip_address(uint8_t ip_address[4]){
uint32_t value = 0;
value = (uint32_t)(ip_address[0] << 24 | ip_address[1] << 16 | ip_address[2] << 8 | ip_address[3]);
return value;
}
Here i am not using DHCP , Am using static IP Address and DHCP configuration parameters are as follows…
#define ipconfigUSE_DHCP 0
#define ipconfigDHCP_REGISTER_HOSTNAME 0
#define ipconfigDHCP_USES_UNICAST 0
#define ipconfigDHCP_SEND_DISCOVER_AFTER_AUTO_IP 0
#define ipconfigUSE_DHCP_HOOK 0
Please let me know how to change IP address and MAC address and let me know if you have any queries…
Note: Kindly concentrate on change_ip_address function.
Thanks & regards,
Vikram