Racelogic / Mbed 2 deprecated VIPS_LTC_RAW_IMU

Dependencies:   BufferedSerial FatFileSystemCpp mbed

Committer:
AndyA
Date:
Mon Jul 05 15:30:14 2021 +0000
Revision:
22:0dd9c1b5664a
First pass at adding UDP FreeD output

Who changed what in which revision?

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