J&W / Mbed 2 deprecated Rejestrator

Dependencies:   mbed Rejestrator

Dependents:   Rejestrator

Committer:
Waldek
Date:
Sat Apr 18 17:01:57 2015 +0000
Revision:
0:fa31f8461c63
working version, stop

Who changed what in which revision?

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