1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Bugfix and fix compilation erro with new-extensions branch

This commit is contained in:
mlafauci 2011-05-18 08:39:47 +02:00
parent 8d1761f009
commit 4f7e2f1201
12 changed files with 144 additions and 29 deletions

View File

@ -3,6 +3,7 @@ extern "C" {
#include "utility/wl_types.h" #include "utility/wl_types.h"
#include "socket.h" #include "socket.h"
#include "string.h" #include "string.h"
#include "utility/debug.h"
} }
#include "WProgram.h" #include "WProgram.h"
@ -35,25 +36,28 @@ uint8_t Client::connect() {
void Client::write(uint8_t b) { void Client::write(uint8_t b) {
if (_sock != 255) if (_sock != 255)
{ {
while (!ServerDrv::isDataSent(_sock)); START();
ServerDrv::sendData(_sock, &b, 1); ServerDrv::sendData(_sock, &b, 1);
while (!ServerDrv::isDataSent(_sock));
END();
} }
} }
void Client::write(const char *str) { void Client::write(const char *str) {
if (_sock != 255) if (_sock != 255)
{ {
while (!ServerDrv::isDataSent(_sock));
unsigned int len = strlen(str); unsigned int len = strlen(str);
ServerDrv::sendData(_sock, (const uint8_t *)str, len); ServerDrv::sendData(_sock, (const uint8_t *)str, len);
while (!ServerDrv::isDataSent(_sock));
} }
} }
void Client::write(const uint8_t *buf, size_t size) { void Client::write(const uint8_t *buf, size_t size) {
if (_sock != 255) if (_sock != 255)
{ {
while (!ServerDrv::isDataSent(_sock));
ServerDrv::sendData(_sock, buf, size); ServerDrv::sendData(_sock, buf, size);
while (!ServerDrv::isDataSent(_sock));
} }
} }

View File

@ -66,10 +66,7 @@ void Server::write(const uint8_t *buffer, size_t size)
client.status() == ESTABLISHED) client.status() == ESTABLISHED)
{ {
client.write(buffer, size); client.write(buffer, size);
}else{ }
delay(20);
}
} }
} }
} }

View File

@ -191,5 +191,11 @@ uint8_t WiFiClass::status()
return WiFiDrv::getConnectionStatus(); return WiFiDrv::getConnectionStatus();
} }
uint8_t WiFiClass::test()
{
return WiFiDrv::testCmd();
}
WiFiClass WiFi; WiFiClass WiFi;

View File

@ -86,6 +86,9 @@ public:
// Return Connection status // Return Connection status
uint8_t status(); uint8_t status();
// function used for test
uint8_t test();
friend class Client; friend class Client;
friend class Server; friend class Server;
}; };

View File

@ -10,6 +10,7 @@
*/ */
#include <WiFi.h> #include <WiFi.h>
#include <IPAddress.h> #include <IPAddress.h>
#define _PRINT_
byte mac[6] = { 0 }; byte mac[6] = { 0 };
IPAddress ip; IPAddress ip;
@ -103,11 +104,13 @@ int startWiFiWpa()
{ {
Serial.println("\nSetup WiFi Wpa..."); Serial.println("\nSetup WiFi Wpa...");
//strcpy(ssid, "AndroidAP9647"); //strcpy(ssid, "AndroidAP9647");
//strcpy(ssid, "AndroidAP3551");
strcpy(ssid, "Cariddi"); strcpy(ssid, "Cariddi");
Serial.print("SSID: "); Serial.print("SSID: ");
Serial.println(ssid); Serial.println(ssid);
const char *pass = "1234567890"; const char *pass = "1234567890";
status = WiFi.begin(ssid, pass); status = WiFi.begin(ssid, pass);
//status = WiFi.begin(ssid);
if ( status != WL_CONNECTED) if ( status != WL_CONNECTED)
{ {
Serial.println("Connection Failed"); Serial.println("Connection Failed");
@ -146,9 +149,12 @@ void setup()
void execCmd(char* buf) void execCmd(char* buf)
{ {
#ifdef _PRINT_
Serial.print("\nExecuting command: "); Serial.print("\nExecuting command: ");
Serial.println(buf); Serial.println(buf);
server.write(buf); #endif
//server.write(buf);
server.print(buf);
} }
@ -166,12 +172,18 @@ void loop()
} }
static byte idx = 0; static byte idx = 0;
int c = 0;
while (client.available()) do
{ {
dataBuf[idx] = client.read(); c = client.read();
if (c!=-1)
{
dataBuf[idx] = c;
#ifdef _PRINT_
if (idx == 0) Serial.print("Client chatting...: "); if (idx == 0) Serial.print("Client chatting...: ");
Serial.print(dataBuf[idx]); Serial.print(dataBuf[idx]);
#endif
if ((dataBuf[idx] == 0xa)/*||(dataBuf[idx] == 0xd)*/) if ((dataBuf[idx] == 0xa)/*||(dataBuf[idx] == 0xd)*/)
{ {
dataBuf[idx+1]=0; dataBuf[idx+1]=0;
@ -182,6 +194,7 @@ void loop()
++idx; ++idx;
} }
} }
}while (c!=-1);
} }
} }
} }

View File

@ -114,12 +114,12 @@ void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
Serial.println("*** Start WiFi example ***"); Serial.println("*** Start WiFi example ***");
WiFi.begin();
//scanNetworks(); //scanNetworks();
delay(3000); delay(3000);
int _status = startWiFi(); //int _status = startWiFi();
/*
if ( _status == WL_CONNECTED) if ( _status == WL_CONNECTED)
{ {
Serial.println("Wifi Connected!"); Serial.println("Wifi Connected!");
@ -129,17 +129,53 @@ void setup()
printCurrNet(); printCurrNet();
scanNetworks(); scanNetworks();
/*
Serial.println("Starting server..."); Serial.println("Starting server...");
server.begin(); server.begin();
delay(1000); delay(1000);
*/
} }
*/
} }
void loop() void loop()
{ {
static boolean free = false;
// if (free) Serial.println(WiFi.test(),10);
if (free) WiFi.test();
byte c = Serial.read();
if (c!=255)
{
switch (c)
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
{
int i = 0;
for (;i<(c-0x30);++i)
{
int num = WiFi.test();
//Serial.println(num,10);
}
break;
}
case 'c':
free = true;
break;
case 's':
free = false;
break;
}
}
/* /*
Client client = server.available();
static uint8_t count = 0; static uint8_t count = 0;
Serial.println("Retry connect..."); Serial.println("Retry connect...");
status = WiFi.begin(ssid); status = WiFi.begin(ssid);

View File

@ -13,8 +13,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "HardwareSerial.h"
#define INFO_0 1 #define INFO_0 1
#define INFO_1 2 #define INFO_1 2
#define INFO_2 4 #define INFO_2 4

View File

@ -13,6 +13,7 @@ extern "C" {
#define SLAVESELECT 2//ss #define SLAVESELECT 2//ss
#define SLAVEREADY 3 #define SLAVEREADY 3
#define DELAY_100NS asm volatile("nop")
void SpiDrv::begin() void SpiDrv::begin()
{ {
@ -60,6 +61,16 @@ void SpiDrv::spiSlaveDeselect()
digitalWrite(SLAVESELECT,HIGH); digitalWrite(SLAVESELECT,HIGH);
} }
void delaySpi()
{
int i = 0;
const int DELAY = 1000;
for (;i<DELAY;++i)
{
int a =a+1;
}
}
char SpiDrv::spiTransfer(volatile char data) char SpiDrv::spiTransfer(volatile char data)
{ {
SPDR = data; // Start the transmission SPDR = data; // Start the transmission
@ -67,7 +78,9 @@ char SpiDrv::spiTransfer(volatile char data)
{ {
}; };
char result = SPDR; char result = SPDR;
delayMicroseconds(SPI_TX_DELAY); DELAY_100NS;
DELAY_100NS;
//delayMicroseconds(SPI_TX_DELAY);
return result; // return the received byte return result; // return the received byte
} }
@ -104,14 +117,18 @@ int SpiDrv::waitSpiChar(unsigned char waitChar)
int SpiDrv::readAndCheckChar(char checkChar, char* readChar) int SpiDrv::readAndCheckChar(char checkChar, char* readChar)
{ {
*readChar = spiTransfer(DUMMY_DATA); //get data byte //*readChar = spiTransfer(DUMMY_DATA); //get data byte
getParam((uint8_t*)readChar);
return (*readChar == checkChar); return (*readChar == checkChar);
} }
char SpiDrv::readChar() char SpiDrv::readChar()
{ {
return spiTransfer(DUMMY_DATA); //get data byte uint8_t readChar = 0;
getParam(&readChar);
return readChar;
//return spiTransfer(DUMMY_DATA); //get data byte
} }
//#define WAIT_START_CMD(x) waitSpiChar(START_CMD, &x) //#define WAIT_START_CMD(x) waitSpiChar(START_CMD, &x)
@ -130,18 +147,37 @@ char SpiDrv::readChar()
#define CHECK_DATA(check, x) \ #define CHECK_DATA(check, x) \
if (!readAndCheckChar(check, &x)) \ if (!readAndCheckChar(check, &x)) \
{ \ { \
TOGGLE_TRIGGER() \
WARN("Reply error"); \ WARN("Reply error"); \
INFO2(check, (uint8_t)x); \ INFO2(check, (uint8_t)x); \
return 0; \ return 0; \
}else \ }else \
#define waitSlaveReady() (digitalRead(SLAVEREADY) == LOW) #define waitSlaveReady() (digitalRead(SLAVEREADY) == LOW)
#define waitSlaveSign() (digitalRead(SLAVEREADY) == HIGH)
#define waitSlaveSignalH() while(digitalRead(SLAVEREADY) != HIGH){}
#define waitSlaveSignalL() while(digitalRead(SLAVEREADY) != LOW){}
void SpiDrv::waitForSlaveSign()
{
while (!waitSlaveSign());
}
void SpiDrv::waitForSlaveReady() void SpiDrv::waitForSlaveReady()
{ {
while (!waitSlaveReady()); while (!waitSlaveReady());
} }
void SpiDrv::getParam(uint8_t* param)
{
// Get Params data
*param = spiTransfer(DUMMY_DATA);
DELAY_100NS;
DELAY_100NS;
DELAY_100NS;
DELAY_100NS;
}
int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len) int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len)
{ {
char _data = 0; char _data = 0;
@ -157,7 +193,8 @@ int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8
for (ii=0; ii<(*param_len); ++ii) for (ii=0; ii<(*param_len); ++ii)
{ {
// Get Params data // Get Params data
param[ii] = spiTransfer(DUMMY_DATA); //param[ii] = spiTransfer(DUMMY_DATA);
getParam(&param[ii]);
} }
} }
@ -470,6 +507,7 @@ void SpiDrv::sendCmd(uint8_t cmd, uint8_t numParam)
// Send Spi START CMD // Send Spi START CMD
spiTransfer(START_CMD); spiTransfer(START_CMD);
//waitForSlaveSign();
//wait the interrupt trigger on slave //wait the interrupt trigger on slave
delayMicroseconds(SPI_START_CMD_DELAY); delayMicroseconds(SPI_START_CMD_DELAY);

View File

@ -4,13 +4,8 @@
#include <inttypes.h> #include <inttypes.h>
#include "wifi_spi.h" #include "wifi_spi.h"
#define WAIT_CHAR_DELAY 100
#define TIMEOUT_CHAR_DELAY 1 //10
#define TIMEOUT_READY_SLAVE 1000
#define SPI_TX_DELAY 1
#define SPI_START_CMD_DELAY 10 #define SPI_START_CMD_DELAY 10
#define NO_LAST_PARAM 0 #define NO_LAST_PARAM 0
#define LAST_PARAM 1 #define LAST_PARAM 1
@ -25,7 +20,9 @@
class SpiDrv class SpiDrv
{ {
private: private:
static bool waitSlaveReady(); //static bool waitSlaveReady();
static void waitForSlaveSign();
static void getParam(uint8_t* param);
public: public:
static void begin(); static void begin();

View File

@ -351,4 +351,25 @@ int32_t WiFiDrv::getRSSINetoworks(uint8_t networkItem)
return networkRssi; return networkRssi;
} }
uint8_t WiFiDrv::testCmd()
{
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(TEST_CMD, PARAM_NUMS_0);
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
// Wait for reply
uint8_t _data = 0;
uint8_t _dataLen = 0;
SpiDrv::waitResponseCmd(TEST_CMD, PARAM_NUMS_1, &_data, &_dataLen);
SpiDrv::spiSlaveDeselect();
return _data;
}
WiFiDrv wiFiDrv; WiFiDrv wiFiDrv;

View File

@ -62,6 +62,7 @@ public:
static uint8_t getEncTypeNetowrks(uint8_t networkItem); static uint8_t getEncTypeNetowrks(uint8_t networkItem);
static uint8_t testCmd();
}; };
extern WiFiDrv wiFiDrv; extern WiFiDrv wiFiDrv;

View File

@ -23,6 +23,7 @@ enum {
SET_NET_CMD = 0x10, SET_NET_CMD = 0x10,
SET_PASSPHRASE_CMD = 0x11, SET_PASSPHRASE_CMD = 0x11,
SET_KEY_CMD = 0x12, SET_KEY_CMD = 0x12,
TEST_CMD = 0x13,
GET_CONN_STATUS_CMD = 0x20, GET_CONN_STATUS_CMD = 0x20,
GET_IPADDR_CMD = 0x21, GET_IPADDR_CMD = 0x21,