Skip to content

Commit d414c59

Browse files
committed
Very prelim multi-channel GPT cores0/1
1 parent 8fbf20d commit d414c59

11 files changed

Lines changed: 263 additions & 28 deletions

File tree

ref_app/ref_app.vcxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,14 @@
14011401
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
14021402
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
14031403
</ClCompile>
1404+
<ClCompile Include="src\mcal\xtensa_esp32_p4\mcal_gpt.cpp">
1405+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
1406+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
1407+
</ClCompile>
1408+
<ClCompile Include="src\mcal\xtensa_esp32_p4\mcal_wdg.cpp">
1409+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
1410+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
1411+
</ClCompile>
14041412
<ClCompile Include="src\mcal\xtensa_esp32_s3\mcal_cpu.cpp">
14051413
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
14061414
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
@@ -3233,10 +3241,18 @@
32333241
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
32343242
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
32353243
</ClInclude>
3244+
<ClInclude Include="src\mcal\xtensa_esp32_p4\mcal_gpt.h">
3245+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
3246+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
3247+
</ClInclude>
32363248
<ClInclude Include="src\mcal\xtensa_esp32_p4\mcal_reg.h">
32373249
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
32383250
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
32393251
</ClInclude>
3252+
<ClInclude Include="src\mcal\xtensa_esp32_p4\mcal_wdg.h">
3253+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
3254+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
3255+
</ClInclude>
32403256
<ClInclude Include="src\mcal\xtensa_esp32_s3\mcal_benchmark.h">
32413257
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
32423258
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>

ref_app/ref_app.vcxproj.filters

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,12 @@
13721372
<ClCompile Include="src\mcal\r7fa4m1ab\mcal_spi.cpp">
13731373
<Filter>src\mcal\r7fa4m1ab</Filter>
13741374
</ClCompile>
1375+
<ClCompile Include="src\mcal\xtensa_esp32_p4\mcal_gpt.cpp">
1376+
<Filter>src\mcal\xtensa_esp32_p4</Filter>
1377+
</ClCompile>
1378+
<ClCompile Include="src\mcal\xtensa_esp32_p4\mcal_wdg.cpp">
1379+
<Filter>src\mcal\xtensa_esp32_p4</Filter>
1380+
</ClCompile>
13751381
</ItemGroup>
13761382
<ItemGroup>
13771383
<ClInclude Include="src\math\calculus\derivative.h">
@@ -3126,6 +3132,12 @@
31263132
<ClInclude Include="src\mcal\xtensa_esp32_p4\mcal_reg.h">
31273133
<Filter>src\mcal\xtensa_esp32_p4</Filter>
31283134
</ClInclude>
3135+
<ClInclude Include="src\mcal\xtensa_esp32_p4\mcal_gpt.h">
3136+
<Filter>src\mcal\xtensa_esp32_p4</Filter>
3137+
</ClInclude>
3138+
<ClInclude Include="src\mcal\xtensa_esp32_p4\mcal_wdg.h">
3139+
<Filter>src\mcal\xtensa_esp32_p4</Filter>
3140+
</ClInclude>
31293141
</ItemGroup>
31303142
<ItemGroup>
31313143
<None Include="src\util\STL\algorithm">
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 2022 - 2026.
3+
// Distributed under the Boost Software License,
4+
// Version 1.0. (See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
8+
#include <mcal_gpt.h>
9+
#include <mcal_reg.h>
10+
11+
#include <util/utility/util_two_part_data_manipulation.h>
12+
13+
#include <interrupt.h>
14+
15+
#include <cstddef>
16+
#include <cstdint>
17+
#include <limits>
18+
#include <type_traits>
19+
20+
extern "C"
21+
{
22+
uint32_t osGetActiveCore(void);
23+
}
24+
25+
namespace
26+
{
27+
constexpr unsigned TIMEOUT_1S { 320000000u };
28+
}
29+
30+
void mcal::gpt::init(const config_type*)
31+
{
32+
// Set the MTIME timeout.
33+
CLINT_MTIMECMP = (uint64_t) UINT64_C(0xFFFFFFFFFFFFFFFF);
34+
}
35+
36+
mcal::gpt::value_type mcal::gpt::secure::get_time_elapsed()
37+
{
38+
const std::uint64_t tick_unscaled_01 = (uint64_t) CLINT_MTIME;
39+
const std::uint64_t tick_unscaled_02 = (uint64_t) CLINT_MTIME;
40+
41+
const std::uint64_t tick_unscaled =
42+
(uint64_t) (((uint32_t) tick_unscaled_02 > (uint32_t) tick_unscaled_01) ? tick_unscaled_01 : (uint64_t) CLINT_MTIME);
43+
44+
return (std::uint64_t) ((std::uint64_t) (tick_unscaled + 160U) / 320U);
45+
}
46+
47+
mcal::gpt::value_type mcal::gpt::secure::get_time_elapsed_core1()
48+
{
49+
const std::uint64_t tick_unscaled_01 = (uint64_t) CLINT_MTIME;
50+
const std::uint64_t tick_unscaled_02 = (uint64_t) CLINT_MTIME;
51+
52+
const std::uint64_t tick_unscaled =
53+
(uint64_t) (((uint32_t) tick_unscaled_02 > (uint32_t) tick_unscaled_01) ? tick_unscaled_01 : (uint64_t) CLINT_MTIME);
54+
55+
return (std::uint64_t) ((std::uint64_t) (tick_unscaled + 160U) / 320U);
56+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 2007 - 2025.
3+
// Distributed under the Boost Software License,
4+
// Version 1.0. (See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
8+
#ifndef MCAL_GPT_2022_12_16_H
9+
#define MCAL_GPT_2022_12_16_H
10+
11+
#include <cstdint>
12+
13+
namespace mcal
14+
{
15+
namespace gpt
16+
{
17+
using config_type = void;
18+
using value_type = std::uint64_t;
19+
20+
auto init(const config_type*) -> void;
21+
22+
struct secure final
23+
{
24+
static auto get_time_elapsed() -> value_type;
25+
static auto get_time_elapsed_core1() -> value_type;
26+
};
27+
28+
struct timer_core1_backend
29+
{
30+
using tick_type = std::uint64_t;
31+
32+
static auto get_now() -> tick_type { return static_cast<tick_type>(mcal::gpt::secure::get_time_elapsed_core1()); }
33+
};
34+
}
35+
}
36+
37+
#endif // MCAL_GPT_2022_12_16_H

ref_app/src/mcal/xtensa_esp32_p4/mcal_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{
1515
namespace reg
1616
{
17-
constexpr std::uint32_t clint_base { UINT32_C(0x02000000) };
17+
constexpr std::uint32_t clint_base { UINT32_C(0x20000000) };
1818
constexpr std::uint32_t clint_mtime { clint_base + static_cast<std::uint32_t>(UINT32_C(0x0000BFF8)) };
1919
constexpr std::uint32_t clint_mtimeh { clint_base + static_cast<std::uint32_t>(UINT32_C(0x0000BFFC)) };
2020
constexpr std::uint32_t clint_mtimecmp { clint_base + static_cast<std::uint32_t>(UINT32_C(0x00004000)) };
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 2007 - 2020.
3+
// Distributed under the Boost Software License,
4+
// Version 1.0. (See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
8+
#include <mcal_reg.h>
9+
#include <mcal_wdg.h>
10+
11+
void mcal::wdg::init(const config_type*)
12+
{
13+
}
14+
15+
void mcal::wdg::secure::trigger()
16+
{
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 2007 - 2025.
3+
// Distributed under the Boost Software License,
4+
// Version 1.0. (See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
8+
#ifndef MCAL_WDG_2010_04_10_H
9+
#define MCAL_WDG_2010_04_10_H
10+
11+
namespace mcal
12+
{
13+
namespace wdg
14+
{
15+
using config_type = void;
16+
17+
auto init(const config_type*) -> void;
18+
19+
struct secure final
20+
{
21+
static auto trigger() -> void;
22+
};
23+
}
24+
}
25+
26+
#endif // MCAL_WDG_2010_04_10_H

ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,34 @@ SECTIONS
5454
.text : ALIGN(4)
5555
{
5656
PROVIDE(__CODE_BASE_ADDRESS = .);
57+
. = ALIGN(4);
5758
*(.boot)
59+
. = ALIGN(4);
60+
*(.progmem*)
61+
. = ALIGN(4);
5862
*(.text)
63+
. = ALIGN(4);
5964
*(.text*)
6065
. = ALIGN(4);
66+
*(.glue_7)
67+
. = ALIGN(4);
68+
*(.glue_7t)
69+
. = ALIGN(4);
70+
. = ALIGN(4);
6171
} > FLASH
6272

6373
/* Read-only data (.rodata) */
6474
.rodata : ALIGN(4)
6575
{
6676
PROVIDE(__RODATA_BASE_ADDRESS = .);
77+
. = ALIGN(4);
6778
*(.rodata)
79+
. = ALIGN(4);
6880
*(.rodata*)
81+
. = ALIGN(4);
82+
*(.srodata)
83+
. = ALIGN(4);
84+
*(.srodata*)
6985
} > FLASH
7086

7187
/* Section for constructors */
@@ -114,6 +130,29 @@ SECTIONS
114130
PROVIDE(__CODE_END_ADDRESS = .);
115131
} > FLASH
116132

133+
.riscv.extab :
134+
{
135+
. = ALIGN(4);
136+
*(.riscv.extab)
137+
*(.gnu.linkonce.riscvextab.*)
138+
. = ALIGN(4);
139+
} > FLASH
140+
141+
.exidx :
142+
{
143+
. = ALIGN(4);
144+
PROVIDE(__exidx_start = .);
145+
*(.riscv.exidx*)
146+
. = ALIGN(4);
147+
PROVIDE(__exidx_end = .);
148+
} > FLASH
149+
150+
.riscv.attributes : ALIGN(4)
151+
{
152+
*(.riscv.attributes)
153+
. = ALIGN(4);
154+
} > FLASH
155+
117156
/* The ROM-to-RAM initialized data sections */
118157
.data : ALIGN(4)
119158
{
@@ -130,6 +169,9 @@ SECTIONS
130169
. = ALIGN(4);
131170
} > RAM
132171

172+
PROVIDE(end = .);
173+
PROVIDE(_fini = .);
174+
133175
/* stack definition */
134176
.stack_core0 :
135177
{
@@ -149,5 +191,4 @@ SECTIONS
149191

150192
/* ROM APIs */
151193
printf = 0x4fc00024;
152-
153194
}

ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_files.gmk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright Christopher Kormanyos 2025.
2+
# Copyright Christopher Kormanyos 2025 - 2026.
33
# Distributed under the Boost Software License,
44
# Version 1.0. (See accompanying file LICENSE_1_0.txt
55
# or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -11,7 +11,9 @@
1111

1212
FILES_CPP :=
1313

14-
FILES_TGT := $(PATH_TGT)/startup/Code/Appli/main \
14+
FILES_TGT := $(PATH_APP)/mcal/$(TGT)/mcal_gpt \
15+
$(PATH_APP)/mcal/$(TGT)/mcal_wdg \
16+
$(PATH_TGT)/startup/Code/Appli/main \
1517
$(PATH_TGT)/startup/Code/Mcal/gpio \
1618
$(PATH_TGT)/startup/Code/Startup/boot \
1719
$(PATH_TGT)/startup/Code/Startup/intvect \

0 commit comments

Comments
 (0)