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