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