Merge branch 'mueller/master' of https://egit.irs.uni-stuttgart.de/fsfw/fsfw-example-common into mueller/master

This commit is contained in:
Robin Müller 2021-08-02 15:54:02 +02:00
commit 19a8ba7640
15 changed files with 102 additions and 55 deletions

View File

@ -7,6 +7,6 @@ target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
if(TGT_BSP MATCHES "arm/stm32h743zi-nucleo") if(TGT_BSP MATCHES "arm/stm32h743zi-nucleo")
add_subdirectory(stm32h7) add_subdirectory(stm32h7)
endif() endif()

View File

@ -11,6 +11,9 @@
#define OBSW_PRINT_MISSED_DEADLINES 0 #define OBSW_PRINT_MISSED_DEADLINES 0
//! Perform internal unit testd at application startup
#define OBSW_PERFORM_INTERNAL_UNITTEST 1
//! Add core components for the FSFW and for TMTC communication //! Add core components for the FSFW and for TMTC communication
#define OBSW_ADD_CORE_COMPONENTS 1 #define OBSW_ADD_CORE_COMPONENTS 1

View File

@ -5,6 +5,7 @@
#include "tmtc/pusIds.h" #include "tmtc/pusIds.h"
#include "objects/systemObjectList.h" #include "objects/systemObjectList.h"
#include "fsfw/tests/internal/InternalUnitTester.h"
#include "test/FsfwExampleTask.h" #include "test/FsfwExampleTask.h"
#include "test/FsfwReaderTask.h" #include "test/FsfwReaderTask.h"
@ -116,6 +117,13 @@ void ObjectFactory::produceGenericObjects() {
new TestController(objects::TEST_CONTROLLER); new TestController(objects::TEST_CONTROLLER);
#endif /* OBSW_ADD_CONTROLLER_DEMO == 1 */ #endif /* OBSW_ADD_CONTROLLER_DEMO == 1 */
#if OBSW_PERFORM_INTERNAL_UNITTEST == 1
InternalUnitTester::TestConfig testCfg;
testCfg.testArrayPrinter = false;
InternalUnitTester unittester;
unittester.performTests(testCfg);
#endif /* OBSW_PERFORM_INTERNAL_UNITTEST == 1 */
} }
void Factory::setStaticFrameworkObjectIds() { void Factory::setStaticFrameworkObjectIds() {

View File

@ -2,7 +2,7 @@ target_sources(${TARGET_NAME} PRIVATE
STM32TestTask.cpp 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) if(STM32_ADD_NETWORKING_CODE)
add_subdirectory(networking) add_subdirectory(networking)

View File

@ -5,6 +5,9 @@
STM32TestTask::STM32TestTask(object_id_t objectId, bool enablePrintout, STM32TestTask::STM32TestTask(object_id_t objectId, bool enablePrintout,
bool blinkyLed): TestTask(objectId, enablePrintout), bool blinkyLed): TestTask(objectId, enablePrintout),
blinkyLed(blinkyLed) { blinkyLed(blinkyLed) {
BSP_LED_Init(LED1);
BSP_LED_Init(LED2);
BSP_LED_Init(LED3);
} }
ReturnValue_t STM32TestTask::performPeriodicAction() { ReturnValue_t STM32TestTask::performPeriodicAction() {

View File

@ -1,7 +1,14 @@
# These are part of the RTEMS BSP for RTEMS
if(FSFW_OSAL MATCHES freertos)
target_sources(${TARGET_NAME} PRIVATE
ethernetif.c
)
endif()
target_sources(${TARGET_NAME} PRIVATE target_sources(${TARGET_NAME} PRIVATE
app_dhcp.c
app_ethernet.c
ethernetif.c
UdpTcLwIpPollingTask.cpp UdpTcLwIpPollingTask.cpp
TmTcLwIpUdpBridge.cpp TmTcLwIpUdpBridge.cpp
networking.cpp
app_dhcp.cpp
app_ethernet.cpp
) )

View File

@ -3,16 +3,20 @@
#include "app_ethernet.h" #include "app_ethernet.h"
#include "ethernetif.h" #include "ethernetif.h"
#include "app_dhcp.h" #include "app_dhcp.h"
#include "networking.h"
#include <hardware_init.h> #include <hardware_init.h>
#include "fsfw/ipc/MutexGuard.h" #include "fsfw/ipc/MutexGuard.h"
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/objectmanager/ObjectManager.h"
#include "lwip/timeouts.h" #include "lwip/timeouts.h"
UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId): UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId,
SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId) { struct netif* gnetif):
SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), gnetif(gnetif) {
} }
UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() { UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() {
@ -23,8 +27,8 @@ ReturnValue_t UdpTcLwIpPollingTask::initialize() {
if(udpBridge == nullptr) { if(udpBridge == nullptr) {
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
if (netif_is_link_up(&gnetif)) { if (netif_is_link_up(gnetif)) {
set_eth_cable_connected(true); networking::setEthCableConnected(true);
} }
return RETURN_OK; return RETURN_OK;
} }
@ -34,28 +38,28 @@ ReturnValue_t UdpTcLwIpPollingTask::initialize() {
ReturnValue_t UdpTcLwIpPollingTask::performOperation(uint8_t operationCode) { ReturnValue_t UdpTcLwIpPollingTask::performOperation(uint8_t operationCode) {
/* Read a received packet from the Ethernet buffers and send it /* Read a received packet from the Ethernet buffers and send it
to the lwIP for handling */ to the lwIP for handling */
ethernetif_input(&gnetif); ethernetif_input(gnetif);
/* Handle timeouts */ /* Handle timeouts */
sys_check_timeouts(); sys_check_timeouts();
#if LWIP_NETIF_LINK_CALLBACK == 1 #if LWIP_NETIF_LINK_CALLBACK == 1
ethernet_link_periodic_handle(&gnetif); networking::ethernetLinkPeriodicHandle(gnetif);
#endif #endif
if(udpBridge != nullptr) { if(udpBridge != nullptr) {
MutexGuard lg(udpBridge->bridgeLock); MutexGuard lg(udpBridge->bridgeLock);
/* In case ethernet cable is disconnected */ /* 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); udpBridge->physicalConnectStatusChange(false);
} }
else if(get_eth_cable_connected() and not udpBridge->comLinkUp()) { else if(networking::getEthCableConnected() and not udpBridge->comLinkUp()) {
udpBridge->physicalConnectStatusChange(true); udpBridge->physicalConnectStatusChange(true);
} }
} }
#if LWIP_DHCP == 1 #if LWIP_DHCP == 1
DHCP_Periodic_Handle(&gnetif); DHCP_Periodic_Handle(gnetif);
#endif #endif
return RETURN_OK; return RETURN_OK;

View File

@ -5,6 +5,8 @@
#include <fsfw/tasks/ExecutableObjectIF.h> #include <fsfw/tasks/ExecutableObjectIF.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <lwip/netif.h>
class TmTcLwIpUdpBridge; class TmTcLwIpUdpBridge;
/** /**
@ -16,7 +18,7 @@ class UdpTcLwIpPollingTask:
public ExecutableObjectIF, public ExecutableObjectIF,
public HasReturnvaluesIF { public HasReturnvaluesIF {
public: 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 ~UdpTcLwIpPollingTask();
virtual ReturnValue_t initialize() override; virtual ReturnValue_t initialize() override;
@ -32,6 +34,7 @@ private:
uint8_t periodicHandleCounter; uint8_t periodicHandleCounter;
object_id_t bridgeId = 0; object_id_t bridgeId = 0;
TmTcLwIpUdpBridge* udpBridge = nullptr; TmTcLwIpUdpBridge* udpBridge = nullptr;
struct netif* gnetif = nullptr;
}; };

View File

@ -1,15 +1,14 @@
#include "app_dhcp.h"
#include "app_ethernet.h"
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "example_common/stm32h7/networking/udp_config.h" #include "app_dhcp.h"
#include "example_common/stm32h7/networking/ethernetif.h" #include "app_ethernet.h"
#include "networking.h"
#include "udp_config.h"
#include "ethernetif.h"
#include "lwip/dhcp.h" #include "lwip/dhcp.h"
#include "stm32h7xx_nucleo.h" #include "stm32h7xx_nucleo.h"
#include <stdbool.h>
#if LWIP_DHCP == 1 #if LWIP_DHCP == 1
uint8_t DHCP_state = DHCP_OFF; uint8_t DHCP_state = DHCP_OFF;
@ -59,7 +58,7 @@ void handle_dhcp_timeout(struct netif* netif) {
dhcp_stop(netif); dhcp_stop(netif);
/* Static address used */ /* Static address used */
set_lwip_addresses(&ipaddr, &netmask, &gw); networking::setLwipAddresses(&ipaddr, &netmask, &gw);
netif_set_addr(netif, &ipaddr, &netmask, &gw); netif_set_addr(netif, &ipaddr, &netmask, &gw);
printf("DHCP Timeout\n\r"); 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))); sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif)));
printf("Assigning static IP address: %s\n", iptxt); printf("Assigning static IP address: %s\n", iptxt);
#if defined FSFW_OSAL_FREERTOS
ETH_HandleTypeDef* handle = getEthernetHandle(); ETH_HandleTypeDef* handle = getEthernetHandle();
handle->gState = HAL_ETH_STATE_READY; handle->gState = HAL_ETH_STATE_READY;
#endif
#if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_TMTC_COMMANDING == 1
#if OBSW_ETHERNET_USE_LED1_LED2 == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1
@ -142,7 +143,7 @@ void handle_dhcp_down(struct netif* netif) {
#endif #endif
/* Global boolean to track ethernet connection */ /* Global boolean to track ethernet connection */
set_eth_cable_connected(false); networking::setEthCableConnected(false);
} }
uint8_t get_dhcp_state() { uint8_t get_dhcp_state() {

View File

@ -2,6 +2,7 @@
#include "app_ethernet.h" #include "app_ethernet.h"
#include "ethernetif.h" #include "ethernetif.h"
#include "udp_config.h" #include "udp_config.h"
#include "networking.h"
#if LWIP_DHCP #if LWIP_DHCP
#include "app_dhcp.h" #include "app_dhcp.h"
@ -28,28 +29,20 @@ void handle_status_change(struct netif* netif, bool link_up);
* @param netif: the network interface * @param netif: the network interface
* @retval None * @retval None
*/ */
void ethernet_link_status_updated(struct netif *netif) void networking::ethernetLinkStatusUpdated(struct netif *netif)
{ {
if (netif_is_link_up(netif)) if (netif_is_link_up(netif))
{ {
set_eth_cable_connected(true); networking::setEthCableConnected(true);
handle_status_change(netif, true); handle_status_change(netif, true);
} }
else else
{ {
set_eth_cable_connected(false); networking::setEthCableConnected(false);
handle_status_change(netif, false); handle_status_change(netif, false);
} }
} }
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) { void handle_status_change(struct netif* netif, bool link_up) {
if(link_up) { if(link_up) {
#if LWIP_DHCP #if LWIP_DHCP
@ -87,7 +80,7 @@ void handle_status_change(struct netif* netif, bool link_up) {
* @param netif * @param netif
* @retval None * @retval None
*/ */
void ethernet_link_periodic_handle(struct netif *netif) void networking::ethernetLinkPeriodicHandle(struct netif *netif)
{ {
/* Ethernet Link every 100ms */ /* Ethernet Link every 100ms */
if (HAL_GetTick() - ethernetLinkTimer >= 100) if (HAL_GetTick() - ethernetLinkTimer >= 100)

View File

@ -44,8 +44,8 @@
*/ */
/* Define to prevent recursive inclusion -------------------------------------*/ /* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __APP_ETHERNET_H #ifndef EXAMPLE_COMMON_APP_ETHERNET_H
#define __APP_ETHERNET_H #define EXAMPLE_COMMON_APP_ETHERNET_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -53,23 +53,25 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include <lwip/netif.h> #include <lwip/netif.h>
#include <stdbool.h>
/* Exported types ------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */
void ethernet_link_status_updated(struct netif *netif); namespace networking {
void ethernet_link_periodic_handle(struct netif *netif);
void set_lwip_addresses(ip_addr_t* ipaddr, ip_addr_t* netmask, ip_addr_t* gw); void ethernetLinkStatusUpdated(struct netif *netif);
void ethernetLinkPeriodicHandle(struct netif *netif);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __APP_ETHERNET_H */ #endif /* EXAMPLE_COMMON_APP_ETHERNET_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -54,7 +54,7 @@
#include <lwip/timeouts.h> #include <lwip/timeouts.h>
#include <netif/etharp.h> #include <netif/etharp.h>
#ifdef FSFW_RTEMS #ifdef FSFW_OSAL_RTEMS
#include <rtems.h> #include <rtems.h>
#endif #endif
@ -103,14 +103,14 @@ __attribute__((section(".RxArraySection"))) uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH
#elif defined ( __GNUC__ ) /* GNU Compiler */ #elif defined ( __GNUC__ ) /* GNU Compiler */
#ifdef FSFW_RTEMS #ifdef FSFW_OSAL_RTEMS
/* Put into special RTEMS section and align correctly */ /* Put into special RTEMS section and align correctly */
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".bsp_nocache"), __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Rx DMA Descriptors */ ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".bsp_nocache"), __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Rx DMA Descriptors */
/* Put into special RTEMS section and align correctly */ /* Put into special RTEMS section and align correctly */
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".bsp_nocache"), __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Tx DMA Descriptors */ ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".bsp_nocache"), __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Tx DMA Descriptors */
/* Ethernet Receive Buffers. Just place somewhere is BSS instead of explicitely placing it */ /* Ethernet Receive Buffers. Just place somewhere is BSS instead of explicitely placing it */
uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE];
#elif defined(FSFW_FREERTOS) #elif defined FSFW_OSAL_FREERTOS
/* Placement and alignment specified in linker script here */ /* Placement and alignment specified in linker script here */
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */ ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".TxDecripSection"))); /* Ethernet Tx DMA Descriptors */ ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".TxDecripSection"))); /* Ethernet Tx DMA Descriptors */
@ -610,12 +610,4 @@ ETH_HandleTypeDef* getEthernetHandle() {
return &EthHandle; return &EthHandle;
} }
void set_eth_cable_connected(bool status) {
ethernet_cable_connected = status;
}
bool get_eth_cable_connected() {
return ethernet_cable_connected;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -58,8 +58,6 @@ extern "C" {
#define ETH_RX_BUFFER_SIZE (1536UL) #define ETH_RX_BUFFER_SIZE (1536UL)
/* Exported types ------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/
void set_eth_cable_connected(bool status);
bool get_eth_cable_connected();
ETH_HandleTypeDef* getEthernetHandle(); ETH_HandleTypeDef* getEthernetHandle();
err_t ethernetif_init(struct netif *netif); err_t ethernetif_init(struct netif *netif);

View File

@ -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);
}

View File

@ -0,0 +1,14 @@
#ifndef BSP_STM32H7_RTEMS_NETWORKING_NETWORKING_H_
#define BSP_STM32H7_RTEMS_NETWORKING_NETWORKING_H_
#include <lwip/netif.h>
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_ */