OS2

Dependents:   GYRO_MPU6050 Bluetooth_Powered_Multimeter_Using_STM32F429_and_RTOS fyp

Committer:
guilhemMBED
Date:
Mon Feb 03 13:41:14 2020 +0000
Revision:
0:a7c449cd2d5a
previous version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
guilhemMBED 0:a7c449cd2d5a 1 /* mbed Microcontroller Library
guilhemMBED 0:a7c449cd2d5a 2 * Copyright (c) 2006-2012 ARM Limited
guilhemMBED 0:a7c449cd2d5a 3 *
guilhemMBED 0:a7c449cd2d5a 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
guilhemMBED 0:a7c449cd2d5a 5 * of this software and associated documentation files (the "Software"), to deal
guilhemMBED 0:a7c449cd2d5a 6 * in the Software without restriction, including without limitation the rights
guilhemMBED 0:a7c449cd2d5a 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
guilhemMBED 0:a7c449cd2d5a 8 * copies of the Software, and to permit persons to whom the Software is
guilhemMBED 0:a7c449cd2d5a 9 * furnished to do so, subject to the following conditions:
guilhemMBED 0:a7c449cd2d5a 10 *
guilhemMBED 0:a7c449cd2d5a 11 * The above copyright notice and this permission notice shall be included in
guilhemMBED 0:a7c449cd2d5a 12 * all copies or substantial portions of the Software.
guilhemMBED 0:a7c449cd2d5a 13 *
guilhemMBED 0:a7c449cd2d5a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
guilhemMBED 0:a7c449cd2d5a 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
guilhemMBED 0:a7c449cd2d5a 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
guilhemMBED 0:a7c449cd2d5a 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
guilhemMBED 0:a7c449cd2d5a 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
guilhemMBED 0:a7c449cd2d5a 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
guilhemMBED 0:a7c449cd2d5a 20 * SOFTWARE.
guilhemMBED 0:a7c449cd2d5a 21 */
guilhemMBED 0:a7c449cd2d5a 22 #ifndef SEMAPHORE_H
guilhemMBED 0:a7c449cd2d5a 23 #define SEMAPHORE_H
guilhemMBED 0:a7c449cd2d5a 24
guilhemMBED 0:a7c449cd2d5a 25 #include <stdint.h>
guilhemMBED 0:a7c449cd2d5a 26 #include "cmsis_os.h"
guilhemMBED 0:a7c449cd2d5a 27
guilhemMBED 0:a7c449cd2d5a 28 namespace rtos {
guilhemMBED 0:a7c449cd2d5a 29 /** \addtogroup rtos */
guilhemMBED 0:a7c449cd2d5a 30 /** @{*/
guilhemMBED 0:a7c449cd2d5a 31
guilhemMBED 0:a7c449cd2d5a 32 /** The Semaphore class is used to manage and protect access to a set of shared resources. */
guilhemMBED 0:a7c449cd2d5a 33 class Semaphore {
guilhemMBED 0:a7c449cd2d5a 34 public:
guilhemMBED 0:a7c449cd2d5a 35 /** Create and Initialize a Semaphore object used for managing resources.
guilhemMBED 0:a7c449cd2d5a 36 @param number of available resources; maximum index value is (count-1). (default: 0).
guilhemMBED 0:a7c449cd2d5a 37 */
guilhemMBED 0:a7c449cd2d5a 38 Semaphore(int32_t count=0);
guilhemMBED 0:a7c449cd2d5a 39
guilhemMBED 0:a7c449cd2d5a 40 /** Wait until a Semaphore resource becomes available.
guilhemMBED 0:a7c449cd2d5a 41 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
guilhemMBED 0:a7c449cd2d5a 42 @return number of available tokens, or -1 in case of incorrect parameters
guilhemMBED 0:a7c449cd2d5a 43 */
guilhemMBED 0:a7c449cd2d5a 44 int32_t wait(uint32_t millisec=osWaitForever);
guilhemMBED 0:a7c449cd2d5a 45
guilhemMBED 0:a7c449cd2d5a 46 /** Release a Semaphore resource that was obtain with Semaphore::wait.
guilhemMBED 0:a7c449cd2d5a 47 @return status code that indicates the execution status of the function.
guilhemMBED 0:a7c449cd2d5a 48 */
guilhemMBED 0:a7c449cd2d5a 49 osStatus release(void);
guilhemMBED 0:a7c449cd2d5a 50
guilhemMBED 0:a7c449cd2d5a 51 ~Semaphore();
guilhemMBED 0:a7c449cd2d5a 52
guilhemMBED 0:a7c449cd2d5a 53 private:
guilhemMBED 0:a7c449cd2d5a 54 osSemaphoreId _osSemaphoreId;
guilhemMBED 0:a7c449cd2d5a 55 osSemaphoreDef_t _osSemaphoreDef;
guilhemMBED 0:a7c449cd2d5a 56 #ifdef CMSIS_OS_RTX
guilhemMBED 0:a7c449cd2d5a 57 uint32_t _semaphore_data[2];
guilhemMBED 0:a7c449cd2d5a 58 #endif
guilhemMBED 0:a7c449cd2d5a 59 };
guilhemMBED 0:a7c449cd2d5a 60
guilhemMBED 0:a7c449cd2d5a 61 }
guilhemMBED 0:a7c449cd2d5a 62 #endif
guilhemMBED 0:a7c449cd2d5a 63
guilhemMBED 0:a7c449cd2d5a 64 /** @}*/