Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
targets/TARGET_Maxim/TARGET_MAX32625/mxc/mxc_lock.h@0:098463de4c5d, 2017-01-25 (annotated)
- Committer:
- group-onsemi
- Date:
- Wed Jan 25 20:34:15 2017 +0000
- Revision:
- 0:098463de4c5d
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-onsemi | 0:098463de4c5d | 1 | /******************************************************************************* |
group-onsemi | 0:098463de4c5d | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
group-onsemi | 0:098463de4c5d | 3 | * |
group-onsemi | 0:098463de4c5d | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
group-onsemi | 0:098463de4c5d | 5 | * copy of this software and associated documentation files (the "Software"), |
group-onsemi | 0:098463de4c5d | 6 | * to deal in the Software without restriction, including without limitation |
group-onsemi | 0:098463de4c5d | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
group-onsemi | 0:098463de4c5d | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
group-onsemi | 0:098463de4c5d | 9 | * Software is furnished to do so, subject to the following conditions: |
group-onsemi | 0:098463de4c5d | 10 | * |
group-onsemi | 0:098463de4c5d | 11 | * The above copyright notice and this permission notice shall be included |
group-onsemi | 0:098463de4c5d | 12 | * in all copies or substantial portions of the Software. |
group-onsemi | 0:098463de4c5d | 13 | * |
group-onsemi | 0:098463de4c5d | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
group-onsemi | 0:098463de4c5d | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
group-onsemi | 0:098463de4c5d | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
group-onsemi | 0:098463de4c5d | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
group-onsemi | 0:098463de4c5d | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
group-onsemi | 0:098463de4c5d | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
group-onsemi | 0:098463de4c5d | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
group-onsemi | 0:098463de4c5d | 21 | * |
group-onsemi | 0:098463de4c5d | 22 | * Except as contained in this notice, the name of Maxim Integrated |
group-onsemi | 0:098463de4c5d | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
group-onsemi | 0:098463de4c5d | 24 | * Products, Inc. Branding Policy. |
group-onsemi | 0:098463de4c5d | 25 | * |
group-onsemi | 0:098463de4c5d | 26 | * The mere transfer of this software does not imply any licenses |
group-onsemi | 0:098463de4c5d | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
group-onsemi | 0:098463de4c5d | 28 | * trademarks, maskwork rights, or any other form of intellectual |
group-onsemi | 0:098463de4c5d | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
group-onsemi | 0:098463de4c5d | 30 | * ownership rights. |
group-onsemi | 0:098463de4c5d | 31 | * |
group-onsemi | 0:098463de4c5d | 32 | * $Date: 2016-03-11 11:46:37 -0600 (Fri, 11 Mar 2016) $ |
group-onsemi | 0:098463de4c5d | 33 | * $Revision: 21839 $ |
group-onsemi | 0:098463de4c5d | 34 | * |
group-onsemi | 0:098463de4c5d | 35 | ******************************************************************************/ |
group-onsemi | 0:098463de4c5d | 36 | |
group-onsemi | 0:098463de4c5d | 37 | /** |
group-onsemi | 0:098463de4c5d | 38 | * @file mxc_lock.h |
group-onsemi | 0:098463de4c5d | 39 | * @brief Used to create exclusion for critical sections. |
group-onsemi | 0:098463de4c5d | 40 | */ |
group-onsemi | 0:098463de4c5d | 41 | |
group-onsemi | 0:098463de4c5d | 42 | #ifndef _MXC_LOCK_H_ |
group-onsemi | 0:098463de4c5d | 43 | #define _MXC_LOCK_H_ |
group-onsemi | 0:098463de4c5d | 44 | |
group-onsemi | 0:098463de4c5d | 45 | #ifdef __cplusplus |
group-onsemi | 0:098463de4c5d | 46 | extern "C" { |
group-onsemi | 0:098463de4c5d | 47 | #endif |
group-onsemi | 0:098463de4c5d | 48 | |
group-onsemi | 0:098463de4c5d | 49 | /***** Includes *****/ |
group-onsemi | 0:098463de4c5d | 50 | #include "mxc_config.h" |
group-onsemi | 0:098463de4c5d | 51 | |
group-onsemi | 0:098463de4c5d | 52 | /***** Definitions *****/ |
group-onsemi | 0:098463de4c5d | 53 | |
group-onsemi | 0:098463de4c5d | 54 | /***** Globals *****/ |
group-onsemi | 0:098463de4c5d | 55 | |
group-onsemi | 0:098463de4c5d | 56 | /***** Function Prototypes *****/ |
group-onsemi | 0:098463de4c5d | 57 | |
group-onsemi | 0:098463de4c5d | 58 | /** |
group-onsemi | 0:098463de4c5d | 59 | * @brief Attempts to acquire the lock. |
group-onsemi | 0:098463de4c5d | 60 | * @param lock Pointer to variable used for the lock. |
group-onsemi | 0:098463de4c5d | 61 | * @param value Value to be place in the lock. Can not be 0. |
group-onsemi | 0:098463de4c5d | 62 | * @details This in an interrupt safe function that can be used as a mutex. |
group-onsemi | 0:098463de4c5d | 63 | The lock variable must remain in scope until the lock is released. |
group-onsemi | 0:098463de4c5d | 64 | Will not block if another thread has acquired the lock. |
group-onsemi | 0:098463de4c5d | 65 | * @returns E_NO_ERROR if everything successful, E_BUSY if lock is taken. |
group-onsemi | 0:098463de4c5d | 66 | */ |
group-onsemi | 0:098463de4c5d | 67 | __STATIC_INLINE int mxc_get_lock(uint32_t *lock, uint32_t value) |
group-onsemi | 0:098463de4c5d | 68 | { |
group-onsemi | 0:098463de4c5d | 69 | do { |
group-onsemi | 0:098463de4c5d | 70 | |
group-onsemi | 0:098463de4c5d | 71 | // Return if the lock is taken by a different thread |
group-onsemi | 0:098463de4c5d | 72 | if(__LDREXW((volatile unsigned long *)lock) != 0) { |
group-onsemi | 0:098463de4c5d | 73 | return E_BUSY; |
group-onsemi | 0:098463de4c5d | 74 | } |
group-onsemi | 0:098463de4c5d | 75 | |
group-onsemi | 0:098463de4c5d | 76 | // Attempt to take the lock |
group-onsemi | 0:098463de4c5d | 77 | } while(__STREXW(value, (volatile unsigned long *)lock) != 0); |
group-onsemi | 0:098463de4c5d | 78 | |
group-onsemi | 0:098463de4c5d | 79 | // Do not start any other memory access until memory barrier is complete |
group-onsemi | 0:098463de4c5d | 80 | __DMB(); |
group-onsemi | 0:098463de4c5d | 81 | |
group-onsemi | 0:098463de4c5d | 82 | return E_NO_ERROR; |
group-onsemi | 0:098463de4c5d | 83 | } |
group-onsemi | 0:098463de4c5d | 84 | |
group-onsemi | 0:098463de4c5d | 85 | /** |
group-onsemi | 0:098463de4c5d | 86 | * @brief Free the given lock. |
group-onsemi | 0:098463de4c5d | 87 | * @param lock Pointer to variable used for the lock. |
group-onsemi | 0:098463de4c5d | 88 | */ |
group-onsemi | 0:098463de4c5d | 89 | __STATIC_INLINE void mxc_free_lock(uint32_t *lock) |
group-onsemi | 0:098463de4c5d | 90 | { |
group-onsemi | 0:098463de4c5d | 91 | // Ensure memory operations complete before releasing lock |
group-onsemi | 0:098463de4c5d | 92 | __DMB(); |
group-onsemi | 0:098463de4c5d | 93 | *lock = 0; |
group-onsemi | 0:098463de4c5d | 94 | } |
group-onsemi | 0:098463de4c5d | 95 | |
group-onsemi | 0:098463de4c5d | 96 | #ifdef __cplusplus |
group-onsemi | 0:098463de4c5d | 97 | } |
group-onsemi | 0:098463de4c5d | 98 | #endif |
group-onsemi | 0:098463de4c5d | 99 | |
group-onsemi | 0:098463de4c5d | 100 | #endif /* _MXC_LOCK_H_ */ |