diff --git a/CMakeLists.txt b/CMakeLists.txt index e0ee249..62748ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,6 @@ target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) -if(TGT_BSP MATCHES "arm/stm32h743zi-nucleo") +if(TGT_BSP MATCHES "arm/stm32h743zi-nucleo") add_subdirectory(stm32h7) endif() diff --git a/stm32h7/CMakeLists.txt b/stm32h7/CMakeLists.txt index 7ac82fe..3ae2e12 100644 --- a/stm32h7/CMakeLists.txt +++ b/stm32h7/CMakeLists.txt @@ -2,7 +2,7 @@ target_sources(${TARGET_NAME} PRIVATE STM32TestTask.cpp ) -option(STM32_ADD_NETWORKING_CODE "Add networking code requiring lwIP" OFF) +option(STM32_ADD_NETWORKING_CODE "Add networking code requiring lwIP" ON) if(STM32_ADD_NETWORKING_CODE) add_subdirectory(networking) diff --git a/stm32h7/networking/CMakeLists.txt b/stm32h7/networking/CMakeLists.txt index a14665b..676adb8 100644 --- a/stm32h7/networking/CMakeLists.txt +++ b/stm32h7/networking/CMakeLists.txt @@ -1,11 +1,14 @@ # These are part of the RTEMS BSP for RTEMS if(FSFW_OSAL MATCHES freertos) - app_dhcp.c - app_ethernet.c - ethernetif.c + target_sources(${TARGET_NAME} PRIVATE + app_ethernet.c + ethernetif.c + ) endif() target_sources(${TARGET_NAME} PRIVATE UdpTcLwIpPollingTask.cpp TmTcLwIpUdpBridge.cpp + networking.cpp + app_dhcp.cpp ) diff --git a/stm32h7/networking/UdpTcLwIpPollingTask.cpp b/stm32h7/networking/UdpTcLwIpPollingTask.cpp index 68820eb..8ec0472 100644 --- a/stm32h7/networking/UdpTcLwIpPollingTask.cpp +++ b/stm32h7/networking/UdpTcLwIpPollingTask.cpp @@ -3,16 +3,20 @@ #include "app_ethernet.h" #include "ethernetif.h" #include "app_dhcp.h" +#include "networking.h" #include #include "fsfw/ipc/MutexGuard.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/objectmanager/ObjectManager.h" + + #include "lwip/timeouts.h" -UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId): - SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId) { +UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, + struct netif* gnetif): + SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), gnetif(gnetif) { } UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() { @@ -23,8 +27,8 @@ ReturnValue_t UdpTcLwIpPollingTask::initialize() { if(udpBridge == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } - if (netif_is_link_up(&gnetif)) { - set_eth_cable_connected(true); + if (netif_is_link_up(gnetif)) { + networking::setEthCableConnected(true); } return RETURN_OK; } @@ -34,28 +38,28 @@ ReturnValue_t UdpTcLwIpPollingTask::initialize() { ReturnValue_t UdpTcLwIpPollingTask::performOperation(uint8_t operationCode) { /* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */ - ethernetif_input(&gnetif); + ethernetif_input(gnetif); /* Handle timeouts */ sys_check_timeouts(); #if LWIP_NETIF_LINK_CALLBACK == 1 - ethernet_link_periodic_handle(&gnetif); + ethernet_link_periodic_handle(gnetif); #endif if(udpBridge != nullptr) { MutexGuard lg(udpBridge->bridgeLock); /* In case ethernet cable is disconnected */ - if(not get_eth_cable_connected() and udpBridge->comLinkUp()) { + if(not networking::getEthCableConnected() and udpBridge->comLinkUp()) { udpBridge->physicalConnectStatusChange(false); } - else if(get_eth_cable_connected() and not udpBridge->comLinkUp()) { + else if(networking::getEthCableConnected() and not udpBridge->comLinkUp()) { udpBridge->physicalConnectStatusChange(true); } } #if LWIP_DHCP == 1 - DHCP_Periodic_Handle(&gnetif); + DHCP_Periodic_Handle(gnetif); #endif return RETURN_OK; diff --git a/stm32h7/networking/UdpTcLwIpPollingTask.h b/stm32h7/networking/UdpTcLwIpPollingTask.h index 9262399..0440650 100644 --- a/stm32h7/networking/UdpTcLwIpPollingTask.h +++ b/stm32h7/networking/UdpTcLwIpPollingTask.h @@ -5,6 +5,8 @@ #include #include +#include + class TmTcLwIpUdpBridge; /** @@ -16,7 +18,7 @@ class UdpTcLwIpPollingTask: public ExecutableObjectIF, public HasReturnvaluesIF { public: - UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId); + UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, struct netif* gnetif); virtual ~UdpTcLwIpPollingTask(); virtual ReturnValue_t initialize() override; @@ -32,6 +34,7 @@ private: uint8_t periodicHandleCounter; object_id_t bridgeId = 0; TmTcLwIpUdpBridge* udpBridge = nullptr; + struct netif* gnetif = nullptr; }; diff --git a/stm32h7/networking/app_dhcp.c b/stm32h7/networking/app_dhcp.cpp similarity index 94% rename from stm32h7/networking/app_dhcp.c rename to stm32h7/networking/app_dhcp.cpp index 7c990ad..9b2faa6 100644 --- a/stm32h7/networking/app_dhcp.c +++ b/stm32h7/networking/app_dhcp.cpp @@ -1,15 +1,14 @@ -#include "app_dhcp.h" -#include "app_ethernet.h" #include "OBSWConfig.h" -#include "example_common/stm32h7/networking/udp_config.h" -#include "example_common/stm32h7/networking/ethernetif.h" +#include "app_dhcp.h" +#include "app_ethernet.h" +#include "networking.h" +#include "udp_config.h" +#include "ethernetif.h" #include "lwip/dhcp.h" #include "stm32h7xx_nucleo.h" -#include - #if LWIP_DHCP == 1 uint8_t DHCP_state = DHCP_OFF; @@ -59,7 +58,7 @@ void handle_dhcp_timeout(struct netif* netif) { dhcp_stop(netif); /* Static address used */ - set_lwip_addresses(&ipaddr, &netmask, &gw); + networking::setLwipAddresses(&ipaddr, &netmask, &gw); netif_set_addr(netif, &ipaddr, &netmask, &gw); printf("DHCP Timeout\n\r"); @@ -67,8 +66,10 @@ void handle_dhcp_timeout(struct netif* netif) { sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); printf("Assigning static IP address: %s\n", iptxt); +#if defined FSFW_OSAL_FREERTOS ETH_HandleTypeDef* handle = getEthernetHandle(); handle->gState = HAL_ETH_STATE_READY; +#endif #if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1 @@ -142,7 +143,7 @@ void handle_dhcp_down(struct netif* netif) { #endif /* Global boolean to track ethernet connection */ - set_eth_cable_connected(false); + networking::setEthCableConnected(false); } uint8_t get_dhcp_state() { diff --git a/stm32h7/networking/app_ethernet.c b/stm32h7/networking/app_ethernet.c index b1de345..a359e78 100644 --- a/stm32h7/networking/app_ethernet.c +++ b/stm32h7/networking/app_ethernet.c @@ -42,14 +42,6 @@ void ethernet_link_status_updated(struct netif *netif) } } -void set_lwip_addresses(ip_addr_t* ipaddr, ip_addr_t* netmask, ip_addr_t* gw) { - IP4_ADDR(ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); - IP4_ADDR(netmask, NETMASK_ADDR0, NETMASK_ADDR1 , - NETMASK_ADDR2, NETMASK_ADDR3); - IP4_ADDR(gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); -} - - void handle_status_change(struct netif* netif, bool link_up) { if(link_up) { #if LWIP_DHCP diff --git a/stm32h7/networking/networking.cpp b/stm32h7/networking/networking.cpp new file mode 100644 index 0000000..ad3e90b --- /dev/null +++ b/stm32h7/networking/networking.cpp @@ -0,0 +1,19 @@ +#include "udp_config.h" +#include "networking.h" + +bool ethernetCableConnected = false; + +void networking::setEthCableConnected(bool status) { + ethernetCableConnected = status; +} + +bool networking::getEthCableConnected() { + return ethernetCableConnected; +} + +void networking::setLwipAddresses(ip_addr_t* ipaddr, ip_addr_t* netmask, ip_addr_t* gw) { + IP4_ADDR(ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); + IP4_ADDR(netmask, NETMASK_ADDR0, NETMASK_ADDR1 , + NETMASK_ADDR2, NETMASK_ADDR3); + IP4_ADDR(gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); +} diff --git a/stm32h7/networking/networking.h b/stm32h7/networking/networking.h new file mode 100644 index 0000000..5bb0745 --- /dev/null +++ b/stm32h7/networking/networking.h @@ -0,0 +1,14 @@ +#ifndef BSP_STM32H7_RTEMS_NETWORKING_NETWORKING_H_ +#define BSP_STM32H7_RTEMS_NETWORKING_NETWORKING_H_ + +#include + +namespace networking { + +void setEthCableConnected(bool status); +bool getEthCableConnected(); +void setLwipAddresses(ip_addr_t* ipaddr, ip_addr_t* netmask, ip_addr_t* gw); + +} + +#endif /* BSP_STM32H7_RTEMS_NETWORKING_NETWORKING_H_ */