うおーるぼっとをWiiリモコンでコントロールする新しいプログラムです。 以前のものより、Wiiリモコンが早く繋がる様になりました。 It is a program which controls A with the Wii remote. ※ A Bluetooth dongle and a Wii remote control are needed.

Dependencies:   USBHost mbed FATFileSystem mbed-rtos

Committer:
jksoft
Date:
Mon Jun 10 16:01:50 2013 +0000
Revision:
0:fccb789424fc
1.0

Who changed what in which revision?

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