From 30f3e890ba79484f5851fccd9ff607f9bc6fa271 Mon Sep 17 00:00:00 2001 From: Epagris Date: Mon, 10 Jun 2024 14:09:23 +0200 Subject: [PATCH] - signaling the same link state multiple times fixed - building as CMake library target added --- CMakeLists.txt | 27 ++++++++++++++++++++++++--- eth_interface.c | 27 ++++++++++++++------------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6bc336..6c97efa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,13 @@ -target_sources( - ${CMAKE_PROJECT_NAME} - PUBLIC +cmake_minimum_required(VERSION 3.15) +set(ETHERLIB_TARGET etherlib) + +if (ETHERLIB_TARGET_TAG) + set(ETHERLIB_TARGET "${ETHERLIB_TARGET}_${ETHERLIB_TARGET_TAG}") + message("Custom EtherLib target: ${ETHERLIB_TARGET}") +endif() + +set(ETHERLIB_SRC apps/http_server.c apps/http_server.h apps/ftp_server.c @@ -89,3 +95,18 @@ target_sources( utils.c utils.h ) + +add_library(${ETHERLIB_TARGET} STATIC ${ETHERLIB_SRC}) +target_include_directories(${ETHERLIB_TARGET} PRIVATE ${ETHERLIB_INCLUDES}) +target_compile_options(${ETHERLIB_TARGET} PRIVATE + ${ETHERLIB_CPU_PARAMS} + -Wall + -Wextra + #-Wpedantic + -Wno-unused-parameter + + $<$:-x assembler-with-cpp -MMD -MP> + $<$:-O0 -g3 -ggdb> + $<$:-Og -g0> +) +target_compile_definitions(${ETHERLIB_TARGET} PRIVATE ${ETHERLIB_COMPILE_DEFS}) \ No newline at end of file diff --git a/eth_interface.c b/eth_interface.c index 33e48f0..f4c9c70 100644 --- a/eth_interface.c +++ b/eth_interface.c @@ -97,8 +97,8 @@ static ThreadReturnType task_ethintf(ThreadParamType param) { mq_pop(intf->rxQ); // packet interception, if defined - if (intf->interceptCb != NULL) { - intf->interceptCb(intf, &rawPckt); + if (intf->interceptCb != NULL) { + intf->interceptCb(intf, &rawPckt); } // packet processing @@ -112,23 +112,24 @@ static ThreadReturnType task_ethintf(ThreadParamType param) { uint16_t speed = (event_data >> 2); bool prev_ls = ethinf_get_link_state(intf); // get previous link state - ethinf_set_link_state(intf, ls); // set new link state + ethinf_set_link_state(intf, ls); // set new link state if ((intf->dhcp != NULL) && (ls != prev_ls)) { // no double start! - if (ls) { // if link is on + if (ls) { // if link is on dhcp_start(intf->dhcp); } else { // if link is off dhcp_stop(intf->dhcp); } + + // print generic message + MSG("ETH LINK: %s%s", (ls ? (ANSI_COLOR_BGREEN "UP ") : (ANSI_COLOR_BRED "DOWN\n")), ANSI_COLOR_RESET); + + // print link properties + if (ls) { + MSG("(%u Mbps, %s duplex)\n", speed, duplex ? "FULL" : "HALF"); + } } - // print generic message - MSG("ETH LINK: %s%s", (ls ? (ANSI_COLOR_BGREEN "UP ") : (ANSI_COLOR_BRED "DOWN\n")), ANSI_COLOR_RESET); - - // print link properties - if (ls) { - MSG("(%u Mbps, %s duplex)\n", speed, duplex ? "FULL" : "HALF"); - } } break; case ETH_IIE_TRANSMIT_NOTIFY: { intf->ioDef->llTxTrigger(intf->ioDef, intf->txQ); @@ -156,7 +157,7 @@ void ethinf_transmit(EthInterface *intf, const RawPckt *rawPckt) { } // push packet onto the message queue - if (mq_push(intf->txQ, rawPckt)) { + if (mq_push(intf->txQ, rawPckt)) { ethinf_push_notification(intf, ETH_IIE_TRANSMIT_NOTIFY, 0); // notify processing thread of the peding transmit } else { ERROR("Interface TRANSMIT queue full, packet dropped!\n"); @@ -219,6 +220,6 @@ void ethinf_down(EthInterface *intf) { intf->up = false; } -void ethinf_set_intercept_callback(EthInterface * intf, EthIntfInterceptCb cb) { +void ethinf_set_intercept_callback(EthInterface *intf, EthIntfInterceptCb cb) { intf->interceptCb = cb; } \ No newline at end of file