interrupt.c 2.4 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. * 2008-12-11 XuXinming first version
  13. */
  14. #include <rthw.h>
  15. #include "LPC24xx.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. /* exception and interrupt handler table */
  21. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  22. rt_uint32_t rt_thread_switch_interrupt_flag;
  23. /**
  24. * @addtogroup LPC2478
  25. */
  26. /*@{*/
  27. void rt_hw_interrupt_handler(int vector, void *param)
  28. {
  29. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  30. }
  31. void rt_hw_interrupt_init()
  32. {
  33. register int i;
  34. rt_uint32_t *vect_addr, *vect_cntl;
  35. /* initialize VIC*/
  36. VICIntEnClr = 0xffffffff;
  37. VICVectAddr = 0;
  38. VICIntSelect = 0;
  39. /* init exceptions table */
  40. for(i=0; i < MAX_HANDLERS; i++)
  41. {
  42. irq_desc[i].handler = (rt_isr_handler_t)rt_hw_interrupt_handler;
  43. irq_desc[i].param = RT_NULL;
  44. vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + i*4);
  45. vect_cntl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + i*4);
  46. *vect_addr = (rt_uint32_t)&irq_desc[i];
  47. *vect_cntl = 0xF;
  48. }
  49. /* init interrupt nest, and context in thread sp */
  50. rt_interrupt_nest = 0;
  51. rt_interrupt_from_thread = 0;
  52. rt_interrupt_to_thread = 0;
  53. rt_thread_switch_interrupt_flag = 0;
  54. }
  55. void rt_hw_interrupt_mask(int vector)
  56. {
  57. VICIntEnClr = (1 << vector);
  58. }
  59. void rt_hw_interrupt_umask(int vector)
  60. {
  61. VICIntEnable = (1 << vector);
  62. }
  63. /**
  64. * This function will install a interrupt service routine to a interrupt.
  65. * @param vector the interrupt number
  66. * @param handler the interrupt service routine to be installed
  67. * @param param the parameter for interrupt service routine
  68. * @name unused.
  69. *
  70. * @return the old handler
  71. */
  72. rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
  73. void *param, char *name)
  74. {
  75. rt_isr_handler_t old_handler = RT_NULL;
  76. if(vector >= 0 && vector < MAX_HANDLERS)
  77. {
  78. old_handler = irq_desc[vector].handler;
  79. if (handler != RT_NULL)
  80. {
  81. irq_desc[vector].handler = (rt_isr_handler_t)handler;
  82. irq_desc[vector].param = param;
  83. }
  84. }
  85. return old_handler;
  86. }
  87. /*@}*/