interrupt.c 2.7 KB

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