1 /**
2  * @file    mxc_lock.h
3  * @brief   Exclusive access lock utility functions.
4 */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32670_MXC_LOCK_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32670_MXC_LOCK_H_
29 
30 /* **** Includes **** */
31 #include "mxc_device.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /**
38  * @ingroup    syscfg
39  * @defgroup   mxc_lock_utilities Exclusive Access Locks
40  * @brief      Lock functions to obtain and release a variable for exclusive
41  *             access. These functions are marked interrupt safe if they are
42  *             interrupt safe.
43  * @{
44  */
45 
46 /* **** Definitions **** */
47 
48 /* **** Globals **** */
49 
50 /* **** Function Prototypes **** */
51 
52 /**
53  * @brief      Attempts to acquire the lock.
54  * @details    This in an interrupt safe function that can be used as a mutex.
55  *             The lock variable must remain in scope until the lock is
56  *             released. Will not block if another thread has already acquired
57  *             the lock.
58  * @param      lock   Pointer to variable that is used for the lock.
59  * @param      value  Value to be place in the lock. Can not be 0.
60  *
61  * @return     #E_NO_ERROR if everything successful, #E_BUSY if lock is taken.
62  */
63 int MXC_GetLock(uint32_t *lock, uint32_t value);
64 
65 /**
66  * @brief         Free the given lock.
67  * @param[in,out] lock  Pointer to the variable used for the lock. When the lock
68  *                      is free, the value pointed to by @p lock is set to zero.
69  */
70 void MXC_FreeLock(uint32_t *lock);
71 
72 /**@} end of group mxc_lock_utilities */
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32670_MXC_LOCK_H_
79