interrupt.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "lpc214x.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_interrput_flag;
  20. /**
  21. * @addtogroup LPC214x
  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. rt_uint32_t *vect_addr, *vect_ctl;
  35. /* initialize VIC*/
  36. VICIntEnClr = 0xffffffff;
  37. VICVectAddr = 0;
  38. /* set all to IRQ */
  39. VICIntSelect = 0;
  40. for (index = 0; index < MAX_HANDLERS; index ++)
  41. {
  42. vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + (index << 2));
  43. vect_ctl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + (index << 2));
  44. *vect_addr = (rt_uint32_t)rt_hw_interrupt_handler;
  45. *vect_ctl = 0xF;
  46. }
  47. /* init interrupt nest, and context in thread sp */
  48. rt_interrupt_nest = 0;
  49. rt_interrupt_from_thread = 0;
  50. rt_interrupt_to_thread = 0;
  51. rt_thread_switch_interrput_flag = 0;
  52. }
  53. /**
  54. * This function will mask a interrupt.
  55. * @param vector the interrupt number
  56. */
  57. void rt_hw_interrupt_mask(int vector)
  58. {
  59. VICIntEnClr = (1 << vector);
  60. }
  61. /**
  62. * This function will un-mask a interrupt.
  63. * @param vector the interrupt number
  64. */
  65. void rt_hw_interrupt_umask(int vector)
  66. {
  67. VICIntEnable = (1 << vector);
  68. }
  69. /**
  70. * This function will install a interrupt service routine to a interrupt.
  71. * @param vector the interrupt number
  72. * @param new_handler the interrupt service routine to be installed
  73. * @param old_handler the old interrupt service routine
  74. */
  75. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  76. {
  77. if(vector >= 0 && vector < MAX_HANDLERS)
  78. {
  79. /* get VIC address */
  80. rt_uint32_t* vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + (vector << 2));
  81. rt_uint32_t* vect_ctl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + (vector << 2));
  82. /* assign IRQ slot and enable this slot */
  83. *vect_ctl = 0x20 | (vector & 0x1F);
  84. if (old_handler != RT_NULL) *old_handler = (rt_isr_handler_t) *vect_addr;
  85. if (new_handler != RT_NULL) *vect_addr = (rt_uint32_t) new_handler;
  86. }
  87. }
  88. /*@}*/