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