]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/test_dsp/framework/audioStreamOutProc.c
PASDK-376:Remove GPIO debug for release
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutProc.c
index 480edc03b841f22c1e9fc2633d156ed2b3af0239..63789bcc5f7093e56e425e6c5ce31c933c3e8846 100644 (file)
@@ -67,10 +67,64 @@ Int32 gNumPfpAsot1=0; // debug
 
 // FL: debug
 #include "evmc66x_gpio_dbg.h"
+#include "dbgCapAf.h"
 
 
+// -----------------------------------------------------------------------------
+// Debugging Trace Control, local to this file.
+// 
+#include "logp.h"
+
 #define TRACE_TIME(a)
 
+// Allow a developer to selectively enable tracing.
+#define CURRENT_TRACE_MASK      0x07
+
+#define TRACE_MASK_TERSE        0x01   // only flag errors and show init
+#define TRACE_MASK_GENERAL      0x02   // half dozen lines per frame
+#define TRACE_MASK_VERBOSE      0x04   // trace full operation
+
+#if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
+    #undef  TRACE_TERSE0
+    #undef  TRACE_TERSE1
+    #undef  TRACE_TERSE2
+    #undef  TRACE_TERSE3
+    #undef  TRACE_TERSE4
+    #define TRACE_TERSE0(a)
+    #define TRACE_TERSE1(a,b)
+    #define TRACE_TERSE2(a,b,c)
+    #define TRACE_TERSE3(a,b,c,d)
+    #define TRACE_TERSE4(a,b,c,d,e)
+#endif
+    
+#if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
+    #undef  TRACE_GEN0
+    #undef  TRACE_GEN1
+    #undef  TRACE_GEN2
+    #undef  TRACE_GEN3
+    #undef  TRACE_GEN4
+    #define TRACE_GEN0(a)
+    #define TRACE_GEN1(a,b)
+    #define TRACE_GEN2(a,b,c)
+    #define TRACE_GEN3(a,b,c,d)
+    #define TRACE_GEN4(a,b,c,d,e)
+#endif
+
+#if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
+    #undef  TRACE_VERBOSE0
+    #undef  TRACE_VERBOSE1
+    #undef  TRACE_VERBOSE2
+    #undef  TRACE_VERBOSE3
+    #undef  TRACE_VERBOSE4
+    #define TRACE_VERBOSE0(a)
+    #define TRACE_VERBOSE1(a,b)
+    #define TRACE_VERBOSE2(a,b,c)
+    #define TRACE_VERBOSE3(a,b,c,d)
+    #define TRACE_VERBOSE4(a,b,c,d,e)
+#endif
+
+// .............................................................................
+
 //
 // Audio Stream Definitions
 //
@@ -244,6 +298,7 @@ UInt32 gMaxDecOpCbRdAfUnd   =0; // max (consecutive) decoder output circular buf
 UInt32 gMasterCbResetCnt    =0; // master circular buffer reset count
 
 // Global debug counters */
+UInt32 gAsopTxSioReclaimCnt         =0;
 UInt32 gAsopInitOutProcCnt          =0;
 UInt32 gAsopInitSyncDecResetCnt     =0;
 UInt32 gAsopInitSyncDecInfo1Cnt     =0;
@@ -256,8 +311,6 @@ UInt32 gAsopEncodeCnt               =0;
 UInt32 gAsopFinalCnt                =0;
 UInt32 gAsopOutSioUpdateCnt         =0;
 UInt32 gAsopQuitCnt                 =0;
-UInt32 gAsopTxSioReclaimCnt         =0;
-
 
 /*
  *  ======== taskAsopFxn ========
@@ -302,7 +355,7 @@ Void taskAsopFxn(
 
     if (!pQ)
     {
-        TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
+        TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
         LINNO_RPRT(TaskAsop, -1);
         return;
     }    
@@ -380,7 +433,7 @@ Void taskAsopFxn(
     //   
     for (z=STREAM1; z < STREAMN; z++)
     {
-        TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
+        TRACE_VERBOSE1("TaskAsop: AS%d: running", as+z);
     }
     
     errno = 0;                      // init error indicator -- no error
@@ -1704,6 +1757,8 @@ PAF_ASOT_selectDevices(
             }
         }
 
+/* No need to start-clocks here, since only selecting the device. */
+#if 0
         // if device selected and valid then enable stat tracking if
         // required and start clocking
         if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio)) 
@@ -1720,6 +1775,7 @@ PAF_ASOT_selectDevices(
                 }
             }
         }
+#endif
     }
 
     return errno;
@@ -2058,6 +2114,9 @@ PAF_ASOT_encodeCommand(
     return 0;
 } //PAF_ASOT_encodeCommand
 
+//debug -- allow dynamic config
+//Int16 gStrFrameLen=DEF_STR_FRAME_LEN; // stream frame length (PCM samples)
+
 //   Purpose:   Decoding Function for reinitializing the decoding process.
 Int
 PAF_ASOT_decodeInit(
@@ -2080,12 +2139,9 @@ PAF_ASOT_decodeInit(
 
     for (z=DECODE1; z < DECODEN; z++)
     {
-        //  FRAMELENGTH: pP->frameLength.
-        //    Formerly ASIT, now ASOT but same value (PAF_SYS_FRAMELENGTH).
-        //
-
         // Initialize decoder output circular buffer for stream reads
-        errno = cbInitStreamRead(pCbCtl, z, FRAMELENGTH);
+        //errno = cbInitStreamRead(pCbCtl, z, gStrFrameLen);
+        errno = cbInitStreamRead(pCbCtl, z);
         if (errno)
         {
             TRACE_TERSE1("PAF_ASOT_decodeInit:cbInitStreamRead() error=%d", errno);
@@ -2303,7 +2359,7 @@ PAF_ASOT_decodeStream(
     Int z;                              /* decode/stream counter */
     PAF_AudioFrame *pAfRd;
     Int cbErrno;
-    PAF_AST_DecOpCircBufStats cbStats;  /* circular buffer statistics */
+    //PAF_AST_DecOpCircBufStats cbStats;  /* circular buffer statistics */
     Int errno;
 
 
@@ -2319,26 +2375,25 @@ PAF_ASOT_decodeStream(
         // Read decoder output circular buffer
         //
         pAfRd = pAstCfg->xStr[zS].pAudioFrame;
-        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);   // debug
+        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);       // debug
         cbErrno = cbReadAf(pCbCtl, z, pAfRd);
-        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
-        if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_READ_UNDERFLOW))
+        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);     // debug
+        if ((cbErrno < 0) && 
+            (cbErrno != ASP_DECOP_CB_AF_READ_UNDERFLOW) && 
+            (cbErrno != ASP_DECOP_CB_PCM_READ_UNDERFLOW))
         {
             gCbReadAfErr++;
             TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
-            //SW_BREAKPOINT; // FL: debug
+            //SW_BREAKPOINT; // debug
             return cbErrno;
         }
 
         // Handle underflows
-        if (cbErrno == ASP_DECOP_CB_READ_UNDERFLOW)
+        if ((cbErrno == ASP_DECOP_CB_AF_READ_UNDERFLOW) ||
+            (cbErrno == ASP_DECOP_CB_PCM_READ_UNDERFLOW))
         {
-            // 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
-            // Need to check behavior of cbReset().
+            // (***) FL: Need to check behavior of cbReset().
             // Need to check behavior on exit/re-entry into Output processing.
-            
             gDecOpCbRdAfUnd++; // increment circular buffer underflow count
             if (gDecOpCbRdAfUnd >= DEC_OP_CB_RDAF_UND_THR) 
             {
@@ -2372,7 +2427,7 @@ PAF_ASOT_decodeStream(
             gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
         }
         //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
-        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
+        //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);   // debug
         Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
         
 #if 0 // (***) FL: shows timing of CB read
@@ -2392,9 +2447,9 @@ PAF_ASOT_decodeStream(
         //cbGetStats(pCbCtl, z, &cbStats);
         cbGetStats(pCbCtl, z, &gCbStats);
 
-        // FL: debug
+        // debug
         cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
-        //if (capAfWrite(pAfRd, 0) != CAP_AF_SOK)
+        //if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
         //{
         //    Log_info0("capAfWrite() error");
         //}
@@ -2440,7 +2495,8 @@ PAF_ASOT_decodeEncode(
     Int z;                      /* encode/output counter */
     Int errno;                  /* error number */
     Int zX, zE, zS;
-    UInt32 curTime;
+    // debug
+    //UInt32 curTime;
 
     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
     as = pAstCfg->as;
@@ -2466,9 +2522,9 @@ PAF_ASOT_decodeEncode(
             pAstCfg->xOut[z].outBufConfig.lengthofFrame = 
                 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
             TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- idle", as+zS, block);
-            //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
+            //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);   // debug
             errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
-            //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
+            //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);     // debug
             if (errno < 0)
             {
                 SIO_idle(pAstCfg->xOut[z].hTxSio);
@@ -2489,15 +2545,15 @@ PAF_ASOT_decodeEncode(
             }
 #endif            
 
-            gAsopTxSioReclaimCnt++;
-
             //
             // Simulate Tx SIO_reclaim() pend
             //
             //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
-            curTime = Clock_getTicks();
-            //System_printf("System time in TaskAsipFxn Tx audio = %lu\n", (ULong)curTime);
+            //curTime = Clock_getTicks();
+            //System_printf("System time in TaskAsopFxn Tx audio = %lu\n", (ULong)curTime);
             //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
+            
+            gAsopTxSioReclaimCnt++;
         }
         else 
         {
@@ -2596,10 +2652,10 @@ PAF_ASOT_decodeEncode(
         if (pAstCfg->xOut[z].hTxSio) 
         {
             TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
-            GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106); // debug
+            //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);       // debug
             errno = SIO_issue(pAstCfg->xOut[z].hTxSio, 
                 &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
-            GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
+            //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);     // debug
             if (errno)
             {
                 SIO_idle(pAstCfg->xOut[z].hTxSio);
@@ -2747,7 +2803,7 @@ PAF_ASOT_startOutput(
     PAF_AST_Config *pAstCfg;
     Int as;                     /* Audio Stream Number (1, 2, etc.) */
     Int z;                      /* output counter */
-    Int errno,nbufs;            /* error number */
+    Int errno,nbufs, errme;            /* error number */
     Int zE, zS, zX;
     Int zMD;
     PAF_SIO_IALG_Obj    *pObj;
@@ -2775,6 +2831,26 @@ PAF_ASOT_startOutput(
                 }
             }
 
+// Need to Revisit: Starting Clocks here seems logical & also manages the McASP without spurious underruns .
+
+#if 1
+            // if device selected and valid then enable stat tracking if
+                       // required and start clocking
+                       if ((pAstCfg->xOut[z].outBufStatus.sioSelect < 0) && (pAstCfg->xOut[z].hTxSio))
+                       {
+                               TRACE_VERBOSE0("PAF_ASOT_startOutput: start SIO clocks");
+                               errme = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_OUTPUT_START_CLOCKS, 0);
+                               if (errno)
+                               {
+                                       TRACE_VERBOSE2("PAF_ASOT_startOutput: errme 0x%x, errno 0x%x", errme, errno);
+                                       SIO_idle(pAstCfg->xOut[z].hTxSio);
+                                       if (!errno)
+                                       {
+                                               errno = ASPERR_DEVOUT + errme;
+                                       }
+                               }
+                       }
+#endif
             // Set sample count so that DOB knows how much data to send
             pAstCfg->xOut[z].outBufConfig.lengthofFrame =
                 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
@@ -2950,14 +3026,6 @@ PAF_ASOT_stopOutput(
     return errno;
 } //PAF_ASOT_stopOutput
 
-UInt32 gNumRateXCalc1=0;
-UInt32 gNumRateXCalc2=0;
-UInt32 gNumDobErrRateChange=0;
-Int gCheck[100];
-float gRateI[100];
-float gRateO[100];
-float gRateX[100];
-
 
 // -----------------------------------------------------------------------------
 // ASOT Decoding Function Helper - SIO Driver Change
@@ -3426,6 +3494,9 @@ static Int PAF_ASOT_outputReset(
     return ASOP_SOK;
 }
 
+// FL: debug, allow modification of output frame length via JTAG
+Int16 gOutFrameLen=PAF_ASOT_FRAMELENGTH; // output frame length (PCM samples)
+
 //   Purpose:   Init-Sync Dec Info1 state function.
 //              Performes Dec Info1 Init-Sync.
 static Int PAF_ASOT_initSyncDecInfo1(
@@ -3477,7 +3548,8 @@ static Int PAF_ASOT_initSyncDecInfo1(
             // THD sets this to 256 (hard-coded in Dec Info)
             // DDP sets this to 0 (audio frame passthrough, 0 from ASDT AF frame length)
             // PCM sets this to 256 (decodeControl.frameLength)
-        pDecInfo1Af->sampleCount = 256;                        // !!!! Revisit !!!!
+        //pDecInfo1Af->sampleCount = 256;                      // !!!! GJ: Revisit !!!!
+        pDecInfo1Af->sampleCount = gOutFrameLen;
         
         outIsCpyAf(pDecInfo1Af, pStrAf);
 
@@ -3485,7 +3557,7 @@ static Int PAF_ASOT_initSyncDecInfo1(
             // THD sets this to 256 (hard-coded in Dec Info)
             // DDP sets this to 0 (audio frame passthrough, 0 from ASDT AF frame length)
             // PCM sets this to 256 (decodeControl.frameLength)
-        //pStrAf->sampleCount = 256;                   // !!!! Revisit !!!!
+        //pStrAf->sampleCount = 256;                   // !!!! GJ: Revisit !!!!
 
         // outputInfo1():
         //      - ASP chain reset,
@@ -3680,9 +3752,9 @@ PAF_ASOT_decodeFinalTest(
     zMD = pAsotCfg->pAstCfg->masterDec; // get master Dec index
 
     // Check circular buffer drain state
-    //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);
+    //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);     // debug
     errno = cbCheckDrainState(pCbCtl, zMD, &drainedFlag);
-    //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
+    //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);   // debug
     if (errno < 0)
     {
         return errno;