diff --git a/binary/wifiHD.elf b/binary/wifiHD.elf index 93eada05f..9217d48ae 100644 Binary files a/binary/wifiHD.elf and b/binary/wifiHD.elf differ diff --git a/wifiHD/Release/wifiHD.elf b/wifiHD/Release/wifiHD.elf index 93eada05f..9217d48ae 100644 Binary files a/wifiHD/Release/wifiHD.elf and b/wifiHD/Release/wifiHD.elf differ diff --git a/wifiHD/src/ard_spi.c b/wifiHD/src/ard_spi.c index e22e6340c..ff199a284 100644 --- a/wifiHD/src/ard_spi.c +++ b/wifiHD/src/ard_spi.c @@ -72,7 +72,7 @@ #define REPLY_MAX_LEN 1024 #endif -uint8_t counter = 0; +#define _BUFFERSIZE 100 extern void tcp_debug_print_pcbs(void); @@ -82,7 +82,6 @@ static uint16_t count = 0; static uint16_t replyCount = 0; static cmd_spi_state_t state = SPI_CMD_IDLE; int receivedChars = 0; -#define _BUFFERSIZE 100 static uint8_t _receiveBuffer[_BUFFERSIZE]; bool startReply = false; bool end_write = false; //TODO only for debug @@ -159,8 +158,6 @@ cmd_resetStatSpi(int argc, char* argv[], void* ctx) #define RETURN_ERR(e) return (e==WL_SUCCESS) ? WIFI_SPI_ACK : WIFI_SPI_ERR; #define RESET_USART_CSR(usart) usart->cr = AVR32_USART_CR_RSTSTA_MASK; -tSpiMsg spiMsgBuf[MAX_CMD_PIPE_SIZE]; -unsigned char indexCmdPipe = 0; int result = WL_CONNECT_FAILED; //Store the result of the last operation void* mapSockTCP[MAX_SOCK_NUM]; @@ -196,6 +193,11 @@ void clearMapSockTcp(uint8_t sock) mapSockTCP[sock] = NULL; } +void initMapSockTcp() +{ + memset(mapSockTCP, 0, sizeof(void*)*MAX_SOCK_NUM); +} + /** * Calculate bitrate based on number of bytes transmitted and elapsed time */ @@ -1014,9 +1016,13 @@ cmd_spi_state_t get_client_state_tcp_cmd_cb(char* recv, char* reply, void* ctx, { _state = getStateTcp(p, 1); - INFO_TCP("p=%p _ttcp=%p state:%d\n", + INFO_TCP_VER("p=%p _ttcp=%p state:%d\n", p, ((struct ttcp*) p)->tpcb, _state); }else { + INFO_TCP_VER("p=%p _ttcp=%p state(tpcb):%d state(lpcb):%d\n", + p, ((struct ttcp*) p)->tpcb, + ((struct ttcp*) p)->tpcb->state, + ((struct ttcp*) p)->lpcb->state); _state = getStateTcp(p, 1); } } @@ -1380,6 +1386,8 @@ void spi_poll(struct netif* netif) { { state = SPI_CMD_INPROGRESS; count = receivedChars-offset; + if (count >= CMD_MAX_LEN) + count = CMD_MAX_LEN; memcpy(buf, &_receiveBuffer[offset], count); DISABLE_SPI_INT(); @@ -1637,6 +1645,10 @@ int initSpi() init_spi_cmds(); memset(_receiveBuffer, 0, _BUFFERSIZE); + memset(buf, 0, CMD_MAX_LEN); + memset(reply, 0, REPLY_MAX_LEN); + + initMapSockTcp(); init_pBuf(); diff --git a/wifiHD/src/ard_spi.h b/wifiHD/src/ard_spi.h index 074a50f10..99f98c8d4 100644 --- a/wifiHD/src/ard_spi.h +++ b/wifiHD/src/ard_spi.h @@ -39,7 +39,6 @@ typedef enum { #define TIMEOUT_SPI 200 //#define TIMEOUT_SENT_REPLY 1000 -#define MAX_CMD_PIPE_SIZE 5 #define DUMMY_DATA 0xFF typedef int (*cmd_spi_cb_t)(int numParam, char* buf, void* ctx); diff --git a/wifiHD/src/ard_tcp.c b/wifiHD/src/ard_tcp.c index f5c99b913..22f2be141 100644 --- a/wifiHD/src/ard_tcp.c +++ b/wifiHD/src/ard_tcp.c @@ -297,12 +297,13 @@ static err_t atcp_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err) { */ static int atcp_start(struct ttcp* ttcp) { err_t err = ERR_OK; + ttcp->tpcb = tcp_new(); if (ttcp->tpcb == NULL) { 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); diff --git a/wifiHD/src/debug.h b/wifiHD/src/debug.h index 59e6efdb4..6bbc5c6c2 100644 --- a/wifiHD/src/debug.h +++ b/wifiHD/src/debug.h @@ -23,10 +23,10 @@ #define INFO_E (1<<0xE) // Error #define INFO_WARN_FLAG (1<<0xF) // Warning - extern uint16_t enableDebug; extern uint16_t verboseDebug; +#ifdef _INFO_DEBUG_ #define INFO_INIT(msg, args...) do { \ if (enableDebug & INFO_INIT_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \ } while (0) @@ -35,6 +35,12 @@ if (enableDebug & INFO_INIT_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \ if (enableDebug & INFO_TCP_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \ } while (0) +#define INFO_TCP_VER(msg, args...) do { \ +if ((enableDebug & INFO_TCP_FLAG)&&(verboseDebug & INFO_TCP_FLAG)) \ + printk("I-[%s] " msg , __func__ , ##args ); \ +} while (0) + + #define INFO_SPI(msg, args...) do { \ if (enableDebug & INFO_SPI_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \ } while (0) @@ -42,7 +48,13 @@ if (enableDebug & INFO_SPI_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \ #define INFO_UTIL(msg, args...) do { \ if (enableDebug & INFO_UTIL_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \ } while (0) - +#else +#define INFO_INIT(msg, args...) do {}while(0); +#define INFO_TCP(msg, args...) do {}while(0); +#define INFO_TCP_VER(msg, args...) do { }while(0); +#define INFO_SPI(msg, args...) do {}while(0); +#define INFO_UTIL(msg, args...) do {}while(0); +#endif #ifdef _APP_DEBUG_ #define INFO(msg, args...) do { \