interrupt.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. */
  14. #include <rthw.h>
  15. #include "AT91SAM7X256.h"
  16. #define MAX_HANDLERS 32
  17. /* exception and interrupt handler table */
  18. struct rt_irq_desc irq_desc[MAX_HANDLERS];
  19. extern rt_uint32_t rt_interrupt_nest;
  20. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  21. rt_uint32_t rt_thread_switch_interrupt_flag;
  22. /**
  23. * @addtogroup AT91SAM7
  24. */
  25. /*@{*/
  26. void rt_hw_interrupt_handler(int vector)
  27. {
  28. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  29. }
  30. /**
  31. * This function will initialize hardware interrupt
  32. */
  33. void rt_hw_interrupt_init()
  34. {
  35. rt_base_t index;
  36. /* init exceptions table */
  37. for(index=0; index < MAX_HANDLERS; index++)
  38. {
  39. irq_desc[index].handler = (rt_isr_handler_t)rt_hw_interrupt_handler;
  40. irq_desc[index].param = RT_NULL;
  41. }
  42. for (index = 0; index < MAX_HANDLERS; index ++)
  43. {
  44. AT91C_BASE_AIC->AIC_SVR[index] = (rt_uint32_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_interrupt_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. /* disable interrupt */
  59. AT91C_BASE_AIC->AIC_IDCR = 1 << vector;
  60. /* clear interrupt */
  61. AT91C_BASE_AIC->AIC_ICCR = 1 << vector;
  62. }
  63. /**
  64. * This function will un-mask a interrupt.
  65. * @param vector the interrupt number
  66. */
  67. void rt_hw_interrupt_umask(int vector)
  68. {
  69. AT91C_BASE_AIC->AIC_IECR = 1 << vector;
  70. }
  71. /**
  72. * This function will install a interrupt service routine to a interrupt.
  73. * @param vector the interrupt number
  74. * @param handler the interrupt service routine to be installed
  75. * @param param the parameter for interrupt service routine
  76. * @name unused.
  77. *
  78. * @return the old handler
  79. */
  80. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  81. void *param, char *name)
  82. {
  83. rt_isr_handler_t old_handler = RT_NULL;
  84. if(vector >= 0 && vector < MAX_HANDLERS)
  85. {
  86. old_handler = irq_desc[vector].handler;
  87. if (handler != RT_NULL)
  88. {
  89. irq_desc[vector].handler = (rt_isr_handler_t)handler;
  90. irq_desc[vector].param = param;
  91. }
  92. }
  93. return old_handler;
  94. }
  95. /*@}*/