1 /** 2 * @file 3 * @brief Exclusive access lock utility functions. 4 */ 5 6 /* **************************************************************************** 7 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the "Software"), 11 * to deal in the Software without restriction, including without limitation 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 * and/or sell copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 23 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * OTHER DEALINGS IN THE SOFTWARE. 26 * 27 * Except as contained in this notice, the name of Maxim Integrated 28 * Products, Inc. shall not be used except as stated in the Maxim Integrated 29 * Products, Inc. Branding Policy. 30 * 31 * The mere transfer of this software does not imply any licenses 32 * of trade secrets, proprietary technology, copyrights, patents, 33 * trademarks, maskwork rights, or any other form of intellectual 34 * property whatsoever. Maxim Integrated Products, Inc. retains all 35 * ownership rights. 36 * 37 * $Date: 2018-08-09 18:45:02 -0500 (Thu, 09 Aug 2018) $ 38 * $Revision: 36818 $ 39 * 40 *************************************************************************** */ 41 42 /* Define to prevent redundant inclusion */ 43 #ifndef _MXC_LOCK_H_ 44 #define _MXC_LOCK_H_ 45 46 /* **** Includes **** */ 47 #include "mxc_config.h" 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /** 54 * @ingroup syscfg 55 * @defgroup mxc_lock_utilities Exclusive Access Locks 56 * @brief Lock functions to obtain and release a variable for exclusive 57 * access. These functions are marked interrupt safe if they are 58 * interrupt safe. 59 * @{ 60 */ 61 62 /* **** Definitions **** */ 63 64 /* **** Globals **** */ 65 66 /* **** Function Prototypes **** */ 67 68 /** 69 * @brief Attempts to acquire the lock. 70 * @details This in an interrupt safe function that can be used as a mutex. 71 * The lock variable must remain in scope until the lock is 72 * released. Will not block if another thread has already acquired 73 * the lock. 74 * @param lock Pointer to variable that is used for the lock. 75 * @param value Value to be place in the lock. Can not be 0. 76 * 77 * @return #E_NO_ERROR if everything successful, #E_BUSY if lock is taken. 78 */ 79 int mxc_get_lock(uint32_t *lock, uint32_t value); 80 81 /** 82 * @brief Free the given lock. 83 * @param[in,out] lock Pointer to the variable used for the lock. When the lock 84 * is free, the value pointed to by @p lock is set to zero. 85 */ 86 void mxc_free_lock(uint32_t *lock); 87 88 /**@} end of group mxc_lock_utilities */ 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 #endif /* _MXC_LOCK_H_ */ 95