@@ -326,12 +326,8 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
326326{
327327 uint16_t _len = 0 ;
328328 unsigned short dummy = 0 ;
329- bool streamExit = false;
330329
331330 do {
332- if (* stream == END_CMD )
333- streamExit = true;
334-
335331 //SIGN1_DN();
336332 if (spi_write (spi , * stream ) == SPI_ERROR_TIMEOUT )
337333 {
@@ -350,16 +346,7 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
350346 spi_read (spi ,& dummy );
351347 }
352348 //SIGN1_UP();
353- }while ((!streamExit )&& (_len <= len ));
354-
355- if (!streamExit )
356- {
357- #ifdef _SPI_STATS_
358- statSpi .wrongFrame ++ ;
359- statSpi .lastError = SPI_ERROR_ARGUMENT ;
360- #endif
361- return SPI_ERROR_ARGUMENT ;
362- }
349+ }while (_len < len );
363350 return SPI_OK ;
364351}
365352
@@ -1640,6 +1627,7 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
16401627 int index = 0 ;
16411628 int err = SPI_OK ;
16421629 state = SPI_CMD_INPUT ;
1630+ bool endOfFrame = false;
16431631
16441632 do {
16451633 unsigned int timeout = SPI_TIMEOUT ;
@@ -1680,7 +1668,31 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
16801668 err = SPI_ERROR_OVERRUN_AND_MODE_FAULT ;
16811669 break ;
16821670 }
1683- } while (_receiveBuffer [index - 1 ] != END_CMD );
1671+
1672+ if (_receiveBuffer [index - 1 ] == END_CMD )
1673+ {
1674+ int8_t numParams = 0 ;
1675+ int idx = PARAM_LEN_POS + 1 ;
1676+ bool islen16bit = _receiveBuffer [CMD_POS ] & DATA_FLAG ;
1677+ if (index >= idx )
1678+ {
1679+ numParams = _receiveBuffer [PARAM_LEN_POS ];
1680+ while (((index - 1 ) > idx )&& (numParams > 0 ))
1681+ {
1682+ if (islen16bit )
1683+ idx += (_receiveBuffer [idx ]<<8 ) + _receiveBuffer [idx + 1 ]+ 2 ;
1684+ else
1685+ idx += _receiveBuffer [idx ]+ 1 ;
1686+ -- numParams ;
1687+ }
1688+ if (((index - 1 ) == idx ) && (numParams == 0 ))
1689+ endOfFrame = true;
1690+ }
1691+ if (!endOfFrame ){
1692+ WARN ("Wrong termination index:%d nParam:%d idx:%d 16bit:%d\n" , index , numParams , idx , islen16bit );
1693+ }
1694+ }
1695+ } while (!endOfFrame );
16841696 return err ;
16851697}
16861698
0 commit comments