Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions ref_app/src/mcal/mcal_gpt_arm_sys_tick.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 <cstddef>
#include <cstdint>
#include <limits>

Expand Down Expand Up @@ -48,10 +49,10 @@

template<const std::uint32_t SysTickMHz,
typename ValueType = std::uint64_t>
class arm_sys_tick : private arm_sys_tick_base<SysTickMHz, ValueType, std::uint32_t, std::uint32_t>
class arm_sys_tick : private arm_sys_tick_base<SysTickMHz, ValueType, std::uintptr_t, std::uint32_t>
{
private:
using base_class_type = arm_sys_tick_base<SysTickMHz, ValueType, std::uint32_t, std::uint32_t>;
using base_class_type = arm_sys_tick_base<SysTickMHz, ValueType, std::uintptr_t, std::uint32_t>;

using register_address_type = typename base_class_type::register_address_type;
using register_value_type = typename base_class_type::register_value_type;
Expand Down Expand Up @@ -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<register_value_type>
Expand All @@ -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<register_value_type>
Expand Down
4 changes: 2 additions & 2 deletions ref_app/src/mcal/xtensa_esp32_s3/mcal_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
8 changes: 2 additions & 6 deletions ref_app/src/mcal/xtensa_esp32_s3/mcal_gpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <chrono>
#include <cstdint>

#include <mcal/mcal_gpt_arm_sys_tick.h>

// Forward declaration of the util::timer template class.
namespace util
{
Expand All @@ -26,20 +24,18 @@
{
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;

auto init(const config_type*) -> void;

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;
Expand Down
11 changes: 0 additions & 11 deletions ref_app/src/mcal/xtensa_esp32_s3_riscv_cop/mcal_gpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <chrono>
#include <cstdint>

#include <mcal/mcal_gpt_arm_sys_tick.h>

// Forward declaration of the util::timer template class.
namespace util
{
Expand All @@ -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;

Expand Down
4 changes: 0 additions & 4 deletions ref_app/target.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1151,10 +1151,6 @@
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\crt0.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\crt0_init_ram.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\crt1.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Appli\main.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup\crt0.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup\crt0_init_ram.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup\crt1.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\main.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions ref_app/target.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,6 @@
<ClCompile Include="target\micros\xtensa_esp32_s3\startup\Std\StdLib.cpp">
<Filter>micros\xtensa_esp32_s3\startup\Std</Filter>
</ClCompile>
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Appli\main.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup\crt0.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup\crt0_init_ram.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\from_no_sdk\Code\Startup\crt1.cpp" />
<ClCompile Include="target\micros\xtensa_esp32_s3_riscv_cop\startup\crt0_init_ram.cpp">
<Filter>micros\xtensa_esp32_s3_riscv_cop\startup</Filter>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GCC_PREFIX := riscv-none-elf

GCC_VERSION := 14.2.0

TGT_SUFFIX = elf
TGT_SUFFIX := elf

WARN_FLAGS :=

Expand Down Expand Up @@ -42,7 +42,6 @@ TGT_AFLAGS = $(TGT_ALLFLAGS)

TGT_LDFLAGS = -nostdlib \
-nostartfiles \
-flto \
-e _start \
-Wl,-Map,$(APP).map \
-T $(LINKER_DEFINITION_FILE) \
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down