From bf77a7f1c5fa34b19acb69d9ed10bd88c96a2aa1 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Tue, 13 Oct 2026 03:24:07 +0200 Subject: [PATCH] lldp: time the transmit interval from the system tick lldp_tick counted main-loop passes, so the 6000 meant for 30 s at SYS_TICK_HZ ran at whatever rate the loop happened to have, and the interval moved with httpd and SFP load. Step once per second from the tick counter like the STP timers do, count seconds to the interval and derive the TTL from it with the 802.1AB hold multiplier of 4. --- rtl837x_lldp.c | 19 ++++++++++++------- rtl837x_lldp.h | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/rtl837x_lldp.c b/rtl837x_lldp.c index 84208433..eed26cab 100644 --- a/rtl837x_lldp.c +++ b/rtl837x_lldp.c @@ -13,24 +13,29 @@ extern __xdata bool lldp_enabled; extern __code const struct machine machine; -__xdata uint16_t lldp_ticks; +extern volatile __xdata uint32_t ticks; + +__xdata uint8_t lldp_tick_last; +__xdata uint8_t lldp_seconds; __xdata uint16_t lldp_logical_port_status = 0xffff; void lldp_init(void) __banked { - lldp_ticks = 0; + lldp_tick_last = (uint8_t)ticks; + lldp_seconds = 0; } void lldp_tick(void) __banked { - lldp_ticks++; - - if (lldp_ticks < LLDP_TX_INTERVAL_TICKS) + if (!TICKS_DUE(lldp_tick_last, SYS_TICK_HZ)) return; + lldp_tick_last += SYS_TICK_HZ; - lldp_ticks = 0; + if (++lldp_seconds < LLDP_TX_INTERVAL_S) + return; + lldp_seconds = 0; - if(lldp_enabled == 1) + if (lldp_enabled) lldp_send(); } diff --git a/rtl837x_lldp.h b/rtl837x_lldp.h index 0e6ee674..fd2c5aa3 100644 --- a/rtl837x_lldp.h +++ b/rtl837x_lldp.h @@ -7,7 +7,8 @@ #define LLDP_ETHERTYPE 0x88cc #define LLDP_ETHERTYPE_LENGTH 2 #define LLDP_MAX_FRAME 256 -#define LLDP_TX_INTERVAL_TICKS 6000 +#define LLDP_TX_INTERVAL_S 30 +#define LLDP_HOLD_MULTIPLIER 4 #define LLDP_PORT_ID_TLV_TYPE 2 #define LLDP_PORT_ID_TLV_LENGTH 0x02 @@ -15,7 +16,7 @@ #define LLDP_TTL_TLV_TYPE 3 #define LLDP_TTL_TLV_LENGTH 2 -#define LLDP_TTL_TTL_SECONDS 120 +#define LLDP_TTL_TTL_SECONDS (LLDP_HOLD_MULTIPLIER * LLDP_TX_INTERVAL_S) #define LLDP_CHASSIS_ID_TLV_TYPE 1 #define LLDP_CHASSIS_ID_TLV_LENGTH 7