From c564fa37fde467a0216c041bb81eeed7343ac505 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 29 May 2022 18:41:33 +0200 Subject: [PATCH] common cmake files moved to example_common --- cmake/BuildType.cmake | 45 +++++++++++++++ cmake/common.cmake | 42 ++++++++++++++ config/commonConfig.h.in | 2 +- stm32h7/STM32TestTask.cpp | 2 +- stm32h7/networking/TmTcLwIpUdpBridge.cpp | 13 ++--- stm32h7/networking/TmTcLwIpUdpBridge.h | 8 +-- stm32h7/networking/UdpTcLwIpPollingTask.cpp | 2 - stm32h7/networking/UdpTcLwIpPollingTask.h | 5 +- stm32h7/networking/ethernetif.c | 61 +++++++++++++++++++++ 9 files changed, 161 insertions(+), 19 deletions(-) create mode 100644 cmake/BuildType.cmake create mode 100644 cmake/common.cmake diff --git a/cmake/BuildType.cmake b/cmake/BuildType.cmake new file mode 100644 index 0000000..e078e5c --- /dev/null +++ b/cmake/BuildType.cmake @@ -0,0 +1,45 @@ +function(set_build_type) + +message(STATUS "Used build generator: ${CMAKE_GENERATOR}") + +# Set a default build type if none was specified +set(DEFAULT_BUILD_TYPE "RelWithDebInfo") +if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + set(DEFAULT_BUILD_TYPE "Debug") +endif() + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS + "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified." + ) + set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE + STRING "Choose the type of build." FORCE + ) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" + ) +endif() + +if(${CMAKE_BUILD_TYPE} MATCHES "Debug") + message(STATUS + "Building Debug application with flags: ${CMAKE_C_FLAGS_DEBUG}" + ) +elseif(${CMAKE_BUILD_TYPE} MATCHES "RelWithDebInfo") + message(STATUS + "Building Release (Debug) application with " + "flags: ${CMAKE_C_FLAGS_RELWITHDEBINFO}" + ) +elseif(${CMAKE_BUILD_TYPE} MATCHES "MinSizeRel") + message(STATUS + "Building Release (Size) application with " + "flags: ${CMAKE_C_FLAGS_MINSIZEREL}" + ) +else() + message(STATUS + "Building Release (Speed) application with " + "flags: ${CMAKE_C_FLAGS_RELEASE}" + ) +endif() + +endfunction() diff --git a/cmake/common.cmake b/cmake/common.cmake new file mode 100644 index 0000000..cb2a530 --- /dev/null +++ b/cmake/common.cmake @@ -0,0 +1,42 @@ +function(get_common_build_flags TGT_NAME) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(COMMON_COMPILE_OPTS + -ffunction-sections + -fdata-sections + PARENT_SCOPE) + set(COMMON_LINK_OPTS + -Wl,--gc-sections + -Wl,-Map=${TARGET_NAME}.map + PARENT_SCOPE) + set(COMMON_WARNING_FLAGS + -Wall + -Wextra + -Wimplicit-fallthrough=1 + -Wno-unused-parameter + -Wno-psabi + -Wduplicated-cond # check for duplicate conditions + -Wduplicated-branches # check for duplicate branches + -Wlogical-op # Search for bitwise operations instead of logical + -Wnull-dereference # Search for NULL dereference + -Wundef # Warn if undefind marcos are used + -Wformat=2 # Format string problem detection + -Wformat-overflow=2 # Formatting issues in printf + -Wformat-truncation=2 # Formatting issues in printf + -Wformat-security # Search for dangerous printf operations + -Wstrict-overflow=3 # Warn if integer overflows might happen + -Warray-bounds=2 # Some array bounds violations will be found + -Wshift-overflow=2 # Search for bit left shift overflows ( + #include #include #include #include "app_ethernet.h" -#include "ethernetif.h" #include "udp_config.h" TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId, @@ -56,7 +55,7 @@ ReturnValue_t TmTcLwIpUdpBridge::udp_server_init() { ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) { TmTcBridge::performOperation(); -#if TCPIP_RECV_WIRETAPPING == 1 +#if OBSW_TCPIP_UDP_WIRETAPPING == 1 if (connectFlag) { uint32_t ipAddress = ((ip4_addr *)&lastAdd)->addr; int ipAddress1 = (ipAddress & 0xFF000000) >> 24; @@ -90,7 +89,7 @@ ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { if ((p_tx != nullptr) && (lastAdd.addr != IPADDR_TYPE_ANY) && (upcb != nullptr)) { /* copy data to pbuf */ - err_t err = pbuf_take(p_tx, (char *)data, dataLen); + err_t err = pbuf_take(p_tx, (const char *)data, dataLen); if (err != ERR_OK) { pbuf_free(p_tx); return err; @@ -143,7 +142,7 @@ void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg, udpBridge->lastPort = port; if (not udpBridge->comLinkUp()) { udpBridge->registerCommConnect(); -#if TCPIP_RECV_WIRETAPPING == 1 +#if OBSW_TCPIP_UDP_WIRETAPPING == 1 udpBridge->connectFlag = true; #endif /* This should have already been done, but we will still do it */ @@ -155,8 +154,8 @@ void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg, char *data = reinterpret_cast(p_tx->payload); *(data + p_tx->len) = '\0'; -#if TCPIP_RECV_WIRETAPPING == 1 - udpBridge->printData(p, data); +#if OBSW_TCPIP_UDP_WIRETAPPING == 1 + udpBridge->printData(reinterpret_cast(p->payload), p->len); #endif store_address_t storeId; diff --git a/stm32h7/networking/TmTcLwIpUdpBridge.h b/stm32h7/networking/TmTcLwIpUdpBridge.h index ce849ff..61e80cc 100644 --- a/stm32h7/networking/TmTcLwIpUdpBridge.h +++ b/stm32h7/networking/TmTcLwIpUdpBridge.h @@ -1,12 +1,12 @@ #ifndef BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_ #define BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_ -#include +#include "fsfw/tmtcservices/TmTcBridge.h" +#include "commonConfig.h" + #include #include -#define TCPIP_RECV_WIRETAPPING 0 - /** * This bridge is used to forward TMTC packets received via LwIP UDP to the * internal software bus. @@ -63,7 +63,7 @@ private: bool physicalConnection = false; MutexIF *bridgeLock = nullptr; -#if TCPIP_RECV_WIRETAPPING == 1 +#if OBSW_TCPIP_UDP_WIRETAPPING == 1 bool connectFlag = false; #endif diff --git a/stm32h7/networking/UdpTcLwIpPollingTask.cpp b/stm32h7/networking/UdpTcLwIpPollingTask.cpp index 1730b8e..9b426f8 100644 --- a/stm32h7/networking/UdpTcLwIpPollingTask.cpp +++ b/stm32h7/networking/UdpTcLwIpPollingTask.cpp @@ -1,7 +1,5 @@ #include "UdpTcLwIpPollingTask.h" -#include - #include "TmTcLwIpUdpBridge.h" #include "app_dhcp.h" #include "app_ethernet.h" diff --git a/stm32h7/networking/UdpTcLwIpPollingTask.h b/stm32h7/networking/UdpTcLwIpPollingTask.h index 4090a24..40f688e 100644 --- a/stm32h7/networking/UdpTcLwIpPollingTask.h +++ b/stm32h7/networking/UdpTcLwIpPollingTask.h @@ -1,5 +1,4 @@ -#ifndef BSP_STM32_RTEMS_EMACPOLLINGTASK_H_ -#define BSP_STM32_RTEMS_EMACPOLLINGTASK_H_ +#pragma once #include #include @@ -36,5 +35,3 @@ private: TmTcLwIpUdpBridge *udpBridge = nullptr; struct netif *gnetif = nullptr; }; - -#endif /* BSP_STM32_RTEMS_EMACPOLLINGTASK_H_ */ diff --git a/stm32h7/networking/ethernetif.c b/stm32h7/networking/ethernetif.c index 9260062..38f21dc 100644 --- a/stm32h7/networking/ethernetif.c +++ b/stm32h7/networking/ethernetif.c @@ -597,6 +597,67 @@ void ethernet_link_check_state(struct netif *netif) { } } +void HAL_ETH_RxAllocateCallback(uint8_t **buff) +{ + struct pbuf_custom *p = LWIP_MEMPOOL_ALLOC(RX_POOL); + if (p) + { + /* Get the buff from the struct pbuf address. */ + *buff = (uint8_t *)p + offsetof(RxBuff_t, buff); + p->custom_free_function = pbuf_free_custom; + /* Initialize the struct pbuf. + * This must be performed whenever a buffer's allocated because it may be + * changed by lwIP or the app, e.g., pbuf_free decrements ref. */ + pbuf_alloced_custom(PBUF_RAW, 0, PBUF_REF, p, *buff, ETH_RX_BUFFER_SIZE); + } + else + { + RxAllocStatus = RX_ALLOC_ERROR; + *buff = NULL; + } +} + +void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t Length) +{ + struct pbuf **ppStart = (struct pbuf **)pStart; + struct pbuf **ppEnd = (struct pbuf **)pEnd; + struct pbuf *p = NULL; + + /* Get the struct pbuf from the buff address. */ + p = (struct pbuf *)(buff - offsetof(RxBuff_t, buff)); + p->next = NULL; + p->tot_len = 0; + p->len = Length; + + /* Chain the buffer. */ + if (!*ppStart) + { + /* The first buffer of the packet. */ + *ppStart = p; + } + else + { + /* Chain the buffer to the end of the packet. */ + (*ppEnd)->next = p; + } + *ppEnd = p; + + /* Update the total length of all the buffers of the chain. Each pbuf in the chain should have its tot_len + * set to its own length, plus the length of all the following pbufs in the chain. */ + for (p = *ppStart; p != NULL; p = p->next) + { + p->tot_len += Length; + } + + /* Invalidate data cache because Rx DMA's writing to physical memory makes it stale. */ + SCB_InvalidateDCache_by_Addr((uint32_t *)buff, Length); +} + +void HAL_ETH_TxFreeCallback(uint32_t * buff) +{ + pbuf_free((struct pbuf *)buff); +} + ETH_HandleTypeDef *getEthernetHandle() { return &EthHandle; } /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/