mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1 /* mbed Microcontroller Library
dkato 0:f782d9c66c49 2 * Copyright (c) 2006-2012 ARM Limited
dkato 0:f782d9c66c49 3 *
dkato 0:f782d9c66c49 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
dkato 0:f782d9c66c49 5 * of this software and associated documentation files (the "Software"), to deal
dkato 0:f782d9c66c49 6 * in the Software without restriction, including without limitation the rights
dkato 0:f782d9c66c49 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
dkato 0:f782d9c66c49 8 * copies of the Software, and to permit persons to whom the Software is
dkato 0:f782d9c66c49 9 * furnished to do so, subject to the following conditions:
dkato 0:f782d9c66c49 10 *
dkato 0:f782d9c66c49 11 * The above copyright notice and this permission notice shall be included in
dkato 0:f782d9c66c49 12 * all copies or substantial portions of the Software.
dkato 0:f782d9c66c49 13 *
dkato 0:f782d9c66c49 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dkato 0:f782d9c66c49 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dkato 0:f782d9c66c49 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dkato 0:f782d9c66c49 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dkato 0:f782d9c66c49 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dkato 0:f782d9c66c49 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
dkato 0:f782d9c66c49 20 * SOFTWARE.
dkato 0:f782d9c66c49 21 */
dkato 0:f782d9c66c49 22 #ifndef MUTEX_H
dkato 0:f782d9c66c49 23 #define MUTEX_H
dkato 0:f782d9c66c49 24
dkato 0:f782d9c66c49 25 #include <stdint.h>
dkato 0:f782d9c66c49 26 #include "cmsis_os.h"
dkato 0:f782d9c66c49 27
dkato 0:f782d9c66c49 28 namespace rtos {
dkato 0:f782d9c66c49 29 /** \addtogroup rtos */
dkato 0:f782d9c66c49 30 /** @{*/
dkato 0:f782d9c66c49 31
dkato 0:f782d9c66c49 32 /** The Mutex class is used to synchronise the execution of threads.
dkato 0:f782d9c66c49 33 This is for example used to protect access to a shared resource.
dkato 0:f782d9c66c49 34 */
dkato 0:f782d9c66c49 35 class Mutex {
dkato 0:f782d9c66c49 36 public:
dkato 0:f782d9c66c49 37 /** Create and Initialize a Mutex object */
dkato 0:f782d9c66c49 38 Mutex();
dkato 0:f782d9c66c49 39
dkato 0:f782d9c66c49 40 /** Wait until a Mutex becomes available.
dkato 0:f782d9c66c49 41 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever)
dkato 0:f782d9c66c49 42 @return status code that indicates the execution status of the function.
dkato 0:f782d9c66c49 43 */
dkato 0:f782d9c66c49 44 osStatus lock(uint32_t millisec=osWaitForever);
dkato 0:f782d9c66c49 45
dkato 0:f782d9c66c49 46 /** Try to lock the mutex, and return immediately
dkato 0:f782d9c66c49 47 @return true if the mutex was acquired, false otherwise.
dkato 0:f782d9c66c49 48 */
dkato 0:f782d9c66c49 49 bool trylock();
dkato 0:f782d9c66c49 50
dkato 0:f782d9c66c49 51 /** Unlock the mutex that has previously been locked by the same thread
dkato 0:f782d9c66c49 52 @return status code that indicates the execution status of the function.
dkato 0:f782d9c66c49 53 */
dkato 0:f782d9c66c49 54 osStatus unlock();
dkato 0:f782d9c66c49 55
dkato 0:f782d9c66c49 56 ~Mutex();
dkato 0:f782d9c66c49 57
dkato 0:f782d9c66c49 58 private:
dkato 0:f782d9c66c49 59 osMutexId _osMutexId;
dkato 0:f782d9c66c49 60 osMutexDef_t _osMutexDef;
dkato 0:f782d9c66c49 61 #ifdef CMSIS_OS_RTX
dkato 0:f782d9c66c49 62 #if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
dkato 0:f782d9c66c49 63 int32_t _mutex_data[4];
dkato 0:f782d9c66c49 64 #else
dkato 0:f782d9c66c49 65 int32_t _mutex_data[3];
dkato 0:f782d9c66c49 66 #endif
dkato 0:f782d9c66c49 67 #endif
dkato 0:f782d9c66c49 68 };
dkato 0:f782d9c66c49 69
dkato 0:f782d9c66c49 70 }
dkato 0:f782d9c66c49 71 #endif
dkato 0:f782d9c66c49 72
dkato 0:f782d9c66c49 73 /** @}*/