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