xLAB - acutators / led-mrf-osc_full_Latest_2

Dependencies:   addressable_leds

Dependents:   led-mrf-osc_full

Committer:
Jing_Qiu
Date:
Sat Mar 21 02:40:56 2015 +0000
Revision:
0:284274252007
111

Who changed what in which revision?

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