HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

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