this hurts

Dependencies:   FFT

Committer:
annieluo2
Date:
Wed Dec 02 18:02:03 2020 +0000
Revision:
0:d6c9b09b4042
boo

Who changed what in which revision?

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