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