Running multiple threads on mbed using RTOS

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player_appbd

Committer:
wschon
Date:
Mon Feb 29 03:46:10 2016 +0000
Revision:
4:5fdadaef5b1f
Parent:
1:2129bb91c172
fixed EVERYTHING

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wschon 1:2129bb91c172 1 /* mbed USBHost Library
wschon 1:2129bb91c172 2 * Copyright (c) 2006-2013 ARM Limited
wschon 1:2129bb91c172 3 *
wschon 1:2129bb91c172 4 * Licensed under the Apache License, Version 2.0 (the "License");
wschon 1:2129bb91c172 5 * you may not use this file except in compliance with the License.
wschon 1:2129bb91c172 6 * You may obtain a copy of the License at
wschon 1:2129bb91c172 7 *
wschon 1:2129bb91c172 8 * http://www.apache.org/licenses/LICENSE-2.0
wschon 1:2129bb91c172 9 *
wschon 1:2129bb91c172 10 * Unless required by applicable law or agreed to in writing, software
wschon 1:2129bb91c172 11 * distributed under the License is distributed on an "AS IS" BASIS,
wschon 1:2129bb91c172 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
wschon 1:2129bb91c172 13 * See the License for the specific language governing permissions and
wschon 1:2129bb91c172 14 * limitations under the License.
wschon 1:2129bb91c172 15 */
wschon 1:2129bb91c172 16
wschon 1:2129bb91c172 17 #ifndef USBENDPOINT_H
wschon 1:2129bb91c172 18 #define USBENDPOINT_H
wschon 1:2129bb91c172 19
wschon 1:2129bb91c172 20 #include "FunctionPointer.h"
wschon 1:2129bb91c172 21 #include "USBHostTypes.h"
wschon 1:2129bb91c172 22 #include "rtos.h"
wschon 1:2129bb91c172 23
wschon 1:2129bb91c172 24 class USBDeviceConnected;
wschon 1:2129bb91c172 25
wschon 1:2129bb91c172 26 /**
wschon 1:2129bb91c172 27 * USBEndpoint class
wschon 1:2129bb91c172 28 */
wschon 1:2129bb91c172 29 class USBEndpoint
wschon 1:2129bb91c172 30 {
wschon 1:2129bb91c172 31 public:
wschon 1:2129bb91c172 32 /**
wschon 1:2129bb91c172 33 * Constructor
wschon 1:2129bb91c172 34 */
wschon 1:2129bb91c172 35 USBEndpoint() {
wschon 1:2129bb91c172 36 state = USB_TYPE_FREE;
wschon 1:2129bb91c172 37 nextEp = NULL;
wschon 1:2129bb91c172 38 };
wschon 1:2129bb91c172 39
wschon 1:2129bb91c172 40 /**
wschon 1:2129bb91c172 41 * Initialize an endpoint
wschon 1:2129bb91c172 42 *
wschon 1:2129bb91c172 43 * @param hced hced associated to the endpoint
wschon 1:2129bb91c172 44 * @param type endpoint type
wschon 1:2129bb91c172 45 * @param dir endpoint direction
wschon 1:2129bb91c172 46 * @param size endpoint size
wschon 1:2129bb91c172 47 * @param ep_number endpoint number
wschon 1:2129bb91c172 48 * @param td_list array of two allocated transfer descriptors
wschon 1:2129bb91c172 49 */
wschon 1:2129bb91c172 50 void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]);
wschon 1:2129bb91c172 51
wschon 1:2129bb91c172 52 /**
wschon 1:2129bb91c172 53 * Set next token. Warning: only useful for the control endpoint
wschon 1:2129bb91c172 54 *
wschon 1:2129bb91c172 55 * @param token IN, OUT or SETUP token
wschon 1:2129bb91c172 56 */
wschon 1:2129bb91c172 57 void setNextToken(uint32_t token);
wschon 1:2129bb91c172 58
wschon 1:2129bb91c172 59 /**
wschon 1:2129bb91c172 60 * Queue an endpoint
wschon 1:2129bb91c172 61 *
wschon 1:2129bb91c172 62 * @param endpoint endpoint which will be queued in the linked list
wschon 1:2129bb91c172 63 */
wschon 1:2129bb91c172 64 void queueEndpoint(USBEndpoint * endpoint);
wschon 1:2129bb91c172 65
wschon 1:2129bb91c172 66
wschon 1:2129bb91c172 67 /**
wschon 1:2129bb91c172 68 * Queue a transfer on the endpoint
wschon 1:2129bb91c172 69 */
wschon 1:2129bb91c172 70 void queueTransfer();
wschon 1:2129bb91c172 71
wschon 1:2129bb91c172 72 /**
wschon 1:2129bb91c172 73 * Unqueue a transfer from the endpoint
wschon 1:2129bb91c172 74 *
wschon 1:2129bb91c172 75 * @param td hctd which will be unqueued
wschon 1:2129bb91c172 76 */
wschon 1:2129bb91c172 77 void unqueueTransfer(volatile HCTD * td);
wschon 1:2129bb91c172 78
wschon 1:2129bb91c172 79 /**
wschon 1:2129bb91c172 80 * Attach a member function to call when a transfer is finished
wschon 1:2129bb91c172 81 *
wschon 1:2129bb91c172 82 * @param tptr pointer to the object to call the member function on
wschon 1:2129bb91c172 83 * @param mptr pointer to the member function to be called
wschon 1:2129bb91c172 84 */
wschon 1:2129bb91c172 85 template<typename T>
wschon 1:2129bb91c172 86 inline void attach(T* tptr, void (T::*mptr)(void)) {
wschon 1:2129bb91c172 87 if((mptr != NULL) && (tptr != NULL)) {
wschon 1:2129bb91c172 88 rx.attach(tptr, mptr);
wschon 1:2129bb91c172 89 }
wschon 1:2129bb91c172 90 }
wschon 1:2129bb91c172 91
wschon 1:2129bb91c172 92 /**
wschon 1:2129bb91c172 93 * Attach a callback called when a transfer is finished
wschon 1:2129bb91c172 94 *
wschon 1:2129bb91c172 95 * @param fptr function pointer
wschon 1:2129bb91c172 96 */
wschon 1:2129bb91c172 97 inline void attach(void (*fptr)(void)) {
wschon 1:2129bb91c172 98 if(fptr != NULL) {
wschon 1:2129bb91c172 99 rx.attach(fptr);
wschon 1:2129bb91c172 100 }
wschon 1:2129bb91c172 101 }
wschon 1:2129bb91c172 102
wschon 1:2129bb91c172 103 /**
wschon 1:2129bb91c172 104 * Call the handler associted to the end of a transfer
wschon 1:2129bb91c172 105 */
wschon 1:2129bb91c172 106 inline void call() {
wschon 1:2129bb91c172 107 rx.call();
wschon 1:2129bb91c172 108 };
wschon 1:2129bb91c172 109
wschon 1:2129bb91c172 110
wschon 1:2129bb91c172 111 // setters
wschon 1:2129bb91c172 112 inline void setState(USB_TYPE st) { state = st; }
wschon 1:2129bb91c172 113 void setState(uint8_t st);
wschon 1:2129bb91c172 114 void setDeviceAddress(uint8_t addr);
wschon 1:2129bb91c172 115 inline void setLengthTransferred(int len) { transferred = len; };
wschon 1:2129bb91c172 116 void setSpeed(uint8_t speed);
wschon 1:2129bb91c172 117 void setSize(uint32_t size);
wschon 1:2129bb91c172 118 inline void setDir(ENDPOINT_DIRECTION d) { dir = d; }
wschon 1:2129bb91c172 119 inline void setIntfNb(uint8_t intf_nb_) { intf_nb = intf_nb_; };
wschon 1:2129bb91c172 120
wschon 1:2129bb91c172 121 // getters
wschon 1:2129bb91c172 122 const char * getStateString();
wschon 1:2129bb91c172 123 inline USB_TYPE getState() { return state; }
wschon 1:2129bb91c172 124 inline ENDPOINT_TYPE getType() { return type; };
wschon 1:2129bb91c172 125 inline uint8_t getDeviceAddress() { return hced->control & 0x7f; };
wschon 1:2129bb91c172 126 inline int getLengthTransferred() { return transferred; }
wschon 1:2129bb91c172 127 inline uint8_t * getBufStart() { return buf_start; }
wschon 1:2129bb91c172 128 inline uint8_t getAddress(){ return address; };
wschon 1:2129bb91c172 129 inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; };
wschon 1:2129bb91c172 130 inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); };
wschon 1:2129bb91c172 131 inline volatile HCTD** getTDList() { return td_list; };
wschon 1:2129bb91c172 132 inline volatile HCED * getHCED() { return hced; };
wschon 1:2129bb91c172 133 inline ENDPOINT_DIRECTION getDir() { return dir; }
wschon 1:2129bb91c172 134 inline volatile HCTD * getProcessedTD() { return td_current; };
wschon 1:2129bb91c172 135 inline volatile HCTD* getNextTD() { return td_current; };
wschon 1:2129bb91c172 136 inline bool isSetup() { return setup; }
wschon 1:2129bb91c172 137 inline USBEndpoint * nextEndpoint() { return (USBEndpoint*)nextEp; };
wschon 1:2129bb91c172 138 inline uint8_t getIntfNb() { return intf_nb; };
wschon 1:2129bb91c172 139
wschon 1:2129bb91c172 140 USBDeviceConnected * dev;
wschon 1:2129bb91c172 141
wschon 1:2129bb91c172 142 Queue<uint8_t, 1> ep_queue;
wschon 1:2129bb91c172 143
wschon 1:2129bb91c172 144 private:
wschon 1:2129bb91c172 145 ENDPOINT_TYPE type;
wschon 1:2129bb91c172 146 volatile USB_TYPE state;
wschon 1:2129bb91c172 147 ENDPOINT_DIRECTION dir;
wschon 1:2129bb91c172 148 bool setup;
wschon 1:2129bb91c172 149
wschon 1:2129bb91c172 150 uint8_t address;
wschon 1:2129bb91c172 151
wschon 1:2129bb91c172 152 int transfer_len;
wschon 1:2129bb91c172 153 int transferred;
wschon 1:2129bb91c172 154 uint8_t * buf_start;
wschon 1:2129bb91c172 155
wschon 1:2129bb91c172 156 FunctionPointer rx;
wschon 1:2129bb91c172 157
wschon 1:2129bb91c172 158 USBEndpoint* nextEp;
wschon 1:2129bb91c172 159
wschon 1:2129bb91c172 160 // USBEndpoint descriptor
wschon 1:2129bb91c172 161 volatile HCED * hced;
wschon 1:2129bb91c172 162
wschon 1:2129bb91c172 163 volatile HCTD * td_list[2];
wschon 1:2129bb91c172 164 volatile HCTD * td_current;
wschon 1:2129bb91c172 165 volatile HCTD * td_next;
wschon 1:2129bb91c172 166
wschon 1:2129bb91c172 167 uint8_t intf_nb;
wschon 1:2129bb91c172 168
wschon 1:2129bb91c172 169 };
wschon 1:2129bb91c172 170
wschon 1:2129bb91c172 171 #endif