From f9495c9d4f66e4230c6f5c0a51719d65730cf2df Mon Sep 17 00:00:00 2001 From: Nguyen Hoan Hoang Date: Fri, 25 Oct 2019 08:42:52 -0400 Subject: [PATCH] Merge back from IOsonata --- include/slip_intrf.h | 5 ++++- src/slip_intrf.cpp | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/slip_intrf.h b/include/slip_intrf.h index 52e80b20..92016b78 100755 --- a/include/slip_intrf.h +++ b/include/slip_intrf.h @@ -48,6 +48,7 @@ typedef struct __Slip_Device { DEVINTRF DevIntrf; //!< This interface DEVINTRF *pPhyIntrf; //!< Physical transport interface void *pObj; //!< Slip object instance + volatile bool bSlipEnd; //!< true - indicate slip packet complete } SLIPDEV; #ifdef __cplusplus @@ -65,7 +66,7 @@ static inline int SlipRx(SLIPDEV * const pDev, uint8_t *pBuff, int Bufflen) { static inline int SlipTx(SLIPDEV * const pDev, uint8_t *pData, int Datalen) { return DeviceIntrfTx(&pDev->DevIntrf, 0, pData, Datalen); } - +static inline bool SlipRxCompleted(SLIPDEV * const pDev) { return pDev->bSlipEnd; } #ifdef __cplusplus } @@ -194,6 +195,8 @@ class Slip : public DeviceIntrf { */ virtual void StopTx(void) { DeviceIntrfStopTx(*this); } + bool RxCompleted() { return vDevData.bSlipEnd; } + private: SLIPDEV vDevData; }; diff --git a/src/slip_intrf.cpp b/src/slip_intrf.cpp index 6cba9f8c..f15d72dd 100755 --- a/src/slip_intrf.cpp +++ b/src/slip_intrf.cpp @@ -161,6 +161,7 @@ int SlipIntrfRxDataBlocking(DEVINTRF * const pDevIntrf, uint8_t *pBuff, int Buff uint8_t d; uint8_t *p = pBuff; + dev->bSlipEnd = false; while (BuffLen > 0) { @@ -168,7 +169,10 @@ int SlipIntrfRxDataBlocking(DEVINTRF * const pDevIntrf, uint8_t *pBuff, int Buff { if (*pBuff == SLIP_END_CODE) { - return cnt; +// cnt++; + dev->bSlipEnd = true; + + break; } if (*pBuff == SLIP_ESC_CODE) { @@ -212,6 +216,8 @@ int SlipIntrfRxDataNonBlocking(DEVINTRF * const pDevIntrf, uint8_t *pBuff, int B int cnt = 0; uint8_t d; + dev->bSlipEnd = false; + if (*pBuff == SLIP_ESC_CODE) { if (dev->pPhyIntrf->RxData(dev->pPhyIntrf, &d, 1) <= 0) @@ -242,7 +248,9 @@ int SlipIntrfRxDataNonBlocking(DEVINTRF * const pDevIntrf, uint8_t *pBuff, int B if (*pBuff == SLIP_END_CODE) { - cnt++; + //cnt++; + dev->bSlipEnd = true; + break; } if (*pBuff == SLIP_ESC_CODE) @@ -320,7 +328,7 @@ bool SlipIntrfStartTx(DEVINTRF * const pDevIntrf, int DevAddr) * * @return Number of bytes sent including the SLIP code */ -#if 1 +#if 0 int SlipIntrfTxData(DEVINTRF * const pDevIntrf, uint8_t *pData, int DataLen) { SLIPDEV *dev = (SLIPDEV *)pDevIntrf->pDevData; @@ -542,7 +550,7 @@ bool SlipInit(SLIPDEV * const pDev, DEVINTRF * const pPhyIntrf, bool bBlocking) pDev->DevIntrf.StopTx = SlipIntrfStopTx; pDev->DevIntrf.IntPrio = 0; pDev->DevIntrf.EvtCB = nullptr; - pDev->DevIntrf.MaxRetry = 5; + pDev->DevIntrf.MaxRetry = 0; pDev->DevIntrf.bDma = false; pDev->DevIntrf.PowerOff = SlipIntrfPowerOff; pDev->DevIntrf.EnCnt = 1;