interrupt.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include <rthw.h>
  2. #include "platform.h"
  3. #define MAX_HANDLERS (128)
  4. extern rt_uint32_t rt_interrupt_nest;
  5. /* exception and interrupt handler table */
  6. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  7. rt_uint32_t rt_interrupt_from_thread;
  8. rt_uint32_t rt_interrupt_to_thread;
  9. rt_uint32_t rt_thread_switch_interrupt_flag;
  10. /**
  11. * This function will mask a interrupt.
  12. * @param vector the interrupt number
  13. */
  14. void rt_hw_interrupt_mask(int irq)
  15. {
  16. return;
  17. }
  18. /**
  19. * This function will un-mask a interrupt.
  20. * @param vector the interrupt number
  21. */
  22. void rt_hw_interrupt_unmask(int irq)
  23. {
  24. return;
  25. }
  26. rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector, void *param)
  27. {
  28. rt_kprintf("UN-handled interrupt %d occurred!!!\n", vector);
  29. return RT_NULL;
  30. }
  31. void rt_hw_interrupt_init(void)
  32. {
  33. int idx;
  34. /* config interrupt vector*/
  35. asm volatile(
  36. "la t0, trap_entry\n"
  37. "csrw mtvec, t0"
  38. );
  39. /* enable interrupt*/
  40. /* init exceptions table */
  41. for(idx=0; idx < MAX_HANDLERS; idx++)
  42. {
  43. rt_hw_interrupt_mask(idx);
  44. irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
  45. irq_desc[idx].param = RT_NULL;
  46. #ifdef RT_USING_INTERRUPT_INFO
  47. rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
  48. irq_desc[idx].counter = 0;
  49. #endif
  50. }
  51. /* init interrupt nest, and context in thread sp */
  52. rt_interrupt_nest = 0;
  53. rt_interrupt_from_thread = 0;
  54. rt_interrupt_to_thread = 0;
  55. rt_thread_switch_interrupt_flag = 0;
  56. }
  57. rt_uint32_t rt_hw_interrupt_get_active(rt_uint32_t fiq_irq)
  58. {
  59. //volatile rt_uint32_t irqstat;
  60. rt_uint32_t id;
  61. return 0;
  62. }
  63. void rt_hw_interrupt_ack(rt_uint32_t fiq_irq, rt_uint32_t id)
  64. {
  65. return;
  66. }
  67. /**
  68. * This function will install a interrupt service routine to a interrupt.
  69. * @param vector the interrupt number
  70. * @param handler the interrupt service routine to be installed
  71. * @param param the interrupt service function parameter
  72. * @param name the interrupt name
  73. * @return old handler
  74. */
  75. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  76. void *param, char *name)
  77. {
  78. rt_isr_handler_t old_handler = RT_NULL;
  79. if(vector < MAX_HANDLERS)
  80. {
  81. old_handler = irq_desc[vector].handler;
  82. if (handler != RT_NULL)
  83. {
  84. irq_desc[vector].handler = (rt_isr_handler_t)handler;
  85. irq_desc[vector].param = param;
  86. #ifdef RT_USING_INTERRUPT_INFO
  87. rt_snprintf(irq_desc[vector].name, RT_NAME_MAX - 1, "%s", name);
  88. irq_desc[vector].counter = 0;
  89. #endif
  90. }
  91. }
  92. return old_handler;
  93. }