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