@@ -326,12 +326,8 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
326
326
{
327
327
uint16_t _len = 0 ;
328
328
unsigned short dummy = 0 ;
329
- bool streamExit = false;
330
329
331
330
do {
332
- if (* stream == END_CMD )
333
- streamExit = true;
334
-
335
331
//SIGN1_DN();
336
332
if (spi_write (spi , * stream ) == SPI_ERROR_TIMEOUT )
337
333
{
@@ -350,16 +346,7 @@ int write_stream(volatile avr32_spi_t *spi, const char *stream, uint16_t len)
350
346
spi_read (spi ,& dummy );
351
347
}
352
348
//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 );
363
350
return SPI_OK ;
364
351
}
365
352
@@ -1640,6 +1627,7 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
1640
1627
int index = 0 ;
1641
1628
int err = SPI_OK ;
1642
1629
state = SPI_CMD_INPUT ;
1630
+ bool endOfFrame = false;
1643
1631
1644
1632
do {
1645
1633
unsigned int timeout = SPI_TIMEOUT ;
@@ -1680,7 +1668,31 @@ inline int spi_slaveReceiveInt(volatile avr32_spi_t *spi)
1680
1668
err = SPI_ERROR_OVERRUN_AND_MODE_FAULT ;
1681
1669
break ;
1682
1670
}
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 );
1684
1696
return err ;
1685
1697
}
1686
1698
0 commit comments