interrupt.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "s3c24x0.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. /* all clear source pending */
  39. SRCPND = 0x0;
  40. /* all clear sub source pending */
  41. SUBSRCPND = 0x0;
  42. /* all=IRQ mode */
  43. INTMOD = 0x0;
  44. /* all interrupt disabled include global bit */
  45. INTMSK = BIT_ALLMSK;
  46. /* all sub interrupt disable */
  47. INTSUBMSK = BIT_SUB_ALLMSK;
  48. /* all clear interrupt pending */
  49. INTPND = BIT_ALLMSK;
  50. /* init exceptions table */
  51. rt_memset(isr_table, 0x00, sizeof(isr_table));
  52. for(idx=0; idx < MAX_HANDLERS; idx++)
  53. {
  54. isr_table[idx].handler = rt_hw_interrupt_handle;
  55. }
  56. /* init interrupt nest, and context in thread sp */
  57. rt_interrupt_nest = 0;
  58. rt_interrupt_from_thread = 0;
  59. rt_interrupt_to_thread = 0;
  60. rt_thread_switch_interrupt_flag = 0;
  61. }
  62. /**
  63. * This function will mask a interrupt.
  64. * @param vector the interrupt number
  65. */
  66. void rt_hw_interrupt_mask(int vector)
  67. {
  68. INTMSK |= 1 << vector;
  69. }
  70. /**
  71. * This function will un-mask a interrupt.
  72. * @param vector the interrupt number
  73. */
  74. void rt_hw_interrupt_umask(int vector)
  75. {
  76. if (vector == INTNOTUSED6)
  77. {
  78. rt_kprintf("Interrupt vec %d is not used!\n", vector);
  79. // while(1);
  80. }
  81. else if (vector == INTGLOBAL)
  82. INTMSK = 0x0;
  83. else
  84. INTMSK &= ~(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. /*@}*/