Vodafone K3770/K3772-Z modems driver & networking library

Dependencies:   Socket USBHostWANDongle lwip-sys lwip

Dependents:   VodafoneUSBModemHTTPClientTest VodafoneUSBModemNTPClientTest VodafoneUSBModemSMSTest VodafoneUSBModemUSSDTest ... more

Fork of VodafoneUSBModem_bleedingedge by Donatien Garnier

This is the driver for the Vodafone K3700 & K3772-Z Dongles:

K3770

More details and instructions can be found here.

Committer:
ashleymills
Date:
Fri Apr 25 13:33:55 2014 +0000
Revision:
95:84f01d280c9b
Parent:
91:7b311719374d
Updated lwip to latest mbed version.; Removed useless debug function and messages.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 16:02db4f537955 1 /* MtxCircBuf.h */
donatien 16:02db4f537955 2 /* Copyright (C) 2012 mbed.org, MIT License
donatien 16:02db4f537955 3 *
donatien 16:02db4f537955 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
donatien 16:02db4f537955 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
donatien 16:02db4f537955 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
donatien 16:02db4f537955 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
donatien 16:02db4f537955 8 * furnished to do so, subject to the following conditions:
donatien 16:02db4f537955 9 *
donatien 16:02db4f537955 10 * The above copyright notice and this permission notice shall be included in all copies or
donatien 16:02db4f537955 11 * substantial portions of the Software.
donatien 16:02db4f537955 12 *
donatien 16:02db4f537955 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
donatien 16:02db4f537955 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
donatien 16:02db4f537955 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
donatien 16:02db4f537955 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 16:02db4f537955 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
donatien 16:02db4f537955 18 */
donatien 16:02db4f537955 19
donatien 16:02db4f537955 20 #ifndef MTXCIRCBUFFER_H
donatien 16:02db4f537955 21 #define MTXCIRCBUFFER_H
donatien 16:02db4f537955 22
donatien 16:02db4f537955 23 #include "fwk.h"
donatien 16:02db4f537955 24
donatien 16:02db4f537955 25 #include "rtos.h"
donatien 16:02db4f537955 26
donatien 16:02db4f537955 27 //Mutex protected circualr buffer
donatien 16:02db4f537955 28 template<typename T, int size>
donatien 16:02db4f537955 29 class MtxCircBuffer
donatien 16:02db4f537955 30 {
donatien 16:02db4f537955 31 public:
donatien 16:02db4f537955 32 MtxCircBuffer() //:
donatien 16:02db4f537955 33 //mtx()
donatien 16:02db4f537955 34 {
donatien 16:02db4f537955 35 write = 0;
donatien 16:02db4f537955 36 read = 0;
donatien 16:02db4f537955 37 }
donatien 16:02db4f537955 38
donatien 16:02db4f537955 39 bool isFull()
donatien 16:02db4f537955 40 {
donatien 16:02db4f537955 41 mtx.lock();
donatien 16:02db4f537955 42 bool r = (((write + 1) % size) == read);
donatien 16:02db4f537955 43 mtx.unlock();
donatien 16:02db4f537955 44 return r;
donatien 16:02db4f537955 45 }
donatien 16:02db4f537955 46
donatien 16:02db4f537955 47 bool isEmpty()
donatien 16:02db4f537955 48 {
donatien 16:02db4f537955 49 mtx.lock();
donatien 16:02db4f537955 50 bool r = (read == write);
donatien 16:02db4f537955 51 mtx.unlock();
donatien 16:02db4f537955 52 return r;
donatien 16:02db4f537955 53 }
donatien 16:02db4f537955 54
donatien 16:02db4f537955 55 void queue(T k)
donatien 16:02db4f537955 56 {
ashleymills 91:7b311719374d 57 // XXX Some modems spew stuff out on multiple interfaces
ashleymills 91:7b311719374d 58 // which can cause the circular buffer to block if
ashleymills 91:7b311719374d 59 // the unread queues are not flushed. Need to make this
ashleymills 91:7b311719374d 60 // non-blocking: just overwrite oldest chars for example.
donatien 16:02db4f537955 61 mtx.lock();
donatien 16:02db4f537955 62 while (((write + 1) % size) == read) //if (isFull())
donatien 16:02db4f537955 63 {
donatien 16:02db4f537955 64 /*while((((write + 1) % size) == read))
donatien 16:02db4f537955 65 {*/
donatien 16:02db4f537955 66 mtx.unlock();
donatien 16:02db4f537955 67 Thread::wait(10);
donatien 16:02db4f537955 68 mtx.lock();
donatien 16:02db4f537955 69 /*}*/
donatien 16:02db4f537955 70 //read++;
donatien 16:02db4f537955 71 //read %= size;
donatien 16:02db4f537955 72 }
donatien 16:02db4f537955 73 buf[write++] = k;
donatien 16:02db4f537955 74 write %= size;
donatien 16:02db4f537955 75 mtx.unlock();
donatien 16:02db4f537955 76 }
donatien 16:02db4f537955 77
donatien 16:02db4f537955 78 uint16_t available()
donatien 16:02db4f537955 79 {
donatien 16:02db4f537955 80 mtx.lock();
donatien 16:02db4f537955 81 uint16_t a = (write >= read) ? (write - read) : (size - read + write);
donatien 16:02db4f537955 82 mtx.unlock();
donatien 16:02db4f537955 83 return a;
donatien 16:02db4f537955 84 }
donatien 16:02db4f537955 85
donatien 16:02db4f537955 86 bool dequeue(T * c)
donatien 16:02db4f537955 87 {
donatien 16:02db4f537955 88 mtx.lock();
donatien 16:02db4f537955 89 bool empty = (read == write);
donatien 16:02db4f537955 90 if (!empty)
donatien 16:02db4f537955 91 {
donatien 16:02db4f537955 92 *c = buf[read++];
donatien 16:02db4f537955 93 read %= size;
donatien 16:02db4f537955 94 }
donatien 16:02db4f537955 95 mtx.unlock();
donatien 16:02db4f537955 96 return (!empty);
donatien 16:02db4f537955 97 }
donatien 16:02db4f537955 98
donatien 16:02db4f537955 99 private:
donatien 16:02db4f537955 100 volatile uint16_t write;
donatien 16:02db4f537955 101 volatile uint16_t read;
donatien 16:02db4f537955 102 volatile T buf[size];
donatien 16:02db4f537955 103 Mutex mtx;
donatien 16:02db4f537955 104 };
donatien 16:02db4f537955 105
donatien 16:02db4f537955 106 #endif
donatien 16:02db4f537955 107