Avion Radio IUT / Mbed 2 deprecated MecatroPWM

Dependencies:   mbed

Committer:
qmaker
Date:
Thu Apr 15 08:43:24 2021 +0000
Revision:
3:3bc2882232a6
Parent:
0:0d257bbf5c05
en cours de dev

Who changed what in which revision?

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