The beta version of the Vodafone K3770 dongle driver
This library is deprecated. Please use the newest production branch of the library from https://mbed.org/users/mbed_official/code/VodafoneUSBModem/
USBHostWANDongleLib/USBHost/Endpoint.h@1:4b33ffe61bfa, 2012-11-01 (annotated)
- Committer:
- donatien
- Date:
- Thu Nov 01 10:03:50 2012 +0000
- Revision:
- 1:4b33ffe61bfa
- Parent:
- 0:0ac66acdfdc0
Deprecating library, pointing out at new one
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0ac66acdfdc0 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
donatien | 0:0ac66acdfdc0 | 2 | * |
donatien | 0:0ac66acdfdc0 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 0:0ac66acdfdc0 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
donatien | 0:0ac66acdfdc0 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
donatien | 0:0ac66acdfdc0 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
donatien | 0:0ac66acdfdc0 | 7 | * Software is furnished to do so, subject to the following conditions: |
donatien | 0:0ac66acdfdc0 | 8 | * |
donatien | 0:0ac66acdfdc0 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 0:0ac66acdfdc0 | 10 | * substantial portions of the Software. |
donatien | 0:0ac66acdfdc0 | 11 | * |
donatien | 0:0ac66acdfdc0 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 0:0ac66acdfdc0 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 0:0ac66acdfdc0 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 0:0ac66acdfdc0 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 0:0ac66acdfdc0 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 0:0ac66acdfdc0 | 17 | */ |
donatien | 0:0ac66acdfdc0 | 18 | |
donatien | 0:0ac66acdfdc0 | 19 | #ifndef ENDPOINT_H |
donatien | 0:0ac66acdfdc0 | 20 | #define ENDPOINT_H |
donatien | 0:0ac66acdfdc0 | 21 | |
donatien | 0:0ac66acdfdc0 | 22 | #include "stdint.h" |
donatien | 0:0ac66acdfdc0 | 23 | #include "FunctionPointer.h" |
donatien | 0:0ac66acdfdc0 | 24 | #include "USBHostTypes.h" |
donatien | 0:0ac66acdfdc0 | 25 | |
donatien | 0:0ac66acdfdc0 | 26 | |
donatien | 0:0ac66acdfdc0 | 27 | enum ENDPOINT_TYPE { |
donatien | 0:0ac66acdfdc0 | 28 | CONTROL_ENDPOINT = 0, |
donatien | 0:0ac66acdfdc0 | 29 | ISOCHRONOUS_ENDPOINT, |
donatien | 0:0ac66acdfdc0 | 30 | BULK_ENDPOINT, |
donatien | 0:0ac66acdfdc0 | 31 | INTERRUPT_ENDPOINT |
donatien | 0:0ac66acdfdc0 | 32 | }; |
donatien | 0:0ac66acdfdc0 | 33 | |
donatien | 0:0ac66acdfdc0 | 34 | enum ENDPOINT_DIRECTION { |
donatien | 0:0ac66acdfdc0 | 35 | OUT = 1, |
donatien | 0:0ac66acdfdc0 | 36 | IN |
donatien | 0:0ac66acdfdc0 | 37 | }; |
donatien | 0:0ac66acdfdc0 | 38 | |
donatien | 0:0ac66acdfdc0 | 39 | class Endpoint { |
donatien | 0:0ac66acdfdc0 | 40 | public: |
donatien | 0:0ac66acdfdc0 | 41 | /* |
donatien | 0:0ac66acdfdc0 | 42 | * Constructor |
donatien | 0:0ac66acdfdc0 | 43 | */ |
donatien | 0:0ac66acdfdc0 | 44 | Endpoint() {state = USB_TYPE_FREE; nextEp = NULL;}; |
donatien | 0:0ac66acdfdc0 | 45 | |
donatien | 0:0ac66acdfdc0 | 46 | /* |
donatien | 0:0ac66acdfdc0 | 47 | * Initialize an endpoint |
donatien | 0:0ac66acdfdc0 | 48 | * |
donatien | 0:0ac66acdfdc0 | 49 | * @param hced hced associated to the endpoint |
donatien | 0:0ac66acdfdc0 | 50 | * @param type endpoint type |
donatien | 0:0ac66acdfdc0 | 51 | * @param dir endpoint direction |
donatien | 0:0ac66acdfdc0 | 52 | * @param size endpoint size |
donatien | 0:0ac66acdfdc0 | 53 | * @param ep_number endpoint number |
donatien | 0:0ac66acdfdc0 | 54 | */ |
donatien | 0:0ac66acdfdc0 | 55 | void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); |
donatien | 0:0ac66acdfdc0 | 56 | |
donatien | 0:0ac66acdfdc0 | 57 | /* |
donatien | 0:0ac66acdfdc0 | 58 | * Set next token. Warining: only useful for the control endpoint |
donatien | 0:0ac66acdfdc0 | 59 | * |
donatien | 0:0ac66acdfdc0 | 60 | * @param token IN, OUT or SETUP token |
donatien | 0:0ac66acdfdc0 | 61 | */ |
donatien | 0:0ac66acdfdc0 | 62 | void setNextToken(uint32_t token); |
donatien | 0:0ac66acdfdc0 | 63 | |
donatien | 0:0ac66acdfdc0 | 64 | /* |
donatien | 0:0ac66acdfdc0 | 65 | * Queue an endpoint |
donatien | 0:0ac66acdfdc0 | 66 | * |
donatien | 0:0ac66acdfdc0 | 67 | * endpoint endpoint which will be queued in the linked list |
donatien | 0:0ac66acdfdc0 | 68 | */ |
donatien | 0:0ac66acdfdc0 | 69 | void queueEndpoint(Endpoint * endpoint); |
donatien | 0:0ac66acdfdc0 | 70 | |
donatien | 0:0ac66acdfdc0 | 71 | /* |
donatien | 0:0ac66acdfdc0 | 72 | * Get a td to be queued |
donatien | 0:0ac66acdfdc0 | 73 | * |
donatien | 0:0ac66acdfdc0 | 74 | * @returns td hctd which will be queued |
donatien | 0:0ac66acdfdc0 | 75 | */ |
donatien | 0:0ac66acdfdc0 | 76 | volatile HCTD* getNextTD(); |
donatien | 0:0ac66acdfdc0 | 77 | |
donatien | 0:0ac66acdfdc0 | 78 | /* |
donatien | 0:0ac66acdfdc0 | 79 | * Queue a transfer on the endpoint |
donatien | 0:0ac66acdfdc0 | 80 | * |
donatien | 0:0ac66acdfdc0 | 81 | */ |
donatien | 0:0ac66acdfdc0 | 82 | void queueTransfer(); |
donatien | 0:0ac66acdfdc0 | 83 | |
donatien | 0:0ac66acdfdc0 | 84 | /* |
donatien | 0:0ac66acdfdc0 | 85 | * Get the currently processed td |
donatien | 0:0ac66acdfdc0 | 86 | * |
donatien | 0:0ac66acdfdc0 | 87 | * @returns td hctd that was queued |
donatien | 0:0ac66acdfdc0 | 88 | */ |
donatien | 0:0ac66acdfdc0 | 89 | volatile HCTD * getProcessedTD(); |
donatien | 0:0ac66acdfdc0 | 90 | |
donatien | 0:0ac66acdfdc0 | 91 | /* |
donatien | 0:0ac66acdfdc0 | 92 | * Unqueue a transfer from the endpoint |
donatien | 0:0ac66acdfdc0 | 93 | * |
donatien | 0:0ac66acdfdc0 | 94 | * @param td hctd which will be unqueued |
donatien | 0:0ac66acdfdc0 | 95 | */ |
donatien | 0:0ac66acdfdc0 | 96 | void unqueueTransfer(volatile HCTD * td); |
donatien | 0:0ac66acdfdc0 | 97 | |
donatien | 0:0ac66acdfdc0 | 98 | /* |
donatien | 0:0ac66acdfdc0 | 99 | * Return the next endpoint in the linked list |
donatien | 0:0ac66acdfdc0 | 100 | * |
donatien | 0:0ac66acdfdc0 | 101 | * @returns next endpoint |
donatien | 0:0ac66acdfdc0 | 102 | */ |
donatien | 0:0ac66acdfdc0 | 103 | Endpoint * nextEndpoint(); |
donatien | 0:0ac66acdfdc0 | 104 | |
donatien | 0:0ac66acdfdc0 | 105 | /** |
donatien | 0:0ac66acdfdc0 | 106 | * Attach a member function to call when a transfer is finished |
donatien | 0:0ac66acdfdc0 | 107 | * |
donatien | 0:0ac66acdfdc0 | 108 | * @param tptr pointer to the object to call the member function on |
donatien | 0:0ac66acdfdc0 | 109 | * @param mptr pointer to the member function to be called |
donatien | 0:0ac66acdfdc0 | 110 | */ |
donatien | 0:0ac66acdfdc0 | 111 | template<typename T> |
donatien | 0:0ac66acdfdc0 | 112 | void attach(T* tptr, void (T::*mptr)(void)) { |
donatien | 0:0ac66acdfdc0 | 113 | if((mptr != NULL) && (tptr != NULL)) { |
donatien | 0:0ac66acdfdc0 | 114 | rx.attach(tptr, mptr); |
donatien | 0:0ac66acdfdc0 | 115 | } |
donatien | 0:0ac66acdfdc0 | 116 | } |
donatien | 0:0ac66acdfdc0 | 117 | |
donatien | 0:0ac66acdfdc0 | 118 | /** |
donatien | 0:0ac66acdfdc0 | 119 | * Attach a callback called when a transfer is finished |
donatien | 0:0ac66acdfdc0 | 120 | * |
donatien | 0:0ac66acdfdc0 | 121 | * @param fptr function pointer |
donatien | 0:0ac66acdfdc0 | 122 | */ |
donatien | 0:0ac66acdfdc0 | 123 | void attach(void (*fn)(void)) { |
donatien | 0:0ac66acdfdc0 | 124 | if(fn != NULL) { |
donatien | 0:0ac66acdfdc0 | 125 | rx.attach(fn); |
donatien | 0:0ac66acdfdc0 | 126 | } |
donatien | 0:0ac66acdfdc0 | 127 | } |
donatien | 0:0ac66acdfdc0 | 128 | |
donatien | 0:0ac66acdfdc0 | 129 | /* |
donatien | 0:0ac66acdfdc0 | 130 | * Call the handler associted to the end of a transfer |
donatien | 0:0ac66acdfdc0 | 131 | */ |
donatien | 0:0ac66acdfdc0 | 132 | void call() { |
donatien | 0:0ac66acdfdc0 | 133 | rx.call(); |
donatien | 0:0ac66acdfdc0 | 134 | }; |
donatien | 0:0ac66acdfdc0 | 135 | |
donatien | 0:0ac66acdfdc0 | 136 | |
donatien | 0:0ac66acdfdc0 | 137 | /* |
donatien | 0:0ac66acdfdc0 | 138 | * Setters |
donatien | 0:0ac66acdfdc0 | 139 | */ |
donatien | 0:0ac66acdfdc0 | 140 | void setState(USB_TYPE st) {state = st;} |
donatien | 0:0ac66acdfdc0 | 141 | void setDeviceAddress(uint8_t addr); |
donatien | 0:0ac66acdfdc0 | 142 | void setLengthTransferred(int len); |
donatien | 0:0ac66acdfdc0 | 143 | void setSpeed(uint8_t speed); |
donatien | 0:0ac66acdfdc0 | 144 | void setSize(uint32_t size); |
donatien | 0:0ac66acdfdc0 | 145 | void setDir(ENDPOINT_DIRECTION d) {dir = d;} |
donatien | 0:0ac66acdfdc0 | 146 | |
donatien | 0:0ac66acdfdc0 | 147 | /* |
donatien | 0:0ac66acdfdc0 | 148 | * Getters |
donatien | 0:0ac66acdfdc0 | 149 | */ |
donatien | 0:0ac66acdfdc0 | 150 | USB_TYPE getState() {return state;} |
donatien | 0:0ac66acdfdc0 | 151 | ENDPOINT_TYPE getType(); |
donatien | 0:0ac66acdfdc0 | 152 | uint8_t getDeviceAddress(); |
donatien | 0:0ac66acdfdc0 | 153 | int getLengthTransferred() {return transferred;} |
donatien | 0:0ac66acdfdc0 | 154 | uint32_t getBufStart(); |
donatien | 0:0ac66acdfdc0 | 155 | uint32_t getSize(); |
donatien | 0:0ac66acdfdc0 | 156 | volatile HCTD * getHeadTD(); |
donatien | 0:0ac66acdfdc0 | 157 | volatile HCED * getHCED(); |
donatien | 0:0ac66acdfdc0 | 158 | ENDPOINT_DIRECTION getDir() {return dir;} |
donatien | 0:0ac66acdfdc0 | 159 | bool isSetup() {return setup;} |
donatien | 0:0ac66acdfdc0 | 160 | |
donatien | 0:0ac66acdfdc0 | 161 | |
donatien | 0:0ac66acdfdc0 | 162 | private: |
donatien | 0:0ac66acdfdc0 | 163 | ENDPOINT_TYPE type; |
donatien | 0:0ac66acdfdc0 | 164 | volatile USB_TYPE state; |
donatien | 0:0ac66acdfdc0 | 165 | ENDPOINT_DIRECTION dir; |
donatien | 0:0ac66acdfdc0 | 166 | bool setup; |
donatien | 0:0ac66acdfdc0 | 167 | |
donatien | 0:0ac66acdfdc0 | 168 | int transfer_len; |
donatien | 0:0ac66acdfdc0 | 169 | int transferred; |
donatien | 0:0ac66acdfdc0 | 170 | uint32_t buf_start; |
donatien | 0:0ac66acdfdc0 | 171 | |
donatien | 0:0ac66acdfdc0 | 172 | FunctionPointer rx; |
donatien | 0:0ac66acdfdc0 | 173 | |
donatien | 0:0ac66acdfdc0 | 174 | Endpoint* nextEp; |
donatien | 0:0ac66acdfdc0 | 175 | |
donatien | 0:0ac66acdfdc0 | 176 | // Endpoint descriptor |
donatien | 0:0ac66acdfdc0 | 177 | volatile HCED * hced; |
donatien | 0:0ac66acdfdc0 | 178 | |
donatien | 0:0ac66acdfdc0 | 179 | volatile HCTD * td_list[2]; |
donatien | 0:0ac66acdfdc0 | 180 | volatile HCTD * td_current; |
donatien | 0:0ac66acdfdc0 | 181 | volatile HCTD * td_next; |
donatien | 0:0ac66acdfdc0 | 182 | /*bool carry;*/ |
donatien | 0:0ac66acdfdc0 | 183 | |
donatien | 0:0ac66acdfdc0 | 184 | int count; |
donatien | 0:0ac66acdfdc0 | 185 | |
donatien | 0:0ac66acdfdc0 | 186 | }; |
donatien | 0:0ac66acdfdc0 | 187 | |
donatien | 0:0ac66acdfdc0 | 188 | #endif |