irq.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2006-02-24 Bernard first version
  23. * 2006-05-03 Bernard add IRQ_DEBUG
  24. */
  25. #include <rthw.h>
  26. #include <rtthread.h>
  27. /* #define IRQ_DEBUG */
  28. /**
  29. * @addtogroup Kernel
  30. */
  31. /*@{*/
  32. volatile rt_uint8_t rt_interrupt_nest;
  33. /**
  34. * This function will be invoked by BSP, when enter interrupt service routine
  35. *
  36. * @note please don't invoke this routine in application
  37. *
  38. * @see rt_interrupt_leave
  39. */
  40. void rt_interrupt_enter(void)
  41. {
  42. rt_base_t level;
  43. RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq coming..., irq nest:%d\n",
  44. rt_interrupt_nest));
  45. level = rt_hw_interrupt_disable();
  46. rt_interrupt_nest ++;
  47. rt_hw_interrupt_enable(level);
  48. }
  49. RTM_EXPORT(rt_interrupt_enter);
  50. /**
  51. * This function will be invoked by BSP, when leave interrupt service routine
  52. *
  53. * @note please don't invoke this routine in application
  54. *
  55. * @see rt_interrupt_enter
  56. */
  57. void rt_interrupt_leave(void)
  58. {
  59. rt_base_t level;
  60. RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq leave, irq nest:%d\n",
  61. rt_interrupt_nest));
  62. level = rt_hw_interrupt_disable();
  63. rt_interrupt_nest --;
  64. rt_hw_interrupt_enable(level);
  65. }
  66. RTM_EXPORT(rt_interrupt_leave);
  67. /**
  68. * This function will return the nest of interrupt.
  69. *
  70. * User application can invoke this function to get whether current
  71. * context is interrupt context.
  72. *
  73. * @return the number of nested interrupts.
  74. */
  75. rt_uint8_t rt_interrupt_get_nest(void)
  76. {
  77. return rt_interrupt_nest;
  78. }
  79. RTM_EXPORT(rt_interrupt_get_nest);
  80. RTM_EXPORT(rt_hw_interrupt_disable);
  81. RTM_EXPORT(rt_hw_interrupt_enable);
  82. /*@}*/