em_int.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Interrupt enable/disable unit API
  4. * @author Energy Micro AS
  5. * @version 3.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software.
  17. * 2. Altered source versions must be plainly marked as such, and must not be
  18. * misrepresented as being the original software.
  19. * 3. This notice may not be removed or altered from any source distribution.
  20. *
  21. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  22. * obligation to support this Software. Energy Micro AS is providing the
  23. * Software "AS IS", with no express or implied warranties of any kind,
  24. * including, but not limited to, any implied warranties of merchantability
  25. * or fitness for any particular purpose or warranties against infringement
  26. * of any proprietary rights of a third party.
  27. *
  28. * Energy Micro AS will not be liable for any consequential, incidental, or
  29. * special damages, or any other relief, or for any claim by any third party,
  30. * arising from your use of this Software.
  31. *
  32. ******************************************************************************/
  33. #ifndef __EM_INT_H
  34. #define __EM_INT_H
  35. #include "em_part.h"
  36. extern uint32_t INT_LockCnt;
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /***************************************************************************//**
  41. * @addtogroup EM_Library
  42. * @{
  43. ******************************************************************************/
  44. /***************************************************************************//**
  45. * @addtogroup INT
  46. * @{
  47. ******************************************************************************/
  48. /***************************************************************************//**
  49. * @brief
  50. * Disable interrupts.
  51. *
  52. * @return
  53. * The resulting interrupt nesting level.
  54. *
  55. * @details
  56. * Disable interrupts and increment lock level counter.
  57. *
  58. ******************************************************************************/
  59. __STATIC_INLINE uint32_t INT_Disable(void)
  60. {
  61. __disable_irq();
  62. if (INT_LockCnt < UINT32_MAX)
  63. {
  64. INT_LockCnt++;
  65. }
  66. return INT_LockCnt;
  67. }
  68. /***************************************************************************//**
  69. * @brief
  70. * Enable interrupts.
  71. *
  72. * @return
  73. * The resulting interrupt nesting level.
  74. *
  75. * @details
  76. * Decrement interrupt lock level counter and enable interrupts if counter
  77. * reached zero.
  78. *
  79. ******************************************************************************/
  80. __STATIC_INLINE uint32_t INT_Enable(void)
  81. {
  82. uint32_t retVal;
  83. if (INT_LockCnt > 0)
  84. {
  85. INT_LockCnt--;
  86. retVal = INT_LockCnt;
  87. if (retVal == 0)
  88. {
  89. __enable_irq();
  90. }
  91. return retVal;
  92. }
  93. else
  94. {
  95. return 0;
  96. }
  97. }
  98. /** @} (end addtogroup INT) */
  99. /** @} (end addtogroup EM_Library) */
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif /* __EM_INT_H */