skeleton for lab1
Dependencies: AvailableMemory mbed-rtos mbed
Fork of helloaabbc by
mbed-rtos/rtos/Semaphore.cpp@0:1c8f2727e9f5, 2014-04-03 (annotated)
- Committer:
- y7jin
- Date:
- Thu Apr 03 22:56:32 2014 +0000
- Revision:
- 0:1c8f2727e9f5
hello
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
y7jin | 0:1c8f2727e9f5 | 1 | /* mbed Microcontroller Library |
y7jin | 0:1c8f2727e9f5 | 2 | * Copyright (c) 2006-2012 ARM Limited |
y7jin | 0:1c8f2727e9f5 | 3 | * |
y7jin | 0:1c8f2727e9f5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
y7jin | 0:1c8f2727e9f5 | 5 | * of this software and associated documentation files (the "Software"), to deal |
y7jin | 0:1c8f2727e9f5 | 6 | * in the Software without restriction, including without limitation the rights |
y7jin | 0:1c8f2727e9f5 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
y7jin | 0:1c8f2727e9f5 | 8 | * copies of the Software, and to permit persons to whom the Software is |
y7jin | 0:1c8f2727e9f5 | 9 | * furnished to do so, subject to the following conditions: |
y7jin | 0:1c8f2727e9f5 | 10 | * |
y7jin | 0:1c8f2727e9f5 | 11 | * The above copyright notice and this permission notice shall be included in |
y7jin | 0:1c8f2727e9f5 | 12 | * all copies or substantial portions of the Software. |
y7jin | 0:1c8f2727e9f5 | 13 | * |
y7jin | 0:1c8f2727e9f5 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
y7jin | 0:1c8f2727e9f5 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
y7jin | 0:1c8f2727e9f5 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
y7jin | 0:1c8f2727e9f5 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
y7jin | 0:1c8f2727e9f5 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
y7jin | 0:1c8f2727e9f5 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
y7jin | 0:1c8f2727e9f5 | 20 | * SOFTWARE. |
y7jin | 0:1c8f2727e9f5 | 21 | */ |
y7jin | 0:1c8f2727e9f5 | 22 | #include "Semaphore.h" |
y7jin | 0:1c8f2727e9f5 | 23 | |
y7jin | 0:1c8f2727e9f5 | 24 | #include <string.h> |
y7jin | 0:1c8f2727e9f5 | 25 | #include "error.h" |
y7jin | 0:1c8f2727e9f5 | 26 | |
y7jin | 0:1c8f2727e9f5 | 27 | namespace rtos { |
y7jin | 0:1c8f2727e9f5 | 28 | |
y7jin | 0:1c8f2727e9f5 | 29 | Semaphore::Semaphore(int32_t count) { |
y7jin | 0:1c8f2727e9f5 | 30 | #ifdef CMSIS_OS_RTX |
y7jin | 0:1c8f2727e9f5 | 31 | memset(_semaphore_data, 0, sizeof(_semaphore_data)); |
y7jin | 0:1c8f2727e9f5 | 32 | _osSemaphoreDef.semaphore = _semaphore_data; |
y7jin | 0:1c8f2727e9f5 | 33 | #endif |
y7jin | 0:1c8f2727e9f5 | 34 | _osSemaphoreId = osSemaphoreCreate(&_osSemaphoreDef, count); |
y7jin | 0:1c8f2727e9f5 | 35 | } |
y7jin | 0:1c8f2727e9f5 | 36 | |
y7jin | 0:1c8f2727e9f5 | 37 | int32_t Semaphore::wait(uint32_t millisec) { |
y7jin | 0:1c8f2727e9f5 | 38 | return osSemaphoreWait(_osSemaphoreId, millisec); |
y7jin | 0:1c8f2727e9f5 | 39 | } |
y7jin | 0:1c8f2727e9f5 | 40 | |
y7jin | 0:1c8f2727e9f5 | 41 | osStatus Semaphore::release(void) { |
y7jin | 0:1c8f2727e9f5 | 42 | return osSemaphoreRelease(_osSemaphoreId); |
y7jin | 0:1c8f2727e9f5 | 43 | } |
y7jin | 0:1c8f2727e9f5 | 44 | |
y7jin | 0:1c8f2727e9f5 | 45 | Semaphore::~Semaphore() { |
y7jin | 0:1c8f2727e9f5 | 46 | osSemaphoreDelete(_osSemaphoreId); |
y7jin | 0:1c8f2727e9f5 | 47 | } |
y7jin | 0:1c8f2727e9f5 | 48 | |
y7jin | 0:1c8f2727e9f5 | 49 | } |