/* USER CODE BEGIN Header */ /** ****************************************************************************** * File Name : LWIP.c * Description : This file provides initialization code for LWIP * middleWare. ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "lwip.h" #include "lwip/init.h" #include "lwip/netif.h" #if defined(__CC_ARM) #include "lwip/sio.h" #endif #include "ethernetif.h" // #include "base_service/base_service.h" #include "base_service/task_level_config.h" #define TAG "network" static struct netif gnetif; static ip4_addr_t ipaddr; static ip4_addr_t netmask; static ip4_addr_t gw; static uint8_t IP_ADDRESS[4]; static uint8_t NETMASK_ADDRESS[4]; static uint8_t GATEWAY_ADDRESS[4]; uint8_t g_mac[6]; static void ethernet_link_status_updated(struct netif *netif) { if (netif_is_up(netif)) { ZLOGI(TAG, "ethernet_link_status_updated: netif_is_up"); } else { ZLOGI(TAG, "ethernet_link_status_updated: netif_is_down"); } } void network_service_init() { ZLOGI(TAG, "network_service_init"); *(uint32_t *)(IP_ADDRESS) = config_get()->ip; *(uint32_t *)(NETMASK_ADDRESS) = config_get()->netmask; *(uint32_t *)(GATEWAY_ADDRESS) = config_get()->gw; // IP_ADDRESS[0] = 192; // IP_ADDRESS[1] = 168; // IP_ADDRESS[2] = 8; // IP_ADDRESS[3] = 10; // NETMASK_ADDRESS[0] = 255; // NETMASK_ADDRESS[1] = 255; // NETMASK_ADDRESS[2] = 255; // NETMASK_ADDRESS[3] = 255; // GATEWAY_ADDRESS[0] = 192; // GATEWAY_ADDRESS[1] = 168; // GATEWAY_ADDRESS[2] = 8; // GATEWAY_ADDRESS[3] = 1; memcpy(g_mac, config_get()->mac, 6); /* Initilialize the LwIP stack with RTOS */ tcpip_init(NULL, NULL); /* IP addresses initialization without DHCP (IPv4) */ IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]); IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1], NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]); IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]); /* add the network interface (IPv4/IPv6) with RTOS */ netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); /* Registers the default network interface */ netif_set_default(&gnetif); if (netif_is_link_up(&gnetif)) { /* When the netif is fully configured this function must be called */ netif_set_up(&gnetif); } else { /* When the netif link is down this function must be called */ netif_set_down(&gnetif); } /* Set the link callback function, this function is called on change of link status*/ netif_set_link_callback(&gnetif, ethernet_link_status_updated); osThreadDef(EthLink, ethernet_link_thread, NETWORK_REPORT_TASK_LEVEL, 0, 512); osThreadCreate(osThread(EthLink), &gnetif); }