Skip to content

Commit 651e5e3

Browse files
committed
Further cleanup and C++-ification
1 parent 00cfa6e commit 651e5e3

9 files changed

Lines changed: 21 additions & 23900 deletions

File tree

ref_app/target/micros/bl602_sifive_e24_riscv/Code/Mcal/BL602.h renamed to ref_app/src/mcal/bl602_sifive_e24_riscv/BL602.h

File renamed without changes.

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_gpt.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
//
77

88
#include <mcal_gpt.h>
9+
#include <mcal_reg.h>
910

1011
#include <util/utility/util_noncopyable.h>
1112

12-
#include "BL602.h"
13-
1413
namespace
1514
{
1615
struct mcal_gpt_system_tick final : private util::noncopyable
@@ -20,12 +19,12 @@ namespace
2019

2120
~mcal_gpt_system_tick() = delete;
2221

23-
static void init()
22+
static auto init() -> void
2423
{
2524
initial_count = get_consistent_microsecond_tick();
2625
}
2726

28-
static std::uint64_t get_tick()
27+
static auto get_tick() -> std::uint64_t
2928
{
3029
const std::uint64_t elapsed = get_consistent_microsecond_tick() - initial_count;
3130

@@ -35,7 +34,12 @@ namespace
3534
private:
3635
static std::uint64_t initial_count;
3736

38-
static std::uint64_t get_consistent_microsecond_tick()
37+
static auto read_clic_timer64() -> std::uint64_t
38+
{
39+
return mcal::reg::reg_access_static<std::uintptr_t, std::uint64_t, mcal::reg::clic_mtime>::reg_get();
40+
}
41+
42+
static auto get_consistent_microsecond_tick() -> std::uint64_t
3943
{
4044
// Return the (elapsed) system tick using a multiple read
4145
// to ensure data consistency. The system tick representing
@@ -47,8 +51,8 @@ namespace
4751

4852
// Return the system tick using a multiple read to ensure data consistency.
4953

50-
const volatile std::uint64_t time_first { CLIC_MTIME };
51-
const volatile std::uint64_t time_second { CLIC_MTIME };
54+
const volatile std::uint64_t time_first { read_clic_timer64() };
55+
const volatile std::uint64_t time_second { read_clic_timer64() };
5256

5357
const bool
5458
is_steady
@@ -61,7 +65,7 @@ namespace
6165
{
6266
static_cast<std::uint64_t>
6367
(
64-
is_steady ? time_first : CLIC_MTIME
68+
is_steady ? time_first : read_clic_timer64()
6569
)
6670
};
6771

@@ -76,9 +80,9 @@ namespace
7680

7781
std::uint64_t mcal_gpt_system_tick::initial_count;
7882

79-
bool& gpt_is_initialized() __attribute__((used, noinline));
83+
auto gpt_is_initialized() -> bool& __attribute__((used, noinline));
8084

81-
bool& gpt_is_initialized()
85+
auto gpt_is_initialized() -> bool&
8286
{
8387
static bool is_init = bool();
8488

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_reg.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
{
1515
namespace reg
1616
{
17-
// Port (gpio) registers.
18-
constexpr std::uintptr_t gpio0 { UINT32_C(0x00600010) };
19-
constexpr std::uintptr_t gpio1 { UINT32_C(0x00601010) };
20-
constexpr std::uintptr_t mcu_gpio0 { UINT32_C(0x04201010) };
17+
// CLIC (timer) registers.
18+
constexpr std::uintptr_t clic_ctrl_addr { UINT32_C(0x02000000) };
19+
constexpr std::uintptr_t clic_msip { clic_ctrl_addr + UINT32_C(0x00000000) };
20+
constexpr std::uintptr_t clic_mtimecmp { clic_ctrl_addr + UINT32_C(0x00004000) };
21+
constexpr std::uintptr_t clic_mtime { clic_ctrl_addr + UINT32_C(0x0000BFF8) };
22+
constexpr std::uintptr_t clic_clk_gate { clic_ctrl_addr + UINT32_C(0x007FF000) };
2123
}
2224
}
2325

ref_app/target.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,6 @@
12321232
<ItemGroup>
12331233
<ClInclude Include="target\micros\am6254_soc\Code\Startup\Core\a53\core_macros.h" />
12341234
<ClInclude Include="target\micros\am6254_soc\Code\Startup\Core\a53\gic-500.h" />
1235-
<ClInclude Include="target\micros\bl602_sifive_e24_riscv\Code\Mcal\BL602.h" />
1236-
<ClInclude Include="target\micros\bl602_sifive_e24_riscv\Code\Mcal\riscv-csr.h" />
12371235
<ClInclude Include="target\micros\xtensa_esp32_s3\startup\Std\core-isa.h" />
12381236
</ItemGroup>
12391237
<ItemGroup>

ref_app/target.vcxproj.filters

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,6 @@
331331
<Filter Include="micros\bl602_sifive_e24_riscv\startup">
332332
<UniqueIdentifier>{d9d707dc-1ba0-4d0c-be67-fbb095f42986}</UniqueIdentifier>
333333
</Filter>
334-
<Filter Include="micros\bl602_sifive_e24_riscv\Code">
335-
<UniqueIdentifier>{8c965230-fbcc-427e-8292-9231493dc299}</UniqueIdentifier>
336-
</Filter>
337-
<Filter Include="micros\bl602_sifive_e24_riscv\Code\Mcal">
338-
<UniqueIdentifier>{75fda3d9-17eb-48a8-92e8-9c440411a545}</UniqueIdentifier>
339-
</Filter>
340334
</ItemGroup>
341335
<ItemGroup>
342336
<None Include="target\app\make\app_files.gmk">
@@ -1122,12 +1116,6 @@
11221116
<ClInclude Include="target\micros\am6254_soc\Code\Startup\Core\a53\gic-500.h">
11231117
<Filter>micros\am6254_soc\Code\Startup\Core\a53</Filter>
11241118
</ClInclude>
1125-
<ClInclude Include="target\micros\bl602_sifive_e24_riscv\Code\Mcal\BL602.h">
1126-
<Filter>micros\bl602_sifive_e24_riscv\Code\Mcal</Filter>
1127-
</ClInclude>
1128-
<ClInclude Include="target\micros\bl602_sifive_e24_riscv\Code\Mcal\riscv-csr.h">
1129-
<Filter>micros\bl602_sifive_e24_riscv\Code\Mcal</Filter>
1130-
</ClInclude>
11311119
</ItemGroup>
11321120
<ItemGroup>
11331121
<Library Include="target\micros\xtensa_esp32_s3\startup\Std\lib_call0_abi\libc_call0_abi.a">

0 commit comments

Comments
 (0)