1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #include <metal/machine/platform.h>
6 #ifdef METAL_SIFIVE_FE310_G000_HFXOSC
8 #include <metal/drivers/sifive_fe310-g000_hfxosc.h>
9 #include <metal/machine.h>
11 #define CONFIG_ENABLE 0x40000000UL
12 #define CONFIG_READY 0x80000000UL
14 long __metal_driver_sifive_fe310_g000_hfxosc_get_rate_hz(const struct metal_clock *clock)
16 struct metal_clock *ref = __metal_driver_sifive_fe310_g000_hfxosc_ref(clock);
17 long config_offset = __metal_driver_sifive_fe310_g000_hfxosc_config_offset(clock);
18 struct __metal_driver_sifive_fe310_g000_prci *config_base =
19 __metal_driver_sifive_fe310_g000_hfxosc_config_base(clock);
20 const struct __metal_driver_vtable_sifive_fe310_g000_prci *vtable =
21 __metal_driver_sifive_fe310_g000_prci_vtable();
22 long cfg = vtable->get_reg(config_base, config_offset);
24 if ((cfg & CONFIG_ENABLE) == 0)
26 if ((cfg & CONFIG_READY) == 0)
28 return metal_clock_get_rate_hz(ref);
31 long __metal_driver_sifive_fe310_g000_hfxosc_set_rate_hz(struct metal_clock *clock, long rate)
33 return __metal_driver_sifive_fe310_g000_hfxosc_get_rate_hz(clock);
36 __METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_fe310_g000_hfxosc) = {
37 .clock.get_rate_hz = __metal_driver_sifive_fe310_g000_hfxosc_get_rate_hz,
38 .clock.set_rate_hz = __metal_driver_sifive_fe310_g000_hfxosc_set_rate_hz,
41 #endif /* METAL_SIFIVE_FE310_G000_HFXOSC */
43 typedef int no_empty_translation_units;