Skip to content

Commit 99a3fde

Browse files
committed
Finish C++-ification BL602 with LD-script TBD
1 parent c3b8e49 commit 99a3fde

11 files changed

Lines changed: 60 additions & 1260 deletions

File tree

ref_app/ref_app.vcxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,10 +1908,6 @@
19081908
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
19091909
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
19101910
</ClInclude>
1911-
<ClInclude Include="src\mcal\bl602_sifive_e24_riscv\BL602.h">
1912-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
1913-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
1914-
</ClInclude>
19151911
<ClInclude Include="src\mcal\bl602_sifive_e24_riscv\mcal_benchmark.h">
19161912
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
19171913
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>

ref_app/ref_app.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,9 +3027,6 @@
30273027
<ClInclude Include="src\mcal\bl602_sifive_e24_riscv\mcal_benchmark.h">
30283028
<Filter>src\mcal\bl602_sifive_e24_riscv</Filter>
30293029
</ClInclude>
3030-
<ClInclude Include="src\mcal\bl602_sifive_e24_riscv\BL602.h">
3031-
<Filter>src\mcal\bl602_sifive_e24_riscv</Filter>
3032-
</ClInclude>
30333030
</ItemGroup>
30343031
<ItemGroup>
30353032
<None Include="src\util\STL\algorithm">

ref_app/src/mcal/bl602_sifive_e24_riscv/BL602.h

Lines changed: 0 additions & 1156 deletions
This file was deleted.

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_benchmark.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{
1818
namespace benchmark
1919
{
20-
using benchmark_port_type = mcal::port::port_pin;
20+
using benchmark_port_type = mcal::port::port_pin<unsigned { UINT8_C(4) }>;
2121
}
2222
}
2323

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_cpu.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,8 @@
88
#ifndef MCAL_CPU_2025_07_30_H
99
#define MCAL_CPU_2025_07_30_H
1010

11-
#if defined(__cplusplus)
1211
#include <cstdint>
13-
#else
14-
#include <stdint.h>
15-
#endif
1612

17-
#if defined(__cplusplus)
18-
extern "C"
19-
{
20-
#endif
21-
22-
void mcal_cpu_secure_acquire_spin_lock(volatile uint32_t*);
23-
void mcal_cpu_secure_release_spin_lock(volatile uint32_t*);
24-
25-
static inline void mcal_cpu_nop(void);
26-
27-
#if defined(__cplusplus)
28-
}
29-
#endif
30-
31-
#if defined(__cplusplus)
3213
namespace mcal
3314
{
3415
namespace cpu
@@ -38,25 +19,7 @@
3819
inline auto post_init() -> void { }
3920

4021
inline auto nop() noexcept -> void { asm volatile("nop"); }
41-
42-
struct secure
43-
{
44-
static auto acquire_spin_lock(volatile std::uint32_t* p_sync) noexcept -> void { mcal_cpu_secure_acquire_spin_lock(p_sync); }
45-
static auto release_spin_lock(volatile std::uint32_t* p_sync) noexcept -> void { mcal_cpu_secure_release_spin_lock(p_sync); }
46-
};
4722
}
4823
}
49-
#endif
50-
51-
#if defined(__cplusplus)
52-
extern "C"
53-
{
54-
#endif
55-
56-
static inline void mcal_cpu_nop(void) { __asm volatile("nop"); }
57-
58-
#if defined(__cplusplus)
59-
}
60-
#endif
6124

6225
#endif // MCAL_CPU_2025_07_30_H
Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,20 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2025.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
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)
66
//
77

8-
#include <mcal_led/mcal_led_boolean_state_base.h>
98
#include <mcal_led.h>
10-
#include <mcal_reg.h>
11-
#include <util/utility/util_time.h>
12-
13-
namespace
14-
{
15-
constexpr std::uint32_t GPIO_FUN_SDIO { UINT32_C( 1) };
16-
constexpr std::uint32_t GPIO_FUN_FLASH { UINT32_C( 2) };
17-
constexpr std::uint32_t GPIO_FUN_SPI { UINT32_C( 4) };
18-
constexpr std::uint32_t GPIO_FUN_I2C { UINT32_C( 6) };
19-
constexpr std::uint32_t GPIO_FUN_UART { UINT32_C( 7) };
20-
constexpr std::uint32_t GPIO_FUN_PWM { UINT32_C( 8) };
21-
constexpr std::uint32_t GPIO_FUN_EXT_PA { UINT32_C( 9) };
22-
constexpr std::uint32_t GPIO_FUN_ANALOG { UINT32_C(10) };
23-
constexpr std::uint32_t GPIO_FUN_SWGPIO { UINT32_C(11) };
24-
constexpr std::uint32_t GPIO_FUN_JTAG { UINT32_C(14) };
25-
} // anonymous namespace
26-
27-
class led_port_tmp_bl606 : public mcal::led::led_boolean_state_base
28-
{
29-
public:
30-
led_port_tmp_bl606() noexcept
31-
{
32-
// Configure IO3 as output, low.
33-
// glb->GPIO_CFGCTL1.bit.reg_gpio_3_func_sel = GPIO_FUN_SWGPIO;
34-
// glb->GPIO_CFGCTL1.bit.reg_gpio_3_ie = 0ul;
35-
// glb->GPIO_CFGCTL1.bit.reg_gpio_3_smt = 0ul;
36-
// glb->GPIO_CFGCTL1.bit.reg_gpio_3_drv = 0ul;
37-
// glb->GPIO_CFGCTL34.bit.reg_gpio_3_oe = 1ul;
38-
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl1, static_cast<std::uint32_t>(GPIO_FUN_SWGPIO << 24U)>::template reg_msk<static_cast<std::uint32_t>(UINT32_C(0xF) << 24U)>();
39-
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl1, UINT32_C(16)>::bit_clr();
40-
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl1, UINT32_C(17)>::bit_clr();
41-
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl1, UINT32_C(0) << 18U>::template reg_msk<UINT32_C(3) << 18U>();
42-
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl34, UINT32_C(3)>::bit_set();
43-
}
44-
45-
~led_port_tmp_bl606() override = default;
46-
47-
auto toggle() noexcept -> void override
48-
{
49-
// Toggle the IO3 pin.
50-
// glb->GPIO_CFGCTL32.bit.reg_gpio_3_o ^= 1ul;
51-
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl32, UINT32_C(3)>::bit_not();
52-
53-
using base_class_type = led_boolean_state_base;
54-
55-
base_class_type::toggle();
56-
}
57-
};
9+
#include <mcal_led/mcal_led_port.h>
5810

5911
auto mcal::led::led0() -> mcal::led::led_base&
6012
{
61-
using led0_led_type = led_port_tmp_bl606;
13+
using led0_port_type = mcal::port::port_pin<unsigned { UINT8_C(3) }>;
14+
15+
using led0_led_type = mcal::led::led_port<led0_port_type>;
6216

6317
static led0_led_type l0;
6418

6519
return l0;
6620
}
67-

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_led.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2024.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
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)

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_osc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2024.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
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)

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_port.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,48 @@
2222

2323
void init(const config_type*);
2424

25+
template<const unsigned PortIndex>
2526
class port_pin
2627
{
28+
private:
29+
static constexpr std::uint32_t GPIO_FUN_SDIO { UINT32_C( 1) };
30+
static constexpr std::uint32_t GPIO_FUN_FLASH { UINT32_C( 2) };
31+
static constexpr std::uint32_t GPIO_FUN_SPI { UINT32_C( 4) };
32+
static constexpr std::uint32_t GPIO_FUN_I2C { UINT32_C( 6) };
33+
static constexpr std::uint32_t GPIO_FUN_UART { UINT32_C( 7) };
34+
static constexpr std::uint32_t GPIO_FUN_PWM { UINT32_C( 8) };
35+
static constexpr std::uint32_t GPIO_FUN_EXT_PA { UINT32_C( 9) };
36+
static constexpr std::uint32_t GPIO_FUN_ANALOG { UINT32_C(10) };
37+
static constexpr std::uint32_t GPIO_FUN_SWGPIO { UINT32_C(11) };
38+
static constexpr std::uint32_t GPIO_FUN_JTAG { UINT32_C(14) };
39+
40+
static constexpr std::uint32_t port_index { static_cast<std::uint32_t>(PortIndex) };
41+
42+
static constexpr bool odd_index { ((PortIndex % unsigned { UINT8_C(2) }) != unsigned { UINT8_C(0) }) };
43+
44+
static constexpr std::uintptr_t
45+
cfgctl
46+
{
47+
static_cast<std::uintptr_t>
48+
(
49+
mcal::reg::gpio_cfgctl0 + (port_index / 2U) * 4U
50+
)
51+
};
52+
53+
static constexpr unsigned cfgctl_bpos_reg_gpio_3_func_sel { odd_index ? UINT8_C(24) : UINT8_C(24) - UINT8_C(16) };
54+
static constexpr unsigned cfgctl_bpos_reg_gpio_3_ie { odd_index ? UINT8_C(16) : UINT8_C(16) - UINT8_C(16) };
55+
static constexpr unsigned cfgctl_bpos_reg_gpio_3_smt { odd_index ? UINT8_C(17) : UINT8_C(17) - UINT8_C(16) };
56+
static constexpr unsigned cfgctl_bpos_reg_gpio_3_drv { odd_index ? UINT8_C(18) : UINT8_C(18) - UINT8_C(16) };
57+
2758
public:
2859
static auto set_direction_output() noexcept -> void
2960
{
30-
// Not yet implemented.
61+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, cfgctl, static_cast<std::uint32_t>(GPIO_FUN_SWGPIO << cfgctl_bpos_reg_gpio_3_func_sel)>::template reg_msk<static_cast<std::uint32_t>(UINT32_C(0xF) << cfgctl_bpos_reg_gpio_3_func_sel)>();
62+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, cfgctl, cfgctl_bpos_reg_gpio_3_ie>::bit_clr();
63+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, cfgctl, cfgctl_bpos_reg_gpio_3_smt>::bit_clr();
64+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, cfgctl, UINT32_C(0) << cfgctl_bpos_reg_gpio_3_drv>::template reg_msk<UINT32_C(3) << cfgctl_bpos_reg_gpio_3_drv>();
65+
66+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl34, port_index>::bit_set();
3167
}
3268

3369
static auto set_direction_input() noexcept -> void
@@ -53,7 +89,7 @@
5389

5490
static auto toggle_pin() noexcept -> void
5591
{
56-
// Not yet implemented.
92+
mcal::reg::reg_access_static<std::uintptr_t, std::uint32_t, mcal::reg::gpio_cfgctl32, port_index>::bit_not();
5793
}
5894
};
5995
}

ref_app/src/mcal/bl602_sifive_e24_riscv/mcal_pwm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2007 - 2020.
2+
// Copyright Christopher Kormanyos 2007 - 2025.
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)

0 commit comments

Comments
 (0)