Skip to content

Commit 8a1ed6f

Browse files
henrikbrixandersenkartben
authored andcommitted
soc: neorv32: add option for reading clock frequency from sysinfo at boot
Add Kconfig option for reading the NEORV32 clock frequency from SYSINFO at boot time. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 4b415df commit 8a1ed6f

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

soc/neorv32/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@ config SOC_NEORV32_VERSION
1919
identical to that of the NEORV32 Machine implementation ID (mimpid)
2020
register.
2121

22+
config SOC_NEORV32_READ_FREQUENCY_AT_RUNTIME
23+
bool "Read the NEORV32 clock frequency at runtime"
24+
default y
25+
depends on !$(dt_node_has_prop,/cpus/cpu@0,clock-frequency)
26+
select SOC_EARLY_INIT_HOOK
27+
select TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
28+
help
29+
If enabled, the NEORV32 clock frequency will be read from SYSINFO during boot. This
30+
results in small overhead, which can be avoided by setting the clock-frequency property of
31+
the cpu@0 devicetree node if the frequency is known at build-time.
32+
2233
endif # SOC_NEORV32

soc/neorv32/Kconfig.defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
if SOC_NEORV32
55

66
config SYS_CLOCK_HW_CYCLES_PER_SEC
7-
default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency) if RISCV_MACHINE_TIMER
7+
default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency) if !SOC_NEORV32_READ_FREQUENCY_AT_RUNTIME
88

99
config NUM_IRQS
1010
default 32

soc/neorv32/soc.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
77
#include <zephyr/irq.h>
88
#include <soc.h>
99

10-
#if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT)
10+
#ifdef CONFIG_SOC_NEORV32_READ_FREQUENCY_AT_RUNTIME
11+
extern int z_clock_hw_cycles_per_sec;
12+
13+
void soc_early_init_hook(void)
14+
{
15+
uint32_t base = DT_REG_ADDR(DT_NODELABEL(sysinfo));
16+
17+
z_clock_hw_cycles_per_sec = sys_read32(base + NEORV32_SYSINFO_CLK);
18+
}
19+
#endif /* CONFIG_SOC_NEORV32_READ_FREQUENCY_AT_RUNTIME */
20+
21+
#ifdef CONFIG_RISCV_SOC_INTERRUPT_INIT
1122
void soc_interrupt_init(void)
1223
{
1324
(void)arch_irq_lock();
1425

1526
csr_write(mie, 0);
1627
}
17-
#endif
28+
#endif /* CONFIG_RISCV_SOC_INTERRUPT_INIT */

0 commit comments

Comments
 (0)