Sample program for the USB Host lib with HID

Dependencies:   USBHost_DISCO-F746NG mbed

Committer:
DieterGraef
Date:
Fri Jun 17 09:01:37 2016 +0000
Revision:
2:ca1b5b911ba8
Parent:
0:af2040964256
Demo program now uses USB Stick on high speed and HID on fast speed interface. Move your mouse!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:af2040964256 1 /* mbed Microcontroller Library
DieterGraef 0:af2040964256 2 * Copyright (c) 2006-2012 ARM Limited
DieterGraef 0:af2040964256 3 *
DieterGraef 0:af2040964256 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
DieterGraef 0:af2040964256 5 * of this software and associated documentation files (the "Software"), to deal
DieterGraef 0:af2040964256 6 * in the Software without restriction, including without limitation the rights
DieterGraef 0:af2040964256 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
DieterGraef 0:af2040964256 8 * copies of the Software, and to permit persons to whom the Software is
DieterGraef 0:af2040964256 9 * furnished to do so, subject to the following conditions:
DieterGraef 0:af2040964256 10 *
DieterGraef 0:af2040964256 11 * The above copyright notice and this permission notice shall be included in
DieterGraef 0:af2040964256 12 * all copies or substantial portions of the Software.
DieterGraef 0:af2040964256 13 *
DieterGraef 0:af2040964256 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
DieterGraef 0:af2040964256 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
DieterGraef 0:af2040964256 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
DieterGraef 0:af2040964256 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
DieterGraef 0:af2040964256 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
DieterGraef 0:af2040964256 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
DieterGraef 0:af2040964256 20 * SOFTWARE.
DieterGraef 0:af2040964256 21 */
DieterGraef 0:af2040964256 22 #ifndef THREAD_H
DieterGraef 0:af2040964256 23 #define THREAD_H
DieterGraef 0:af2040964256 24
DieterGraef 0:af2040964256 25 #include <stdint.h>
DieterGraef 0:af2040964256 26 #include "cmsis_os.h"
DieterGraef 0:af2040964256 27
DieterGraef 0:af2040964256 28 namespace rtos {
DieterGraef 0:af2040964256 29
DieterGraef 0:af2040964256 30 /** The Thread class allow defining, creating, and controlling thread functions in the system. */
DieterGraef 0:af2040964256 31 class Thread {
DieterGraef 0:af2040964256 32 public:
DieterGraef 0:af2040964256 33 /** Create a new thread, and start it executing the specified function.
DieterGraef 0:af2040964256 34 @param task function to be executed by this thread.
DieterGraef 0:af2040964256 35 @param argument pointer that is passed to the thread function as start argument. (default: NULL).
DieterGraef 0:af2040964256 36 @param priority initial priority of the thread function. (default: osPriorityNormal).
DieterGraef 0:af2040964256 37 @param stack_size stack size (in bytes) requirements for the thread function. (default: DEFAULT_STACK_SIZE).
DieterGraef 0:af2040964256 38 @param stack_pointer pointer to the stack area to be used by this thread (default: NULL).
DieterGraef 0:af2040964256 39 */
DieterGraef 0:af2040964256 40 Thread(void (*task)(void const *argument), void *argument=NULL,
DieterGraef 0:af2040964256 41 osPriority priority=osPriorityNormal,
DieterGraef 0:af2040964256 42 uint32_t stack_size=DEFAULT_STACK_SIZE,
DieterGraef 0:af2040964256 43 unsigned char *stack_pointer=NULL);
DieterGraef 0:af2040964256 44
DieterGraef 0:af2040964256 45 /** Terminate execution of a thread and remove it from Active Threads
DieterGraef 0:af2040964256 46 @return status code that indicates the execution status of the function.
DieterGraef 0:af2040964256 47 */
DieterGraef 0:af2040964256 48 osStatus terminate();
DieterGraef 0:af2040964256 49
DieterGraef 0:af2040964256 50 /** Set priority of an active thread
DieterGraef 0:af2040964256 51 @param priority new priority value for the thread function.
DieterGraef 0:af2040964256 52 @return status code that indicates the execution status of the function.
DieterGraef 0:af2040964256 53 */
DieterGraef 0:af2040964256 54 osStatus set_priority(osPriority priority);
DieterGraef 0:af2040964256 55
DieterGraef 0:af2040964256 56 /** Get priority of an active thread
DieterGraef 0:af2040964256 57 @return current priority value of the thread function.
DieterGraef 0:af2040964256 58 */
DieterGraef 0:af2040964256 59 osPriority get_priority();
DieterGraef 0:af2040964256 60
DieterGraef 0:af2040964256 61 /** Set the specified Signal Flags of an active thread.
DieterGraef 0:af2040964256 62 @param signals specifies the signal flags of the thread that should be set.
DieterGraef 0:af2040964256 63 @return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
DieterGraef 0:af2040964256 64 */
DieterGraef 0:af2040964256 65 int32_t signal_set(int32_t signals);
DieterGraef 0:af2040964256 66
DieterGraef 0:af2040964256 67 /** Clears the specified Signal Flags of an active thread.
DieterGraef 0:af2040964256 68 @param signals specifies the signal flags of the thread that should be cleared.
DieterGraef 0:af2040964256 69 @return resultant signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
DieterGraef 0:af2040964256 70 */
DieterGraef 0:af2040964256 71 int32_t signal_clr(int32_t signals);
DieterGraef 0:af2040964256 72
DieterGraef 0:af2040964256 73 /** State of the Thread */
DieterGraef 0:af2040964256 74 enum State {
DieterGraef 0:af2040964256 75 Inactive, /**< Not created or terminated */
DieterGraef 0:af2040964256 76 Ready, /**< Ready to run */
DieterGraef 0:af2040964256 77 Running, /**< Running */
DieterGraef 0:af2040964256 78 WaitingDelay, /**< Waiting for a delay to occur */
DieterGraef 0:af2040964256 79 WaitingInterval, /**< Waiting for an interval to occur */
DieterGraef 0:af2040964256 80 WaitingOr, /**< Waiting for one event in a set to occur */
DieterGraef 0:af2040964256 81 WaitingAnd, /**< Waiting for multiple events in a set to occur */
DieterGraef 0:af2040964256 82 WaitingSemaphore, /**< Waiting for a semaphore event to occur */
DieterGraef 0:af2040964256 83 WaitingMailbox, /**< Waiting for a mailbox event to occur */
DieterGraef 0:af2040964256 84 WaitingMutex, /**< Waiting for a mutex event to occur */
DieterGraef 0:af2040964256 85 };
DieterGraef 0:af2040964256 86
DieterGraef 0:af2040964256 87 /** State of this Thread
DieterGraef 0:af2040964256 88 @return the State of this Thread
DieterGraef 0:af2040964256 89 */
DieterGraef 0:af2040964256 90 State get_state();
DieterGraef 0:af2040964256 91
DieterGraef 0:af2040964256 92 /** Get the total stack memory size for this Thread
DieterGraef 0:af2040964256 93 @return the total stack memory size in bytes
DieterGraef 0:af2040964256 94 */
DieterGraef 0:af2040964256 95 uint32_t stack_size();
DieterGraef 0:af2040964256 96
DieterGraef 0:af2040964256 97 /** Get the currently unused stack memory for this Thread
DieterGraef 0:af2040964256 98 @return the currently unused stack memory in bytes
DieterGraef 0:af2040964256 99 */
DieterGraef 0:af2040964256 100 uint32_t free_stack();
DieterGraef 0:af2040964256 101
DieterGraef 0:af2040964256 102 /** Get the currently used stack memory for this Thread
DieterGraef 0:af2040964256 103 @return the currently used stack memory in bytes
DieterGraef 0:af2040964256 104 */
DieterGraef 0:af2040964256 105 uint32_t used_stack();
DieterGraef 0:af2040964256 106
DieterGraef 0:af2040964256 107 /** Get the maximum stack memory usage to date for this Thread
DieterGraef 0:af2040964256 108 @return the maximum stack memory usage to date in bytes
DieterGraef 0:af2040964256 109 */
DieterGraef 0:af2040964256 110 uint32_t max_stack();
DieterGraef 0:af2040964256 111
DieterGraef 0:af2040964256 112 /** Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
DieterGraef 0:af2040964256 113 @param signals wait until all specified signal flags set or 0 for any single signal flag.
DieterGraef 0:af2040964256 114 @param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
DieterGraef 0:af2040964256 115 @return event flag information or error code.
DieterGraef 0:af2040964256 116 */
DieterGraef 0:af2040964256 117 static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever);
DieterGraef 0:af2040964256 118
DieterGraef 0:af2040964256 119 /** Wait for a specified time period in millisec:
DieterGraef 0:af2040964256 120 @param millisec time delay value
DieterGraef 0:af2040964256 121 @return status code that indicates the execution status of the function.
DieterGraef 0:af2040964256 122 */
DieterGraef 0:af2040964256 123 static osStatus wait(uint32_t millisec);
DieterGraef 0:af2040964256 124
DieterGraef 0:af2040964256 125 /** Pass control to next thread that is in state READY.
DieterGraef 0:af2040964256 126 @return status code that indicates the execution status of the function.
DieterGraef 0:af2040964256 127 */
DieterGraef 0:af2040964256 128 static osStatus yield();
DieterGraef 0:af2040964256 129
DieterGraef 0:af2040964256 130 /** Get the thread id of the current running thread.
DieterGraef 0:af2040964256 131 @return thread ID for reference by other functions or NULL in case of error.
DieterGraef 0:af2040964256 132 */
DieterGraef 0:af2040964256 133 static osThreadId gettid();
DieterGraef 0:af2040964256 134
DieterGraef 0:af2040964256 135 /** Attach a function to be called by the RTOS idle task
DieterGraef 0:af2040964256 136 @param fptr pointer to the function to be called
DieterGraef 0:af2040964256 137 */
DieterGraef 0:af2040964256 138 static void attach_idle_hook(void (*fptr)(void));
DieterGraef 0:af2040964256 139
DieterGraef 0:af2040964256 140 virtual ~Thread();
DieterGraef 0:af2040964256 141
DieterGraef 0:af2040964256 142 private:
DieterGraef 0:af2040964256 143 osThreadId _tid;
DieterGraef 0:af2040964256 144 osThreadDef_t _thread_def;
DieterGraef 0:af2040964256 145 bool _dynamic_stack;
DieterGraef 0:af2040964256 146 };
DieterGraef 0:af2040964256 147
DieterGraef 0:af2040964256 148 }
DieterGraef 0:af2040964256 149 #endif