Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

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