ethernet

/***********************************************************************************************************************

* File Name : https_client_thread_entry.c

* Description : Contains entry function of HTTPS Client.

***********************************************************************************************************************/

/***********************************************************************************************************************

* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates

*

* SPDX-License-Identifier: BSD-3-Clause

***********************************************************************************************************************/

/* Include Header Files. */

#include "https_client_thread.h"

#include "common_utils.h"

#include "https_client_app.h"

#include "adc_app.h"

#include "user_app.h" // or another relevant file for g_sf_el_nx

#include "r_ether_api.h"

/*******************************************************************************************************************//**

* @addtogroup NetX_https_client_ep

* @{

**********************************************************************************************************************/

/* Auto generated global variables */

/* Packet pool instance. */

NX_PACKET_POOL g_packet_pool0;

/* Web HTTP Client instance. */

NX_WEB_HTTP_CLIENT g_web_http_client0;

/* IP instance */

NX_IP g_ip0;

/* DNS instance. */

NX_DNS g_dns0;

NX_PACKET *gp_response_ptr = NULL;

/* Stack memory for g_ip0. */

uint8_t g_ip0_stack_memory[G_IP0_TASK_STACK_SIZE] BSP_PLACE_IN_SECTION(".stack.g_ip0") BSP_ALIGN_VARIABLE(BSP_STACK_ALIGNMENT);

/* ARP cache memory for g_ip0. */

uint8_t g_ip0_arp_cache_memory[G_IP0_ARP_CACHE_SIZE] BSP_ALIGN_VARIABLE(4);

/* Packet Pool Memory for g_packet_pool0. */

uint8_t g_packet_pool0_pool_memory[G_PACKET_POOL0_PACKET_NUM * (G_PACKET_POOL0_PACKET_SIZE + sizeof(NX_PACKET))] BSP_ALIGN_VARIABLE(4) ETHER_BUFFER_PLACE_IN_SECTION;

/* Buffer to read Response from server. */

extern UCHAR g_receive_buffer[DATA_SIZE];

/* variable to capture invalid input state */

volatile bool g_invalid_input = false;

/* IPv4 Address structure for server. */

static NXD_ADDRESS server_ip_address;

static ULONG server_addr = 0xC0A81FA0;

static ULONG dns_server_addr = 0xC0A81F01;

static void nx_common_init0(void);

static UINT web_http_client0_init(void);

static UINT ip0_init(void);

static UINT packet_pool0_init0(void);

static UINT dns_client_init(void);

static UINT Process_InputRequest(uint8_t input_data);

#define SERVER_IP_ADDRESS 0xC0A81F01 // For 192.168.31.1 in hex

NX_INTERFACE g_sf_el_nx;

/*******************************************************************************************************************//**

* @brief This is the User Thread Entry for the EP.

* @param[in] Thread specific parameters

* @retval None

**********************************************************************************************************************/

void https_client_thread_entry(void)

{

/* To capture the status(Success/Failure) of each Function/API. */

UINT status = NX_SUCCESS;

UINT err = TX_SUCCESS;

fsp_err_t adc_err = FSP_SUCCESS;

/* Client IP address and Network Mask. */

ULONG client_ip_address = RESET_VALUE;

ULONG network_mask = RESET_VALUE;

uint8_t read_data = RESET_VALUE;

float init_adc_val = RESET_VALUE;

/* Initialize the RTT Thread.*/

rtt_thread_init_check();

/* Print EP and Banner info. */

app_rtt_print_data(RTT_OUTPUT_MESSAGE_BANNER, RESET_VALUE, NULL);

/* Initialize the ADC. */

adc_err = hal_adc_init();

if(FSP_SUCCESS != adc_err)

{

PRINT_ERR_STR("hal_adc_init() Function failed.");

ERROR_TRAP(adc_err);

}

/* Initialize NetX. */

nx_common_init0();

/* Initialize Packet Pool. */

status = packet_pool0_init0();

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("packet_pool0_init0() Function failed.");

ERROR_TRAP(status);

}

/* Initialize IP with manual settings. */

status = ip0_init();

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("ip0_init() Function failed.");

ERROR_TRAP(status);

}

/* Initialize DNS Client. */

status = dns_client_init();

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("dns_client_init() Function failed.");

ERROR_TRAP(status);

}

/* Initialize Web HTTPS Client. */

status = web_http_client0_init();

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("web_http_client0_init() Function failed.");

ERROR_TRAP(status);

}

/* Initialize the TLS Component. */

nx_secure_tls_initialize();

/* Add Server IP address and IPv4 info in structure. */

server_ip_address.nxd_ip_address.v4 = server_addr;

server_ip_address.nxd_ip_version = NX_IP_VERSION_V4;

/* Connect to the HTTPS server. */

status = nx_web_http_client_secure_connect(&g_web_http_client0, &server_ip_address, NX_WEB_HTTPS_SERVER_PORT,

tls_setup_callback, SECURE_CONNECT_WAIT_TIME);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_web_http_client_secure_connect API failed.");

deinit_https_client();

ERROR_TRAP(status);

}

PRINT_INFO_STR("HTTPS Client is connected to the server successfully!");

/* Retrieve the IP Address. */

status = nx_ip_address_get(&g_ip0, &client_ip_address, &network_mask);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_ip_address_get API failed.");

deinit_https_client();

ERROR_TRAP(status);

}

/* Print the client IP address. */

app_rtt_print_data(RTT_OUTPUT_MESSAGE_APP_PRINT_CLIENT_IP, sizeof(ULONG *), &client_ip_address);

/* Post Request with initial data. */

PRINT_INFO_STR("Adding an initial data on the feed...");

init_adc_val = adc_data_read();

status = processPostRequest(init_adc_val);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("processPostRequest() Function failed.");

deinit_https_client();

ERROR_TRAP(status);

}

PRINT_INFO_STR("Posted initial data on the feed successfully!");

/* Print the Menu Options */

app_rtt_print_data(RTT_OUTPUT_MESSAGE_APP_PRINT_MENU, RESET_VALUE, NULL);

/* Process the data as per the user selected option from the menu. */

while (true)

{

do

{

err = check_for_rtt_user_ip(&read_data);

}while (err != TX_SUCCESS);

status = Process_InputRequest(read_data);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("Process_InputRequest() function failed.");

deinit_https_client();

ERROR_TRAP(status);

}

if (!g_invalid_input)

{

status = readResponsefromServer();

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("readResponsefromServer() function failed.");

deinit_https_client();

ERROR_TRAP(status);

}

else

{

APP_PRINT("Received data: %s\n", g_receive_buffer);

PRINT_INFO_STR("Read the response from server Successfully!");

}

}

g_invalid_input = false;

app_rtt_print_data(RTT_OUTPUT_MESSAGE_APP_PRINT_MENU, RESET_VALUE, NULL);

tx_thread_sleep(1);

}

}

/*******************************************************************************************************************//**

* @brief This function initializes the NetX System.

* @param[IN] None

* @retval None

**********************************************************************************************************************/

static void nx_common_init0(void)

{

/* Initialize the NetX system. */

nx_system_initialize();

}

/*******************************************************************************************************************//**

* @brief This function creates the packet pool.

* @param[IN] None

* @retval None

**********************************************************************************************************************/

static UINT packet_pool0_init0(void)

{

UINT status = NX_SUCCESS;

status = nx_packet_pool_create(&g_packet_pool0, "g_packet_pool0 Packet Pool",

G_PACKET_POOL0_PACKET_SIZE, &g_packet_pool0_pool_memory[0],

G_PACKET_POOL0_PACKET_NUM * (G_PACKET_POOL0_PACKET_SIZE + sizeof(NX_PACKET)));

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_packet_pool_create API failed.");

}

return status;

}

/*******************************************************************************************************************//**

* @brief This function initializes the Web HTTPS Client.

* @param[IN] None

* @retval None

**********************************************************************************************************************/

static UINT web_http_client0_init(void)

{

UINT status = NX_SUCCESS;

status = nx_web_http_client_create(&g_web_http_client0, "g_web_http_client0",

&g_ip0, &g_packet_pool0, G_WEB_HTTP_CLIENT0_WINDOW_SIZE);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_web_http_client_create API failed.");

}

return status;

}

/*******************************************************************************************************************//**

* @brief This function creates the ip instance with manual IP settings.

* @param[IN] None

* @retval None

**********************************************************************************************************************/

static UINT ip0_init(void)

{

UINT status = NX_SUCCESS;

ULONG current_state = RESET_VALUE;

/* Manual IP configuration */

ULONG manual_ip_address = 0xC0A80A36; /* 192.168.10.54 */

ULONG subnet_mask = 0xFFFFFF00; /* 255.255.255.0 */

ULONG gateway_address = 0xC0A80A01; /* 192.168.10.1 */

/* Create the IP instance */

status = nxe_ip_create(&g_ip0, "g_ip0 IP Instance", manual_ip_address, subnet_mask,

&g_packet_pool0, g_ether0, g_ip0_stack_memory,

G_IP0_TASK_STACK_SIZE, G_IP0_TASK_PRIORITY);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_ip_create API failed.");

return status;

}

/* Set the gateway address */

status = nx_ip_gateway_address_set(&g_ip0, gateway_address);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_ip_gateway_address_set API failed.");

return status;

}

/* Enable ARP and supply ARP cache memory */

status = nx_arp_enable(&g_ip0, g_ip0_arp_cache_memory, G_IP0_ARP_CACHE_SIZE);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_arp_enable API failed.");

return status;

}

/* Enable ICMP (ping) */

status = nx_icmp_enable(&g_ip0);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_icmp_enable API failed.");

return status;

}

/* Enable TCP traffic */

status = nx_tcp_enable(&g_ip0);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_tcp_enable API failed.");

return status;

}

/* Enable UDP traffic */

status = nx_udp_enable(&g_ip0);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_udp_enable API failed.");

return status;

}

/* Check for interface link status */

status = nx_ip_interface_status_check(&g_ip0, 0U, NX_IP_LINK_ENABLED, &current_state, LINK_ENABLE_WAIT_TIME);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_ip_interface_status_check API failed.");

}

return status;

}

/*******************************************************************************************************************//**

* @brief This function creates the DNS Client.

* @param[IN] None

* @retval None

**********************************************************************************************************************/

static UINT dns_client_init(void)

{

UINT status = NX_SUCCESS;

/* Create a DNS instance for the Client */

status = nx_dns_create(&g_dns0, &g_ip0, (UCHAR *)"g_dns0");

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_dns_create API failed.");

return status;

}

/* Initialize DNS Client to point to a DNS Server */

dns_server_addr = SERVER_IP_ADDRESS;

status = nx_dns_server_add(&g_dns0, dns_server_addr);

if(NX_SUCCESS != status)

{

PRINT_ERR_STR("nx_dns_server_add API failed.");

}

return status;

}

/*******************************************************************************************************************//**

* @} (end addtogroup NetX_https_client_ep)

**********************************************************************************************************************/

how to update this code for manual ip set this program has some errors can you help to solve this error?