trap.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <rtthread.h>
  2. #include <rthw.h>
  3. #include <platform.h>
  4. #include <encoding.h>
  5. #include "interrupt.h"
  6. extern struct rt_irq_desc irq_desc[];
  7. extern rt_uint32_t rt_hw_interrupt_get_active(rt_uint32_t fiq_irq);
  8. void rt_hw_trap_irq()
  9. {
  10. rt_isr_handler_t isr_func;
  11. rt_uint32_t irq;
  12. void *param;
  13. /* get irq number */
  14. irq = rt_hw_interrupt_get_active(0);
  15. /* get interrupt service routine */
  16. isr_func = irq_desc[irq].handler;
  17. param = irq_desc[irq].param;
  18. /* turn to interrupt service routine */
  19. isr_func(irq, param);
  20. rt_hw_interrupt_ack(0, irq);
  21. #ifdef RT_USING_INTERRUPT_INFO
  22. irq_desc[irq].counter ++;
  23. #endif
  24. }
  25. void handle_m_ext_interrupt()
  26. {
  27. }
  28. void rt_systick_handler(void)
  29. {
  30. clear_csr(mie, MIP_MTIP);
  31. // Reset the timer for 3s in the future.
  32. // This also clears the existing timer interrupt.
  33. volatile uint64_t * mtime = (uint64_t*) (CLINT_CTRL_ADDR + CLINT_MTIME);
  34. volatile uint64_t * mtimecmp = (uint64_t*) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
  35. uint64_t now = *mtime;
  36. uint64_t then = now + 2 * RTC_FREQ/RT_TICK_PER_SECOND;
  37. *mtimecmp = then;
  38. rt_tick_increase();
  39. // read the current value of the LEDS and invert them.
  40. /*
  41. GPIO_REG(GPIO_OUTPUT_VAL) ^= ((0x1 << RED_LED_OFFSET) |
  42. (0x1 << GREEN_LED_OFFSET) |
  43. (0x1 << BLUE_LED_OFFSET));
  44. */
  45. // Re-enable the timer interrupt.
  46. set_csr(mie, MIP_MTIP);
  47. }