<div dir="ltr">Ok, I fixed it.</div><div class="gmail_extra"><br><div class="gmail_quote">2017-08-22 3:48 GMT+02:00 Gedare Bloom <span dir="ltr"><<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Aug 21, 2017 at 7:56 PM, Denis Obrezkov <<a href="mailto:denisobrezkov@gmail.com">denisobrezkov@gmail.com</a>> wrote:<br>
> ---<br>
> c/src/lib/libbsp/riscv32/<wbr>hifive1/include/prci.h | 9 +++++<br>
> c/src/lib/libbsp/riscv32/<wbr>hifive1/start/bspstart.c | 23 +++++++++++++<br>
> c/src/lib/libbsp/riscv32/<wbr>hifive1/start/prci.c | 40 +++++++++++++++++++++++<br>
> 3 files changed, 72 insertions(+)<br>
> create mode 100644 c/src/lib/libbsp/riscv32/<wbr>hifive1/start/bspstart.c<br>
><br>
> diff --git a/c/src/lib/libbsp/riscv32/<wbr>hifive1/include/prci.h b/c/src/lib/libbsp/riscv32/<wbr>hifive1/include/prci.h<br>
> index c71edbc..3a4ea15 100644<br>
> --- a/c/src/lib/libbsp/riscv32/<wbr>hifive1/include/prci.h<br>
> +++ b/c/src/lib/libbsp/riscv32/<wbr>hifive1/include/prci.h<br>
> @@ -56,6 +56,10 @@<br>
> #define HFROSC_TRIM_OFFSET 16<br>
> #define HFROSC_EN_OFFSET 30<br>
> #define HFROSC_RDY_OFFSET 31<br>
> +#define HFROSC_DIV_MASK 0x2F<br>
> +#define HFROSC_TRIM_MASK 0x1F<br>
> +#define HFROSC_EN_MASK 0x1<br>
> +<br>
><br>
> /*<br>
> * HFXOSCCFG configuration register values<br>
> @@ -69,7 +73,12 @@<br>
> * PLLCFG configuration register<br>
> */<br>
> #define PLL_SEL_OFFSET 16<br>
> +#define PLL_REF_SEL_OFFSET 17<br>
> +#define PLL_BYPASS_OFFSET 18<br>
> +#define PLL_LOCK_OFFSET 31<br>
><br>
> uint32_t hifive1_current_freq();<br>
><br>
> +void initialize_oscills();<br>
</div></div>This function is in the application namespace. It should probably be<br>
hifive1_initialize_<wbr>oscillators() to be a bit more distinct.<br>
<div class="HOEnZb"><div class="h5"><br>
> +<br>
> #endif /* PRCI_H */<br>
> diff --git a/c/src/lib/libbsp/riscv32/<wbr>hifive1/start/bspstart.c b/c/src/lib/libbsp/riscv32/<wbr>hifive1/start/bspstart.c<br>
> new file mode 100644<br>
> index 0000000..bb04a22<br>
> --- /dev/null<br>
> +++ b/c/src/lib/libbsp/riscv32/<wbr>hifive1/start/bspstart.c<br>
> @@ -0,0 +1,23 @@<br>
> +/*<br>
> + * Copyright (c) 2017<br>
> + * Denis Obrezkov <<a href="mailto:denisobrezkov@gmail.com">denisobrezkov@gmail.com</a>><br>
> + *<br>
> + * The license and distribution terms for this file may be<br>
> + * found in the file LICENSE in this distribution or at<br>
> + * <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/<wbr>LICENSE</a>.<br>
> + */<br>
> +<br>
> +#include <bsp.h><br>
> +#include <bsp/bootcard.h><br>
> +#include <bsp/prci.h><br>
> +#include <bsp/fe310.h><br>
> +<br>
> +/*<br>
> + * This routine make initialization of HiFive1 (FE310) counters.<br>
> + */<br>
> +<br>
> +void bsp_start( void )<br>
> +{<br>
> + initialize_oscills();<br>
> + bsp_interrupt_initialize();<br>
> +}<br>
> diff --git a/c/src/lib/libbsp/riscv32/<wbr>hifive1/start/prci.c b/c/src/lib/libbsp/riscv32/<wbr>hifive1/start/prci.c<br>
> index bf3d288..1f3abb6 100644<br>
> --- a/c/src/lib/libbsp/riscv32/<wbr>hifive1/start/prci.c<br>
> +++ b/c/src/lib/libbsp/riscv32/<wbr>hifive1/start/prci.c<br>
> @@ -26,7 +26,47 @@<br>
> */<br>
><br>
> #include <bsp/prci.h><br>
> +#include <bsp/fe310.h><br>
><br>
> uint32_t hifive1_current_freq() {<br>
> return hifive1_default_freq;<br>
> }<br>
> +<br>
> +void initialize_oscills() {<br>
> + volatile uint32_t * pll_reg = (volatile uint32_t *) PRCI_PLLCFG;<br>
> + volatile uint32_t * high_freq_reg = (volatile uint32_t *) PRCI_HFROSCCFG;<br>
> +<br>
> +#ifdef USE_HFROSC<br>
> + /* Setting up osc frequency */<br>
> + uint32_t tmp_reg = 0;<br>
> + /* Install divider in high frequency oscillator */<br>
> + tmp_reg |= (HFROSC_DIV_VAL & HFROSC_DIV_MASK) << HFROSC_DIV_OFFSET;<br>
> + tmp_reg |= (HFROSC_TRIM_VAL & HFROSC_TRIM_MASK) << HFROSC_TRIM_OFFSET;<br>
> + tmp_reg |= (HFROSC_EN_VAL & HFROSC_EN_MASK) << HFROSC_EN_OFFSET;<br>
> + (*high_freq_reg) = tmp_reg;<br>
> + while (( (*high_freq_reg) & ((HFROSC_RDY_VAL & 0x1) \<br>
> + << HFROSC_RDY_OFFSET)) == 0 ) {<br>
> + ;<br>
> + }<br>
> +#endif /* USE_HFROSC */<br>
> +<br>
> +#ifdef USE_HFXOSC<br>
> + volatile uint32_t * ext_freq_reg = (volatile uint32_t *) PRCI_HFXOSCCFG;<br>
> + (*ext_freq_reg) |= ((HFXOSC_EN_VAL & 0x1) << HFXOSC_EN_OFFSET);<br>
> + while (( (*ext_freq_reg) & ((HFXOSC_RDY_VAL & 0x1) \<br>
> + << HFXOSC_RDY_OFFSET)) == 0 ) {<br>
> + ;<br>
> + }<br>
> + (*pll_reg) |= (0x1 << PLL_BYPASS_OFFSET);<br>
> + (*pll_reg) |= (0x1 << PLL_REF_SEL_OFFSET);<br>
> + (*pll_reg) |= (0x1 << PLL_SEL_OFFSET);<br>
> + (*high_freq_reg) &= ~(0x1 << HFROSC_EN_OFFSET);<br>
> +<br>
> +#endif /* USE_HFXOSC */<br>
> +#ifndef USE_PLL<br>
> + /* Disable PLL */<br>
> + (*pll_reg) &= ~(0x1 << PLL_SEL_OFFSET);<br>
> +#else<br>
> +<br>
> +#endif<br>
> +}<br>
> --<br>
> 2.1.4<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> ______________________________<wbr>_________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/<wbr>mailman/listinfo/devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Regards, Denis Obrezkov</div>
</div>