GainSpan Wi-Fi library see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Dependents:   GSwifi_httpd GSwifi_websocket GSwifi_tcpclient GSwifi_tcpserver ... more

Fork of GSwifi by gs fan

GainSpan Wi-Fi library

The GS1011 is an ultra low power 802.11b wireless module from GainSpan.

see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

/media/uploads/gsfan/gs_im_002.jpg /media/uploads/gsfan/gs1011m_2.jpg

ゲインスパン Wi-Fi モジュール ライブラリ

ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。

解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Committer:
gsfan
Date:
Mon Feb 11 06:01:46 2013 +0000
Revision:
25:f6e5622d2930
Child:
26:b347ee3a1087
split the file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gsfan 25:f6e5622d2930 1 /* Copyright (C) 2012 mbed.org, MIT License
gsfan 25:f6e5622d2930 2 *
gsfan 25:f6e5622d2930 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
gsfan 25:f6e5622d2930 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
gsfan 25:f6e5622d2930 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
gsfan 25:f6e5622d2930 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
gsfan 25:f6e5622d2930 7 * furnished to do so, subject to the following conditions:
gsfan 25:f6e5622d2930 8 *
gsfan 25:f6e5622d2930 9 * The above copyright notice and this permission notice shall be included in all copies or
gsfan 25:f6e5622d2930 10 * substantial portions of the Software.
gsfan 25:f6e5622d2930 11 *
gsfan 25:f6e5622d2930 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
gsfan 25:f6e5622d2930 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
gsfan 25:f6e5622d2930 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
gsfan 25:f6e5622d2930 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gsfan 25:f6e5622d2930 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
gsfan 25:f6e5622d2930 17 */
gsfan 25:f6e5622d2930 18
gsfan 25:f6e5622d2930 19 #ifndef CIRCBUFFER_H_
gsfan 25:f6e5622d2930 20 #define CIRCBUFFER_H_
gsfan 25:f6e5622d2930 21
gsfan 25:f6e5622d2930 22 template <class T>
gsfan 25:f6e5622d2930 23 class CircBuffer {
gsfan 25:f6e5622d2930 24 public:
gsfan 25:f6e5622d2930 25 CircBuffer(int length) {
gsfan 25:f6e5622d2930 26 write = 0;
gsfan 25:f6e5622d2930 27 read = 0;
gsfan 25:f6e5622d2930 28 size = length + 1;
gsfan 25:f6e5622d2930 29 buf = (T *)malloc(size * sizeof(T));
gsfan 25:f6e5622d2930 30 };
gsfan 25:f6e5622d2930 31
gsfan 25:f6e5622d2930 32 bool isFull() {
gsfan 25:f6e5622d2930 33 return (((write + 1) % size) == read);
gsfan 25:f6e5622d2930 34 };
gsfan 25:f6e5622d2930 35
gsfan 25:f6e5622d2930 36 bool isEmpty() {
gsfan 25:f6e5622d2930 37 return (read == write);
gsfan 25:f6e5622d2930 38 };
gsfan 25:f6e5622d2930 39
gsfan 25:f6e5622d2930 40 void queue(T k) {
gsfan 25:f6e5622d2930 41 if (isFull()) {
gsfan 25:f6e5622d2930 42 read++;
gsfan 25:f6e5622d2930 43 read %= size;
gsfan 25:f6e5622d2930 44 }
gsfan 25:f6e5622d2930 45 buf[write++] = k;
gsfan 25:f6e5622d2930 46 write %= size;
gsfan 25:f6e5622d2930 47 }
gsfan 25:f6e5622d2930 48
gsfan 25:f6e5622d2930 49 void flush() {
gsfan 25:f6e5622d2930 50 read = 0;
gsfan 25:f6e5622d2930 51 write = 0;
gsfan 25:f6e5622d2930 52 }
gsfan 25:f6e5622d2930 53
gsfan 25:f6e5622d2930 54
gsfan 25:f6e5622d2930 55 uint32_t available() {
gsfan 25:f6e5622d2930 56 return (write >= read) ? write - read : size - read + write;
gsfan 25:f6e5622d2930 57 };
gsfan 25:f6e5622d2930 58
gsfan 25:f6e5622d2930 59 uint32_t use() {
gsfan 25:f6e5622d2930 60 return size - available() - 1;
gsfan 25:f6e5622d2930 61 };
gsfan 25:f6e5622d2930 62
gsfan 25:f6e5622d2930 63 bool dequeue(T * c) {
gsfan 25:f6e5622d2930 64 bool empty = isEmpty();
gsfan 25:f6e5622d2930 65 if (!empty) {
gsfan 25:f6e5622d2930 66 *c = buf[read++];
gsfan 25:f6e5622d2930 67 read %= size;
gsfan 25:f6e5622d2930 68 }
gsfan 25:f6e5622d2930 69 return(!empty);
gsfan 25:f6e5622d2930 70 };
gsfan 25:f6e5622d2930 71
gsfan 25:f6e5622d2930 72 private:
gsfan 25:f6e5622d2930 73 volatile uint32_t write;
gsfan 25:f6e5622d2930 74 volatile uint32_t read;
gsfan 25:f6e5622d2930 75 uint32_t size;
gsfan 25:f6e5622d2930 76 T * buf;
gsfan 25:f6e5622d2930 77 };
gsfan 25:f6e5622d2930 78
gsfan 25:f6e5622d2930 79 #endif