Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New version.

-------------------------------------------------------------------------------
Version 1.1.0
-------------------------------------------------------------------------------
Changes:
- The WiShield library now uses a new, more stable TCP/IP stack. The library
  includes a port of the uIP stack.
- Server and client modes supported in the TCP/IP stack.
- The limitation of 446 bytes is removed. Larger sized packets can be
  transmitted and received but will have to be broken down into smaller
  sized chunks which are <= 346 bytes.
- Sample WebServer sketch modified to use the new stack to serve up simple
  webpages
- The stack provides an implementation of the socket interface which can be
  used to transmit or receive data

New features:
- Sample WebClient sketch added which demonstrates the operation of sending
  status updates to a Twitter.com account
- ARP client added to periodically send ARP packets to the AP. This was done
  to prevent certain APs from disconnecting the device due to long periods of
  inactivity

Known issues:
None
-------------------------------------------------------------------------------
  • Loading branch information...
commit 5191a3c0c6fff49082635b72c650cc4f58e7ce26 1 parent b813881
@asynclabs authored
Showing with 9,983 additions and 1,313 deletions.
  1. +21 −12 README
  2. +66 −84 WiShield.cpp
  3. +53 −58 WiShield.h
  4. +50 −0 apps-conf.h
  5. +83 −0 avrlibdefs.h
  6. +84 −0 avrlibtypes.h
  7. +86 −0 clock-arch.c
  8. +47 −0 clock-arch.h
  9. +88 −0 clock.h
  10. +5 −7 config.h
  11. +0 −173 examples/LEDControl/LEDControl.pde
  12. +74 −0 examples/WebClient/WebClient.pde
  13. +372 −0 examples/WebClient/webclient.c
  14. +6 −106 examples/WebServer/WebServer.pde
  15. +118 −0 examples/WebServer/webserver.c
  16. +45 −0 global-conf.h
  17. +34 −0 global.h
  18. +83 −0 lc-addrlabels.h
  19. +76 −0 lc-switch.h
  20. +131 −0 lc.h
  21. +104 −0 memb.c
  22. +142 −0 memb.h
  23. +71 −0 network.c
  24. +53 −0 network.h
  25. +338 −0 psock.c
  26. +380 −0 psock.h
  27. +323 −0 pt.h
  28. +1 −0  spi.h
  29. +145 −690 stack.c
  30. +0 −183 stack.h
  31. +127 −0 timer.c
  32. +86 −0 timer.h
  33. +1 −0  types.h
  34. +146 −0 uip-conf.h
  35. +532 −0 uip-fw.c
  36. +176 −0 uip-fw.h
  37. +158 −0 uip-neighbor.c
  38. +61 −0 uip-neighbor.h
  39. +136 −0 uip-split.c
  40. +96 −0 uip-split.h
  41. +1,922 −0 uip.c
  42. +1,634 −0 uip.h
  43. +138 −0 uip_arch.h
  44. +481 −0 uip_arp.c
  45. +179 −0 uip_arp.h
  46. +74 −0 uiplib.c
  47. +71 −0 uiplib.h
  48. +573 −0 uipopt.h
  49. +262 −0 webclient.h
  50. +51 −0 webserver.h
View
33 README
@@ -4,18 +4,27 @@ Async Labs Inc.
www.asynclabs.com
-------------------------------------------------------------------------------
-Version 1.0.0
+Version 1.1.0
-------------------------------------------------------------------------------
-This release includes the WiShield and TCP/IP stack files to be used with the
-Async Labs WiShield 1.0 wireless devices.
+Changes:
+- The WiShield library now uses a new, more stable TCP/IP stack. The library
+ includes a port of the uIP stack.
+- Server and client modes supported in the TCP/IP stack.
+- The limitation of 446 bytes is removed. Larger sized packets can be
+ transmitted and received but will have to be broken down into smaller
+ sized chunks which are <= 346 bytes.
+- Sample WebServer sketch modified to use the new stack to serve up simple
+ webpages
+- The stack provides an implementation of the socket interface which can be
+ used to transmit or receive data
-The release includes:
-- Driver for ZeroG G2100 series WiFi device (for download instructions, see:
- http://asynclabs.com/wiki/)
-- Simplified TCP/IP stack for use with the WiShield
-- Sample WebServer sketch demonstrating the implementation of a simple
- webserver to serve up a webpage when requested from a client browser
- application
-- Sample LEDControl sketch demonstrating the implementation of a control
- application using the webserver mode of the WiShield library.
+New features:
+- Sample WebClient sketch added which demonstrates the operation of sending
+ status updates to a Twitter.com account
+- ARP client added to periodically send ARP packets to the AP. This was done
+ to prevent certain APs from disconnecting the device due to long periods of
+ inactivity
+
+Known issues:
+None
View
150 WiShield.cpp
@@ -1,84 +1,66 @@
-
-/******************************************************************************
-
- Filename: WiShield.cpp
- Description: WiShield library file for the WiShield 1.0
-
- ******************************************************************************
-
- TCP/IP stack and driver for the WiShield 1.0 wireless devices
-
- Copyright(c) 2009 Async Labs Inc. All rights reserved.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59
- Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Contact Information:
- <asynclabs@asynclabs.com>
-
- Author Date Comment
- ---------------------------------------------------------------
- AsyncLabs 05/01/2009 Initial version
-
- *****************************************************************************/
-
-extern "C" {
- #include "types.h"
- #include "config.h"
- #include "g2100.h"
- #include "stack.h"
-}
-
-#include "WProgram.h"
-#include "WiShield.h"
-
-void WiShield::init()
-{
- zg_init(GBLBUF, 0);
- attachInterrupt(0, zg_isr, LOW);
-}
-
-void WiShield::driver_task()
-{
- zg_drv_process();
-}
-
-void WiShield::stack_task()
-{
- stack_process();
-}
-
-// FIXME : return success or failure
-void WiShield::server_listen(U16 port)
-{
- socket(SOCK_STREAM, port);
-}
-
-U8* WiShield::data_available(U16* app_len)
-{
- *app_len = stack_app_data();
-
- return APPBUF;
-}
-
-void WiShield::send_data(U16 app_len)
-{
- stack_set_app_data(app_len);
-}
-
-void WiShield::set_more_data(U8 flag)
-{
- stack_set_app_more_data(flag);
-}
-
-WiShield WiFi;
+
+/******************************************************************************
+
+ Filename: WiShield.cpp
+ Description: WiShield library file for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/01/2009 Initial version
+ AsyncLabs 05/29/2009 Adding support for new library
+
+ *****************************************************************************/
+
+extern "C" {
+ #include "types.h"
+ #include "global-conf.h"
+ #include "network.h"
+ #include "g2100.h"
+ void stack_init(void);
+ void stack_process(void);
+}
+
+#include "WProgram.h"
+#include "WiShield.h"
+
+void WiShield::init()
+{
+ zg_init();
+ attachInterrupt(0, zg_isr, LOW);
+
+ while(zg_get_conn_state() != 1) {
+ zg_drv_process();
+ }
+
+ stack_init();
+}
+
+void WiShield::run()
+{
+ stack_process();
+ zg_drv_process();
+}
+
+WiShield WiFi;
View
111 WiShield.h
@@ -1,58 +1,53 @@
-
-/******************************************************************************
-
- Filename: WiShield.h
- Description: WiShield library file for the WiShield 1.0
-
- ******************************************************************************
-
- TCP/IP stack and driver for the WiShield 1.0 wireless devices
-
- Copyright(c) 2009 Async Labs Inc. All rights reserved.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of version 2 of the GNU General Public License as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 59
- Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- Contact Information:
- <asynclabs@asynclabs.com>
-
- Author Date Comment
- ---------------------------------------------------------------
- AsyncLabs 05/01/2009 Initial version
-
- *****************************************************************************/
-
-#ifndef WISHIELD_H_
-#define WISHIELD_H_
-
-extern "C" {
- #include "config.h"
- #include "spi.h"
-}
-
-class WiShield
-{
- private:
- public:
- void init();
- void driver_task();
- void stack_task();
- void server_listen(U16 port);
- U8* data_available(U16* app_len);
- void send_data(U16 app_len);
- void set_more_data(U8 flag);
-};
-
-extern WiShield WiFi;
-
-#endif /* WISHIELD_H_ */
+
+/******************************************************************************
+
+ Filename: WiShield.h
+ Description: WiShield library file for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/01/2009 Initial version
+ AsyncLabs 05/29/2009 Adding support for new library
+
+ *****************************************************************************/
+
+#ifndef WISHIELD_H_
+#define WISHIELD_H_
+
+extern "C" {
+ #include "config.h"
+ #include "spi.h"
+ extern unsigned char webclient_get(char *host, unsigned int port, char *file);
+}
+
+class WiShield {
+ public:
+ void init();
+ void run();
+};
+
+extern WiShield WiFi;
+
+#endif /* WISHIELD_H_ */
View
50 apps-conf.h
@@ -0,0 +1,50 @@
+
+/******************************************************************************
+
+ Filename: apps-conf.h
+ Description: Web application configuration file
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial port
+
+ *****************************************************************************/
+
+#ifndef __APPS_CONF_H__
+#define __APPS_CONF_H__
+
+//Here we include the header file for the application(s) we use in our project.
+#define APP_WEBSERVER
+//#define APP_WEBCLIENT
+
+#ifdef APP_WEBSERVER
+#include "webserver.h"
+#endif
+
+#ifdef APP_WEBCLIENT
+#include "webclient.h"
+#endif
+
+#endif /*__APPS_CONF_H__*/
View
83 avrlibdefs.h
@@ -0,0 +1,83 @@
+/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */
+//*****************************************************************************
+//
+// File Name : 'avrlibdefs.h'
+// Title : AVRlib global defines and macros include file
+// Author : Pascal Stang
+// Created : 7/12/2001
+// Revised : 9/30/2002
+// Version : 1.1
+// Target MCU : Atmel AVR series
+// Editor Tabs : 4
+//
+// Description : This include file is designed to contain items useful to all
+// code files and projects, regardless of specific implementation.
+//
+// This code is distributed under the GNU Public License
+// which can be found at http://www.gnu.org/licenses/gpl.txt
+//
+//*****************************************************************************
+
+
+#ifndef AVRLIBDEFS_H
+#define AVRLIBDEFS_H
+
+// Code compatibility to new AVR-libc
+// outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli()
+#ifndef outb
+ #define outb(addr, data) addr = (data)
+#endif
+#ifndef inb
+ #define inb(addr) (addr)
+#endif
+#ifndef outw
+ #define outw(addr, data) addr = (data)
+#endif
+#ifndef inw
+ #define inw(addr) (addr)
+#endif
+#ifndef BV
+ #define BV(bit) (1<<(bit))
+#endif
+#ifndef cbi
+ #define cbi(reg,bit) reg &= ~(BV(bit))
+#endif
+#ifndef sbi
+ #define sbi(reg,bit) reg |= (BV(bit))
+#endif
+#ifndef cli
+ #define cli() __asm__ __volatile__ ("cli" ::)
+#endif
+#ifndef sei
+ #define sei() __asm__ __volatile__ ("sei" ::)
+#endif
+
+// support for individual port pin naming in the mega128
+// see port128.h for details
+#ifdef __AVR_ATmega128__
+// not currently necessary due to inclusion
+// of these defines in newest AVR-GCC
+// do a quick test to see if include is needed
+#ifndef PD0
+ #include "port128.h"
+#endif
+#endif
+
+// use this for packed structures
+// (this is seldom necessary on an 8-bit architecture like AVR,
+// but can assist in code portability to AVR)
+#define GNUC_PACKED __attribute__((packed))
+
+// port address helpers
+#define DDR(x) ((x)-1) // address of data direction register of port x
+#define PIN(x) ((x)-2) // address of input register of port x
+
+// MIN/MAX/ABS macros
+#define MIN(a,b) ((a<b)?(a):(b))
+#define MAX(a,b) ((a>b)?(a):(b))
+#define ABS(x) ((x>0)?(x):(-x))
+
+// constants
+#define PI 3.14159265359
+
+#endif
View
84 avrlibtypes.h
@@ -0,0 +1,84 @@
+/*! \file avrlibtypes.h \brief AVRlib global types and typedefines. */
+//*****************************************************************************
+//
+// File Name : 'avrlibtypes.h'
+// Title : AVRlib global types and typedefines include file
+// Author : Pascal Stang
+// Created : 7/12/2001
+// Revised : 9/30/2002
+// Version : 1.0
+// Target MCU : Atmel AVR series
+// Editor Tabs : 4
+//
+// Description : Type-defines required and used by AVRlib. Most types are also
+// generally useful.
+//
+// This code is distributed under the GNU Public License
+// which can be found at http://www.gnu.org/licenses/gpl.txt
+//
+//*****************************************************************************
+
+
+#ifndef AVRLIBTYPES_H
+#define AVRLIBTYPES_H
+
+#ifndef WIN32
+ // true/false defines
+ #define FALSE 0
+ #define TRUE -1
+#endif
+
+// datatype definitions macros
+typedef unsigned char u08;
+typedef signed char s08;
+typedef unsigned short u16;
+typedef signed short s16;
+typedef unsigned long u32;
+typedef signed long s32;
+typedef unsigned long long u64;
+typedef signed long long s64;
+
+/* use inttypes.h instead
+// C99 standard integer type definitions
+typedef unsigned char uint8_t;
+typedef signed char int8_t;
+typedef unsigned short uint16_t;
+typedef signed short int16_t;
+typedef unsigned long uint32_t;
+typedef signed long int32_t;
+typedef unsigned long uint64_t;
+typedef signed long int64_t;
+*/
+// maximum value that can be held
+// by unsigned data types (8,16,32bits)
+#define MAX_U08 255
+#define MAX_U16 65535
+#define MAX_U32 4294967295
+
+// maximum values that can be held
+// by signed data types (8,16,32bits)
+#define MIN_S08 -128
+#define MAX_S08 127
+#define MIN_S16 -32768
+#define MAX_S16 32767
+#define MIN_S32 -2147483648
+#define MAX_S32 2147483647
+
+#ifndef WIN32
+ // more type redefinitions
+ typedef unsigned char BOOL;
+ typedef unsigned char BYTE;
+ typedef unsigned int WORD;
+ typedef unsigned long DWORD;
+
+ typedef unsigned char UCHAR;
+ typedef unsigned int UINT;
+ typedef unsigned short USHORT;
+ typedef unsigned long ULONG;
+
+ typedef char CHAR;
+ typedef int INT;
+ typedef long LONG;
+#endif
+
+#endif
View
86 clock-arch.c
@@ -0,0 +1,86 @@
+
+/******************************************************************************
+
+ Filename: clock-arch.c
+ Description: Timer routine file
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial port
+
+ *****************************************************************************/
+
+#include "global-conf.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <avr/interrupt.h>
+#include <avr/io.h>
+#include <avr/sfr_defs.h>
+
+#include "clock-arch.h"
+#include "wiring.h"
+
+#if 0
+//Counted time
+clock_time_t clock_datetime = 0;
+
+//Overflow interrupt
+ISR(TIMER0_OVF_vect)
+{
+ clock_datetime += 1;
+ TIFR0 |= (1<<TOV0);
+}
+*/
+
+//Initialise the clock
+void clock_init(){
+ //Activate overflow interrupt for timer0
+ TIMSK0 |= (1<<TOIE0);
+
+ //Use prescaler 1024
+ TCCR0B |= ((1<<CS12)|(1<<CS10));
+
+ //Activate interrupts
+ sei();
+}
+
+//Return time
+clock_time_t clock_time(){
+ clock_time_t time;
+
+ cli();
+ time = clock_datetime;
+ sei();
+
+ return time;
+}
+#endif
+
+//Return time
+clock_time_t clock_time()
+{
+ return millis();
+}
View
47 clock-arch.h
@@ -0,0 +1,47 @@
+
+/******************************************************************************
+
+ Filename: clock-arch.h
+ Description: Timer routine file
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial port
+
+ *****************************************************************************/
+
+#ifndef __CLOCK_ARCH_H__
+#define __CLOCK_ARCH_H__
+
+#include <stdint.h>
+
+typedef uint32_t clock_time_t;
+#define CLOCK_CONF_SECOND (clock_time_t)1000
+ //(F_CPU / (1024*255)), this cannot be used as it gives overflows
+ //Freqency divided prescaler and counter register size
+
+#include "clock.h"
+
+#endif /* __CLOCK_ARCH_H__ */
View
88 clock.h
@@ -0,0 +1,88 @@
+/**
+ * \defgroup clock Clock interface
+ *
+ * The clock interface is the interface between the \ref timer "timer library"
+ * and the platform specific clock functionality. The clock
+ * interface must be implemented for each platform that uses the \ref
+ * timer "timer library".
+ *
+ * The clock interface does only one this: it measures time. The clock
+ * interface provides a macro, CLOCK_SECOND, which corresponds to one
+ * second of system time.
+ *
+ * \sa \ref timer "Timer library"
+ *
+ * @{
+ */
+
+/*
+ * Copyright (c) 2004, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the uIP TCP/IP stack
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: clock.h,v 1.3 2006/06/11 21:46:39 adam Exp $
+ */
+#ifndef __CLOCK_H__
+#define __CLOCK_H__
+
+#include "clock-arch.h"
+
+/**
+ * Initialize the clock library.
+ *
+ * This function initializes the clock library and should be called
+ * from the main() function of the system.
+ *
+ */
+void clock_init(void);
+
+/**
+ * Get the current clock time.
+ *
+ * This function returns the current system clock time.
+ *
+ * \return The current clock time, measured in system ticks.
+ */
+clock_time_t clock_time(void);
+
+/**
+ * A second, measured in system clock time.
+ *
+ * \hideinitializer
+ */
+#ifdef CLOCK_CONF_SECOND
+#define CLOCK_SECOND CLOCK_CONF_SECOND
+#else
+#define CLOCK_SECOND (clock_time_t)32
+#endif
+
+#endif /* __CLOCK_H__ */
+
+/** @} */
View
12 config.h
@@ -29,6 +29,7 @@
Author Date Comment
---------------------------------------------------------------
AsyncLabs 05/01/2009 Initial version
+ AsyncLabs 05/29/2009 Adding support for new library
*****************************************************************************/
@@ -37,9 +38,9 @@
#include "types.h"
-#define IP_ADDR(a,b,c,d) ((((U32)d)<<24)|(((U32)c)<<16)|(((U32)b)<<8)|(a))
-
-extern U32 local_ip;
+extern U8 local_ip[];
+extern U8 gateway_ip[];
+extern U8 subnet_mask[];
extern const prog_char ssid[];
extern U8 ssid_len;
extern const prog_char security_passphrase[];
@@ -50,10 +51,7 @@ extern U8 wireless_mode;
extern prog_uchar wep_keys[];
extern const prog_char webpage[];
-
-extern U8 buf[];
-
-#define GBLBUF ((U8*)buf)
+extern const prog_char twitter[];
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
View
173 examples/LEDControl/LEDControl.pde
@@ -1,173 +0,0 @@
-/*
- * LED Control example
- *
- * A simple LED control app using the web server example
- * for the WiShield 1.0
- */
-
-#include <WiShield.h>
-
-#define WIRELESS_MODE_INFRA 1
-#define WIRELESS_MODE_ADHOC 2
-
-// Wireless configuration parameters ----------------------------------------
-unsigned long local_ip = IP_ADDR(192,168,1,2);
-const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
-
-unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
-
-// WPA/WPA2 passphrase
-const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
-
-// WEP 128-bit keys
-// sample HEX keys
-prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
- };
-
-// setup the wireless mode
-// infrastructure - connect to AP
-// adhoc - connect to another WiFi device
-unsigned char wireless_mode = WIRELESS_MODE_INFRA;
-
-unsigned char ssid_len;
-unsigned char security_passphrase_len;
-//---------------------------------------------------------------------------
-
-
-// Webpages served by the webserver
-//
-// Due to the RAM limitation, the largest data packet that the application can
-// transmit is limited to 446 bytes. Larger webpages can be broken down into
-// smaller chunks and transmitted as shown in the code below to overcome this
-// limitation
-const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><p><h1>LED control</h1></p><p><a href=\"0\">LED 0</a><br><a href=\"1\">LED 1</a></p></center> "};
-const prog_char webpage1[] PROGMEM = {"<center><p><h1>This is line 2</h1></p></center>"};
-unsigned int webpage_len;
-
-
-
-void setup()
-{
- // Initialize the WiFi device
- // Resets the WiFi device and sets up the interrupt
- WiFi.init();
-
- // Initialize the Analog In pins 0, 1, 2, 3
- // on the Arduino Duemilanove as outputs to
- // control LEDs
- LED_Init();
-
- Serial.begin(9600);
-}
-
-#define APP_IDLE 0
-#define APP_MORE_DATA 1
-
-void loop()
-{
- char* data; // variable pointing to the data received from the client
- unsigned int data_len; //length of data received from the client
- unsigned char app_state = APP_IDLE;
-
- webpage_len = strlen_P(webpage); // length of the webpage
-
- WiFi.server_listen(80); // start server on port 80 (HTTP)
-
- while(1) {
- WiFi.driver_task(); // run WiFi driver task
- WiFi.stack_task(); // run stack task
-
- data = (char*)WiFi.data_available(&data_len);
-
- if (data_len) {
- // process data
- Serial.println(data);
-
- if (memcmp(data, "GET /", 5) == 0) {
- switch(data[5]) {
- case '0':
- // toggle LED 0
- // Analog In port 0 on the Duemilanove
- LED0_toggle();
- WiFi.send_data(webpage_len);
- break;
- case '1':
- // toggle LED 1
- // Analog In port 1 on the Duemilanove
- LED1_toggle();
- WiFi.send_data(webpage_len);
- break;
- case ' ':
- // browser requested index.html
- // just send main page
- WiFi.send_data(webpage_len);
- break;
- default:
- // unknown request, do not respond
- WiFi.send_data(0);
- break;
- }
-
- // copy data into TX buffer
- memcpy_P(data, webpage, webpage_len);
-
- // indicate this was the last chunk for TX
- WiFi.set_more_data(1);
- }
-
- // we run the stack task again here to allow the stack
- // to package the app data and set it up for TX when
- // the driver task runs the next time
- WiFi.stack_task();
- }
-
-#if 0
- // This code block implements multiple chunk TX
-
- switch (app_state) {
- case APP_IDLE:
- data = (char*)WiFi.data_available(&data_len);
-
- if (data_len) {
- // process data
- Serial.println(data);
-
- // copy data into TX buffer
- memcpy_P(data, webpage, 104);
- WiFi.send_data(104);
-
- // indicate that the webpage has more data to TX
- WiFi.set_more_data(0);
-
- app_state = APP_MORE_DATA;
-
- // we run the stack task again here to allow the stack
- // to package the app data and set it up for TX when
- // the driver task runs the next time
- WiFi.stack_task();
- }
- break;
- case APP_MORE_DATA:
- data = (char*)WiFi.data_available(&data_len);
-
- // copy more webpage data into TX buffer
- memcpy_P(data, webpage1, 47);
- WiFi.send_data(47);
-
- // indicate end of webpage data
- WiFi.set_more_data(1);
-
- app_state = APP_IDLE;
-
- // we run the stack task again here to allow the stack
- // to package the app data and set it up for TX when
- // the driver task runs the next time
- WiFi.stack_task();
- break;
- }
-#endif
- }
-}
View
74 examples/WebClient/WebClient.pde
@@ -0,0 +1,74 @@
+/*
+ * Web Client
+ *
+ * A simple web client example using the WiShield 1.0
+ */
+
+#include <WiShield.h>
+
+#define WIRELESS_MODE_INFRA 1
+#define WIRELESS_MODE_ADHOC 2
+
+// Wireless configuration parameters ----------------------------------------
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
+const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
+
+unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
+
+// WPA/WPA2 passphrase
+const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
+
+// WEP 128-bit keys
+// sample HEX keys
+prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
+ };
+
+// setup the wireless mode
+// infrastructure - connect to AP
+// adhoc - connect to another WiFi device
+unsigned char wireless_mode = WIRELESS_MODE_INFRA;
+
+unsigned char ssid_len;
+unsigned char security_passphrase_len;
+//---------------------------------------------------------------------------
+
+void setup()
+{
+ WiFi.init();
+}
+
+unsigned char loop_cnt = 0;
+
+// The stack does not have support for DNS and therefore cannot resolve
+// host names. It needs actual IP addresses of the servers. This info
+// can be obtained by executing, for example, $ ping twitter.com on
+// a terminal on your PC
+//char google_ip[] = {74,125,67,100}; // Google
+char twitter_ip[] = {128,121,146,100}; // Twitter
+
+// This string can be used to send a request to Twitter.com to update your status
+// It will need a valid Authorization string which can be derived from your
+// Twitter.com username and password using Base64 algorithm
+// See, http://en.wikipedia.org/wiki/Basic_access_authentication
+// You need to replace <-!!-Authorization String-!!-> with a valid string before
+// using this sample sketch.
+// The Content-Length variable should equal the length of the data string
+// In the example below, "Content-Length: 21" corresponds to "status=Ready to sleep"
+const prog_char twitter[] PROGMEM = {"POST /statuses/update.xml HTTP/1.1\r\nAuthorization: Basic <-!!-Authorization String-!!->\r\nUser-Agent: uIP/1.0\r\nHost: twitter.com\r\nContent-Length: 21\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nstatus=Ready to sleep"};
+
+void loop()
+{
+ // if this is the first iteration
+ // send the request
+ if (loop_cnt == 0) {
+ webclient_get(twitter_ip, 80, "/");
+ loop_cnt = 1;
+ }
+
+ WiFi.run();
+}
View
372 examples/WebClient/webclient.c
@@ -0,0 +1,372 @@
+
+/******************************************************************************
+
+ Filename: webclient.c
+ Description: Webclient app for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial version
+
+ *****************************************************************************/
+
+#include "uip.h"
+#include "uiplib.h"
+#include "webclient.h"
+#include "config.h"
+
+#include <string.h>
+
+#define WEBCLIENT_TIMEOUT 100
+
+#define WEBCLIENT_STATE_STATUSLINE 0
+#define WEBCLIENT_STATE_HEADERS 1
+#define WEBCLIENT_STATE_DATA 2
+#define WEBCLIENT_STATE_CLOSE 3
+
+#define HTTPFLAG_NONE 0
+#define HTTPFLAG_OK 1
+#define HTTPFLAG_MOVED 2
+#define HTTPFLAG_ERROR 3
+
+
+#define ISO_nl 0x0a
+#define ISO_cr 0x0d
+
+static struct webclient_state s;
+
+const char http_11[9] =
+ /* "HTTP/1.1" */
+{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0 };
+const char http_200[5] =
+ /* "200 " */
+{0x32, 0x30, 0x30, 0x20, 0 };
+const char http_301[5] =
+ /* "301 " */
+{0x33, 0x30, 0x31, 0x20, 0 };
+const char http_302[5] =
+ /* "302 " */
+{0x33, 0x30, 0x32, 0x20, 0 };
+
+/*-----------------------------------------------------------------------------------*/
+char* webclient_mimetype(void)
+{
+ return s.mimetype;
+}
+/*-----------------------------------------------------------------------------------*/
+char* webclient_filename(void)
+{
+ return s.file;
+}
+/*-----------------------------------------------------------------------------------*/
+char* webclient_hostname(void)
+{
+ return s.host;
+}
+/*-----------------------------------------------------------------------------------*/
+unsigned short webclient_port(void)
+{
+ return s.port;
+}
+/*-----------------------------------------------------------------------------------*/
+void webclient_init(void)
+{
+
+}
+/*-----------------------------------------------------------------------------------*/
+static void init_connection(void)
+{
+ s.state = WEBCLIENT_STATE_STATUSLINE;
+
+ // set the length of the client string to be transmitted
+ s.getrequestleft = strlen_P(twitter);
+
+ s.getrequestptr = 0;
+
+ s.httpheaderlineptr = 0;
+}
+/*-----------------------------------------------------------------------------------*/
+void webclient_close(void)
+{
+ s.state = WEBCLIENT_STATE_CLOSE;
+}
+/*-----------------------------------------------------------------------------------*/
+unsigned char webclient_get(char *host, u16_t port, char *file)
+{
+ struct uip_conn *conn;
+ uip_ipaddr_t ipaddr;
+
+ uip_ipaddr(&ipaddr, host[0],host[1],host[2],host[3]);
+
+ conn = uip_connect(&ipaddr, htons(port));
+
+ if(conn == NULL) {
+ return 0;
+ }
+
+ s.port = port;
+ strncpy(s.file, file, sizeof(s.file));
+ strncpy(s.host, host, sizeof(s.host));
+
+ init_connection();
+ return 1;
+}
+/*-----------------------------------------------------------------------------------*/
+static unsigned char* copy_string(unsigned char *dest, const unsigned char *src, unsigned char len)
+{
+ strncpy(dest, src, len);
+ return dest + len;
+}
+/*-----------------------------------------------------------------------------------*/
+static void senddata(void)
+{
+ u16_t len;
+ char *getrequest;
+ char *cptr;
+
+ if(s.getrequestleft > 0) {
+ cptr = getrequest = (char *)uip_appdata;
+
+#if 0
+ cptr = copy_string(cptr, http_get, sizeof(http_get) - 1);
+ cptr = copy_string(cptr, s.file, strlen(s.file));
+ *cptr++ = ISO_space;
+ cptr = copy_string(cptr, http_10, sizeof(http_10) - 1);
+
+ cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1);
+
+ cptr = copy_string(cptr, http_host, sizeof(http_host) - 1);
+ cptr = copy_string(cptr, s.host, strlen(s.host));
+ cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1);
+
+ cptr = copy_string(cptr, http_user_agent_fields,
+ strlen(http_user_agent_fields));
+#endif
+
+ // copy the client transmit string into the TX buffer
+ memcpy_P(cptr, twitter, strlen_P(twitter));
+
+ len = s.getrequestleft > uip_mss()?uip_mss():s.getrequestleft;
+ uip_send(&(getrequest[s.getrequestptr]), len);
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+static void acked(void)
+{
+ u16_t len;
+
+ if(s.getrequestleft > 0) {
+ len = s.getrequestleft > uip_mss()?uip_mss():s.getrequestleft;
+ s.getrequestleft -= len;
+ s.getrequestptr += len;
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+static u16_t parse_statusline(u16_t len)
+{
+ char *cptr;
+ char* temp;
+
+ while(len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline)) {
+ s.httpheaderline[s.httpheaderlineptr] = *(char *)uip_appdata;
+ //((char *)uip_appdata)++;
+ temp = (char *)uip_appdata;
+ temp++;
+ uip_appdata = temp;
+ --len;
+ if(s.httpheaderline[s.httpheaderlineptr] == ISO_nl) {
+
+ if((strncmp(s.httpheaderline, http_11,sizeof(http_11) - 1) == 0)) {
+ cptr = &(s.httpheaderline[9]);
+ s.httpflag = HTTPFLAG_NONE;
+ if(strncmp(cptr, http_200, sizeof(http_200) - 1) == 0) {
+ /* 200 OK */
+ s.httpflag = HTTPFLAG_OK;
+ }
+ else if(strncmp(cptr, http_301, sizeof(http_301) - 1) == 0 ||
+ strncmp(cptr, http_302, sizeof(http_302) - 1) == 0) {
+ /* 301 Moved permanently or 302 Found. Location: header line
+ * will contain the new location. */
+ s.httpflag = HTTPFLAG_MOVED;
+ }
+ else {
+ s.httpheaderline[s.httpheaderlineptr - 1] = 0;
+ }
+ }
+ else {
+ uip_abort();
+ webclient_aborted();
+ return 0;
+ }
+
+ /* We're done parsing the status line, so we reset the pointer
+ * and start parsing the HTTP headers.*/
+ s.httpheaderlineptr = 0;
+ s.state = WEBCLIENT_STATE_HEADERS;
+ break;
+ }
+ else {
+ ++s.httpheaderlineptr;
+ }
+ }
+ return len;
+}
+/*-----------------------------------------------------------------------------------*/
+static u16_t parse_headers(u16_t len)
+{
+ char *cptr;
+ static unsigned char i;
+ char* temp;
+
+ while(len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline)) {
+ s.httpheaderline[s.httpheaderlineptr] = *(char *)uip_appdata;
+ //++((char *)uip_appdata);
+ temp = (char *)uip_appdata;
+ temp++;
+ uip_appdata = temp;
+ --len;
+ if(s.httpheaderline[s.httpheaderlineptr] == ISO_nl) {
+ /* We have an entire HTTP header line in s.httpheaderline, so
+ * we parse it. */
+ if(s.httpheaderline[0] == ISO_cr) {
+ /* This was the last header line (i.e., and empty "\r\n"), so
+ * we are done with the headers and proceed with the actual
+ * data. */
+ s.state = WEBCLIENT_STATE_DATA;
+ return len;
+ }
+
+ /* We're done parsing, so we reset the pointer and start the
+ * next line. */
+ s.httpheaderlineptr = 0;
+ }
+ else {
+ ++s.httpheaderlineptr;
+ }
+ }
+
+ return len;
+}
+/*-----------------------------------------------------------------------------------*/
+static void newdata(void)
+{
+ u16_t len;
+
+ len = uip_datalen();
+
+ if(s.state == WEBCLIENT_STATE_STATUSLINE) {
+ len = parse_statusline(len);
+ }
+
+ if(s.state == WEBCLIENT_STATE_HEADERS && len > 0) {
+ len = parse_headers(len);
+ }
+
+ if(len > 0 && s.state == WEBCLIENT_STATE_DATA &&
+ s.httpflag != HTTPFLAG_MOVED) {
+ webclient_datahandler((char *)uip_appdata, len);
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+void webclient_appcall(void)
+{
+ if(uip_connected()) {
+ s.timer = 0;
+ s.state = WEBCLIENT_STATE_STATUSLINE;
+ senddata();
+ webclient_connected();
+ return;
+ }
+
+ if(s.state == WEBCLIENT_STATE_CLOSE) {
+ webclient_closed();
+ uip_abort();
+ return;
+ }
+
+ if(uip_aborted()) {
+ webclient_aborted();
+ }
+
+ if(uip_timedout()) {
+ webclient_timedout();
+ }
+
+ if(uip_acked()) {
+ s.timer = 0;
+ acked();
+ }
+
+ if(uip_newdata()) {
+ s.timer = 0;
+ newdata();
+ }
+
+ if(uip_rexmit() || uip_newdata() || uip_acked()) {
+ senddata();
+ }
+ else if(uip_poll()) {
+ ++s.timer;
+ if(s.timer == WEBCLIENT_TIMEOUT) {
+ webclient_timedout();
+ uip_abort();
+ return;
+ }
+ }
+
+ if(uip_closed()) {
+ if(s.httpflag != HTTPFLAG_MOVED) {
+ /* Send NULL data to signal EOF. */
+ webclient_datahandler(NULL, 0);
+ }
+ else {
+ //webclient_get(s.host, s.port, s.file);
+ }
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+
+void webclient_datahandler(char *data, u16_t len)
+{
+}
+
+void webclient_connected(void)
+{
+}
+
+void webclient_timedout(void)
+{
+}
+
+void webclient_aborted(void)
+{
+}
+
+void webclient_closed(void)
+{
+}
+
+/** @} */
+/** @} */
View
112 examples/WebServer/WebServer.pde
@@ -10,7 +10,9 @@
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
-unsigned long local_ip = IP_ADDR(192,168,1,2);
+unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
+unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
+unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
@@ -35,117 +37,15 @@ unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
-
-// Webpages served by the webserver
-//
-// Due to the RAM limitation, the largest data packet that the application can
-// transmit is limited to 446 bytes. Larger webpages can be broken down into
-// smaller chunks and transmitted as shown in the code below to overcome this
-// limitation
-const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><p><h1>Hello World!! I am WiShield</h1></p></center>"};
-const prog_char webpage1[] PROGMEM = {"<center><p><h1>This is line 2</h1></p></center>"};
-unsigned int webpage_len;
-
-
-
void setup()
{
- // Initialize the WiFi device
- // Resets the WiFi device and sets up the interrupt
WiFi.init();
-
- Serial.begin(9600);
}
-#define APP_IDLE 0
-#define APP_MORE_DATA 1
+// This is the webpage that is served up by the webserver
+const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><h1>Hello World!! I am WiShield</h1><form method=\"get\" action=\"0\">Toggle LED:<input type=\"submit\" name=\"0\" value=\"LED1\"></input></form></center>"};
void loop()
{
- char* data; // variable pointing to the data received from the client
- unsigned int data_len; //length of data received from the client
- unsigned char app_state = APP_IDLE;
-
- webpage_len = strlen_P(webpage); // length of the webpage
-
- WiFi.server_listen(80); // start server on port 80 (HTTP)
-
- while(1) {
- WiFi.driver_task(); // run WiFi driver task
- WiFi.stack_task(); // run stack task
-
- data = (char*)WiFi.data_available(&data_len);
-
- if (data_len) {
- // process data
- Serial.println(data);
-
- if (memcmp(data, "GET / ", 6) == 0) {
- // copy data into TX buffer
-
- memcpy_P(data, webpage, webpage_len);
- WiFi.send_data(webpage_len);
-
- // indicate this was the last chunk for TX
- WiFi.set_more_data(1);
- }
- else {
- WiFi.send_data(0);
-
- WiFi.set_more_data(1);
- }
-
- // we run the stack task again here to allow the stack
- // to package the app data and set it up for TX when
- // the driver task runs the next time
- WiFi.stack_task();
- }
-
-
-#if 0
- // This code block implements multiple chunk TX
-
- switch (app_state) {
- case APP_IDLE:
- data = (char*)WiFi.data_available(&data_len);
-
- if (data_len) {
- // process data
- Serial.println(data);
-
- // copy data into TX buffer
- memcpy_P(data, webpage, 104);
- WiFi.send_data(104);
-
- // indicate that the webpage has more data to TX
- WiFi.set_more_data(0);
-
- app_state = APP_MORE_DATA;
-
- // we run the stack task again here to allow the stack
- // to package the app data and set it up for TX when
- // the driver task runs the next time
- WiFi.stack_task();
- }
- break;
- case APP_MORE_DATA:
- data = (char*)WiFi.data_available(&data_len);
-
- // copy more webpage data into TX buffer
- memcpy_P(data, webpage1, 47);
- WiFi.send_data(47);
-
- // indicate end of webpage data
- WiFi.set_more_data(1);
-
- app_state = APP_IDLE;
-
- // we run the stack task again here to allow the stack
- // to package the app data and set it up for TX when
- // the driver task runs the next time
- WiFi.stack_task();
- break;
- }
-#endif
- }
+ WiFi.run();
}
View
118 examples/WebServer/webserver.c
@@ -0,0 +1,118 @@
+
+/******************************************************************************
+
+ Filename: webserver.h
+ Description: Webserver app for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial version
+
+ *****************************************************************************/
+
+#include "uip.h"
+#include <string.h>
+#include "webserver.h"
+#include "config.h"
+
+static int handle_connection(struct webserver_state *s);
+
+void webserver_init(void)
+{
+ uip_listen(HTONS(80));
+}
+
+void webserver_appcall(void)
+{
+ struct webserver_state *s = &(uip_conn->appstate);
+
+ if(uip_connected()) {
+ PSOCK_INIT(&s->p, s->inputbuf, sizeof(s->inputbuf));
+ }
+
+ handle_connection(s);
+}
+
+#define ISO_nl 0x0a
+#define ISO_space 0x20
+#define ISO_slash 0x2f
+
+const char http_get[5] = {0x47, 0x45, 0x54, 0x20, }; /* "GET " */
+
+unsigned short fill_buf(void* blk)
+{
+ unsigned short webpage_len;
+
+ webpage_len = (strlen_P(webpage)>uip_mss())?uip_mss():strlen_P(webpage);
+
+ memcpy_P(uip_appdata, webpage, webpage_len);
+ return webpage_len;
+}
+
+static int handle_connection(struct webserver_state *s)
+{
+ PSOCK_BEGIN(&s->p);
+
+ // the incoming GET request will have the following format:
+ // GET / HTTP/1.1 ....
+ // we have to parse this string to determine the resource being requested
+ // if the requested resource is not the root webpage ('/') then,
+ // GET /<resource name> HTTP/1.1 ....
+ // we should parse the specific resource and react appropriately
+
+ // read incoming data until we read a space character
+ PSOCK_READTO(&s->p, ISO_space);
+
+ // parse the data to determine if it was a GET request
+ if(strncmp(s->inputbuf, http_get, 4) != 0) {
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ // continue reading until the next space character
+ PSOCK_READTO(&s->p, ISO_space);
+
+ // determine the requested resource
+ // in this case, we check if the request was for the '/' root page
+ // AKA index.html
+ if(s->inputbuf[0] != ISO_slash) {
+ // request for unknown webpage, close and exit
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ if(s->inputbuf[1] != ISO_space) {
+ // request for unavailable resource
+ // not supported, modify to add support for additional resources
+ PSOCK_CLOSE_EXIT(&s->p);
+ }
+
+ //PSOCK_SEND_STR(&s->p, "HTTP/1.1 200 OK\r\n");
+ //PSOCK_SEND_STR(&s->p, "Content-Type: text/html\r\n");
+ //PSOCK_SEND_STR(&s->p, "\r\n");
+ //PSOCK_SEND_STR(&s->p, "Hello World, I am WiShield");
+ //PSOCK_SEND_STR(&s->p, "<center><h1>Hello World!! I am WiShield</h1></center>");
+ PSOCK_GENERATOR_SEND(&s->p, fill_buf, 0);
+ PSOCK_CLOSE(&s->p);
+ PSOCK_END(&s->p);
+}
View
45 global-conf.h
@@ -0,0 +1,45 @@
+
+/******************************************************************************
+
+ Filename: global-conf.h
+ Description: Stack configuration for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial version
+
+ *****************************************************************************/
+
+//Project specific configurations
+#ifndef __GLOBAL_CONF_H__
+#define __GLOBAL_CONF_H__
+
+//Define frequency
+//#define F_CPU 12500000UL
+
+//Include uip.h gives all the uip configurations in uip-conf.h
+#include "uip.h"
+
+#endif /*__GLOBAL_CONF_H__*/
View
34 global.h
@@ -0,0 +1,34 @@
+/*! \file global.h \brief AVRlib project global include. */
+//*****************************************************************************
+//
+// File Name : 'global.h'
+// Title : AVRlib project global include
+// Author : Pascal Stang - Copyright (C) 2001-2002
+// Created : 7/12/2001
+// Revised : 9/30/2002
+// Version : 1.1
+// Target MCU : Atmel AVR series
+// Editor Tabs : 4
+//
+// Description : This include file is designed to contain items useful to all
+// code files and projects.
+//
+// This code is distributed under the GNU Public License
+// which can be found at http://www.gnu.org/licenses/gpl.txt
+//
+//*****************************************************************************
+
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+#include "uip.h"
+
+// global AVRLIB defines
+#include "avrlibdefs.h"
+// global AVRLIB types definitions
+#include "avrlibtypes.h"
+
+// project/system dependent defines
+#define CYCLES_PER_US ((F_CPU+500000)/1000000) // cpu cycles per microsecond
+
+#endif
View
83 lc-addrlabels.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the uIP TCP/IP stack
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: lc-addrlabels.h,v 1.3 2006/06/12 08:00:30 adam Exp $
+ */
+
+/**
+ * \addtogroup lc
+ * @{
+ */
+
+/**
+ * \file
+ * Implementation of local continuations based on the "Labels as
+ * values" feature of gcc
+ * \author
+ * Adam Dunkels <adam@sics.se>
+ *
+ * This implementation of local continuations is based on a special
+ * feature of the GCC C compiler called "labels as values". This
+ * feature allows assigning pointers with the address of the code
+ * corresponding to a particular C label.
+ *
+ * For more information, see the GCC documentation:
+ * http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+ *
+ * Thanks to dividuum for finding the nice local scope label
+ * implementation.
+ */
+
+#ifndef __LC_ADDRLABELS_H__
+#define __LC_ADDRLABELS_H__
+
+/** \hideinitializer */
+typedef void * lc_t;
+
+#define LC_INIT(s) s = NULL
+
+
+#define LC_RESUME(s) \
+ do { \
+ if(s != NULL) { \
+ goto *s; \
+ } \
+ } while(0)
+
+#define LC_SET(s) \
+ do { ({ __label__ resume; resume: (s) = &&resume; }); }while(0)
+
+#define LC_END(s)
+
+#endif /* __LC_ADDRLABELS_H__ */
+
+/** @} */
View
76 lc-switch.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the uIP TCP/IP stack
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: lc-switch.h,v 1.2 2006/06/12 08:00:30 adam Exp $
+ */
+
+/**
+ * \addtogroup lc
+ * @{
+ */
+
+/**
+ * \file
+ * Implementation of local continuations based on switch() statment
+ * \author Adam Dunkels <adam@sics.se>
+ *
+ * This implementation of local continuations uses the C switch()
+ * statement to resume execution of a function somewhere inside the
+ * function's body. The implementation is based on the fact that
+ * switch() statements are able to jump directly into the bodies of
+ * control structures such as if() or while() statmenets.
+ *
+ * This implementation borrows heavily from Simon Tatham's coroutines
+ * implementation in C:
+ * http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
+ */
+
+#ifndef __LC_SWITCH_H__
+#define __LC_SWTICH_H__
+
+/* WARNING! lc implementation using switch() does not work if an
+ LC_SET() is done within another switch() statement! */
+
+/** \hideinitializer */
+typedef unsigned short lc_t;
+
+#define LC_INIT(s) s = 0;
+
+#define LC_RESUME(s) switch(s) { case 0:
+
+#define LC_SET(s) s = __LINE__; case __LINE__:
+
+#define LC_END(s) }
+
+#endif /* __LC_SWITCH_H__ */
+
+/** @} */
View
131 lc.h
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2004-2005, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the uIP TCP/IP stack
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: lc.h,v 1.2 2006/06/12 08:00:30 adam Exp $
+ */
+
+/**
+ * \addtogroup pt
+ * @{
+ */
+
+/**
+ * \defgroup lc Local continuations
+ * @{
+ *
+ * Local continuations form the basis for implementing protothreads. A
+ * local continuation can be <i>set</i> in a specific function to
+ * capture the state of the function. After a local continuation has
+ * been set can be <i>resumed</i> in order to restore the state of the
+ * function at the point where the local continuation was set.
+ *
+ *
+ */
+
+/**
+ * \file lc.h
+ * Local continuations
+ * \author
+ * Adam Dunkels <adam@sics.se>
+ *
+ */
+
+#ifdef DOXYGEN
+/**
+ * Initialize a local continuation.
+ *
+ * This operation initializes the local continuation, thereby
+ * unsetting any previously set continuation state.
+ *
+ * \hideinitializer
+ */
+#define LC_INIT(lc)
+
+/**
+ * Set a local continuation.
+ *
+ * The set operation saves the state of the function at the point
+ * where the operation is executed. As far as the set operation is
+ * concerned, the state of the function does <b>not</b> include the
+ * call-stack or local (automatic) variables, but only the program
+ * counter and such CPU registers that needs to be saved.
+ *
+ * \hideinitializer
+ */
+#define LC_SET(lc)
+
+/**
+ * Resume a local continuation.
+ *
+ * The resume operation resumes a previously set local continuation, thus
+ * restoring the state in which the function was when the local
+ * continuation was set. If the local continuation has not been
+ * previously set, the resume operation does nothing.
+ *
+ * \hideinitializer
+ */
+#define LC_RESUME(lc)
+
+/**
+ * Mark the end of local continuation usage.
+ *
+ * The end operation signifies that local continuations should not be
+ * used any more in the function. This operation is not needed for
+ * most implementations of local continuation, but is required by a
+ * few implementations.
+ *
+ * \hideinitializer
+ */
+#define LC_END(lc)
+
+/**
+ * \var typedef lc_t;
+ *
+ * The local continuation type.
+ *
+ * \hideinitializer
+ */
+#endif /* DOXYGEN */
+
+#ifndef __LC_H__
+#define __LC_H__
+
+#ifdef LC_CONF_INCLUDE
+#include LC_CONF_INCLUDE
+#else
+#include "lc-switch.h"
+#endif /* LC_CONF_INCLUDE */
+
+#endif /* __LC_H__ */
+
+/** @} */
+/** @} */
View
104 memb.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2004, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the uIP TCP/IP stack
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: memb.c,v 1.1 2006/06/12 08:21:43 adam Exp $
+ */
+
+/**
+ * \addtogroup memb
+ * @{
+ */
+
+ /**
+ * \file
+ * Memory block allocation routines.
+ * \author Adam Dunkels <adam@sics.se>
+ */
+#include <string.h>
+
+#include "memb.h"
+
+/*---------------------------------------------------------------------------*/
+void
+memb_init(struct memb_blocks *m)
+{
+ memset(m->count, 0, m->num);
+ memset(m->mem, 0, m->size * m->num);
+}
+/*---------------------------------------------------------------------------*/
+void *
+memb_alloc(struct memb_blocks *m)
+{
+ int i;
+
+ for(i = 0; i < m->num; ++i) {
+ if(m->count[i] == 0) {
+ /* If this block was unused, we increase the reference count to
+ indicate that it now is used and return a pointer to the
+ memory block. */
+ ++(m->count[i]);
+ return (void *)((char *)m->mem + (i * m->size));
+ }
+ }
+
+ /* No free block was found, so we return NULL to indicate failure to
+ allocate block. */
+ return NULL;
+}
+/*---------------------------------------------------------------------------*/
+char
+memb_free(struct memb_blocks *m, void *ptr)
+{
+ int i;
+ char *ptr2;
+
+ /* Walk through the list of blocks and try to find the block to
+ which the pointer "ptr" points to. */
+ ptr2 = (char *)m->mem;
+ for(i = 0; i < m->num; ++i) {
+
+ if(ptr2 == (char *)ptr) {
+ /* We've found to block to which "ptr" points so we decrease the
+ reference count and return the new value of it. */
+ if(m->count[i] > 0) {
+ /* Make sure that we don't deallocate free memory. */
+ --(m->count[i]);
+ }
+ return m->count[i];
+ }
+ ptr2 += m->size;
+ }
+ return -1;
+}
+/*---------------------------------------------------------------------------*/
+
+/** @} */
View
142 memb.h
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2004, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the uIP TCP/IP stack
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ * $Id: memb.h,v 1.1 2006/06/12 08:21:43 adam Exp $
+ */
+
+/**
+ * \defgroup memb Memory block management functions
+ *
+ * The memory block allocation routines provide a simple yet powerful
+ * set of functions for managing a set of memory blocks of fixed
+ * size. A set of memory blocks is statically declared with the
+ * MEMB() macro. Memory blocks are allocated from the declared
+ * memory by the memb_alloc() function, and are deallocated with the
+ * memb_free() function.
+ *
+ * \note Because of namespace clashes only one MEMB() can be
+ * declared per C module, and the name scope of a MEMB() memory
+ * block is local to each C module.
+ *
+ * The following example shows how to declare and use a memory block
+ * called "cmem" which has 8 chunks of memory with each memory chunk
+ * being 20 bytes large.
+ *
+ * @{
+ */
+
+
+/**
+ * \file
+ * Memory block allocation routines.
+ * \author
+ * Adam Dunkels <adam@sics.se>
+ *
+ */
+
+#ifndef __MEMB_H__
+#define __MEMB_H__
+
+/*
+ * Here we define a C preprocessing macro for concatenating to
+ * strings. We need use two macros in order to allow concatenation of
+ * two #defined macros.
+ */
+#define MEMB_CONCAT2(s1, s2) s1##s2
+#define MEMB_CONCAT(s1, s2) MEMB_CONCAT2(s1, s2)
+
+/**
+ * Declare a memory block.
+ *
+ * This macro is used to staticall declare a block of memory that can
+ * be used by the block allocation functions. The macro statically
+ * declares a C array with a size that matches the specified number of
+ * blocks and their individual sizes.
+ *
+ * Example:
+ \code
+MEMB(connections, sizeof(struct connection), 16);
+ \endcode
+ *
+ * \param name The name of the memory block (later used with
+ * memb_init(), memb_alloc() and memb_free()).
+ *
+ * \param size The size of each memory chunk, in bytes.
+ *
+ * \param num The total number of memory chunks in the block.
+ *
+ */
+#define MEMB(name, structure, num) \
+ static char MEMB_CONCAT(name,_memb_count)[num]; \
+ static structure MEMB_CONCAT(name,_memb_mem)[num]; \
+ static struct memb_blocks name = {sizeof(structure), num, \
+ MEMB_CONCAT(name,_memb_count), \
+ (void *)MEMB_CONCAT(name,_memb_mem)}
+
+struct memb_blocks {
+ unsigned short size;
+ unsigned short num;
+ char *count;
+ void *mem;
+};
+
+/**
+ * Initialize a memory block that was declared with MEMB().
+ *
+ * \param m A memory block previosly declared with MEMB().
+ */
+void memb_init(struct memb_blocks *m);
+
+/**
+ * Allocate a memory block from a block of memory declared with MEMB().
+ *
+ * \param m A memory block previosly declared with MEMB().
+ */
+void *memb_alloc(struct memb_blocks *m);
+
+/**
+ * Deallocate a memory block from a memory block previously declared
+ * with MEMB().
+ *
+ * \param m m A memory block previosly declared with MEMB().
+ *
+ * \param ptr A pointer to the memory block that is to be deallocated.
+ *
+ * \return The new reference count for the memory block (should be 0
+ * if successfully deallocated) or -1 if the pointer "ptr" did not
+ * point to a legal memory block.
+ */
+char memb_free(struct memb_blocks *m, void *ptr);
+
+/** @} */
+
+#endif /* __MEMB_H__ */
View
71 network.c
@@ -0,0 +1,71 @@
+
+/******************************************************************************
+
+ Filename: network.c
+ Description: Network interface for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial version
+
+ *****************************************************************************/
+
+#include "global-conf.h"
+#include <avr/io.h>
+#include <util/delay.h>
+#include <string.h>
+#include "types.h"
+#include "g2100.h"
+
+void network_init(void)
+{
+}
+
+unsigned int network_read(void)
+{
+ return zg_get_rx_status();
+}
+
+void network_send(void)
+{
+ if (uip_len > 0) {
+ if(uip_len <= UIP_LLH_LEN + 40){
+ zg_set_buf(uip_buf, uip_len);
+ }
+ else{
+ memcpy((u8*)&uip_buf[54], (u8*)uip_appdata, (uip_len-54));
+ zg_set_buf(uip_buf, uip_len);
+ }
+ zg_set_tx_status(1);
+ }
+}
+
+void network_get_MAC(u8* macaddr)
+{
+}
+
+void network_set_MAC(u8* macaddr)
+{
+}
View
53 network.h
@@ -0,0 +1,53 @@
+
+/******************************************************************************
+
+ Filename: network.h
+ Description: Network interface for the WiShield 1.0
+
+ ******************************************************************************
+
+ TCP/IP stack and driver for the WiShield 1.0 wireless devices
+
+ Copyright(c) 2009 Async Labs Inc. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59
+ Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Contact Information:
+ <asynclabs@asynclabs.com>
+
+ Author Date Comment
+ ---------------------------------------------------------------
+ AsyncLabs 05/29/2009 Initial version
+
+ *****************************************************************************/
+
+#ifndef __NETWORK_H__
+#define __NETWORK_H__
+
+/*Initialize the network*/
+void network_init(void);
+
+/*Read from the network, returns number of read bytes*/
+unsigned int network_read(void);
+
+/*Send using the network*/
+void network_send(void);
+
+/*Sets the MAC address of the device*/
+void network_set_MAC(uint8_t* mac);
+
+/*Gets the MAC address of the device*/
+void network_get_MAC(uint8_t* mac);
+
+#endif /* __NETWORK_H__ */
View
338 psock.c
@@ -0,0 +1,338 @@
+/*
+ * Copyright (c) 2004, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS