PASDK-53: Experimental code for circular buffer overflow/underflow handling
authorFrank Livingston <frank-livingston@ti.com>
Tue, 28 Feb 2017 18:36:03 +0000 (12:36 -0600)
committerFrank Livingston <frank-livingston@ti.com>
Tue, 28 Feb 2017 18:36:03 +0000 (12:36 -0600)
pasdk/test_arm/framework/audioStreamDecodeProc.c
pasdk/test_dsp/framework/audioStreamInpProc.c
pasdk/test_dsp/framework/audioStreamOutProc.c

index 38820aeb6a6d64f712329c81a800234ba9590cc2..effd395e41d8ea41477dd533e450733145de04b1 100644 (file)
@@ -101,7 +101,7 @@ PAF_AudioData  *gDecAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 PAF_AudioSize  gDecAudioFrameChannelSizes[PAF_MAXNUMCHAN_AF];
 PAF_AudioData  *gDecOrigAudioFrameChannelPointers[PAF_MAXNUMCHAN_AF];
 
-// Underflow threshold before returning error to Top-Level FSM
+// Underflow threshold before circular buffer reset and return error to Top-Level FSM
 #define DEC_OP_CB_WRTAF_OVR_THR  ( 20 ) // FL: arbitrary setting
 UInt32 gDecOpCbWrtAfOvr  =0; // decoder output circular buffer overflow count
 
@@ -118,6 +118,12 @@ UInt32 gSlaveDecInfoCnt         =0;
 UInt32 gSlaveDecDecodeCnt       =0;
 UInt32 gSlaveDecDeactivateCnt   =0;
 
+// debug
+UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count
+
+// FL: (***) debug
+#include "evmc66x_gpio_dbg.h"
+
 
 /*
  *  ======== taskAsdpFxn ========
@@ -493,6 +499,8 @@ Void taskAsdpFxn(
                     {
                         SW_BREAKPOINT;
                     }
+                    gCbWrtAfErrCnt=0;   // debug
+                    gDecOpCbWrtAfOvr=0; // decoder output circular buffer overflow count
                     // FL: debug, log circular buffer control variables
                     cbLog(pCbCtl, z, 1, "cbWriteStart");
                     // Reset audio frame
@@ -712,13 +720,13 @@ Void taskAsdpFxn(
                         cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
                         if (cbErrno < 0)
                         {
+                            gCbWrtAfErrCnt++;
                             //SW_BREAKPOINT; // FL: debug
                             
                             if (cbErrno == ASP_DECOP_CB_WRITE_OVERFLOW)
                             {
-                                // Reset circular buffer
-                                cbReset(pCbCtl, z);
-                                // Update overflow count, return if above threshold
+                                // Update underflow count.
+                                // If above underflow threshold, reset circular buffer underflow count.
                                 gDecOpCbWrtAfOvr++;
                                 if (gDecOpCbWrtAfOvr < DEC_OP_CB_WRTAF_OVR_THR)
                                 {
@@ -726,12 +734,28 @@ Void taskAsdpFxn(
                                 }
                                 else 
                                 {
+                                    // Reset circular buffer
+                                    cbReset(pCbCtl, z);
+                                    // 
                                     gDecOpCbWrtAfOvr = 0;
                                 }
                             }
                         }
                         TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
+#if 1 // (***) FL: shows timing of CB write
+                        // (***) debug // B9
+                        {
+                            static Uint8 toggleState = 0;
+                            if (toggleState == 0)
+                                GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
+                            else
+                                GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
+                            toggleState = ~(toggleState);
+                        }
+#endif        
+                        
+                        
                         // FL: debug, log circular buffer control variables
                         cbLog(pCbCtl, z, 1, "cbWriteAf");
                     }
index cb0adfafc00233232d16927705ba80a98f667bf4..e791f6c141cb30bb34f29dbb030135f1a0d37177 100644 (file)
@@ -311,7 +311,8 @@ UInt32 gcapIb_cnt               =0;
 UInt32 gAsipInfo2_PrimaryErrCnt =0;
 UInt32 gAsipInfo2_ErrCnt        =0;
 // debug
-UInt32 gCbErrnoCnt              =0; // decoder circular buffer error count (write on ARM returned to DSP)
+UInt32 gCbWrtAfErrCnt           =0; // // decoder output circular buffer write error count (returned from ARM to DSP)
+                                   
 
 #include "dbgDib.h" // debug
 
@@ -321,7 +322,6 @@ extern struct {
 } IACP_STD_BETA_TABLE;
 
 // FL: debug
-#include "evmc66x_pinmux.h"
 #include "evmc66x_gpio_dbg.h"
 
 /*
@@ -3447,7 +3447,7 @@ PAF_ASIT_decodeDecode(
                 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
                 if (cbErrno != 0)
                 {
-                    gCbErrnoCnt++;
+                    gCbWrtAfErrCnt++;
                     TRACE_TERSE1("CB write error=%d", cbErrno);
                     //SW_BREAKPOINT; // temporary
                 }
index 2395334e7899a833b0aee625d52d69fbbb95392f..eae79357db92cd1c75ef626540721e7f1774a0cd 100644 (file)
@@ -119,8 +119,8 @@ PAF_ASOT_Config gPAF_ASOT_config = {
     &gPAF_AST_config    // pAstCfg
 };
 
-// Underflow threshold before returning error to Top-Level FSM
-#define DEC_OP_CB_RDAF_UND_THR  ( 20 ) // FL: arbitrary setting
+// Underflow threshold before circular buffer reset and return error to Top-Level FSM
+#define DEC_OP_CB_RDAF_UND_THR  ( 80 ) // FL: arbitrary setting
 UInt32 gDecOpCbRdAfUnd  =0; // decoder output circular buffer underflow count
 
 // Global debug counters */
@@ -1665,6 +1665,9 @@ PAF_ASOT_decodeInit(
             SW_BREAKPOINT; // FL: debug
             return errno;
         }
+        gCbReadAfErr=0;     // debug
+        gDecOpCbRdAfUnd=0;  // decoder output circular buffer underflow count
+
         // FL: debug
         cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
     }
@@ -1693,6 +1696,7 @@ PAF_ASOT_decodeInit(
         }
     }
     
+    
     return 0;
 }
 
@@ -1868,15 +1872,23 @@ PAF_ASOT_decodeStream(
             
             if (cbErrno == ASP_DECOP_CB_READ_UNDERFLOW)
             {
-                // Reset circular buffer
-                //cbReset(pCbCtl, z);
-                //Log_info0("PAF_ASOT_decodeStream:cbReset");
-
-                // Update underflow count, return if above threshold
+                // FL: some number of underflows alway occur on start of stream when ASOT only depends on configured Output.
+                //     DDP: ~2 underflows
+                //     MAT-THD: ~16 underflows
+                // Underflows are accumulated across streams since ASOT continues to run.
+                // This means underflow threshold will be reached if enough streams are run.
+                // Need to check behavior on exit/re-entry into Output processing.
+                
+                // Update underflow count.
+                // If above underflow threshold, reset circular buffer underflow count.
                 gDecOpCbRdAfUnd++;
-                //if (gDecOpCbRdAfUnd == DEC_OP_CB_RDAF_UND_THR)
+                //if (gDecOpCbRdAfUnd == DEC_OP_CB_RDAF_UND_THR) 
                 //{
-                //    gDecOpCbRdAfUnd = 0;
+                //    // Reset circular buffer
+                //    cbReset(pCbCtl, z);
+                //    Log_info0("PAF_ASOT_decodeStream:cbReset");
+                //
+                //    gDecOpCbRdAfUnd = 0; // reset underflow count
                 //    return cbErrno;
                 //}
             }