interrupt.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * File : trap.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-03-13 Bernard first version
  13. * 2013-03-29 aozima Modify the interrupt interface implementations.
  14. */
  15. #include <rtthread.h>
  16. #include <rthw.h>
  17. #include <sep4020.h>
  18. #define MAX_HANDLERS 32
  19. extern rt_uint32_t rt_interrupt_nest;
  20. /* exception and interrupt handler table */
  21. struct rt_irq_desc isr_table[MAX_HANDLERS];
  22. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  23. rt_uint32_t rt_thread_switch_interrupt_flag;
  24. /**
  25. * @addtogroup S3C24X0
  26. */
  27. /*@{*/
  28. static void rt_hw_interrupt_handle(int vector, void *param)
  29. {
  30. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  31. }
  32. /**
  33. * This function will initialize hardware interrupt
  34. */
  35. void rt_hw_interrupt_init(void)
  36. {
  37. register rt_uint32_t idx;
  38. /*Make sure all intc registers in proper state*/
  39. /*mask all the irq*/
  40. *(RP)(INTC_IMR) = 0xFFFFFFFF;
  41. /*enable all the irq*/
  42. *(RP)(INTC_IER) = 0XFFFFFFFF;
  43. /*Dont use any forced irq*/
  44. *(RP)(INTC_IFR) = 0x0;
  45. /*Disable all the fiq*/
  46. *(RP)(INTC_FIER) = 0x0;
  47. /*Mask all the fiq*/
  48. *(RP)(INTC_FIMR) = 0x0F;
  49. /*Dont use forced fiq*/
  50. *(RP)(INTC_FIFR) = 0x0;
  51. /*Intrrupt priority register*/
  52. *(RP)(INTC_IPLR) = 0x0;
  53. /* init exceptions table */
  54. rt_memset(isr_table, 0x00, sizeof(isr_table));
  55. for(idx=0; idx < MAX_HANDLERS; idx++)
  56. {
  57. isr_table[idx].handler = rt_hw_interrupt_handle;
  58. }
  59. /* init interrupt nest, and context in thread sp */
  60. rt_interrupt_nest = 0;
  61. rt_interrupt_from_thread = 0;
  62. rt_interrupt_to_thread = 0;
  63. rt_thread_switch_interrupt_flag = 0;
  64. }
  65. /**
  66. * This function will mask a interrupt.
  67. * @param vector the interrupt number
  68. */
  69. void rt_hw_interrupt_mask(int vector)
  70. {
  71. *(RP)(INTC_IMR) |= 1 << vector;
  72. }
  73. /**
  74. * This function will un-mask a interrupt.
  75. * @param vector the interrupt number
  76. */
  77. void rt_hw_interrupt_umask(int vector)
  78. {
  79. if(vector == 16)
  80. {
  81. rt_kprintf("Interrupt vec %d is not used!\n", vector);
  82. }
  83. else
  84. *(RP)(INTC_IMR) &= ~(1 << vector);
  85. }
  86. /**
  87. * This function will install a interrupt service routine to a interrupt.
  88. * @param vector the interrupt number
  89. * @param new_handler the interrupt service routine to be installed
  90. * @param old_handler the old interrupt service routine
  91. */
  92. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  93. void *param, char *name)
  94. {
  95. rt_isr_handler_t old_handler = RT_NULL;
  96. if(vector < MAX_HANDLERS)
  97. {
  98. old_handler = isr_table[vector].handler;
  99. if (handler != RT_NULL)
  100. {
  101. #ifdef RT_USING_INTERRUPT_INFO
  102. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  103. #endif /* RT_USING_INTERRUPT_INFO */
  104. isr_table[vector].handler = handler;
  105. isr_table[vector].param = param;
  106. }
  107. }
  108. return old_handler;
  109. }
  110. /*@}*/