Fix: Remove static CRC table duplication in MAVLink helpers - #11825
Fix: Remove static CRC table duplication in MAVLink helpers#11825sensei-hacker wants to merge 2 commits into
Conversation
mavlink_helpers.h defines every helper (and the ~3.7 KB mavlink_message_crcs[] table inside mavlink_get_msg_entry()) with internal linkage via the MAVLINK_HELPER macro, so each TU that includes the MAVLink headers compiles its own private copy. BLUEBERRYF405 carried two copies of the table (2 x 4,044 B = 8,088 B) before this change. Define MAVLINK_SEPARATE_HELPERS in the two INAV headers that pull in storm32/mavlink.h so protocol.h emits only extern prototypes, and compile the helper definitions exactly once in a new mavlink/mavlink_helpers.c. Uses the vendored library's own documented mechanism, so no lib/ edits and the fix survives generate.sh regeneration. Measured on BLUEBERRYF405: mavlink_message_crcs 2 copies -> 1, flash 667,416 -> 661,336 B (-6,080 B), RAM 122,884 -> 122,500 B (-384 B). mavlink_unittest: 96/96 tests pass.
Add #ifndef guards around the MAVLINK_SEPARATE_HELPERS and MAVLINK_COMM_NUM_BUFFERS defines in the two wrapper headers and mavlink_helpers.c, and trim the helpers comment to current-state rationale (no pre-change history).
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoDeduplicate MAVLink helper definitions and CRC table
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding |
|
RAM / Flash usage vs. base branch — commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #11825 246 targets built. Find your board's
|
Summary
Removes duplicated static data in the MAVLink helper functions.
mavlink_helpers.hdefines every helper — and themavlink_message_crcs[]table insidemavlink_get_msg_entry()— with internal (static) linkage via theMAVLINK_HELPERmacro, so every TU that includes the MAVLink headers compiles its own private copy of the functions and of the ~3.7 KB CRC table. A plain grep for"static inline"misses this because the macro hides thestatickeyword from the call site.Changes
MAVLINK_SEPARATE_HELPERSin the two INAV headers that includestorm32/mavlink.h(src/main/rx/mavlink.h,src/main/mavlink/mavlink_types.h), so the vendoredprotocol.hemits only extern prototypes (its own documented mechanism,#ifdef MAVLINK_SEPARATE_HELPERSblock).src/main/mavlink/mavlink_helpers.c— a single translation unit that compiles all helper definitions once with external linkage.src/main/CMakeLists.txtand themavlink_unittest.ccbuild (viaextra_sources, since the unit-test helper requires a sibling.hfordependsentries and this file's header is the vendored one).No
lib/files are touched, so the fix survivesgenerate.shregeneration.Testing
arm-none-eabi-nm --size-sort -S -C):mavlink_message_crcs.0+.1, 2 × 4,044 B = 8,088 B duplicatedmavlink_unittest— 96/96 pass.Notes
protocol.hSEPARATE_HELPERS prototype block declares 13 of 22 non-convenience helpers; the other 9 (mavlink_get_channel_buffer,mavlink_sign_packet,mavlink_get_crc_extra, etc.) are referenced only withinmavlink_helpers.hitself, so no implicit declarations occur. Verified: no INAV source or test calls them.m_mavlink_status[], per-channel buffers) becomes globally shared instead of per-TU — no observable INAV change (onlymavlink_runtime.cparses MAVLink), and the RAM delta is consistent with exactly two live copies before.