diff --git a/binary/wifiHD.elf b/binary/wifiHD.elf
index 8d45aee4b..c9375daf4 100644
Binary files a/binary/wifiHD.elf and b/binary/wifiHD.elf differ
diff --git a/wifiHD/.cproject b/wifiHD/.cproject
index faf616847..dd675e8b3 100644
--- a/wifiHD/.cproject
+++ b/wifiHD/.cproject
@@ -56,7 +56,7 @@
+
+
+
+
+
+
@@ -113,6 +118,8 @@
+
+
@@ -187,7 +194,7 @@
-
+
@@ -1101,6 +1108,7 @@
+
@@ -1191,7 +1199,7 @@
-
+
diff --git a/wifiHD/.project b/wifiHD/.project
index 692a28f9b..74f16db04 100644
--- a/wifiHD/.project
+++ b/wifiHD/.project
@@ -27,7 +27,7 @@
org.eclipse.cdt.make.core.buildLocation
- ${workspace_loc:/wifiHD/Release}
+ ${workspace_loc:/wifiHD/Debug}
org.eclipse.cdt.make.core.contents
@@ -60,6 +60,11 @@
+
+ com.atmel.avr32.managedbuilder.ui.extras.ListingBuilder
+
+
+
com.atmel.avr32.core.nature
@@ -76,7 +81,7 @@
include
2
- /usr/avr32/include
+ C:/usr/avr32/include
diff --git a/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h b/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h
index fbdd466ef..4d3f1c354 100644
--- a/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h
+++ b/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h
@@ -84,7 +84,7 @@
//! Number of LEDs.
-#define LED_COUNT 3
+#define LED_COUNT 0
/*! \name GPIO Connections of LEDs
*/
@@ -114,8 +114,8 @@
*/
//! @{
#define LED_MONO0_GREEN LED0
-#define LED_MONO1_GREEN LED1
-#define LED_MONO2_GREEN LED2
+#define LED_MONO1_RED LED1
+#define LED_MONO2_BLU LED2
//! @}
#if 0
diff --git a/wifiHD/src/ard_spi.c b/wifiHD/src/ard_spi.c
index 90e95ce4a..40b0d76b2 100644
--- a/wifiHD/src/ard_spi.c
+++ b/wifiHD/src/ard_spi.c
@@ -94,6 +94,7 @@ typedef struct sCmd_spi_list{
static tCmd_spi_list cmd_spi_list[MAX_CMD_NUM] = { {0} };
+#ifdef _SPI_STATS_
typedef struct sStatSpi
{
int timeoutIntErr;
@@ -145,6 +146,7 @@ cmd_resetStatSpi(int argc, char* argv[], void* ctx)
initStatSpi();
return CMD_DONE;
}
+#endif
#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
#define RETURN_ERR(e) return (e==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR;
@@ -201,10 +203,12 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
//SIGN1_DN();
if (spi_write(spi, *stream) == SPI_ERROR_TIMEOUT)
{
+#ifdef _SPI_STATS_
statSpi.timeoutErr++;
statSpi.txErr++;
statSpi.lastError = SPI_ERROR_TIMEOUT;
statSpi.status = spi_getStatus(spi);
+#endif
return SPI_ERROR_TIMEOUT;
}
else
@@ -238,8 +242,10 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
if (!streamExit)
{
+#ifdef _SPI_STATS_
statSpi.wrongFrame++;
statSpi.lastError = SPI_ERROR_ARGUMENT;
+#endif
return SPI_ERROR_ARGUMENT;
}
if ((ARD_SPI->sr & AVR32_SPI_SR_RDRF_MASK) != 0)
@@ -317,13 +323,13 @@ int set_net_cmd_cb(int numParam, char* buf, void* ctx) {
memcpy(ssid.ssid, ¶m->param, param->paramLen);
ssid.len = param->paramLen;
ssid.ssid[ssid.len] = 0;
- printk("SSID:%s\n", ssid.ssid);
+ INFO("SSID:%s\n", ssid.ssid);
//dump(ssid.ssid, ssid.len);
err = wl_cm_set_network(&ssid, NULL);
if (err != 1)
- printk("err=%d\n", err);
+ WARN("err=%d\n", err);
} else {
- printk("SSID len out of range");
+ WARN("SSID len out of range");
}
return err;
}
@@ -339,7 +345,7 @@ int set_key_cmd_cb(int numParam, char* buf, void* ctx) {
wl_err_t err = WL_SUCCESS;
tParam* params = (tParam*) buf;
- printk("%s params=%d\n", __FUNCTION__, numParam);
+ INFO("%s params=%d\n", __FUNCTION__, numParam);
// SSID
memset(&ssid, 0, sizeof ssid);
@@ -347,9 +353,9 @@ int set_key_cmd_cb(int numParam, char* buf, void* ctx) {
if (params->paramLen < WL_SSID_MAX_LENGTH) {
memcpy(ssid.ssid, ¶ms->param, params->paramLen);
ssid.len = params->paramLen;
- printk("%s\n", ssid.ssid);
+ INFO("%s\n", ssid.ssid);
} else {
- printk("SSID len out of range");
+ //printk("SSID len out of range");
RETURN_ERR(WL_FAILURE)
}
@@ -360,7 +366,7 @@ int set_key_cmd_cb(int numParam, char* buf, void* ctx) {
idx = (uint8_t)atoi(keyIdx);
// KEY IDX
if ((params->paramLen != 1)||(idx < 0)||(idx > 3)){
- printk("KEY IDX out of range %d\n", idx);
+ //printk("KEY IDX out of range %d\n", idx);
RETURN_ERR(WL_FAILURE)
}
@@ -371,7 +377,7 @@ int set_key_cmd_cb(int numParam, char* buf, void* ctx) {
// KEY
if (( len != 5)&&(len != 13))
{
- printk("KEY len out of range %d", len);
+ //printk("KEY len out of range %d", len);
RETURN_ERR(WL_FAILURE)
}
#ifdef _APP_DEBUG_
@@ -398,7 +404,7 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) {
wl_err_t err = WL_SUCCESS;
tParam* params = (tParam*) buf;
- printk("%s params=%d\n", __FUNCTION__, numParam);
+ INFO("%s params=%d\n", __FUNCTION__, numParam);
memset(&net, 0, sizeof net);
memset(net.bssid.octet, 0xFF, sizeof net.bssid.octet);
@@ -409,9 +415,9 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) {
if (params->paramLen < WL_SSID_MAX_LENGTH) {
memcpy(net.ssid.ssid, ¶ms->param, params->paramLen);
net.ssid.len = params->paramLen;
- printk("%s\n", net.ssid.ssid);
+ INFO("%s %d\n", net.ssid.ssid, net.ssid.len);
} else {
- printk("SSID len out of range");
+ //printk("SSID len out of range");
RETURN_ERR(WL_FAILURE)
}
params = (tParam*)((char*)buf+PARAM_LEN_SIZE+params->paramLen);
@@ -419,7 +425,7 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) {
strncpy(pass, (const char*)¶ms->param, params->paramLen);
pass[(uint8_t)params->paramLen]='\0';
- printk("Pass: %s %d\n", pass, params->paramLen);
+ INFO("Pass: %s %d\n", pass, params->paramLen);
if (wl_set_passphrase(&net,
pass,
@@ -427,14 +433,17 @@ int set_passphrase_cmd_cb(int numParam, char* buf, void* ctx) {
ENC_TYPE_AUTO,
AUTH_MODE_AUTO)
!= WL_SUCCESS) {
- printk("%s : Failed to add passphrase\n", __func__);
+ WARN("%s : Failed to add passphrase\n", __func__);
RETURN_ERR(WL_FAILURE)
}
+ printk("Connect to network...");
//Connect
err = wl_cm_set_network(&net.ssid, NULL);
if (err != 1)
printk("err=%d\n", err);
+ else
+ printk("OK\n");
RETURN_ERR(err)
}
@@ -451,6 +460,7 @@ void set_result_cmd(int err)
{
case WL_SUCCESS:
set_result(WL_CONNECTED);
+ ERROR_LED_OFF();
break;
default:
case WL_OOM:
@@ -462,6 +472,7 @@ void set_result_cmd(int err)
case WL_RETRY:
case WL_FAILURE:
set_result(WL_CONNECT_FAILED);
+ ERROR_LED_ON();
break;
}
printk("%s %d\n", __FUNCTION__, result);
@@ -495,12 +506,12 @@ int start_server_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
if (sock >= MAX_SOCK_NUM)
return WIFI_SPI_ERR;
- printk("Start Server [%d, %d]\n", port, sock);
+ INFO("Start Server [%d, %d]\n", port, sock);
if (ard_tcp_start(addr, port, NULL, NULL, mode, nbuf, buflen, udp, verbose, sock, &_ttcp) == 0)
{
if (sock < MAX_SOCK_NUM)
mapSockTCP[sock]=_ttcp;
- printk("Map [%d, %p]\n", sock, _ttcp);
+ INFO("Map [%d, %p]\n", sock, _ttcp);
err = WL_SUCCESS;
}
}
@@ -533,22 +544,43 @@ int start_client_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
if (sock >= MAX_SOCK_NUM)
return WIFI_SPI_ERR;
- printk("Start Client [0x%x, %d, %d]\n", addr, port, sock);
+ INFO("Start Client [0x%x, %d, %d]\n", addr, port, sock);
if (ard_tcp_start((struct ip_addr)addr, port, NULL, NULL, mode, nbuf, buflen, udp, verbose, sock, &_ttcp) == 0)
{
if (sock < MAX_SOCK_NUM)
mapSockTCP[sock]=_ttcp;
- printk("Map [%d, %p]\n", sock, _ttcp);
+ INFO("Map [%d, %p]\n", sock, _ttcp);
err = WL_SUCCESS;
}
}
return (err==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR;
}
+int stop_client_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
+ wl_err_t err = WL_FAILURE;
+ tParam* params = (tParam*) buf;
+ void* _ttcp = NULL;
+
+ if (numParam == 1)
+ {
+ GET_PARAM_NEXT(BYTE, params, sock);
+
+ INFO("Stop client sock:%d\n", sock);
+
+ if (sock < MAX_SOCK_NUM)
+ {
+ _ttcp = mapSockTCP[sock];
+ ard_tcp_stop(_ttcp);
+ mapSockTCP[sock]=0;
+ err = WL_SUCCESS;
+ }
+ }
+ return (err==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR;
+}
int send_data_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
wl_err_t err = WL_FAILURE;
- SIGN1_DN();
+ DATA_LED_ON();
tDataParam* msg = (tDataParam*) buf;
if ((numParam == 2)&&(msg->dataLen == 1))
{
@@ -556,7 +588,7 @@ int send_data_tcp_cmd_cb(int numParam, char* buf, void* ctx) {
GET_DATA_INT(len, buf+3);
err = sendTcpData(getTTCP(sock), (uint8_t*)(buf+5), len);
}
- SIGN1_UP();
+ DATA_LED_OFF();
return (err==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR;
}
@@ -757,7 +789,7 @@ cmd_spi_state_t get_state_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_
uint8_t _state = CLOSED;
if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]=0)&&(recv[4]rdr >> AVR32_SPI_RDR_RD_OFFSET) & 0x00ff;
- if (_receiveBuffer[index] == START_CMD)
+ if (_receiveBuffer[index] == START_CMD){
TOGGLE_SIG0();
//SIGN1_UP();
-
+ }
if (err == SPI_OK) {
++index;
++receivedChars;
}else{
+#ifdef _SPI_STATS_
STATSPI_TIMEOUT_ERROR();
+#endif
break;
}
@@ -1230,9 +1285,11 @@ static void spi_int_handler(void)
int err = spi_slaveReceiveInt(ARD_SPI, dummy==START_CMD);
if (err != SPI_OK)
{
+#ifdef _SPI_STATS_
//TODO verify why at the end of cmd cycle RDF bit is high without any data recv.
if (statSpi.lastError != SPI_ERROR_TIMEOUT)
INFO("[E(0x%x):%d spiStatus:%d]\n", statSpi.lastError, err, statSpi.status);
+#endif
}else{
BUSY_FOR_SPI();
startReply=true;
@@ -1356,9 +1413,9 @@ int initSpi()
ENABLE_SPI_INT();
spi_enable(spi);
-
+#ifdef _SPI_STATS_
initStatSpi();
-
+#endif
init_spi_cmds();
return 0;
diff --git a/wifiHD/src/ard_tcp.c b/wifiHD/src/ard_tcp.c
index b0e3d53f7..47dfbb7e6 100644
--- a/wifiHD/src/ard_tcp.c
+++ b/wifiHD/src/ard_tcp.c
@@ -5,7 +5,7 @@
* Author: mlf by Metodo2 srl
*/
-#undef _APP_DEBUG_
+#define _APP_DEBUG_
#include "lwip/opt.h"
#include "lwip/mem.h"
@@ -93,18 +93,23 @@ ard_tcp_print_stats(struct ttcp *ttcp)
static void
ard_tcp_destroy(struct ttcp* ttcp)
{
+ err_t err = ERR_OK;
if (ttcp->tpcb) {
tcp_arg(ttcp->tpcb, NULL);
tcp_sent(ttcp->tpcb, NULL);
tcp_recv(ttcp->tpcb, NULL);
tcp_err(ttcp->tpcb, NULL);
- tcp_close(ttcp->tpcb);
+ err = tcp_close(ttcp->tpcb);
+ printk("Closing tpcb: state:0x%x err:%d\n",
+ ttcp->tpcb->state, err);
}
if (ttcp->lpcb) {
tcp_arg(ttcp->lpcb, NULL);
tcp_accept(ttcp->lpcb, NULL);
tcp_close(ttcp->lpcb);
+ printk("Closing lpcb: state:0x%x err:%d\n",
+ ttcp->lpcb->state, err);
}
if (ttcp->upcb) {
@@ -281,7 +286,7 @@ atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
ard_tcp_done(ttcp, 0);
return ERR_OK;
}
-
+ DATA_LED_ON();
/* for print_stats() */
ttcp->recved += p->tot_len;
@@ -294,6 +299,7 @@ atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
insert_pBuf(p, ttcp->sock, (void*)pcb);
pbuf_free(p);
tcp_recved(pcb, p->tot_len);
+ DATA_LED_OFF();
return ERR_OK;
}
@@ -303,6 +309,13 @@ void ack_recved(void* pcb, int len)
//tcp_recved(pcb, len);
}
+static err_t
+atcp_poll(void *arg, struct tcp_pcb *pcb)
+{
+ return ERR_OK;
+}
+
+
/**
* Only used in TCP mode.
*/
@@ -314,9 +327,10 @@ atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err)
ttcp->tpcb = newpcb;
tcp_recv(ttcp->tpcb, atcp_recv_cb);
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
+ tcp_poll(ttcp->tpcb, atcp_poll, 4);
printk("ARD TCP [%p]: accept new [%p]\n", ttcp, newpcb);
- printk("local:%d remote:%d state:%d\n", newpcb->local_port, newpcb->remote_port, newpcb->state);
+ INFO("local:%d remote:%d state:%d\n", newpcb->local_port, newpcb->remote_port, newpcb->state);
ttcp->start_time = timer_get_ms();
return ERR_OK;
}
@@ -360,8 +374,9 @@ atcp_start(struct ttcp* ttcp)
printk("TTCP [%p]: listen failed\n", ttcp);
return -1;
}
-
- printk("local:%d remote:%d state:%d\n", ttcp->lpcb->local_port, ttcp->lpcb->state);
+ printk("ttcp:%p lpcb:%p pcb:%p\n", ttcp, ttcp->lpcb, ttcp->tpcb);
+ printk("local:%d remote:%d state:%d\n", ttcp->lpcb->local_port,
+ ttcp->lpcb->remote_port, ttcp->lpcb->state);
tcp_accept(ttcp->lpcb, atcp_accept_cb);
}
@@ -557,18 +572,20 @@ ard_tcp_start(struct ip_addr addr, uint16_t port, void *opaque,
ttcp->verbose = verbose;
ttcp->buflen = buflen;
- printk("TTCP [%p-%p]: nbuf=%d, buflen=%d, port=%d (%s/%s)\n",
- ttcp, ttcp->tpcb, ttcp->nbuf, ttcp->buflen, ttcp->port,
- ttcp->udp ? "udp" : "tcp",
- ttcp->mode == TTCP_MODE_TRANSMIT ? "tx" : "rx");
-
if (ttcp->udp)
status = udp_start(ttcp);
else
status = atcp_start(ttcp);
if (status)
+ {
+ WARN("Start server FAILED!");
goto fail;
+ }
+ printk("TTCP [%p-%p]: nbuf=%d, buflen=%d, port=%d (%s/%s)\n",
+ ttcp, ttcp->tpcb, ttcp->nbuf, ttcp->buflen, ttcp->port,
+ ttcp->udp ? "udp" : "tcp",
+ ttcp->mode == TTCP_MODE_TRANSMIT ? "tx" : "rx");
*_ttcp = (void*)ttcp;
ttcp->sock = sock;
@@ -581,15 +598,37 @@ fail:
return -1;
}
-uint8_t getStateTcp(void* p )
+static void
+close_conn(struct ttcp *_ttcp)
+{
+ ard_tcp_done(_ttcp, 0);
+}
+
+
+void ard_tcp_stop(void* ttcp)
+{
+ struct ttcp* _ttcp = (struct ttcp*)ttcp;
+ printk("Stop client %p-%p-%p\n", _ttcp, _ttcp->tpcb, _ttcp->lpcb);
+ close_conn(_ttcp);
+ asm("nop");
+}
+
+uint8_t getStateTcp(void* p, bool client)
{
struct ttcp* _ttcp = (struct ttcp*)p;
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL))
{
-// if (_ttcp->tpcb->state > 1)
-// INFO("ttcp:%p tpcb:%p state:%d\n",p, _ttcp->tpcb, _ttcp->tpcb->state);
+// INFO("ttcp:%p tpcb:%p state:%d lpcb:%p state:%d\n",
+// p, _ttcp->tpcb, _ttcp->tpcb->state,
+// _ttcp->lpcb, _ttcp->lpcb->state);
+ if (client)
return _ttcp->tpcb->state;
+ else
+ return _ttcp->lpcb->state;
+ }else{
+ WARN("TCP not initialized ttcp:%p tpcb:%p lpcb:%p\n",
+ _ttcp, ((_ttcp)?_ttcp->tpcb:0), ((_ttcp)?_ttcp->lpcb:0));
}
return CLOSED;
}
@@ -599,9 +638,7 @@ uint8_t isDataSent(void* p )
struct ttcp* _ttcp = (struct ttcp*)p;
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL))
{
-#define _APP_DEBUG_
- INFO("ttcp:%p tpcb:%p sent:%d\n",p, _ttcp->tpcb, _ttcp->buff_sent);
-#undef _APP_DEBUG_
+ //INFO("ttcp:%p tpcb:%p sent:%d\n",p, _ttcp->tpcb, _ttcp->buff_sent);
return _ttcp->buff_sent;
}else{
WARN("TCP null!\n");
@@ -622,19 +659,19 @@ tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
if (_ttcp->left > 0) {
//send_data(pcb, hs);
- printk("data left: %d", _ttcp->left );
+ INFO("data left: %d", _ttcp->left );
}
-//printk("Sent!\n");
_ttcp->buff_sent = 1;
- printk("%s: duration: %d\n", __FUNCTION__, timer_get_ms() - startTime);
+ //INFO("%s: duration: %d\n", __FUNCTION__, timer_get_ms() - startTime);
return ERR_OK;
}
int sendTcpData(void* p, uint8_t* buf, uint16_t len)
{
- printk("buf:%p len:%d\n", buf, len);
+ //INFO("buf:%p len:%d\n", buf, len);
+ //DUMP(buf,len);
+
startTime = timer_get_ms();
- DUMP(buf,len);
struct ttcp* _ttcp = (struct ttcp*)p;
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL)&&(buf!=NULL)&&(len!=0))
{
diff --git a/wifiHD/src/ard_tcp.h b/wifiHD/src/ard_tcp.h
index 6a2c7c005..52365ef57 100644
--- a/wifiHD/src/ard_tcp.h
+++ b/wifiHD/src/ard_tcp.h
@@ -15,7 +15,9 @@ typedef void (ard_tcp_done_cb_t)(void *opaque, int result);
int ard_tcp_start(struct ip_addr addr, uint16_t port, void *opaque,
ard_tcp_done_cb_t *done_cb, int mode, uint16_t nbuf, uint16_t buflen, int udp, int verbose, uint8_t sock, void** _ttcp);
-uint8_t getStateTcp(void* p );
+void ard_tcp_stop(void* ttcp);
+
+uint8_t getStateTcp(void* p, bool client );
int sendTcpData(void* p, uint8_t* buf, uint16_t len);
diff --git a/wifiHD/src/ard_utils.h b/wifiHD/src/ard_utils.h
index 7ac8be774..8430e16a3 100644
--- a/wifiHD/src/ard_utils.h
+++ b/wifiHD/src/ard_utils.h
@@ -9,23 +9,61 @@
#define ARD_UTILS_H_
#include "gpio.h"
+#include "arduino/arduino.h"
#define INIT_SIGNAL_FOR_SPI() gpio_enable_pin_pull_up(ARDUINO_HANDSHAKE_PIN)
#define BUSY_FOR_SPI() gpio_set_gpio_pin(ARDUINO_HANDSHAKE_PIN)
#define AVAIL_FOR_SPI() gpio_clr_gpio_pin(ARDUINO_HANDSHAKE_PIN)
-#define SIGN0_UP() gpio_set_gpio_pin(LED0_GPIO)
-#define SIGN0_DN() gpio_clr_gpio_pin(LED0_GPIO)
-#define SIGN1_UP() gpio_set_gpio_pin(LED1_GPIO)
-#define SIGN1_DN() gpio_clr_gpio_pin(LED1_GPIO)
-#define SIGN2_UP() gpio_set_gpio_pin(LED2_GPIO)
-#define SIGN2_DN() gpio_clr_gpio_pin(LED2_GPIO)
+#define LED0_UP() gpio_set_gpio_pin(LED0_GPIO)
+#define LED0_DN() gpio_clr_gpio_pin(LED0_GPIO)
+#define LED0_TL() gpio_tgl_gpio_pin(LED0_GPIO)
+#define LED1_UP() gpio_set_gpio_pin(LED1_GPIO)
+#define LED1_DN() gpio_clr_gpio_pin(LED1_GPIO)
+#define LED1_TL() gpio_tgl_gpio_pin(LED1_GPIO)
+#define LED2_UP() gpio_set_gpio_pin(LED2_GPIO)
+#define LED2_DN() gpio_clr_gpio_pin(LED2_GPIO)
+#define LED2_TL() gpio_tgl_gpio_pin(LED2_GPIO)
+
+#ifdef _DEBUG_
+#define SIGN0_UP LED0_UP
+#define SIGN0_DN LED0_DN
+#define SIGN0_TL LED0_TL
+#define SIGN1_UP LED1_UP
+#define SIGN1_DN LED1_DN
+#define SIGN1_TL LED1_TL
+#define SIGN2_UP LED2_UP
+#define SIGN2_DN LED2_DN
+#define SIGN2_TL LED2_TL
+
+#else
+#define SIGN0_UP()
+#define SIGN0_DN()
+#define SIGN0_TL()
+#define SIGN1_UP()
+#define SIGN1_DN()
+#define SIGN1_TL()
+#define SIGN2_UP()
+#define SIGN2_DN()
+#define SIGN2_TL()
+//#define TOGGLE_SIG0
+#endif
#define DELAY_450NS asm volatile("nop")
#define DELAY_1uS DELAY_450NS; DELAY_450NS;
-
#define TOGGLE_SIG0() SIGN0_UP(); DELAY_450NS;SIGN0_DN();
+#define LINK_LED_OFF LED0_UP
+#define ERROR_LED_OFF LED1_UP
+#define DATA_LED_OFF LED2_UP
+
+#define LINK_LED_ON LED0_DN
+#define ERROR_LED_ON LED1_DN
+#define DATA_LED_ON LED2_DN
+
+#define LINK_LED_BL LED0_TL
+#define ERROR_LED_BL LED1_TL
+#define DATA_LED_BL LED2_TL
#define CREATE_HEADER_REPLY(REPLY, RECV, NUM_PARAMS)\
@@ -165,12 +203,14 @@
typedef struct sData
{
- u8_t* data;
- u16_t len;
- u16_t idx;
+ uint8_t* data;
+ uint16_t len;
+ uint16_t idx;
void* pcb;
}tData;
+struct pbuf;
+
void insert_pBuf(struct pbuf* q, uint8_t sock, void* _pcb);
tData* get_pBuf(uint8_t sock);
@@ -185,6 +225,6 @@ bool getTcpDataByte(uint8_t sock, uint8_t* payload);
bool isAvailTcpDataByte(uint8_t sock);
-u8_t freeTcpData(uint8_t sock);
+uint8_t freeTcpData(uint8_t sock);
#endif /* ARD_UTILS_H_ */
diff --git a/wifiHD/src/cmd_wl.c b/wifiHD/src/cmd_wl.c
index bba50c7d9..b3439cbfa 100644
--- a/wifiHD/src/cmd_wl.c
+++ b/wifiHD/src/cmd_wl.c
@@ -193,7 +193,7 @@ cmd_status(int argc, char* argv[], void* ctx)
return CMD_DONE;
}
-
+#ifdef ADD_CMDS
/**
*
*/
@@ -225,8 +225,9 @@ cmd_power(int argc, char* argv[], void* ctx)
printk(usage);
return CMD_DONE;
}
+#endif
-
+#ifdef ADD_CMDS
/**
*
*/
@@ -273,6 +274,7 @@ cmd_psconf(int argc, char* argv[], void* ctx)
return CMD_DONE;
}
+#endif
#define MAX_KEY_LEN 64
diff --git a/wifiHD/src/debug.h b/wifiHD/src/debug.h
index 8ab0d9240..ccaaf60c8 100644
--- a/wifiHD/src/debug.h
+++ b/wifiHD/src/debug.h
@@ -32,9 +32,13 @@ printk("I-[%s] " msg , __func__ , ##args ); \
#define INFO(msg, args...) do {} while (0)
#endif /* !defined(_DEBUG_) */
+#if 1
#define WARN(msg, args...) do { \
printk("W-[%s] " msg , __func__ , ##args ); \
} while (0)
+#else
+#define WARN(msg, args...) do { } while (0)
+#endif
extern void dump(char* _buf, uint16_t _count);
diff --git a/wifiHD/src/lwipopts.h b/wifiHD/src/lwipopts.h
index 9fcada5db..5e5243de2 100644
--- a/wifiHD/src/lwipopts.h
+++ b/wifiHD/src/lwipopts.h
@@ -423,10 +423,10 @@
#undef DHCP_DOES_ARP_CHECK
-#if 0
+#if 1
#define LWIP_DEBUG 1
//#define NETIF_DEBUG LWIP_DBG_ON
-#define DHCP_DEBUG LWIP_DBG_ON
+//#define DHCP_DEBUG LWIP_DBG_ON
//#define ICMP_DEBUG LWIP_DBG_ON
//#define TCP_DEBUG LWIP_DBG_ON
//#define TCP_RTO_DEBUG LWIP_DBG_ON
@@ -434,8 +434,8 @@
//#define TCP_CWND_DEBUG LWIP_DBG_ON
//#define ETHARP_DEBUG LWIP_DBG_ON
//#define PBUF_DEBUG LWIP_DBG_ON
-#define TCP_INPUT_DEBUG LWIP_DBG_ON
-#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
+//#define TCP_INPUT_DEBUG LWIP_DBG_ON
+//#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#endif
#define ETH_PAD_SIZE WL_HEADER_SIZE /* size of wifiengine header */
diff --git a/wifiHD/src/main.c b/wifiHD/src/main.c
index 1574f3fdc..59478540a 100644
--- a/wifiHD/src/main.c
+++ b/wifiHD/src/main.c
@@ -74,11 +74,15 @@ void fw_download_cb(void* ctx, uint8_t** buf, uint32_t* len)
#include "debug.h"
#include "ard_utils.h"
-struct http_server {
+struct ctx_server {
struct netif *netif;
uint8_t wl_init_complete;
};
+// to maintain the word alignment
+#define PAD_CTX_SIZE 0x18
+#define PAD_NETIF_SIZE 0x3c
+
static bool initSpiComplete = false;
/**
@@ -127,7 +131,7 @@ static void
wl_cm_scan_cb(void* ctx)
{
#ifdef _APP_DEBUG_
- struct http_server* hs = ctx;
+ struct ctx_server* hs = ctx;
uint8_t init = hs->wl_init_complete;
@@ -142,7 +146,9 @@ wl_cm_scan_cb(void* ctx)
static void
wl_cm_conn_cb(struct wl_network_t* net, void* ctx)
{
- struct http_server* hs = ctx;
+ struct ctx_server* hs = ctx;
+
+ LINK_LED_ON();
printk("link up, connected to \"%s\"\n", ssid2str(&net->ssid));
printk("requesting dhcp ... ");
@@ -157,7 +163,9 @@ wl_cm_conn_cb(struct wl_network_t* net, void* ctx)
static void
wl_cm_disconn_cb(void* ctx)
{
- struct http_server* hs = ctx;
+ struct ctx_server* hs = ctx;
+
+ LINK_LED_OFF();
if (netif_is_up(hs->netif)) {
printk("link down, release dhcp\n");
@@ -187,16 +195,8 @@ ip_status_cb(struct netif* netif)
if (netif_is_up(netif)) {
set_result_cmd(WL_SUCCESS);
printk("bound to %s\n", ip2str(netif->ip_addr));
- printk("starting httpd ... ");
- if (httpd_start() == ERR_OK)
- printk("ok\n");
- else
- printk("fail\n");
-
- }
- else {
- printk("stopping httpd\n");
- httpd_stop();
+ }else{
+ WARN("Interface not up!");
}
}
@@ -207,10 +207,15 @@ ip_status_cb(struct netif* netif)
void
led_init(void)
{
+ gpio_enable_gpio_pin(LED0_GPIO);
gpio_enable_gpio_pin(LED1_GPIO);
gpio_enable_gpio_pin(LED2_GPIO);
- LED_Off(LED1);
- LED_Off(LED2);
+ LINK_LED_OFF();
+ ERROR_LED_OFF();
+ DATA_LED_OFF();
+
+ //LED_Off(LED1);
+ //LED_Off(LED2);
}
@@ -271,7 +276,7 @@ void wifi_init()
*
*/
void
-poll(struct http_server* hs)
+poll(struct ctx_server* hs)
{
/* this will trigger any scheduled timer callbacks */
timer_poll();
@@ -300,14 +305,16 @@ void initShell()
console_add_cmd("connect", cmd_connect, NULL);
console_add_cmd("setkey", cmd_setkey, NULL);
console_add_cmd("status", cmd_status, NULL);
+#ifdef ADD_CMDS
console_add_cmd("powersave", cmd_power, NULL);
console_add_cmd("psconf", cmd_psconf, NULL);
console_add_cmd("ping", cmd_ping, NULL);
+#endif
#ifdef WITH_WPA
console_add_cmd("wpass", cmd_setpass, NULL);
console_add_cmd("dpass", cmd_delpass, NULL);
#endif
-#if BOARD == ARDUINO
+#ifdef STAT_SPI
console_add_cmd("spiStat", cmd_statSpi, NULL);
console_add_cmd("resetSpiStat", cmd_resetStatSpi, NULL);
#endif
@@ -320,7 +327,7 @@ void initShell()
void
wl_init_complete_cb(void* ctx)
{
- struct http_server *hs = ctx;
+ struct ctx_server *hs = ctx;
struct ip_addr ipaddr, netmask, gw;
wl_err_t wl_status;
@@ -355,6 +362,7 @@ wl_init_complete_cb(void* ctx)
initSpiComplete = true;
AVAIL_FOR_SPI();
}
+
/* start connection manager */
wl_status = wl_cm_start(wl_cm_scan_cb, wl_cm_conn_cb, wl_cm_disconn_cb, wl_cm_err_cb, hs);
ASSERT(wl_status == WL_SUCCESS, "failed to init wl conn mgr");
@@ -368,7 +376,7 @@ main(void)
{
wl_err_t wl_status;
int status;
- struct http_server *hs;
+ struct ctx_server *hs;
startup_init();
@@ -394,12 +402,16 @@ main(void)
#else
printk("Arduino Wifi Startup... [%s]\n", __TIMESTAMP__);
- hs = calloc(1, sizeof(struct http_server));
+ size_t size_ctx_server = sizeof(struct ctx_server)+PAD_CTX_SIZE;
+ hs = calloc(1, size_ctx_server);
ASSERT(hs, "out of memory");
- hs->netif = calloc(1, sizeof(struct netif));
+ size_t size_netif = sizeof(struct netif)+PAD_NETIF_SIZE;
+ hs->netif = calloc(1, size_netif);
ASSERT(hs->netif, "out of memory");
+ INFO("hs:%p size:0x%x netif:%p size:0x%x\n", hs, size_ctx_server,
+ hs->netif, size_netif);
timer_init(NULL, NULL);
lwip_init();
diff --git a/wifiHD/src/ping.c b/wifiHD/src/ping.c
index c9ddcf03d..d04128706 100644
--- a/wifiHD/src/ping.c
+++ b/wifiHD/src/ping.c
@@ -29,7 +29,7 @@
* This file is derived from a part of the lwIP TCP/IP stack.
*
*/
-
+#ifdef ADD_CMDS
#include "lwip/opt.h"
#include "lwip/mem.h"
@@ -338,3 +338,4 @@ cmd_state_t cmd_ping(int argc, char* argv[], void* ctx)
Assert(0);
return CMD_DONE;
}
+#endif
diff --git a/wifiHD/src/wifi_spi.h b/wifiHD/src/wifi_spi.h
index 3f6deab11..b9ce88129 100644
--- a/wifiHD/src/wifi_spi.h
+++ b/wifiHD/src/wifi_spi.h
@@ -45,6 +45,8 @@ enum {
AVAIL_DATA_TCP_CMD = 0x2B,
GET_DATA_TCP_CMD = 0x2C,
START_CLIENT_TCP_CMD= 0x2D,
+ STOP_CLIENT_TCP_CMD = 0x2E,
+ GET_CLIENT_STATE_TCP_CMD = 0x2F,
DISCONNECT_CMD = 0x30,
// All command with DATA_FLAG 0x40 send a 16bit Len
diff --git a/wifiHD/src/wl_cm.c b/wifiHD/src/wl_cm.c
index c05461662..01eac6178 100644
--- a/wifiHD/src/wl_cm.c
+++ b/wifiHD/src/wl_cm.c
@@ -35,6 +35,7 @@
#if 1
# include "printf-stdarg.h"
+#include "ard_utils.h"
# define CM_DPRINTF(fmt...) printk(fmt)
#else
# define CM_DPRINTF(fmt...)
@@ -178,6 +179,8 @@ wl_media_connected_cb(void* ctx)
struct cm *cm = ctx;
struct wl_network_t *net = wl_get_current_network();
CM_DPRINTF("CM: connected to %s\n", ssid2str(&net->ssid));
+ LINK_LED_ON();
+ ERROR_LED_OFF();
if (cm->conn_cb)
cm->conn_cb(net, cm->ctx);
}
@@ -190,7 +193,8 @@ static void
wl_conn_failure_cb(void* ctx)
{
CM_DPRINTF("CM: connect failed, scanning\n");
-
+ ERROR_LED_ON();
+ LINK_LED_OFF();
if (wl_scan() != WL_SUCCESS)
/* should never happen */
CM_DPRINTF("CM: could not start scan after connect fail!\n");
@@ -205,7 +209,7 @@ wl_conn_lost_cb(void* ctx)
{
struct cm *cm = ctx;
CM_DPRINTF("CM: connection lost, scanning\n");
-
+ LINK_LED_OFF();
if (cm->disconn_cb)
cm->disconn_cb(cm->ctx);