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 #define __DEBUG__ 0
sam_grove 5:3f93dd1d4cb3 20 #ifndef __MODULE__
sam_grove 5:3f93dd1d4cb3 21 #define __MODULE__ "WANDongleSerialPort.cpp"
sam_grove 5:3f93dd1d4cb3 22 #endif
sam_grove 5:3f93dd1d4cb3 23
sam_grove 5:3f93dd1d4cb3 24 #include "core/dbg.h"
sam_grove 5:3f93dd1d4cb3 25 #include <cstdint>
sam_grove 5:3f93dd1d4cb3 26 #include "rtos.h"
sam_grove 5:3f93dd1d4cb3 27
sam_grove 5:3f93dd1d4cb3 28 #include "WANDongleSerialPort.h"
sam_grove 5:3f93dd1d4cb3 29
sam_grove 5:3f93dd1d4cb3 30 WANDongleSerialPort::WANDongleSerialPort() : cb_tx_en(false), cb_rx_en(false), listener(NULL)
sam_grove 5:3f93dd1d4cb3 31 {
sam_grove 5:3f93dd1d4cb3 32 reset();
sam_grove 5:3f93dd1d4cb3 33 }
sam_grove 5:3f93dd1d4cb3 34
sam_grove 5:3f93dd1d4cb3 35 void WANDongleSerialPort::init(USBHost* pHost)
sam_grove 5:3f93dd1d4cb3 36 {
sam_grove 5:3f93dd1d4cb3 37 host = pHost;
sam_grove 5:3f93dd1d4cb3 38 }
sam_grove 5:3f93dd1d4cb3 39
sam_grove 5:3f93dd1d4cb3 40 void WANDongleSerialPort::reset()
sam_grove 5:3f93dd1d4cb3 41 {
sam_grove 5:3f93dd1d4cb3 42 tx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 43 rx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 44
sam_grove 5:3f93dd1d4cb3 45 bulk_in = NULL;
sam_grove 5:3f93dd1d4cb3 46 bulk_out = NULL;
sam_grove 5:3f93dd1d4cb3 47
sam_grove 5:3f93dd1d4cb3 48 buf_out_len = 0;
sam_grove 5:3f93dd1d4cb3 49 max_out_size = 0;
sam_grove 5:3f93dd1d4cb3 50 lock_tx = false;
sam_grove 5:3f93dd1d4cb3 51 cb_tx_pending = false;
sam_grove 5:3f93dd1d4cb3 52
sam_grove 5:3f93dd1d4cb3 53 buf_in_len = 0;
sam_grove 5:3f93dd1d4cb3 54 buf_in_read_pos = 0;
sam_grove 5:3f93dd1d4cb3 55 lock_rx = false;
sam_grove 5:3f93dd1d4cb3 56 cb_rx_pending = false;
sam_grove 5:3f93dd1d4cb3 57
sam_grove 5:3f93dd1d4cb3 58 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 59 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 60 }
sam_grove 5:3f93dd1d4cb3 61
sam_grove 5:3f93dd1d4cb3 62 int WANDongleSerialPort::readPacket()
sam_grove 5:3f93dd1d4cb3 63 {
sam_grove 5:3f93dd1d4cb3 64 DBG("Read packet on %p", this);
sam_grove 5:3f93dd1d4cb3 65 rx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 66 if(lock_rx)
sam_grove 5:3f93dd1d4cb3 67 {
sam_grove 5:3f93dd1d4cb3 68 ERR("Fail");
sam_grove 5:3f93dd1d4cb3 69 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 70 return -1;
sam_grove 5:3f93dd1d4cb3 71 }
sam_grove 5:3f93dd1d4cb3 72
sam_grove 5:3f93dd1d4cb3 73 if( bulk_in == NULL )
sam_grove 5:3f93dd1d4cb3 74 {
sam_grove 5:3f93dd1d4cb3 75 WARN("Port is disconnected");
sam_grove 5:3f93dd1d4cb3 76 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 77 return -1;
sam_grove 5:3f93dd1d4cb3 78 }
sam_grove 5:3f93dd1d4cb3 79
sam_grove 5:3f93dd1d4cb3 80 lock_rx = true; //Receiving
sam_grove 5:3f93dd1d4cb3 81 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 82 // DBG("readPacket");
sam_grove 5:3f93dd1d4cb3 83 //lock_rx.lock();
sam_grove 5:3f93dd1d4cb3 84 host->lock();
sam_grove 5:3f93dd1d4cb3 85 USB_TYPE res = host->bulkRead(dev, (USBEndpoint *)bulk_in, buf_in, ((USBEndpoint *)bulk_in)->getSize(), false); //Queue transfer
sam_grove 5:3f93dd1d4cb3 86 if(res != USB_TYPE_PROCESSING)
sam_grove 5:3f93dd1d4cb3 87 {
sam_grove 5:3f93dd1d4cb3 88 host->unlock();
sam_grove 5:3f93dd1d4cb3 89 //lock_rx.unlock();
sam_grove 5:3f93dd1d4cb3 90 ERR("host->bulkRead() returned %d", res);
sam_grove 5:3f93dd1d4cb3 91 Thread::wait(100);
sam_grove 5:3f93dd1d4cb3 92 return -1;
sam_grove 5:3f93dd1d4cb3 93 }
sam_grove 5:3f93dd1d4cb3 94 host->unlock();
sam_grove 5:3f93dd1d4cb3 95 return 0;
sam_grove 5:3f93dd1d4cb3 96 }
sam_grove 5:3f93dd1d4cb3 97
sam_grove 5:3f93dd1d4cb3 98 int WANDongleSerialPort::writePacket()
sam_grove 5:3f93dd1d4cb3 99 {
sam_grove 5:3f93dd1d4cb3 100 tx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 101 if(lock_tx)
sam_grove 5:3f93dd1d4cb3 102 {
sam_grove 5:3f93dd1d4cb3 103 ERR("Fail");
sam_grove 5:3f93dd1d4cb3 104 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 105 return -1;
sam_grove 5:3f93dd1d4cb3 106 }
sam_grove 5:3f93dd1d4cb3 107
sam_grove 5:3f93dd1d4cb3 108 if( bulk_out == NULL )
sam_grove 5:3f93dd1d4cb3 109 {
sam_grove 5:3f93dd1d4cb3 110 WARN("Port is disconnected");
sam_grove 5:3f93dd1d4cb3 111 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 112 return -1;
sam_grove 5:3f93dd1d4cb3 113 }
sam_grove 5:3f93dd1d4cb3 114
sam_grove 5:3f93dd1d4cb3 115 lock_tx = true; //Transmitting
sam_grove 5:3f93dd1d4cb3 116 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 117 // DBG("writePacket");
sam_grove 5:3f93dd1d4cb3 118
sam_grove 5:3f93dd1d4cb3 119 //lock_tx.lock();
sam_grove 5:3f93dd1d4cb3 120 host->lock();
sam_grove 5:3f93dd1d4cb3 121 USB_TYPE res = host->bulkWrite(dev, (USBEndpoint *)bulk_out, buf_out, buf_out_len, false); //Queue transfer
sam_grove 5:3f93dd1d4cb3 122 if(res != USB_TYPE_PROCESSING)
sam_grove 5:3f93dd1d4cb3 123 {
sam_grove 5:3f93dd1d4cb3 124 host->unlock();
sam_grove 5:3f93dd1d4cb3 125 //lock_tx.unlock();
sam_grove 5:3f93dd1d4cb3 126 ERR("host->bulkWrite() returned %d", res);
sam_grove 5:3f93dd1d4cb3 127 Thread::wait(100);
sam_grove 5:3f93dd1d4cb3 128 return -1;
sam_grove 5:3f93dd1d4cb3 129 }
sam_grove 5:3f93dd1d4cb3 130 host->unlock();
sam_grove 5:3f93dd1d4cb3 131 return 0;
sam_grove 5:3f93dd1d4cb3 132 }
sam_grove 5:3f93dd1d4cb3 133
sam_grove 5:3f93dd1d4cb3 134 int WANDongleSerialPort::putc(int c)
sam_grove 5:3f93dd1d4cb3 135 {
sam_grove 5:3f93dd1d4cb3 136 tx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 137 if(!lock_tx)
sam_grove 5:3f93dd1d4cb3 138 {
sam_grove 5:3f93dd1d4cb3 139 if(buf_out_len < max_out_size)
sam_grove 5:3f93dd1d4cb3 140 {
sam_grove 5:3f93dd1d4cb3 141 buf_out[buf_out_len] = (uint8_t)c;
sam_grove 5:3f93dd1d4cb3 142 buf_out_len++;
sam_grove 5:3f93dd1d4cb3 143 }
sam_grove 5:3f93dd1d4cb3 144 }
sam_grove 5:3f93dd1d4cb3 145 else
sam_grove 5:3f93dd1d4cb3 146 {
sam_grove 5:3f93dd1d4cb3 147 ERR("CAN'T WRITE!");
sam_grove 5:3f93dd1d4cb3 148 }
sam_grove 5:3f93dd1d4cb3 149 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 150 return c;
sam_grove 5:3f93dd1d4cb3 151 }
sam_grove 5:3f93dd1d4cb3 152
sam_grove 5:3f93dd1d4cb3 153 int WANDongleSerialPort::getc()
sam_grove 5:3f93dd1d4cb3 154 {
sam_grove 5:3f93dd1d4cb3 155 rx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 156 int c = 0;
sam_grove 5:3f93dd1d4cb3 157 if(!lock_rx)
sam_grove 5:3f93dd1d4cb3 158 {
sam_grove 5:3f93dd1d4cb3 159 if(buf_in_read_pos < buf_in_len)
sam_grove 5:3f93dd1d4cb3 160 {
sam_grove 5:3f93dd1d4cb3 161 c = (int)buf_in[buf_in_read_pos];
sam_grove 5:3f93dd1d4cb3 162 buf_in_read_pos++;
sam_grove 5:3f93dd1d4cb3 163 }
sam_grove 5:3f93dd1d4cb3 164 }
sam_grove 5:3f93dd1d4cb3 165 else
sam_grove 5:3f93dd1d4cb3 166 {
sam_grove 5:3f93dd1d4cb3 167 ERR("CAN'T READ!");
sam_grove 5:3f93dd1d4cb3 168 }
sam_grove 5:3f93dd1d4cb3 169 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 170 return c;
sam_grove 5:3f93dd1d4cb3 171 }
sam_grove 5:3f93dd1d4cb3 172
sam_grove 5:3f93dd1d4cb3 173 int WANDongleSerialPort::readable()
sam_grove 5:3f93dd1d4cb3 174 {
sam_grove 5:3f93dd1d4cb3 175 rx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 176 if (lock_rx)
sam_grove 5:3f93dd1d4cb3 177 {
sam_grove 5:3f93dd1d4cb3 178 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 179 return 0;
sam_grove 5:3f93dd1d4cb3 180 }
sam_grove 5:3f93dd1d4cb3 181
sam_grove 5:3f93dd1d4cb3 182 /* if( !lock_rx.trylock() )
sam_grove 5:3f93dd1d4cb3 183 {
sam_grove 5:3f93dd1d4cb3 184 return 0;
sam_grove 5:3f93dd1d4cb3 185 }*/
sam_grove 5:3f93dd1d4cb3 186 int res = buf_in_len - buf_in_read_pos;
sam_grove 5:3f93dd1d4cb3 187 //lock_rx.unlock();
sam_grove 5:3f93dd1d4cb3 188 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 189 return res;
sam_grove 5:3f93dd1d4cb3 190 }
sam_grove 5:3f93dd1d4cb3 191
sam_grove 5:3f93dd1d4cb3 192 int WANDongleSerialPort::writeable()
sam_grove 5:3f93dd1d4cb3 193 {
sam_grove 5:3f93dd1d4cb3 194 tx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 195 if (lock_tx)
sam_grove 5:3f93dd1d4cb3 196 {
sam_grove 5:3f93dd1d4cb3 197 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 198 return 0;
sam_grove 5:3f93dd1d4cb3 199 }
sam_grove 5:3f93dd1d4cb3 200
sam_grove 5:3f93dd1d4cb3 201 /*if( !lock_tx.trylock() )
sam_grove 5:3f93dd1d4cb3 202 {
sam_grove 5:3f93dd1d4cb3 203 return 0;
sam_grove 5:3f93dd1d4cb3 204 }*/
sam_grove 5:3f93dd1d4cb3 205 int res = max_out_size - buf_out_len;
sam_grove 5:3f93dd1d4cb3 206 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 207 //lock_tx.unlock();
sam_grove 5:3f93dd1d4cb3 208 return res;
sam_grove 5:3f93dd1d4cb3 209 }
sam_grove 5:3f93dd1d4cb3 210
sam_grove 5:3f93dd1d4cb3 211 void WANDongleSerialPort::attach(IUSBHostSerialListener* pListener)
sam_grove 5:3f93dd1d4cb3 212 {
sam_grove 5:3f93dd1d4cb3 213 if(pListener == NULL)
sam_grove 5:3f93dd1d4cb3 214 {
sam_grove 5:3f93dd1d4cb3 215 setupIrq(false, RxIrq);
sam_grove 5:3f93dd1d4cb3 216 setupIrq(false, TxIrq);
sam_grove 5:3f93dd1d4cb3 217 }
sam_grove 5:3f93dd1d4cb3 218 listener = pListener;
sam_grove 5:3f93dd1d4cb3 219 if(pListener != NULL)
sam_grove 5:3f93dd1d4cb3 220 {
sam_grove 5:3f93dd1d4cb3 221 setupIrq(true, RxIrq);
sam_grove 5:3f93dd1d4cb3 222 setupIrq(true, TxIrq);
sam_grove 5:3f93dd1d4cb3 223 }
sam_grove 5:3f93dd1d4cb3 224 }
sam_grove 5:3f93dd1d4cb3 225
sam_grove 5:3f93dd1d4cb3 226 void WANDongleSerialPort::setupIrq(bool en, IrqType irq /*= RxIrq*/)
sam_grove 5:3f93dd1d4cb3 227 {
sam_grove 5:3f93dd1d4cb3 228 switch(irq)
sam_grove 5:3f93dd1d4cb3 229 {
sam_grove 5:3f93dd1d4cb3 230 case RxIrq:
sam_grove 5:3f93dd1d4cb3 231 rx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 232 cb_rx_en = en;
sam_grove 5:3f93dd1d4cb3 233 if(en && cb_rx_pending)
sam_grove 5:3f93dd1d4cb3 234 {
sam_grove 5:3f93dd1d4cb3 235 cb_rx_pending = false;
sam_grove 5:3f93dd1d4cb3 236 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 237 listener->readable(); //Process the interrupt that was raised
sam_grove 5:3f93dd1d4cb3 238 }
sam_grove 5:3f93dd1d4cb3 239 else
sam_grove 5:3f93dd1d4cb3 240 {
sam_grove 5:3f93dd1d4cb3 241 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 242 }
sam_grove 5:3f93dd1d4cb3 243 break;
sam_grove 5:3f93dd1d4cb3 244 case TxIrq:
sam_grove 5:3f93dd1d4cb3 245 tx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 246 cb_tx_en = en;
sam_grove 5:3f93dd1d4cb3 247 if(en && cb_tx_pending)
sam_grove 5:3f93dd1d4cb3 248 {
sam_grove 5:3f93dd1d4cb3 249 cb_tx_pending = false;
sam_grove 5:3f93dd1d4cb3 250 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 251 listener->writeable(); //Process the interrupt that was raised
sam_grove 5:3f93dd1d4cb3 252 }
sam_grove 5:3f93dd1d4cb3 253 else
sam_grove 5:3f93dd1d4cb3 254 {
sam_grove 5:3f93dd1d4cb3 255 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 256 }
sam_grove 5:3f93dd1d4cb3 257 break;
sam_grove 5:3f93dd1d4cb3 258 }
sam_grove 5:3f93dd1d4cb3 259 }
sam_grove 5:3f93dd1d4cb3 260
sam_grove 5:3f93dd1d4cb3 261
sam_grove 5:3f93dd1d4cb3 262 void WANDongleSerialPort::connect( USBDeviceConnected* pDev, USBEndpoint* pInEp, USBEndpoint* pOutEp )
sam_grove 5:3f93dd1d4cb3 263 {
sam_grove 5:3f93dd1d4cb3 264 dev = pDev;
sam_grove 5:3f93dd1d4cb3 265 bulk_in = pInEp;
sam_grove 5:3f93dd1d4cb3 266 bulk_out = pOutEp;
sam_grove 5:3f93dd1d4cb3 267 max_out_size = bulk_out->getSize();
sam_grove 5:3f93dd1d4cb3 268 if( max_out_size > WANDONGLE_MAX_OUTEP_SIZE )
sam_grove 5:3f93dd1d4cb3 269 {
sam_grove 5:3f93dd1d4cb3 270 max_out_size = WANDONGLE_MAX_OUTEP_SIZE;
sam_grove 5:3f93dd1d4cb3 271 }
sam_grove 5:3f93dd1d4cb3 272 bulk_in->attach(this, &WANDongleSerialPort::rxHandler);
sam_grove 5:3f93dd1d4cb3 273 bulk_out->attach(this, &WANDongleSerialPort::txHandler);
sam_grove 5:3f93dd1d4cb3 274 readPacket(); //Start receiving data
sam_grove 5:3f93dd1d4cb3 275 }
sam_grove 5:3f93dd1d4cb3 276
sam_grove 5:3f93dd1d4cb3 277 void WANDongleSerialPort::disconnect( )
sam_grove 5:3f93dd1d4cb3 278 {
sam_grove 5:3f93dd1d4cb3 279 reset();
sam_grove 5:3f93dd1d4cb3 280 }
sam_grove 5:3f93dd1d4cb3 281
sam_grove 5:3f93dd1d4cb3 282 //Private methods
sam_grove 5:3f93dd1d4cb3 283
sam_grove 5:3f93dd1d4cb3 284
sam_grove 5:3f93dd1d4cb3 285 void WANDongleSerialPort::rxHandler()
sam_grove 5:3f93dd1d4cb3 286 {
sam_grove 5:3f93dd1d4cb3 287 if (((USBEndpoint *) bulk_in)->getState() == USB_TYPE_IDLE) //Success
sam_grove 5:3f93dd1d4cb3 288 {
sam_grove 5:3f93dd1d4cb3 289 buf_in_read_pos = 0;
sam_grove 5:3f93dd1d4cb3 290 buf_in_len = ((USBEndpoint *) bulk_in)->getLengthTransferred(); //Update length
sam_grove 5:3f93dd1d4cb3 291 //lock_rx.unlock();
sam_grove 5:3f93dd1d4cb3 292 rx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 293 lock_rx = false; //Transmission complete
sam_grove 5:3f93dd1d4cb3 294 if(cb_rx_en)
sam_grove 5:3f93dd1d4cb3 295 {
sam_grove 5:3f93dd1d4cb3 296 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 297 listener->readable(); //Call handler from the IRQ context
sam_grove 5:3f93dd1d4cb3 298 //readPacket() should be called by the handler subsequently once the buffer has been emptied
sam_grove 5:3f93dd1d4cb3 299 }
sam_grove 5:3f93dd1d4cb3 300 else
sam_grove 5:3f93dd1d4cb3 301 {
sam_grove 5:3f93dd1d4cb3 302 cb_rx_pending = true; //Queue the callback
sam_grove 5:3f93dd1d4cb3 303 rx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 304 }
sam_grove 5:3f93dd1d4cb3 305
sam_grove 5:3f93dd1d4cb3 306 }
sam_grove 5:3f93dd1d4cb3 307 else //Error, try reading again
sam_grove 5:3f93dd1d4cb3 308 {
sam_grove 5:3f93dd1d4cb3 309 //lock_rx.unlock();
sam_grove 5:3f93dd1d4cb3 310 DBG("Trying again");
sam_grove 5:3f93dd1d4cb3 311 readPacket();
sam_grove 5:3f93dd1d4cb3 312 }
sam_grove 5:3f93dd1d4cb3 313 }
sam_grove 5:3f93dd1d4cb3 314
sam_grove 5:3f93dd1d4cb3 315 void WANDongleSerialPort::txHandler()
sam_grove 5:3f93dd1d4cb3 316 {
sam_grove 5:3f93dd1d4cb3 317 if (((USBEndpoint *) bulk_out)->getState() == USB_TYPE_IDLE) //Success
sam_grove 5:3f93dd1d4cb3 318 {
sam_grove 5:3f93dd1d4cb3 319 tx_mtx.lock();
sam_grove 5:3f93dd1d4cb3 320 buf_out_len = 0; //Reset length
sam_grove 5:3f93dd1d4cb3 321 lock_tx = false; //Transmission complete
sam_grove 5:3f93dd1d4cb3 322 //lock_tx.unlock();
sam_grove 5:3f93dd1d4cb3 323 if(cb_tx_en)
sam_grove 5:3f93dd1d4cb3 324 {
sam_grove 5:3f93dd1d4cb3 325 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 326 listener->writeable(); //Call handler from the IRQ context
sam_grove 5:3f93dd1d4cb3 327 //writePacket() should be called by the handler subsequently once the buffer has been filled
sam_grove 5:3f93dd1d4cb3 328 }
sam_grove 5:3f93dd1d4cb3 329 else
sam_grove 5:3f93dd1d4cb3 330 {
sam_grove 5:3f93dd1d4cb3 331 cb_tx_pending = true; //Queue the callback
sam_grove 5:3f93dd1d4cb3 332 tx_mtx.unlock();
sam_grove 5:3f93dd1d4cb3 333 }
sam_grove 5:3f93dd1d4cb3 334 }
sam_grove 5:3f93dd1d4cb3 335 else //Error, try reading again
sam_grove 5:3f93dd1d4cb3 336 {
sam_grove 5:3f93dd1d4cb3 337 //lock_tx.unlock();
sam_grove 5:3f93dd1d4cb3 338 writePacket();
sam_grove 5:3f93dd1d4cb3 339 }
sam_grove 5:3f93dd1d4cb3 340 }