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
rtos/Semaphore.cpp@0:f782d9c66c49, 2018-02-02 (annotated)
- 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?
User | Revision | Line number | New 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 | #include "rtos/Semaphore.h" |
dkato | 0:f782d9c66c49 | 23 | |
dkato | 0:f782d9c66c49 | 24 | #include <string.h> |
dkato | 0:f782d9c66c49 | 25 | |
dkato | 0:f782d9c66c49 | 26 | namespace rtos { |
dkato | 0:f782d9c66c49 | 27 | |
dkato | 0:f782d9c66c49 | 28 | Semaphore::Semaphore(int32_t count) { |
dkato | 0:f782d9c66c49 | 29 | #ifdef CMSIS_OS_RTX |
dkato | 0:f782d9c66c49 | 30 | memset(_semaphore_data, 0, sizeof(_semaphore_data)); |
dkato | 0:f782d9c66c49 | 31 | _osSemaphoreDef.semaphore = _semaphore_data; |
dkato | 0:f782d9c66c49 | 32 | #endif |
dkato | 0:f782d9c66c49 | 33 | _osSemaphoreId = osSemaphoreCreate(&_osSemaphoreDef, count); |
dkato | 0:f782d9c66c49 | 34 | } |
dkato | 0:f782d9c66c49 | 35 | |
dkato | 0:f782d9c66c49 | 36 | int32_t Semaphore::wait(uint32_t millisec) { |
dkato | 0:f782d9c66c49 | 37 | return osSemaphoreWait(_osSemaphoreId, millisec); |
dkato | 0:f782d9c66c49 | 38 | } |
dkato | 0:f782d9c66c49 | 39 | |
dkato | 0:f782d9c66c49 | 40 | osStatus Semaphore::release(void) { |
dkato | 0:f782d9c66c49 | 41 | return osSemaphoreRelease(_osSemaphoreId); |
dkato | 0:f782d9c66c49 | 42 | } |
dkato | 0:f782d9c66c49 | 43 | |
dkato | 0:f782d9c66c49 | 44 | Semaphore::~Semaphore() { |
dkato | 0:f782d9c66c49 | 45 | osSemaphoreDelete(_osSemaphoreId); |
dkato | 0:f782d9c66c49 | 46 | } |
dkato | 0:f782d9c66c49 | 47 | |
dkato | 0:f782d9c66c49 | 48 | } |