hal_atomic.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
  3. *
  4. * All Rights Reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice, this
  11. * list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form, except as embedded into a Nordic
  14. * Semiconductor ASA integrated circuit in a product or a software update for
  15. * such product, must reproduce the above copyright notice, this list of
  16. * conditions and the following disclaimer in the documentation and/or other
  17. * materials provided with the distribution.
  18. *
  19. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * 4. This software, with or without modification, must only be used with a
  24. * Nordic Semiconductor ASA integrated circuit.
  25. *
  26. * 5. Any software provided in binary form under this license must not be reverse
  27. * engineered, decompiled, modified and/or disassembled.
  28. *
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  31. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  36. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  39. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. */
  42. #ifndef HAL_ATOMIC_H_INCLUDED
  43. #define HAL_ATOMIC_H_INCLUDED
  44. #include <stdint.h>
  45. /** @file
  46. * This file contains declarations of the Atomic section routines and necessary types.
  47. *
  48. * @defgroup hal_atomic HAL Atomic API
  49. * @ingroup hal_15_4
  50. * @{
  51. * @brief Module to declare HAL Atomic API
  52. * @details The Atomic module implements atomic section interface. This is made by disabling the global interrupts,
  53. * which is a hardware dependent feature. The user may call hal_atomic_start() to open an atomic section
  54. * (disable interrupts) and hal_atomic_end() to exit from the section (restore interrupts). The algorithm
  55. * supports nesting sections.
  56. */
  57. typedef volatile uint32_t atomic_t;
  58. /**@brief Enters atomic section.
  59. *
  60. * @details Disables global interrupts.
  61. *
  62. * @param[in] p_atomic pointer to buffer to store current value of the status register.
  63. */
  64. void hal_atomic_start(atomic_t * p_atomic);
  65. /**
  66. * @brief Exits atomic section
  67. *
  68. * @details Restores status register
  69. *
  70. * @param[in] p_atomic pointer to buffer to restore current value of the status register from.
  71. */
  72. void hal_atomic_end(atomic_t * p_atomic);
  73. /** @} */
  74. #endif // HAL_ATOMIC_H_INCLUDED