local fork (temporary)
Dependents: VodafoneUSBModem_bleedingedge2
Fork of USBHostWANDongle_bleedingedge by
USBEndpoint.h
00001 /* Copyright (c) 2010-2012 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #ifndef USBENDPOINT_H 00020 #define USBENDPOINT_H 00021 00022 #include "stdint.h" 00023 #include "FunctionPointer.h" 00024 #include "USBHostTypes.h" 00025 00026 00027 enum ENDPOINT_TYPE { 00028 CONTROL_ENDPOINT = 0, 00029 ISOCHRONOUS_ENDPOINT, 00030 BULK_ENDPOINT, 00031 INTERRUPT_ENDPOINT 00032 }; 00033 00034 enum ENDPOINT_DIRECTION { 00035 OUT = 1, 00036 IN 00037 }; 00038 00039 class USBEndpoint { 00040 public: 00041 /* 00042 * Constructor 00043 */ 00044 USBEndpoint() {state = USB_TYPE_FREE; nextEp = NULL;}; 00045 00046 /* 00047 * Initialize an endpoint 00048 * 00049 * @param hced hced associated to the endpoint 00050 * @param type endpoint type 00051 * @param dir endpoint direction 00052 * @param size endpoint size 00053 * @param ep_number endpoint number 00054 */ 00055 void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); 00056 00057 /* 00058 * Set next token. Warining: only useful for the control endpoint 00059 * 00060 * @param token IN, OUT or SETUP token 00061 */ 00062 void setNextToken(uint32_t token); 00063 00064 /* 00065 * Queue an endpoint 00066 * 00067 * endpoint endpoint which will be queued in the linked list 00068 */ 00069 void queueEndpoint(USBEndpoint * endpoint); 00070 00071 /* 00072 * Get a td to be queued 00073 * 00074 * @returns td hctd which will be queued 00075 */ 00076 volatile HCTD* getNextTD(); 00077 00078 /* 00079 * Queue a transfer on the endpoint 00080 * 00081 */ 00082 void queueTransfer(); 00083 00084 /* 00085 * Get the currently processed td 00086 * 00087 * @returns td hctd that was queued 00088 */ 00089 volatile HCTD * getProcessedTD(); 00090 00091 /* 00092 * Unqueue a transfer from the endpoint 00093 * 00094 * @param td hctd which will be unqueued 00095 */ 00096 void unqueueTransfer(volatile HCTD * td); 00097 00098 /* 00099 * Return the next endpoint in the linked list 00100 * 00101 * @returns next endpoint 00102 */ 00103 USBEndpoint * nextEndpoint(); 00104 00105 /** 00106 * Attach a member function to call when a transfer is finished 00107 * 00108 * @param tptr pointer to the object to call the member function on 00109 * @param mptr pointer to the member function to be called 00110 */ 00111 template<typename T> 00112 void attach(T* tptr, void (T::*mptr)(void)) { 00113 if((mptr != NULL) && (tptr != NULL)) { 00114 rx.attach(tptr, mptr); 00115 } 00116 } 00117 00118 /** 00119 * Attach a callback called when a transfer is finished 00120 * 00121 * @param fptr function pointer 00122 */ 00123 void attach(void (*fn)(void)) { 00124 if(fn != NULL) { 00125 rx.attach(fn); 00126 } 00127 } 00128 00129 /* 00130 * Call the handler associted to the end of a transfer 00131 */ 00132 void call() { 00133 rx.call(); 00134 }; 00135 00136 00137 /* 00138 * Setters 00139 */ 00140 void setState(USB_TYPE st) {state = st;} 00141 void setDeviceAddress(uint8_t addr); 00142 void setLengthTransferred(int len); 00143 void setSpeed(uint8_t speed); 00144 void setSize(uint32_t size); 00145 void setDir(ENDPOINT_DIRECTION d) {dir = d;} 00146 00147 /* 00148 * Getters 00149 */ 00150 USB_TYPE getState() {return state;} 00151 ENDPOINT_TYPE getType(); 00152 uint8_t getDeviceAddress(); 00153 int getLengthTransferred() {return transferred;} 00154 uint32_t getBufStart(); 00155 uint32_t getSize(); 00156 volatile HCTD * getHeadTD(); 00157 volatile HCTD** getTDList(); 00158 volatile HCED * getHCED(); 00159 ENDPOINT_DIRECTION getDir() {return dir;} 00160 bool isSetup() {return setup;} 00161 00162 00163 private: 00164 ENDPOINT_TYPE type; 00165 volatile USB_TYPE state; 00166 ENDPOINT_DIRECTION dir; 00167 bool setup; 00168 00169 int transfer_len; 00170 int transferred; 00171 uint32_t buf_start; 00172 00173 FunctionPointer rx; 00174 00175 USBEndpoint* nextEp; 00176 00177 // USBEndpoint descriptor 00178 volatile HCED * hced; 00179 00180 volatile HCTD * td_list[2]; 00181 volatile HCTD * td_current; 00182 volatile HCTD * td_next; 00183 /*bool carry;*/ 00184 00185 int count; 00186 00187 }; 00188 00189 #endif
Generated on Sun Jul 17 2022 23:31:27 by 1.7.2