Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Fork of mbed-rtos by mbed official

Committer:
Maor_T
Date:
Mon Jul 04 15:22:27 2016 +0000
Revision:
108:78d11dd53a40
Parent:
40:bd07334df5b1
a

Who changed what in which revision?

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