interrupt.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <rtthread.h>
  15. #include "LPC24xx.h"
  16. #define MAX_HANDLERS 32
  17. extern rt_uint32_t rt_interrupt_nest;
  18. /* exception and interrupt handler table */
  19. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  20. rt_uint32_t rt_thread_switch_interrput_flag;
  21. /**
  22. * @addtogroup LPC2478
  23. */
  24. /*@{*/
  25. void rt_hw_interrupt_handle(int vector)
  26. {
  27. rt_kprintf("Unhandled interrupt %d occured!!!\n", vector);
  28. }
  29. void rt_hw_interrupt_init()
  30. {
  31. register int i;
  32. rt_uint32_t *vect_addr, *vect_cntl;
  33. /* initialize VIC*/
  34. VICIntEnClr = 0xffffffff;
  35. VICVectAddr = 0;
  36. VICIntSelect = 0;
  37. for ( i = 0; i < 32; i++ )
  38. {
  39. vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + i*4);
  40. vect_cntl = (rt_uint32_t *)(VIC_BASE_ADDR + 0x200 + i*4);
  41. *vect_addr = 0x0;
  42. *vect_cntl = 0xF;
  43. }
  44. /* init interrupt nest, and context in thread sp */
  45. rt_interrupt_nest = 0;
  46. rt_interrupt_from_thread = 0;
  47. rt_interrupt_to_thread = 0;
  48. rt_thread_switch_interrput_flag = 0;
  49. }
  50. void rt_hw_interrupt_mask(int vector)
  51. {
  52. VICIntEnClr = (1 << vector);
  53. }
  54. void rt_hw_interrupt_umask(int vector)
  55. {
  56. VICIntEnable = (1 << vector);
  57. }
  58. void rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler)
  59. {
  60. rt_uint32_t *vect_addr;
  61. if(vector < MAX_HANDLERS)
  62. {
  63. /* find first un-assigned VIC address for the handler */
  64. vect_addr = (rt_uint32_t *)(VIC_BASE_ADDR + 0x100 + vector*4);
  65. *vect_addr = (rt_uint32_t)new_handler; /* set interrupt vector */
  66. }
  67. }
  68. /*@}*/