Test1 of cmsis and IMU/AHRS (sensor BMA180,HMC5883,ITG3200) IMU/AHRS is not ok

Dependencies:   mbed

Committer:
caroe
Date:
Mon Jun 11 12:02:30 2012 +0000
Revision:
0:cb04b53e6f9b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
caroe 0:cb04b53e6f9b 1 /* Copyright (c) 2012 mbed.org */
caroe 0:cb04b53e6f9b 2 #ifndef MAIL_H
caroe 0:cb04b53e6f9b 3 #define MAIL_H
caroe 0:cb04b53e6f9b 4
caroe 0:cb04b53e6f9b 5 #include <stdint.h>
caroe 0:cb04b53e6f9b 6 #include <string.h>
caroe 0:cb04b53e6f9b 7
caroe 0:cb04b53e6f9b 8 #include "cmsis_os.h"
caroe 0:cb04b53e6f9b 9
caroe 0:cb04b53e6f9b 10 namespace rtos {
caroe 0:cb04b53e6f9b 11
caroe 0:cb04b53e6f9b 12 /*! The Mail class allow to control, send, receive, or wait for mail.
caroe 0:cb04b53e6f9b 13 A mail is a memory block that is send to a thread or interrupt service routine.
caroe 0:cb04b53e6f9b 14 \tparam T data type of a single message element.
caroe 0:cb04b53e6f9b 15 \tparam queue_sz maximum number of messages in queue.
caroe 0:cb04b53e6f9b 16 */
caroe 0:cb04b53e6f9b 17 template<typename T, uint32_t queue_sz>
caroe 0:cb04b53e6f9b 18 class Mail {
caroe 0:cb04b53e6f9b 19 public:
caroe 0:cb04b53e6f9b 20 /*! Create and Initialise Mail queue. */
caroe 0:cb04b53e6f9b 21 Mail() {
caroe 0:cb04b53e6f9b 22 #ifdef CMSIS_OS_RTX
caroe 0:cb04b53e6f9b 23 memset(_mail_q, 0, sizeof(_mail_q));
caroe 0:cb04b53e6f9b 24 _mail_p[0] = _mail_q;
caroe 0:cb04b53e6f9b 25
caroe 0:cb04b53e6f9b 26 memset(_mail_m, 0, sizeof(_mail_m));
caroe 0:cb04b53e6f9b 27 _mail_p[1] = _mail_m;
caroe 0:cb04b53e6f9b 28
caroe 0:cb04b53e6f9b 29 _mail_def.pool = _mail_p;
caroe 0:cb04b53e6f9b 30 _mail_def.queue_sz = queue_sz;
caroe 0:cb04b53e6f9b 31 _mail_def.item_sz = sizeof(T);
caroe 0:cb04b53e6f9b 32 #endif
caroe 0:cb04b53e6f9b 33 _mail_id = osMailCreate(&_mail_def, NULL);
caroe 0:cb04b53e6f9b 34 }
caroe 0:cb04b53e6f9b 35
caroe 0:cb04b53e6f9b 36 /*! Allocate a memory block of type T
caroe 0:cb04b53e6f9b 37 \param millisec timeout value or 0 in case of no time-out. (default: 0).
caroe 0:cb04b53e6f9b 38 \return pointer to memory block that can be filled with mail or NULL in case error.
caroe 0:cb04b53e6f9b 39 */
caroe 0:cb04b53e6f9b 40 T* alloc(uint32_t millisec=0) {
caroe 0:cb04b53e6f9b 41 return (T*)osMailAlloc(_mail_id, millisec);
caroe 0:cb04b53e6f9b 42 }
caroe 0:cb04b53e6f9b 43
caroe 0:cb04b53e6f9b 44 /*! Allocate a memory block of type T and set memory block to zero.
caroe 0:cb04b53e6f9b 45 \param millisec timeout value or 0 in case of no time-out. (default: 0).
caroe 0:cb04b53e6f9b 46 \return pointer to memory block that can be filled with mail or NULL in case error.
caroe 0:cb04b53e6f9b 47 */
caroe 0:cb04b53e6f9b 48 T* calloc(uint32_t millisec=0) {
caroe 0:cb04b53e6f9b 49 return (T*)osMailCAlloc(_mail_id, millisec);
caroe 0:cb04b53e6f9b 50 }
caroe 0:cb04b53e6f9b 51
caroe 0:cb04b53e6f9b 52 /*! Put a mail in the queue.
caroe 0:cb04b53e6f9b 53 \param mptr memory block previously allocated with Mail::alloc or Mail::calloc.
caroe 0:cb04b53e6f9b 54 \return status code that indicates the execution status of the function.
caroe 0:cb04b53e6f9b 55 */
caroe 0:cb04b53e6f9b 56 osStatus put(T *mptr) {
caroe 0:cb04b53e6f9b 57 return osMailPut(_mail_id, (void*)mptr);
caroe 0:cb04b53e6f9b 58 }
caroe 0:cb04b53e6f9b 59
caroe 0:cb04b53e6f9b 60 /*! Get a mail from a queue.
caroe 0:cb04b53e6f9b 61 \param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
caroe 0:cb04b53e6f9b 62 \return event that contains mail information or error code.
caroe 0:cb04b53e6f9b 63 */
caroe 0:cb04b53e6f9b 64 osEvent get(uint32_t millisec=osWaitForever) {
caroe 0:cb04b53e6f9b 65 return osMailGet(_mail_id, millisec);
caroe 0:cb04b53e6f9b 66 }
caroe 0:cb04b53e6f9b 67
caroe 0:cb04b53e6f9b 68 /*! Free a memory block from a mail.
caroe 0:cb04b53e6f9b 69 \param mptr pointer to the memory block that was obtained with Mail::get.
caroe 0:cb04b53e6f9b 70 \return status code that indicates the execution status of the function.
caroe 0:cb04b53e6f9b 71 */
caroe 0:cb04b53e6f9b 72 osStatus free(T *mptr) {
caroe 0:cb04b53e6f9b 73 return osMailFree(_mail_id, (void*)mptr);
caroe 0:cb04b53e6f9b 74 }
caroe 0:cb04b53e6f9b 75
caroe 0:cb04b53e6f9b 76 private:
caroe 0:cb04b53e6f9b 77 osMailQId _mail_id;
caroe 0:cb04b53e6f9b 78 osMailQDef_t _mail_def;
caroe 0:cb04b53e6f9b 79 #ifdef CMSIS_OS_RTX
caroe 0:cb04b53e6f9b 80 uint32_t _mail_q[4+(queue_sz)];
caroe 0:cb04b53e6f9b 81 uint32_t _mail_m[3+((sizeof(T)+3)/4)*(queue_sz)];
caroe 0:cb04b53e6f9b 82 void *_mail_p[2];
caroe 0:cb04b53e6f9b 83 #endif
caroe 0:cb04b53e6f9b 84 };
caroe 0:cb04b53e6f9b 85
caroe 0:cb04b53e6f9b 86 }
caroe 0:cb04b53e6f9b 87
caroe 0:cb04b53e6f9b 88 #endif
caroe 0:cb04b53e6f9b 89