hal_mutex.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_MUTEX_H_INCLUDED
  43. #define HAL_MUTEX_H_INCLUDED
  44. #include "hal_atomic.h"
  45. /** @file
  46. * This is a simple mutex interface to be used in System Memory Manager
  47. * to make it thread aware.
  48. *
  49. * @defgroup hal_mutex HAL Mutex API
  50. * @ingroup hal_15_4
  51. * @{
  52. * @details NRF52 implementation is void and PC implementation is identical to atomic.
  53. */
  54. #if defined ( __GNUC__ )
  55. #include <signal.h>
  56. typedef volatile sig_atomic_t mutex_t;
  57. #else
  58. #include <stdint.h>
  59. typedef volatile uint32_t mutex_t;
  60. #endif
  61. /**@brief Configures mutex lock before first usage.
  62. *
  63. * @param[inout] p_mutex pointer to mutex variable.
  64. */
  65. void hal_mutex_init(mutex_t * p_mutex);
  66. /**@brief Atomically sets mutex. If set is failed, enters spin lock loop.
  67. *
  68. * @param[in] p_mutex pointer to mutex variable.
  69. */
  70. void hal_mutex_lock(mutex_t * p_mutex);
  71. /**
  72. * @brief Atomically clears mutex. Every other thread, spinning at this lock may
  73. * try to lock it afterwards.
  74. *
  75. * @param[in] p_mutex pointer to mutex variable.
  76. */
  77. void hal_mutex_unlock(mutex_t * p_mutex);
  78. /** @} */
  79. #endif /* HAL_MUTEX_H_INCLUDED */