irq.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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",
  51. rt_interrupt_nest));
  52. level = rt_hw_interrupt_disable();
  53. rt_interrupt_nest --;
  54. rt_hw_interrupt_enable(level);
  55. }
  56. RTM_EXPORT(rt_interrupt_leave);
  57. /**
  58. * This function will return the nest of interrupt.
  59. *
  60. * User application can invoke this function to get whether current
  61. * context is interrupt context.
  62. *
  63. * @return the number of nested interrupts.
  64. */
  65. rt_uint8_t rt_interrupt_get_nest(void)
  66. {
  67. return rt_interrupt_nest;
  68. }
  69. RTM_EXPORT(rt_interrupt_get_nest);
  70. RTM_EXPORT(rt_hw_interrupt_disable);
  71. RTM_EXPORT(rt_hw_interrupt_enable);
  72. /*@}*/