Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Committer:
gert_lauritsen
Date:
Fri Jul 05 12:55:53 2019 +0000
Branch:
MbedBMAGThrRev
Revision:
61:52a6d0ffd8e5
dato rettel og ID i file lagt ind i version 5

Who changed what in which revision?

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