ソースの整理中ですが、利用はできます。 大きなファイルはできないかもしれません。
Dependencies: EthernetInterface HttpServer TextLCD expatlib mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip
Fork of giken9_HTMLServer_Sample by
mbed-rtos/rtos/Mail.h@2:6f25f8327180, 2014-03-12 (annotated)
- Committer:
- yueee_yt
- Date:
- Wed Mar 12 06:30:30 2014 +0000
- Revision:
- 2:6f25f8327180
- Parent:
- 0:7766f6712673
debug comment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:7766f6712673 | 1 | /* mbed Microcontroller Library |
yueee_yt | 0:7766f6712673 | 2 | * Copyright (c) 2006-2012 ARM Limited |
yueee_yt | 0:7766f6712673 | 3 | * |
yueee_yt | 0:7766f6712673 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
yueee_yt | 0:7766f6712673 | 5 | * of this software and associated documentation files (the "Software"), to deal |
yueee_yt | 0:7766f6712673 | 6 | * in the Software without restriction, including without limitation the rights |
yueee_yt | 0:7766f6712673 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
yueee_yt | 0:7766f6712673 | 8 | * copies of the Software, and to permit persons to whom the Software is |
yueee_yt | 0:7766f6712673 | 9 | * furnished to do so, subject to the following conditions: |
yueee_yt | 0:7766f6712673 | 10 | * |
yueee_yt | 0:7766f6712673 | 11 | * The above copyright notice and this permission notice shall be included in |
yueee_yt | 0:7766f6712673 | 12 | * all copies or substantial portions of the Software. |
yueee_yt | 0:7766f6712673 | 13 | * |
yueee_yt | 0:7766f6712673 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
yueee_yt | 0:7766f6712673 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
yueee_yt | 0:7766f6712673 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
yueee_yt | 0:7766f6712673 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
yueee_yt | 0:7766f6712673 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
yueee_yt | 0:7766f6712673 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
yueee_yt | 0:7766f6712673 | 20 | * SOFTWARE. |
yueee_yt | 0:7766f6712673 | 21 | */ |
yueee_yt | 0:7766f6712673 | 22 | #ifndef MAIL_H |
yueee_yt | 0:7766f6712673 | 23 | #define MAIL_H |
yueee_yt | 0:7766f6712673 | 24 | |
yueee_yt | 0:7766f6712673 | 25 | #include <stdint.h> |
yueee_yt | 0:7766f6712673 | 26 | #include <string.h> |
yueee_yt | 0:7766f6712673 | 27 | |
yueee_yt | 0:7766f6712673 | 28 | #include "cmsis_os.h" |
yueee_yt | 0:7766f6712673 | 29 | |
yueee_yt | 0:7766f6712673 | 30 | namespace rtos { |
yueee_yt | 0:7766f6712673 | 31 | |
yueee_yt | 0:7766f6712673 | 32 | /** The Mail class allow to control, send, receive, or wait for mail. |
yueee_yt | 0:7766f6712673 | 33 | A mail is a memory block that is send to a thread or interrupt service routine. |
yueee_yt | 0:7766f6712673 | 34 | @tparam T data type of a single message element. |
yueee_yt | 0:7766f6712673 | 35 | @tparam queue_sz maximum number of messages in queue. |
yueee_yt | 0:7766f6712673 | 36 | */ |
yueee_yt | 0:7766f6712673 | 37 | template<typename T, uint32_t queue_sz> |
yueee_yt | 0:7766f6712673 | 38 | class Mail { |
yueee_yt | 0:7766f6712673 | 39 | public: |
yueee_yt | 0:7766f6712673 | 40 | /** Create and Initialise Mail queue. */ |
yueee_yt | 0:7766f6712673 | 41 | Mail() { |
yueee_yt | 0:7766f6712673 | 42 | #ifdef CMSIS_OS_RTX |
yueee_yt | 0:7766f6712673 | 43 | memset(_mail_q, 0, sizeof(_mail_q)); |
yueee_yt | 0:7766f6712673 | 44 | _mail_p[0] = _mail_q; |
yueee_yt | 0:7766f6712673 | 45 | |
yueee_yt | 0:7766f6712673 | 46 | memset(_mail_m, 0, sizeof(_mail_m)); |
yueee_yt | 0:7766f6712673 | 47 | _mail_p[1] = _mail_m; |
yueee_yt | 0:7766f6712673 | 48 | |
yueee_yt | 0:7766f6712673 | 49 | _mail_def.pool = _mail_p; |
yueee_yt | 0:7766f6712673 | 50 | _mail_def.queue_sz = queue_sz; |
yueee_yt | 0:7766f6712673 | 51 | _mail_def.item_sz = sizeof(T); |
yueee_yt | 0:7766f6712673 | 52 | #endif |
yueee_yt | 0:7766f6712673 | 53 | _mail_id = osMailCreate(&_mail_def, NULL); |
yueee_yt | 0:7766f6712673 | 54 | } |
yueee_yt | 0:7766f6712673 | 55 | |
yueee_yt | 0:7766f6712673 | 56 | /** Allocate a memory block of type T |
yueee_yt | 0:7766f6712673 | 57 | @param millisec timeout value or 0 in case of no time-out. (default: 0). |
yueee_yt | 0:7766f6712673 | 58 | @return pointer to memory block that can be filled with mail or NULL in case error. |
yueee_yt | 0:7766f6712673 | 59 | */ |
yueee_yt | 0:7766f6712673 | 60 | T* alloc(uint32_t millisec=0) { |
yueee_yt | 0:7766f6712673 | 61 | return (T*)osMailAlloc(_mail_id, millisec); |
yueee_yt | 0:7766f6712673 | 62 | } |
yueee_yt | 0:7766f6712673 | 63 | |
yueee_yt | 0:7766f6712673 | 64 | /** Allocate a memory block of type T and set memory block to zero. |
yueee_yt | 0:7766f6712673 | 65 | @param millisec timeout value or 0 in case of no time-out. (default: 0). |
yueee_yt | 0:7766f6712673 | 66 | @return pointer to memory block that can be filled with mail or NULL in case error. |
yueee_yt | 0:7766f6712673 | 67 | */ |
yueee_yt | 0:7766f6712673 | 68 | T* calloc(uint32_t millisec=0) { |
yueee_yt | 0:7766f6712673 | 69 | return (T*)osMailCAlloc(_mail_id, millisec); |
yueee_yt | 0:7766f6712673 | 70 | } |
yueee_yt | 0:7766f6712673 | 71 | |
yueee_yt | 0:7766f6712673 | 72 | /** Put a mail in the queue. |
yueee_yt | 0:7766f6712673 | 73 | @param mptr memory block previously allocated with Mail::alloc or Mail::calloc. |
yueee_yt | 0:7766f6712673 | 74 | @return status code that indicates the execution status of the function. |
yueee_yt | 0:7766f6712673 | 75 | */ |
yueee_yt | 0:7766f6712673 | 76 | osStatus put(T *mptr) { |
yueee_yt | 0:7766f6712673 | 77 | return osMailPut(_mail_id, (void*)mptr); |
yueee_yt | 0:7766f6712673 | 78 | } |
yueee_yt | 0:7766f6712673 | 79 | |
yueee_yt | 0:7766f6712673 | 80 | /** Get a mail from a queue. |
yueee_yt | 0:7766f6712673 | 81 | @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever). |
yueee_yt | 0:7766f6712673 | 82 | @return event that contains mail information or error code. |
yueee_yt | 0:7766f6712673 | 83 | */ |
yueee_yt | 0:7766f6712673 | 84 | osEvent get(uint32_t millisec=osWaitForever) { |
yueee_yt | 0:7766f6712673 | 85 | return osMailGet(_mail_id, millisec); |
yueee_yt | 0:7766f6712673 | 86 | } |
yueee_yt | 0:7766f6712673 | 87 | |
yueee_yt | 0:7766f6712673 | 88 | /** Free a memory block from a mail. |
yueee_yt | 0:7766f6712673 | 89 | @param mptr pointer to the memory block that was obtained with Mail::get. |
yueee_yt | 0:7766f6712673 | 90 | @return status code that indicates the execution status of the function. |
yueee_yt | 0:7766f6712673 | 91 | */ |
yueee_yt | 0:7766f6712673 | 92 | osStatus free(T *mptr) { |
yueee_yt | 0:7766f6712673 | 93 | return osMailFree(_mail_id, (void*)mptr); |
yueee_yt | 0:7766f6712673 | 94 | } |
yueee_yt | 0:7766f6712673 | 95 | |
yueee_yt | 0:7766f6712673 | 96 | private: |
yueee_yt | 0:7766f6712673 | 97 | osMailQId _mail_id; |
yueee_yt | 0:7766f6712673 | 98 | osMailQDef_t _mail_def; |
yueee_yt | 0:7766f6712673 | 99 | #ifdef CMSIS_OS_RTX |
yueee_yt | 0:7766f6712673 | 100 | uint32_t _mail_q[4+(queue_sz)]; |
yueee_yt | 0:7766f6712673 | 101 | uint32_t _mail_m[3+((sizeof(T)+3)/4)*(queue_sz)]; |
yueee_yt | 0:7766f6712673 | 102 | void *_mail_p[2]; |
yueee_yt | 0:7766f6712673 | 103 | #endif |
yueee_yt | 0:7766f6712673 | 104 | }; |
yueee_yt | 0:7766f6712673 | 105 | |
yueee_yt | 0:7766f6712673 | 106 | } |
yueee_yt | 0:7766f6712673 | 107 | |
yueee_yt | 0:7766f6712673 | 108 | #endif |
yueee_yt | 0:7766f6712673 | 109 |