10000 Fix issue with peek function · arduino/wifishield@9928ada · GitHub
[go: up one dir, main page]

Skip to content

Commit 9928ada

Browse files
committed
Fix issue with peek function
1 parent fba0984 commit 9928ada

File tree

12 files changed

+117
-42
lines changed

12 files changed

+117
-42
lines changed

firmware/wifiHD/.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</dictionary>
2828
<dictionary>
2929
<key>org.eclipse.cdt.make.core.buildLocation</key>
30-
<value>${workspace_loc:/wifiHD/Release}</value>
30+
<value>${workspace_loc:/wifiHD/Debug}</value>
3131
</dictionary>
3232
<dictionary>
3333
<key>org.eclipse.cdt.make.core.contents</key>

firmware/wifiHD/Release/wifiHD.elf

-385 KB
Binary file not shown.

firmware/wifiHD/src/SOFTWARE_FRAMEWORK/BOARDS/ARDUINO/arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199

200200
/* Pin related to shield communication */
201201
#define ARDUINO_HANDSHAKE_PIN AVR32_PIN_PA25
202+
#define ARDUINO_EXTINT_PIN AVR32_PIN_PA04 //not used
202203

203204
#define AVR32_PDCA_PID_TX AVR32_PDCA_PID_SPI1_TX
204205
#define AVR32_PDCA_PID_RX AVR32_PDCA_PID_SPI1_RX

firmware/wifiHD/src/SOFTWARE_FRAMEWORK/SERVICES/LWIP/lwip-1.3.2/src/core/tcp_out.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include "lwip/snmp.h"
5858

5959
#include <string.h>
60-
60+
#define _TEST_HD_
6161
/* Forward declarations.*/
6262
static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb);
6363

@@ -699,6 +699,19 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
699699
}
700700
#endif
701701

702+
#ifdef _TEST_HD_
703+
/* ANGR: set rtime this _before_ checking ip_route(). Otherwise TCP_SYN will
704+
* not be retransmitted in case the interface was down and tcp_connect()
705+
* will not return any error. Since we still want the err_cb() (or maybe
706+
* the wifi link comes up), make sure that we fulfill the retransmissions in
707+
* tcp_slowtmr()
708+
*/
709+
710+
/* Set retransmission timer running if it is not currently enabled */
711+
if(pcb->rtime == -1)
712+
pcb->rtime = 0;
713+
#endif
714+
702715
/* If we don't have a local IP address, we get one by
703716
calling ip_route(). */
704717
if (ip_addr_isany(&(pcb->local_ip))) {
@@ -709,9 +722,11 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
709722
ip_addr_set(&(pcb->local_ip), &(netif->ip_addr));
710723
}
711724

712-
/* Set retransmission timer running if it is not currently enabled */
725+
#ifndef _TEST_HD_
726+
//Set retransmission timer running if it is not currently enabled
713727
if(pcb->rtime == -1)
714728
pcb->rtime = 0;
729+
#endif
715730

716731
if (pcb->rttest == 0) {
717732
pcb->rttest = tcp_ticks;

firmware/wifiHD/src/ard_spi.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ void setMapSock(uint8_t sock, void* _ttcp)
204204
void clearMapSockTcp(uint8_t sock)
205205
{
206206
if (sock < MAX_SOCK_NUM)
207+
{
208+
//printk("UnMap [%d, %p]\n", sock, mapSockTCP[sock]);
207209
mapSockTCP[sock] = NULL;
210+
}
211+
208212
}
209213

210214
void initMapSockTcp()
@@ -649,7 +653,7 @@ int start_server_tcp(uint16_t port, uint8_t sock)
649653
err = WL_SUCCESS;
650654
}else{
651655

652-
INFO_SPI("Start Server [%d, %d] FAILED!\n", port, sock);
656+
WARN("Start Server [%d, %d] FAILED!\n", port, sock);
653657
clearMapSockTcp(sock);
654658
}
655659
return err;
@@ -1140,7 +1144,6 @@ cmd_spi_state_t get_client_state_tcp_cmd_cb(char* recv, char* reply, void* ctx,
11401144
((struct ttcp*) p)->tpcb->state,
11411145
((struct ttcp*) p)->lpcb->state,
11421146
_state);
1143-
11441147
}
11451148
}
11461149
}
@@ -1226,10 +1229,16 @@ cmd_spi_state_t get_data_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_t
12261229

12271230
CHECK_ARD_NETIF(recv, reply, count);
12281231

1232+
tParam* params = (tParam*)&recv[3];
1233+
1234+
GET_PARAM_NEXT(BYTE, params, _sock);
1235+
GET_PARAM_NEXT(INT, params, _peek);
1236+
12291237
if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]<MAX_SOCK_NUM))
12301238
{
12311239
SIGN2_DN();
1232-
if (getTcpDataByte((uint8_t)recv[4], &data))
1240+
1241+
if (getTcpDataByte((uint8_t)recv[4], &data, _peek))
12331242
{
12341243
CREATE_HEADER_REPLY(reply, recv, PARAM_NUMS_1);
12351244
PUT_DATA_BYTE(data, reply, 3);

firmware/wifiHD/src/ard_tcp.c

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ static int isDataSentCount = 0;
3636
bool pending_close = false;
3737
bool pending_accept = false;
3838

39+
static err_t tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len);
40+
3941
static void atcp_init()
4042
{
4143
pending_close = false;
@@ -48,12 +50,16 @@ static void ard_tcp_destroy(struct ttcp* ttcp) {
4850
err_t err = ERR_OK;
4951
DUMP_TCP_STATE(ttcp);
5052

53+
if (getSock(ttcp)==-1)
54+
WARN("ttcp already deallocated!\n");
55+
5156
if (ttcp->tpcb) {
5257
tcp_arg(ttcp->tpcb, NULL);
5358
tcp_sent(ttcp->tpcb, NULL);
5459
tcp_recv(ttcp->tpcb, NULL);
5560
tcp_err(ttcp->tpcb, NULL);
56-
err = tcp_close(ttcp->tpcb);
61+
//TEMPORAQARY
62+
//err = tcp_close(ttcp->tpcb);
5763
INFO_TCP("Closing tpcb: state:0x%x err:%d\n", ttcp->tpcb->state, err);
5864
}
5965

@@ -118,6 +124,7 @@ static void ard_tcp_done(struct ttcp* ttcp, int result) {
118124
ttcp->done_cb(ttcp->opaque, result);
119125

120126
ard_tcp_destroy(ttcp);
127+
clearMapSockTcp(getSock(ttcp));
121128
}
122129

123130
static void
@@ -233,8 +240,16 @@ static void atcp_conn_cli_err_cb(void *arg, err_t err) {
233240

234241
if (ifStatus == false)
235242
printk("Abort connection\n");
236-
ard_tcp_destroy(_ttcp);
237-
cleanSockState_cb(_ttcp);
243+
244+
if ((_ttcp)&&(err == ERR_ABRT))
245+
{
246+
WARN("TTCP [%p]: free memory\n", _ttcp);
247+
tcp_poll_retries = 0;
248+
cleanSockState_cb(_ttcp);
249+
if (_ttcp->payload)
250+
free(_ttcp->payload);
251+
free(_ttcp);
252+
}
238253

239254
pending_close = false;
240255
}
@@ -269,7 +284,7 @@ void closeConnections()
269284
_ttcp->tpcb, _ttcp->tpcb->state, _ttcp->lpcb, _ttcp->lpcb->state);
270285
//tcp_close(_ttcp->tpcb);
271286
ard_tcp_destroy(_ttcp);
272-
cleanSockState_cb(_ttcp);
287+
clearMapSockTcp(getSock(_ttcp));
273288
}
274289
}
275290
}
@@ -305,6 +320,8 @@ static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
305320
close_conn(ttcp);
306321
}
307322

323+
if (err!=ERR_OK)
324+
WARN("err=%d p=%p\n", err, p);
308325
return ERR_OK;
309326
}
310327

@@ -352,21 +369,18 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) {
352369
struct ttcp* _ttcp = arg;
353370
++tcp_poll_retries;
354371

355-
if (tcp_poll_retries > 4) {
356-
WARN("ARD TCP [%p] arg=%p retries=%d\n",
357-
pcb, arg, tcp_poll_retries);
372+
if (tcp_poll_retries > 8) {
373+
WARN("ARD TCP [%p-%p] arg=%p retries=%d\n",
374+
pcb, _ttcp->tpcb, arg, tcp_poll_retries);
358375
tcp_poll_retries = 0;
359376
tcp_abort(pcb);
360-
ard_tcp_destroy(_ttcp);
361-
cleanSockState_cb(_ttcp);
362-
pending_close = false;
363-
return ERR_ABRT;
377+
return ERR_ABRT;
364378
}
365379

366-
WARN("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg,
367-
tcp_poll_retries, pending_close);
380+
WARN("ARD TCP [%p-%p] arg=%p retries=%d pend.close:%d conn:%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg,
381+
tcp_poll_retries, pending_close, _connected);
368382

369-
if (_ttcp) tcp_send_data(_ttcp);
383+
if ((_ttcp)&&(_connected)) tcp_send_data(_ttcp);
370384

371385
if (pending_close)
372386
{
@@ -377,7 +391,12 @@ static err_t atcp_poll_conn(void *arg, struct tcp_pcb *pcb) {
377391
}
378392
else
379393
{
394+
cleanSockState_cb(_ttcp);
395+
if (_ttcp->payload)
396+
free(_ttcp->payload);
397+
free(_ttcp);
380398
pending_close = false;
399+
381400
}
382401

383402
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) {
423442
WARN("TTCP [%p]: could not allocate pcb\n", ttcp);
424443
return -1;
425444
}
426-
INFO_TCP("tcp:%x\n", ttcp->tpcb);
445+
427446
ttcp->payload = malloc(ttcp->buflen);
428447
if (ttcp->payload == NULL) {
429448
WARN("TTCP [%p]: could not allocate payload\n", ttcp);
@@ -436,14 +455,14 @@ static int atcp_start(struct ttcp* ttcp) {
436455
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
437456
tcp_err(ttcp->tpcb, atcp_conn_cli_err_cb);
438457
tcp_recv(ttcp->tpcb, atcp_recv_cb);
439-
tcp_poll(ttcp->tpcb, atcp_poll, 4);
458+
tcp_sent(ttcp->tpcb, tcp_data_sent);
459+
tcp_poll(ttcp->tpcb, atcp_poll_conn, 4);
440460
_connected = false;
441-
INFO_TCP("[tpcb]- %p\n", ttcp->tpcb);
461+
INFO_TCP("[tpcb]-%p payload:%p\n", ttcp->tpcb, ttcp->payload);
442462
DUMP_TCP_STATE(ttcp);
443463
if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
444464
!= ERR_OK) {
445465
WARN("TTCP [%p]: tcp connect failed\n", ttcp);
446-
atcp_conn_err_cb(ttcp, err);
447466
return -1;
448467
}
449468

@@ -681,13 +700,15 @@ void ard_tcp_stop(void* ttcp) {
681700
INFO_TCP("Destroy TCP connection...state:%d\n", _ttcp->tpcb->state);
682701
ard_tcp_destroy(_ttcp);
683702
clearMapSockTcp(getSock(_ttcp));
703+
tcp_poll_retries = 0;
684704
}else{
685705
INFO_TCP("Closing connection...state:%d\n", _ttcp->tpcb->state);
686706
DUMP_TCP_STATE(_ttcp);
687707
if ((_ttcp)&&(_ttcp->tpcb)&&(_ttcp->tpcb->state!=LAST_ACK)&&(_ttcp->tpcb->state!=CLOSED))
688708
{
689709
close_conn(_ttcp);
690710
}
711+
pending_accept = false;
691712
}
692713
}
693714

@@ -756,7 +777,7 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len) {
756777

757778
if (_ttcp==NULL)
758779
{
759-
WARN("ttcp == NULL!");
780+
WARN("ttcp == NULL!\n");
760781
return WL_FAILURE;
761782
}
762783

firmware/wifiHD/src/ard_utils.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ bool isAvailTcpDataByte(uint8_t sock)
8888
INFO_UTIL("check:%d %d %p\n",p->idx, p->len, p->data);
8989
if (p->idx == p->len)
9090
{
91-
INFO_UTIL("Free %p other buf %d\n", p->data, IS_BUF_AVAIL());
9291
freetData(p->data);
9392
ack_recved(p->pcb, p->len);
93+
INFO_UTIL("Free %p other buf %d tail:%d head:%d\n",
94+
p->data, IS_BUF_AVAIL(), tailBuf, headBuf);
9495
return (IS_BUF_AVAIL());
9596
}else{
9697
return true;
@@ -101,7 +102,7 @@ bool isAvailTcpDataByte(uint8_t sock)
101102

102103

103104

104-
bool getTcpDataByte(uint8_t sock, uint8_t* payload)
105+
bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek)
105106
{
106107
// ref field in struct pbuf has been used as index pointer for byte data
107108
tData* p = get_pBuf(sock);
@@ -111,7 +112,10 @@ bool getTcpDataByte(uint8_t sock, uint8_t* payload)
111112
if (p->idx < p->len)
112113
{
113114
uint8_t* buf = (uint8_t*)p->data;
114-
*payload = buf[p->idx++];
115+
if (peek)
116+
*payload = buf[p->idx];
117+
else
118+
*payload = buf[p->idx++];
115119
INFO_UTIL("get:%d %p %d\n",p->idx, p->data, *payload);
116120
return true;
117121
}else{

firmware/wifiHD/src/ard_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define LED2_DN() gpio_clr_gpio_pin(LED2_GPIO)
2626
#define LED2_TL() gpio_tgl_gpio_pin(LED2_GPIO)
2727

28-
28+
#define _DEBUG_
2929
#ifdef _DEBUG_
3030
#define SIGN0_UP LED0_UP
3131
#define SIGN0_DN LED0_DN
@@ -238,7 +238,7 @@ bool isBufAvail();
238238

239239
bool getTcpData(uint8_t sock, void** payload, uint16_t* len);
240240

241-
bool getTcpDataByte(uint8_t sock, uint8_t* payload);
241+
bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek);
242242

243243
bool isAvailTcpDataByte(uint8_t sock);
244244

firmware/wifiHD/src/lwipopts.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@
433433
//#define IP_DEBUG LWIP_DBG_ON
434434
//#define TCP_CWND_DEBUG LWIP_DBG_ON
435435
//#define ETHARP_DEBUG LWIP_DBG_ON
436-
//#define PBUF_DEBUG LWIP_DBG_ON
437-
#define TCP_INPUT_DEBUG LWIP_DBG_ON
438-
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
436+
#define PBUF_DEBUG LWIP_DBG_ON
437+
//#define TCP_INPUT_DEBUG LWIP_DBG_ON
438+
//#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
439439
#endif
440440

441441
#define ETH_PAD_SIZE WL_HEADER_SIZE /* size of wifiengine header */

0 commit comments

Comments
 (0)
0