interrupt.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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-08-23 Bernard first version
  13. * 2010-03-17 zchong SEP4020
  14. */
  15. #include <rtthread.h>
  16. #include "sep4020.h"
  17. #define MAX_HANDLERS 32
  18. extern rt_uint32_t rt_interrupt_nest;
  19. /* exception and interrupt handler table */
  20. rt_isr_handler_t isr_table[MAX_HANDLERS];
  21. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  22. rt_uint32_t rt_thread_switch_interrput_flag;
  23. /**
  24. * @addtogroup SEP4020
  25. */
  26. /*@{*/
  27. void rt_hw_interrupt_handler(int vector)
  28. {
  29. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  30. }
  31. /**
  32. * This function will initialize hardware interrupt
  33. */
  34. void rt_hw_interrupt_init()
  35. {
  36. register rt_uint32_t idx;
  37. /* disable all interrupts */
  38. INTC_IER = 0x0;
  39. /* mask all interrupts */
  40. INTC_IMR = 0xFFFFFFFF;
  41. /* init exceptions table */
  42. for(idx=0; idx < MAX_HANDLERS; idx++)
  43. {
  44. isr_table[idx] = (rt_isr_handler_t)rt_hw_interrupt_handler;
  45. }
  46. /* init interrupt nest, and context in thread sp */
  47. rt_interrupt_nest = 0;
  48. rt_interrupt_from_thread = 0;
  49. rt_interrupt_to_thread = 0;
  50. rt_thread_switch_interrput_flag = 0;
  51. }
  52. /**
  53. * This function will mask a interrupt.
  54. * @param vector the interrupt number
  55. */
  56. void rt_hw_interrupt_mask(int vector)
  57. {
  58. INTC_IMR |= 1 << vector;
  59. }
  60. /**
  61. * This function will un-mask a interrupt.
  62. * @param vector the interrupt number
  63. */
  64. void rt_hw_interrupt_umask(int vector)
  65. {
  66. /* un-mask interrupt */
  67. if ((vector == INT_NOTUSED0) || (vector == INT_NOTUSED16))
  68. {
  69. rt_kprintf("Interrupt vec %d is not used!\n", vector);
  70. // while(1);
  71. }
  72. else if (vector == INTGLOBAL)
  73. INTC_IMR = 0x0;
  74. else
  75. INTC_IMR &= ~(1 << vector);
  76. }
  77. /**
  78. * This function will install a interrupt service routine to a interrupt.
  79. * @param vector the interrupt number
  80. * @param new_handler the interrupt service routine to be installed
  81. * @param old_handler the old interrupt service routine
  82. */
  83. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  84. {
  85. if(vector >= 0 && vector < MAX_HANDLERS)
  86. {
  87. if (*old_handler != RT_NULL) *old_handler = isr_table[vector];
  88. if (new_handler != RT_NULL) isr_table[vector] = new_handler;
  89. }
  90. }
  91. /*@}*/