cvb
Fork of nrf51-sdk by
source/nordic_sdk/components/ble/peer_manager/pm_mutex.h@0:bc2961fa1ef0, 2016-04-06 (annotated)
- Committer:
- Jonathan Austin
- Date:
- Wed Apr 06 23:55:04 2016 +0100
- Revision:
- 0:bc2961fa1ef0
Synchronized with git rev 90647e3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
0:bc2961fa1ef0 | 1 | /* |
Jonathan Austin |
0:bc2961fa1ef0 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Jonathan Austin |
0:bc2961fa1ef0 | 3 | * All rights reserved. |
Jonathan Austin |
0:bc2961fa1ef0 | 4 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Jonathan Austin |
0:bc2961fa1ef0 | 6 | * are permitted provided that the following conditions are met: |
Jonathan Austin |
0:bc2961fa1ef0 | 7 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Jonathan Austin |
0:bc2961fa1ef0 | 9 | * list of conditions and the following disclaimer. |
Jonathan Austin |
0:bc2961fa1ef0 | 10 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Jonathan Austin |
0:bc2961fa1ef0 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Jonathan Austin |
0:bc2961fa1ef0 | 13 | * other materials provided with the distribution. |
Jonathan Austin |
0:bc2961fa1ef0 | 14 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Jonathan Austin |
0:bc2961fa1ef0 | 16 | * contributors to this software may be used to endorse or promote products |
Jonathan Austin |
0:bc2961fa1ef0 | 17 | * derived from this software without specific prior written permission. |
Jonathan Austin |
0:bc2961fa1ef0 | 18 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 19 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Jonathan Austin |
0:bc2961fa1ef0 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Jonathan Austin |
0:bc2961fa1ef0 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Jonathan Austin |
0:bc2961fa1ef0 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Jonathan Austin |
0:bc2961fa1ef0 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Jonathan Austin |
0:bc2961fa1ef0 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Jonathan Austin |
0:bc2961fa1ef0 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Jonathan Austin |
0:bc2961fa1ef0 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Jonathan Austin |
0:bc2961fa1ef0 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Jonathan Austin |
0:bc2961fa1ef0 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Jonathan Austin |
0:bc2961fa1ef0 | 30 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 31 | */ |
Jonathan Austin |
0:bc2961fa1ef0 | 32 | |
Jonathan Austin |
0:bc2961fa1ef0 | 33 | |
Jonathan Austin |
0:bc2961fa1ef0 | 34 | |
Jonathan Austin |
0:bc2961fa1ef0 | 35 | #ifndef MUTEX_H__ |
Jonathan Austin |
0:bc2961fa1ef0 | 36 | #define MUTEX_H__ |
Jonathan Austin |
0:bc2961fa1ef0 | 37 | |
Jonathan Austin |
0:bc2961fa1ef0 | 38 | |
Jonathan Austin |
0:bc2961fa1ef0 | 39 | #include <stdint.h> |
Jonathan Austin |
0:bc2961fa1ef0 | 40 | #include <stdbool.h> |
Jonathan Austin |
0:bc2961fa1ef0 | 41 | |
Jonathan Austin |
0:bc2961fa1ef0 | 42 | /** |
Jonathan Austin |
0:bc2961fa1ef0 | 43 | * @defgroup pm_mutex Mutex |
Jonathan Austin |
0:bc2961fa1ef0 | 44 | * @ingroup peer_manager |
Jonathan Austin |
0:bc2961fa1ef0 | 45 | * @{ |
Jonathan Austin |
0:bc2961fa1ef0 | 46 | * @brief An internal module of @ref peer_manager. This module provides thread-safe mutexes. |
Jonathan Austin |
0:bc2961fa1ef0 | 47 | */ |
Jonathan Austin |
0:bc2961fa1ef0 | 48 | |
Jonathan Austin |
0:bc2961fa1ef0 | 49 | |
Jonathan Austin |
0:bc2961fa1ef0 | 50 | /**@brief Defines the storage size of a specified mutex group. |
Jonathan Austin |
0:bc2961fa1ef0 | 51 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 52 | * @param number_of_mutexes the number of mutexes in the group. |
Jonathan Austin |
0:bc2961fa1ef0 | 53 | */ |
Jonathan Austin |
0:bc2961fa1ef0 | 54 | #define MUTEX_STORAGE_SIZE(number_of_mutexes) ((7 + (number_of_mutexes)) >> 3) |
Jonathan Austin |
0:bc2961fa1ef0 | 55 | |
Jonathan Austin |
0:bc2961fa1ef0 | 56 | |
Jonathan Austin |
0:bc2961fa1ef0 | 57 | /**@brief Initializes a mutex group. |
Jonathan Austin |
0:bc2961fa1ef0 | 58 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 59 | * @param[in] p_mutex Pointer to the mutex group. See @ref MUTEX_STORAGE_SIZE(). |
Jonathan Austin |
0:bc2961fa1ef0 | 60 | * @param[in] mutex_size The size of the mutex group in number of mutexes. |
Jonathan Austin |
0:bc2961fa1ef0 | 61 | */ |
Jonathan Austin |
0:bc2961fa1ef0 | 62 | void pm_mutex_init(uint8_t * p_mutex, uint16_t mutex_size); |
Jonathan Austin |
0:bc2961fa1ef0 | 63 | |
Jonathan Austin |
0:bc2961fa1ef0 | 64 | |
Jonathan Austin |
0:bc2961fa1ef0 | 65 | /**@brief Locks the mutex specified by the bit id. |
Jonathan Austin |
0:bc2961fa1ef0 | 66 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 67 | * @param[inout] p_mutex Pointer to the mutex group. |
Jonathan Austin |
0:bc2961fa1ef0 | 68 | * @param[in] mutex_bit_id The bit id of the mutex. |
Jonathan Austin |
0:bc2961fa1ef0 | 69 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 70 | * @retval true if it was possible to lock the mutex. |
Jonathan Austin |
0:bc2961fa1ef0 | 71 | * @retval false otherwise. |
Jonathan Austin |
0:bc2961fa1ef0 | 72 | */ |
Jonathan Austin |
0:bc2961fa1ef0 | 73 | bool pm_mutex_lock(uint8_t * p_mutex, uint16_t mutex_bit_id); |
Jonathan Austin |
0:bc2961fa1ef0 | 74 | |
Jonathan Austin |
0:bc2961fa1ef0 | 75 | |
Jonathan Austin |
0:bc2961fa1ef0 | 76 | /**@brief Locks the first unlocked mutex within the mutex group. |
Jonathan Austin |
0:bc2961fa1ef0 | 77 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 78 | * @param[in, out] p_mutex Pointer to the mutex group. |
Jonathan Austin |
0:bc2961fa1ef0 | 79 | * @param[in] mutex_size The size of the mutex group. |
Jonathan Austin |
0:bc2961fa1ef0 | 80 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 81 | * @return The first unlocked mutex id in the group. |
Jonathan Austin |
0:bc2961fa1ef0 | 82 | * @retval group-size if there was no unlocked mutex available. |
Jonathan Austin |
0:bc2961fa1ef0 | 83 | */ |
Jonathan Austin |
0:bc2961fa1ef0 | 84 | uint16_t pm_mutex_lock_first_available(uint8_t * p_mutex, uint16_t mutex_size); |
Jonathan Austin |
0:bc2961fa1ef0 | 85 | |
Jonathan Austin |
0:bc2961fa1ef0 | 86 | |
Jonathan Austin |
0:bc2961fa1ef0 | 87 | /**@brief Unlocks the mutex specified by the bit id. |
Jonathan Austin |
0:bc2961fa1ef0 | 88 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 89 | * @param[in, out] p_mutex Pointer to the mutex group. |
Jonathan Austin |
0:bc2961fa1ef0 | 90 | * @param[in] mutex_bit_id The bit id of the mutex. |
Jonathan Austin |
0:bc2961fa1ef0 | 91 | */ |
Jonathan Austin |
0:bc2961fa1ef0 | 92 | void pm_mutex_unlock(uint8_t * p_mutex, uint16_t mutex_bit_id); |
Jonathan Austin |
0:bc2961fa1ef0 | 93 | |
Jonathan Austin |
0:bc2961fa1ef0 | 94 | |
Jonathan Austin |
0:bc2961fa1ef0 | 95 | /**@brief Gets the locking status of the specified mutex. |
Jonathan Austin |
0:bc2961fa1ef0 | 96 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 97 | * @param[in, out] p_mutex Pointer to the mutex group. |
Jonathan Austin |
0:bc2961fa1ef0 | 98 | * @param[in] mutex_bit_id The bit id of the mutex. |
Jonathan Austin |
0:bc2961fa1ef0 | 99 | * |
Jonathan Austin |
0:bc2961fa1ef0 | 100 | * @retval true if the mutex was locked. |
Jonathan Austin |
0:bc2961fa1ef0 | 101 | * @retval false otherwise. |
Jonathan Austin |
0:bc2961fa1ef0 | 102 | */ |
Jonathan Austin |
0:bc2961fa1ef0 | 103 | bool pm_mutex_lock_status_get(uint8_t * p_mutex, uint16_t mutex_bit_id); |
Jonathan Austin |
0:bc2961fa1ef0 | 104 | |
Jonathan Austin |
0:bc2961fa1ef0 | 105 | |
Jonathan Austin |
0:bc2961fa1ef0 | 106 | #endif // MUTEX_H__ |
Jonathan Austin |
0:bc2961fa1ef0 | 107 | |
Jonathan Austin |
0:bc2961fa1ef0 | 108 | /** @} */ |