efm32_int.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Interrupt enable/disable unit API for EFM32.
  4. * @author Energy Micro AS
  5. * @version 2.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2011 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. ******************************************************************************/
  28. #ifndef __EFM32_INT_H
  29. #define __EFM32_INT_H
  30. #include "efm32.h"
  31. extern uint32_t INT_LockCnt;
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /***************************************************************************//**
  36. * @addtogroup EFM32_Library
  37. * @{
  38. ******************************************************************************/
  39. /***************************************************************************//**
  40. * @addtogroup INT
  41. * @{
  42. ******************************************************************************/
  43. /***************************************************************************//**
  44. * @brief
  45. * Disable interrupts.
  46. *
  47. * @return
  48. * The resulting interrupt nesting level.
  49. *
  50. * @details
  51. * Disable interrupts and increment lock level counter.
  52. *
  53. ******************************************************************************/
  54. static __INLINE uint32_t INT_Disable(void)
  55. {
  56. __disable_irq();
  57. if (INT_LockCnt < UINT32_MAX)
  58. {
  59. INT_LockCnt++;
  60. }
  61. return INT_LockCnt;
  62. }
  63. /***************************************************************************//**
  64. * @brief
  65. * Enable interrupts.
  66. *
  67. * @return
  68. * The resulting interrupt nesting level.
  69. *
  70. * @details
  71. * Decrement interrupt lock level counter and enable interrupts if counter
  72. * reached zero.
  73. *
  74. ******************************************************************************/
  75. static __INLINE uint32_t INT_Enable(void)
  76. {
  77. uint32_t retVal;
  78. if (INT_LockCnt > 0)
  79. {
  80. INT_LockCnt--;
  81. retVal = INT_LockCnt;
  82. if (retVal == 0)
  83. {
  84. __enable_irq();
  85. }
  86. return retVal;
  87. }
  88. else
  89. {
  90. return 0;
  91. }
  92. }
  93. /** @} (end addtogroup INT) */
  94. /** @} (end addtogroup EFM32_Library) */
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* __EFM32_INT_H */