Skip to content

Commit 09e1c8d

Browse files
committed
Fix issue with Google Chromw
1 parent 5ce9067 commit 09e1c8d

File tree

6 files changed

+68
-88
lines changed

6 files changed

+68
-88
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#define LED0_GPIO AVR32_PIN_PB19
9393
#define LED1_GPIO AVR32_PIN_PB20
9494
#define LED2_GPIO AVR32_PIN_PB21
95+
#define DEB_PIN_GPIO AVR32_PIN_PA20
9596
//! @}
9697

9798
/*! \name PWM Channels of LEDs

wifiHD/src/ard_spi.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
343343

344344
void sendError()
345345
{
346-
AVAIL_FOR_SPI();
346+
AVAIL_FOR_SPI();
347347
if (spi_write(&AVR32_SPI, ERR_CMD) != SPI_ERROR_TIMEOUT)
348348
{
349349
//Wait to empty the buffer
@@ -1277,20 +1277,25 @@ unsigned char* getStartCmdSeq(unsigned char* _recv, int len, int *offset)
12771277
{
12781278
int i = 0;
12791279
*offset = 0;
1280+
DEB_PIN_UP();
12801281
for (; i<len; ++i)
12811282
{
12821283
if (_recv[i]==START_CMD)
12831284
{
12841285
if (i!=0)
12851286
{
1287+
DEB_PIN_DN();
12861288
//WARN("Disall. %d/%d cmd:%d\n", i, len,_recv[i+1]);
1287-
//SIGN2_DN();
1289+
WARN("D=%d\n", i);
1290+
12881291
}
12891292
*offset = i;
12901293
return &_recv[i];
12911294
}
12921295
}
1293-
WARN("Disall. %d\n", i);
1296+
DEB_PIN_DN();
1297+
WARN("D=%d\n", i);
1298+
12941299
return NULL;
12951300
}
12961301

@@ -1442,10 +1447,9 @@ bool checkMsgFormat(uint8_t* _recv, int len, int* offset)
14421447
unsigned char* recv = getStartCmdSeq(_recv, len, offset);
14431448
if ((recv == NULL)||(recv!=_recv))
14441449
{
1445-
//LED_On(LED2);
1446-
if (len < 20) //TODO stamp only short messages wrong
1450+
if ((verboseDebug & INFO_SPI_FLAG)&&(len < 20)) //TODO stamp only short messages wrong
14471451
dump((char*)_recv, len);
1448-
//LED_Off(LED2);
1452+
14491453
if (recv == NULL)
14501454
return false;
14511455
}
@@ -1498,11 +1502,8 @@ void spi_poll(struct netif* netif) {
14981502
int err = call_reply_cb(buf, &reply[0]);
14991503
if (err != REPLY_NO_ERR)
15001504
{
1501-
//LED_On(LED1);
1502-
//INFO_SPI("[E(0x%x):%d spiStatus:%d]\n", statSpi.lastCmd, err, statSpi.status);
15031505
DUMP_SPI_DATA(buf, count);
15041506
DUMP_SPI_DATA(reply, replyCount);
1505-
//LED_Off(LED1);
15061507
}
15071508
receivedChars = 0;
15081509
count = 0;

wifiHD/src/ard_tcp.c

Lines changed: 33 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static uint8_t tcp_poll_retries = 0;
3434
static int isDataSentCount = 0;
3535

3636
bool pending_close = false;
37+
bool pending_accept = false;
3738

3839
static void atcp_init()
3940
{
@@ -130,7 +131,7 @@ tcp_timeout_cb(void *ctx);
130131
*/
131132
static void tcp_send_data(struct ttcp *ttcp) {
132133
err_t err = ERR_OK;
133-
uint32_t len;
134+
uint32_t len, orig_len;
134135

135136
len = ttcp->left;
136137
INFO_TCP_VER("left=%d len:%d tcp_sndbuf:%d\n", ttcp->left, len, tcp_sndbuf(ttcp->tpcb));
@@ -145,11 +146,12 @@ static void tcp_send_data(struct ttcp *ttcp) {
145146
if (len > tcp_sndbuf(ttcp->tpcb))
146147
len = tcp_sndbuf(ttcp->tpcb);
147148

149+
orig_len = len;
148150
uint8_t count = 0;
149151
do {
150152
startTime = timer_get_ms();
151153
err = tcp_write(ttcp->tpcb, ttcp->payload, len, TCP_WRITE_FLAG_COPY);
152-
INFO_TCP_VER("%d) tcp_write len:%d err:%d\n", count++, len, err);
154+
INFO_TCP("%d) tcp_write %p len:%d err:%d\n", count++, ttcp->tpcb, len, err);
153155
if (err == ERR_MEM)
154156
{
155157
len /= 2;
@@ -167,65 +169,13 @@ static void tcp_send_data(struct ttcp *ttcp) {
167169
ttcp->left -= len;
168170
}
169171
else
170-
WARN("TTCP [%p]: tcp_write failed err:%d len:%d\n", ttcp, err, len);
172+
WARN("TTCP [%p-%p]: tcp_write failed err:%d origLen:%d len:%d\n",
173+
ttcp, ttcp->tpcb, err, orig_len, len);
171174
//
172175
// ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
173176
// tcp_timeout_cb, ttcp);
174177
}
175178

176-
/**
177-
* Only used in TCP mode.
178-
* Scheduled by tcp_send_data(). tcp_sent() is not used for performance reasons.
179-
*/
180-
static void tcp_timeout_cb(void *ctx) {
181-
struct ttcp *ttcp = ctx;
182-
183-
if (ttcp->left > 0) {
184-
tcp_send_data(ttcp);
185-
if (ttcp->verbose) {
186-
printk(".");
187-
if (ttcp->print_cnt % 80 == 0)
188-
printk("\n");
189-
ttcp->print_cnt++;
190-
}
191-
return;
192-
}
193-
194-
/* all sent - empty queue */
195-
if (ttcp->tpcb->snd_queuelen)
196-
ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT, tcp_timeout_cb,
197-
ttcp);
198-
else
199-
ard_tcp_done(ttcp, 0);
200-
}
201-
202-
#if 0
203-
/**
204-
* Only used in TCP mode.
205-
* Called by lwip when there is new space available in the TCP send buffer
206-
*/
207-
static err_t
208-
tcp_sent_cb(void *arg, struct tcp_pcb *pcb, u16_t len)
209-
{
210-
struct ttcp *ttcp = arg;
211-
212-
if (ttcp->left > 0) {
213-
tcp_send_data(ttcp);
214-
if (ttcp->verbose) {
215-
printk(".");
216-
if (ttcp->print_cnt % 80 == 0)
217-
printk("\n");
218-
ttcp->print_cnt++;
219-
}
220-
221-
} else if (pcb->snd_queuelen == 0) {
222-
ard_tcp_done(ttcp, 0);
223-
}
224-
225-
return ERR_OK;
226-
}
227-
#endif
228-
229179
/**
230180
* Only used in TCP mode.
231181
*/
@@ -262,14 +212,15 @@ static void cleanSockStateDelayed(void * arg)
262212
* Only used in TCP mode.
263213
*/
264214
static void atcp_conn_err_cb(void *arg, err_t err) {
265-
struct ttcp* ttcp = arg;
215+
struct ttcp* _ttcp = arg;
266216

267217
WARN("TTCP [%p]: connection error: %d arg:%p\n",
268-
ttcp, err, arg);
218+
_ttcp, err, arg);
269219

270220
if (ifStatus == false)
271221
printk("Abort connection\n");
272-
cleanSockState_cb(ttcp);
222+
cleanSockState_cb(_ttcp);
223+
273224
pending_close = false;
274225
}
275226

@@ -278,9 +229,12 @@ static void close_conn(struct ttcp *_ttcp) {
278229
tcp_sent(_ttcp->tpcb, NULL);
279230
tcp_recv(_ttcp->tpcb, NULL);
280231
err_t err = tcp_close(_ttcp->tpcb);
232+
INFO_TCP("Closing tpcb[%p]: state:0x%x err:%d\n",_ttcp->tpcb, _ttcp->tpcb->state, err);
233+
281234
if (err == ERR_MEM)
282235
pending_close = true;
283-
INFO_TCP("Closing tpcb[%p]: state:0x%x err:%d\n",_ttcp->tpcb, _ttcp->tpcb->state, err);
236+
pending_accept = false;
237+
WARN("----------------------\n");
284238
}
285239

286240
void closeConnections()
@@ -309,14 +263,14 @@ static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
309263
err_t err) {
310264
struct ttcp* ttcp = arg;
311265

312-
INFO_TCP("pcb:%p p: %p err:%d\n", pcb, p, err);
266+
INFO_TCP("pcb:%p pbuf: %p err:%d\n", pcb, p, err);
313267
if (err == ERR_OK && p != NULL) {
314268
DATA_LED_ON();
315269
/* for print_stats() */
316270
ttcp->recved += p->tot_len;
317271

318272
if ((ttcp->verbose)||(verboseDebug & INFO_TCP_FLAG)) {
319-
INFO_TCP("Recv:%d\n",p->tot_len);
273+
INFO_TCP("len:%d\n",p->tot_len);
320274
DUMP_TCP(p->payload, p->tot_len);
321275
ttcp->print_cnt++;
322276
}
@@ -346,24 +300,30 @@ static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
346300
++tcp_poll_retries;
347301

348302
if (tcp_poll_retries > 4) {
349-
INFO_TCP("ARD TCP [%p] arg=%p retries=%d\n",
303+
WARN("ARD TCP [%p] arg=%p retries=%d\n",
350304
pcb, arg, tcp_poll_retries);
351305
tcp_poll_retries = 0;
352306
tcp_abort(pcb);
307+
pending_accept = false;
308+
pending_close = false;
353309
return ERR_ABRT;
354310
}
355311

356312
if (pending_close)
357313
{
358314
err_t err = tcp_close(pcb);
359315
if (err == ERR_MEM)
316+
{
360317
pending_close = true;
318+
}
361319
else
320+
{
362321
pending_close = false;
322+
}
363323

364324
INFO_TCP("ARD TCP [%p-%p] try to close pending:%d\n", pcb, (_ttcp)?_ttcp->tpcb:0, pending_close);
365325
}else{
366-
INFO_TCP("ARD TCP [%p-%p] arg=%p retries=%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg, tcp_poll_retries);
326+
WARN("ARD TCP [%p-%p] arg=%p retries=%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg, tcp_poll_retries);
367327
if (_ttcp) tcp_send_data(_ttcp);
368328
else WARN("ttcp NULL!");
369329
}
@@ -377,15 +337,22 @@ static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
377337
static err_t atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err) {
378338
struct ttcp* ttcp = arg;
379339

340+
INFO_TCP("ARD TCP [%p]: accept new [%p]\n", ttcp, newpcb);
341+
INFO_TCP("local:%d remote:%d state:%d\n", newpcb->local_port, newpcb->remote_port, newpcb->state);
342+
343+
if (pending_accept)
344+
{
345+
WARN("Accepting another connection: %p-%p\n", ttcp->tpcb, newpcb);
346+
return ERR_OK;
347+
}
348+
pending_accept = true;
380349
tcp_setprio(newpcb, TCP_PRIO_MIN);
381350
tcp_poll_retries = 0;
382351
ttcp->tpcb = newpcb;
383352
tcp_recv(ttcp->tpcb, atcp_recv_cb);
384353
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
385354
tcp_poll(ttcp->tpcb, atcp_poll, 4);
386355

387-
INFO_TCP("ARD TCP [%p]: accept new [%p]\n", ttcp, newpcb);
388-
INFO_TCP("local:%d remote:%d state:%d\n", newpcb->local_port, newpcb->remote_port, newpcb->state);
389356
ttcp->start_time = timer_get_ms();
390357
return ERR_OK;
391358
}

wifiHD/src/ard_utils.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "gpio.h"
1212
#include "debug.h"
1313
#include "ARDUINO/arduino.h"
14-
#define INIT_SIGNAL_FOR_SPI() gpio_enable_pin_pull_up(ARDUINO_HANDSHAKE_PIN)
14+
#define INIT_SIGNAL_FOR_SPI() gpio_disable_pin_pull_up(ARDUINO_HANDSHAKE_PIN);
1515
#define BUSY_FOR_SPI() gpio_set_gpio_pin(ARDUINO_HANDSHAKE_PIN)
1616
#define AVAIL_FOR_SPI() gpio_clr_gpio_pin(ARDUINO_HANDSHAKE_PIN)
1717

@@ -25,6 +25,7 @@
2525
#define LED2_DN() gpio_clr_gpio_pin(LED2_GPIO)
2626
#define LED2_TL() gpio_tgl_gpio_pin(LED2_GPIO)
2727

28+
2829
#ifdef _DEBUG_
2930
#define SIGN0_UP LED0_UP
3031
#define SIGN0_DN LED0_DN
@@ -36,6 +37,10 @@
3637
#define SIGN2_DN LED2_DN
3738
#define SIGN2_TL LED2_TL
3839

40+
#define DEB_PIN_UP() gpio_set_gpio_pin(DEB_PIN_GPIO)
41+
#define DEB_PIN_DN() gpio_clr_gpio_pin(DEB_PIN_GPIO)
42+
#define DEB_PIN_ENA() gpio_enable_gpio_pin(DEB_PIN_GPIO);
43+
3944
#else
4045
#define SIGN0_UP()
4146
#define SIGN0_DN()
@@ -46,6 +51,10 @@
4651
#define SIGN2_UP()
4752
#define SIGN2_DN()
4853
#define SIGN2_TL()
54+
55+
#define DEB_PIN_UP()
56+
#define DEB_PIN_DN()
57+
4958
//#define TOGGLE_SIG0
5059
#endif
5160

wifiHD/src/board_init.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,16 @@ static void init_printk(void)
282282
void board_init(void)
283283
{
284284

285-
init_exceptions();
286-
init_hmatrix();
287-
init_sys_clocks();
288-
init_interrupts();
285+
init_exceptions();
286+
init_hmatrix();
287+
init_sys_clocks();
288+
init_interrupts();
289289

290-
init_rs232();
291-
init_printk();
290+
init_rs232();
291+
init_printk();
292292

293293
#ifdef WITH_SDRAM
294-
sdramc_init(FHSB_HZ);
294+
sdramc_init(FHSB_HZ);
295295
#endif
296-
init_spi();
296+
init_spi();
297297
}

wifiHD/src/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ wl_cm_disconn_cb(void* ctx)
155155
set_result_cmd(WL_FAILURE);
156156
}
157157

158-
158+
#if 0
159159
static void wl_cm_err_cb(void* ctx)
160160
{
161161
int err = *(int*)ctx;
162162
WARN("Error: %d\n", err);
163163
set_result_cmd(err);
164164
}
165+
#endif
165166

166167
/**
167168
*
@@ -194,9 +195,6 @@ led_init(void)
194195
LINK_LED_OFF();
195196
ERROR_LED_OFF();
196197
DATA_LED_OFF();
197-
198-
//LED_Off(LED1);
199-
//LED_Off(LED2);
200198
}
201199

202200

@@ -354,6 +352,10 @@ void startup_init(void)
354352
{
355353
INIT_SIGNAL_FOR_SPI();
356354
BUSY_FOR_SPI();
355+
356+
// if DEBUG enabled use DEB_PIN_GPIO for debug purposes
357+
DEB_PIN_ENA();
358+
DEB_PIN_UP();
357359
}
358360

359361
/**

0 commit comments

Comments
 (0)