From 74bac35b2fa3b6bc0aedaeedf8abf605d0b79f2d Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sun, 30 Mar 2025 14:04:09 +0200 Subject: [PATCH] Clean up even more syntax --- ref_app/src/mcal/mcal_gpt_arm_sys_tick.h | 15 +++++----- ref_app/src/mcal/xtensa_esp32_s3/mcal_cpu.cpp | 4 +-- ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.cpp | 6 ++-- ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.h | 8 ++--- .../mcal/xtensa_esp32_s3_riscv_cop/mcal_gpt.h | 11 ------- ref_app/target.vcxproj | 4 --- ref_app/target.vcxproj.filters | 4 --- .../make/xtensa_esp32_s3_riscv_cop_flags.gmk | 29 +++++++++++++------ .../startup/main.cpp | 5 +++- 9 files changed, 39 insertions(+), 47 deletions(-) diff --git a/ref_app/src/mcal/mcal_gpt_arm_sys_tick.h b/ref_app/src/mcal/mcal_gpt_arm_sys_tick.h index 5811995b6..65620803d 100644 --- a/ref_app/src/mcal/mcal_gpt_arm_sys_tick.h +++ b/ref_app/src/mcal/mcal_gpt_arm_sys_tick.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2022 - 2024. +// Copyright Christopher Kormanyos 2022 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,6 +8,7 @@ #ifndef MCAL_GPT_ARM_SYS_TICK_2022_11_30_H #define MCAL_GPT_ARM_SYS_TICK_2022_11_30_H + #include #include #include @@ -48,10 +49,10 @@ template - class arm_sys_tick : private arm_sys_tick_base + class arm_sys_tick : private arm_sys_tick_base { private: - using base_class_type = arm_sys_tick_base; + using base_class_type = arm_sys_tick_base; using register_address_type = typename base_class_type::register_address_type; using register_value_type = typename base_class_type::register_value_type; @@ -112,8 +113,8 @@ // Return the system tick using a multiple read to ensure data consistency. // Do the first read of the sys-tick counter and the sys-tick - // value. Handle reverse counting for sys-tick counter, which is - // counting down. + // value. Also handle reverse counting for the sys-tick counter, + // since this timer counts down. const auto sys_tick_counter_1 = static_cast @@ -128,8 +129,8 @@ const value_type sys_tick_value { my_sys_tick_value }; // Do the second read of the sys-tick counter and the sys-tick - // value. Handle reverse counting for sys-tick counter, which is - // counting down. + // value. Also handle reverse counting for the sys-tick counter, + // since this timer counts down. const auto sys_tick_counter_2 = static_cast diff --git a/ref_app/src/mcal/xtensa_esp32_s3/mcal_cpu.cpp b/ref_app/src/mcal/xtensa_esp32_s3/mcal_cpu.cpp index 45b611675..2046b6f50 100644 --- a/ref_app/src/mcal/xtensa_esp32_s3/mcal_cpu.cpp +++ b/ref_app/src/mcal/xtensa_esp32_s3/mcal_cpu.cpp @@ -117,7 +117,7 @@ auto main_c1() -> void // by the core1 branch of the subroutine _start(). // Set the private cpu timer1 for core1. - set_cpu_private_timer1(mcal::gpt::timer1_reload()); + set_cpu_private_timer1(mcal::gpt::detail::timer1_reload()); // Enable all interrupts on core1. mcal::irq::init(nullptr); @@ -133,7 +133,7 @@ auto mcal::cpu::post_init() noexcept -> void // Note: This subroutine is called from core0. // Set the private cpu timer1 for core0. - set_cpu_private_timer1(mcal::gpt::timer1_reload()); + set_cpu_private_timer1(mcal::gpt::detail::timer1_reload()); // Use core0 to start the RISC-V core. Mcu_StartCoProcessorRiscV(); diff --git a/ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.cpp b/ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.cpp index 662d2c513..6fa8c5bb7 100644 --- a/ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.cpp +++ b/ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.cpp @@ -54,14 +54,14 @@ namespace extern "C" void __system_tick_handler() { // Reload the private timer1 for the running core. - set_cpu_private_timer1(mcal::gpt::timer1_reload()); + set_cpu_private_timer1(mcal::gpt::detail::timer1_reload()); const bool is_not_core0 { (get_core_id() != std::uint32_t { UINT8_C(0) }) }; // Toggle the LED (on core1) or increment the 64-bit system tick (on core0). if(is_not_core0) { mcal::led::led1().toggle(); } - else { system_tick += mcal::gpt::timer1_max(); } + else { system_tick += mcal::gpt::detail::timer1_max(); } } auto mcal::gpt::init(const config_type*) -> void @@ -79,7 +79,7 @@ auto mcal::gpt::secure::get_time_elapsed() -> mcal::gpt::value_type if(gpt_is_initialized()) { - constexpr std::uint32_t mhz_value { (mcal::gpt::timer1_max() / UINT32_C(1000000)) }; + constexpr std::uint32_t mhz_value { (mcal::gpt::detail::timer1_max() / UINT32_C(1000000)) }; result = get_consistent_tick() / mhz_value; } diff --git a/ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.h b/ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.h index af04a27d3..050668d4e 100644 --- a/ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.h +++ b/ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.h @@ -11,8 +11,6 @@ #include #include - #include - // Forward declaration of the util::timer template class. namespace util { @@ -26,13 +24,10 @@ { namespace detail { - constexpr inline auto timer1_max () noexcept -> std::uint32_t { return UINT32_C(80000000); } + constexpr inline auto timer1_max () noexcept -> std::uint32_t { return UINT32_C(80'000'000); } constexpr inline auto timer1_reload() noexcept -> std::uint32_t { return timer1_max() - UINT32_C(1); } } - using detail::timer1_max; - using detail::timer1_reload; - using config_type = void; using value_type = std::uint64_t; @@ -40,6 +35,7 @@ struct secure final { + private: static auto get_time_elapsed() -> value_type; friend auto std::chrono::high_resolution_clock::now() noexcept -> std::chrono::high_resolution_clock::time_point; diff --git a/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_gpt.h b/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_gpt.h index af04a27d3..049ba66b4 100644 --- a/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_gpt.h +++ b/ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_gpt.h @@ -11,8 +11,6 @@ #include #include - #include - // Forward declaration of the util::timer template class. namespace util { @@ -24,15 +22,6 @@ { namespace gpt { - namespace detail - { - constexpr inline auto timer1_max () noexcept -> std::uint32_t { return UINT32_C(80000000); } - constexpr inline auto timer1_reload() noexcept -> std::uint32_t { return timer1_max() - UINT32_C(1); } - } - - using detail::timer1_max; - using detail::timer1_reload; - using config_type = void; using value_type = std::uint64_t; diff --git a/ref_app/target.vcxproj b/ref_app/target.vcxproj index 3f386c04a..d8558f7ae 100644 --- a/ref_app/target.vcxproj +++ b/ref_app/target.vcxproj @@ -1151,10 +1151,6 @@ - - - - diff --git a/ref_app/target.vcxproj.filters b/ref_app/target.vcxproj.filters index 0828673fd..94e2ca635 100644 --- a/ref_app/target.vcxproj.filters +++ b/ref_app/target.vcxproj.filters @@ -992,10 +992,6 @@ micros\xtensa_esp32_s3\startup\Std - - - - micros\xtensa_esp32_s3_riscv_cop\startup diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop_flags.gmk b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop_flags.gmk index 146a36ab0..e156b8e32 100644 --- a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop_flags.gmk +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/make/xtensa_esp32_s3_riscv_cop_flags.gmk @@ -13,7 +13,7 @@ GCC_PREFIX := riscv-none-elf GCC_VERSION := 14.2.0 -TGT_SUFFIX = elf +TGT_SUFFIX := elf WARN_FLAGS := @@ -42,7 +42,6 @@ TGT_AFLAGS = $(TGT_ALLFLAGS) TGT_LDFLAGS = -nostdlib \ -nostartfiles \ - -flto \ -e _start \ -Wl,-Map,$(APP).map \ -T $(LINKER_DEFINITION_FILE) \ @@ -79,17 +78,29 @@ $(PATH_OBJ)/%.o : %.S # ------------------------------------------------------------------------------ ifeq ($(TYP_OS),WIN) -OBJCOPY := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-objcopy.exe +OBJCOPY := $(PATH_TOOLS_CC)\$(GCC_PREFIX)-objcopy.exe else -OBJCOPY := $(GCC_PREFIX)-objcopy +OBJCOPY := $(GCC_PREFIX)-objcopy endif -PYTHON := python +PYTHON := python + +BIN2ASM_FLAGS := -s ".coprocessor" \ + -l 16 \ + -g coprocessor_bin + + +RULE_SPECIAL_MAKE_IMAGE_FILE_PART00 := $(ECHO) +++ creating binary $(APP).bin RULE_SPECIAL_MAKE_IMAGE_FILE_PART01 := $(OBJCOPY) $(APP).$(TGT_SUFFIX) -O binary $(APP).bin -RULE_SPECIAL_MAKE_IMAGE_FILE_PART02 := $(PYTHON) $(PATH_TGT)/startup/Scripts/bin2asm.py -i $(APP).bin -o $(PATH_BIN)/coprocessor_binary.S -s ".coprocessor" -l 16 -g coprocessor_bin -RULE_SPECIAL_MAKE_IMAGE_FILE_PART03 := $(PYTHON) $(PATH_TGT)/startup/Scripts/bin2asm.py -i $(APP).bin -o $(PATH_TGT)/../xtensa_esp32_s3/startup/coprocessor_binary.S -s ".coprocessor" -l 16 -g coprocessor_bin +RULE_SPECIAL_MAKE_IMAGE_FILE_PART02 := $(ECHO) +++ creating assembly image as byte-array source file $(PATH_BIN)/coprocessor_binary.S +RULE_SPECIAL_MAKE_IMAGE_FILE_PART03 := $(PYTHON) $(PATH_TGT)/startup/Scripts/bin2asm.py -i $(APP).bin -o $(PATH_BIN)/coprocessor_binary.S $(BIN2ASM_FLAGS) +RULE_SPECIAL_MAKE_IMAGE_FILE_PART04 := $(ECHO) +++ creating assembly image as byte-array source file for xtensa_esp32_s3/startup/coprocessor_binary.S +RULE_SPECIAL_MAKE_IMAGE_FILE_PART05 := $(PYTHON) $(PATH_TGT)/startup/Scripts/bin2asm.py -i $(APP).bin -o $(PATH_TGT)/../xtensa_esp32_s3/startup/coprocessor_binary.S $(BIN2ASM_FLAGS) -RULE_SPECIAL_MAKE_IMAGE_FILE := $(RULE_SPECIAL_MAKE_IMAGE_FILE_PART01) \ +RULE_SPECIAL_MAKE_IMAGE_FILE := $(RULE_SPECIAL_MAKE_IMAGE_FILE_PART00) \ + && $(RULE_SPECIAL_MAKE_IMAGE_FILE_PART01) \ && $(RULE_SPECIAL_MAKE_IMAGE_FILE_PART02) \ - && $(RULE_SPECIAL_MAKE_IMAGE_FILE_PART03) + && $(RULE_SPECIAL_MAKE_IMAGE_FILE_PART03) \ + && $(RULE_SPECIAL_MAKE_IMAGE_FILE_PART04) \ + && $(RULE_SPECIAL_MAKE_IMAGE_FILE_PART05) diff --git a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/main.cpp b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/main.cpp index f2f42b351..6998f27db 100644 --- a/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/main.cpp +++ b/ref_app/target/micros/xtensa_esp32_s3_riscv_cop/startup/main.cpp @@ -81,7 +81,10 @@ extern "C" auto main() -> int my_pwm.set_duty(duty_table[duty_index]); - for(unsigned srv_idx { UINT8_C(0) }; srv_idx < unsigned { UINT16_C(16411) }; ++srv_idx) + // Table[Prime[n], {n, 1900, 1905, 1}] + // {16381, 16411, 16417, 16421, 16427, 16433} + + for(unsigned srv_idx { UINT8_C(0) }; srv_idx < unsigned { UINT16_C(16'411) }; ++srv_idx) { my_pwm.service(); }