interrupt.c 2.6 KB

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