Skip to content

Commit 410b769

Browse files
committed
Remove BL602 timer interrupt
1 parent d3bebae commit 410b769

3 files changed

Lines changed: 52 additions & 47 deletions

File tree

ref_app/src/mcal/am6254_soc/mcal_gpt.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@
1111

1212
auto mcal::gpt::secure::get_time_elapsed() -> mcal::gpt::value_type
1313
{
14-
// Get the system tick from the system counter register.
15-
const value_type consistent_microsecond_tick = static_cast<value_type>(ARM64_READ_SYSREG(CNTPCT_EL0));
14+
// Get the consistent system tick from the system counter register.
15+
const value_type
16+
consistent_microsecond_tick
17+
{
18+
static_cast<value_type>(ARM64_READ_SYSREG(CNTPCT_EL0))
19+
};
1620

1721
// Convert the consistent tick to microseconds.
18-
return static_cast<value_type>(static_cast<value_type>(consistent_microsecond_tick + UINT64_C(100)) / UINT64_C(200));
22+
return
23+
static_cast<value_type>
24+
(
25+
static_cast<value_type>(consistent_microsecond_tick + UINT64_C(100)) / UINT64_C(200)
26+
);
1927
}
2028

2129
auto mcal::gpt::secure::get_time_elapsed_core1() -> mcal::gpt::value_type_core1

ref_app/target/micros/bl602_sifive_e24_riscv/Code/Appli/mcal_gpt.cpp

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,71 @@
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
77

8-
#include "BL602.h"
9-
108
#include <mcal_gpt.h>
119

12-
//-----------------------------------------------------------------------------------------
13-
// Defines
14-
//-----------------------------------------------------------------------------------------
15-
namespace
10+
#include "BL602.h"
11+
12+
namespace local
1613
{
1714
constexpr std::uint64_t TIMEOUT_1S { UINT64_C(10000000) };
1815

19-
// The one (and only one) system tick.
20-
volatile auto mcal_gpt_system_tick = mcal::gpt::value_type { };
21-
2216
auto gpt_is_initialized() -> bool& __attribute__((used, noinline));
2317

18+
auto get_consistent_tick
19+
{
20+
[]()
21+
{
22+
// Return the system tick using a multiple read to ensure data consistency.
23+
24+
const volatile std::uint64_t time_first { CLIC_MTIME };
25+
const volatile std::uint64_t time_second { CLIC_MTIME };
26+
27+
const bool
28+
is_steady
29+
{
30+
(static_cast<std::uint32_t>(time_second) >= static_cast<std::uint32_t>(time_first))
31+
};
32+
33+
return
34+
static_cast<mcal::gpt::value_type>
35+
(
36+
is_steady ? time_first : CLIC_MTIME
37+
);
38+
}
39+
};
40+
2441
auto gpt_is_initialized() -> bool&
2542
{
26-
static auto is_init = bool { };
43+
static bool is_init { };
2744

2845
return is_init;
2946
}
30-
}
31-
32-
extern "C" void Isr_TIMER_Interrupt (void) __attribute__((interrupt,used,noinline));
33-
34-
extern "C"
35-
void Isr_TIMER_Interrupt (void)
36-
{
37-
// Set the next timer timeout timeout.
38-
39-
CLIC_MTIMECMP = (uint64_t)(CLIC_MTIME + TIMEOUT_1S);
40-
}
47+
} // namespace local
4148

4249
extern "C" auto mcal_gpt_init() -> void;
4350

4451
extern "C" auto mcal_gpt_init() -> void
4552
{
46-
/* enabled selective hardware vectoring */
47-
CLIC_CFG |= 1ul;
48-
49-
/* enable timer interrupt in CLIC vectored mode */
50-
CLIC_INTIE[7] = 1u;
5153
}
5254

5355
auto mcal::gpt::init(const config_type*) -> void { }
5456

5557
auto mcal::gpt::secure::get_time_elapsed() -> mcal::gpt::value_type
5658
{
57-
if(!gpt_is_initialized())
59+
if(!local::gpt_is_initialized())
5860
{
59-
// Set the next timer interrupt timeout.
60-
CLIC_MTIMECMP = (uint64_t)(CLIC_MTIME + TIMEOUT_1S);
61-
6261
// Set the is-initialized indication flag.
63-
gpt_is_initialized() = true;
62+
local::gpt_is_initialized() = true;
6463
}
6564

66-
// Return the system tick using a multiple read to ensure data consistency.
67-
68-
const volatile uint64_t time_first = CLIC_MTIME;
69-
const volatile uint64_t time_second = CLIC_MTIME;
70-
71-
const volatile bool is_steady = (((uint32_t) time_second > (uint32_t) time_first) ? true : false);
72-
73-
value_type consistent_microsecond_tick = (is_steady ? time_first : CLIC_MTIME);
74-
75-
consistent_microsecond_tick /= 10U;
76-
77-
return consistent_microsecond_tick;
65+
// Convert the consistent tick to microseconds.
66+
return
67+
static_cast<mcal::gpt::value_type>
68+
(
69+
static_cast<mcal::gpt::value_type>
70+
(
71+
static_cast<mcal::gpt::value_type>(local::get_consistent_tick() + UINT32_C(5))
72+
/ UINT32_C(10)
73+
)
74+
);
7875
}

ref_app/target/micros/bl602_sifive_e24_riscv/startup/intvect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void UndefinedHandler(void);
3535
static void UndefinedHandler(void){ for(;;); }
3636

3737
void Isr_SW_Interrupt (void) __attribute__((weak, alias("UndefinedHandler")));
38-
void Isr_TIMER_Interrupt (void) __attribute__((interrupt,used,noinline));
38+
void Isr_TIMER_Interrupt (void) __attribute__((weak, alias("UndefinedHandler")));
3939
void Isr_Ext_Interrupt (void) __attribute__((weak, alias("UndefinedHandler")));
4040
void Isr_CLIC_SW_Interrupt (void) __attribute__((weak, alias("UndefinedHandler")));
4141
void L1C_BMX_ERR (void) __attribute__((weak, alias("UndefinedHandler")));

0 commit comments

Comments
 (0)