<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2017-08-17 17:11 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 Wed, Aug 16, 2017 at 11:12 AM, Denis Obrezkov<br>
<<a href="mailto:denisobrezkov@gmail.com">denisobrezkov@gmail.com</a>> wrote:<br>
> ---<br>
> c/src/lib/libbsp/riscv32/<wbr>hifive1/irq/irq.c | 90 ++++++++++++++++++++++++++++++<br>
> 1 file changed, 90 insertions(+)<br>
> create mode 100644 c/src/lib/libbsp/riscv32/<wbr>hifive1/irq/irq.c<br>
><br>
> diff --git a/c/src/lib/libbsp/riscv32/<wbr>hifive1/irq/irq.c b/c/src/lib/libbsp/riscv32/<wbr>hifive1/irq/irq.c<br>
> new file mode 100644<br>
> index 0000000..6fd4e75<br>
> --- /dev/null<br>
> +++ b/c/src/lib/libbsp/riscv32/<wbr>hifive1/irq/irq.c<br>
> @@ -0,0 +1,90 @@<br>
> +/**<br>
> + * @file<br>
> + *<br>
> + * @ingroup riscv_interrupt<br>
> + *<br>
> + * @brief Interrupt support.<br>
> + */<br>
> +<br>
> +/*<br>
> + * RISCV CPU Dependent Source<br>
> + *<br>
> + * Copyright (c) 2015 University of York.<br>
> + * Hesham ALMatary <<a href="mailto:hmka501@york.ac.uk">hmka501@york.ac.uk</a>><br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND<br>
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE<br>
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br>
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br>
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br>
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br>
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br>
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>
> + * SUCH DAMAGE.<br>
> + */<br>
> +<br>
> +#include <bsp/fe310.h><br>
> +#include <bsp/irq.h><br>
> +#include <bsp/irq-generic.h><br>
> +<br>
> +/* Almost all of the jobs that the following functions should<br>
> + * do are implemented in cpukit<br>
> + */<br>
> +<br>
> +void bsp_interrupt_handler_default(<wbr>rtems_vector_number vector)<br>
> +{<br>
> + printk("spurious interrupt: %u\n", vector);<br>
> +}<br>
> +<br>
> +rtems_status_code bsp_interrupt_facility_<wbr>initialize()<br>
> +{<br>
> + return 0;<br>
> +}<br>
> +<br>
> +rtems_status_code bsp_interrupt_vector_enable(<wbr>rtems_vector_number vector)<br>
> +{<br>
> + return 0;<br>
> +}<br>
> +<br>
> +rtems_status_code bsp_interrupt_vector_disable(<wbr>rtems_vector_number vector)<br>
> +{<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static uint32_t cause = 0;<br>
> +volatile uint64_t * mtimecmp = (volatile uint64_t *)0x02004000;<br>
> +volatile uint64_t * mtime = (volatile uint64_t *)0x0200bff8;<br>
> +<br>
</div></div>What are these global variables used for?<br></blockquote><div>mtime - memory mapped timer register with a current timer value,</div><div>mtimecmp - comparator, if mtime>=mtimecmp, then interrupt generated </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> +void handle_trap_new ()<br>
What is the purpose of this function?<br></blockquote><div>I think it is better to rename it. It's an irq dispatching function. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
> +{<br>
> + asm volatile ("csrr %0, mcause": "=r" (cause));<br>
</span>It would be good to have a static inline function for reading this register.<br>
<span class=""><br>
> + if (cause & MCAUSE_INT) {<br>
> + /* an interrupt occurred */<br>
> + if ((cause & MCAUSE_MTIME) == MCAUSE_MTIME) {<br>
> + /* Timer interrupt */<br>
> + (*mtimecmp) = (*mtime) + FE310_CLOCK_PERIOD;<br>
> + bsp_interrupt_handler_table[1]<wbr>.handler(bsp_interrupt_<wbr>handler_table[1].arg);<br>
> + } else if ((cause & MCAUSE_MEXT) == MCAUSE_MEXT) {<br>
> + /*External interrupt */<br>
> + asm volatile ("csrci mie, 0x800");<br>
> + } else if ((cause & MCAUSE_MSWI) == MCAUSE_MSWI) {<br>
> + /* Software interrupt */<br>
> + volatile uint32_t * msip_reg = (volatile uint32_t *) 0x02000000;<br>
> + *msip_reg = 0;<br>
> + }<br>
> + } else {<br>
> + /* an exception occurred */<br>
> + }<br>
> +<br>
> +}<br>
> --<br>
> 2.1.4<br>
><br>
</span>> ______________________________<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>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Regards, Denis Obrezkov</div>
</div></div>