irq.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * File : irq.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, 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://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-02-24 Bernard first version
  13. * 2006-05-03 Bernard add IRQ_DEBUG
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. /* #define IRQ_DEBUG */
  18. /**
  19. * @addtogroup Kernel
  20. */
  21. /*@{*/
  22. volatile rt_uint8_t rt_interrupt_nest;
  23. /**
  24. * This function will be invoked by BSP, when enter interrupt service routine
  25. *
  26. * @note please don't invoke this routine in application
  27. *
  28. * @see rt_interrupt_leave
  29. */
  30. void rt_interrupt_enter(void)
  31. {
  32. rt_base_t level;
  33. RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq coming..., irq nest:%d\n",
  34. rt_interrupt_nest));
  35. level = rt_hw_interrupt_disable();
  36. rt_interrupt_nest ++;
  37. rt_hw_interrupt_enable(level);
  38. }
  39. RTM_EXPORT(rt_interrupt_enter);
  40. /**
  41. * This function will be invoked by BSP, when leave interrupt service routine
  42. *
  43. * @note please don't invoke this routine in application
  44. *
  45. * @see rt_interrupt_enter
  46. */
  47. void rt_interrupt_leave(void)
  48. {
  49. rt_base_t level;
  50. RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq leave, irq nest:%d\n", rt_interrupt_nest));
  51. level = rt_hw_interrupt_disable();
  52. rt_interrupt_nest --;
  53. rt_hw_interrupt_enable(level);
  54. }
  55. RTM_EXPORT(rt_interrupt_leave);
  56. /**
  57. * This function will return the nest of interrupt.
  58. *
  59. * User application can invoke this function to get whether current
  60. * context is interrupt context.
  61. *
  62. * @return the number of nested interrupts.
  63. */
  64. rt_uint8_t rt_interrupt_get_nest(void)
  65. {
  66. return rt_interrupt_nest;
  67. }
  68. RTM_EXPORT(rt_interrupt_get_nest);
  69. RTM_EXPORT(rt_hw_interrupt_disable);
  70. RTM_EXPORT(rt_hw_interrupt_enable);
  71. /*@}*/