The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

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