<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-07-08 18:05 GMT+02:00 Joel Sherrill <span dir="ltr"><<a href="mailto:joel@rtems.org" target="_blank">joel@rtems.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><span class="gmail-"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Jul 8, 2017 10:09 AM, "Denis Obrezkov" <<a href="mailto:denisobrezkov@gmail.com" target="_blank">denisobrezkov@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail-m_-5744152555478909875quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello all,<div>I worked with local interrupts last few days and found some strange behavior:</div><div><p style="margin-top:0px;font-family:Roboto;font-size:14px"><br></p><p style="margin-top:0px;font-family:Roboto;font-size:14px">I am trying to handle local interrupts.<br>That's what I do, in my handler for timer interrupts:<br>* disable timer interrupts in mie<br>* read a current value from mtime<br>* copy it to mtimecmp (both are 64bit width types)<br>* add some big value to mtimecmp<br>* enable timer interrupts in mie.</p><p style="font-family:Roboto;font-size:14px">And I have two boards and the problem is that on one of them interrupts are permanently generated because mip register is always 1 in mtip position, though mtimecmp is greater than mtime, and are not generated at all on the other.</p></div></div></blockquote></div></div></div></span><div dir="auto">Is there a procedure for clearing the interrupt? </div></div></blockquote><div>Yes, it is written that external interrupts are cleared by PLIC (external interrupt controller), </div><div>software interrupts are cleared I think by the main thread (I didn't find it in docs), and timer</div><div>interrupts are cleared by writing the value in mtimecmp memory-mapped register greater</div><div>than in mtime  (memory mapped register too.) [2, p.28]  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><span class="gmail-"><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail-m_-5744152555478909875quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><p style="font-family:Roboto;font-size:14px">In this piece of code, I turn on interrupts:<br>la t0, RISCV_Exception_default<br>csrs mtvec, t0<br>li t0, 0x88<br>csrs mie, t0<br>csrsi mstatus, 0x8</p></div></div></blockquote></div></div></div><div dir="auto"><br></div></span><div dir="auto">Can you point us to the documentation and section where this timer behavior is defined? Sometimes having someone else read it can provide a different interpretation.</div><div dir="auto"><br></div><div dir="auto">And is there other code like Linux which deals with this timer? There may be a magic sequence you are missing </div></div></blockquote><div><br></div><div>I wasn't able to find a magic sequence and didn't look at Linux code, but I initialized it like in hifive1 example provided with FreedomStudio (IDE for HiFive1).:</div><div><a href="https://github.com/sifive/freedom-e-sdk/tree/master/bsp">https://github.com/sifive/freedom-e-sdk/tree/master/bsp</a><br></div><div><br></div><div>But these are the docs:</div><div>Description of mstatus register, which contains mie field for global interrupt enabling (Ch 3.1.6):</div><div>[1] <a href="https://riscv.org/specifications/privileged-isa/">https://riscv.org/specifications/privileged-isa/</a></div><div>Description of the core, on which SoC is based (Ch 6 is about interrupts):</div><div>[2] <a href="https://www.sifive.com/documentation/coreplex/e31-coreplex-manual/">https://www.sifive.com/documentation/coreplex/e31-coreplex-manual/</a><br></div><div><br></div><div>There are also description of the SoC:</div><div><a href="https://www.sifive.com/documentation/freedom-soc/freedom-e300-platform-reference-manual/">https://www.sifive.com/documentation/freedom-soc/freedom-e300-platform-reference-manual/</a><br></div><div>and description of the chip:</div><div><a href="https://www.sifive.com/documentation/chips/freedom-e310-g000-manual/">https://www.sifive.com/documentation/chips/freedom-e310-g000-manual/</a><br></div><div> </div></div>-- <br><div class="gmail_signature">Regards, Denis Obrezkov</div>
</div></div>