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:
Wed Jun 26 02:39:59 2013 +0000
Revision:
37:e61ea8267415
Parent:
29:1c4419512941
fix uart lock; sort functions

Who changed what in which revision?

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