diff --git a/wifiHD/.project b/wifiHD/.project index af5155341..c284bab1b 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 diff --git a/wifiHD/Release/wifiHD.elf b/wifiHD/Release/wifiHD.elf deleted file mode 100644 index 7db1d88e2..000000000 Binary files a/wifiHD/Release/wifiHD.elf and /dev/null differ diff --git a/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h b/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h index 568548aac..2b78ab635 100644 --- a/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h +++ b/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h @@ -199,6 +199,7 @@ /* Pin related to shield communication */ #define ARDUINO_HANDSHAKE_PIN AVR32_PIN_PA25 + #define ARDUINO_EXTINT_PIN AVR32_PIN_PA04 //not used #define AVR32_PDCA_PID_TX AVR32_PDCA_PID_SPI1_TX #define AVR32_PDCA_PID_RX AVR32_PDCA_PID_SPI1_RX diff --git a/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_out.c b/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_out.c index 0428d5b29..9605beb8e 100644 --- a/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_out.c +++ b/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_out.c @@ -57,7 +57,7 @@ #include "lwip/snmp.h" #include - +#define _TEST_HD_ /* Forward declarations.*/ static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb); @@ -699,6 +699,19 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb) } #endif +#ifdef _TEST_HD_ + /* ANGR: set rtime this _before_ checking ip_route(). Otherwise TCP_SYN will + * not be retransmitted in case the interface was down and tcp_connect() + * will not return any error. Since we still want the err_cb() (or maybe + * the wifi link comes up), make sure that we fulfill the retransmissions in + * tcp_slowtmr() + */ + + /* Set retransmission timer running if it is not currently enabled */ + if(pcb->rtime == -1) + pcb->rtime = 0; +#endif + /* If we don't have a local IP address, we get one by calling ip_route(). */ if (ip_addr_isany(&(pcb->local_ip))) { @@ -709,9 +722,11 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb) ip_addr_set(&(pcb->local_ip), &(netif->ip_addr)); } - /* Set retransmission timer running if it is not currently enabled */ +#ifndef _TEST_HD_ + //Set retransmission timer running if it is not currently enabled if(pcb->rtime == -1) pcb->rtime = 0; +#endif if (pcb->rttest == 0) { pcb->rttest = tcp_ticks; diff --git a/wifiHD/src/ard_spi.c b/wifiHD/src/ard_spi.c index 0696cc0f9..4862cdf54 100644 --- a/wifiHD/src/ard_spi.c +++ b/wifiHD/src/ard_spi.c @@ -204,7 +204,11 @@ void setMapSock(uint8_t sock, void* _ttcp) void clearMapSockTcp(uint8_t sock) { if (sock < MAX_SOCK_NUM) + { + //printk("UnMap [%d, %p]\n", sock, mapSockTCP[sock]); mapSockTCP[sock] = NULL; + } + } void initMapSockTcp() @@ -649,7 +653,7 @@ int start_server_tcp(uint16_t port, uint8_t sock) err = WL_SUCCESS; }else{ - INFO_SPI("Start Server [%d, %d] FAILED!\n", port, sock); + WARN("Start Server [%d, %d] FAILED!\n", port, sock); clearMapSockTcp(sock); } return err; @@ -1140,7 +1144,6 @@ cmd_spi_state_t get_client_state_tcp_cmd_cb(char* recv, char* reply, void* ctx, ((struct ttcp*) p)->tpcb->state, ((struct ttcp*) p)->lpcb->state, _state); - } } } @@ -1226,10 +1229,16 @@ cmd_spi_state_t get_data_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_t CHECK_ARD_NETIF(recv, reply, count); + tParam* params = (tParam*)&recv[3]; + + GET_PARAM_NEXT(BYTE, params, _sock); + GET_PARAM_NEXT(INT, params, _peek); + if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]tpcb) { tcp_arg(ttcp->tpcb, NULL); tcp_sent(ttcp->tpcb, NULL); tcp_recv(ttcp->tpcb, NULL); tcp_err(ttcp->tpcb, NULL); - err = tcp_close(ttcp->tpcb); + //TEMPORAQARY + //err = tcp_close(ttcp->tpcb); INFO_TCP("Closing tpcb: state:0x%x err:%d\n", ttcp->tpcb->state, err); } @@ -118,6 +124,7 @@ static void ard_tcp_done(struct ttcp* ttcp, int result) { ttcp->done_cb(ttcp->opaque, result); ard_tcp_destroy(ttcp); + clearMapSockTcp(getSock(ttcp)); } static void @@ -233,8 +240,16 @@ static void atcp_conn_cli_err_cb(void *arg, err_t err) { if (ifStatus == false) printk("Abort connection\n"); - ard_tcp_destroy(_ttcp); - cleanSockState_cb(_ttcp); + + if ((_ttcp)&&(err == ERR_ABRT)) + { + WARN("TTCP [%p]: free memory\n", _ttcp); + tcp_poll_retries = 0; + cleanSockState_cb(_ttcp); + if (_ttcp->payload) + free(_ttcp->payload); + free(_ttcp); + } pending_close = false; } @@ -269,7 +284,7 @@ void closeConnections() _ttcp->tpcb, _ttcp->tpcb->state, _ttcp->lpcb, _ttcp->lpcb->state); //tcp_close(_ttcp->tpcb); ard_tcp_destroy(_ttcp); - cleanSockState_cb(_ttcp); + clearMapSockTcp(getSock(_ttcp)); } } } @@ -305,6 +320,8 @@ static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p, close_conn(ttcp); } + if (err!=ERR_OK) + WARN("err=%d p=%p\n", err, p); return ERR_OK; } @@ -352,21 +369,18 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) { struct ttcp* _ttcp = arg; ++tcp_poll_retries; - if (tcp_poll_retries > 4) { - WARN("ARD TCP [%p] arg=%p retries=%d\n", - pcb, arg, tcp_poll_retries); + if (tcp_poll_retries > 8) { + WARN("ARD TCP [%p-%p] arg=%p retries=%d\n", + pcb, _ttcp->tpcb, arg, tcp_poll_retries); tcp_poll_retries = 0; tcp_abort(pcb); - ard_tcp_destroy(_ttcp); - cleanSockState_cb(_ttcp); - pending_close = false; - return ERR_ABRT; + return ERR_ABRT; } - WARN("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg, - tcp_poll_retries, pending_close); + WARN("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d conn:%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg, + tcp_poll_retries, pending_close, _connected); - if (_ttcp) tcp_send_data(_ttcp); + if ((_ttcp)&&(_connected)) tcp_send_data(_ttcp); if (pending_close) { @@ -377,7 +391,12 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) { } else { + cleanSockState_cb(_ttcp); + if (_ttcp->payload) + free(_ttcp->payload); + free(_ttcp); pending_close = false; + } INFO_TCP("ARD TCP [%p-%p] try to close pending:%d\n", pcb, (_ttcp)?_ttcp->tpcb:0, pending_close); @@ -423,7 +442,7 @@ static int atcp_start(struct ttcp* ttcp) { WARN("TTCP [%p]: could not allocate pcb\n", ttcp); return -1; } - INFO_TCP("tcp:%x\n", ttcp->tpcb); + ttcp->payload = malloc(ttcp->buflen); if (ttcp->payload == NULL) { WARN("TTCP [%p]: could not allocate payload\n", ttcp); @@ -436,14 +455,14 @@ static int atcp_start(struct ttcp* ttcp) { if (ttcp->mode == TTCP_MODE_TRANSMIT) { tcp_err(ttcp->tpcb, atcp_conn_cli_err_cb); tcp_recv(ttcp->tpcb, atcp_recv_cb); - tcp_poll(ttcp->tpcb, atcp_poll, 4); + tcp_sent(ttcp->tpcb, tcp_data_sent); + tcp_poll(ttcp->tpcb, atcp_poll_conn, 4); _connected = false; - INFO_TCP("[tpcb]- %p\n", ttcp->tpcb); + INFO_TCP("[tpcb]-%p payload:%p\n", ttcp->tpcb, ttcp->payload); DUMP_TCP_STATE(ttcp); if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port, tcp_connect_cb) != ERR_OK) { WARN("TTCP [%p]: tcp connect failed\n", ttcp); - atcp_conn_err_cb(ttcp, err); return -1; } @@ -681,6 +700,7 @@ void ard_tcp_stop(void* ttcp) { INFO_TCP("Destroy TCP connection...state:%d\n", _ttcp->tpcb->state); ard_tcp_destroy(_ttcp); clearMapSockTcp(getSock(_ttcp)); + tcp_poll_retries = 0; }else{ INFO_TCP("Closing connection...state:%d\n", _ttcp->tpcb->state); DUMP_TCP_STATE(_ttcp); @@ -688,6 +708,7 @@ void ard_tcp_stop(void* ttcp) { { close_conn(_ttcp); } + pending_accept = false; } } @@ -756,7 +777,7 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len) { if (_ttcp==NULL) { - WARN("ttcp == NULL!"); + WARN("ttcp == NULL!\n"); return WL_FAILURE; } diff --git a/wifiHD/src/ard_utils.c b/wifiHD/src/ard_utils.c index 7008257e5..03665a327 100644 --- a/wifiHD/src/ard_utils.c +++ b/wifiHD/src/ard_utils.c @@ -88,9 +88,10 @@ bool isAvailTcpDataByte(uint8_t sock) INFO_UTIL("check:%d %d %p\n",p->idx, p->len, p->data); if (p->idx == p->len) { - INFO_UTIL("Free %p other buf %d\n", p->data, IS_BUF_AVAIL()); freetData(p->data); ack_recved(p->pcb, p->len); + INFO_UTIL("Free %p other buf %d tail:%d head:%d\n", + p->data, IS_BUF_AVAIL(), tailBuf, headBuf); return (IS_BUF_AVAIL()); }else{ return true; @@ -101,7 +102,7 @@ bool isAvailTcpDataByte(uint8_t sock) -bool getTcpDataByte(uint8_t sock, uint8_t* payload) +bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek) { // ref field in struct pbuf has been used as index pointer for byte data tData* p = get_pBuf(sock); @@ -111,7 +112,10 @@ bool getTcpDataByte(uint8_t sock, uint8_t* payload) if (p->idx < p->len) { uint8_t* buf = (uint8_t*)p->data; - *payload = buf[p->idx++]; + if (peek) + *payload = buf[p->idx]; + else + *payload = buf[p->idx++]; INFO_UTIL("get:%d %p %d\n",p->idx, p->data, *payload); return true; }else{ diff --git a/wifiHD/src/ard_utils.h b/wifiHD/src/ard_utils.h index 62eeeb9cc..bd60b0f0f 100644 --- a/wifiHD/src/ard_utils.h +++ b/wifiHD/src/ard_utils.h @@ -25,7 +25,7 @@ #define LED2_DN() gpio_clr_gpio_pin(LED2_GPIO) #define LED2_TL() gpio_tgl_gpio_pin(LED2_GPIO) - +#define _DEBUG_ #ifdef _DEBUG_ #define SIGN0_UP LED0_UP #define SIGN0_DN LED0_DN @@ -238,7 +238,7 @@ bool isBufAvail(); bool getTcpData(uint8_t sock, void** payload, uint16_t* len); -bool getTcpDataByte(uint8_t sock, uint8_t* payload); +bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek); bool isAvailTcpDataByte(uint8_t sock); diff --git a/wifiHD/src/lwipopts.h b/wifiHD/src/lwipopts.h index 426593958..64965bfb2 100644 --- a/wifiHD/src/lwipopts.h +++ b/wifiHD/src/lwipopts.h @@ -433,9 +433,9 @@ //#define IP_DEBUG LWIP_DBG_ON //#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 PBUF_DEBUG LWIP_DBG_ON +//#define TCP_INPUT_DEBUG LWIP_DBG_ON +//#define TCP_OUTPUT_DEBUG LWIP_DBG_ON #endif #define ETH_PAD_SIZE WL_HEADER_SIZE /* size of wifiengine header */