Alan Ffrench / Mbed 2 deprecated Experiment_2_5

Dependencies:   mbed

Committer:
alanffrench
Date:
Wed Jul 29 18:51:38 2020 +0000
Revision:
0:52468b19aa21
Threads

Who changed what in which revision?

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