[rtems commit] bsp/riscv: riscv_get_core_frequency()
Sebastian Huber
sebh at rtems.org
Thu Nov 14 10:49:23 UTC 2019
Module: rtems
Branch: master
Commit: df9426f970c6c3ff11300cefbf221abee679b270
Changeset: http://git.rtems.org/rtems/commit/?id=df9426f970c6c3ff11300cefbf221abee679b270
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Thu Nov 14 11:08:28 2019 +0100
bsp/riscv: riscv_get_core_frequency()
Always provide this function. Return 0 by default. Fix formatting.
Simplify function.
Update #3785.
---
bsps/riscv/riscv/include/bsp/riscv.h | 2 --
bsps/riscv/riscv/start/bspstart.c | 64 +++++++++++++-----------------------
2 files changed, 23 insertions(+), 43 deletions(-)
diff --git a/bsps/riscv/riscv/include/bsp/riscv.h b/bsps/riscv/riscv/include/bsp/riscv.h
index f2f1a59..a469155 100644
--- a/bsps/riscv/riscv/include/bsp/riscv.h
+++ b/bsps/riscv/riscv/include/bsp/riscv.h
@@ -38,9 +38,7 @@ extern volatile RISCV_CLINT_regs *riscv_clint;
void *riscv_fdt_get_address(const void *fdt, int node);
-#if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
uint32_t riscv_get_core_frequency(void);
-#endif
#ifdef RTEMS_SMP
extern uint32_t riscv_hart_count;
diff --git a/bsps/riscv/riscv/start/bspstart.c b/bsps/riscv/riscv/start/bspstart.c
index a462bbe..ff57386 100644
--- a/bsps/riscv/riscv/start/bspstart.c
+++ b/bsps/riscv/riscv/start/bspstart.c
@@ -32,9 +32,7 @@
#include <libfdt.h>
#include <string.h>
-#if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
-unsigned int riscv_core_freq;
-#endif
+static uint32_t riscv_core_freq;
void *riscv_fdt_get_address(const void *fdt, int node)
{
@@ -166,55 +164,39 @@ uint32_t riscv_get_hart_index_by_phandle(uint32_t phandle)
return UINT32_MAX;
}
-#if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
static uint32_t get_core_frequency(void)
{
- uint32_t node;
- const char *fdt=bsp_fdt_get();
-
- char *tlclk;
- uint32_t len;
-
- do
- {
- node=fdt_node_offset_by_compatible(fdt, -1,"fixed-clock");
- uint32_t *val=NULL;
- if (node>0)
- {
- tlclk = fdt_getprop(fdt, node, "clock-output-names", &len);
-
- if (strcmp(tlclk,"tlclk") == 0)
- {
- val = fdt_getprop(fdt, node, "clock-frequency", &len);
- if(val !=NULL)
- {
- riscv_core_freq=fdt32_to_cpu(*val);
- break;
- }
- }
- }else
- {
- bsp_fatal(RISCV_FATAL_NO_TLCLOCK_FREQUENCY_IN_DEVICE_TREE);
- }
+#if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
+ uint32_t node;
+ const char *fdt;
+ const char *tlclk;
+ int len;
+ const fdt32_t *val;
- } while (node > 0);
+ fdt = bsp_fdt_get();
+ node = fdt_node_offset_by_compatible(fdt, -1,"fixed-clock");
+ tlclk = fdt_getprop(fdt, node, "clock-output-names", &len);
- return riscv_core_freq;
+ if (strcmp(tlclk,"tlclk") != 0) {
+ bsp_fatal(RISCV_FATAL_NO_TLCLOCK_FREQUENCY_IN_DEVICE_TREE);
+ }
+
+ val = fdt_getprop(fdt, node, "clock-frequency", &len);
+ if (val != NULL && len == 4) {
+ return fdt32_to_cpu(*val);
+ }
+#endif
+ return 0;
}
-inline uint32_t riscv_get_core_frequency(void)
+uint32_t riscv_get_core_frequency(void)
{
- return riscv_core_freq;
+ return riscv_core_freq;
}
-#endif
void bsp_start(void)
{
riscv_find_harts();
bsp_interrupt_initialize();
-
-#if RISCV_ENABLE_FRDME310ARTY_SUPPORT != 0
- riscv_core_freq=get_core_frequency();
-#endif
-
+ riscv_core_freq = get_core_frequency();
}
More information about the vc
mailing list