mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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