interrupt.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector)
  29. {
  30. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  31. return RT_NULL;
  32. }
  33. /**
  34. * This function will initialize hardware interrupt
  35. */
  36. void rt_hw_interrupt_init(void)
  37. {
  38. register rt_uint32_t idx;
  39. /*Make sure all intc registers in proper state*/
  40. /*mask all the irq*/
  41. *(RP)(INTC_IMR) = 0xFFFFFFFF;
  42. /*enable all the irq*/
  43. *(RP)(INTC_IER) = 0XFFFFFFFF;
  44. /*Dont use any forced irq*/
  45. *(RP)(INTC_IFR) = 0x0;
  46. /*Disable all the fiq*/
  47. *(RP)(INTC_FIER) = 0x0;
  48. /*Mask all the fiq*/
  49. *(RP)(INTC_FIMR) = 0x0F;
  50. /*Dont use forced fiq*/
  51. *(RP)(INTC_FIFR) = 0x0;
  52. /*Intrrupt priority register*/
  53. *(RP)(INTC_IPLR) = 0x0;
  54. /* init exceptions table */
  55. rt_memset(isr_table, 0x00, sizeof(isr_table));
  56. for(idx=0; idx < MAX_HANDLERS; idx++)
  57. {
  58. isr_table[idx].handler = rt_hw_interrupt_handle;
  59. }
  60. /* init interrupt nest, and context in thread sp */
  61. rt_interrupt_nest = 0;
  62. rt_interrupt_from_thread = 0;
  63. rt_interrupt_to_thread = 0;
  64. rt_thread_switch_interrupt_flag = 0;
  65. }
  66. /**
  67. * This function will mask a interrupt.
  68. * @param vector the interrupt number
  69. */
  70. void rt_hw_interrupt_mask(rt_uint32_t vector)
  71. {
  72. *(RP)(INTC_IMR) |= 1 << vector;
  73. }
  74. /**
  75. * This function will un-mask a interrupt.
  76. * @param vector the interrupt number
  77. */
  78. void rt_hw_interrupt_umask(rt_uint32_t vector)
  79. {
  80. if(vector == 16)
  81. {
  82. rt_kprintf("Interrupt vec %d is not used!\n", vector);
  83. }
  84. else
  85. *(RP)(INTC_IMR) &= ~(1 << vector);
  86. }
  87. /**
  88. * This function will install a interrupt service routine to a interrupt.
  89. * @param vector the interrupt number
  90. * @param new_handler the interrupt service routine to be installed
  91. * @param old_handler the old interrupt service routine
  92. */
  93. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  94. void *param, char *name)
  95. {
  96. rt_isr_handler_t old_handler = RT_NULL;
  97. if(vector < MAX_HANDLERS)
  98. {
  99. old_handler = isr_table[vector].handler;
  100. if (handler != RT_NULL)
  101. {
  102. #ifdef RT_USING_INTERRUPT_INFO
  103. rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
  104. #endif /* RT_USING_INTERRUPT_INFO */
  105. isr_table[vector].handler = handler;
  106. isr_table[vector].param = param;
  107. }
  108. }
  109. return old_handler;
  110. }
  111. /*@}*/