interrupt.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <rtthread.h>
  15. #include "AT91SAM7S.h"
  16. #define MAX_HANDLERS 32
  17. extern rt_uint32_t rt_interrupt_nest;
  18. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  19. rt_uint32_t rt_thread_switch_interrupt_flag;
  20. /**
  21. * @addtogroup AT91SAM7
  22. */
  23. /*@{*/
  24. void rt_hw_interrupt_handler(int vector)
  25. {
  26. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  27. }
  28. /**
  29. * This function will initialize hardware interrupt
  30. */
  31. void rt_hw_interrupt_init()
  32. {
  33. rt_base_t index;
  34. for (index = 0; index < MAX_HANDLERS; index ++)
  35. {
  36. AT91C_AIC_SVR(index) = (rt_uint32_t)rt_hw_interrupt_handler;
  37. }
  38. /* init interrupt nest, and context in thread sp */
  39. rt_interrupt_nest = 0;
  40. rt_interrupt_from_thread = 0;
  41. rt_interrupt_to_thread = 0;
  42. rt_thread_switch_interrupt_flag = 0;
  43. }
  44. /**
  45. * This function will mask a interrupt.
  46. * @param vector the interrupt number
  47. */
  48. void rt_hw_interrupt_mask(int vector)
  49. {
  50. /* disable interrupt */
  51. AT91C_AIC_IDCR = 1 << vector;
  52. /* clear interrupt */
  53. AT91C_AIC_ICCR = 1 << vector;
  54. }
  55. /**
  56. * This function will un-mask a interrupt.
  57. * @param vector the interrupt number
  58. */
  59. void rt_hw_interrupt_umask(int vector)
  60. {
  61. AT91C_AIC_IECR = 1 << vector;
  62. }
  63. /**
  64. * This function will install a interrupt service routine to a interrupt.
  65. * @param vector the interrupt number
  66. * @param new_handler the interrupt service routine to be installed
  67. * @param old_handler the old interrupt service routine
  68. */
  69. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  70. {
  71. if(vector >= 0 && vector < MAX_HANDLERS)
  72. {
  73. if (*old_handler != RT_NULL) *old_handler = (rt_isr_handler_t)AT91C_AIC_SVR(vector);
  74. if (new_handler != RT_NULL) AT91C_AIC_SVR(vector) = (rt_uint32_t)new_handler;
  75. }
  76. }
  77. /*@}*/