mirror of
https://github.com/halleysfifthinc/AVCLAN-Mockingboard.git
synced 2026-08-07 01:13:18 +00:00
Decouple hardware specific code from generic, agnostic code
This commit is contained in:
+22
-121
@@ -1,67 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
include(CMakeDependentOption)
|
||||
|
||||
set(WITH_MCU OFF) # Disable target name modification setting from toolchain
|
||||
set(AVR_MCU "attiny3216")
|
||||
set(AVR_PROGRAMMER serialupdi)
|
||||
set(AVR_UPLOADTOOL_BAUDRATE 230400)
|
||||
|
||||
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/avr-gcc-toolchain.cmake")
|
||||
|
||||
project(avclan-mockingboard VERSION 1 LANGUAGES C CXX ASM)
|
||||
|
||||
set(FREQSEL 16MHz CACHE STRING "Select the operating frequency")
|
||||
set_property(CACHE FREQSEL PROPERTY STRINGS "20MHz" "16MHz")
|
||||
|
||||
if(FREQSEL MATCHES "20MHz")
|
||||
set(FREQSEL 20000000L)
|
||||
set(AVR_UPLOADTOOL_BASE_OPTIONS ${AVR_UPLOADTOOL_BASE_OPTIONS} -U osccfg:w:0x2:m)
|
||||
else()
|
||||
set(FREQSEL 16000000L)
|
||||
set(AVR_UPLOADTOOL_BASE_OPTIONS ${AVR_UPLOADTOOL_BASE_OPTIONS} -U osccfg:w:0x1:m)
|
||||
endif()
|
||||
|
||||
# Set startup time to 8 ms (0x4)
|
||||
set(AVR_UPLOADTOOL_BASE_OPTIONS ${AVR_UPLOADTOOL_BASE_OPTIONS} -U syscfg1:w:0x4:m)
|
||||
|
||||
option(CLK_PRESCALE "Enable the main clock prescaler")
|
||||
cmake_dependent_option(CLK_PRESCALE_DIV "Prescaler divisor" CLKCTRL_PDIV_2X_gc STRING "CLK_PRESCALE")
|
||||
if(DEFINED CACHE{CLK_PRESCALE_DIV})
|
||||
set_property(CACHE CLK_PRESCALE_DIV PROPERTY STRINGS
|
||||
CLKCTRL_PDIV_2X_gc
|
||||
CLKCTRL_PDIV_4X_gc
|
||||
CLKCTRL_PDIV_8X_gc
|
||||
CLKCTRL_PDIV_16X_gc
|
||||
CLKCTRL_PDIV_32X_gc
|
||||
CLKCTRL_PDIV_64X_gc
|
||||
CLKCTRL_PDIV_6X_gc
|
||||
CLKCTRL_PDIV_10X_gc
|
||||
CLKCTRL_PDIV_12X_gc
|
||||
CLKCTRL_PDIV_24X_gc
|
||||
CLKCTRL_PDIV_48X_gc
|
||||
)
|
||||
else()
|
||||
set(CLK_PRESCALE_DIV CLKCTRL_PDIV_2X_gc)
|
||||
endif()
|
||||
|
||||
set(TCB_CLKSEL "TCB_CLKSEL_CLKDIV2_gc" CACHE STRING "Choose the clock for TCB")
|
||||
set_property(CACHE TCB_CLKSEL PROPERTY STRINGS
|
||||
TCB_CLKSEL_CLKDIV1_gc
|
||||
TCB_CLKSEL_CLKDIV2_gc
|
||||
TCB_CLKSEL_CLKTCA_gc
|
||||
)
|
||||
|
||||
set(USART_RXMODE "USART_RXMODE_CLK2X_gc" CACHE STRING "USART at normal or double speed operation")
|
||||
set_property(CACHE USART_RXMODE PROPERTY STRINGS
|
||||
USART_RXMODE_CLK2X_gc
|
||||
USART_RXMODE_NORMAL_gc
|
||||
)
|
||||
|
||||
# Measured wall-clock duration (ms) of one nominal 32768-tick RTC period, used
|
||||
# to calibrate out the internal OSCULP32K's tolerance for the status-update
|
||||
# tick. 1000 = no correction; set per-board in CMakeUserPresets.json.
|
||||
set(RTC_STATUS_PERIOD_MS 1000 CACHE STRING "Measured ms per nominal RTC status period (1000 = no correction)")
|
||||
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
@@ -75,77 +15,38 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# The AVC-LAN stack as a (currently AVR-only) static library. Establishing this
|
||||
# boundary now sets up the planned HAL extraction + off-target protocol testing.
|
||||
add_avr_library(avclan
|
||||
src/avclan/avclan_phy.c
|
||||
# Hardware target (port) selection. The chosen target/<name>/ directory supplies
|
||||
# the port implementation sources, the per-target include path, and all
|
||||
# hardware-specific build configuration (compile defs/options, device-pack
|
||||
# handling, flashing) via its own CMakeLists, pulled in with add_subdirectory
|
||||
# below. The matching cross-compiler is selected separately by a toolchain file
|
||||
# (e.g. cmake/avr-gcc-toolchain.cmake) named in a CMake preset. Adding a new
|
||||
# board = a sibling target/ directory + a toolchain file + a preset wiring them.
|
||||
set(AVCLAN_TARGET avr-attiny3216 CACHE STRING "Hardware target (port) to build")
|
||||
|
||||
# The AVC-LAN stack as a static library: the target-agnostic generic core (no
|
||||
# <avr/...>, no register access). The selected target's port sources and flags
|
||||
# are contributed by its subdirectory.
|
||||
add_library(avclan STATIC
|
||||
src/avclan/avclan_frame.c
|
||||
src/avclan/avclan_protocol.c
|
||||
src/avclan/cdchanger.c
|
||||
src/avclan/mediacontrol.c
|
||||
src/avclan/statustimer.c)
|
||||
src/avclan/cdchanger.c)
|
||||
|
||||
add_avr_executable(mockingboard
|
||||
add_executable(mockingboard
|
||||
src/sniffer.c
|
||||
src/com232.c
|
||||
src/queue.c)
|
||||
|
||||
# avclan exports its public headers (src/avclan) to consumers, and reaches into
|
||||
# src/ for sibling driver headers (com232.h, timing.h) during its own build.
|
||||
# avclan exports its public generic headers (src/avclan) to consumers and
|
||||
# reaches into src/ for sibling headers (com232.h, board.h) during its own
|
||||
# build. The selected target adds its own per-target include path.
|
||||
target_include_directories(avclan
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/avclan
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
target_link_libraries(mockingboard avclan)
|
||||
|
||||
# Handle libc versioning
|
||||
try_compile(LIBC_VERSION_TEST
|
||||
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libc-version-test.cpp"
|
||||
COMPILE_DEFINITIONS -mmcu=${AVR_MCU}
|
||||
)
|
||||
|
||||
if(NOT LIBC_VERSION_TEST)
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
attiny_atpack
|
||||
URL http://packs.download.atmel.com/Atmel.ATtiny_DFP.2.0.368.atpack
|
||||
URL_HASH SHA512=ee16a8ebecb57bd998a9cd4373368e3d45982cbbc3825e18d1dcac58215db6b9d907ad1ba2020cba9187fed7ba8c6f255a4fa1214e40c7a17ab2d18474f4d079
|
||||
DOWNLOAD_NAME Atmel.ATtiny_DFP.2.0.368.atpack.zip
|
||||
)
|
||||
FetchContent_MakeAvailable(attiny_atpack)
|
||||
try_compile(LIBC_VERSION_TEST
|
||||
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/libc-version-test.cpp"
|
||||
COMPILE_DEFINITIONS
|
||||
-B "${attiny_atpack_SOURCE_DIR}/gcc/dev/${AVR_MCU}"
|
||||
-isystem "${attiny_atpack_SOURCE_DIR}/include"
|
||||
-mmcu=${AVR_MCU}
|
||||
)
|
||||
if(NOT LIBC_VERSION_TEST)
|
||||
message(FATAL_ERROR "Insufficient AVR-LIBC/Microchip pack for chosen MCU '${AVR_MCU}'")
|
||||
else()
|
||||
# PUBLIC on the library so its compile inherits the device headers and
|
||||
# the requirement propagates to mockingboard via linking.
|
||||
target_include_directories(avclan SYSTEM
|
||||
PUBLIC "${attiny_atpack_SOURCE_DIR}/include")
|
||||
target_link_options(mockingboard PUBLIC
|
||||
-B "${attiny_atpack_SOURCE_DIR}/gcc/dev/${AVR_MCU}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# PUBLIC on avclan so these reach both the library TUs and the executable TUs
|
||||
# (mockingboard inherits them by linking avclan).
|
||||
target_compile_definitions(avclan PUBLIC
|
||||
FREQSEL=${FREQSEL}
|
||||
CLK_PRESCALE=$<IF:$<BOOL:${CLK_PRESCALE}>,0x01,0x00>
|
||||
CLK_PRESCALE_DIV=${CLK_PRESCALE_DIV}
|
||||
__CLK_PRESCALE_DIV=__${CLK_PRESCALE_DIV}
|
||||
TCB_CLKSEL=${TCB_CLKSEL}
|
||||
USART_RXMODE=${USART_RXMODE}
|
||||
RTC_STATUS_PERIOD_MS=${RTC_STATUS_PERIOD_MS}
|
||||
)
|
||||
target_compile_options(avclan PUBLIC
|
||||
--param=min-pagesize=0
|
||||
-ffunction-sections
|
||||
-fdata-sections
|
||||
)
|
||||
# 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.
|
||||
add_subdirectory(src/avclan/target/${AVCLAN_TARGET})
|
||||
|
||||
Reference in New Issue
Block a user