Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/LICENSE
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/LICENSE	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/LICENSE	(revision 175)
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Arduino.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/README.md
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/README.md	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/README.md	(revision 175)
@@ -0,0 +1,20 @@
+##Arduino Ciao (MCU side)
+Simple library in C to make MCU communicate with "outside World" through Ciao Core.
+
+###What is Arduino Ciao?
+
+**Arduino Ciao** is a easy-to-use and powerful technology that enables Arduino sketches to communicate intuitively with the "outside World". It aims to simplify interaction between microcontroller and Linino OS allowing a variety of connections with most common protocols, third-party services and social networks.
+
+Arduino Ciao is open-source and distributed under MIT license: feel free to read it, suggest improvements, provide feedbacks and develop new features.
+
+More information about Arduino Ciao project can be found at http://labs.arduino.org/Ciao
+
+###Arduino Ciao (MCU side) - Ciao Library
+
+Arduino Ciao is made of two main parts:
+ * the **Ciao Library** - usable inside *sketches*, it's written in C.
+ * the [Ciao Core](http://labs.arduino.org/Ciao+CPU) - a library developed in python that runs on the CPU/MIPS side of the board.(source code available [here](https://github.com/arduino-org/Ciao+CPU))
+
+**Ciao Library**  allows you to send and receive data outside the microcontroller, through a serial communication, in a simple and intuitive way.
+
+Details about **Ciao Library** architecture are available in the [Arduino wiki](http://labs.arduino.org/Ciao+MCU)
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoArduinoXMPP/CiaoArduinoXMPP.ino	(revision 175)
@@ -0,0 +1,43 @@
+/*
+  Arduino Ciao example
+  
+ This sketch uses ciao xmpp connector. It sends back âhello worldâ message to the xmpp client when receives âciaoâ from it. 
+  
+ Be sure to set the xmpp client in the "USER" field used to receive the response by MCU.
+
+ Possible commands to send from the xmpp client:
+ * "ciao"               -> random answers in 5 different languages
+ 
+ created September 2015
+ by andrea[at]arduino[dot]org
+ 
+ 
+  NOTE: be sure to activate and configure xmpp connector on Linino OS
+       http://labs.arduino.org/Ciao
+   
+ */
+ 
+#include <Ciao.h>
+
+String USER="user@domain";
+String mess[5]={"Hi, I am MCU :-P","hallo , ik ben MCU :-P","bonjour, je suis MCU :-P","Ciao, io sono MCU :-P","Kon'nichiwa, watashi wa MCU yo :-P" };
+
+void setup() {
+  Ciao.begin(); 
+}
+
+void loop() {
+    
+  CiaoData data = Ciao.read("xmpp");  
+  
+  if(!data.isEmpty()){
+    String id = data.get(0);
+    String sender = data.get(1);
+    String message = data.get(2);
+    
+    message.toLowerCase();
+    if(message == "ciao" )
+      Ciao.write("xmpp", USER,mess[random(0,5)]);
+  }
+}
+
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino	(revision 175)
@@ -0,0 +1,46 @@
+/*
+  Arduino Ciao example
+  
+ This sketch uses Ciao mqtt connector. Sketch sends via MQTT brightness and temperature information that will be shown graphically in the blueMix IBM system.
+ Upload your sketch an than connect to the webpage:  
+ https://quickstart.internetofthings.ibmcloud.com/#/device/BlueMixTest902345/sensor/
+ 
+  NOTE: be sure to activate and configure mqtt connector on Linino OS.
+       http://labs.arduino.org/Ciao
+
+ created September 2015
+ by andrea[at]arduino[dot]org
+   
+ */
+
+#include <Ciao.h>
+
+int ctrl=0;
+void setup()
+{
+  Ciao.begin();  //Start the serial connection with the computer
+                       //to view the result open the serial monitor 
+  pinMode(9,OUTPUT);
+}
+ 
+void loop()                     // run over and over again
+{
+   //getting the voltage reading from the temperature sensor
+   int readingTemp = analogRead(A0);   
+   // converting readingTemp to voltage
+   float voltage = readingTemp * 4.56;
+   voltage /= 1024; 
+   // now print out the temperature
+   float temperatureC = (voltage - 0.5) * 100 ; 
+   int readingLum = analogRead(A2);
+
+   analogWrite(9,map(readingLum,0,1023,0,255)); 
+   
+   if (ctrl>=10){
+     Ciao.write("mqtt","iot-2/evt/status/fmt/json","{\"d\": {\"temperature\":"+String(temperatureC)+",\"luminosity\":"+String(readingLum)+"}}");
+     ctrl=0;
+   }
+   ctrl++;
+   delay(100);
+ 
+}
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-TalkBackRecv/CiaoRestClient-TalkBackRecv.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-TalkBackRecv/CiaoRestClient-TalkBackRecv.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-TalkBackRecv/CiaoRestClient-TalkBackRecv.ino	(revision 175)
@@ -0,0 +1,53 @@
+#include <Wire.h>
+#include <Ciao.h>
+
+/* 
+
+This example show the interaction between the Ciao Library and the Thingspeak Cloud. 
+To run the example you need to register an account on thingspeak.com.
+After that, you need to create a new channel and a new talkback app.
+To create a new channel click the "Channels" section in the website (Channels -> My Channels -> New Channel).
+To create a new talkback click the "Apps" section in the website (Apps -> TalkBack -> New TalkBack). 
+Replace the APIKEY_TALKBACK and ID_TALKBACK values with the values reported in the API section of the site. 
+
+*/
+
+#define CONNECTOR     "rest" 
+#define SERVER_ADDR   "api.thingspeak.com"
+
+#define APIKEY_TALKBACK    "XXXXXXXXXXXXX"
+#define ID_TALKBACK      "XXXX"
+
+
+void setup() {
+
+  Ciao.begin(); // CIAO INIT
+
+}
+
+void loop() {
+  
+
+      String request = "/talkbacks/";  
+          request +=  ID_TALKBACK;
+          request +=  "/commands/execute?api_key=";
+          request +=  APIKEY_TALKBACK;
+    
+      Ciao.println("Read cmd from TalkBack Queue"); 
+      CiaoData data = Ciao.read(CONNECTOR, SERVER_ADDR, request);
+ 
+      String state = data.get(1);
+      String response = data.get(2);
+      
+      if (!data.isEmpty()){
+          Ciao.println( "State: " + String (data.get(1)) );
+          Ciao.println( "Response: " + String (data.get(2)) );
+        }
+        else{ 
+          Ciao.println ("Read Error OR EmptyQueue");
+        }
+ 
+  delay(30000); // Thinkspeak policy
+
+}  
+    
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-TalkBackSend/CiaoRestClient-TalkBackSend.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-TalkBackSend/CiaoRestClient-TalkBackSend.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-TalkBackSend/CiaoRestClient-TalkBackSend.ino	(revision 175)
@@ -0,0 +1,51 @@
+#include <Wire.h>
+#include <Ciao.h>
+
+/* 
+
+This example show the interaction between the Ciao Library and the Thingspeak Cloud. 
+To run the example you need to register an account on thingspeak.com.
+After that, you need to create a new channel and a new talkback app.
+To create a new channel click the "Channels" section in the website (Channels -> My Channels -> New Channel).
+To create a new talkback click the "Apps" section in the website (Apps -> TalkBack -> New TalkBack). 
+Replace the APIKEY_TALKBACK and ID_TALKBACK values with the values reported in the API section of the site. 
+
+*/
+
+#define CONNECTOR     "rest" 
+#define SERVER_ADDR   "api.thingspeak.com"
+
+#define APIKEY_TALKBACK     "XXXXXXXXXXXXXX"
+#define ID_TALKBACK         "XXXX"
+
+String cmd = "D13_ON";
+
+void setup() {
+
+  Ciao.begin(); // CIAO INIT
+}
+
+void loop() {
+      
+      String uri = "/talkbacks/";
+    	uri += ID_TALKBACK;
+    	uri += "/commands?api_key=";
+    	uri += APIKEY_TALKBACK;
+    	uri += "&command_string=";
+    	uri += cmd;
+
+      Ciao.println("Write cmd on TalkBack Queue"); 
+      CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, uri,"POST");
+  
+      if (!data.isEmpty()){
+          Ciao.println( "State: " + String (data.get(1)) );
+          Ciao.println( "Response: " + String (data.get(2)) );
+        }
+        else{ 
+          Ciao.println ("Write Error");
+        }
+ 
+  delay(30000); // Thinkspeak policy
+
+}  
+    
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-ThingSpeak/CiaoRestClient-ThingSpeak.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-ThingSpeak/CiaoRestClient-ThingSpeak.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient-ThingSpeak/CiaoRestClient-ThingSpeak.ino	(revision 175)
@@ -0,0 +1,50 @@
+#include <Wire.h>
+#include <Ciao.h>
+
+/* 
+
+This example show the interaction between the Ciao Library and the Thingspeak Cloud. 
+To run the example you need to register an account on thingspeak.com and create a 
+new channel by clicking "Channels" section in the website (Channels -> My Channels -> New Channel). 
+In the new channel you need to add two fields. The first one refers to the humidity data and the second one to the temperature value.
+After that, replace the "XXXXXXXXX" value of APIKEY_THINGSPEAK with "Write API key" value reported in the API Keys section of the channel. 
+
+*/
+
+#define CONNECTOR     "rest" 
+#define SERVER_ADDR   "api.thingspeak.com"
+
+#define APIKEY_THINGSPEAK  "XXXXXXXXXXXXX"
+
+short hum = 60;
+short temp = 22;
+
+void setup() {
+
+  Ciao.begin(); // CIAO INIT
+}
+
+void loop() {
+      
+    String uri = "/update?api_key=";
+    uri += APIKEY_THINGSPEAK;
+    uri += "&field1=";
+    uri += String(hum);
+    uri += "&field2=";
+    uri += String(temp);
+
+    Ciao.println("Send data on ThingSpeak Channel"); 
+      
+    CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, uri);
+
+    if (!data.isEmpty()){
+      Ciao.println( "State: " + String (data.get(1)) );
+      Ciao.println( "Response: " + String (data.get(2)) );
+    }
+    else{ 
+      Ciao.println("Write Error");
+    }    
+ 
+  delay(30000); // Thinkspeak policy
+
+}  
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino	(revision 175)
@@ -0,0 +1,51 @@
+#include <Wire.h>
+#include <Ciao.h>
+
+#define CONNECTOR     "rest" 
+#define SERVER_ADDR   "192.168.0.100" // change ip address with your server ip address
+
+int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed
+int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
+long lastDebounceTime = 0;  // the last time the output pin was toggled
+long debounceDelay = 50;    // the debounce time; increase if the output flickers
+
+void setup() {
+  Ciao.begin();
+  pinMode(2, INPUT);
+  
+}
+ 
+void loop() {
+ 
+  //sample the state of the button - is it pressed or not?
+  buttonState = digitalRead(2);
+ 
+  //filter out any noise by setting a time buffer
+  if ( (millis() - lastDebounceTime) > debounceDelay) {
+ 
+    //if the button has been pressed, lets toggle the LED from "off to on" or "on to off"
+    if ( (buttonState == HIGH) && (ledState < 0) ) {
+ 
+      CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/digital/12/1"); //turn LED on
+      ledState = -ledState; //now the LED is on, we need to change the state
+      lastDebounceTime = millis(); //set the current time
+    }
+    else if ( (buttonState == HIGH) && (ledState > 0) ) {
+ 
+      CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/digital/12/0"); //turn LED off
+      ledState = -ledState; //now the LED is off, we need to change the state
+      lastDebounceTime = millis(); //set the current time
+        
+      if (!data.isEmpty()){
+        Ciao.println( "State: " + String (data.get(1)) );
+        Ciao.println( "Response: " + String (data.get(2)) );
+      }
+      else{ 
+        Ciao.println ("Write Error");
+      }
+              
+    }
+ 
+  }
+ 
+}
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestServer/CiaoRestServer.ino
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestServer/CiaoRestServer.ino	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestServer/CiaoRestServer.ino	(revision 175)
@@ -0,0 +1,142 @@
+/*
+
+ This sketch uses the xmpp connector to receive command for the MCU from a xmpp client.
+
+ Possible commands to send from the xmpp client:
+
+ * "digital/PIN"        -> to read a digital PIN
+ * "digital/PIN/VALUE"  -> to write a digital PIN (VALUE: 1/0)
+ * "analog/PIN/VALUE"   -> to write in a PWM PIN(VALUE range: 0 - 255);
+ * "analog/PIN"         -> to read a analog PIN
+ * "servo/PIN/VALUE"	  -> to write angle in a SERVO PIN(VALUE range: 0 - 180);
+ * "mode/PIN/VALUE"     -> to set the PIN mode (VALUE: input / output)
+ * "ledon"              -> turn on led 13
+ * "ledoff"             -> turn off led 13
+ * "ciao"               -> random answers in 5 different languages
+ 
+ NOTE: be sure to activate and configure xmpp connector on Linino OS
+       http://labs.arduino.org/Ciao
+   
+ created September 2015
+ by andrea[at]arduino[dot]org
+ 
+ */
+ 
+#include <Ciao.h>
+#include <Servo.h>
+
+Servo servo;
+
+void setup() {
+
+  Ciao.begin();
+}
+
+void loop() {
+
+  CiaoData data = Ciao.read("restserver");   
+  if(!data.isEmpty()){  
+    String id = data.get(0);
+    String sender = data.get(1);
+    String message = data.get(2);
+    
+    message.toUpperCase();
+    
+    String command[3];
+          
+    splitString(message,"/",command,3);
+    execute(command,id);
+
+  }
+}
+
+void execute(String cmd[], String id) {
+
+  if (cmd[0] == "DIGITAL") {
+    digitalCommand(cmd,id);
+  }
+  else if (cmd[0] == "ANALOG") {
+    analogCommand(cmd,id);
+  }
+  else if (cmd[0] == "SERVO") {
+    servoCommand(cmd,id);
+  }
+  else if (cmd[0] == "MODE") {
+    setMode(cmd,id);
+  }
+  else
+    Ciao.writeResponse("restserver",id,"sorry, i don't understand :(");
+}
+
+void servoCommand(String cmd[], String id){
+   int pin, value;
+  
+  pin = (cmd[1]).toInt();
+  
+  if (cmd[2] != "-1") {
+    value = (cmd[2]).toInt();
+    if(value <= 180 && value >=0){
+      servo.attach(pin);
+      servo.write(value);
+      Ciao.writeResponse("restserver",id,"Servo D"+String(pin)+" set to "+String(value)+" degrees");
+    }
+    else
+      Ciao.writeResponse("restserver",id,"Invalid angle value");
+  }
+  else
+    Ciao.writeResponse("restserver",id,"Invalid command");  
+}
+
+void digitalCommand(String cmd[], String id) {
+  int pin, value;
+  
+  pin = (cmd[1]).toInt();
+  
+  if (cmd[2] != "-1") {
+    value = (cmd[2]).toInt();
+    digitalWrite(pin, value);
+    if (value == 1)
+      Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" ON");
+    else if(value == 0)
+      Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" OFF");   
+  }
+  else if (cmd[2] == "-1") {
+    value = digitalRead(pin);
+    Ciao.writeResponse("restserver",id,"D"+String(pin)+" value = "+String(value));
+  }
+}
+
+void analogCommand(String cmd[], String id) {
+  int pin, value;
+
+  pin = (cmd[1]).toInt();
+  
+  if (cmd[2] != "-1") {
+    value =(cmd[2]).toInt();
+    analogWrite(pin, value);
+    Ciao.writeResponse("restserver",id,"D"+String(pin)+" set to analog");
+  }
+  else if (cmd[2] == "-1") {
+    value = analogRead(pin);
+    Ciao.writeResponse("restserver",id,"A"+String(pin)+" value = "+String(value));
+  }
+}
+
+void setMode(String cmd[], String id) {
+  int pin;
+
+  pin = (cmd[1]).toInt();
+  
+  if (cmd[2] == "INPUT") {
+    pinMode(pin, INPUT);
+    Ciao.writeResponse("restserver",id," pin D"+String(pin)+" set in INPUT mode");
+    return;
+  }
+
+  if (cmd[2] == "OUTPUT") {
+    pinMode(pin, OUTPUT);
+    Ciao.writeResponse("restserver",id," pin D"+String(pin)+" set in OUTPUT mode");
+    return;
+  }
+  Ciao.writeResponse("restserver",id,"invalid mode");
+}
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/keywords.txt
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/keywords.txt	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/keywords.txt	(revision 175)
@@ -0,0 +1,24 @@
+#######################################
+# Syntax Coloring Map For Ciao
+#######################################
+
+#######################################
+# Class (KEYWORD3)
+#######################################
+
+Ciao		KEYWORD3
+CiaoData	KEYWORD3
+Wifi		KEYWORD3
+WifiData	KEYWORD3
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+begin			KEYWORD2
+writeResponse	KEYWORD2
+available		KEYWORD2
+read			KEYWORD2
+write			KEYWORD2
+bool			KEYWORD2
+
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/library.properties
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/library.properties	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/library.properties	(revision 175)
@@ -0,0 +1,9 @@
+name=Ciao
+version=1.0
+author=Arduino srl
+maintainer=Arduino srl<info@arduino.org>
+sentence=Enables the communication between the Linux processor and the AVR. For Arduino Y炭n, Y炭n Mini, Linino One, Arduino Tian and Arduino Industrial.
+paragraph=
+category=Communication
+url=http://labs.arduino.org/Ciao
+architectures=*
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/Ciao.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/Ciao.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/Ciao.h	(revision 175)
@@ -0,0 +1,136 @@
+/*
+****************************************************************************
+* Copyright (c) 2015 Arduino srl. All right reserved.
+*
+* File : Ciao.h
+* Date : 2016/02/16
+* Revision : 0.0.2 $
+* Author: andrea[at]arduino[dot]org
+* Author: adriano[at]arduino[dot]org
+*
+****************************************************************************
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef CIAO_H_
+#define CIAO_H_
+
+#include <Arduino.h>
+#include "lib/CiaoData.h"
+#if defined(__AVR_ATmega328P__)
+#include "lib/rest.h"
+#include "lib/SC16IS750.h"
+#include "lib/espduino.h"
+#else
+#include <Stream.h>
+#endif
+
+#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)
+
+#if defined(__AVR_ATmega32U4__)
+#define BAUDRATE 250000
+#elif defined(ARDUINO_ARCH_SAMD)
+#define BAUDRATE 115200
+#endif
+
+class CiaoClass {
+	public:
+		void begin();
+		CiaoData read( String protocol, String param1 = "", String param2 = "", String param3 = "");
+		CiaoData write( String protocol, String param1, String param2 = "", String param3 = "");
+		CiaoData writeResponse( String protocol, String id, String param1="", String param2 = "", String param3 = "");
+		CiaoData parse( String, String);
+		void println(String log){};
+		#if defined(__AVR_ATmega32U4__) 
+		CiaoClass(Stream &_stream);
+		#elif defined(ARDUINO_ARCH_SAMD)
+		CiaoClass(Serial_ stream);
+		#endif
+
+	private:
+		void dropAll();
+		bool started;
+		#if defined(__AVR_ATmega32U4__)
+		Stream &stream;
+		#elif defined(ARDUINO_ARCH_SAMD)
+		Serial_ stream;
+		#endif
+};
+
+// This subclass uses a serial port Stream
+class SerialCiaoClass : public CiaoClass {
+	public:
+		#if defined(__AVR_ATmega32U4__)
+		SerialCiaoClass(HardwareSerial &_serial)
+			: CiaoClass(_serial), serial(_serial) {
+			// Empty
+		}
+		#elif defined(ARDUINO_ARCH_SAMD)
+		SerialCiaoClass(Serial_ serial)
+			: CiaoClass(serial){
+			// Empty	
+		}
+		#endif
+		void begin( unsigned long baudrate = BAUDRATE) {
+			serial.begin(baudrate);
+			CiaoClass::begin();
+		}
+	private:
+		#if defined(__AVR_ATmega32U4__)
+		HardwareSerial &serial;
+		#elif defined(ARDUINO_ARCH_SAMD)
+		Serial_ serial;
+		#endif
+};
+
+void splitString(String, String, String[], int size);
+
+extern SerialCiaoClass Ciao;
+
+#else
+
+// class CiaoData {
+// 	public:
+		
+// 		char* get(int index){
+// 			return msg_split[index];
+// 		}
+  
+// 	public:
+// 		char* msg_split[3];
+		
+// };
+
+class CiaoClass {
+	public:
+		void begin();
+
+		CiaoData read( char*, char*, String );            // ârestâ, âhostnameâ, âStringoneâ,		
+		CiaoData read( char*, char*, String, char*);      // ârestâ, âhostnameâ, âStringoneâ, âmethodâ
+
+		CiaoData write( char*, char*, String );            // ârestâ, âhostnameâ, âStringoneâ,		
+		CiaoData write( char*, char*, String, char*);      // ârestâ, âhostnameâ, âStringoneâ, âmethodâ
+		
+		void print(String str);
+		void println(String str);
+	
+};
+extern CiaoClass Ciao;
+
+#endif
+
+
+#endif /* CIAO_H_ */
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Ciao.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Ciao.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Ciao.cpp	(revision 175)
@@ -0,0 +1,190 @@
+/*
+****************************************************************************
+* Copyright (c) 2015 Arduino srl. All right reserved.
+*
+* File : Ciao.cpp
+* Date : 2016/02/16
+* Revision : 0.0.2 $
+* Author: andrea[at]arduino[dot]org
+*
+****************************************************************************
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "Ciao.h"
+
+#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)
+
+#if defined(__AVR_ATmega32U4__)
+CiaoClass::CiaoClass(Stream &_stream) :
+	stream(_stream), started(false) {
+  // Empty
+}
+#elif defined(ARDUINO_ARCH_SAMD)
+CiaoClass::CiaoClass(Serial_ stream){
+  // Empty
+}
+#endif
+
+void CiaoClass::begin() {
+	
+	String start;
+	String stop;
+
+  	// Wait for U-boot to finish startup
+	do {
+		dropAll();
+		delay(1000);
+	}while (stream.available() > 0);
+
+	stream.println("ciao;r;status");					//check the bridge python status	
+	String status = stream.readStringUntil(END_TX_CHAR);
+	if(status == "1;running"){						
+	 	do{												//kill a istance of the bridge.py
+	 		stream.println("ciao;w;quit");
+	 		stop = stream.readStringUntil(END_TX_CHAR);
+	 		delay(3000);
+	 	}while(stop != "1;done");
+    }
+	do{ 
+		#if defined(__AVR_ATmega32U4__)
+		stream.print(F("run-ciao\n"));				//start bridge python
+		stream.readStringUntil(END_TX_CHAR);
+		#endif
+		delay(3000);
+		stream.println("ciao;r;status");				//check if bridge python is running
+		start = stream.readStringUntil(END_TX_CHAR);
+	}while (start != "1;running");
+}
+
+CiaoData CiaoClass::read( String connector, String param1, String param2 , String param3 ) {
+	
+	CiaoData data;
+	stream.print(connector + ";r");					// send read request 
+	if (param1 != ""){
+		stream.print(";"+param1);
+	}
+	if (param2 != ""){
+		stream.print(DATA_SPLIT_CHAR);
+		stream.print(param2);
+	}
+	if (param3 != ""){
+		stream.print(DATA_SPLIT_CHAR);
+		stream.print(param3);
+	}
+	stream.println();
+	String message = stream.readStringUntil(END_TX_CHAR);
+	data = parse(message, ";");
+	return data;
+}
+
+CiaoData CiaoClass::write( String connector, String param1, String param2 , String param3 ) {
+
+	CiaoData data;
+	if (param1 != ""){
+		stream.print(connector+";w;");
+		stream.print(param1);
+	}
+	if (param2 != ""){
+		stream.print(DATA_SPLIT_CHAR);
+		stream.print(param2);
+	}
+	if (param3 != ""){
+		stream.print(DATA_SPLIT_CHAR);
+		stream.print(param3);
+	}
+	stream.println();
+	String mess_receive = stream.readStringUntil(END_TX_CHAR);
+	data = parse(mess_receive, ";");
+	return data;
+	
+}
+
+CiaoData CiaoClass::writeResponse( String connector, String id, String param1, String param2 , String param3) {
+
+	CiaoData data;
+	if(id.length()> ID_SIZE_TX){
+		if (param1 != ""){
+			stream.print(connector+";wr;");
+			stream.print(id+";");
+			stream.print(param1);
+		}
+		if (param2 != ""){
+			stream.print(DATA_SPLIT_CHAR);
+			stream.print(param2);
+		}
+		if (param3 != ""){
+			stream.print(DATA_SPLIT_CHAR);
+			stream.print(param3);
+		}
+		stream.println();
+		String mess_receive = stream.readStringUntil(END_TX_CHAR);
+		data = parse(mess_receive, ";");
+	}
+	return data;
+}
+
+CiaoData CiaoClass::parse(String message, String split){
+	String status;
+	CiaoData data;
+	int statusIndex = message.indexOf(split);
+	int messIndex = message.indexOf(split, statusIndex+1);
+	status = message.substring(0, statusIndex);				//message status (0: no message; 1:data ready; -1:error)
+
+	if(status == ID_READY && message.substring(statusIndex+1, messIndex) != "done"){
+		data.msg_split[0]=message.substring(statusIndex+1, messIndex);
+		data.parseMessage(message.substring(messIndex+1));	//parsing data received
+	}
+	else{
+		data.msg_split[0] = status;
+		data.msg_split[2] = message.substring(statusIndex+1, messIndex);
+	}
+	return data;
+}
+
+void CiaoClass::dropAll() {
+  while (stream.available() > 0) {
+    stream.read();
+  }
+}
+
+//fuction to split command (ex: digital/13/1)
+void splitString(String command, String split, String msg[], int size){		
+	  
+	for(int a=0;a< size ;a++)		//initialize array element to -1
+		msg[a]= ID_ERROR;
+	char buf[command.length()+1];
+	command.toCharArray(buf, command.length()+1);
+	char* array;
+	const char splt[1]= {split.charAt(0)};
+	int i=0;
+	array = strtok (buf,splt);
+	while (array != NULL){  
+		msg[i]=String(array);
+		array = strtok (NULL, splt);
+		i++; 
+	}
+}
+
+// Ciao instance
+#ifdef __AVR_ATmega32U4__ 
+// Yun variants (where HardwareSerial is Serial1)
+SerialCiaoClass Ciao(Serial1);
+#elif defined ARDUINO_ARCH_SAMD
+// Tian variants (where Serial_ is SerialUSB)
+SerialCiaoClass Ciao(SerialUSB);
+#endif
+
+#endif
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/CiaoData.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/CiaoData.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/CiaoData.h	(revision 175)
@@ -0,0 +1,89 @@
+/*
+****************************************************************************
+* Copyright (c) 2015 Arduino srl. All right reserved.
+*
+* File : CiaoData.h
+* Date : 2016/02/16
+* Revision : 0.0.2 $
+* Author: andrea[at]arduino[dot]org
+*
+****************************************************************************
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include <Arduino.h>
+
+#define ID_ERROR		String(-1)
+#define ID_EMPTY		String(0)
+#define ID_READY		String(1)
+#define END_TX_CHAR		(char)4
+#define DATA_SPLIT_CHAR	(char)30
+#define ID_SIZE_TX		25
+
+#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)
+class CiaoData {
+	public:
+		
+		String get(int index){
+			return msg_split[index];
+		}
+		
+		void parseMessage(String command){
+			int statusIndex = command.indexOf(DATA_SPLIT_CHAR);
+			msg_split[1] = command.substring(0, statusIndex);
+			msg_split[2] = command.substring(statusIndex+1);
+		}
+  
+		bool isError(){		//check for an error in data received
+			if(get(0) == ID_ERROR)
+				return true;
+			else
+				return false;			
+		}
+		
+		bool isEmpty(){		//check if data received is empty
+			if(get(0) == ID_EMPTY)
+				return true;
+			else
+				return false;	
+		}
+		
+	public:
+		String msg_split[3];
+};
+
+#elif defined(__AVR_ATmega328P__)
+
+class CiaoData {
+	public:
+
+		char* get(int index){
+			return msg_split[index];
+		}
+
+		bool isEmpty(){	
+			if (atoi( get(1) ) > 0)
+				return false;
+			else
+				return true;	
+		}
+		
+	public:
+		char* msg_split[3];
+};
+
+#endif
+
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/FP.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/FP.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/FP.cpp	(revision 175)
@@ -0,0 +1,600 @@
+/**
+ * @file    FP.cpp
+ * @brief   Core Utility - Templated Function Pointer Class
+ * @author  sam grove
+ * @version 1.0
+ * @see     
+ *
+ * Copyright (c) 2013
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "FP.h"
+#include <stdint.h>
+
+template<class retT, class argT>
+FP<retT, argT>::FP()
+{
+    obj_callback = 0;
+    c_callback = 0;
+}
+
+template<class retT, class argT>
+bool FP<retT, argT>::attached()
+{
+    return obj_callback || c_callback;
+}
+
+
+template<class retT, class argT>
+void FP<retT, argT>::detach()
+{
+    obj_callback = 0;
+    c_callback = 0;
+}
+
+
+template<class retT, class argT>
+void FP<retT, argT>::attach(retT (*function)(argT))
+{
+    c_callback = function;
+}
+
+template<class retT, class argT>
+retT FP<retT, argT>::operator()(argT arg) const
+{
+    if( 0 != c_callback )
+    {
+        return obj_callback ? (obj_callback->*method_callback)(arg) : (*c_callback)(arg);
+    }
+    return (retT)0;
+}
+
+// pre-define the types for the linker
+template class FP<void,char>;
+template class FP<void,char*>;
+template class FP<void,int8_t>;
+template class FP<void,int8_t*>;
+template class FP<void,uint8_t>;
+template class FP<void,uint8_t*>;
+template class FP<void,int16_t>;
+template class FP<void,int16_t*>;
+template class FP<void,uint16_t>;
+template class FP<void,uint16_t*>;
+template class FP<void,int32_t>;
+template class FP<void,int32_t*>;
+template class FP<void,uint32_t>;
+template class FP<void,uint32_t*>;
+template class FP<void,int64_t>;
+template class FP<void,int64_t*>;
+template class FP<void,uint64_t>;
+template class FP<void,uint64_t*>;
+template class FP<void,bool>;
+template class FP<void,bool*>;
+template class FP<void,float>;
+template class FP<void,float*>;
+template class FP<void,double>;
+template class FP<void,double*>;
+template class FP<void,void*>;
+
+template class FP<int8_t,char>;
+template class FP<int8_t,char*>;
+template class FP<int8_t,int8_t>;
+template class FP<int8_t,int8_t*>;
+template class FP<int8_t,uint8_t>;
+template class FP<int8_t,uint8_t*>;
+template class FP<int8_t,int16_t>;
+template class FP<int8_t,int16_t*>;
+template class FP<int8_t,uint16_t>;
+template class FP<int8_t,uint16_t*>;
+template class FP<int8_t,int32_t>;
+template class FP<int8_t,int32_t*>;
+template class FP<int8_t,uint32_t>;
+template class FP<int8_t,uint32_t*>;
+template class FP<int8_t,int64_t>;
+template class FP<int8_t,int64_t*>;
+template class FP<int8_t,uint64_t>;
+template class FP<int8_t,uint64_t*>;
+template class FP<int8_t,bool>;
+template class FP<int8_t,bool*>;
+template class FP<int8_t,float>;
+template class FP<int8_t,float*>;
+template class FP<int8_t,double>;
+template class FP<int8_t,double*>;
+
+template class FP<int8_t*,char>;
+template class FP<int8_t*,char*>;
+template class FP<int8_t*,int8_t>;
+template class FP<int8_t*,int8_t*>;
+template class FP<int8_t*,uint8_t>;
+template class FP<int8_t*,uint8_t*>;
+template class FP<int8_t*,int16_t>;
+template class FP<int8_t*,int16_t*>;
+template class FP<int8_t*,uint16_t>;
+template class FP<int8_t*,uint16_t*>;
+template class FP<int8_t*,int32_t>;
+template class FP<int8_t*,int32_t*>;
+template class FP<int8_t*,uint32_t>;
+template class FP<int8_t*,uint32_t*>;
+template class FP<int8_t*,int64_t>;
+template class FP<int8_t*,int64_t*>;
+template class FP<int8_t*,uint64_t>;
+template class FP<int8_t*,uint64_t*>;
+template class FP<int8_t*,bool>;
+template class FP<int8_t*,bool*>;
+template class FP<int8_t*,float>;
+template class FP<int8_t*,float*>;
+template class FP<int8_t*,double>;
+template class FP<int8_t*,double*>;
+
+template class FP<uint8_t,char>;
+template class FP<uint8_t,char*>;
+template class FP<uint8_t,int8_t>;
+template class FP<uint8_t,int8_t*>;
+template class FP<uint8_t,uint8_t>;
+template class FP<uint8_t,uint8_t*>;
+template class FP<uint8_t,int16_t>;
+template class FP<uint8_t,int16_t*>;
+template class FP<uint8_t,uint16_t>;
+template class FP<uint8_t,uint16_t*>;
+template class FP<uint8_t,int32_t>;
+template class FP<uint8_t,int32_t*>;
+template class FP<uint8_t,uint32_t>;
+template class FP<uint8_t,uint32_t*>;
+template class FP<uint8_t,int64_t>;
+template class FP<uint8_t,int64_t*>;
+template class FP<uint8_t,uint64_t>;
+template class FP<uint8_t,uint64_t*>;
+template class FP<uint8_t,bool>;
+template class FP<uint8_t,bool*>;
+template class FP<uint8_t,float>;
+template class FP<uint8_t,float*>;
+template class FP<uint8_t,double>;
+template class FP<uint8_t,double*>;
+
+template class FP<uint8_t*,char>;
+template class FP<uint8_t*,char*>;
+template class FP<uint8_t*,int8_t>;
+template class FP<uint8_t*,int8_t*>;
+template class FP<uint8_t*,uint8_t>;
+template class FP<uint8_t*,uint8_t*>;
+template class FP<uint8_t*,int16_t>;
+template class FP<uint8_t*,int16_t*>;
+template class FP<uint8_t*,uint16_t>;
+template class FP<uint8_t*,uint16_t*>;
+template class FP<uint8_t*,int32_t>;
+template class FP<uint8_t*,int32_t*>;
+template class FP<uint8_t*,uint32_t>;
+template class FP<uint8_t*,uint32_t*>;
+template class FP<uint8_t*,int64_t>;
+template class FP<uint8_t*,int64_t*>;
+template class FP<uint8_t*,uint64_t>;
+template class FP<uint8_t*,uint64_t*>;
+template class FP<uint8_t*,bool>;
+template class FP<uint8_t*,bool*>;
+template class FP<uint8_t*,float>;
+template class FP<uint8_t*,float*>;
+template class FP<uint8_t*,double>;
+template class FP<uint8_t*,double*>;
+
+template class FP<int16_t,char>;
+template class FP<int16_t,char*>;
+template class FP<int16_t,int8_t>;
+template class FP<int16_t,int8_t*>;
+template class FP<int16_t,uint8_t>;
+template class FP<int16_t,uint8_t*>;
+template class FP<int16_t,int16_t>;
+template class FP<int16_t,int16_t*>;
+template class FP<int16_t,uint16_t>;
+template class FP<int16_t,uint16_t*>;
+template class FP<int16_t,int32_t>;
+template class FP<int16_t,int32_t*>;
+template class FP<int16_t,uint32_t>;
+template class FP<int16_t,uint32_t*>;
+template class FP<int16_t,int64_t>;
+template class FP<int16_t,int64_t*>;
+template class FP<int16_t,uint64_t>;
+template class FP<int16_t,uint64_t*>;
+template class FP<int16_t,bool>;
+template class FP<int16_t,bool*>;
+template class FP<int16_t,float>;
+template class FP<int16_t,float*>;
+template class FP<int16_t,double>;
+template class FP<int16_t,double*>;
+
+template class FP<int16_t*,char>;
+template class FP<int16_t*,char*>;
+template class FP<int16_t*,int8_t>;
+template class FP<int16_t*,int8_t*>;
+template class FP<int16_t*,uint8_t>;
+template class FP<int16_t*,uint8_t*>;
+template class FP<int16_t*,int16_t>;
+template class FP<int16_t*,int16_t*>;
+template class FP<int16_t*,uint16_t>;
+template class FP<int16_t*,uint16_t*>;
+template class FP<int16_t*,int32_t>;
+template class FP<int16_t*,int32_t*>;
+template class FP<int16_t*,uint32_t>;
+template class FP<int16_t*,uint32_t*>;
+template class FP<int16_t*,int64_t>;
+template class FP<int16_t*,int64_t*>;
+template class FP<int16_t*,uint64_t>;
+template class FP<int16_t*,uint64_t*>;
+template class FP<int16_t*,bool>;
+template class FP<int16_t*,bool*>;
+template class FP<int16_t*,float>;
+template class FP<int16_t*,float*>;
+template class FP<int16_t*,double>;
+template class FP<int16_t*,double*>;
+
+template class FP<uint16_t,char>;
+template class FP<uint16_t,char*>;
+template class FP<uint16_t,int8_t>;
+template class FP<uint16_t,int8_t*>;
+template class FP<uint16_t,uint8_t>;
+template class FP<uint16_t,uint8_t*>;
+template class FP<uint16_t,int16_t>;
+template class FP<uint16_t,int16_t*>;
+template class FP<uint16_t,uint16_t>;
+template class FP<uint16_t,uint16_t*>;
+template class FP<uint16_t,int32_t>;
+template class FP<uint16_t,int32_t*>;
+template class FP<uint16_t,uint32_t>;
+template class FP<uint16_t,uint32_t*>;
+template class FP<uint16_t,int64_t>;
+template class FP<uint16_t,int64_t*>;
+template class FP<uint16_t,uint64_t>;
+template class FP<uint16_t,uint64_t*>;
+template class FP<uint16_t,bool>;
+template class FP<uint16_t,bool*>;
+template class FP<uint16_t,float>;
+template class FP<uint16_t,float*>;
+template class FP<uint16_t,double>;
+template class FP<uint16_t,double*>;
+
+template class FP<uint16_t*,char>;
+template class FP<uint16_t*,char*>;
+template class FP<uint16_t*,int8_t>;
+template class FP<uint16_t*,int8_t*>;
+template class FP<uint16_t*,uint8_t>;
+template class FP<uint16_t*,uint8_t*>;
+template class FP<uint16_t*,int16_t>;
+template class FP<uint16_t*,int16_t*>;
+template class FP<uint16_t*,uint16_t>;
+template class FP<uint16_t*,uint16_t*>;
+template class FP<uint16_t*,int32_t>;
+template class FP<uint16_t*,int32_t*>;
+template class FP<uint16_t*,uint32_t>;
+template class FP<uint16_t*,uint32_t*>;
+template class FP<uint16_t*,int64_t>;
+template class FP<uint16_t*,int64_t*>;
+template class FP<uint16_t*,uint64_t>;
+template class FP<uint16_t*,uint64_t*>;
+template class FP<uint16_t*,bool>;
+template class FP<uint16_t*,bool*>;
+template class FP<uint16_t*,float>;
+template class FP<uint16_t*,float*>;
+template class FP<uint16_t*,double>;
+template class FP<uint16_t*,double*>;
+
+template class FP<int32_t,char>;
+template class FP<int32_t,char*>;
+template class FP<int32_t,int8_t>;
+template class FP<int32_t,int8_t*>;
+template class FP<int32_t,uint8_t>;
+template class FP<int32_t,uint8_t*>;
+template class FP<int32_t,int16_t>;
+template class FP<int32_t,int16_t*>;
+template class FP<int32_t,uint16_t>;
+template class FP<int32_t,uint16_t*>;
+template class FP<int32_t,int32_t>;
+template class FP<int32_t,int32_t*>;
+template class FP<int32_t,uint32_t>;
+template class FP<int32_t,uint32_t*>;
+template class FP<int32_t,int64_t>;
+template class FP<int32_t,int64_t*>;
+template class FP<int32_t,uint64_t>;
+template class FP<int32_t,uint64_t*>;
+template class FP<int32_t,bool>;
+template class FP<int32_t,bool*>;
+template class FP<int32_t,float>;
+template class FP<int32_t,float*>;
+template class FP<int32_t,double>;
+template class FP<int32_t,double*>;
+
+template class FP<int32_t*,char>;
+template class FP<int32_t*,char*>;
+template class FP<int32_t*,int8_t>;
+template class FP<int32_t*,int8_t*>;
+template class FP<int32_t*,uint8_t>;
+template class FP<int32_t*,uint8_t*>;
+template class FP<int32_t*,int16_t>;
+template class FP<int32_t*,int16_t*>;
+template class FP<int32_t*,uint16_t>;
+template class FP<int32_t*,uint16_t*>;
+template class FP<int32_t*,int32_t>;
+template class FP<int32_t*,int32_t*>;
+template class FP<int32_t*,uint32_t>;
+template class FP<int32_t*,uint32_t*>;
+template class FP<int32_t*,int64_t>;
+template class FP<int32_t*,int64_t*>;
+template class FP<int32_t*,uint64_t>;
+template class FP<int32_t*,uint64_t*>;
+template class FP<int32_t*,bool>;
+template class FP<int32_t*,bool*>;
+template class FP<int32_t*,float>;
+template class FP<int32_t*,float*>;
+template class FP<int32_t*,double>;
+template class FP<int32_t*,double*>;
+
+template class FP<uint32_t,char>;
+template class FP<uint32_t,char*>;
+template class FP<uint32_t,int8_t>;
+template class FP<uint32_t,int8_t*>;
+template class FP<uint32_t,uint8_t>;
+template class FP<uint32_t,uint8_t*>;
+template class FP<uint32_t,int16_t>;
+template class FP<uint32_t,int16_t*>;
+template class FP<uint32_t,uint16_t>;
+template class FP<uint32_t,uint16_t*>;
+template class FP<uint32_t,int32_t>;
+template class FP<uint32_t,int32_t*>;
+template class FP<uint32_t,uint32_t>;
+template class FP<uint32_t,uint32_t*>;
+template class FP<uint32_t,int64_t>;
+template class FP<uint32_t,int64_t*>;
+template class FP<uint32_t,uint64_t>;
+template class FP<uint32_t,uint64_t*>;
+template class FP<uint32_t,bool>;
+template class FP<uint32_t,bool*>;
+template class FP<uint32_t,float>;
+template class FP<uint32_t,float*>;
+template class FP<uint32_t,double>;
+template class FP<uint32_t,double*>;
+
+template class FP<uint32_t*,char>;
+template class FP<uint32_t*,char*>;
+template class FP<uint32_t*,int8_t>;
+template class FP<uint32_t*,int8_t*>;
+template class FP<uint32_t*,uint8_t>;
+template class FP<uint32_t*,uint8_t*>;
+template class FP<uint32_t*,int16_t>;
+template class FP<uint32_t*,int16_t*>;
+template class FP<uint32_t*,uint16_t>;
+template class FP<uint32_t*,uint16_t*>;
+template class FP<uint32_t*,int32_t>;
+template class FP<uint32_t*,int32_t*>;
+template class FP<uint32_t*,uint32_t>;
+template class FP<uint32_t*,uint32_t*>;
+template class FP<uint32_t*,int64_t>;
+template class FP<uint32_t*,int64_t*>;
+template class FP<uint32_t*,uint64_t>;
+template class FP<uint32_t*,uint64_t*>;
+template class FP<uint32_t*,bool>;
+template class FP<uint32_t*,bool*>;
+template class FP<uint32_t*,float>;
+template class FP<uint32_t*,float*>;
+template class FP<uint32_t*,double>;
+template class FP<uint32_t*,double*>;
+
+template class FP<int64_t,char>;
+template class FP<int64_t,char*>;
+template class FP<int64_t,int8_t>;
+template class FP<int64_t,int8_t*>;
+template class FP<int64_t,uint8_t>;
+template class FP<int64_t,uint8_t*>;
+template class FP<int64_t,int16_t>;
+template class FP<int64_t,int16_t*>;
+template class FP<int64_t,uint16_t>;
+template class FP<int64_t,uint16_t*>;
+template class FP<int64_t,int32_t>;
+template class FP<int64_t,int32_t*>;
+template class FP<int64_t,uint32_t>;
+template class FP<int64_t,uint32_t*>;
+template class FP<int64_t,int64_t>;
+template class FP<int64_t,int64_t*>;
+template class FP<int64_t,uint64_t>;
+template class FP<int64_t,uint64_t*>;
+template class FP<int64_t,bool>;
+template class FP<int64_t,bool*>;
+template class FP<int64_t,float>;
+template class FP<int64_t,float*>;
+template class FP<int64_t,double>;
+template class FP<int64_t,double*>;
+
+template class FP<int64_t*,char>;
+template class FP<int64_t*,char*>;
+template class FP<int64_t*,int8_t>;
+template class FP<int64_t*,int8_t*>;
+template class FP<int64_t*,uint8_t>;
+template class FP<int64_t*,uint8_t*>;
+template class FP<int64_t*,int16_t>;
+template class FP<int64_t*,int16_t*>;
+template class FP<int64_t*,uint16_t>;
+template class FP<int64_t*,uint16_t*>;
+template class FP<int64_t*,int32_t>;
+template class FP<int64_t*,int32_t*>;
+template class FP<int64_t*,uint32_t>;
+template class FP<int64_t*,uint32_t*>;
+template class FP<int64_t*,int64_t>;
+template class FP<int64_t*,int64_t*>;
+template class FP<int64_t*,uint64_t>;
+template class FP<int64_t*,uint64_t*>;
+template class FP<int64_t*,bool>;
+template class FP<int64_t*,bool*>;
+template class FP<int64_t*,float>;
+template class FP<int64_t*,float*>;
+template class FP<int64_t*,double>;
+template class FP<int64_t*,double*>;
+
+template class FP<uint64_t,char>;
+template class FP<uint64_t,char*>;
+template class FP<uint64_t,int8_t>;
+template class FP<uint64_t,int8_t*>;
+template class FP<uint64_t,uint8_t>;
+template class FP<uint64_t,uint8_t*>;
+template class FP<uint64_t,int16_t>;
+template class FP<uint64_t,int16_t*>;
+template class FP<uint64_t,uint16_t>;
+template class FP<uint64_t,uint16_t*>;
+template class FP<uint64_t,int32_t>;
+template class FP<uint64_t,int32_t*>;
+template class FP<uint64_t,uint32_t>;
+template class FP<uint64_t,uint32_t*>;
+template class FP<uint64_t,int64_t>;
+template class FP<uint64_t,int64_t*>;
+template class FP<uint64_t,uint64_t>;
+template class FP<uint64_t,uint64_t*>;
+template class FP<uint64_t,bool>;
+template class FP<uint64_t,bool*>;
+template class FP<uint64_t,float>;
+template class FP<uint64_t,float*>;
+template class FP<uint64_t,double>;
+template class FP<uint64_t,double*>;
+
+template class FP<uint64_t*,char>;
+template class FP<uint64_t*,char*>;
+template class FP<uint64_t*,int8_t>;
+template class FP<uint64_t*,int8_t*>;
+template class FP<uint64_t*,uint8_t>;
+template class FP<uint64_t*,uint8_t*>;
+template class FP<uint64_t*,int16_t>;
+template class FP<uint64_t*,int16_t*>;
+template class FP<uint64_t*,uint16_t>;
+template class FP<uint64_t*,uint16_t*>;
+template class FP<uint64_t*,int32_t>;
+template class FP<uint64_t*,int32_t*>;
+template class FP<uint64_t*,uint32_t>;
+template class FP<uint64_t*,uint32_t*>;
+template class FP<uint64_t*,int64_t>;
+template class FP<uint64_t*,int64_t*>;
+template class FP<uint64_t*,uint64_t>;
+template class FP<uint64_t*,uint64_t*>;
+template class FP<uint64_t*,bool>;
+template class FP<uint64_t*,bool*>;
+template class FP<uint64_t*,float>;
+template class FP<uint64_t*,float*>;
+template class FP<uint64_t*,double>;
+template class FP<uint64_t*,double*>;
+
+template class FP<float,char>;
+template class FP<float,char*>;
+template class FP<float,int8_t>;
+template class FP<float,int8_t*>;
+template class FP<float,uint8_t>;
+template class FP<float,uint8_t*>;
+template class FP<float,int16_t>;
+template class FP<float,int16_t*>;
+template class FP<float,uint16_t>;
+template class FP<float,uint16_t*>;
+template class FP<float,int32_t>;
+template class FP<float,int32_t*>;
+template class FP<float,uint32_t>;
+template class FP<float,uint32_t*>;
+template class FP<float,int64_t>;
+template class FP<float,int64_t*>;
+template class FP<float,uint64_t>;
+template class FP<float,uint64_t*>;
+template class FP<float,bool>;
+template class FP<float,bool*>;
+template class FP<float,float>;
+template class FP<float,float*>;
+template class FP<float,double>;
+template class FP<float,double*>;
+
+template class FP<float*,char>;
+template class FP<float*,char*>;
+template class FP<float*,int8_t>;
+template class FP<float*,int8_t*>;
+template class FP<float*,uint8_t>;
+template class FP<float*,uint8_t*>;
+template class FP<float*,int16_t>;
+template class FP<float*,int16_t*>;
+template class FP<float*,uint16_t>;
+template class FP<float*,uint16_t*>;
+template class FP<float*,int32_t>;
+template class FP<float*,int32_t*>;
+template class FP<float*,uint32_t>;
+template class FP<float*,uint32_t*>;
+template class FP<float*,int64_t>;
+template class FP<float*,int64_t*>;
+template class FP<float*,uint64_t>;
+template class FP<float*,uint64_t*>;
+template class FP<float*,bool>;
+template class FP<float*,bool*>;
+template class FP<float*,float>;
+template class FP<float*,float*>;
+template class FP<float*,double>;
+template class FP<float*,double*>;
+
+template class FP<double,char>;
+template class FP<double,char*>;
+template class FP<double,int8_t>;
+template class FP<double,int8_t*>;
+template class FP<double,uint8_t>;
+template class FP<double,uint8_t*>;
+template class FP<double,int16_t>;
+template class FP<double,int16_t*>;
+template class FP<double,uint16_t>;
+template class FP<double,uint16_t*>;
+template class FP<double,int32_t>;
+template class FP<double,int32_t*>;
+template class FP<double,uint32_t>;
+template class FP<double,uint32_t*>;
+template class FP<double,int64_t>;
+template class FP<double,int64_t*>;
+template class FP<double,uint64_t>;
+template class FP<double,uint64_t*>;
+template class FP<double,bool>;
+template class FP<double,bool*>;
+template class FP<double,float>;
+template class FP<double,float*>;
+template class FP<double,double>;
+template class FP<double,double*>;
+
+template class FP<double*,char>;
+template class FP<double*,char*>;
+template class FP<double*,int8_t>;
+template class FP<double*,int8_t*>;
+template class FP<double*,uint8_t>;
+template class FP<double*,uint8_t*>;
+template class FP<double*,int16_t>;
+template class FP<double*,int16_t*>;
+template class FP<double*,uint16_t>;
+template class FP<double*,uint16_t*>;
+template class FP<double*,int32_t>;
+template class FP<double*,int32_t*>;
+template class FP<double*,uint32_t>;
+template class FP<double*,uint32_t*>;
+template class FP<double*,int64_t>;
+template class FP<double*,int64_t*>;
+template class FP<double*,uint64_t>;
+template class FP<double*,uint64_t*>;
+template class FP<double*,bool>;
+template class FP<double*,bool*>;
+template class FP<double*,float>;
+template class FP<double*,float*>;
+template class FP<double*,double>;
+template class FP<double*,double*>;
+
+template class FP<char, char>;
+template class FP<char, char*>;
+template class FP<char, const char*>;
+
+template class FP<char*, char>;
+template class FP<char*, char*>;
+template class FP<char*, const char*>;
+
+
+
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/FP.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/FP.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/FP.h	(revision 175)
@@ -0,0 +1,188 @@
+/**
+ * @file    FP.h
+ * @brief   Core Utility - Templated Function Pointer Class
+ * @author  sam grove
+ * @version 1.0
+ * @see     
+ *
+ * Copyright (c) 2013
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FP_H
+#define FP_H
+
+/** Example using the FP Class with global functions
+ * @code
+ *  #include "mbed.h"
+ *  #include "FP.h"
+ *  
+ *  FP<void,bool>fp;
+ *  DigitalOut myled(LED1);
+ *  
+ *  void handler(bool value)
+ *  {
+ *      myled = value;
+ *      return;
+ *  }
+ *  
+ *  int main()
+ *  {
+ *      fp.attach(&handler);
+ *      
+ *      while(1) 
+ *      {
+ *          fp(1);
+ *          wait(0.2);
+ *          fp(0);
+ *          wait(0.2);
+ *      }
+ *  }
+ * @endcode
+ */
+ 
+/** Example using the FP Class with different class member functions
+ * @code
+ *  #include "mbed.h"
+ *  #include "FP.h"
+ *  
+ *  FP<void,bool>fp;
+ *  DigitalOut myled(LED4);
+ *  
+ *  class Wrapper
+ *  {
+ *  public:
+ *      Wrapper(){}
+ *  
+ *      void handler(bool value)
+ *      {
+ *          myled = value;
+ *          return;
+ *      }
+ *  };
+ *  
+ *  int main()
+ *  {
+ *      Wrapper wrapped;
+ *      fp.attach(&wrapped, &Wrapper::handler);
+ *      
+ *      while(1) 
+ *      {
+ *          fp(1);
+ *          wait(0.2);
+ *          fp(0);
+ *          wait(0.2);
+ *      }
+ *  }
+ * @endcode
+ */
+ 
+ /** Example using the FP Class with member FP and member function
+ * @code
+ *  #include "mbed.h"
+ *  #include "FP.h"
+ *  
+ *  DigitalOut myled(LED2);
+ *  
+ *  class Wrapper
+ *  {
+ *  public:
+ *      Wrapper()
+ *      {
+ *          fp.attach(this, &Wrapper::handler);
+ *      }
+ *  
+ *      void handler(bool value)
+ *      {
+ *          myled = value;
+ *          return;
+ *      }
+ *      
+ *      FP<void,bool>fp;
+ *  };
+ *  
+ *  int main()
+ *  {
+ *      Wrapper wrapped;
+ *      
+ *      while(1) 
+ *      {
+ *          wrapped.fp(1);
+ *          wait(0.2);
+ *          wrapped.fp(0);
+ *          wait(0.2);
+ *      }
+ *  }
+ * @endcode
+ */
+
+/**
+ *  @class FP
+ *  @brief API abstraction for a Function Pointers
+ */ 
+template<class retT, class argT>
+class FP
+{
+public:
+    /** Create the FP object
+     */ 
+    FP();
+
+    /** Add a callback function to the class
+     *  @param item - Address of the initialized class
+     *  @param member - Address of the member function (dont forget the scope that the function is defined in)
+     */
+    template<class T>
+    void attach(T *item, retT (T::*method)(argT))
+    {
+        obj_callback = (FPtrDummy *)(item);
+        method_callback = (retT (FPtrDummy::*)(argT))(method);
+        return;
+    }
+
+    /** Add a callback function to the class
+     *  @param function - The address of a globally defined function
+     */
+    void attach(retT (*function)(argT));
+    
+    /** Invoke the function attached to the class
+     *  @param arg - An argument that is passed into the function handler that is called
+     *  @return The return from the function hanlder called by this class
+     */
+    retT operator()(argT arg) const;
+    
+    bool attached();
+    
+    void detach();
+
+private:
+    
+    // empty type used for casting
+    class FPtrDummy;
+    
+    FPtrDummy *obj_callback;
+    
+    /**
+     *  @union Funciton
+     *  @brief Member or global callback function
+     */ 
+    union
+    {
+        retT (*c_callback)(argT);                   /*!< Footprint for a global function */
+        retT (FPtrDummy::*method_callback)(argT);   /*!< Footprint for a member function */
+    };
+};
+
+#endif
+
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.cpp	(revision 175)
@@ -0,0 +1,494 @@
+/* 
+Description:
+This is a example code for Sandbox Electronics' I2C/SPI to UART bridge module.
+You can get one of those products on 
+http://sandboxelectronics.com
+
+Version:
+V0.1
+
+Release Date:
+2014-02-16
+
+Author:
+Tiequan Shao          info@sandboxelectronics.com
+
+Lisence:
+CC BY-NC-SA 3.0
+
+Please keep the above information when you use this code in your project. 
+*/
+
+#if defined(__AVR_ATmega328P__)
+
+#include "SC16IS750.h"
+#include <Wire.h>
+
+#define WIRE Wire
+
+
+WifiData::WifiData(uint8_t prtcl, uint8_t addr_sspin)
+{
+    protocol = prtcl;
+    if ( protocol == SC16IS750_PROTOCOL_I2C ) {
+        device_address_sspin = (addr_sspin>>1);
+    } else {
+        device_address_sspin = addr_sspin;
+    }
+    peek_flag = 0;
+}
+
+void WifiData::begin(uint32_t baud)
+{
+    //Serial.println("1111111111111111");
+    if ( protocol == SC16IS750_PROTOCOL_I2C) {
+    //Serial.println("22222222222222");
+        WIRE.begin();
+    } 
+    ResetDevice();
+    FIFOEnable(1);
+    SetBaudrate(baud);
+    SetLine(8,0,1);
+}
+
+int WifiData::available(void)
+{
+    return FIFOAvailableData();
+}
+
+int WifiData::read(void)
+{
+    if ( peek_flag == 0) {
+        return ReadByte();
+    } else {
+        peek_flag = 0;
+        return peek_buf;
+    }
+}
+
+size_t WifiData::write(uint8_t val)
+{
+    WriteByte(val);
+}
+
+void WifiData::pinMode(uint8_t pin, uint8_t i_o)
+{
+    GPIOSetPinMode(pin, i_o);
+}
+
+void WifiData::digitalWrite(uint8_t pin, uint8_t value)
+{
+    GPIOSetPinState(pin, value);
+}
+
+uint8_t WifiData::digitalRead(uint8_t pin)
+{
+   return GPIOGetPinState(pin);
+}
+
+
+uint8_t WifiData::ReadRegister(uint8_t reg_addr)
+{
+    uint8_t result;
+    if ( protocol == SC16IS750_PROTOCOL_I2C ) {  // register read operation via I2C
+
+        WIRE.beginTransmission(device_address_sspin);
+        WIRE.write((reg_addr<<3));
+        WIRE.endTransmission(0);
+        WIRE.requestFrom(device_address_sspin,(uint8_t)1);
+        result = WIRE.read();
+    } 
+
+    return result;
+
+}
+
+void WifiData::WriteRegister(uint8_t reg_addr, uint8_t val)
+{
+    if ( protocol == SC16IS750_PROTOCOL_I2C ) {  // register read operation via I2C
+        WIRE.beginTransmission(device_address_sspin);
+        WIRE.write((reg_addr<<3));
+        WIRE.write(val);
+        WIRE.endTransmission(1);
+    } 
+
+
+    return ;
+}
+
+int16_t WifiData::SetBaudrate(uint32_t baudrate) //return error of baudrate parts per thousand
+{
+    uint16_t divisor;
+    uint8_t prescaler;
+    uint32_t actual_baudrate;
+    int16_t error;
+    uint8_t temp_lcr;
+    if ( (ReadRegister(SC16IS750_REG_MCR)&0x80) == 0) { //if prescaler==1
+        prescaler = 1;
+    } else {
+        prescaler = 4;
+    }
+
+    divisor = (SC16IS750_CRYSTCAL_FREQ/prescaler)/(baudrate*16);
+
+    temp_lcr = ReadRegister(SC16IS750_REG_LCR);
+    temp_lcr |= 0x80;
+    WriteRegister(SC16IS750_REG_LCR,temp_lcr);
+    //write to DLL
+    WriteRegister(SC16IS750_REG_DLL,(uint8_t)divisor);
+    //write to DLH
+    WriteRegister(SC16IS750_REG_DLH,(uint8_t)(divisor>>8));
+    temp_lcr &= 0x7F;
+    WriteRegister(SC16IS750_REG_LCR,temp_lcr);
+
+
+    actual_baudrate = (SC16IS750_CRYSTCAL_FREQ/prescaler)/(16*divisor);
+    error = ((float)actual_baudrate-baudrate)*1000/baudrate;
+
+    return error;
+
+}
+
+void WifiData::SetLine(uint8_t data_length, uint8_t parity_select, uint8_t stop_length )
+{
+    uint8_t temp_lcr;
+    temp_lcr = ReadRegister(SC16IS750_REG_LCR);
+    temp_lcr &= 0xC0; //Clear the lower six bit of LCR (LCR[0] to LCR[5]
+
+    switch (data_length) {            //data length settings
+        case 5:
+            break;
+        case 6:
+            temp_lcr |= 0x01;
+            break;
+        case 7:
+            temp_lcr |= 0x02;
+            break;
+        case 8:
+            temp_lcr |= 0x03;
+            break;
+        default:
+            temp_lcr |= 0x03;
+            break;
+    }
+
+    if ( stop_length == 2 ) {
+        temp_lcr |= 0x04;
+    }
+
+    switch (parity_select) {            //parity selection length settings
+        case 0:                         //no parity
+             break;
+        case 1:                         //odd parity
+            temp_lcr |= 0x08;
+            break;
+        case 2:                         //even parity
+            temp_lcr |= 0x18;
+            break;
+        case 3:                         //force '1' parity
+            temp_lcr |= 0x03;
+            break;
+        case 4:                         //force '0' parity
+            break;
+        default:
+            break;
+    }
+
+    WriteRegister(SC16IS750_REG_LCR,temp_lcr);
+}
+
+void WifiData::GPIOSetPinMode(uint8_t pin_number, uint8_t i_o)
+{
+    uint8_t temp_iodir;
+
+    temp_iodir = ReadRegister(SC16IS750_REG_IODIR);
+    if ( i_o == OUTPUT ) {
+      temp_iodir |= (0x01 << pin_number);
+    } else {
+      temp_iodir &= (uint8_t)~(0x01 << pin_number);
+    }
+
+    WriteRegister(SC16IS750_REG_IODIR, temp_iodir);
+    return;
+}
+
+void WifiData::GPIOSetPinState(uint8_t pin_number, uint8_t pin_state)
+{
+    uint8_t temp_iostate;
+
+    temp_iostate = ReadRegister(SC16IS750_REG_IOSTATE);
+    if ( pin_state == 1 ) {
+      temp_iostate |= (0x01 << pin_number);
+    } else {
+      temp_iostate &= (uint8_t)~(0x01 << pin_number);
+    }
+
+    WriteRegister(SC16IS750_REG_IOSTATE, temp_iostate);
+    return;
+}
+
+
+uint8_t WifiData::GPIOGetPinState(uint8_t pin_number)
+{
+    uint8_t temp_iostate;
+
+    temp_iostate = ReadRegister(SC16IS750_REG_IOSTATE);
+    if ( temp_iostate & (0x01 << pin_number)== 0 ) {
+      return 0;
+    }
+    return 1;
+}
+
+uint8_t WifiData::GPIOGetPortState(void)
+{
+
+    return ReadRegister(SC16IS750_REG_IOSTATE);
+
+}
+
+void WifiData::GPIOSetPortMode(uint8_t port_io)
+{
+    WriteRegister(SC16IS750_REG_IODIR, port_io);
+    return;
+}
+
+void WifiData::GPIOSetPortState(uint8_t port_state)
+{
+    WriteRegister(SC16IS750_REG_IOSTATE, port_state);
+    return;
+}
+
+void WifiData::SetPinInterrupt(uint8_t io_int_ena)
+{
+    WriteRegister(SC16IS750_REG_IOINTENA, io_int_ena);
+    return;
+}
+
+void WifiData::ResetDevice(void)
+{
+    uint8_t reg;
+
+    reg = ReadRegister(SC16IS750_REG_IOCONTROL);
+    reg |= 0x08;
+    WriteRegister(SC16IS750_REG_IOCONTROL, reg);
+
+    return;
+}
+
+void WifiData::ModemPin(uint8_t gpio) //gpio == 0, gpio[7:4] are modem pins, gpio == 1 gpio[7:4] are gpios
+{
+    uint8_t temp_iocontrol;
+
+    temp_iocontrol = ReadRegister(SC16IS750_REG_IOCONTROL);
+    if ( gpio == 0 ) {
+        temp_iocontrol |= 0x02;
+    } else {
+        temp_iocontrol &= 0xFD;
+    }
+    WriteRegister(SC16IS750_REG_IOCONTROL, temp_iocontrol);
+
+    return;
+}
+
+void WifiData::GPIOLatch(uint8_t latch)
+{
+    uint8_t temp_iocontrol;
+
+    temp_iocontrol = ReadRegister(SC16IS750_REG_IOCONTROL);
+    if ( latch == 0 ) {
+        temp_iocontrol &= 0xFE;
+    } else {
+        temp_iocontrol |= 0x01;
+    }
+    WriteRegister(SC16IS750_REG_IOCONTROL, temp_iocontrol);
+
+    return;
+}
+
+void WifiData::InterruptControl(uint8_t int_ena)
+{
+    WriteRegister(SC16IS750_REG_IER, int_ena);
+}
+
+uint8_t WifiData::InterruptPendingTest(void)
+{
+    return (ReadRegister(SC16IS750_REG_IIR) & 0x01);
+}
+
+void WifiData::__isr(void)
+{
+    uint8_t irq_src;
+
+    irq_src = ReadRegister(SC16IS750_REG_IIR);
+    irq_src = (irq_src >> 1);
+    irq_src &= 0x3F;
+
+    switch (irq_src) {
+        case 0x06:                  //Receiver Line Status Error
+            break;
+        case 0x0c:               //Receiver time-out interrupt
+            break;
+        case 0x04:               //RHR interrupt
+            break;
+        case 0x02:               //THR interrupt
+            break;
+        case 0x00:                  //modem interrupt;
+            break;
+        case 0x30:                  //input pin change of state
+            break;
+        case 0x10:                  //XOFF
+            break;
+        case 0x20:                  //CTS,RTS
+            break;
+        default:
+            break;
+    }
+    return;
+}
+
+void WifiData::FIFOEnable(uint8_t fifo_enable)
+{
+    uint8_t temp_fcr;
+
+    temp_fcr = ReadRegister(SC16IS750_REG_FCR);
+
+    if (fifo_enable == 0){
+        temp_fcr &= 0xFE;
+    } else {
+        temp_fcr |= 0x01;
+    }
+    WriteRegister(SC16IS750_REG_FCR,temp_fcr);
+
+    return;
+}
+
+void WifiData::FIFOReset(uint8_t rx_fifo)
+{
+     uint8_t temp_fcr;
+
+    temp_fcr = ReadRegister(SC16IS750_REG_FCR);
+
+    if (rx_fifo == 0){
+        temp_fcr |= 0x04;
+    } else {
+        temp_fcr |= 0x02;
+    }
+    WriteRegister(SC16IS750_REG_FCR,temp_fcr);
+
+    return;
+
+}
+
+void WifiData::FIFOSetTriggerLevel(uint8_t rx_fifo, uint8_t length)
+{
+    uint8_t temp_reg;
+
+    temp_reg = ReadRegister(SC16IS750_REG_MCR);
+    temp_reg |= 0x04;
+    WriteRegister(SC16IS750_REG_MCR,temp_reg); //SET MCR[2] to '1' to use TLR register or trigger level control in FCR register
+
+    temp_reg = ReadRegister(SC16IS750_REG_EFR);
+    WriteRegister(SC16IS750_REG_EFR, temp_reg|0x10); //set ERF[4] to '1' to use the  enhanced features
+    if (rx_fifo == 0) {
+        WriteRegister(SC16IS750_REG_TLR, length<<4); //Tx FIFO trigger level setting
+    } else {
+        WriteRegister(SC16IS750_REG_TLR, length);    //Rx FIFO Trigger level setting
+    }
+    WriteRegister(SC16IS750_REG_EFR, temp_reg); //restore EFR register
+
+    return;
+}
+
+uint8_t WifiData::FIFOAvailableData(void)
+{
+   return ReadRegister(SC16IS750_REG_RXLVL);
+
+}
+
+uint8_t WifiData::FIFOAvailableSpace(void)
+{
+   return ReadRegister(SC16IS750_REG_TXLVL);
+
+}
+
+void WifiData::WriteByte(uint8_t val)
+{
+    uint8_t tmp_lsr;
+    do {
+        tmp_lsr = ReadRegister(SC16IS750_REG_LSR);
+    } while ((tmp_lsr&0x20) ==0);
+
+    WriteRegister(SC16IS750_REG_THR,val);
+
+}
+
+int WifiData::ReadByte(void)
+{
+    volatile uint8_t val;
+    if (FIFOAvailableData() == 0) {
+
+        return -1;
+
+    } else {
+
+      val = ReadRegister(SC16IS750_REG_RHR);
+      return val;
+    }
+
+}
+
+void WifiData::EnableTransmit(uint8_t tx_enable)
+{
+    uint8_t temp_efcr;
+    temp_efcr = ReadRegister(SC16IS750_REG_EFCR);
+    if ( tx_enable == 0) {
+        temp_efcr |= 0x04;
+    } else {
+        temp_efcr &= 0xFB;
+    }
+    WriteRegister(SC16IS750_REG_EFCR,temp_efcr);
+
+    return;
+}
+
+uint8_t WifiData::ping()
+{
+    WriteRegister(SC16IS750_REG_SPR,0x55);
+    if (ReadRegister(SC16IS750_REG_SPR) !=0x55) {
+        return 0;
+    }
+
+    WriteRegister(SC16IS750_REG_SPR,0xAA);
+    if (ReadRegister(SC16IS750_REG_SPR) !=0xAA) {
+        return 0;
+    }
+
+    return 1;
+
+}
+
+void WifiData::flush()
+{
+    uint8_t tmp_lsr;
+
+    do {
+        tmp_lsr = ReadRegister(SC16IS750_REG_LSR);
+    } while ((tmp_lsr&0x20) ==0);
+
+
+}
+
+int WifiData::peek()
+{
+    if ( peek_flag == 0 ) {
+        peek_buf =ReadByte();
+        if (  peek_buf >= 0 ) {
+            peek_flag = 1;
+        }
+    }
+
+    return peek_buf;
+
+}
+
+#endif
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.h	(revision 175)
@@ -0,0 +1,163 @@
+/* 
+Description:
+This is a example code for Sandbox Electronics' I2C/SPI to UART bridge module.
+You can get one of those products on 
+http://sandboxelectronics.com
+
+Version:
+V0.1
+
+Release Date:
+2014-02-16
+
+Author:
+Tiequan Shao          info@sandboxelectronics.com
+
+Lisence:
+CC BY-NC-SA 3.0
+
+Please keep the above information when you use this code in your project. 
+*/
+
+
+#ifndef _SC16IS750_H_
+#define _SC16IS750_H_
+
+#if ARDUINO >= 100
+ #include "Arduino.h"
+#else
+ #include "WProgram.h"
+#endif
+
+//Device Address
+
+//A:VDD
+//B:GND
+//C:SCL
+//D:SDA
+#define     SC16IS750_ADDRESS_AA     (0X90)
+#define     SC16IS750_ADDRESS_AB     (0X92)
+#define     SC16IS750_ADDRESS_AC     (0X94)
+#define     SC16IS750_ADDRESS_AD     (0X96)
+#define     SC16IS750_ADDRESS_BA     (0X98)
+#define     SC16IS750_ADDRESS_BB     (0X9A)
+#define     SC16IS750_ADDRESS_BC     (0X9C)
+#define     SC16IS750_ADDRESS_BD     (0X9E)
+#define     SC16IS750_ADDRESS_CA     (0XA0)
+#define     SC16IS750_ADDRESS_CB     (0XA2)
+#define     SC16IS750_ADDRESS_CC     (0XA4)
+#define     SC16IS750_ADDRESS_CD     (0XA6)
+#define     SC16IS750_ADDRESS_DA     (0XA8)
+#define     SC16IS750_ADDRESS_DB     (0XAA)
+#define     SC16IS750_ADDRESS_DC     (0XAC)
+#define     SC16IS750_ADDRESS_DD     (0XAE)
+
+
+//General Registers
+#define     SC16IS750_REG_RHR        (0x00)
+#define     SC16IS750_REG_THR        (0X00)
+#define     SC16IS750_REG_IER        (0X01)
+#define     SC16IS750_REG_FCR        (0X02)
+#define     SC16IS750_REG_IIR        (0X02)
+#define     SC16IS750_REG_LCR        (0X03)
+#define     SC16IS750_REG_MCR        (0X04)
+#define     SC16IS750_REG_LSR        (0X05)
+#define     SC16IS750_REG_MSR        (0X06)
+#define     SC16IS750_REG_SPR        (0X07)
+#define     SC16IS750_REG_TCR        (0X06)
+#define     SC16IS750_REG_TLR        (0X07)
+#define     SC16IS750_REG_TXLVL      (0X08)
+#define     SC16IS750_REG_RXLVL      (0X09)
+#define     SC16IS750_REG_IODIR      (0X0A)
+#define     SC16IS750_REG_IOSTATE    (0X0B)
+#define     SC16IS750_REG_IOINTENA   (0X0C)
+#define     SC16IS750_REG_IOCONTROL  (0X0E)
+#define     SC16IS750_REG_EFCR       (0X0F)
+
+//Special Registers
+#define     SC16IS750_REG_DLL        (0x00)
+#define     SC16IS750_REG_DLH        (0X01)
+
+//Enhanced Registers
+#define     SC16IS750_REG_EFR        (0X02)
+#define     SC16IS750_REG_XON1       (0X04)
+#define     SC16IS750_REG_XON2       (0X05)
+#define     SC16IS750_REG_XOFF1      (0X06)
+#define     SC16IS750_REG_XOFF2      (0X07)
+
+//
+#define     SC16IS750_INT_CTS        (0X80)
+#define     SC16IS750_INT_RTS        (0X40)
+#define     SC16IS750_INT_XOFF       (0X20)
+#define     SC16IS750_INT_SLEEP      (0X10)
+#define     SC16IS750_INT_MODEM      (0X08)
+#define     SC16IS750_INT_LINE       (0X04)
+#define     SC16IS750_INT_THR        (0X02)
+#define     SC16IS750_INT_RHR        (0X01)
+
+//Application Related 
+
+#define     SC16IS750_CRYSTCAL_FREQ (14745600UL) 
+//#define   SC16IS750_CRYSTCAL_FREQ (1843200UL)   
+//#define     SC16IS750_CRYSTCAL_FREQ (16000000UL)    
+//#define     SC16IS750_DEBUG_PRINT   (0)
+#define     SC16IS750_PROTOCOL_I2C  (0)
+#define     SC16IS750_PROTOCOL_I2C  (0)
+#define     END     "<!--~-->"
+
+class WifiData : public Stream
+{ 
+    public:
+        WifiData(uint8_t prtcl = SC16IS750_PROTOCOL_I2C, uint8_t addr = SC16IS750_ADDRESS_AD);
+        void begin(uint32_t baud);                               
+        int read();
+        size_t write(uint8_t val);
+        int available();
+        void pinMode(uint8_t pin, uint8_t io);
+        void digitalWrite(uint8_t pin, uint8_t value);
+        uint8_t digitalRead(uint8_t pin);
+        uint8_t ping();
+        int peek();
+        void flush();
+        uint8_t GPIOGetPortState(void);
+        uint8_t InterruptPendingTest(void);
+        void    SetPinInterrupt(uint8_t io_int_ena);
+        void    InterruptControl(uint8_t int_ena);
+        void    ModemPin(uint8_t gpio); //gpio == 0, gpio[7:4] are modem pins, gpio == 1 gpio[7:4] are gpios
+        void    GPIOLatch(uint8_t latch);
+        
+    
+    private:
+        uint8_t device_address_sspin;
+        uint8_t protocol;
+    //  uint32_t timeout;
+        int16_t SetBaudrate(uint32_t baudrate);
+        uint8_t ReadRegister(uint8_t reg_addr);
+        void    WriteRegister(uint8_t reg_addr, uint8_t val);
+        void    SetLine(uint8_t data_length, uint8_t parity_select, uint8_t stop_length );
+        void    GPIOSetPinMode(uint8_t pin_number, uint8_t i_o);
+        void    GPIOSetPinState(uint8_t pin_number, uint8_t pin_state);
+        
+        uint8_t GPIOGetPinState(uint8_t pin_number);
+        void    GPIOSetPortMode(uint8_t port_io);
+        void    GPIOSetPortState(uint8_t port_state);
+        void    ResetDevice(void);
+        
+        
+        
+        void    __isr(void);
+        void    FIFOEnable(uint8_t fifo_enable);
+        void    FIFOReset(uint8_t rx_fifo);
+        void    FIFOSetTriggerLevel(uint8_t rx_fifo, uint8_t length);
+        uint8_t FIFOAvailableData(void);
+        uint8_t FIFOAvailableSpace(void);
+        void    WriteByte(uint8_t val);
+        int     ReadByte(void);
+        void    EnableTransmit(uint8_t tx_enable);
+    //  int16_t readwithtimeout();
+        int     peek_buf;
+        uint8_t peek_flag;
+        
+};
+
+#endif
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/UnowifiCiao.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/UnowifiCiao.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/UnowifiCiao.cpp	(revision 175)
@@ -0,0 +1,207 @@
+/*
+****************************************************************************
+* Copyright (c) 2015 Arduino srl. All right reserved.
+*
+* File : UnowifiCiao.cpp
+* Date : 2016/02/16
+* Revision : 0.0.1 $
+* Author: adriano[at]arduino[dot]org
+*
+****************************************************************************
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "Ciao.h"
+#include "Wifi.h"
+
+#if defined(__AVR_ATmega328P__)
+
+#include <stdarg.h>
+#include <stdio.h>
+
+WifiData espSerial = WifiData(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_AA);
+ESP esp(&espSerial, 4);
+REST rest(&esp);
+
+CiaoClass Ciao;
+WifiClass Wifi;
+
+boolean wifiConnected = false;
+
+void wifiCb(void* response)
+{
+	uint32_t status;
+	RESPONSE res(response);
+
+	if(res.getArgc() == 1) {
+		res.popArgs((uint8_t*)&status, 4);
+		if(status == STATION_GOT_IP){
+			espSerial.println("DBG: Internet Connected");
+			wifiConnected = true;
+		}
+		else {
+			wifiConnected = false;
+		}
+	}
+}
+
+void WifiClass::powerON(){ 	
+	
+}
+void WifiClass::powerOFF(){ 	
+	
+}
+
+WifiData WifiClass::stream(){
+	return espSerial;
+}
+int WifiClass::read(){
+	return espSerial.read();
+}
+void WifiClass::print(String str){
+	espSerial.print(str);
+}
+void WifiClass::println(String str){
+	espSerial.println(str);
+}
+void CiaoClass::print(String str){
+	espSerial.print(str);
+}
+void CiaoClass::println(String str){
+	espSerial.println(str);
+}
+boolean WifiClass::available(){
+	return espSerial.available();
+}
+void WifiClass::connect(char* ssid,char* pwd){
+	esp.wifiConnect(ssid, pwd);
+}
+boolean WifiClass::connected(){
+	return wifiConnected;
+}
+
+void WifiBegin() {
+	Serial.begin(9600);
+	espSerial.begin(9600);
+	if(espSerial.ping()!=1) {
+		espSerial.println("DBG: esp not found");
+		while(1);
+	}
+	else {
+		//espSerial.println("device found");
+	}
+	//metti GPIO control here !!!
+	esp.enable();
+	delay(1000);
+	esp.reset();
+	delay(1000);
+	while(!esp.ready());
+	esp.wifiCb.attach(&wifiCb);
+	espSerial.println("\nDBG: UnoWiFi Start");
+}
+void WifiClass::begin() {
+	WifiBegin();
+}
+void CiaoClass::begin() {
+
+	WifiBegin();
+	espSerial.println("DBG: Ciao start");
+	rest.begin("google.com");
+	rest.get("/");
+	delay(3000);
+}
+
+CiaoData responseREAD(){
+	CiaoData data;
+	delay(400);
+	char response[64] = "";
+	char cstr[8] = "";
+
+	int ret = rest.getResponse(response, 64);
+	//espSerial.println(ret);
+
+	snprintf(cstr,8,"%d",ret);
+
+		data.msg_split[0]="id";
+		data.msg_split[1]=cstr;
+		data.msg_split[2]=response;
+				
+	return data;
+}
+CiaoData requestPOST(char* hostname, String stringone){
+	rest.begin(hostname);
+	//delay(1000);	fix
+	//esp.process(); 
+	rest.post((const char*) stringone.c_str(),0);
+	return responseREAD(); 
+}
+
+CiaoData requestGET(char* hostname, String stringone){
+
+	rest.begin(hostname);
+	//delay(1000);   fix
+	//esp.process(); 
+	rest.get((const char*) stringone.c_str());
+	return responseREAD(); 
+}
+
+CiaoData PassThroughM(char* connector,char* hostname, String stringone, char* method){
+  
+	short mode = 0;
+	if (!strcmp(connector, "rest")){
+		mode = 0;
+	}
+	else if (!strcmp(connector, "mqtt")){
+		mode = 1;
+	}
+	else {
+		CiaoData data;				
+		data.msg_split[0]="";
+		data.msg_split[1]="";
+		data.msg_split[2]="Protocol Error";
+		return data;
+	}
+	
+	if (mode == 0){ 
+		if (!strcmp(method, "GET")){
+			return requestGET(hostname, stringone); 
+		}
+		else if (!strcmp(method, "POST")){
+			return requestPOST(hostname, stringone); 
+		}
+		else{
+			CiaoData data;				
+			data.msg_split[0]="";
+			data.msg_split[1]="";
+			data.msg_split[2]="Method Error";
+			return data;
+		}   
+	}
+}
+
+CiaoData CiaoClass::write(char* connector,char* hostname, String stringone, char* method) {
+	return PassThroughM(connector, hostname, stringone, method);
+}
+CiaoData CiaoClass::read(char* connector,char* hostname, String stringone, char* method) {
+	return PassThroughM(connector, hostname, stringone, method);
+}
+CiaoData CiaoClass::write(char* connector,char* hostname, String stringone) {
+	return PassThroughM(connector, hostname, stringone, "GET");
+}
+CiaoData CiaoClass::read(char* connector,char* hostname, String stringone) {
+	return PassThroughM(connector, hostname, stringone, "GET");
+}
+
+#endif
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Wifi.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Wifi.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Wifi.h	(revision 175)
@@ -0,0 +1,47 @@
+#ifndef WIFI_H_
+#define WIFI_H_
+
+#include <Arduino.h>
+
+#include <Stream.h>
+#include "crc16.h"
+//#include <mqtt.h>
+#include "rest.h"
+#include "espduino.h"
+#include "ringbuf.h"
+#include "FP.h"
+#include <string.h>
+
+#ifdef __AVR_ATmega328P__
+
+//#else
+
+#include "SC16IS750.h"
+
+class WifiClass {
+
+	public:
+		void begin();
+
+		void print(String str);
+		void println(String str);
+		int read();		
+
+		WifiData stream();
+
+		boolean available();
+		boolean connected();
+
+		void connect(char* , char*);
+
+		void powerON();
+		void powerOFF();
+
+};
+
+extern WifiClass Wifi;
+
+#endif
+
+
+#endif /* WIFI_H_ */
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/crc16.c
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/crc16.c	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/crc16.c	(revision 175)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 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 Contiki operating system.
+ *
+ */
+
+/** \addtogroup crc16
+ * @{ */
+
+/**
+ * \file
+ *         Implementation of the CRC16 calculcation
+ * \author
+ *         Adam Dunkels <adam@sics.se>
+ *
+ */
+
+/* CITT CRC16 polynomial ^16 + ^12 + ^5 + 1 */
+/*---------------------------------------------------------------------------*/
+unsigned short
+crc16_add(unsigned char b, unsigned short acc)
+{
+  /*
+    acc  = (unsigned char)(acc >> 8) | (acc << 8);
+    acc ^= b;
+    acc ^= (unsigned char)(acc & 0xff) >> 4;
+    acc ^= (acc << 8) << 4;
+    acc ^= ((acc & 0xff) << 4) << 1;
+  */
+
+  acc ^= b;
+  acc  = (acc >> 8) | (acc << 8);
+  acc ^= (acc & 0xff00) << 4;
+  acc ^= (acc >> 8) >> 4;
+  acc ^= (acc & 0xff00) >> 5;
+  return acc;
+}
+/*---------------------------------------------------------------------------*/
+unsigned short
+crc16_data(const unsigned char *data, int len, unsigned short acc)
+{
+  int i;
+  
+  for(i = 0; i < len; ++i) {
+    acc = crc16_add(*data, acc);
+    ++data;
+  }
+  return acc;
+}
+/*---------------------------------------------------------------------------*/
+
+/** @} */
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/crc16.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/crc16.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/crc16.h	(revision 175)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 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 Contiki operating system.
+ *
+ */
+
+/**
+ * \file
+ *         Header file for the CRC16 calculcation
+ * \author
+ *         Adam Dunkels <adam@sics.se>
+ *
+ */
+
+/** \addtogroup lib
+ * @{ */
+
+/**
+ * \defgroup crc16 Cyclic Redundancy Check 16 (CRC16) calculation
+ *
+ * The Cyclic Redundancy Check 16 is a hash function that produces a
+ * checksum that is used to detect errors in transmissions. The CRC16
+ * calculation module is an iterative CRC calculator that can be used
+ * to cumulatively update a CRC checksum for every incoming byte.
+ *
+ * @{
+ */
+
+#ifndef CRC16_H_
+#define CRC16_H_
+#ifdef	__cplusplus
+extern "C" {
+#endif
+/**
+ * \brief      Update an accumulated CRC16 checksum with one byte.
+ * \param b    The byte to be added to the checksum
+ * \param crc  The accumulated CRC that is to be updated.
+ * \return     The updated CRC checksum.
+ *
+ *             This function updates an accumulated CRC16 checksum
+ *             with one byte. It can be used as a running checksum, or
+ *             to checksum an entire data block.
+ *
+ *             \note The algorithm used in this implementation is
+ *             tailored for a running checksum and does not perform as
+ *             well as a table-driven algorithm when checksumming an
+ *             entire data block.
+ *
+ */
+unsigned short crc16_add(unsigned char b, unsigned short crc);
+
+/**
+ * \brief      Calculate the CRC16 over a data area
+ * \param data Pointer to the data
+ * \param datalen The length of the data
+ * \param acc  The accumulated CRC that is to be updated (or zero).
+ * \return     The CRC16 checksum.
+ *
+ *             This function calculates the CRC16 checksum of a data area.
+ *
+ *             \note The algorithm used in this implementation is
+ *             tailored for a running checksum and does not perform as
+ *             well as a table-driven algorithm when checksumming an
+ *             entire data block.
+ */
+unsigned short crc16_data(const unsigned char *data, int datalen,
+			  unsigned short acc);
+#ifdef	__cplusplus
+}
+#endif
+#endif /* CRC16_H_ */
+
+/** @} */
+/** @} */
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.cpp	(revision 175)
@@ -0,0 +1,297 @@
+/**
+ * \file
+ *       ESP8266 bridge arduino library 
+ * \author
+ *       Tuan PM <tuanpm@live.com>
+ */
+#include "espduino.h"
+
+RESPONSE::RESPONSE(void * response)
+{
+  cmd = (PACKET_CMD*)response;
+  arg_ptr = (uint8_t*)&cmd->args;
+  arg_num = 0;
+}
+
+uint16_t RESPONSE::getArgc()
+{
+  return cmd->argc;
+}
+uint16_t RESPONSE::argLen()
+{
+  return *(uint16_t*)arg_ptr;
+}
+int32_t RESPONSE::popArgs(uint8_t *data, uint16_t maxLen)
+{
+  uint16_t length, len, incLen = 0;
+
+   if(arg_num >= cmd->argc)
+     return -1;
+ 
+  length = *(uint16_t*)arg_ptr;
+  len = length;
+  arg_ptr += 2;
+
+  while(length --){
+    *data ++ = *arg_ptr ++;
+    incLen ++;
+    if(incLen > maxLen){
+      arg_num ++;
+      return maxLen;
+    }
+      
+  }
+  arg_num ++;
+  return len;
+}
+
+String RESPONSE::popString()
+{
+  String ret;
+  uint16_t len = *(uint16_t*)arg_ptr;
+  arg_ptr += 2;
+  while(len --)
+    ret += (char)*arg_ptr ++;
+  arg_num ++;
+  return ret;
+}
+void RESPONSE::popString(String* data)
+{
+  uint16_t len = *(uint16_t*)arg_ptr;
+  arg_ptr += 2;
+  while(len --)
+    data->concat( (char)*arg_ptr ++);
+  arg_num ++;
+}
+
+void ESP::protoCompletedCb(void)
+{
+  PACKET_CMD *cmd = (PACKET_CMD*)_proto.buf;
+  uint16_t crc = 0, argc, len, resp_crc;
+  uint8_t *data_ptr;
+  argc = cmd->argc;
+  data_ptr = (uint8_t*)&cmd->args ;
+  crc = crc16_data((uint8_t*)&cmd->cmd, 12, crc);
+  while(argc--){
+    len = *((uint16_t*)data_ptr);
+    crc = crc16_data(data_ptr, 2, crc);
+    data_ptr += 2;
+    while(len --){
+      crc = crc16_data(data_ptr, 1, crc);
+      data_ptr ++;
+    }
+  }
+  resp_crc =  *(uint16_t*)data_ptr;
+  if(crc != resp_crc) {
+      INFO("ARDUINO: Invalid CRC");
+    return;
+  }
+
+  FP<void, void*> *fp;
+  if(cmd->callback != 0){
+    fp = (FP<void, void*>*)cmd->callback;
+
+    return_cmd = cmd->cmd;
+    return_value = cmd->_return;
+
+    if(fp->attached())
+      (*fp)((void*)cmd);
+  } else {
+    if(cmd->argc == 0) {
+      is_return = true;
+      return_cmd = cmd->cmd;
+      return_value = cmd->_return;
+    }
+    
+  }
+}
+
+void ESP::wifiConnect(const char* ssid, const char* password)
+{
+  uint16_t crc;
+  crc = request(CMD_WIFI_CONNECT, (uint32_t)&wifiCb, 0, 2);
+  crc = request(crc,(uint8_t*)ssid, strlen(ssid));
+  crc = request(crc,(uint8_t*)password, strlen(password));
+  request(crc);
+}
+void ESP::write(uint8_t data)
+{
+  switch(data){
+  case SLIP_START:
+  case SLIP_END:
+  case SLIP_REPL:
+    _serial->write(SLIP_REPL);
+    _serial->write(SLIP_ESC(data));
+    break;
+  default:
+    _serial->write(data);
+  }
+}
+void ESP::write(uint8_t* data, uint16_t len)
+{
+  while(len --)
+    write(*data ++);
+}
+uint16_t ESP::request(uint16_t cmd, uint32_t callback, uint32_t _return, uint16_t argc)
+{
+  uint16_t crc = 0;
+  _serial->write(0x7E);
+  write((uint8_t*)&cmd, 2);
+  crc = crc16_data((uint8_t*)&cmd, 2, crc);
+
+  write((uint8_t*)&callback, 4);
+  crc = crc16_data((uint8_t*)&callback, 4, crc);
+
+  write((uint8_t*)&_return, 4);
+  crc = crc16_data((uint8_t*)&_return, 4, crc);
+
+  write((uint8_t*)&argc, 2);
+  crc = crc16_data((uint8_t*)&argc, 2, crc);
+  return crc;
+}
+
+uint16_t ESP::request(uint16_t crc_in, uint8_t* data, uint16_t len)
+{
+  uint8_t temp = 0;
+  uint16_t pad_len = len;
+  while(pad_len % 4 != 0)
+    pad_len++;
+  write((uint8_t*)&pad_len, 2);
+  crc_in = crc16_data((uint8_t*)&pad_len, 2, crc_in);
+  while(len --){
+    write(*data);
+    crc_in = crc16_data((uint8_t*)data, 1, crc_in);
+    data ++;
+    if(pad_len > 0) pad_len --;
+  }
+  
+  while(pad_len --){
+    write(temp);
+    crc_in = crc16_data((uint8_t*)&temp, 1, crc_in);
+  }
+  return crc_in;
+}
+uint16_t ESP::request(uint16_t crc)
+{
+  write((uint8_t*)&crc, 2);
+  _serial->write(0x7F);
+}
+
+void ESP::init()
+{
+  _proto.buf = _protoBuf;
+  _proto.bufSize = sizeof(_protoBuf);
+  _proto.dataLen = 0;
+  _proto.isEsc = 0;
+  pinMode(_chip_pd, OUTPUT);
+
+}
+
+ESP::ESP(Stream *serial, int chip_pd):
+_serial(serial), _chip_pd(chip_pd)
+{
+  _debugEn = false;
+  init();
+}
+
+ESP::ESP(Stream *serial, Stream* debug, int chip_pd):
+_serial(serial), _debug(debug), _chip_pd(chip_pd)
+{
+    _debugEn = true;
+    //_serial = _debug;
+    init();
+}
+void ESP::enable()
+{
+  digitalWrite(_chip_pd, HIGH);
+}
+void ESP::disable()
+{
+  digitalWrite(_chip_pd, LOW);
+}
+void ESP::INFO(String info)
+{
+  if(_debugEn)
+    _debug->println(info);
+}
+
+void ESP::reset()
+{
+  uint16_t crc = request(CMD_RESET, 0, 0, 0);
+  request(crc);
+}
+
+boolean ESP::ready()
+{
+  uint32_t wait;
+
+  for(uint8_t wait_time=5; wait_time>0; wait_time--){
+    is_return = false;
+    return_value = 0;
+    uint16_t crc = request(CMD_IS_READY, 0, 1, 0);
+    request(crc);
+    wait = millis();
+    while(is_return == false && (millis() - wait < 1000)) {
+      process();
+    }
+    if(is_return && return_value)
+      return true;
+  }
+  return false;
+  
+}
+boolean ESP::waitReturn(uint32_t timeout)
+{
+  is_return = false;
+  return_value = 0;
+  return_cmd = 0;
+  uint32_t wait = millis();
+  while(is_return == false && (millis() - wait < timeout)) {
+    process();
+  }
+  return is_return;
+}
+boolean ESP::waitReturn()
+{
+  return waitReturn(ESP_TIMEOUT);
+}
+void ESP::process()
+{
+  char value;
+  while(_serial->available()) {
+    value = _serial->read();
+    switch(value){
+    case 0x7D:
+      _proto.isEsc = 1;
+      break;
+    
+    case 0x7E:
+      _proto.dataLen = 0;
+      _proto.isEsc = 0;
+      _proto.isBegin = 1;
+      break;
+    
+    case 0x7F:
+      protoCompletedCb();
+      _proto.isBegin = 0;
+      break;
+    
+    default:
+      if(_proto.isBegin == 0) {
+        if(_debugEn) {
+            _debug->write(value);
+        }
+        break;
+      }
+      if(_proto.isEsc){
+        value ^= 0x20;
+        _proto.isEsc = 0;
+      }
+        
+      if(_proto.dataLen < _proto.bufSize)
+        _proto.buf[_proto.dataLen++] = value;
+        
+      break;
+    }
+  }
+}
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.h	(revision 175)
@@ -0,0 +1,130 @@
+/**
+ * \file
+ *       ESP8266 bridge arduino library 
+ * \author
+ *       Tuan PM <tuanpm@live.com>
+ */
+#ifndef _ARDUINO_WIFI_H_
+#define _ARDUINO_WIFI_H_
+#include <stdint.h>
+//#include <HardwareSerial.h>
+#include <Arduino.h>
+#include "FP.h"
+#include "crc16.h"
+#include "ringbuf.h"
+
+#define ESP_TIMEOUT 2000
+
+#define SLIP_START 0x7E
+#define SLIP_END  0x7F
+#define SLIP_REPL 0x7D
+#define SLIP_ESC(x) (x ^ 0x20)
+
+typedef enum
+{
+  CMD_NULL = 0,
+  CMD_RESET,
+  CMD_IS_READY,
+  CMD_WIFI_CONNECT,
+  CMD_MQTT_SETUP,
+  CMD_MQTT_CONNECT,
+  CMD_MQTT_DISCONNECT,
+  CMD_MQTT_PUBLISH, 
+  CMD_MQTT_SUBSCRIBE,
+  CMD_MQTT_LWT,
+  CMD_MQTT_EVENTS,
+  CMD_REST_SETUP,
+  CMD_REST_REQUEST,
+  CMD_REST_SETHEADER,
+  CMD_REST_EVENTS
+}CMD_NAME;
+
+enum WIFI_STATUS{
+  STATION_IDLE = 0,
+  STATION_CONNECTING,
+  STATION_WRONG_PASSWORD,
+  STATION_NO_AP_FOUND,
+  STATION_CONNECT_FAIL,
+  STATION_GOT_IP
+};
+
+typedef struct{
+  uint8_t *buf;
+  uint16_t bufSize;
+  uint16_t dataLen;
+  uint8_t isEsc;
+  uint8_t isBegin;
+}PROTO;
+
+typedef struct __attribute((__packed__)) {
+  uint16_t len;
+  uint8_t data;
+} ARGS;
+
+typedef struct __attribute((__packed__)) {
+  uint16_t cmd;
+  uint32_t callback;
+  uint32_t _return;
+  uint16_t argc;
+  ARGS args;
+}PACKET_CMD;
+
+class ESP;
+class RESPONSE;
+class MQTT;
+
+class RESPONSE {
+private:
+  uint16_t arg_num;
+  uint8_t *arg_ptr;
+  PACKET_CMD* cmd;
+public:
+  RESPONSE(void *response);
+  uint16_t getArgc();
+  int32_t popArgs(uint8_t *data, uint16_t maxLen);
+  uint16_t argLen();
+  String popString();
+  void popString(String* data);
+};
+
+
+class ESP
+{
+public:
+  ESP(Stream *serial, Stream* debug, int chip_pd);
+  ESP(Stream *serial, int chip_pd);
+  Stream *_debug;
+
+  FP<void, void*> wifiCb;
+  uint32_t return_value;
+  uint16_t return_cmd;
+  boolean is_return;
+
+  void wifiConnect(const char* ssid, const char* password);
+  void process();
+  uint16_t request(uint16_t cmd, uint32_t callback, uint32_t _return, uint16_t argc);
+  uint16_t request(uint16_t crc_in, uint8_t* data, uint16_t len);
+  uint16_t request(uint16_t crc);
+  void reset();
+  boolean ready();
+  void enable();
+  void disable();
+  boolean waitReturn(uint32_t timeout);
+  boolean waitReturn();
+
+private:
+  Stream *_serial;
+  
+  boolean _debugEn;
+  PROTO _proto;
+  uint8_t _protoBuf[512];
+  int _chip_pd;
+  
+
+  void init();
+  void INFO(String info);
+  void protoCompletedCb(void);
+  void write(uint8_t data);
+  void write(uint8_t* data, uint16_t len);
+};
+#endif
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/rest.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/rest.cpp	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/rest.cpp	(revision 175)
@@ -0,0 +1,138 @@
+/**
+ * \file
+ *       ESP8266 RESTful Bridge
+ * \author
+ *       Tuan PM <tuanpm@live.com>
+ */
+#include "rest.h"
+REST::REST(ESP *e)
+{
+  esp = e;
+  remote_instance = 0;
+  timeout = DEFAULT_REST_TIMEOUT;
+}
+void REST::restCallback(void *resp)
+{
+  response = true;
+  res = resp;
+}
+
+boolean REST::begin(const char* host, uint16_t port, boolean security)
+{
+  uint8_t sec = 0;
+  if(security)
+    sec = 1;
+  restCb.attach(this, &REST::restCallback);
+  
+  uint16_t crc = esp->request(CMD_REST_SETUP, (uint32_t)&restCb, 1, 3);
+  crc = esp->request(crc,(uint8_t*)host, strlen(host));
+  crc = esp->request(crc,(uint8_t*)&port, 2);
+  crc = esp->request(crc,(uint8_t*)&sec, 1);
+  esp->request(crc);
+
+  if(esp->waitReturn(timeout) && esp->return_value != 0){
+    remote_instance = esp->return_value;
+    return true;
+  }
+  return false;
+}
+
+boolean REST::begin(const char* host)
+{
+  return begin(host, 80, false);
+}
+void REST::request(const char* path, const char* method, const char* data, int len)
+{
+  if(remote_instance == 0)
+    return;
+  uint16_t crc;
+  if(len > 0)
+    crc = esp->request(CMD_REST_REQUEST, 0, 0, 5);
+  else
+    crc = esp->request(CMD_REST_REQUEST, 0, 0, 3);
+  crc = esp->request(crc,(uint8_t*)&remote_instance, 4);
+  crc = esp->request(crc,(uint8_t*)method, strlen(method));
+  crc = esp->request(crc,(uint8_t*)path, strlen(path));
+  if(len > 0){
+    crc = esp->request(crc,(uint8_t*)&len, 2);
+    crc = esp->request(crc,(uint8_t*)data, len);
+  }
+    
+  esp->request(crc);
+}
+void REST::request(const char* path, const char* method, const char* data)
+{
+  request(path, method, data, strlen(data));
+}
+void REST::get(const char* path, const char* data)
+{
+  request(path, "GET", data);
+}
+void REST::get(const char* path)
+{
+  request(path, "GET", 0, 0);
+}
+void REST::post(const char* path, const char* data)
+{
+  request(path, "POST", data);
+}
+void REST::put(const char* path, const char* data)
+{
+  request(path, "PUT", data);
+}
+void REST::del(const char* path, const char* data)
+{
+  request(path, "DELETE", data);
+}
+
+/*
+void REST::setHeader(const char* value)
+{
+  uint8_t header_index = HEADER_GENERIC;
+  uint16_t crc = esp->request(CMD_REST_SETHEADER, 0, 0, 3);
+  crc = esp->request(crc,(uint8_t*)&remote_instance, 4);
+  crc = esp->request(crc,(uint8_t*)&header_index, 1);
+  crc = esp->request(crc,(uint8_t*)value, strlen(value));
+  esp->request(crc);
+}
+void REST::setContentType(const char* value)
+{
+  uint8_t header_index = HEADER_CONTENT_TYPE;
+  uint16_t crc = esp->request(CMD_REST_SETHEADER, 0, 0, 3);
+  crc = esp->request(crc,(uint8_t*)&remote_instance, 4);
+  crc = esp->request(crc,(uint8_t*)&header_index, 1);
+  crc = esp->request(crc,(uint8_t*)value, strlen(value));
+  esp->request(crc);
+}
+void REST::setUserAgent(const char* value)
+{
+  uint8_t header_index = HEADER_USER_AGENT;
+  uint16_t crc = esp->request(CMD_REST_SETHEADER, 0, 0, 3);
+  crc = esp->request(crc,(uint8_t*)&remote_instance, 4);
+  crc = esp->request(crc,(uint8_t*)&header_index, 1);
+  crc = esp->request(crc,(uint8_t*)value, strlen(value));
+  esp->request(crc);
+}
+void REST::setTimeout(uint32_t ms)
+{
+  timeout = ms;
+}
+*/
+
+uint16_t REST::getResponse(char* data, uint16_t maxLen)
+{
+  response = false;
+  uint32_t wait = millis();
+  while(response == false && (millis() - wait < timeout)) {
+    esp->process();
+  }
+  if(response){
+    RESPONSE resp(res);
+
+    resp.popArgs((uint8_t*)data, maxLen);
+    return esp->return_value;
+  }
+    
+  
+  return 0;
+}
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/rest.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/rest.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/rest.h	(revision 175)
@@ -0,0 +1,57 @@
+/**
+ * \file
+ *       ESP8266 RESTful Bridge
+ * \author
+ *       Tuan PM <tuanpm@live.com>
+ */
+#ifndef _REST_H_
+#define _REST_H_
+
+#include <stdint.h>
+#include <Arduino.h>
+#include "FP.h"
+#include "espduino.h"
+
+#define DEFAULT_REST_TIMEOUT  7000
+
+typedef enum {
+  HEADER_GENERIC = 0,
+  HEADER_CONTENT_TYPE,
+  HEADER_USER_AGENT
+} HEADER_TYPE;
+
+typedef enum {
+  HTTP_STATUS_OK = 200
+} HTTP_STATUS;
+
+class REST {
+private:
+  uint32_t remote_instance, timeout;
+  ESP *esp;
+  void restCallback(void* resp);
+  FP<void, void*> restCb;
+  boolean response;
+  void *res;
+
+public:
+  
+  REST(ESP *e);
+  boolean begin(const char* host, uint16_t port, boolean security);
+  boolean begin(const char* host);
+  void request(const char* path, const char* method, const char* data);
+  void request(const char* path, const char* method, const char* data, int len);
+  void get(const char* path, const char* data);
+  void get(const char* path);
+  void post(const char* path, const char* data);
+  void put(const char* path, const char* data);
+  void del(const char* path, const char* data);
+
+ // void setTimeout(uint32_t ms);
+  uint16_t getResponse(char* data, uint16_t maxLen);
+ // void setUserAgent(const char* value);
+ // Set Content-Type Header
+ // void setContentType(const char* value);
+ // void setHeader(const char* value);
+
+};
+#endif
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/ringbuf.c
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/ringbuf.c	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/ringbuf.c	(revision 175)
@@ -0,0 +1,67 @@
+/**
+* \file
+*		Ring Buffer library
+*/
+
+#include "ringbuf.h"
+
+
+/**
+* \brief init a RINGBUF object
+* \param r pointer to a RINGBUF object
+* \param buf pointer to a byte array
+* \param size size of buf
+* \return 0 if successfull, otherwise failed
+*/
+int16_t RINGBUF_Init(RINGBUF *r, uint8_t* buf, int32_t size)
+{
+	if(r == NULL || buf == NULL || size < 2) return -1;
+	
+	r->p_o = r->p_r = r->p_w = buf;
+	r->fill_cnt = 0;
+	r->size = size;
+	
+	return 0;
+}
+/**
+* \brief put a character into ring buffer
+* \param r pointer to a ringbuf object
+* \param c character to be put
+* \return 0 if successfull, otherwise failed
+*/
+int16_t RINGBUF_Put(RINGBUF *r, uint8_t c)
+{
+	if(r->fill_cnt>=r->size)return -1;		// ring buffer is full, this should be atomic operation
+	
+
+	r->fill_cnt++;							// increase filled slots count, this should be atomic operation
+
+	
+	*r->p_w++ = c;							// put character into buffer
+	
+	if(r->p_w >= r->p_o + r->size)			// rollback if write pointer go pass
+		r->p_w = r->p_o;					// the physical boundary
+	
+	return 0;
+}
+/**
+* \brief get a character from ring buffer
+* \param r pointer to a ringbuf object
+* \param c read character
+* \return 0 if successfull, otherwise failed
+*/
+int16_t RINGBUF_Get(RINGBUF *r, uint8_t* c)
+{
+	if(r->fill_cnt<=0)return -1;				// ring buffer is empty, this should be atomic operation
+	
+
+	r->fill_cnt--;								// decrease filled slots count
+
+	
+	*c = *r->p_r++;								// get the character out
+	
+	if(r->p_r >= r->p_o + r->size)				// rollback if write pointer go pass
+		r->p_r = r->p_o;						// the physical boundary
+	
+	return 0;
+}
Index: rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/ringbuf.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/ringbuf.h	(revision 175)
+++ rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/ringbuf.h	(revision 175)
@@ -0,0 +1,25 @@
+#ifndef _RING_BUF_H_
+#define _RING_BUF_H_
+
+#include <stdint.h>
+#include <stdlib.h>
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+typedef struct{
+	uint8_t* p_o;				/**< Original pointer */
+	uint8_t* volatile p_r;		/**< Read pointer */
+	uint8_t* volatile p_w;		/**< Write pointer */
+	volatile int32_t fill_cnt;	/**< Number of filled slots */
+	int32_t size;				/**< Buffer size */
+}RINGBUF;
+
+int16_t RINGBUF_Init(RINGBUF *r, uint8_t* buf, int32_t size);
+int16_t RINGBUF_Put(RINGBUF *r, uint8_t c);
+int16_t RINGBUF_Get(RINGBUF *r, uint8_t* c);
+
+#ifdef	__cplusplus
+}
+#endif
+#endif
