Skip to content

Commit 6b10635

Browse files
committed
Initial support r7fa4m1ab via Chalandi arch
1 parent d0d49e6 commit 6b10635

25 files changed

Lines changed: 130630 additions & 2 deletions

.github/workflows/real-time-cpp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##############################################################################
2-
# Copyright Christopher Kormanyos 2021 - 2025.
2+
# Copyright Christopher Kormanyos 2021 - 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)
@@ -133,7 +133,7 @@ jobs:
133133
strategy:
134134
fail-fast: false
135135
matrix:
136-
suite: [ am335x, bcm2835_raspi_b, lpc11c24, nxp_imxrt1062, rpi_pico_rp2040, rpi_pico2_rp2350, stm32f100, stm32f407, stm32f429, stm32f446, stm32h7a3, stm32l100c, stm32l152, stm32l432 ]
136+
suite: [ am335x, bcm2835_raspi_b, lpc11c24, nxp_imxrt1062, r7fa4m1ab, rpi_pico_rp2040, rpi_pico2_rp2350, stm32f100, stm32f407, stm32f429, stm32f446, stm32h7a3, stm32l100c, stm32l152, stm32l432 ]
137137
steps:
138138
- uses: actions/checkout@v4
139139
with:

ref_app/ref_app.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Global
5555
target bl602_sifive_e24_riscv|x64 = target bl602_sifive_e24_riscv|x64
5656
target lpc11c24|x64 = target lpc11c24|x64
5757
target nxp_imxrt1062|x64 = target nxp_imxrt1062|x64
58+
target r7fa4m1ab|x64 = target r7fa4m1ab|x64
5859
target riscvfe310|x64 = target riscvfe310|x64
5960
target rl78|x64 = target rl78|x64
6061
target rpi_pico_rp2040|x64 = target rpi_pico_rp2040|x64
@@ -90,6 +91,7 @@ Global
9091
{C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target bl602_sifive_e24_riscv|x64.ActiveCfg = Release|x64
9192
{C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target lpc11c24|x64.ActiveCfg = Release|x64
9293
{C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target nxp_imxrt1062|x64.ActiveCfg = Release|x64
94+
{C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target r7fa4m1ab|x64.ActiveCfg = Release|x64
9395
{C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target riscvfe310|x64.ActiveCfg = Release|x64
9496
{C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target rl78|x64.ActiveCfg = Release|x64
9597
{C8B59726-9319-45C3-8F11-F9F388FB6A2C}.target rpi_pico_rp2040|x64.ActiveCfg = Release|x64
@@ -130,6 +132,8 @@ Global
130132
{30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target lpc11c24|x64.Build.0 = target lpc11c24|x64
131133
{30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target nxp_imxrt1062|x64.ActiveCfg = target nxp_imxrt1062|x64
132134
{30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target nxp_imxrt1062|x64.Build.0 = target nxp_imxrt1062|x64
135+
{30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target r7fa4m1ab|x64.ActiveCfg = target r7fa4m1ab|x64
136+
{30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target r7fa4m1ab|x64.Build.0 = target r7fa4m1ab|x64
133137
{30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target riscvfe310|x64.ActiveCfg = target riscvfe310|x64
134138
{30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target riscvfe310|x64.Build.0 = target riscvfe310|x64
135139
{30CE370B-40F3-4BCD-8986-64AAFF8971BD}.target rl78|x64.ActiveCfg = target rl78|x64

ref_app/ref_app.vcxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@
609609
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
610610
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
611611
</ClCompile>
612+
<ClCompile Include="src\mcal\r7fa4m1ab\mcal_gpt.cpp">
613+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
614+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
615+
</ClCompile>
612616
<ClCompile Include="src\mcal\riscvfe310\mcal_cpu.cpp">
613617
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
614618
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
@@ -2101,6 +2105,10 @@
21012105
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
21022106
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
21032107
</ClInclude>
2108+
<ClInclude Include="src\mcal\r7fa4m1ab\mcal_gpt.h">
2109+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
2110+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
2111+
</ClInclude>
21042112
<ClInclude Include="src\mcal\riscvfe310\mcal_benchmark.h">
21052113
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
21062114
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>

ref_app/ref_app.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@
284284
<Filter Include="src\mcal\bl602_sifive_e24_riscv">
285285
<UniqueIdentifier>{9575513c-b5da-473e-9095-bbd968c02f6b}</UniqueIdentifier>
286286
</Filter>
287+
<Filter Include="src\mcal\r7fa4m1ab">
288+
<UniqueIdentifier>{40be70da-9086-46f9-b158-4dc468860fc7}</UniqueIdentifier>
289+
</Filter>
287290
</ItemGroup>
288291
<ItemGroup>
289292
<ClCompile Include="src\app\led\app_led.cpp">
@@ -1336,6 +1339,9 @@
13361339
<ClCompile Include="src\mcal\bl602_sifive_e24_riscv\mcal_wdg.cpp">
13371340
<Filter>src\mcal\bl602_sifive_e24_riscv</Filter>
13381341
</ClCompile>
1342+
<ClCompile Include="src\mcal\r7fa4m1ab\mcal_gpt.cpp">
1343+
<Filter>src\mcal\r7fa4m1ab</Filter>
1344+
</ClCompile>
13391345
</ItemGroup>
13401346
<ItemGroup>
13411347
<ClInclude Include="src\math\calculus\derivative.h">
@@ -3045,6 +3051,9 @@
30453051
<ClInclude Include="src\math\checksums\hash\hash_stream_base.h">
30463052
<Filter>src\math\checksums\hash</Filter>
30473053
</ClInclude>
3054+
<ClInclude Include="src\mcal\r7fa4m1ab\mcal_gpt.h">
3055+
<Filter>src\mcal\r7fa4m1ab</Filter>
3056+
</ClInclude>
30483057
</ItemGroup>
30493058
<ItemGroup>
30503059
<None Include="src\util\STL\algorithm">
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
#include <mcal_gpt.h>
9+
#include <mcal_reg.h>
10+
11+
#include <util/utility/util_attribute.h>
12+
13+
namespace
14+
{
15+
// The one (and only one) system tick.
16+
volatile auto mcal_gpt_system_tick = mcal::gpt::value_type { };
17+
18+
auto gpt_is_initialized() -> bool& ATTRIBUTE(used, noinline);
19+
20+
auto gpt_is_initialized() -> bool&
21+
{
22+
static auto is_init = bool { };
23+
24+
return is_init;
25+
}
26+
}
27+
28+
extern "C"
29+
auto __vector_16() -> void ATTRIBUTE(signal, used, externally_visible);
30+
31+
auto __vector_16() -> void
32+
{
33+
// Increment the 64-bit system tick with 0x100, representing 256 [(1/2) us].
34+
// This is basically the roll-over of the 8-bit timer0 at 2MHz each 128us.
35+
36+
const auto new_tick =
37+
static_cast<mcal::gpt::value_type>
38+
(
39+
mcal_gpt_system_tick + static_cast<std::uint16_t>(UINT16_C(0x100))
40+
);
41+
42+
mcal_gpt_system_tick = new_tick;
43+
}
44+
45+
auto mcal::gpt::init(const config_type*) -> void
46+
{
47+
if(!gpt_is_initialized())
48+
{
49+
// Clear the timer0 overflow flag.
50+
mcal::reg::reg_access_static<std::uint8_t, std::uint8_t, mcal::reg::tifr0, static_cast<std::uint8_t>(UINT8_C(0x01))>::reg_set();
51+
52+
// Enable the timer0 overflow interrupt.
53+
mcal::reg::reg_access_static<std::uint8_t, std::uint8_t, mcal::reg::timsk0, static_cast<std::uint8_t>(UINT8_C(0x01))>::reg_set();
54+
55+
// Set the timer0 clock source to f_osc/8 = 2MHz and begin counting.
56+
mcal::reg::reg_access_static<std::uint8_t, std::uint8_t, mcal::reg::tccr0b, static_cast<std::uint8_t>(UINT8_C(0x02))>::reg_set();
57+
58+
// Set the is-initialized indication flag.
59+
gpt_is_initialized() = true;
60+
}
61+
}
62+
63+
auto mcal::gpt::secure::get_time_elapsed() -> mcal::gpt::value_type
64+
{
65+
if(gpt_is_initialized())
66+
{
67+
// Return the system tick using a multiple read to ensure data consistency.
68+
69+
using timer_address_type = std::uint8_t;
70+
using timer_register_type = std::uint8_t;
71+
72+
// Do the first read of the timer0 counter and the system tick.
73+
const auto t0_cnt_1 = mcal::reg::reg_access_static<timer_address_type, timer_register_type, mcal::reg::tcnt0>::reg_get();
74+
const auto sys_tick_1 = mcal_gpt_system_tick;
75+
76+
// Do the second read of the timer0 counter.
77+
const auto t0_cnt_2 = mcal::reg::reg_access_static<timer_address_type, timer_register_type, mcal::reg::tcnt0>::reg_get();
78+
79+
const auto t0_tick_is_consistent = (t0_cnt_2 >= t0_cnt_1);
80+
81+
// Perform the consistency check.
82+
const auto consistent_half_microsecond_tick =
83+
static_cast<value_type>
84+
(
85+
t0_tick_is_consistent ? static_cast<value_type>(sys_tick_1 | t0_cnt_1)
86+
: static_cast<value_type>(mcal_gpt_system_tick | t0_cnt_2)
87+
);
88+
89+
// Scale the timer0 tick to 1MHz and perform a rounding correction.
90+
return
91+
static_cast<value_type>
92+
(
93+
static_cast<std::uint64_t>
94+
(
95+
static_cast<std::uint64_t>
96+
(
97+
static_cast<std::uint64_t>(consistent_half_microsecond_tick)
98+
+ static_cast<std::uint8_t>(UINT8_C(1))
99+
)
100+
/ static_cast<std::uint8_t>(UINT8_C(2))
101+
)
102+
);
103+
}
104+
else
105+
{
106+
return static_cast<value_type>(UINT8_C(0));
107+
}
108+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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_2011_10_20_H
9+
#define MCAL_GPT_2011_10_20_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+
};
26+
}
27+
}
28+
29+
#endif // MCAL_GPT_2011_10_20_H

0 commit comments

Comments
 (0)