GSwifiInterface library (interface for GainSpan Wi-Fi GS1011 modules) Please see https://mbed.org/users/gsfan/notebook/GSwifiInterface/

Dependents:   GSwifiInterface_HelloWorld GSwifiInterface_HelloServo GSwifiInterface_UDPEchoServer GSwifiInterface_UDPEchoClient ... more

Fork of WiflyInterface by mbed official

GainSpan Wi-Fi library

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

mbed RTOS supported.

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

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

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

mbed RTOS に対応しています。(mbed2.0)

Files at this revision

API Documentation at this revision

Comitter:
gsfan
Date:
Thu Jun 05 04:21:02 2014 +0000
Parent:
18:20970aec3ad3
Child:
20:9bfb8a13010c
Commit message:
supported http server with rtos

Changed in this revision

GSwifi/CBuffer.h Show annotated file Show diff for this revision Revisions of this file
GSwifi/GSwifi.cpp Show annotated file Show diff for this revision Revisions of this file
GSwifi/GSwifi.h Show annotated file Show diff for this revision Revisions of this file
GSwifi/GSwifi_conf.h Show annotated file Show diff for this revision Revisions of this file
GSwifi/GSwifi_hal.cpp Show annotated file Show diff for this revision Revisions of this file
GSwifi/GSwifi_httpd.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GSwifi/CBuffer.h	Mon May 12 01:24:09 2014 +0000
+++ b/GSwifi/CBuffer.h	Thu Jun 05 04:21:02 2014 +0000
@@ -22,11 +22,15 @@
 template <class T>
 class CircBuffer {
 public:
-    CircBuffer(int length) {
+    CircBuffer(int length, void *addr = NULL) {
         write = 0;
         read = 0;
         size = length + 1;
-        buf = (T *)malloc(size * sizeof(T));
+        if (addr) {
+            buf = (T *)addr;
+        } else {
+            buf = (T *)malloc(size * sizeof(T));
+        }
         if (buf == NULL)
             error("Can't allocate memory");
     };
--- a/GSwifi/GSwifi.cpp	Mon May 12 01:24:09 2014 +0000
+++ b/GSwifi/GSwifi.cpp	Thu Jun 05 04:21:02 2014 +0000
@@ -32,6 +32,18 @@
     _state.initialized = false;
     _state.status = STAT_READY;
     _state.cid = -1;
+#ifdef CFG_EXTENDED_MEMORY1
+    int n = CFG_EXTENDED_SIZE1 / (CFG_MAX_SOCKETS + 1);
+    _state.buf = new CircBuffer<char>(n - 1, CFG_EXTENDED_MEMORY1);
+#ifdef CFG_ENABLE_RTOS
+    for (int i = 0; i < CFG_MAX_SOCKETS; i ++) {
+        _con[i].buf = new CircBuffer<char>(n - 1, CFG_EXTENDED_MEMORY1 + (n * (i + 1)));
+        if (_con[i].buf == NULL)
+            error("CircBuffer failed");
+    }
+    _threadPoll = NULL;
+#endif
+#else // CFG_EXTENDED_MEMORY
     _state.buf = new CircBuffer<char>(CFG_DATA_SIZE);
 #ifdef CFG_ENABLE_RTOS
     for (int i = 0; i < CFG_MAX_SOCKETS; i ++) {
@@ -41,6 +53,7 @@
     }
     _threadPoll = NULL;
 #endif
+#endif // CFG_EXTENDED_MEMORY
 
     setReset(true);
     initUart(cts, rts, alarm, baud);
@@ -373,9 +386,16 @@
 
     INFO("threadPoll");
     for (;;) {
+        _wifi->poll();
+#ifdef CFG_ENABLE_HTTPD
+        if (_wifi->isAssociated()) {
+            Thread::wait(1);
+        }
+#else
         Thread::signal_wait(1);
         Thread::wait(1000);
         INFO("disassociated");
+#endif
         while (!_wifi->isAssociated()){
             _wifi->poll();
             Thread::wait(CFG_RECONNECT * 1000);
--- a/GSwifi/GSwifi.h	Mon May 12 01:24:09 2014 +0000
+++ b/GSwifi/GSwifi.h	Thu Jun 05 04:21:02 2014 +0000
@@ -342,13 +342,13 @@
     /** http request (GET method)
      */
     int httpGet (const char *host, int port, const char *uri, bool ssl = false, const char *user = NULL, const char *pwd = NULL, void(*func)(int) = NULL);
-    int httpGet (const char *host, int port, const char *uri, void(*func)(int) = NULL) {
+    int httpGet (const char *host, int port, const char *uri, void(*func)(int)) {
         return httpGet(host, port, uri, false, NULL, NULL, func);
     }
     /** http request (POST method)
      */
     int httpPost (const char *host, int port, const char *uri, const char *body, bool ssl = false, const char *user = NULL, const char *pwd = NULL, void(*func)(int) = NULL);
-    int httpPost (const char *host, int port, const char *uri, const char *body, void(*func)(int) = NULL) {
+    int httpPost (const char *host, int port, const char *uri, const char *body, void(*func)(int)) {
         return httpPost(host, port, uri, body, false, NULL, NULL, func);
     }
 
--- a/GSwifi/GSwifi_conf.h	Mon May 12 01:24:09 2014 +0000
+++ b/GSwifi/GSwifi_conf.h	Thu Jun 05 04:21:02 2014 +0000
@@ -32,6 +32,13 @@
 #elif defined(TARGET_KL25Z)
 #define CFG_DATA_SIZE 512
 #endif
-
+/*
+#if defined(TARGET_LPC1768) || defined(TARGET_LPC176X)
+#define CFG_EXTENDED_MEMORY1 0x20080000
+#define CFG_EXTENDED_SIZE1 0x4000
+#define CFG_EXTENDED_MEMORY2 0x2007e000
+#define CFG_EXTENDED_SIZE2 0x2000
+#endif
+*/
 #define CFG_HTTPD_HANDLER_NUM 10
 #define CFG_HTTPD_KEEPALIVE 10
--- a/GSwifi/GSwifi_hal.cpp	Mon May 12 01:24:09 2014 +0000
+++ b/GSwifi/GSwifi_hal.cpp	Thu Jun 05 04:21:02 2014 +0000
@@ -199,7 +199,7 @@
         _flow = 2;
     }
 #elif defined(TARGET_LPC4088) || defined(TARGET_LPC408X)
-    _uart = (LPC_UART_TypeDef*)LPC_UART2;
+    _uart = (LPC_UART1_TypeDef*)LPC_UART2;
     if (cts != NC) {
         _cts = new DigitalIn(cts);
     }
--- a/GSwifi/GSwifi_httpd.cpp	Mon May 12 01:24:09 2014 +0000
+++ b/GSwifi/GSwifi_httpd.cpp	Thu Jun 05 04:21:02 2014 +0000
@@ -26,9 +26,28 @@
     if (!isAssociated() || _state.status != STAT_READY) return -1;
 
     memset(&_httpd, 0, sizeof(_httpd));
-    for (i = 0; i < 16; i ++) {
+    for (i = 0; i < CFG_MAX_SOCKETS; i ++) {
         _httpd[i].mode = HTTPDMODE_REQUEST;
+        _httpd[i].buf = _con[i].buf;
     }
+#ifdef CFG_ENABLE_RTOS
+#ifdef CFG_EXTENDED_MEMORY2
+    int n = CFG_EXTENDED_SIZE2 / CFG_MAX_SOCKETS;
+    for (i = 0; i < CFG_MAX_SOCKETS; i ++) {
+        _httpd[i].uri = (char*)(CFG_EXTENDED_MEMORY2 + (n * i));
+#ifdef CFG_ENABLE_RTOS
+        _httpd[i].websocket_key = (char*)malloc(30);
+#endif
+    }
+#else // CFG_EXTENDED_MEMORY
+    for (i = 0; i < CFG_MAX_SOCKETS; i ++) {
+        _httpd[i].uri = (char*)malloc(CFG_CMD_SIZE);
+#ifdef CFG_ENABLE_RTOS
+        _httpd[i].websocket_key = (char*)malloc(30);
+#endif
+    }
+#endif // CFG_EXTENDED_MEMORY
+#endif
     _handler_count = 0;
 
     _httpd_cid = listen(PROTO_TCP, port);
@@ -204,10 +223,10 @@
     } else {
         return -1;
     }
-
+#ifndef CFG_ENABLE_RTOS
     if (_httpd[cid].uri == NULL)
         _httpd[cid].uri = (char*)malloc(CFG_CMD_SIZE);
-
+#endif
     for (i = 0; i < len - j; i ++) {
         _httpd[cid].uri[i] = buf[i + j];
         if (buf[i + j] == ' ' || i >= CFG_CMD_SIZE - 1) {
@@ -298,9 +317,11 @@
 }
 
 void GSwifi::reqWebSocketKey (int cid, const char *buf) {
+#ifndef CFG_ENABLE_RTOS
     if (_httpd[cid].websocket_key == NULL) {
         _httpd[cid].websocket_key = (char*)malloc(30);
     }
+#endif
     strncpy(_httpd[cid].websocket_key, &buf[19], 30);
 }
 #else