diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cbb5a7..230f163 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,10 @@ add_compile_options( $<$:-fno-threadsafe-statics> $<$:-fno-exceptions> $<$:-fno-rtti> + # Debug must not be -O0: both the vendored usart.h and avr-libc's + # #warning when __OPTIMIZE__ is undefined, and -Werror makes + # that fatal. + $<$:-Og> $<$:-fanalyzer> $<$:-Wno-analyzer-use-of-uninitialized-value>) @@ -72,6 +76,25 @@ add_library(avclan STATIC target_include_directories(avclan PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/avclan) +add_executable(mockingboard + src/sniffer.cc +) +target_link_libraries(mockingboard avclan) + +# Report firmware section sizes on every build, when the toolchain provides a +# size tool (CMAKE_SIZE). A standalone custom target (rather than a POST_BUILD +# command on mockingboard) so it prints even when the link is up to date: +# custom targets with no output are always considered stale and re-run. +# add_dependencies orders it after the link. +if(CMAKE_SIZE) + add_custom_target(mockingboard-size ALL + COMMAND ${CMAKE_SIZE} $ + COMMENT "Section sizes: mockingboard firmware" + VERBATIM + ) + add_dependencies(mockingboard-size mockingboard) +endif() + # Pull in the selected hardware target: its port sources, per-target headers, # hardware-specific compile options/definitions, device-pack handling, and the # flashing target. Added after the targets above so it can extend them. @@ -145,9 +168,3 @@ endif() # INTERFACE ${tl_optional_SOURCE_DIR}/include) # target_link_libraries(avclan PUBLIC tl_optional_hdr) # endif() - -add_executable(mockingboard - src/sniffer.cc -) - -target_link_libraries(mockingboard avclan) diff --git a/CMakePresets.json b/CMakePresets.json index 9bc0ec6..5d61e71 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -22,7 +22,7 @@ "hidden": true, "description": "AVR ATtiny3216 cross-compile toolchain + matching port", "toolchainFile": "${sourceDir}/cmake/avr-gcc-toolchain.cmake", - "binaryDir": "${sourceDir}/out/build/attiny3216", + "binaryDir": "${sourceDir}/out/build/avr-attiny3216", "cacheVariables": { "AVCLAN_TARGET": "avr-attiny3216", "FREQSEL": "20MHz", @@ -34,8 +34,6 @@ "name": "debug-base", "hidden": true, "description": "Debug build settings", - "generator": "Unix Makefiles", - "binaryDir": "${sourceDir}/out/build", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } @@ -49,13 +47,30 @@ "CMAKE_BUILD_TYPE": "RelWithDebInfo" } }, + { + "name": "attiny3216-relwithdebinfo", + "hidden": true, + "description": "ATtiny3216 RelWithDebInfo build,", + "inherits": [ + "avr-attiny3216", + "relwithdebinfo-base" + ] + }, + { + "name": "attiny3216-debug", + "hidden": true, + "description": "ATtiny3216 Debug build", + "inherits": [ + "avr-attiny3216", + "debug-base" + ] + }, { "name": "attiny3216-relwithdebinfo-usb0", "displayName": "ATtiny3216 RelWithDebInfo (ttyUSB0)", "description": "ATtiny3216 RelWithDebInfo build, program over /dev/ttyUSB0", "inherits": [ - "avr-attiny3216", - "relwithdebinfo-base", + "attiny3216-relwithdebinfo", "usb0" ] }, @@ -64,8 +79,25 @@ "displayName": "ATtiny3216 RelWithDebInfo (ttyUSB1)", "description": "ATtiny3216 RelWithDebInfo build, program over /dev/ttyUSB1", "inherits": [ - "avr-attiny3216", - "relwithdebinfo-base", + "attiny3216-relwithdebinfo", + "usb1" + ] + }, + { + "name": "attiny3216-debug-usb0", + "displayName": "ATtiny3216 Debug (ttyUSB0)", + "description": "ATtiny3216 Debug build, program over /dev/ttyUSB0", + "inherits": [ + "attiny3216-debug", + "usb0" + ] + }, + { + "name": "attiny3216-debug-usb1", + "displayName": "ATtiny3216 Debug (ttyUSB1)", + "description": "ATtiny3216 Debug build, program over /dev/ttyUSB1", + "inherits": [ + "attiny3216-debug", "usb1" ] } diff --git a/cmake/avr-gcc-toolchain.cmake b/cmake/avr-gcc-toolchain.cmake index 80c21b0..049c8a5 100644 --- a/cmake/avr-gcc-toolchain.cmake +++ b/cmake/avr-gcc-toolchain.cmake @@ -13,6 +13,9 @@ ########################################################################## find_program(AVR_CC avr-gcc REQUIRED) find_program(AVR_CXX avr-g++ REQUIRED) +# Section-size reporter; consumed by an optional POST_BUILD in the top-level +# CMakeLists (left unset -> no size report) so the top level stays HW-agnostic. +find_program(CMAKE_SIZE avr-size) set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR avr) diff --git a/src/avclan/bus.cc b/src/avclan/bus.cc index aaa11c5..3ced901 100644 --- a/src/avclan/bus.cc +++ b/src/avclan/bus.cc @@ -423,7 +423,7 @@ auto Bus::send(const Frame &out, Frame::Print print) -> Send { Bus::Handle Bus::get() { return Handle{*this}; }; -#ifndef NDEBUG +#if !defined(NDEBUG) && defined(MEASURE_BUS) // Debug bit-timing measurement on the one physical bus; instance-scoped for the // same reason as is_active(). // NOLINTNEXTLINE(readability-convert-member-functions-to-static) diff --git a/src/avclan/hal/phy.h b/src/avclan/hal/phy.h index 4ee6741..a55c186 100644 --- a/src/avclan/hal/phy.h +++ b/src/avclan/hal/phy.h @@ -77,7 +77,7 @@ Bit phy_read_bits_u8(uint8_t *bits, uint8_t len); Bit phy_read_bits_u16(uint16_t *bits, int8_t len); Bit phy_read_byte(uint8_t *byte); -#ifndef NDEBUG +#if !defined(NDEBUG) && defined(MEASURE_BUS) // Sample and dump bus bit timing over the serial link (REPL `M`). void phy_measure(void); #endif diff --git a/src/avclan/target/avr-attiny3216/CMakeLists.txt b/src/avclan/target/avr-attiny3216/CMakeLists.txt index 204fc00..00e96cd 100644 --- a/src/avclan/target/avr-attiny3216/CMakeLists.txt +++ b/src/avclan/target/avr-attiny3216/CMakeLists.txt @@ -77,7 +77,7 @@ set_property(CACHE USART_RXMODE PROPERTY STRINGS set(RTC_STATUS_PERIOD_MS 1000 CACHE STRING "Measured ms per nominal RTC status period (1000 = no correction)") # --- Firmware configuration options ---------------------------------------- -set(AVCLAN_FRAME_POOL_N 32 CACHE STRING "Frame pool depth (pooled targets)") +set(AVCLAN_FRAME_POOL_N 24 CACHE STRING "Pool allocator capacity for avclan::Frame (must be <= incoming/outgoing queue size)") try_compile(LIBC_VERSION_TEST SOURCES "${CMAKE_SOURCE_DIR}/cmake/libc-version-test.cpp" diff --git a/src/sniffer.cc b/src/sniffer.cc index 1cb716b..2dfdf62 100644 --- a/src/sniffer.cc +++ b/src/sniffer.cc @@ -176,7 +176,9 @@ int main() { while (peripheral.device().media_busy()) {} puts("end"); break; + #ifdef MEASURE_BUS case 'M': peripheral.get_bus().measure(); break; + #endif #endif case 0x10: // Signals binary sequence incoming