1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-10 21:24:12 +01:00

Less print msgs on wifishield

This commit is contained in:
Mimmo La Fauci 2012-02-01 08:15:37 +01:00
parent 5778170fa6
commit 7c2934a91b
5 changed files with 442 additions and 502 deletions

View File

@ -78,10 +78,15 @@
<type>2</type>
<locationURI>framework:/com.atmel.avr32.sf.uc3</locationURI>
</link>
<link>
<name>arduino</name>
<type>2</type>
<location>/media/WindowsNTFS/Projects/Arduino/Arduino-git</location>
</link>
<link>
<name>include</name>
<type>2</type>
<location>C:/usr/avr32/include</location>
<location>/home/dlafauci/C::/usr/avr32/include</location>
</link>
</linkedResources>
</projectDescription>

BIN
wifiHD/Release/wifiHD.elf Normal file

Binary file not shown.

View File

@ -30,8 +30,6 @@
#define TTCP_MODE_TRANSMIT 0
#define TTCP_MODE_RECEIVE 1
struct ttcp {
/* options */
@ -67,32 +65,26 @@ struct ttcp {
unsigned int startTime = 0;
/**
* Calculate bitrate based on number of bytes transmitted and elapsed time
*/
static void
ard_tcp_print_stats(struct ttcp *ttcp)
{
static void ard_tcp_print_stats(struct ttcp *ttcp) {
uint32_t ms = timer_get_ms() - ttcp->start_time;
uint32_t bytes = ttcp->mode == TTCP_MODE_TRANSMIT ?
ttcp->nbuf * ttcp->buflen : ttcp->recved;
uint32_t bytes = ttcp->mode == TTCP_MODE_TRANSMIT ? ttcp->nbuf
* ttcp->buflen : ttcp->recved;
if (ttcp->verbose)
printk("\n");
printk("TTCP [%p]: %d bytes processed, %d.%d KB/s (%s/%s)\n",
ttcp, bytes, bytes / ms, bytes % ms, ttcp->udp ? "udp" : "tcp",
ttcp->mode == TTCP_MODE_TRANSMIT ? "tx" : "rx");
printk("TTCP [%p]: %d bytes processed, %d.%d KB/s (%s/%s)\n", ttcp, bytes,
bytes / ms, bytes % ms, ttcp->udp ? "udp" : "tcp", ttcp->mode
== TTCP_MODE_TRANSMIT ? "tx" : "rx");
}
/**
* Clean up and free the ttcp structure
*/
static void
ard_tcp_destroy(struct ttcp* ttcp)
{
static void ard_tcp_destroy(struct ttcp* ttcp) {
err_t err = ERR_OK;
if (ttcp->tpcb) {
tcp_arg(ttcp->tpcb, NULL);
@ -100,16 +92,14 @@ ard_tcp_destroy(struct ttcp* ttcp)
tcp_recv(ttcp->tpcb, NULL);
tcp_err(ttcp->tpcb, NULL);
err = tcp_close(ttcp->tpcb);
printk("Closing tpcb: state:0x%x err:%d\n",
ttcp->tpcb->state, err);
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);
printk("Closing lpcb: state:0x%x err:%d\n", ttcp->lpcb->state, err);
}
if (ttcp->upcb) {
@ -123,13 +113,10 @@ ard_tcp_destroy(struct ttcp* ttcp)
free(ttcp);
}
/**
* Invoked when transfer is done or aborted (non-zero result).
*/
static void
ard_tcp_done(struct ttcp* ttcp, int result)
{
static void ard_tcp_done(struct ttcp* ttcp, int result) {
if (result == 0)
ard_tcp_print_stats(ttcp);
@ -148,9 +135,7 @@ tcp_timeout_cb(void *ctx);
* Called upon connect and when there's space available in the TCP send window
*
*/
static void
tcp_send_data(struct ttcp *ttcp)
{
static void tcp_send_data(struct ttcp *ttcp) {
err_t err;
uint32_t len;
@ -176,19 +161,16 @@ tcp_send_data(struct ttcp *ttcp)
ttcp->left -= len;
else
printk("TTCP [%p]: tcp_write failed\n", ttcp);
//
// ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
// tcp_timeout_cb, ttcp);
//
// ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
// tcp_timeout_cb, ttcp);
}
/**
* Only used in TCP mode.
* Scheduled by tcp_send_data(). tcp_sent() is not used for performance reasons.
*/
static void
tcp_timeout_cb(void *ctx)
{
static void tcp_timeout_cb(void *ctx) {
struct ttcp *ttcp = ctx;
if (ttcp->left > 0) {
@ -204,13 +186,12 @@ tcp_timeout_cb(void *ctx)
/* all sent - empty queue */
if (ttcp->tpcb->snd_queuelen)
ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
tcp_timeout_cb, ttcp);
ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT, tcp_timeout_cb,
ttcp);
else
ard_tcp_done(ttcp, 0);
}
#if 0
/**
* Only used in TCP mode.
@ -241,9 +222,7 @@ tcp_sent_cb(void *arg, struct tcp_pcb *pcb, u16_t len)
/**
* Only used in TCP mode.
*/
static err_t
tcp_connect_cb(void *arg, struct tcp_pcb *tpcb, err_t err)
{
static err_t tcp_connect_cb(void *arg, struct tcp_pcb *tpcb, err_t err) {
struct ttcp* ttcp = arg;
printk("TTCP [%p]: connect\n", ttcp);
@ -257,28 +236,23 @@ tcp_connect_cb(void *arg, struct tcp_pcb *tpcb, err_t err)
return ERR_OK;
}
/**
* Only used in TCP mode.
*/
static void
atcp_conn_err_cb(void *arg, err_t err)
{
static void atcp_conn_err_cb(void *arg, err_t err) {
struct ttcp* ttcp = arg;
printk("TTCP [%p]: connection error:0x%x\n", ttcp,err);
printk("TTCP [%p]: connection error:0x%x\n", ttcp, err);
ttcp->tpcb = NULL; /* free'd by lwip upon return */
ard_tcp_done(ttcp, err);
}
/**
* Only used in TCP mode.
*/
static err_t
atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
err_t err) {
struct ttcp* ttcp = arg;
/* p will be NULL when remote end is done */
if (p == NULL) {
@ -296,32 +270,26 @@ atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
ttcp->print_cnt++;
}
insert_pBuf(p, ttcp->sock, (void*)pcb);
insert_pBuf(p, ttcp->sock, (void*) pcb);
pbuf_free(p);
tcp_recved(pcb, p->tot_len);
DATA_LED_OFF();
return ERR_OK;
}
void ack_recved(void* pcb, int len)
{
void ack_recved(void* pcb, int len) {
// Comment the call because it is activated on atcp_recv_cb
//tcp_recved(pcb, len);
}
static err_t
atcp_poll(void *arg, struct tcp_pcb *pcb)
{
static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
return ERR_OK;
}
/**
* Only used in TCP mode.
*/
static err_t
atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err)
{
static err_t atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err) {
struct ttcp* ttcp = arg;
ttcp->tpcb = newpcb;
@ -335,15 +303,11 @@ atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err)
return ERR_OK;
}
/**
* Start TCP transfer.
*/
static int
atcp_start(struct ttcp* ttcp)
{
static int atcp_start(struct ttcp* ttcp) {
err_t err = ERR_OK;
ttcp->tpcb = tcp_new();
if (ttcp->tpcb == NULL) {
printk("TTCP [%p]: could not allocate pcb\n", ttcp);
@ -361,14 +325,20 @@ atcp_start(struct ttcp* ttcp)
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
tcp_recv(ttcp->tpcb, atcp_recv_cb);
if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port,
tcp_connect_cb) != ERR_OK) {
if (tcp_connect(ttcp->tpcb, &ttcp->addr, ttcp->port, tcp_connect_cb)
!= ERR_OK) {
printk("TTCP [%p]: tcp connect failed\n", ttcp);
atcp_conn_err_cb(ttcp, err);
return -1;
}
} else {
tcp_bind(ttcp->tpcb, IP_ADDR_ANY, ttcp->port);
err = tcp_bind(ttcp->tpcb, IP_ADDR_ANY, ttcp->port);
if (err != ERR_OK){
printk("TTCP [%p]: bind failed err=%d\n", ttcp, err);
return -1;
}
ttcp->lpcb = tcp_listen(ttcp->tpcb);
if (ttcp->lpcb == NULL) {
printk("TTCP [%p]: listen failed\n", ttcp);
@ -383,7 +353,6 @@ atcp_start(struct ttcp* ttcp)
return 0;
}
static void
udp_send_data(struct ttcp* ttcp);
@ -391,16 +360,12 @@ udp_send_data(struct ttcp* ttcp);
* Only used in UDP mode. Scheduled after data has been sent in udp_send_data()
* if we have more data to send.
*/
static void udp_timeout_cb(void *ctx)
{
static void udp_timeout_cb(void *ctx) {
struct ttcp* ttcp = ctx;
udp_send_data(ttcp);
}
static int
udp_send_bytes(struct ttcp* ttcp, uint32_t len)
{
static int udp_send_bytes(struct ttcp* ttcp, uint32_t len) {
struct pbuf* p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
if (p == NULL) {
printk("TTCP [%p]: could not allocate pbuf\n", ttcp);
@ -422,9 +387,7 @@ udp_send_bytes(struct ttcp* ttcp, uint32_t len)
* ttcp data has been sent, a number of end markers will be sent. After
* end marker transmission, this function will complete the ttcp process.
*/
static void
udp_send_data(struct ttcp* ttcp)
{
static void udp_send_data(struct ttcp* ttcp) {
/* send start marker first time */
if (!ttcp->udp_started) {
if (udp_send_bytes(ttcp, 4) == 0) {
@ -452,19 +415,16 @@ udp_send_data(struct ttcp* ttcp)
return;
}
ttcp->tid = timer_sched_timeout_cb(0, TIMEOUT_ONESHOT,
udp_timeout_cb, ttcp);
ttcp->tid
= timer_sched_timeout_cb(0, TIMEOUT_ONESHOT, udp_timeout_cb, ttcp);
}
/**
* Only used in UDP mode. Will finalize the ttcp process when an end marker
* is seen.
*/
static void
udp_recv_cb(void *arg, struct udp_pcb *upcb, struct pbuf *p,
struct ip_addr *addr, u16_t port)
{
static void udp_recv_cb(void *arg, struct udp_pcb *upcb, struct pbuf *p,
struct ip_addr *addr, u16_t port) {
struct ttcp* ttcp = arg;
/* got start marker? we might lose this so if we get it just reset
@ -493,17 +453,13 @@ udp_recv_cb(void *arg, struct udp_pcb *upcb, struct pbuf *p,
ttcp->print_cnt++;
}
out:
pbuf_free(p);
out: pbuf_free(p);
}
/**
* Start UDP transfer.
*/
static int
udp_start(struct ttcp* ttcp)
{
static int udp_start(struct ttcp* ttcp) {
ttcp->udp_end_marker_left = 5;
ttcp->upcb = udp_new();
if (ttcp->upcb == NULL) {
@ -512,8 +468,7 @@ udp_start(struct ttcp* ttcp)
}
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
if (udp_connect(ttcp->upcb, &ttcp->addr, ttcp->port) !=
ERR_OK) {
if (udp_connect(ttcp->upcb, &ttcp->addr, ttcp->port) != ERR_OK) {
printk("TTCP [%p]: udp connect failed\n", ttcp);
return -1;
}
@ -525,18 +480,15 @@ udp_start(struct ttcp* ttcp)
return 0;
}
/**
* Start a new ttcp transfer. It should be possible to call this function
* multiple times in order to get multiple ttcp streams. done_cb() will be
* invoked upon completion.
*
*/
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)
{
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) {
struct ttcp* ttcp;
int status;
@ -577,80 +529,66 @@ ard_tcp_start(struct ip_addr addr, uint16_t port, void *opaque,
else
status = atcp_start(ttcp);
if (status)
{
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");
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 = (void*) ttcp;
ttcp->sock = sock;
ttcp->buff_sent = 1;
return 0;
fail:
ard_tcp_destroy(ttcp);
fail: ard_tcp_destroy(ttcp);
return -1;
}
static void
close_conn(struct ttcp *_ttcp)
{
static void close_conn(struct ttcp *_ttcp) {
ard_tcp_done(_ttcp, 0);
}
void ard_tcp_stop(void* ttcp)
{
struct ttcp* _ttcp = (struct ttcp*)ttcp;
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");
//asm("nop");
}
uint8_t getStateTcp(void* p, bool client)
{
struct ttcp* _ttcp = (struct ttcp*)p;
uint8_t getStateTcp(void* p, bool client) {
struct ttcp* _ttcp = (struct ttcp*) p;
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL))
{
// INFO("ttcp:%p tpcb:%p state:%d lpcb:%p state:%d\n",
// p, _ttcp->tpcb, _ttcp->tpcb->state,
// _ttcp->lpcb, _ttcp->lpcb->state);
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL)) {
// 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{
} else {
WARN("TCP not initialized ttcp:%p tpcb:%p lpcb:%p\n",
_ttcp, ((_ttcp)?_ttcp->tpcb:0), ((_ttcp)?_ttcp->lpcb:0));
}
return CLOSED;
}
uint8_t isDataSent(void* p )
{
struct ttcp* _ttcp = (struct ttcp*)p;
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL))
{
uint8_t isDataSent(void* p) {
struct ttcp* _ttcp = (struct ttcp*) p;
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL)) {
//INFO("ttcp:%p tpcb:%p sent:%d\n",p, _ttcp->tpcb, _ttcp->buff_sent);
return _ttcp->buff_sent;
}else{
} else {
WARN("TCP null!\n");
}
return -1;
}
static err_t
tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
static err_t tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len) {
struct ttcp *_ttcp;
LWIP_UNUSED_ARG(len);
@ -666,15 +604,13 @@ tcp_data_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
return ERR_OK;
}
int sendTcpData(void* p, uint8_t* buf, uint16_t len)
{
int sendTcpData(void* p, uint8_t* buf, uint16_t len) {
//INFO("buf:%p len:%d\n", buf, len);
//DUMP(buf,len);
startTime = timer_get_ms();
struct ttcp* _ttcp = (struct ttcp*)p;
if ((_ttcp != NULL)&&(_ttcp->tpcb != NULL)&&(buf!=NULL)&&(len!=0))
{
struct ttcp* _ttcp = (struct ttcp*) p;
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL) && (buf != NULL) && (len != 0)) {
_ttcp->buff_sent = 0;
//pbuf_take(buf, len, _ttcp->);
memcpy(_ttcp->payload, buf, len);
@ -687,7 +623,9 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len)
return WL_FAILURE;
}
char usage[] = "Usage: ttcp -t/-r [-options] host\n\
char
usage[] =
"Usage: ttcp -t/-r [-options] host\n\
-l length of bufs written to network (default 1024)\n\
-n number of bufs written to network (default 1024)\n\
-p port number to send to (default 2000)\n\
@ -697,9 +635,7 @@ char usage[] = "Usage: ttcp -t/-r [-options] host\n\
/**
*
*/
cmd_state_t
cmd_ttcp(int argc, char* argv[], void* ctx)
{
cmd_state_t cmd_ttcp(int argc, char* argv[], void* ctx) {
int c;
int mode = TTCP_MODE_TRANSMIT;
@ -750,14 +686,13 @@ cmd_ttcp(int argc, char* argv[], void* ctx)
}
}
void* _ttcp = NULL;
if (ard_tcp_start(addr, port, NULL, NULL, mode, nbuf, buflen, udp,
verbose,0,&_ttcp))
if (ard_tcp_start(addr, port, NULL, NULL, mode, nbuf, buflen, udp, verbose,
0, &_ttcp))
return CMD_DONE;
return CMD_DONE;
}
#if 0
#include "lwip/sockets.h"

View File

@ -9,7 +9,7 @@
#define ARD_UTILS_H_
#include "gpio.h"
#include "arduino/arduino.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)

View File

@ -423,8 +423,8 @@
#undef DHCP_DOES_ARP_CHECK
#if 1
#define LWIP_DEBUG 1
#if 0
#define LWIP_DEBUG 0
//#define NETIF_DEBUG LWIP_DBG_ON
//#define DHCP_DEBUG LWIP_DBG_ON
//#define ICMP_DEBUG LWIP_DBG_ON