IMU and knee angle. No servo yet

Dependencies:   mbed

Fork of FYDP_Final2 by Dave Lu

Committer:
tntmarket
Date:
Wed Mar 25 11:44:05 2015 +0000
Revision:
8:3d5a84b897be
Parent:
mbed/mbed-rtos/rtos/Mail.h@0:21019d94ad33
lift folders

Who changed what in which revision?

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