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