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