Example program with HTTPServer and sensor data streaming over TCPSockets, using Donatien Garnier's Net APIs and services code on top of LWIP. Files StreamServer.h and .cpp encapsulate streaming over TCPSockets. Broadcast is done by sendToAll(), and all incoming data is echoed back to the client. Echo code can be replaced with some remote control of the streaming interface. See main() that shows how to periodically send some data to all subscribed clients. To subscribe, a client should open a socket at <mbed_ip> port 123. I used few lines in TCL code to set up a quick sink for the data. HTTP files are served on port 80 concurrently to the streaming.
drv/usb/UsbEndpoint.cpp@1:3ee499525aa5, 2010-06-14 (annotated)
- Committer:
- iva2k
- Date:
- Mon Jun 14 03:24:33 2010 +0000
- Revision:
- 1:3ee499525aa5
- Parent:
- 0:e614f7875b60
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iva2k | 0:e614f7875b60 | 1 | |
iva2k | 0:e614f7875b60 | 2 | /* |
iva2k | 0:e614f7875b60 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
iva2k | 0:e614f7875b60 | 4 | |
iva2k | 0:e614f7875b60 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
iva2k | 0:e614f7875b60 | 6 | of this software and associated documentation files (the "Software"), to deal |
iva2k | 0:e614f7875b60 | 7 | in the Software without restriction, including without limitation the rights |
iva2k | 0:e614f7875b60 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
iva2k | 0:e614f7875b60 | 9 | copies of the Software, and to permit persons to whom the Software is |
iva2k | 0:e614f7875b60 | 10 | furnished to do so, subject to the following conditions: |
iva2k | 0:e614f7875b60 | 11 | |
iva2k | 0:e614f7875b60 | 12 | The above copyright notice and this permission notice shall be included in |
iva2k | 0:e614f7875b60 | 13 | all copies or substantial portions of the Software. |
iva2k | 0:e614f7875b60 | 14 | |
iva2k | 0:e614f7875b60 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
iva2k | 0:e614f7875b60 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
iva2k | 0:e614f7875b60 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
iva2k | 0:e614f7875b60 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
iva2k | 0:e614f7875b60 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
iva2k | 0:e614f7875b60 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
iva2k | 0:e614f7875b60 | 21 | THE SOFTWARE. |
iva2k | 0:e614f7875b60 | 22 | */ |
iva2k | 0:e614f7875b60 | 23 | |
iva2k | 0:e614f7875b60 | 24 | #include "UsbEndpoint.h" |
iva2k | 0:e614f7875b60 | 25 | |
iva2k | 0:e614f7875b60 | 26 | #include "netCfg.h" |
iva2k | 0:e614f7875b60 | 27 | #if NET_USB |
iva2k | 0:e614f7875b60 | 28 | |
iva2k | 0:e614f7875b60 | 29 | EdPool::EdPool(int size) : m_pos(0) |
iva2k | 0:e614f7875b60 | 30 | { |
iva2k | 0:e614f7875b60 | 31 | m_pool = new uint8_t[2*size*0x10]; |
iva2k | 0:e614f7875b60 | 32 | printf("\r\n--HCED* m_pool= %p of size %d--\r\n", m_pool, 2*size*0x10); |
iva2k | 0:e614f7875b60 | 33 | } |
iva2k | 0:e614f7875b60 | 34 | |
iva2k | 0:e614f7875b60 | 35 | EdPool::~EdPool() |
iva2k | 0:e614f7875b60 | 36 | { |
iva2k | 0:e614f7875b60 | 37 | printf("\r\n--~EdPool()--\r\n"); |
iva2k | 0:e614f7875b60 | 38 | delete[] m_pool; |
iva2k | 0:e614f7875b60 | 39 | } |
iva2k | 0:e614f7875b60 | 40 | |
iva2k | 0:e614f7875b60 | 41 | HCED* EdPool::get() |
iva2k | 0:e614f7875b60 | 42 | { |
iva2k | 0:e614f7875b60 | 43 | printf("\r\n--HCED* &m_pool[m_pos]= %p--\r\n", &m_pool[m_pos]); |
iva2k | 0:e614f7875b60 | 44 | while( ( ((uint32_t)&m_pool[m_pos]) & 0xF ) != 0 ) |
iva2k | 0:e614f7875b60 | 45 | { |
iva2k | 0:e614f7875b60 | 46 | m_pos++; |
iva2k | 0:e614f7875b60 | 47 | } |
iva2k | 0:e614f7875b60 | 48 | HCED* pEd = (HCED*) &m_pool[m_pos]; |
iva2k | 0:e614f7875b60 | 49 | m_pos += sizeof(HCED); |
iva2k | 0:e614f7875b60 | 50 | printf("\r\n--HCED* pEd = %p--\r\n", pEd); |
iva2k | 0:e614f7875b60 | 51 | return pEd; |
iva2k | 0:e614f7875b60 | 52 | } |
iva2k | 0:e614f7875b60 | 53 | |
iva2k | 0:e614f7875b60 | 54 | TdPool::TdPool(int size) : m_pos(0) |
iva2k | 0:e614f7875b60 | 55 | { |
iva2k | 0:e614f7875b60 | 56 | m_pool = new uint8_t[2*size*0x10]; |
iva2k | 0:e614f7875b60 | 57 | printf("\r\n--HCTD* m_pool= %p of size %d--\r\n", m_pool, 2*size*0x10); |
iva2k | 0:e614f7875b60 | 58 | } |
iva2k | 0:e614f7875b60 | 59 | |
iva2k | 0:e614f7875b60 | 60 | TdPool::~TdPool() |
iva2k | 0:e614f7875b60 | 61 | { |
iva2k | 0:e614f7875b60 | 62 | printf("\r\n--~EdPool()--\r\n"); |
iva2k | 0:e614f7875b60 | 63 | delete[] m_pool; |
iva2k | 0:e614f7875b60 | 64 | } |
iva2k | 0:e614f7875b60 | 65 | |
iva2k | 0:e614f7875b60 | 66 | HCTD* TdPool::get() |
iva2k | 0:e614f7875b60 | 67 | { |
iva2k | 0:e614f7875b60 | 68 | printf("\r\n--HCTD* &m_pool[m_pos]= %p--\r\n", &m_pool[m_pos]); |
iva2k | 0:e614f7875b60 | 69 | while( ( ((uint32_t)&m_pool[m_pos]) & 0xF ) != 0 ) |
iva2k | 0:e614f7875b60 | 70 | { |
iva2k | 0:e614f7875b60 | 71 | m_pos++; |
iva2k | 0:e614f7875b60 | 72 | } |
iva2k | 0:e614f7875b60 | 73 | HCTD* pTd = (HCTD*) &m_pool[m_pos]; |
iva2k | 0:e614f7875b60 | 74 | m_pos += sizeof(HCTD); |
iva2k | 0:e614f7875b60 | 75 | printf("\r\n--HCTD* pTd = %p--\r\n", pTd); |
iva2k | 0:e614f7875b60 | 76 | return pTd; |
iva2k | 0:e614f7875b60 | 77 | } |
iva2k | 0:e614f7875b60 | 78 | //uint8_t TdPool::pool[16*0x10]={0};//Ok for 2 Eps (2*(2Tds/Ep*2Eps)) |
iva2k | 0:e614f7875b60 | 79 | //int TdPool::pos = 0; |
iva2k | 0:e614f7875b60 | 80 | |
iva2k | 0:e614f7875b60 | 81 | extern volatile HCED* EDBulkHead; |
iva2k | 0:e614f7875b60 | 82 | //volatile HCED* UsbEndpoint::m_pNextEd = NULL; |
iva2k | 0:e614f7875b60 | 83 | |
iva2k | 0:e614f7875b60 | 84 | UsbEndpoint::UsbEndpoint( /* UsbDevice*, */ uint8_t ep, bool dir, uint16_t size ) : m_edPool(1), m_tdPool(2), m_done(true), m_len(0), m_pBufStartPtr(NULL) |
iva2k | 0:e614f7875b60 | 85 | { |
iva2k | 0:e614f7875b60 | 86 | #if 1 |
iva2k | 0:e614f7875b60 | 87 | |
iva2k | 0:e614f7875b60 | 88 | m_pEd = m_edPool.get(); |
iva2k | 0:e614f7875b60 | 89 | |
iva2k | 0:e614f7875b60 | 90 | #else |
iva2k | 0:e614f7875b60 | 91 | if(m_pNextEd == NULL) |
iva2k | 0:e614f7875b60 | 92 | { |
iva2k | 0:e614f7875b60 | 93 | m_pNextEd = EDBulkHead; |
iva2k | 0:e614f7875b60 | 94 | //printf("\r\n--m_pEd = %p < EDBulkHead = %p --\r\n", m_pEd, EDBulkHead); |
iva2k | 0:e614f7875b60 | 95 | } |
iva2k | 0:e614f7875b60 | 96 | |
iva2k | 0:e614f7875b60 | 97 | printf("\r\n--Ep Inst--\r\n"); |
iva2k | 0:e614f7875b60 | 98 | m_pEd = /*new HCED(); // */m_pNextEd; |
iva2k | 0:e614f7875b60 | 99 | |
iva2k | 0:e614f7875b60 | 100 | //printf("\r\n--m_pNextEd = %p--\r\n", m_pNextEd); |
iva2k | 0:e614f7875b60 | 101 | m_pNextEd += 1; //TODO: Avail mem check |
iva2k | 0:e614f7875b60 | 102 | //printf("\r\n--m_pNextEd = %p--\r\n", m_pNextEd); |
iva2k | 0:e614f7875b60 | 103 | #endif |
iva2k | 0:e614f7875b60 | 104 | |
iva2k | 0:e614f7875b60 | 105 | m_pTdHead = m_tdPool.get();//new HCTD(); |
iva2k | 0:e614f7875b60 | 106 | m_pTdTail = m_tdPool.get();//new HCTD(); |
iva2k | 0:e614f7875b60 | 107 | |
iva2k | 0:e614f7875b60 | 108 | printf("\r\n--m_pEd = %p--\r\n", m_pEd); |
iva2k | 0:e614f7875b60 | 109 | |
iva2k | 0:e614f7875b60 | 110 | //Init Ed & Td |
iva2k | 0:e614f7875b60 | 111 | printf("\r\n--Ep Init--\r\n"); |
iva2k | 0:e614f7875b60 | 112 | Host_EDInit(m_pEd); |
iva2k | 0:e614f7875b60 | 113 | printf("\r\n--Td Init--\r\n"); |
iva2k | 0:e614f7875b60 | 114 | Host_TDInit(m_pTdHead); |
iva2k | 0:e614f7875b60 | 115 | Host_TDInit(m_pTdTail); |
iva2k | 0:e614f7875b60 | 116 | |
iva2k | 0:e614f7875b60 | 117 | //Setup Ed |
iva2k | 0:e614f7875b60 | 118 | printf("\r\n--Ep Setup--\r\n"); |
iva2k | 0:e614f7875b60 | 119 | m_pEd->Control = 1 | /* USB address */ //FIXME: Device Id |
iva2k | 0:e614f7875b60 | 120 | ((ep & 0x7F) << 7) | /* Endpoint address */ |
iva2k | 0:e614f7875b60 | 121 | ((dir?2:1) << 11) | /* direction : Out = 1, 2 = In */ |
iva2k | 0:e614f7875b60 | 122 | (size << 16); /* MaxPkt Size */ |
iva2k | 0:e614f7875b60 | 123 | |
iva2k | 0:e614f7875b60 | 124 | m_dir = dir; |
iva2k | 0:e614f7875b60 | 125 | |
iva2k | 0:e614f7875b60 | 126 | m_pEd->TailTd = m_pEd->HeadTd = (USB_INT32U) m_pTdTail; //Empty TD list |
iva2k | 0:e614f7875b60 | 127 | |
iva2k | 0:e614f7875b60 | 128 | printf("\r\n--Ep Reg--\r\n"); |
iva2k | 0:e614f7875b60 | 129 | //Append Ed to bulk Ep list |
iva2k | 0:e614f7875b60 | 130 | #if 1 |
iva2k | 0:e614f7875b60 | 131 | volatile HCED* prevEd = (volatile HCED*) LPC_USB->HcBulkHeadED; |
iva2k | 0:e614f7875b60 | 132 | m_pEd->Next = (USB_INT32U) prevEd; |
iva2k | 0:e614f7875b60 | 133 | LPC_USB->HcBulkHeadED = (USB_INT32U) m_pEd; |
iva2k | 0:e614f7875b60 | 134 | #else |
iva2k | 0:e614f7875b60 | 135 | if( LPC_USB->HcBulkHeadED == 0 ) |
iva2k | 0:e614f7875b60 | 136 | { |
iva2k | 0:e614f7875b60 | 137 | LPC_USB->HcBulkHeadED = (USB_INT32U)m_pEd; |
iva2k | 0:e614f7875b60 | 138 | printf("\r\n--Bulk head--\r\n"); |
iva2k | 0:e614f7875b60 | 139 | } |
iva2k | 0:e614f7875b60 | 140 | else |
iva2k | 0:e614f7875b60 | 141 | { |
iva2k | 0:e614f7875b60 | 142 | volatile HCED* prevEd = (volatile HCED*) LPC_USB->HcBulkHeadED; |
iva2k | 0:e614f7875b60 | 143 | while(prevEd->Next) |
iva2k | 0:e614f7875b60 | 144 | { |
iva2k | 0:e614f7875b60 | 145 | prevEd = (volatile HCED*) prevEd->Next; |
iva2k | 0:e614f7875b60 | 146 | } |
iva2k | 0:e614f7875b60 | 147 | printf("\r\n--Appended to ep list (prevEd = %p)--\r\n", prevEd); |
iva2k | 0:e614f7875b60 | 148 | prevEd->Next = (USB_INT32U) m_pEd; |
iva2k | 0:e614f7875b60 | 149 | } |
iva2k | 0:e614f7875b60 | 150 | #endif |
iva2k | 0:e614f7875b60 | 151 | /* |
iva2k | 0:e614f7875b60 | 152 | printf("\r\n--Writing config reg--\r\n"); |
iva2k | 0:e614f7875b60 | 153 | LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF; |
iva2k | 0:e614f7875b60 | 154 | LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE; |
iva2k | 0:e614f7875b60 | 155 | */ |
iva2k | 0:e614f7875b60 | 156 | } |
iva2k | 0:e614f7875b60 | 157 | |
iva2k | 0:e614f7875b60 | 158 | UsbEndpoint::~UsbEndpoint() |
iva2k | 0:e614f7875b60 | 159 | { |
iva2k | 0:e614f7875b60 | 160 | m_pEd->Control |= ED_SKIP; //Skip this Ep in queue |
iva2k | 0:e614f7875b60 | 161 | |
iva2k | 0:e614f7875b60 | 162 | //Remove from queue |
iva2k | 0:e614f7875b60 | 163 | if( LPC_USB->HcBulkHeadED == (USB_INT32U) m_pEd ) |
iva2k | 0:e614f7875b60 | 164 | { |
iva2k | 0:e614f7875b60 | 165 | LPC_USB->HcBulkHeadED = m_pEd->Next; |
iva2k | 0:e614f7875b60 | 166 | } |
iva2k | 0:e614f7875b60 | 167 | else |
iva2k | 0:e614f7875b60 | 168 | { |
iva2k | 0:e614f7875b60 | 169 | volatile HCED* prevEd = (volatile HCED*) LPC_USB->HcBulkHeadED; |
iva2k | 0:e614f7875b60 | 170 | while( prevEd->Next != (USB_INT32U) m_pEd ) |
iva2k | 0:e614f7875b60 | 171 | { |
iva2k | 0:e614f7875b60 | 172 | prevEd = (volatile HCED*) prevEd->Next; |
iva2k | 0:e614f7875b60 | 173 | } |
iva2k | 0:e614f7875b60 | 174 | prevEd->Next = m_pEd->Next; |
iva2k | 0:e614f7875b60 | 175 | } |
iva2k | 0:e614f7875b60 | 176 | |
iva2k | 0:e614f7875b60 | 177 | if( LPC_USB->HcBulkCurrentED == (USB_INT32U) m_pEd ) |
iva2k | 0:e614f7875b60 | 178 | { |
iva2k | 0:e614f7875b60 | 179 | LPC_USB->HcBulkCurrentED = 0; |
iva2k | 0:e614f7875b60 | 180 | } |
iva2k | 0:e614f7875b60 | 181 | |
iva2k | 0:e614f7875b60 | 182 | |
iva2k | 0:e614f7875b60 | 183 | #if 0 //NO WAY! Owned by pool!!! |
iva2k | 0:e614f7875b60 | 184 | delete m_pEd; |
iva2k | 0:e614f7875b60 | 185 | delete m_pTdHead; |
iva2k | 0:e614f7875b60 | 186 | delete m_pTdTail; |
iva2k | 0:e614f7875b60 | 187 | #endif |
iva2k | 0:e614f7875b60 | 188 | } |
iva2k | 0:e614f7875b60 | 189 | |
iva2k | 0:e614f7875b60 | 190 | RC UsbEndpoint::transfer(volatile uint8_t* buf, uint32_t len) |
iva2k | 0:e614f7875b60 | 191 | { |
iva2k | 0:e614f7875b60 | 192 | if(!m_done) |
iva2k | 0:e614f7875b60 | 193 | return ERR_TD_FAIL; |
iva2k | 0:e614f7875b60 | 194 | volatile USB_INT32U token = (m_dir?TD_IN:TD_OUT); |
iva2k | 0:e614f7875b60 | 195 | //printf("\r\n--m_pEd->HeadTd = %16x, m_pTdHead = %16x, m_pEd->TailTd = %16x, m_pTdTail = %16x--\r\n",m_pEd->HeadTd,(USB_INT32U)m_pTdHead,m_pEd->TailTd,(USB_INT32U)m_pTdTail); |
iva2k | 0:e614f7875b60 | 196 | |
iva2k | 0:e614f7875b60 | 197 | //Swap Tds |
iva2k | 0:e614f7875b60 | 198 | //printf("\r\n--Swap Tds--\r\n"); |
iva2k | 0:e614f7875b60 | 199 | volatile HCTD* pTdSwap; |
iva2k | 0:e614f7875b60 | 200 | pTdSwap = m_pTdTail; |
iva2k | 0:e614f7875b60 | 201 | m_pTdTail = m_pTdHead; |
iva2k | 0:e614f7875b60 | 202 | m_pTdHead = pTdSwap; |
iva2k | 0:e614f7875b60 | 203 | |
iva2k | 0:e614f7875b60 | 204 | |
iva2k | 0:e614f7875b60 | 205 | // printf("\r\n--m_pEd->HeadTd = %16x, m_pTdHead = %16x, m_pEd->TailTd = %16x, m_pTdTail = %16x--\r\n",m_pEd->HeadTd,(USB_INT32U)m_pTdHead,m_pEd->TailTd,(USB_INT32U)m_pTdTail); |
iva2k | 0:e614f7875b60 | 206 | |
iva2k | 0:e614f7875b60 | 207 | // printf("\r\n--Tds setup--\r\n"); |
iva2k | 0:e614f7875b60 | 208 | m_pTdHead->Control = (TD_ROUNDING | |
iva2k | 0:e614f7875b60 | 209 | token | |
iva2k | 0:e614f7875b60 | 210 | // TD_DELAY_INT(0) | |
iva2k | 0:e614f7875b60 | 211 | TD_DELAY_INT(7) | |
iva2k | 0:e614f7875b60 | 212 | TD_CC); |
iva2k | 0:e614f7875b60 | 213 | m_pTdTail->Control = 0; |
iva2k | 0:e614f7875b60 | 214 | m_pTdHead->CurrBufPtr = (USB_INT32U) buf; |
iva2k | 0:e614f7875b60 | 215 | m_pBufStartPtr = buf; |
iva2k | 0:e614f7875b60 | 216 | m_pTdTail->CurrBufPtr = 0; |
iva2k | 0:e614f7875b60 | 217 | m_pTdHead->Next = (USB_INT32U) m_pTdTail; |
iva2k | 0:e614f7875b60 | 218 | m_pTdTail->Next = 0; |
iva2k | 0:e614f7875b60 | 219 | m_pTdHead->BufEnd = (USB_INT32U)(buf + (len - 1)); |
iva2k | 0:e614f7875b60 | 220 | m_pTdTail->BufEnd = 0; |
iva2k | 0:e614f7875b60 | 221 | |
iva2k | 0:e614f7875b60 | 222 | // printf("\r\n--Ed setup--\r\n"); |
iva2k | 0:e614f7875b60 | 223 | // m_pEd->HeadTd = (USB_INT32U)m_pTdHead | ((m_pEd->HeadTd) & 0x00000002); |
iva2k | 0:e614f7875b60 | 224 | m_pEd->HeadTd = (USB_INT32U)m_pTdHead | ((m_pEd->HeadTd) & 0x00000002); //Carry bit |
iva2k | 0:e614f7875b60 | 225 | m_pEd->TailTd = (USB_INT32U)m_pTdTail; |
iva2k | 0:e614f7875b60 | 226 | /* |
iva2k | 0:e614f7875b60 | 227 | printf("\r\n--Swap Tds--\r\n"); |
iva2k | 0:e614f7875b60 | 228 | volatile HCTD* pTdSwap; |
iva2k | 0:e614f7875b60 | 229 | pTdSwap = m_pTdTail; |
iva2k | 0:e614f7875b60 | 230 | m_pTdTail = m_pTdHead; |
iva2k | 0:e614f7875b60 | 231 | m_pTdHead = pTdSwap; |
iva2k | 0:e614f7875b60 | 232 | */ |
iva2k | 0:e614f7875b60 | 233 | // ed->Next = 0; |
iva2k | 0:e614f7875b60 | 234 | |
iva2k | 0:e614f7875b60 | 235 | //printf("\r\n--m_pEd->HeadTd = %16x, m_pTdHead = %16x, m_pEd->TailTd = %16x, m_pTdTail = %16x--\r\n",m_pEd->HeadTd,(USB_INT32U)m_pTdHead,m_pEd->TailTd,(USB_INT32U)m_pTdTail); |
iva2k | 0:e614f7875b60 | 236 | |
iva2k | 0:e614f7875b60 | 237 | // printf("\r\n--Writing config reg--\r\n"); |
iva2k | 0:e614f7875b60 | 238 | LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF; |
iva2k | 0:e614f7875b60 | 239 | LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE; |
iva2k | 0:e614f7875b60 | 240 | |
iva2k | 0:e614f7875b60 | 241 | // printf("\r\n--Processing queue--\r\n"); |
iva2k | 0:e614f7875b60 | 242 | // __WFI(); |
iva2k | 0:e614f7875b60 | 243 | m_done = false; |
iva2k | 0:e614f7875b60 | 244 | m_len = len; |
iva2k | 0:e614f7875b60 | 245 | return PROCESSING; |
iva2k | 0:e614f7875b60 | 246 | |
iva2k | 0:e614f7875b60 | 247 | } |
iva2k | 0:e614f7875b60 | 248 | |
iva2k | 0:e614f7875b60 | 249 | RC UsbEndpoint::status() |
iva2k | 0:e614f7875b60 | 250 | { |
iva2k | 0:e614f7875b60 | 251 | if( m_done ) |
iva2k | 0:e614f7875b60 | 252 | { |
iva2k | 0:e614f7875b60 | 253 | return OK; |
iva2k | 0:e614f7875b60 | 254 | } |
iva2k | 0:e614f7875b60 | 255 | //volatile HCTD* pTd = (volatile HCTD*) m_pEd->HeadTd; |
iva2k | 0:e614f7875b60 | 256 | //printf("\r\nm_pTdHead->CurrBufPtr = %16x", m_pTdHead->CurrBufPtr); |
iva2k | 0:e614f7875b60 | 257 | //printf("\r\n--m_pEd->HeadTd = %16x, m_pTdHead = %16x, m_pEd->TailTd = %16x, m_pTdTail = %16x--\r\n",m_pEd->HeadTd,(USB_INT32U)m_pTdHead,m_pEd->TailTd,(USB_INT32U)m_pTdTail); |
iva2k | 0:e614f7875b60 | 258 | //if( pTd->CurrBufPtr == 0 /*m_pEd->HeadTd != (USB_INT32U)m_pTdHead*//*m_pEd->HeadTd == (USB_INT32U)m_pTdTail*/) //Empty queue |
iva2k | 0:e614f7875b60 | 259 | else if( (m_pEd->HeadTd & ~0xF) == (USB_INT32U) m_pTdTail ) |
iva2k | 0:e614f7875b60 | 260 | { |
iva2k | 0:e614f7875b60 | 261 | //Done |
iva2k | 0:e614f7875b60 | 262 | //printf("\r\n--m_pEd->HeadTd = %16x, m_pTdHead = %16x, m_pEd->TailTd = %16x, m_pTdTail = %16x--\r\n",m_pEd->HeadTd,(USB_INT32U)m_pTdHead,m_pEd->TailTd,(USB_INT32U)m_pTdTail); |
iva2k | 0:e614f7875b60 | 263 | int len; |
iva2k | 0:e614f7875b60 | 264 | if(m_pTdHead->CurrBufPtr) |
iva2k | 0:e614f7875b60 | 265 | len = m_pTdHead->CurrBufPtr - (USB_INT32U)m_pBufStartPtr; //Does not work properly, packet might have been discarded |
iva2k | 0:e614f7875b60 | 266 | else |
iva2k | 0:e614f7875b60 | 267 | len = m_len; |
iva2k | 0:e614f7875b60 | 268 | // printf("\r\nDone w/ len = %d (m_pTdHead->CurrBufPtr=%16x)\r\n", len, m_pTdHead->CurrBufPtr); |
iva2k | 0:e614f7875b60 | 269 | if(len == 0) //Packet transfered completely |
iva2k | 0:e614f7875b60 | 270 | len = m_len; |
iva2k | 0:e614f7875b60 | 271 | //Host_TDInit(m_pTdTail); |
iva2k | 0:e614f7875b60 | 272 | //m_pEd->TailTd = m_pEd->HeadTd = (USB_INT32U) m_pTdTail; //Empty TD list |
iva2k | 0:e614f7875b60 | 273 | |
iva2k | 0:e614f7875b60 | 274 | // printf("\r\n--Writing config reg--\r\n"); |
iva2k | 0:e614f7875b60 | 275 | //LPC_USB->HcCommandStatus = LPC_USB->HcCommandStatus | OR_CMD_STATUS_BLF; |
iva2k | 0:e614f7875b60 | 276 | //LPC_USB->HcControl = LPC_USB->HcControl | OR_CONTROL_BLE; |
iva2k | 0:e614f7875b60 | 277 | |
iva2k | 0:e614f7875b60 | 278 | m_done = true; |
iva2k | 0:e614f7875b60 | 279 | return len; |
iva2k | 0:e614f7875b60 | 280 | //return OK; |
iva2k | 0:e614f7875b60 | 281 | } |
iva2k | 0:e614f7875b60 | 282 | else if( m_pEd->HeadTd & 0x1 ) |
iva2k | 0:e614f7875b60 | 283 | { |
iva2k | 0:e614f7875b60 | 284 | printf("\r\nHALTED!!\r\n"); |
iva2k | 0:e614f7875b60 | 285 | return ERR_TD_FAIL; |
iva2k | 0:e614f7875b60 | 286 | } |
iva2k | 0:e614f7875b60 | 287 | else |
iva2k | 0:e614f7875b60 | 288 | { |
iva2k | 0:e614f7875b60 | 289 | // wait(1); |
iva2k | 0:e614f7875b60 | 290 | return PROCESSING; |
iva2k | 0:e614f7875b60 | 291 | } |
iva2k | 0:e614f7875b60 | 292 | } |
iva2k | 0:e614f7875b60 | 293 | |
iva2k | 0:e614f7875b60 | 294 | #endif |