Code for our FYDP -only one IMU works right now -RTOS is working

Dependencies:   mbed

Committer:
majik
Date:
Wed Mar 18 22:23:48 2015 +0000
Revision:
0:964eb6a2ef00
This is our FYDP code, but only one IMU works with the RTOS.

Who changed what in which revision?

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