Anasse Abdoul / Mbed 2 deprecated Test_MPU6050

Dependencies:   mbed

Committer:
anasse
Date:
Thu Mar 31 07:43:50 2022 +0000
Revision:
0:a59a3d743804
vers0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anasse 0:a59a3d743804 1 /* mbed Microcontroller Library
anasse 0:a59a3d743804 2 * Copyright (c) 2006-2012 ARM Limited
anasse 0:a59a3d743804 3 *
anasse 0:a59a3d743804 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
anasse 0:a59a3d743804 5 * of this software and associated documentation files (the "Software"), to deal
anasse 0:a59a3d743804 6 * in the Software without restriction, including without limitation the rights
anasse 0:a59a3d743804 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
anasse 0:a59a3d743804 8 * copies of the Software, and to permit persons to whom the Software is
anasse 0:a59a3d743804 9 * furnished to do so, subject to the following conditions:
anasse 0:a59a3d743804 10 *
anasse 0:a59a3d743804 11 * The above copyright notice and this permission notice shall be included in
anasse 0:a59a3d743804 12 * all copies or substantial portions of the Software.
anasse 0:a59a3d743804 13 *
anasse 0:a59a3d743804 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
anasse 0:a59a3d743804 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
anasse 0:a59a3d743804 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
anasse 0:a59a3d743804 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
anasse 0:a59a3d743804 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
anasse 0:a59a3d743804 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
anasse 0:a59a3d743804 20 * SOFTWARE.
anasse 0:a59a3d743804 21 */
anasse 0:a59a3d743804 22 #include "rtos/Mutex.h"
anasse 0:a59a3d743804 23
anasse 0:a59a3d743804 24 #include <string.h>
anasse 0:a59a3d743804 25 #include "platform/mbed_error.h"
anasse 0:a59a3d743804 26
anasse 0:a59a3d743804 27 namespace rtos {
anasse 0:a59a3d743804 28
anasse 0:a59a3d743804 29 Mutex::Mutex() {
anasse 0:a59a3d743804 30 #ifdef CMSIS_OS_RTX
anasse 0:a59a3d743804 31 memset(_mutex_data, 0, sizeof(_mutex_data));
anasse 0:a59a3d743804 32 _osMutexDef.mutex = _mutex_data;
anasse 0:a59a3d743804 33 #endif
anasse 0:a59a3d743804 34 _osMutexId = osMutexCreate(&_osMutexDef);
anasse 0:a59a3d743804 35 if (_osMutexId == NULL) {
anasse 0:a59a3d743804 36 error("Error initializing the mutex object\n");
anasse 0:a59a3d743804 37 }
anasse 0:a59a3d743804 38 }
anasse 0:a59a3d743804 39
anasse 0:a59a3d743804 40 osStatus Mutex::lock(uint32_t millisec) {
anasse 0:a59a3d743804 41 return osMutexWait(_osMutexId, millisec);
anasse 0:a59a3d743804 42 }
anasse 0:a59a3d743804 43
anasse 0:a59a3d743804 44 bool Mutex::trylock() {
anasse 0:a59a3d743804 45 return (osMutexWait(_osMutexId, 0) == osOK);
anasse 0:a59a3d743804 46 }
anasse 0:a59a3d743804 47
anasse 0:a59a3d743804 48 osStatus Mutex::unlock() {
anasse 0:a59a3d743804 49 return osMutexRelease(_osMutexId);
anasse 0:a59a3d743804 50 }
anasse 0:a59a3d743804 51
anasse 0:a59a3d743804 52 Mutex::~Mutex() {
anasse 0:a59a3d743804 53 osMutexDelete(_osMutexId);
anasse 0:a59a3d743804 54 }
anasse 0:a59a3d743804 55
anasse 0:a59a3d743804 56 }