Dependencies:   Servo mbed

Fork of FYDP_Final2 by Mark Vandermeulen

Committer:
tntmarket
Date:
Wed Mar 25 09:58:50 2015 +0000
Revision:
5:d2e955a94940
Parent:
0:21019d94ad33
only imu output

Who changed what in which revision?

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