app_util_platform.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #include "app_util_platform.h"
  13. static uint32_t m_in_critical_region = 0;
  14. void app_util_disable_irq(void)
  15. {
  16. __disable_irq();
  17. m_in_critical_region++;
  18. }
  19. void app_util_enable_irq(void)
  20. {
  21. m_in_critical_region--;
  22. if (m_in_critical_region == 0)
  23. {
  24. __enable_irq();
  25. }
  26. }
  27. void app_util_critical_region_enter(uint8_t *p_nested)
  28. {
  29. #ifdef NRF52
  30. ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
  31. #endif
  32. #if defined(SOFTDEVICE_PRESENT)
  33. /* return value can be safely ignored */
  34. (void) sd_nvic_critical_region_enter(p_nested);
  35. #else
  36. app_util_disable_irq();
  37. #endif
  38. }
  39. void app_util_critical_region_exit(uint8_t nested)
  40. {
  41. #ifdef NRF52
  42. ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
  43. #endif
  44. #if defined(SOFTDEVICE_PRESENT)
  45. /* return value can be safely ignored */
  46. (void) sd_nvic_critical_region_exit(nested);
  47. #else
  48. app_util_enable_irq();
  49. #endif
  50. }