Skip to content

Commit e24409c

Browse files
committed
Further architectural adaptions
1 parent d414c59 commit e24409c

3 files changed

Lines changed: 39 additions & 44 deletions

File tree

ref_app/src/mcal/xtensa_esp32_p4/mcal_gpt.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
#include <mcal_gpt.h>
99
#include <mcal_reg.h>
1010

11-
#include <util/utility/util_two_part_data_manipulation.h>
12-
1311
#include <interrupt.h>
1412

15-
#include <cstddef>
1613
#include <cstdint>
1714
#include <limits>
18-
#include <type_traits>
1915

2016
extern "C"
2117
{
@@ -24,33 +20,33 @@ extern "C"
2420

2521
namespace
2622
{
27-
constexpr unsigned TIMEOUT_1S { 320000000u };
23+
constexpr std::uint32_t TIMEOUT_1S { UINT32_C(320000000) };
2824
}
2925

3026
void mcal::gpt::init(const config_type*)
3127
{
3228
// Set the MTIME timeout.
33-
CLINT_MTIMECMP = (uint64_t) UINT64_C(0xFFFFFFFFFFFFFFFF);
29+
CLINT_MTIMECMP = (std::numeric_limits<std::uint64_t>::max)();
3430
}
3531

3632
mcal::gpt::value_type mcal::gpt::secure::get_time_elapsed()
3733
{
38-
const std::uint64_t tick_unscaled_01 = (uint64_t) CLINT_MTIME;
39-
const std::uint64_t tick_unscaled_02 = (uint64_t) CLINT_MTIME;
34+
const std::uint64_t tick_unscaled_01 = (std::uint64_t) CLINT_MTIME;
35+
const std::uint64_t tick_unscaled_02 = (std::uint64_t) CLINT_MTIME;
4036

4137
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);
38+
(std::uint64_t) (((std::uint32_t) tick_unscaled_02 > (std::uint32_t) tick_unscaled_01) ? tick_unscaled_01 : (std::uint64_t) CLINT_MTIME);
4339

4440
return (std::uint64_t) ((std::uint64_t) (tick_unscaled + 160U) / 320U);
4541
}
4642

4743
mcal::gpt::value_type mcal::gpt::secure::get_time_elapsed_core1()
4844
{
49-
const std::uint64_t tick_unscaled_01 = (uint64_t) CLINT_MTIME;
50-
const std::uint64_t tick_unscaled_02 = (uint64_t) CLINT_MTIME;
45+
const std::uint64_t tick_unscaled_01 = (std::uint64_t) CLINT_MTIME;
46+
const std::uint64_t tick_unscaled_02 = (std::uint64_t) CLINT_MTIME;
5147

5248
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);
49+
(std::uint64_t) (((std::uint32_t) tick_unscaled_02 > (std::uint32_t) tick_unscaled_01) ? tick_unscaled_01 : (std::uint64_t) CLINT_MTIME);
5450

5551
return (std::uint64_t) ((std::uint64_t) (tick_unscaled + 160U) / 320U);
5652
}

ref_app/src/mcal/xtensa_esp32_p4/mcal_gpt.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@
2424
static auto get_time_elapsed() -> value_type;
2525
static auto get_time_elapsed_core1() -> value_type;
2626
};
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-
};
3427
}
3528
}
3629

ref_app/target/micros/xtensa_esp32_p4/startup/Code/Appli/main.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,12 @@
1515
1616
******************************************************************************************/
1717

18-
#include <riscv-csr.h>
19-
#include <interrupt.h>
2018
#include <gpio.h>
2119

2220
#include <mcal_gpt.h>
2321

2422
#include <util/utility/util_time.h>
2523

26-
#include <cstdint>
27-
28-
constexpr unsigned TIMEOUT_500MS { 160000000u };
29-
constexpr unsigned TIMEOUT_1S { 320000000u };
30-
3124
extern "C"
3225
{
3326
uint32_t osGetActiveCore(void);
@@ -40,9 +33,9 @@ auto main(void) -> int __attribute__((used,noinline));
4033

4134
auto main(void) -> int
4235
{
43-
const std::uint32_t core_id { osGetActiveCore() };
36+
const bool core_id_is_zero { (std::uint32_t { UINT8_C(0) } == osGetActiveCore()) };
4437

45-
if(std::uint32_t { UINT8_C(0) } == core_id)
38+
if(core_id_is_zero)
4639
{
4740
gpio_cfg_output(7);
4841
gpio_cfg_output(8);
@@ -69,41 +62,52 @@ auto main(void) -> int
6962
}
7063

7164
// Go to the core-specific main subroutines.
72-
if(std::uint32_t { UINT8_C(0) } == core_id)
65+
if(core_id_is_zero)
7366
{
74-
mcal::gpt::init(nullptr);
75-
7667
::main_core0();
7768
}
7869
else
7970
{
80-
mcal::gpt::init(nullptr);
81-
8271
::main_core1();
8372
}
8473
}
8574

8675
namespace local
8776
{
77+
struct timer_core1_backend
78+
{
79+
using tick_type = std::uint64_t;
80+
81+
static auto get_now() -> tick_type { return static_cast<tick_type>(mcal::gpt::secure::get_time_elapsed_core1()); }
82+
};
83+
8884
using timer_type = util::timer<std::uint64_t>;
8985

90-
using timer_core1_type = util::timer<std::uint64_t, mcal::gpt::timer_core1_backend>;
86+
constexpr typename timer_type::tick_type
87+
led_timeout
88+
{
89+
static_cast<typename timer_type::tick_type>(timer_type::seconds(UINT8_C(1)))
90+
};
91+
92+
using timer_core1_type = util::timer<std::uint64_t, timer_core1_backend>;
9193
} // namespace local
9294

9395
auto main_core0() -> void
9496
{
9597
gpio_toggle_output_level(54);
9698

97-
local::timer_type led_timer(local::timer_type::seconds(1U));
99+
mcal::gpt::init(nullptr);
98100

99-
// Endless loop: Never return or break.
100-
while(1)
101+
local::timer_type local_led_timer(local::led_timeout);
102+
103+
// Endless LED tollge-loop: Never return or break.
104+
for(;;)
101105
{
102-
if(led_timer.timeout())
106+
if(local_led_timer.timeout())
103107
{
104108
gpio_toggle_output_level(54);
105109

106-
led_timer.start_interval(local::timer_type::seconds(1U));
110+
local_led_timer.start_interval(local::led_timeout);
107111
}
108112
}
109113
}
@@ -112,16 +116,18 @@ auto main_core1() -> void
112116
{
113117
gpio_toggle_output_level(19);
114118

115-
local::timer_core1_type led_timer(local::timer_type::seconds(1U));
119+
mcal::gpt::init(nullptr);
120+
121+
local::timer_core1_type local_led_timer(local::led_timeout);
116122

117-
// Endless loop: Never return or break.
118-
while(1)
123+
// Endless LED tollge-loop: Never return or break.
124+
for(;;)
119125
{
120-
if(led_timer.timeout())
126+
if(local_led_timer.timeout())
121127
{
122128
gpio_toggle_output_level(19);
123129

124-
led_timer.start_interval(local::timer_type::seconds(1U));
130+
local_led_timer.start_interval(local::led_timeout);
125131
}
126132
}
127133
}

0 commit comments

Comments
 (0)