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