diff --git a/wifiHD/src/ard_spi.c b/wifiHD/src/ard_spi.c index 9ac169b27..a099958eb 100644 --- a/wifiHD/src/ard_spi.c +++ b/wifiHD/src/ard_spi.c @@ -80,6 +80,7 @@ extern bool scanNetCompleted; static char buf[CMD_MAX_LEN]; static char reply[REPLY_MAX_LEN]; +static uint16_t cmdCorr = 0; static uint16_t count = 0; static uint16_t replyCount = 0; static cmd_spi_state_t state = SPI_CMD_IDLE; @@ -111,6 +112,7 @@ typedef struct sStatSpi int rxErr; int wrongFrame; int frameDisalign; + int overrideFrame; int lastCmd; int lastError; unsigned long status; @@ -129,6 +131,7 @@ void initStatSpi() statSpi.timeoutIntErr= 0; statSpi.wrongFrame = 0; statSpi.frameDisalign = 0; + statSpi.overrideFrame = 0; } void printStatSpi() @@ -142,6 +145,7 @@ void printStatSpi() printk("spiTmoIntErr\t: 0x%x\n", statSpi.timeoutIntErr); printk("wrongFrame\t: 0x%x\n", statSpi.wrongFrame); printk("disalFrame\t: 0x%x\n", statSpi.frameDisalign); + printk("overrideFrame\t: 0x%x\n", statSpi.overrideFrame); } cmd_state_t @@ -286,10 +290,11 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len) else { stream++; + _len++; spi_read(spi,&dummy); } //SIGN1_UP(); - }while ((!streamExit)&&(_len++ <= len)); + }while ((!streamExit)&&(_len <= len)); if (!streamExit) { @@ -1113,7 +1118,6 @@ cmd_spi_state_t get_client_state_tcp_cmd_cb(char* recv, char* reply, void* ctx, return SPI_CMD_DONE; } - cmd_spi_state_t avail_data_tcp_cmd_cb(char* recv, char* reply, void* ctx, uint16_t* count) { CHECK_ARD_NETIF(recv, reply, count); @@ -1143,28 +1147,6 @@ cmd_spi_state_t test_cmd_cb(char* recv, char* reply, void* ctx, uint16_t* count) return SPI_CMD_DONE; } - - -/* -cmd_spi_state_t ack_data_sent_reply_cb(char* recv, char* reply, void* ctx, uint16_t* count) { - - CHECK_ARD_NETIF(recv, reply, count); - - CREATE_HEADER_REPLY(reply, recv, PARAM_NUMS_1); - uint8_t dataSent = 0; - if ((recv[3]==1)&&(recv[4]>=0)&&(recv[4]=0)&&(recv[4]<0xFF)) + { + len = recv[4]; + int i= 0; + for (; isr & (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) != - (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) { - if ((timeout--)==0) { - err=SPI_ERROR_TIMEOUT; - break; - } - } - _receiveBuffer[index] = (spi->rdr >> AVR32_SPI_RDR_RD_OFFSET) & 0x00ff; - if (err == SPI_OK) { - ++index; - ++receivedChars; - }else{ + if (_receiveBuffer[0] != 0) + { + STATSPI_OVERRIDE_ERROR(); + } + + do { + unsigned int timeout = SPI_TIMEOUT; + err = SPI_OK; + + while ((spi->sr & (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) != + (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) { + if ((timeout--)==0) { + err=SPI_ERROR_TIMEOUT; + break; + } + } + _receiveBuffer[index] = (spi->rdr >> AVR32_SPI_RDR_RD_OFFSET) & 0x00ff; + if (err == SPI_OK) { + ++index; + ++receivedChars; + }else{ #ifdef _SPI_STATS_ - STATSPI_TIMEOUT_ERROR(); + STATSPI_TIMEOUT_ERROR(); #endif - break; - } + break; + } - /* break on buffer overflow */ - if (receivedChars >= _BUFFERSIZE) { - err = SPI_ERROR_OVERRUN_AND_MODE_FAULT; - break; - } - - } while (_receiveBuffer[index - 1] != END_CMD); - return err; + /* break on buffer overflow */ + if (receivedChars >= _BUFFERSIZE) { + err = SPI_ERROR_OVERRUN_AND_MODE_FAULT; + break; + } + } while (_receiveBuffer[index - 1] != END_CMD); + return err; } #if defined (__GNUC__) @@ -1591,19 +1598,17 @@ static void spi_int_handler(void) { volatile avr32_spi_t *spi = ARD_SPI; //DEB_PIN_DN(); - //eic_clear_interrupt_line(&AVR32_EIC, AVR32_SPI0_IRQ); - AVAIL_FOR_SPI(); + //AVAIL_FOR_SPI(); DISABLE_SPI_INT(); - unsigned short dummy = 0; - - if (((spi->sr & AVR32_SPI_SR_RDRF_MASK) != 0)||(dummy==START_CMD)) + if ((spi->sr & AVR32_SPI_SR_RDRF_MASK) != 0) { - int err = spi_slaveReceiveInt(ARD_SPI, dummy==START_CMD); + int err = spi_slaveReceiveInt(ARD_SPI); if (err == SPI_OK) { BUSY_FOR_SPI(); startReply=true; + ++cmdCorr; //maintain disable interrupt to send the reply command //DEB_PIN_UP(); return; diff --git a/wifiHD/src/ard_spi.h b/wifiHD/src/ard_spi.h index c2125d9ab..628f1155b 100644 --- a/wifiHD/src/ard_spi.h +++ b/wifiHD/src/ard_spi.h @@ -39,6 +39,7 @@ typedef enum { #define TIMEOUT_SPI 200 #define SPI_ALIGN_ERROR 0xF0 +#define SPI_OVERRIDE_ERROR 0xF1 #define DUMMY_DATA 0xFF typedef int (*cmd_spi_cb_t)(int numParam, char* buf, void* ctx); diff --git a/wifiHD/src/ard_utils.h b/wifiHD/src/ard_utils.h index 7ed218e18..0778adcfb 100644 --- a/wifiHD/src/ard_utils.h +++ b/wifiHD/src/ard_utils.h @@ -210,6 +210,12 @@ statSpi.lastError = SPI_ALIGN_ERROR; \ statSpi.status = spi_getStatus(ARD_SPI); +#define STATSPI_OVERRIDE_ERROR() \ + statSpi.overrideFrame++; \ + statSpi.rxErr++; \ + statSpi.lastError = SPI_OVERRIDE_ERROR; \ + statSpi.status = spi_getStatus(ARD_SPI); + #define STATSPI_TX_TIMEOUT_ERROR() \ statSpi.timeoutErr++; \ statSpi.txErr++; \ diff --git a/wifiHD/src/wifi_spi.h b/wifiHD/src/wifi_spi.h index 7332aea0f..6e6b4bb72 100644 --- a/wifiHD/src/wifi_spi.h +++ b/wifiHD/src/wifi_spi.h @@ -55,11 +55,13 @@ enum { GET_HOST_BY_NAME_CMD= 0x35, START_SCAN_NETWORKS = 0x36, GET_FW_VERSION_CMD = 0x37, + GET_TEST_CMD = 0x38, // All command with DATA_FLAG 0x40 send a 16bit Len SEND_DATA_TCP_CMD = 0x44, GET_DATABUF_TCP_CMD = 0x45, + }; #if 0