Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 5:3f93dd1d4cb3 1 /* Copyright (c) 2010-2012 mbed.org, MIT License
sam_grove 5:3f93dd1d4cb3 2 *
sam_grove 5:3f93dd1d4cb3 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
sam_grove 5:3f93dd1d4cb3 4 * and associated documentation files (the "Software"), to deal in the Software without
sam_grove 5:3f93dd1d4cb3 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
sam_grove 5:3f93dd1d4cb3 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
sam_grove 5:3f93dd1d4cb3 7 * Software is furnished to do so, subject to the following conditions:
sam_grove 5:3f93dd1d4cb3 8 *
sam_grove 5:3f93dd1d4cb3 9 * The above copyright notice and this permission notice shall be included in all copies or
sam_grove 5:3f93dd1d4cb3 10 * substantial portions of the Software.
sam_grove 5:3f93dd1d4cb3 11 *
sam_grove 5:3f93dd1d4cb3 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
sam_grove 5:3f93dd1d4cb3 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
sam_grove 5:3f93dd1d4cb3 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
sam_grove 5:3f93dd1d4cb3 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sam_grove 5:3f93dd1d4cb3 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sam_grove 5:3f93dd1d4cb3 17 */
sam_grove 5:3f93dd1d4cb3 18
sam_grove 5:3f93dd1d4cb3 19
sam_grove 5:3f93dd1d4cb3 20 #define __DEBUG__ 0 //Maximum verbosity
sam_grove 5:3f93dd1d4cb3 21 #ifndef __MODULE__
sam_grove 5:3f93dd1d4cb3 22 #define __MODULE__ "USBEndpoint.cpp"
sam_grove 5:3f93dd1d4cb3 23 #endif
sam_grove 5:3f93dd1d4cb3 24
sam_grove 5:3f93dd1d4cb3 25 #include "core/dbg.h"
sam_grove 5:3f93dd1d4cb3 26 #include <cstdint>
sam_grove 5:3f93dd1d4cb3 27
sam_grove 5:3f93dd1d4cb3 28 #include "USBEndpoint.h"
sam_grove 5:3f93dd1d4cb3 29
sam_grove 5:3f93dd1d4cb3 30
sam_grove 5:3f93dd1d4cb3 31 void USBEndpoint::init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]) {
sam_grove 5:3f93dd1d4cb3 32 this->hced = hced;
sam_grove 5:3f93dd1d4cb3 33 this->type = type;
sam_grove 5:3f93dd1d4cb3 34 this->dir = /*(type == CONTROL_ENDPOINT) ? OUT :*/ dir;
sam_grove 5:3f93dd1d4cb3 35 setup = (type == CONTROL_ENDPOINT) ? true : false;
sam_grove 5:3f93dd1d4cb3 36
sam_grove 5:3f93dd1d4cb3 37 //TDs have been allocated by the host
sam_grove 5:3f93dd1d4cb3 38 memcpy((HCTD**)this->td_list, td_list, sizeof(HCTD*)*2); //TODO: Maybe should add a param for td_list size... at least a define
sam_grove 5:3f93dd1d4cb3 39 memcpy(td_list[0], 0, sizeof(HCTD));
sam_grove 5:3f93dd1d4cb3 40 memcpy(td_list[1], 0, sizeof(HCTD));
sam_grove 5:3f93dd1d4cb3 41
sam_grove 5:3f93dd1d4cb3 42 this->hced->control = 0;
sam_grove 5:3f93dd1d4cb3 43 //Empty queue
sam_grove 5:3f93dd1d4cb3 44 this->hced->tailTD = (uint32_t)td_list[0];
sam_grove 5:3f93dd1d4cb3 45 this->hced->headTD = (uint32_t)td_list[0];
sam_grove 5:3f93dd1d4cb3 46 this->hced->nextED = 0;
sam_grove 5:3f93dd1d4cb3 47
sam_grove 5:3f93dd1d4cb3 48 this->hced->control = ((ep_number & 0x7F) << 7) // Endpoint address
sam_grove 5:3f93dd1d4cb3 49 | (type != CONTROL_ENDPOINT ? ( dir << 11) : 0 ) // direction : Out = 1, 2 = In
sam_grove 5:3f93dd1d4cb3 50 | ((size & 0x3ff) << 16); // MaxPkt Size
sam_grove 5:3f93dd1d4cb3 51
sam_grove 5:3f93dd1d4cb3 52 //carry = false;
sam_grove 5:3f93dd1d4cb3 53 transfer_len = 0;
sam_grove 5:3f93dd1d4cb3 54 transferred = 0;
sam_grove 5:3f93dd1d4cb3 55 buf_start = 0;
sam_grove 5:3f93dd1d4cb3 56 nextEp = NULL;
sam_grove 5:3f93dd1d4cb3 57
sam_grove 5:3f93dd1d4cb3 58 td_current = td_list[0];
sam_grove 5:3f93dd1d4cb3 59 td_next = td_list[1];
sam_grove 5:3f93dd1d4cb3 60
sam_grove 5:3f93dd1d4cb3 61 state = USB_TYPE_IDLE;
sam_grove 5:3f93dd1d4cb3 62 }
sam_grove 5:3f93dd1d4cb3 63
sam_grove 5:3f93dd1d4cb3 64 void USBEndpoint::setSize(uint32_t size) {
sam_grove 5:3f93dd1d4cb3 65 hced->control &= ~(0x3ff << 16);
sam_grove 5:3f93dd1d4cb3 66 hced->control |= (size << 16);
sam_grove 5:3f93dd1d4cb3 67 }
sam_grove 5:3f93dd1d4cb3 68
sam_grove 5:3f93dd1d4cb3 69
sam_grove 5:3f93dd1d4cb3 70 uint32_t USBEndpoint::getSize() {
sam_grove 5:3f93dd1d4cb3 71 return (hced->control >> 16) & 0x3ff;
sam_grove 5:3f93dd1d4cb3 72 }
sam_grove 5:3f93dd1d4cb3 73
sam_grove 5:3f93dd1d4cb3 74 void USBEndpoint::setDeviceAddress(uint8_t addr) {
sam_grove 5:3f93dd1d4cb3 75 hced->control &= ~(0x7f);
sam_grove 5:3f93dd1d4cb3 76 hced->control |= (addr & 0x7F);
sam_grove 5:3f93dd1d4cb3 77 }
sam_grove 5:3f93dd1d4cb3 78
sam_grove 5:3f93dd1d4cb3 79 uint8_t USBEndpoint::getDeviceAddress() {
sam_grove 5:3f93dd1d4cb3 80 return hced->control & 0x7f;
sam_grove 5:3f93dd1d4cb3 81 }
sam_grove 5:3f93dd1d4cb3 82
sam_grove 5:3f93dd1d4cb3 83 void USBEndpoint::setSpeed(uint8_t speed) {
sam_grove 5:3f93dd1d4cb3 84 if(speed) {
sam_grove 5:3f93dd1d4cb3 85 DBG("SET LOW SPEED");
sam_grove 5:3f93dd1d4cb3 86 }
sam_grove 5:3f93dd1d4cb3 87 hced->control &= ~(1 << 13);
sam_grove 5:3f93dd1d4cb3 88 hced->control |= (speed << 13);
sam_grove 5:3f93dd1d4cb3 89 }
sam_grove 5:3f93dd1d4cb3 90
sam_grove 5:3f93dd1d4cb3 91
sam_grove 5:3f93dd1d4cb3 92 void USBEndpoint::setNextToken(uint32_t token) { //Only for control Eps
sam_grove 5:3f93dd1d4cb3 93 switch (token) {
sam_grove 5:3f93dd1d4cb3 94 case TD_SETUP:
sam_grove 5:3f93dd1d4cb3 95 dir = OUT;
sam_grove 5:3f93dd1d4cb3 96 setup = true;
sam_grove 5:3f93dd1d4cb3 97 break;
sam_grove 5:3f93dd1d4cb3 98 case TD_IN:
sam_grove 5:3f93dd1d4cb3 99 dir = IN;
sam_grove 5:3f93dd1d4cb3 100 setup = false;
sam_grove 5:3f93dd1d4cb3 101 break;
sam_grove 5:3f93dd1d4cb3 102 case TD_OUT:
sam_grove 5:3f93dd1d4cb3 103 dir = OUT;
sam_grove 5:3f93dd1d4cb3 104 setup = false;
sam_grove 5:3f93dd1d4cb3 105 break;
sam_grove 5:3f93dd1d4cb3 106 }
sam_grove 5:3f93dd1d4cb3 107 }
sam_grove 5:3f93dd1d4cb3 108
sam_grove 5:3f93dd1d4cb3 109 volatile HCTD* USBEndpoint::getNextTD()
sam_grove 5:3f93dd1d4cb3 110 {
sam_grove 5:3f93dd1d4cb3 111 return td_current/*(HCTD*) hced->tailTD*/; //It's the tailing one
sam_grove 5:3f93dd1d4cb3 112 }
sam_grove 5:3f93dd1d4cb3 113
sam_grove 5:3f93dd1d4cb3 114 void USBEndpoint::queueTransfer() {
sam_grove 5:3f93dd1d4cb3 115 //Try with OHCI impl
sam_grove 5:3f93dd1d4cb3 116 //Caller of getNextTD() has now populated the td
sam_grove 5:3f93dd1d4cb3 117 //So insert it into queue
sam_grove 5:3f93dd1d4cb3 118
sam_grove 5:3f93dd1d4cb3 119 //Find an OTHER free td
sam_grove 5:3f93dd1d4cb3 120 //TODO: if we had more than 2 tds, this would have to be changed
sam_grove 5:3f93dd1d4cb3 121 /*HCTD* toSendTD = (HCTD*) hced->tailTD;*/
sam_grove 5:3f93dd1d4cb3 122 //HCTD* freeTD;
sam_grove 5:3f93dd1d4cb3 123 /*
sam_grove 5:3f93dd1d4cb3 124 if( hced->tailTD == td_list[0] )
sam_grove 5:3f93dd1d4cb3 125 {
sam_grove 5:3f93dd1d4cb3 126 freeTD = td_list[1];
sam_grove 5:3f93dd1d4cb3 127 }
sam_grove 5:3f93dd1d4cb3 128 else *//*if( hced->tailTD == (uint32_t) td_list[1] )*/
sam_grove 5:3f93dd1d4cb3 129 /*{
sam_grove 5:3f93dd1d4cb3 130 freeTD = td_list[0];
sam_grove 5:3f93dd1d4cb3 131 }
sam_grove 5:3f93dd1d4cb3 132 */
sam_grove 5:3f93dd1d4cb3 133
sam_grove 5:3f93dd1d4cb3 134 /*
sam_grove 5:3f93dd1d4cb3 135 freeTD->control = 0;
sam_grove 5:3f93dd1d4cb3 136 freeTD->currBufPtr = 0;
sam_grove 5:3f93dd1d4cb3 137 freeTD->bufEnd = 0;
sam_grove 5:3f93dd1d4cb3 138 freeTD->nextTD = 0;
sam_grove 5:3f93dd1d4cb3 139
sam_grove 5:3f93dd1d4cb3 140 td_current = toSendTD;
sam_grove 5:3f93dd1d4cb3 141 */
sam_grove 5:3f93dd1d4cb3 142 transfer_len = td_current->bufEnd - td_current->currBufPtr + 1;
sam_grove 5:3f93dd1d4cb3 143 transferred = transfer_len;
sam_grove 5:3f93dd1d4cb3 144 buf_start = td_current->currBufPtr;
sam_grove 5:3f93dd1d4cb3 145
sam_grove 5:3f93dd1d4cb3 146 //No add this free TD at this end of the queue
sam_grove 5:3f93dd1d4cb3 147 state = USB_TYPE_PROCESSING;
sam_grove 5:3f93dd1d4cb3 148 td_current->nextTD = (volatile uint32_t)td_next;
sam_grove 5:3f93dd1d4cb3 149 hced->tailTD = (volatile uint32_t)td_next;
sam_grove 5:3f93dd1d4cb3 150
sam_grove 5:3f93dd1d4cb3 151 #if 0
sam_grove 5:3f93dd1d4cb3 152 // if TD list empty -> we put the head of the list
sam_grove 5:3f93dd1d4cb3 153 if (!hced->headTD) {
sam_grove 5:3f93dd1d4cb3 154 state = USB_TYPE_IDLE;
sam_grove 5:3f93dd1d4cb3 155 hced->headTD = (uint32_t)(td);
sam_grove 5:3f93dd1d4cb3 156 hced->tailTD = (uint32_t)(td);
sam_grove 5:3f93dd1d4cb3 157 tailTD = (HCTD *) (hced->headTD);
sam_grove 5:3f93dd1d4cb3 158 //DBG("queue null transfer: endpoint: %p, %08X\r\n", this, (uint32_t)(td));
sam_grove 5:3f93dd1d4cb3 159 } else {
sam_grove 5:3f93dd1d4cb3 160 state = USB_TYPE_PROCESSING;
sam_grove 5:3f93dd1d4cb3 161 td->nextTD = (uint32_t)headTD & ~(0x0f);
sam_grove 5:3f93dd1d4cb3 162 hced->headTD = (uint32_t)(td) | ((carry) ? 0x2 : 0);
sam_grove 5:3f93dd1d4cb3 163 }
sam_grove 5:3f93dd1d4cb3 164 headTD = (HCTD *) ((hced->headTD) & ~(0x3));
sam_grove 5:3f93dd1d4cb3 165 transfer_len = td->bufEnd - td->currBufPtr + 1;
sam_grove 5:3f93dd1d4cb3 166 transferred = transfer_len;
sam_grove 5:3f93dd1d4cb3 167 buf_start = td->currBufPtr;
sam_grove 5:3f93dd1d4cb3 168 #endif
sam_grove 5:3f93dd1d4cb3 169 //printf("queue real transfer: endpoint: %p \t headTD: %p \t head: %08X \t tail: %08X \t td: %08X \t nexttd: %08X\r\n", this, hced->headTD, hced->headTD, ((HCTD *)((hced->headTD) & ~(0x0f)))->nextTD, toSendTD, toSendTD->nextTD);
sam_grove 5:3f93dd1d4cb3 170 }
sam_grove 5:3f93dd1d4cb3 171
sam_grove 5:3f93dd1d4cb3 172 volatile HCTD * USBEndpoint::getProcessedTD()
sam_grove 5:3f93dd1d4cb3 173 {
sam_grove 5:3f93dd1d4cb3 174 return td_current;
sam_grove 5:3f93dd1d4cb3 175 }
sam_grove 5:3f93dd1d4cb3 176
sam_grove 5:3f93dd1d4cb3 177 void USBEndpoint::setLengthTransferred(int len) {
sam_grove 5:3f93dd1d4cb3 178 transferred = len;
sam_grove 5:3f93dd1d4cb3 179 }
sam_grove 5:3f93dd1d4cb3 180
sam_grove 5:3f93dd1d4cb3 181 uint32_t USBEndpoint::getBufStart() {
sam_grove 5:3f93dd1d4cb3 182 return buf_start;
sam_grove 5:3f93dd1d4cb3 183 }
sam_grove 5:3f93dd1d4cb3 184
sam_grove 5:3f93dd1d4cb3 185 void USBEndpoint::unqueueTransfer(volatile HCTD * td) {
sam_grove 5:3f93dd1d4cb3 186 //printf("unqueue transfer: %p on endpoint: %p\r\n", (void *)td, this);
sam_grove 5:3f93dd1d4cb3 187 //headTD = tailTD; //FIXME FIXME
sam_grove 5:3f93dd1d4cb3 188 // hced->headTD = hced->headTD | (td-> & 0x02);
sam_grove 5:3f93dd1d4cb3 189 if(td != td_current)
sam_grove 5:3f93dd1d4cb3 190 {
sam_grove 5:3f93dd1d4cb3 191 ERR("MISMATCH");
sam_grove 5:3f93dd1d4cb3 192 ERR("this=%p, td_current = %p, td_next=%p, td=%p", this, td_current, td_next, td);
sam_grove 5:3f93dd1d4cb3 193 error("");
sam_grove 5:3f93dd1d4cb3 194 }
sam_grove 5:3f93dd1d4cb3 195 td->control=0;
sam_grove 5:3f93dd1d4cb3 196 td->currBufPtr=0;
sam_grove 5:3f93dd1d4cb3 197 td->bufEnd=0;
sam_grove 5:3f93dd1d4cb3 198 td->nextTD=0;
sam_grove 5:3f93dd1d4cb3 199 hced->headTD = hced->tailTD | (hced->headTD & 0x2); //Carry bit
sam_grove 5:3f93dd1d4cb3 200 td_current = td_next;
sam_grove 5:3f93dd1d4cb3 201 td_next = td;
sam_grove 5:3f93dd1d4cb3 202 DBG("current:%p, next:%p", td_current, td_next);
sam_grove 5:3f93dd1d4cb3 203 }
sam_grove 5:3f93dd1d4cb3 204
sam_grove 5:3f93dd1d4cb3 205 ENDPOINT_TYPE USBEndpoint::getType() {
sam_grove 5:3f93dd1d4cb3 206 return type;
sam_grove 5:3f93dd1d4cb3 207 }
sam_grove 5:3f93dd1d4cb3 208
sam_grove 5:3f93dd1d4cb3 209
sam_grove 5:3f93dd1d4cb3 210 USBEndpoint * USBEndpoint::nextEndpoint() {
sam_grove 5:3f93dd1d4cb3 211 return (USBEndpoint*)nextEp;
sam_grove 5:3f93dd1d4cb3 212 }
sam_grove 5:3f93dd1d4cb3 213
sam_grove 5:3f93dd1d4cb3 214
sam_grove 5:3f93dd1d4cb3 215 void USBEndpoint::queueEndpoint(USBEndpoint * ed) {
sam_grove 5:3f93dd1d4cb3 216 nextEp = ed;
sam_grove 5:3f93dd1d4cb3 217 hced->nextED = (ed == NULL) ? 0 : (uint32_t)ed->getHCED();
sam_grove 5:3f93dd1d4cb3 218 }
sam_grove 5:3f93dd1d4cb3 219
sam_grove 5:3f93dd1d4cb3 220 volatile HCED * USBEndpoint::getHCED() {
sam_grove 5:3f93dd1d4cb3 221 return hced;
sam_grove 5:3f93dd1d4cb3 222 }
sam_grove 5:3f93dd1d4cb3 223
sam_grove 5:3f93dd1d4cb3 224
sam_grove 5:3f93dd1d4cb3 225 volatile HCTD * USBEndpoint::getHeadTD() {
sam_grove 5:3f93dd1d4cb3 226 //return headTD;
sam_grove 5:3f93dd1d4cb3 227 return (volatile HCTD*) (hced->headTD & ~0xF);
sam_grove 5:3f93dd1d4cb3 228 }
sam_grove 5:3f93dd1d4cb3 229
sam_grove 5:3f93dd1d4cb3 230 volatile HCTD ** USBEndpoint::getTDList()
sam_grove 5:3f93dd1d4cb3 231 {
sam_grove 5:3f93dd1d4cb3 232 return td_list;
sam_grove 5:3f93dd1d4cb3 233 }