Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
segundo 0:ac1725ba162c 1
segundo 0:ac1725ba162c 2 /*
segundo 0:ac1725ba162c 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
segundo 0:ac1725ba162c 4
segundo 0:ac1725ba162c 5 Permission is hereby granted, free of charge, to any person obtaining a copy
segundo 0:ac1725ba162c 6 of this software and associated documentation files (the "Software"), to deal
segundo 0:ac1725ba162c 7 in the Software without restriction, including without limitation the rights
segundo 0:ac1725ba162c 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
segundo 0:ac1725ba162c 9 copies of the Software, and to permit persons to whom the Software is
segundo 0:ac1725ba162c 10 furnished to do so, subject to the following conditions:
segundo 0:ac1725ba162c 11
segundo 0:ac1725ba162c 12 The above copyright notice and this permission notice shall be included in
segundo 0:ac1725ba162c 13 all copies or substantial portions of the Software.
segundo 0:ac1725ba162c 14
segundo 0:ac1725ba162c 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
segundo 0:ac1725ba162c 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
segundo 0:ac1725ba162c 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
segundo 0:ac1725ba162c 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
segundo 0:ac1725ba162c 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
segundo 0:ac1725ba162c 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
segundo 0:ac1725ba162c 21 THE SOFTWARE.
segundo 0:ac1725ba162c 22 */
segundo 0:ac1725ba162c 23
segundo 0:ac1725ba162c 24 #include "UsbEndpoint.h"
segundo 0:ac1725ba162c 25
segundo 0:ac1725ba162c 26 #include "UsbDevice.h"
segundo 0:ac1725ba162c 27
segundo 0:ac1725ba162c 28 #include "usb_mem.h"
segundo 0:ac1725ba162c 29
segundo 0:ac1725ba162c 30 #include "netCfg.h"
segundo 0:ac1725ba162c 31 #if NET_USB
segundo 0:ac1725ba162c 32
segundo 0:ac1725ba162c 33 //#define __DEBUG
segundo 0:ac1725ba162c 34 #include "dbg/dbg.h"
segundo 0:ac1725ba162c 35
segundo 0:ac1725ba162c 36 UsbEndpoint::UsbEndpoint( UsbDevice* pDevice, uint8_t ep, bool dir, UsbEndpointType type, uint16_t size, int addr /*= -1*/ ) : m_pDevice(pDevice), m_result(true), m_status((int)USBERR_OK), m_len(0), m_pBufStartPtr(NULL),
segundo 0:ac1725ba162c 37 m_pCbItem(NULL), m_pCbMeth(NULL), m_pNextEp(NULL)
segundo 0:ac1725ba162c 38 {
segundo 0:ac1725ba162c 39 //Insert into Eps list
segundo 0:ac1725ba162c 40 //FIXME: Assert that no USB interrupt is triggered meanwhile
segundo 0:ac1725ba162c 41 if(m_pHeadEp)
segundo 0:ac1725ba162c 42 {
segundo 0:ac1725ba162c 43 m_pNextEp = m_pHeadEp;
segundo 0:ac1725ba162c 44 m_pHeadEp = this;
segundo 0:ac1725ba162c 45 }
segundo 0:ac1725ba162c 46 else
segundo 0:ac1725ba162c 47 {
segundo 0:ac1725ba162c 48 m_pNextEp = NULL;
segundo 0:ac1725ba162c 49 m_pHeadEp = this;
segundo 0:ac1725ba162c 50 }
segundo 0:ac1725ba162c 51
segundo 0:ac1725ba162c 52 m_pEd = (volatile HCED*)usb_get_ed();
segundo 0:ac1725ba162c 53
segundo 0:ac1725ba162c 54 m_pTdHead = (volatile HCTD*)usb_get_td();
segundo 0:ac1725ba162c 55 m_pTdTail = (volatile HCTD*)usb_get_td();
segundo 0:ac1725ba162c 56
segundo 0:ac1725ba162c 57 //printf("\r\n--m_pEd = %p--\r\n", m_pEd);
segundo 0:ac1725ba162c 58 DBG("m_pEd = %p\n", m_pEd);
segundo 0:ac1725ba162c 59 DBG("m_pTdHead = %p\n", m_pTdHead);
segundo 0:ac1725ba162c 60 DBG("m_pTdTail = %p\n", m_pTdTail);
segundo 0:ac1725ba162c 61
segundo 0:ac1725ba162c 62 //Init Ed & Td
segundo 0:ac1725ba162c 63 //printf("\r\n--Ep Init--\r\n");
segundo 0:ac1725ba162c 64 memset((void*)m_pEd, 0, sizeof(HCED));
segundo 0:ac1725ba162c 65 //printf("\r\n--Td Init--\r\n");
segundo 0:ac1725ba162c 66
segundo 0:ac1725ba162c 67 memset((void*)m_pTdHead, 0, sizeof(HCTD));
segundo 0:ac1725ba162c 68 memset((void*)m_pTdTail, 0, sizeof(HCTD));
segundo 0:ac1725ba162c 69
segundo 0:ac1725ba162c 70 if(addr == -1)
segundo 0:ac1725ba162c 71 addr = pDevice->m_addr;
segundo 0:ac1725ba162c 72
segundo 0:ac1725ba162c 73 //Setup Ed
segundo 0:ac1725ba162c 74 //printf("\r\n--Ep Setup--\r\n");
segundo 0:ac1725ba162c 75 m_pEd->Control = addr | /* USB address */
segundo 0:ac1725ba162c 76 ((ep & 0x7F) << 7) | /* Endpoint address */
segundo 0:ac1725ba162c 77 (type!=USB_CONTROL?((dir?2:1) << 11):0) | /* direction : Out = 1, 2 = In */
segundo 0:ac1725ba162c 78 (size << 16); /* MaxPkt Size */
segundo 0:ac1725ba162c 79
segundo 0:ac1725ba162c 80 m_dir = dir;
segundo 0:ac1725ba162c 81 m_setup = false;
segundo 0:ac1725ba162c 82 m_type = type;
segundo 0:ac1725ba162c 83
segundo 0:ac1725ba162c 84 m_pEd->TailTd = m_pEd->HeadTd = (uint32_t) m_pTdTail; //Empty TD list
segundo 0:ac1725ba162c 85
segundo 0:ac1725ba162c 86 DBG("Before link\n");
segundo 0:ac1725ba162c 87
segundo 0:ac1725ba162c 88 //printf("\r\n--Ep Reg--\r\n");
segundo 0:ac1725ba162c 89 //Append Ed to Ed list
segundo 0:ac1725ba162c 90 volatile HCED* prevEd;
segundo 0:ac1725ba162c 91 switch( m_type )
segundo 0:ac1725ba162c 92 {
segundo 0:ac1725ba162c 93 case USB_CONTROL:
segundo 0:ac1725ba162c 94 prevEd = (volatile HCED*) LPC_USB->HcControlHeadED;
segundo 0:ac1725ba162c 95 break;
segundo 0:ac1725ba162c 96 case USB_BULK:
segundo 0:ac1725ba162c 97 default:
segundo 0:ac1725ba162c 98 prevEd = (volatile HCED*) LPC_USB->HcBulkHeadED;
segundo 0:ac1725ba162c 99 break;
segundo 0:ac1725ba162c 100 }
segundo 0:ac1725ba162c 101
segundo 0:ac1725ba162c 102 DBG("prevEd is %p\n", prevEd);
segundo 0:ac1725ba162c 103
segundo 0:ac1725ba162c 104 if(prevEd)
segundo 0:ac1725ba162c 105 {
segundo 0:ac1725ba162c 106 DBG("prevEd set\n")
segundo 0:ac1725ba162c 107
segundo 0:ac1725ba162c 108 while(prevEd->Next)
segundo 0:ac1725ba162c 109 {
segundo 0:ac1725ba162c 110 DBG("prevEd->Next = %08x\n", prevEd->Next);
segundo 0:ac1725ba162c 111 prevEd = (volatile HCED*) prevEd->Next;
segundo 0:ac1725ba162c 112 }
segundo 0:ac1725ba162c 113 prevEd->Next = (uint32_t) m_pEd;
segundo 0:ac1725ba162c 114
segundo 0:ac1725ba162c 115 }
segundo 0:ac1725ba162c 116 else
segundo 0:ac1725ba162c 117 {
segundo 0:ac1725ba162c 118 switch( m_type )
segundo 0:ac1725ba162c 119 {
segundo 0:ac1725ba162c 120 case USB_CONTROL:
segundo 0:ac1725ba162c 121 LPC_USB->HcControlHeadED = (uint32_t) m_pEd;
segundo 0:ac1725ba162c 122 break;
segundo 0:ac1725ba162c 123 case USB_BULK:
segundo 0:ac1725ba162c 124 default:
segundo 0:ac1725ba162c 125 LPC_USB->HcBulkHeadED = (uint32_t) m_pEd;
segundo 0:ac1725ba162c 126 break;
segundo 0:ac1725ba162c 127 }
segundo 0:ac1725ba162c 128 }
segundo 0:ac1725ba162c 129
segundo 0:ac1725ba162c 130 DBG("Ep init\n");
segundo 0:ac1725ba162c 131 }
segundo 0:ac1725ba162c 132
segundo 0:ac1725ba162c 133 UsbEndpoint::~UsbEndpoint()
segundo 0:ac1725ba162c 134 {
segundo 0:ac1725ba162c 135 //Remove from Eps list
segundo 0:ac1725ba162c 136 //FIXME: Assert that no USB interrupt is triggered meanwhile
segundo 0:ac1725ba162c 137 if(m_pHeadEp != this)
segundo 0:ac1725ba162c 138 {
segundo 0:ac1725ba162c 139 UsbEndpoint* prevEp = m_pHeadEp;
segundo 0:ac1725ba162c 140 while(prevEp->m_pNextEp != this)
segundo 0:ac1725ba162c 141 prevEp = prevEp->m_pNextEp;
segundo 0:ac1725ba162c 142 prevEp->m_pNextEp = m_pNextEp;
segundo 0:ac1725ba162c 143 }
segundo 0:ac1725ba162c 144 else
segundo 0:ac1725ba162c 145 {
segundo 0:ac1725ba162c 146 m_pHeadEp = m_pNextEp;
segundo 0:ac1725ba162c 147 }
segundo 0:ac1725ba162c 148
segundo 0:ac1725ba162c 149 m_pEd->Control |= ED_SKIP; //Skip this Ep in queue
segundo 0:ac1725ba162c 150
segundo 0:ac1725ba162c 151 //Remove from queue
segundo 0:ac1725ba162c 152 volatile HCED* prevEd;
segundo 0:ac1725ba162c 153 switch( m_type )
segundo 0:ac1725ba162c 154 {
segundo 0:ac1725ba162c 155 case USB_CONTROL:
segundo 0:ac1725ba162c 156 prevEd = (volatile HCED*) LPC_USB->HcControlHeadED;
segundo 0:ac1725ba162c 157 break;
segundo 0:ac1725ba162c 158 case USB_BULK:
segundo 0:ac1725ba162c 159 default:
segundo 0:ac1725ba162c 160 prevEd = (volatile HCED*) LPC_USB->HcBulkHeadED;
segundo 0:ac1725ba162c 161 break;
segundo 0:ac1725ba162c 162 }
segundo 0:ac1725ba162c 163 if( m_pEd == prevEd )
segundo 0:ac1725ba162c 164 {
segundo 0:ac1725ba162c 165 switch( m_type )
segundo 0:ac1725ba162c 166 {
segundo 0:ac1725ba162c 167 case USB_CONTROL:
segundo 0:ac1725ba162c 168 LPC_USB->HcControlHeadED = m_pEd->Next;
segundo 0:ac1725ba162c 169 break;
segundo 0:ac1725ba162c 170 case USB_BULK:
segundo 0:ac1725ba162c 171 default:
segundo 0:ac1725ba162c 172 LPC_USB->HcBulkHeadED = m_pEd->Next;
segundo 0:ac1725ba162c 173 break;
segundo 0:ac1725ba162c 174 }
segundo 0:ac1725ba162c 175 LPC_USB->HcBulkHeadED = m_pEd->Next;
segundo 0:ac1725ba162c 176 }
segundo 0:ac1725ba162c 177 else
segundo 0:ac1725ba162c 178 {
segundo 0:ac1725ba162c 179 while( prevEd->Next != (uint32_t) m_pEd )
segundo 0:ac1725ba162c 180 {
segundo 0:ac1725ba162c 181 prevEd = (volatile HCED*) prevEd->Next;
segundo 0:ac1725ba162c 182 }
segundo 0:ac1725ba162c 183 prevEd->Next = m_pEd->Next;
segundo 0:ac1725ba162c 184 }
segundo 0:ac1725ba162c 185
segundo 0:ac1725ba162c 186 //
segundo 0:ac1725ba162c 187 usb_free_ed((volatile byte*)m_pEd);
segundo 0:ac1725ba162c 188
segundo 0:ac1725ba162c 189 usb_free_td((volatile byte*)m_pTdHead);
segundo 0:ac1725ba162c 190 usb_free_td((volatile byte*)m_pTdTail);
segundo 0:ac1725ba162c 191 }
segundo 0:ac1725ba162c 192
segundo 0:ac1725ba162c 193 void UsbEndpoint::setNextToken(uint32_t token) //Only for control Eps
segundo 0:ac1725ba162c 194 {
segundo 0:ac1725ba162c 195 switch(token)
segundo 0:ac1725ba162c 196 {
segundo 0:ac1725ba162c 197 case TD_SETUP:
segundo 0:ac1725ba162c 198 m_dir = false;
segundo 0:ac1725ba162c 199 m_setup = true;
segundo 0:ac1725ba162c 200 break;
segundo 0:ac1725ba162c 201 case TD_IN:
segundo 0:ac1725ba162c 202 m_dir = true;
segundo 0:ac1725ba162c 203 m_setup = false;
segundo 0:ac1725ba162c 204 break;
segundo 0:ac1725ba162c 205 case TD_OUT:
segundo 0:ac1725ba162c 206 m_dir = false;
segundo 0:ac1725ba162c 207 m_setup = false;
segundo 0:ac1725ba162c 208 break;
segundo 0:ac1725ba162c 209 }
segundo 0:ac1725ba162c 210 }
segundo 0:ac1725ba162c 211
segundo 0:ac1725ba162c 212 UsbErr UsbEndpoint::transfer(volatile uint8_t* buf, uint32_t len)
segundo 0:ac1725ba162c 213 {
segundo 0:ac1725ba162c 214 if(!m_result)
segundo 0:ac1725ba162c 215 return USBERR_BUSY; //The previous trasnfer is not completed
segundo 0:ac1725ba162c 216 //FIXME: We should be able to queue the next transfer, still needs to be implemented
segundo 0:ac1725ba162c 217
segundo 0:ac1725ba162c 218 if( !m_pDevice->connected() )
segundo 0:ac1725ba162c 219 return USBERR_DISCONNECTED;
segundo 0:ac1725ba162c 220
segundo 0:ac1725ba162c 221 m_result = false;
segundo 0:ac1725ba162c 222
segundo 0:ac1725ba162c 223 volatile uint32_t token = (m_setup?TD_SETUP:(m_dir?TD_IN:TD_OUT));
segundo 0:ac1725ba162c 224
segundo 0:ac1725ba162c 225 volatile uint32_t td_toggle;
segundo 0:ac1725ba162c 226 if (m_type == USB_CONTROL)
segundo 0:ac1725ba162c 227 {
segundo 0:ac1725ba162c 228 if (m_setup)
segundo 0:ac1725ba162c 229 {
segundo 0:ac1725ba162c 230 td_toggle = TD_TOGGLE_0;
segundo 0:ac1725ba162c 231 }
segundo 0:ac1725ba162c 232 else
segundo 0:ac1725ba162c 233 {
segundo 0:ac1725ba162c 234 td_toggle = TD_TOGGLE_1;
segundo 0:ac1725ba162c 235 }
segundo 0:ac1725ba162c 236 }
segundo 0:ac1725ba162c 237 else
segundo 0:ac1725ba162c 238 {
segundo 0:ac1725ba162c 239 td_toggle = 0;
segundo 0:ac1725ba162c 240 }
segundo 0:ac1725ba162c 241
segundo 0:ac1725ba162c 242 //Swap Tds
segundo 0:ac1725ba162c 243 volatile HCTD* pTdSwap;
segundo 0:ac1725ba162c 244 pTdSwap = m_pTdTail;
segundo 0:ac1725ba162c 245 m_pTdTail = m_pTdHead;
segundo 0:ac1725ba162c 246 m_pTdHead = pTdSwap;
segundo 0:ac1725ba162c 247
segundo 0:ac1725ba162c 248 m_pTdHead->Control = (TD_ROUNDING |
segundo 0:ac1725ba162c 249 token |
segundo 0:ac1725ba162c 250 TD_DELAY_INT(0) |//7
segundo 0:ac1725ba162c 251 td_toggle |
segundo 0:ac1725ba162c 252 TD_CC);
segundo 0:ac1725ba162c 253
segundo 0:ac1725ba162c 254 m_pTdTail->Control = 0;
segundo 0:ac1725ba162c 255 m_pTdHead->CurrBufPtr = (uint32_t) buf;
segundo 0:ac1725ba162c 256 m_pBufStartPtr = buf;
segundo 0:ac1725ba162c 257 m_pTdTail->CurrBufPtr = 0;
segundo 0:ac1725ba162c 258 m_pTdHead->Next = (uint32_t) m_pTdTail;
segundo 0:ac1725ba162c 259 m_pTdTail->Next = 0;
segundo 0:ac1725ba162c 260 m_pTdHead->BufEnd = (uint32_t)(buf + (len - 1));
segundo 0:ac1725ba162c 261 m_pTdTail->BufEnd = 0;
segundo 0:ac1725ba162c 262
segundo 0:ac1725ba162c 263 m_pEd->HeadTd = (uint32_t)m_pTdHead | ((m_pEd->HeadTd) & 0x00000002); //Carry bit
segundo 0:ac1725ba162c 264 m_pEd->TailTd = (uint32_t)m_pTdTail;
segundo 0:ac1725ba162c 265
segundo 0:ac1725ba162c 266 //DBG("m_pEd->HeadTd = %08x\n", m_pEd->HeadTd);
segundo 0:ac1725ba162c 267
segundo 0:ac1725ba162c 268 if(m_type == USB_CONTROL)
segundo 0:ac1725ba162c 269 {
segundo 0:ac1725ba162c 270 LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_CLF;
segundo 0:ac1725ba162c 271 LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_CLE; //Enable control list
segundo 0:ac1725ba162c 272 }
segundo 0:ac1725ba162c 273 else //USB_BULK
segundo 0:ac1725ba162c 274 {
segundo 0:ac1725ba162c 275 LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF;
segundo 0:ac1725ba162c 276 LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE; //Enable bulk list
segundo 0:ac1725ba162c 277 }
segundo 0:ac1725ba162c 278
segundo 0:ac1725ba162c 279 //m_done = false;
segundo 0:ac1725ba162c 280 m_len = len;
segundo 0:ac1725ba162c 281
segundo 0:ac1725ba162c 282 return USBERR_PROCESSING;
segundo 0:ac1725ba162c 283
segundo 0:ac1725ba162c 284 }
segundo 0:ac1725ba162c 285
segundo 0:ac1725ba162c 286 int UsbEndpoint::status()
segundo 0:ac1725ba162c 287 {
segundo 0:ac1725ba162c 288 if( !m_pDevice->connected() )
segundo 0:ac1725ba162c 289 {
segundo 0:ac1725ba162c 290 if(!m_result)
segundo 0:ac1725ba162c 291 onCompletion();
segundo 0:ac1725ba162c 292 m_result = true;
segundo 0:ac1725ba162c 293 return (int)USBERR_DISCONNECTED;
segundo 0:ac1725ba162c 294 }
segundo 0:ac1725ba162c 295 else if( !m_result )
segundo 0:ac1725ba162c 296 {
segundo 0:ac1725ba162c 297 return (int)USBERR_PROCESSING;
segundo 0:ac1725ba162c 298 }
segundo 0:ac1725ba162c 299 /*else if( m_done )
segundo 0:ac1725ba162c 300 {
segundo 0:ac1725ba162c 301 return (int)USBERR_OK;
segundo 0:ac1725ba162c 302 }*/
segundo 0:ac1725ba162c 303 else
segundo 0:ac1725ba162c 304 {
segundo 0:ac1725ba162c 305 return m_status;
segundo 0:ac1725ba162c 306 }
segundo 0:ac1725ba162c 307 }
segundo 0:ac1725ba162c 308
segundo 0:ac1725ba162c 309 void UsbEndpoint::updateAddr(int addr)
segundo 0:ac1725ba162c 310 {
segundo 0:ac1725ba162c 311 DBG("m_pEd->Control = %08x\n", m_pEd->Control);
segundo 0:ac1725ba162c 312 m_pEd->Control &= ~0x7F;
segundo 0:ac1725ba162c 313 m_pEd->Control |= addr;
segundo 0:ac1725ba162c 314 DBG("m_pEd->Control = %08x\n", m_pEd->Control);
segundo 0:ac1725ba162c 315 }
segundo 0:ac1725ba162c 316
segundo 0:ac1725ba162c 317 void UsbEndpoint::updateSize(uint16_t size)
segundo 0:ac1725ba162c 318 {
segundo 0:ac1725ba162c 319 DBG("m_pEd->Control = %08x\n", m_pEd->Control);
segundo 0:ac1725ba162c 320 m_pEd->Control &= ~0x3FF0000;
segundo 0:ac1725ba162c 321 m_pEd->Control |= (size << 16);
segundo 0:ac1725ba162c 322 DBG("m_pEd->Control = %08x\n", m_pEd->Control);
segundo 0:ac1725ba162c 323 }
segundo 0:ac1725ba162c 324
segundo 0:ac1725ba162c 325 #if 0 //For doc only
segundo 0:ac1725ba162c 326 template <class T>
segundo 0:ac1725ba162c 327 void UsbEndpoint::setOnCompletion( T* pCbItem, void (T::*pCbMeth)() )
segundo 0:ac1725ba162c 328 {
segundo 0:ac1725ba162c 329 m_pCbItem = (CDummy*) pCbItem;
segundo 0:ac1725ba162c 330 m_pCbMeth = (void (CDummy::*)()) pCbMeth;
segundo 0:ac1725ba162c 331 }
segundo 0:ac1725ba162c 332 #endif
segundo 0:ac1725ba162c 333
segundo 0:ac1725ba162c 334 void UsbEndpoint::onCompletion()
segundo 0:ac1725ba162c 335 {
segundo 0:ac1725ba162c 336 //DBG("Transfer completed\n");
segundo 0:ac1725ba162c 337 if( m_pTdHead->Control >> 28 )
segundo 0:ac1725ba162c 338 {
segundo 0:ac1725ba162c 339 DBG("TD Failed with condition code %01x\n", m_pTdHead->Control >> 28 );
segundo 0:ac1725ba162c 340 m_status = (int)USBERR_TDFAIL;
segundo 0:ac1725ba162c 341 }
segundo 0:ac1725ba162c 342 else if( m_pEd->HeadTd & 0x1 )
segundo 0:ac1725ba162c 343 {
segundo 0:ac1725ba162c 344 m_pEd->HeadTd = m_pEd->HeadTd & ~0x1;
segundo 0:ac1725ba162c 345 DBG("\r\nHALTED!!\r\n");
segundo 0:ac1725ba162c 346 m_status = (int)USBERR_HALTED;
segundo 0:ac1725ba162c 347 }
segundo 0:ac1725ba162c 348 else if( (m_pEd->HeadTd & ~0xF) == (uint32_t) m_pTdTail )
segundo 0:ac1725ba162c 349 {
segundo 0:ac1725ba162c 350 //Done
segundo 0:ac1725ba162c 351 int len;
segundo 0:ac1725ba162c 352 //DBG("m_pTdHead->CurrBufPtr = %08x, m_pBufStartPtr=%08x\n", m_pTdHead->CurrBufPtr, (uint32_t) m_pBufStartPtr);
segundo 0:ac1725ba162c 353 if(m_pTdHead->CurrBufPtr)
segundo 0:ac1725ba162c 354 len = m_pTdHead->CurrBufPtr - (uint32_t) m_pBufStartPtr;
segundo 0:ac1725ba162c 355 else
segundo 0:ac1725ba162c 356 len = m_len;
segundo 0:ac1725ba162c 357 /*if(len == 0) //Packet transfered completely
segundo 0:ac1725ba162c 358 len = m_len;*/
segundo 0:ac1725ba162c 359 //m_done = true;
segundo 0:ac1725ba162c 360 DBG("Transfered %d bytes\n", len);
segundo 0:ac1725ba162c 361 m_status = len;
segundo 0:ac1725ba162c 362 }
segundo 0:ac1725ba162c 363 else
segundo 0:ac1725ba162c 364 {
segundo 0:ac1725ba162c 365 DBG("Unknown error...\n");
segundo 0:ac1725ba162c 366 m_status = (int)USBERR_ERROR;
segundo 0:ac1725ba162c 367 }
segundo 0:ac1725ba162c 368 m_result = true;
segundo 0:ac1725ba162c 369 if(m_pCbItem && m_pCbMeth)
segundo 0:ac1725ba162c 370 (m_pCbItem->*m_pCbMeth)();
segundo 0:ac1725ba162c 371 }
segundo 0:ac1725ba162c 372
segundo 0:ac1725ba162c 373 void UsbEndpoint::sOnCompletion(uint32_t pTd)
segundo 0:ac1725ba162c 374 {
segundo 0:ac1725ba162c 375 if(!m_pHeadEp)
segundo 0:ac1725ba162c 376 return;
segundo 0:ac1725ba162c 377 do
segundo 0:ac1725ba162c 378 {
segundo 0:ac1725ba162c 379 //DBG("sOnCompletion (pTd = %08x)\n", pTd);
segundo 0:ac1725ba162c 380 UsbEndpoint* pEp = m_pHeadEp;
segundo 0:ac1725ba162c 381 do
segundo 0:ac1725ba162c 382 {
segundo 0:ac1725ba162c 383 if((uint32_t)pEp->m_pTdHead == pTd)
segundo 0:ac1725ba162c 384 {
segundo 0:ac1725ba162c 385 pEp->onCompletion();
segundo 0:ac1725ba162c 386 break;
segundo 0:ac1725ba162c 387 }
segundo 0:ac1725ba162c 388 } while(pEp = pEp->m_pNextEp);
segundo 0:ac1725ba162c 389 } while( pTd = (uint32_t)( ((HCTD*)pTd)->Next ) ); //Go around the Done queue
segundo 0:ac1725ba162c 390 }
segundo 0:ac1725ba162c 391
segundo 0:ac1725ba162c 392 UsbEndpoint* UsbEndpoint::m_pHeadEp = NULL;
segundo 0:ac1725ba162c 393
segundo 0:ac1725ba162c 394 #endif