From c0d9bf7f0d137d9bc1d5e4a0cd68722642fe51e5 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Mon, 31 Aug 2026 21:50:19 +0200 Subject: [PATCH] stp: take the review notes on types and register reads stp_enabled is a flag, so say bool. cmpBytes() returns a comparison result, so say int8_t. The three busy waits this branch adds read the status straight out of the SFR instead of copying four bytes to xdata first. --- cmd_parser.c | 2 +- rtl837x_common.h | 2 +- rtl837x_port.c | 12 ++++++------ rtl837x_stp.c | 2 +- rtlplayground.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd_parser.c b/cmd_parser.c index bf266b2..0f94b58 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -26,7 +26,7 @@ #pragma constseg BANK2 extern __code struct machine machine; -extern __xdata uint8_t stp_enabled; +extern __xdata bool stp_enabled; extern __code uint8_t log_to_phys_port[9]; extern volatile __xdata uint32_t ticks; diff --git a/rtl837x_common.h b/rtl837x_common.h index 923d02a..77a31b1 100644 --- a/rtl837x_common.h +++ b/rtl837x_common.h @@ -119,7 +119,7 @@ struct flash_region_t { extern __xdata char port_names[9][PORT_NAME_SIZE]; -extern __xdata uint8_t stp_enabled; +extern __xdata bool stp_enabled; /* System hostname (device identity). Set via `hostname ` and the System * Settings page, reported in /information.json. Other modules (e.g. LLDP, which diff --git a/rtl837x_port.c b/rtl837x_port.c index b357e58..8eea5a3 100644 --- a/rtl837x_port.c +++ b/rtl837x_port.c @@ -323,8 +323,8 @@ void port_l2_forget_port(uint8_t port) __banked REG_SET(RTL837x_L2_TBL_FLUSH_CTRL, L2_TBL_FLUSH_EXEC | (((uint16_t)1) << port)); do { - reg_read_m(RTL837x_L2_TBL_FLUSH_CTRL); - } while (sfr_data[1]); + reg_read(RTL837x_L2_TBL_FLUSH_CTRL); + } while (SFR_DATA_16); } @@ -421,16 +421,16 @@ void port_l2_learned(void) __banked void port_l2mc_set(uint8_t mac_last, __xdata uint16_t vid, __xdata uint16_t pmask) __banked { do { - reg_read_m(RTL837X_TBL_CTRL); - } while (sfr_data[3] & TBL_EXECUTE); + reg_read(RTL837X_TBL_CTRL); + } while (SFR_DATA_0 & TBL_EXECUTE); REG_WRITE(RTL837x_TBL_DATA_IN_A, 0xc2, 0x00, 0x00, mac_last); REG_WRITE(RTL837x_TBL_DATA_IN_B, 0x20 | (vid >> 8) | ((pmask & 0x3) << 6), vid, 0x01, 0x80); REG_WRITE(RTL837x_TBL_DATA_IN_C, 0, 0, 0, pmask >> 2); REG_WRITE(RTL837X_TBL_CTRL, 0, 0, TBL_L2_UNICAST, TBL_WRITE | TBL_EXECUTE); do { - reg_read_m(RTL837X_TBL_CTRL); - } while (sfr_data[3] & TBL_EXECUTE); + reg_read(RTL837X_TBL_CTRL); + } while (SFR_DATA_0 & TBL_EXECUTE); } diff --git a/rtl837x_stp.c b/rtl837x_stp.c index cc4e916..83d351c 100644 --- a/rtl837x_stp.c +++ b/rtl837x_stp.c @@ -254,7 +254,7 @@ static void stp_record_designated(uint8_t port) __reentrant /* Lexicographic compare of n bytes. A MAC is 6 of them; a Bridge Identifier * is 8, the two priority octets ahead of the MAC, compared as one unsigned * number per 802.1D. */ -signed char cmpBytes(__xdata uint8_t *m1, __xdata uint8_t *m2, uint8_t n) __reentrant +int8_t cmpBytes(__xdata uint8_t *m1, __xdata uint8_t *m2, uint8_t n) __reentrant { for (uint8_t i = 0; i < n; i++) { if (m1[i] == m2[i]) diff --git a/rtlplayground.c b/rtlplayground.c index 23e93fa..a853e42 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -121,7 +121,7 @@ __xdata uint16_t management_vlan; __xdata bool frame_tagged; __xdata uint8_t tx_seq; -__xdata uint8_t stp_enabled; +__xdata bool stp_enabled; __xdata uint8_t igmpEnabled; __xdata char hostname[24]; /* device hostname, default set at boot, see rtl837x_common.h */