local fork

Dependents:   Encrypted

Fork of mbed-rtos by mbed official

Committer:
ashleymills
Date:
Fri Apr 26 16:49:39 2013 +0000
Revision:
11:2162c1c1f255
Parent:
8:88a1a9c26ae3
tiny change due to resolution of error.h

Who changed what in which revision?

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