test
Fork of nrf51-sdk by
Embed:
(wiki syntax)
Show/hide line numbers
pm_mutex.h
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 00034 00035 #ifndef MUTEX_H__ 00036 #define MUTEX_H__ 00037 00038 00039 #include <stdint.h> 00040 #include <stdbool.h> 00041 00042 /** 00043 * @defgroup pm_mutex Mutex 00044 * @ingroup peer_manager 00045 * @{ 00046 * @brief An internal module of @ref peer_manager. This module provides thread-safe mutexes. 00047 */ 00048 00049 00050 /**@brief Defines the storage size of a specified mutex group. 00051 * 00052 * @param number_of_mutexes the number of mutexes in the group. 00053 */ 00054 #define MUTEX_STORAGE_SIZE(number_of_mutexes) ((7 + (number_of_mutexes)) >> 3) 00055 00056 00057 /**@brief Initializes a mutex group. 00058 * 00059 * @param[in] p_mutex Pointer to the mutex group. See @ref MUTEX_STORAGE_SIZE(). 00060 * @param[in] mutex_size The size of the mutex group in number of mutexes. 00061 */ 00062 void pm_mutex_init(uint8_t * p_mutex, uint16_t mutex_size); 00063 00064 00065 /**@brief Locks the mutex specified by the bit id. 00066 * 00067 * @param[inout] p_mutex Pointer to the mutex group. 00068 * @param[in] mutex_bit_id The bit id of the mutex. 00069 * 00070 * @retval true if it was possible to lock the mutex. 00071 * @retval false otherwise. 00072 */ 00073 bool pm_mutex_lock(uint8_t * p_mutex, uint16_t mutex_bit_id); 00074 00075 00076 /**@brief Locks the first unlocked mutex within the mutex group. 00077 * 00078 * @param[in, out] p_mutex Pointer to the mutex group. 00079 * @param[in] mutex_size The size of the mutex group. 00080 * 00081 * @return The first unlocked mutex id in the group. 00082 * @retval group-size if there was no unlocked mutex available. 00083 */ 00084 uint16_t pm_mutex_lock_first_available(uint8_t * p_mutex, uint16_t mutex_size); 00085 00086 00087 /**@brief Unlocks the mutex specified by the bit id. 00088 * 00089 * @param[in, out] p_mutex Pointer to the mutex group. 00090 * @param[in] mutex_bit_id The bit id of the mutex. 00091 */ 00092 void pm_mutex_unlock(uint8_t * p_mutex, uint16_t mutex_bit_id); 00093 00094 00095 /**@brief Gets the locking status of the specified mutex. 00096 * 00097 * @param[in, out] p_mutex Pointer to the mutex group. 00098 * @param[in] mutex_bit_id The bit id of the mutex. 00099 * 00100 * @retval true if the mutex was locked. 00101 * @retval false otherwise. 00102 */ 00103 bool pm_mutex_lock_status_get(uint8_t * p_mutex, uint16_t mutex_bit_id); 00104 00105 00106 #endif // MUTEX_H__ 00107 00108 /** @} */
Generated on Tue Jul 12 2022 15:51:28 by 1.7.2