5.2.1 - Updated I2C files
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
rtos/Queue.h@0:098463de4c5d, 2017-01-25 (annotated)
- Committer:
- group-onsemi
- Date:
- Wed Jan 25 20:34:15 2017 +0000
- Revision:
- 0:098463de4c5d
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-onsemi | 0:098463de4c5d | 1 | /* mbed Microcontroller Library |
group-onsemi | 0:098463de4c5d | 2 | * Copyright (c) 2006-2012 ARM Limited |
group-onsemi | 0:098463de4c5d | 3 | * |
group-onsemi | 0:098463de4c5d | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
group-onsemi | 0:098463de4c5d | 5 | * of this software and associated documentation files (the "Software"), to deal |
group-onsemi | 0:098463de4c5d | 6 | * in the Software without restriction, including without limitation the rights |
group-onsemi | 0:098463de4c5d | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
group-onsemi | 0:098463de4c5d | 8 | * copies of the Software, and to permit persons to whom the Software is |
group-onsemi | 0:098463de4c5d | 9 | * furnished to do so, subject to the following conditions: |
group-onsemi | 0:098463de4c5d | 10 | * |
group-onsemi | 0:098463de4c5d | 11 | * The above copyright notice and this permission notice shall be included in |
group-onsemi | 0:098463de4c5d | 12 | * all copies or substantial portions of the Software. |
group-onsemi | 0:098463de4c5d | 13 | * |
group-onsemi | 0:098463de4c5d | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
group-onsemi | 0:098463de4c5d | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
group-onsemi | 0:098463de4c5d | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
group-onsemi | 0:098463de4c5d | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
group-onsemi | 0:098463de4c5d | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
group-onsemi | 0:098463de4c5d | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
group-onsemi | 0:098463de4c5d | 20 | * SOFTWARE. |
group-onsemi | 0:098463de4c5d | 21 | */ |
group-onsemi | 0:098463de4c5d | 22 | #ifndef QUEUE_H |
group-onsemi | 0:098463de4c5d | 23 | #define QUEUE_H |
group-onsemi | 0:098463de4c5d | 24 | |
group-onsemi | 0:098463de4c5d | 25 | #include <stdint.h> |
group-onsemi | 0:098463de4c5d | 26 | #include <string.h> |
group-onsemi | 0:098463de4c5d | 27 | |
group-onsemi | 0:098463de4c5d | 28 | #include "cmsis_os.h" |
group-onsemi | 0:098463de4c5d | 29 | #include "platform/mbed_error.h" |
group-onsemi | 0:098463de4c5d | 30 | |
group-onsemi | 0:098463de4c5d | 31 | namespace rtos { |
group-onsemi | 0:098463de4c5d | 32 | /** \addtogroup rtos */ |
group-onsemi | 0:098463de4c5d | 33 | /** @{*/ |
group-onsemi | 0:098463de4c5d | 34 | |
group-onsemi | 0:098463de4c5d | 35 | /** The Queue class allow to control, send, receive, or wait for messages. |
group-onsemi | 0:098463de4c5d | 36 | A message can be a integer or pointer value to a certain type T that is send |
group-onsemi | 0:098463de4c5d | 37 | to a thread or interrupt service routine. |
group-onsemi | 0:098463de4c5d | 38 | @tparam T data type of a single message element. |
group-onsemi | 0:098463de4c5d | 39 | @tparam queue_sz maximum number of messages in queue. |
group-onsemi | 0:098463de4c5d | 40 | */ |
group-onsemi | 0:098463de4c5d | 41 | template<typename T, uint32_t queue_sz> |
group-onsemi | 0:098463de4c5d | 42 | class Queue { |
group-onsemi | 0:098463de4c5d | 43 | public: |
group-onsemi | 0:098463de4c5d | 44 | /** Create and initialise a message Queue. */ |
group-onsemi | 0:098463de4c5d | 45 | Queue() { |
group-onsemi | 0:098463de4c5d | 46 | #ifdef CMSIS_OS_RTX |
group-onsemi | 0:098463de4c5d | 47 | memset(_queue_q, 0, sizeof(_queue_q)); |
group-onsemi | 0:098463de4c5d | 48 | _queue_def.pool = _queue_q; |
group-onsemi | 0:098463de4c5d | 49 | _queue_def.queue_sz = queue_sz; |
group-onsemi | 0:098463de4c5d | 50 | #endif |
group-onsemi | 0:098463de4c5d | 51 | _queue_id = osMessageCreate(&_queue_def, NULL); |
group-onsemi | 0:098463de4c5d | 52 | if (_queue_id == NULL) { |
group-onsemi | 0:098463de4c5d | 53 | error("Error initialising the queue object\n"); |
group-onsemi | 0:098463de4c5d | 54 | } |
group-onsemi | 0:098463de4c5d | 55 | } |
group-onsemi | 0:098463de4c5d | 56 | |
group-onsemi | 0:098463de4c5d | 57 | /** Put a message in a Queue. |
group-onsemi | 0:098463de4c5d | 58 | @param data message pointer. |
group-onsemi | 0:098463de4c5d | 59 | @param millisec timeout value or 0 in case of no time-out. (default: 0) |
group-onsemi | 0:098463de4c5d | 60 | @return status code that indicates the execution status of the function. |
group-onsemi | 0:098463de4c5d | 61 | */ |
group-onsemi | 0:098463de4c5d | 62 | osStatus put(T* data, uint32_t millisec=0) { |
group-onsemi | 0:098463de4c5d | 63 | return osMessagePut(_queue_id, (uint32_t)data, millisec); |
group-onsemi | 0:098463de4c5d | 64 | } |
group-onsemi | 0:098463de4c5d | 65 | |
group-onsemi | 0:098463de4c5d | 66 | /** Get a message or Wait for a message from a Queue. |
group-onsemi | 0:098463de4c5d | 67 | @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
group-onsemi | 0:098463de4c5d | 68 | @return event information that includes the message and the status code. |
group-onsemi | 0:098463de4c5d | 69 | */ |
group-onsemi | 0:098463de4c5d | 70 | osEvent get(uint32_t millisec=osWaitForever) { |
group-onsemi | 0:098463de4c5d | 71 | return osMessageGet(_queue_id, millisec); |
group-onsemi | 0:098463de4c5d | 72 | } |
group-onsemi | 0:098463de4c5d | 73 | |
group-onsemi | 0:098463de4c5d | 74 | private: |
group-onsemi | 0:098463de4c5d | 75 | osMessageQId _queue_id; |
group-onsemi | 0:098463de4c5d | 76 | osMessageQDef_t _queue_def; |
group-onsemi | 0:098463de4c5d | 77 | #ifdef CMSIS_OS_RTX |
group-onsemi | 0:098463de4c5d | 78 | uint32_t _queue_q[4+(queue_sz)]; |
group-onsemi | 0:098463de4c5d | 79 | #endif |
group-onsemi | 0:098463de4c5d | 80 | }; |
group-onsemi | 0:098463de4c5d | 81 | |
group-onsemi | 0:098463de4c5d | 82 | } |
group-onsemi | 0:098463de4c5d | 83 | #endif |
group-onsemi | 0:098463de4c5d | 84 | |
group-onsemi | 0:098463de4c5d | 85 | /** @}*/ |