Update capIb to account for input buffer wrap. Add gCapIbAccBytes reset to capIbReset().
authorFrank Livingston <frank-livingston@ti.com>
Thu, 26 Jan 2017 22:46:31 +0000 (16:46 -0600)
committerFrank Livingston <frank-livingston@ti.com>
Thu, 26 Jan 2017 22:46:31 +0000 (16:46 -0600)
pasdk/common/dbgDib.c

index a56fef2e0bcabef8db261365f916c0fdcba61b0c..03ec55a750ee790cc462595fe3fd37a2d1a229d4 100644 (file)
@@ -37,6 +37,7 @@ All rights reserved.
 #include <xdc/std.h>
 #include <xdc/runtime/Log.h>
 
+#include <ti/sysbios/hal/Cache.h>
 
 #include "common.h"
 
@@ -97,6 +98,7 @@ Int8 gCapIbBuf[2][CAP_IB_BUF_SZ] __attribute__ ((section(".gCapIbBuf")));
 Int32 gCapIbBufIdx[2]={0,0};
 Int32 gCapIbBufWrapCnt[2]={0,0};
 Int8 gCapIbBufPingPongSel=1;
+Int32 gCapIbAccBytes=0;
 Int32 gNumDiffFrame[2]={0,0};
 
 #endif // CAP_IP
@@ -205,6 +207,7 @@ Int capIbReset(Void)
     gCapIbBufIdx[gCapIbBufPingPongSel] = 0;
     gCapIbBufWrapCnt[gCapIbBufPingPongSel] = 0;
     gNumDiffFrame[gCapIbBufPingPongSel] = 0;
+    gCapIbAccBytes=0;
 
     return 0;
 }
@@ -214,7 +217,7 @@ Void capIb(
     PAF_InpBufConfig *pInpBufConfig
 )
 {
-    UInt32 nBytes;
+    UInt32 nBytes, bufEnd, currentBufSize, chunkSize, wrapSize;
     
     nBytes = pInpBufConfig->frameLength * pInpBufConfig->sizeofElement;
     
@@ -227,6 +230,16 @@ Void capIb(
     }
 #endif    
     
+    bufEnd = (Int) pInpBufConfig->base.pVoid + pInpBufConfig->sizeofBuffer;
+    currentBufSize = (bufEnd - (Int)pInpBufConfig->pntr.pSmInt);
+
+    if (currentBufSize >= nBytes)
+        chunkSize = nBytes;
+    else
+        chunkSize = currentBufSize;
+
+    wrapSize = nBytes - chunkSize;
+
     if ((CAP_IB_BUF_SZ - gCapIbBufIdx[gCapIbBufPingPongSel]) < nBytes)
     {
         //return; // fixed buffer
@@ -234,8 +247,24 @@ Void capIb(
         gCapIbBufWrapCnt[gCapIbBufPingPongSel]++;
     }
 
-    memcpy(&gCapIbBuf[gCapIbBufPingPongSel][gCapIbBufIdx[gCapIbBufPingPongSel]], pInpBufConfig->pntr.pSmInt, nBytes);
-    gCapIbBufIdx[gCapIbBufPingPongSel] += nBytes;
+    // invalidate input data
+    Cache_inv((Ptr)pInpBufConfig->pntr.pSmInt, chunkSize, Cache_Type_ALLD, 0);
+    Cache_wait();
+
+    memcpy(&gCapIbBuf[gCapIbBufPingPongSel][gCapIbBufIdx[gCapIbBufPingPongSel]], pInpBufConfig->pntr.pSmInt, chunkSize);
+
+    gCapIbBufIdx[gCapIbBufPingPongSel] += chunkSize;
+    gCapIbAccBytes += chunkSize;
+
+    if(wrapSize > 0)
+       {
+               // invalidate input data
+               Cache_inv((Ptr)pInpBufConfig->base.pSmInt, wrapSize, Cache_Type_ALLD, 0);
+               Cache_wait();
+               memcpy(&gCapIbBuf[gCapIbBufPingPongSel][gCapIbBufIdx[gCapIbBufPingPongSel]], pInpBufConfig->base.pSmInt, wrapSize);
+               gCapIbBufIdx[gCapIbBufPingPongSel] += wrapSize;
+               gCapIbAccBytes += wrapSize;
+       }
 }
 
 #endif // CAP_IP