]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/test_dsp/framework/audioStreamOutProc.c
Split ASIP and ASOP initialization into separate routines.
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutProc.c
index 3f2f22907911ae1e08f6ba16b978d9836e530f17..e744cd2a7b02ce31c0e60d0fb084e27924c9e26e 100644 (file)
@@ -70,8 +70,61 @@ Int32 gNumPfpAsot1=0; // debug
 #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,7 +297,12 @@ UInt32 gDecOpCbRdAfUnd      =0; // decoder output circular buffer underflow coun
 UInt32 gMaxDecOpCbRdAfUnd   =0; // max (consecutive) decoder output circular buffer underflow count
 UInt32 gMasterCbResetCnt    =0; // master circular buffer reset count
 
+// For writeDECCommandRestart
+extern volatile UInt32 gCommandOutputTask_SYNC;
+extern volatile UInt32 gCommandOutputTask_ACK;
+
 // Global debug counters */
+UInt32 gAsopTxSioReclaimCnt         =0;
 UInt32 gAsopInitOutProcCnt          =0;
 UInt32 gAsopInitSyncDecResetCnt     =0;
 UInt32 gAsopInitSyncDecInfo1Cnt     =0;
@@ -257,14 +315,12 @@ UInt32 gAsopEncodeCnt               =0;
 UInt32 gAsopFinalCnt                =0;
 UInt32 gAsopOutSioUpdateCnt         =0;
 UInt32 gAsopQuitCnt                 =0;
-UInt32 gAsopTxSioReclaimCnt         =0;
 
 /*
- *  ======== taskAsopFxn ========
- *  Audio Stream Output Processing task function
+ *  ======== taskAsopFxnInit ========
+ *  Audio Stream Output Processing initialization function
  */
-Void taskAsopFxn(
-//    Int betaPrimeValue, // FL: revisit
+Void taskAsopFxnInit(
     const PAF_ASOT_Params *pP,
     const PAF_ASOT_Patchs *pQ
 )
@@ -275,25 +331,13 @@ Void taskAsopFxn(
     Int z;                          /* input/encode/stream/decode/output counter */
     Int i;                          /* phase */
     Int zMS;
-    Int errno;                      // error number
-    Int8 procSleep;                 // whether to sleep: 0: No, 1: Yes
-    Int8 procOutDevSel;             // whether to perform output device selection: 0: No, 1:Yes
-    Int outSel;                     // whether output device selected
-    enum { INIT_OUT_PROC_STATE, 
-           INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_DEC_DECODE1_STATE, 
-           INITSYNC_RESYNC_STATE, 
-           OUT_PROC_STATE } state;
-    PAF_AudioFrame decResetAf;
-    PAF_AudioFrame decInfo1Af;
-    Int loopCount = 0;              // used to stop trace to see startup behavior.
-    
 
-    Log_info0("Enter taskAsopFxn()");    
+    Log_info0("Enter taskAsopFxnInit()");
 
     //
     // Audio Stream Output Task Parameters & Patch (*pP, *pQ)
     //
-    if (!pP) 
+    if (!pP)
     {
         TRACE_TERSE0("TaskAsop: No Parameters defined. Exiting.");
         LINNO_RPRT(TaskAsop, -1);
@@ -302,10 +346,10 @@ Void taskAsopFxn(
 
     if (!pQ)
     {
-        TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
+        TRACE_TERSE0("TaskAsop: No Patchs defined. Exiting.");
         LINNO_RPRT(TaskAsop, -1);
         return;
-    }    
+    }
 
     //
     // Audio Stream Output Task Configuration (*pAsotCfg):
@@ -314,7 +358,7 @@ Void taskAsopFxn(
     pAsotCfg->taskHandle = Task_self(); // set task handle
     pAstCfg = pAsotCfg->pAstCfg;        // get pointer to AST common (shared) configuration
 
-    /* Obtain Audio Stream Number (1, 2, etc.) */    
+    /* Obtain Audio Stream Number (1, 2, etc.) */
     as = pAstCfg->as;
     TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
 
@@ -326,7 +370,7 @@ Void taskAsopFxn(
         TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
     }
     LINNO_RPRT(TaskAsop, -1);
-    
+
     //
     // Determine stream index
     //
@@ -351,36 +395,80 @@ Void taskAsopFxn(
         if (pP->fxns->initPhase[i])
         {
             linno = pP->fxns->initPhase[i](pP, pQ, pAsotCfg);
-            if (linno) 
+            if (linno)
             {
                 LINNO_RPRT(TaskAsop, linno);
                 return;
             }
         }
-        else 
+        else
         {
             TRACE_TERSE1("TaskAsop: AS%d: initialization phase - null", as+zMS);
         }
         TRACE_TERSE2("TaskAsop: AS%d: initialization phase - %d completed", as+zMS, i);
         LINNO_RPRT(TaskAsop, -i-3);
     }
-  
+
     //
     // End of Initialization -- display memory usage report.
     //
     if (pP->fxns->memStatusPrint)
     {
         pP->fxns->memStatusPrint("ASOT MEMSTAT REPORT",
-            HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, 
+            HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL,
             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
     }
+} /* taskAsopFxnInit */
+
+
+/*
+ *  ======== taskAsopFxn ========
+ *  Audio Stream Output Processing task function
+ */
+Void taskAsopFxn(
+//    Int betaPrimeValue, // FL: revisit
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ
+)
+{
+    PAF_ASOT_Config *pAsotCfg;      /* ASOT configuration pointer */
+    PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
+    Int as;                         /* Audio Stream Number (1, 2, etc.) */
+    Int z;                          /* input/encode/stream/decode/output counter */
+    Int zMS;
+    Int errno;                      // error number
+    Int8 procSleep;                 // whether to sleep: 0: No, 1: Yes
+    Int8 procOutDevSel;             // whether to perform output device selection: 0: No, 1:Yes
+    Int outSel;                     // whether output device selected
+    enum { INIT_OUT_PROC_STATE, 
+           INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_DEC_DECODE1_STATE, 
+           INITSYNC_RESYNC_STATE, 
+           OUT_PROC_STATE } state;
+    PAF_AudioFrame decResetAf;
+    PAF_AudioFrame decInfo1Af;
+    Int loopCount = 0;              // used to stop trace to see startup behavior.
+
+    Log_info0("Enter taskAsopFxn()");
+
+    taskAsopFxnInit(pP, pQ);    // initialization of output task
+
+    //
+    // Audio Stream Output Task Configuration (*pAsotCfg):
+    //
+    pAsotCfg = &gPAF_ASOT_config;       // initialize pointer to task configuration
+    pAstCfg = pAsotCfg->pAstCfg;        // get pointer to AST common (shared) configuration
+
+    /* Obtain Audio Stream Number (1, 2, etc.) */    
+    as = pAstCfg->as;
+    
+    zMS = pAstCfg->masterStr;
 
     //
     // Main processing loop
     //   
     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
@@ -396,6 +484,20 @@ Void taskAsopFxn(
         // Check forward (ASIT) error here, TBD
         //
         
+        // Even if we are not in error state, we check if writeDECCommandRestar issued or not
+        if (gCommandOutputTask_SYNC) {
+            TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Wait for the command deasserted");
+            gCommandOutputTask_ACK = 1;
+            while (gCommandOutputTask_SYNC) {
+                Task_sleep(1);
+            }
+            TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Startover the process");
+            procSleep = 1;                  // init sleep flag -- sleep
+            procOutDevSel = 1;              // init device output selection flag -- perform output device selection
+            state = INIT_OUT_PROC_STATE;    // init state -- starover
+            errno = ASOP_DP_FORWARD_ERR;    // Override the error -- for flushing SIO output device
+        }
+        
         // any error forces idling of output
         if (errno) 
         {
@@ -409,8 +511,8 @@ Void taskAsopFxn(
         
             TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
             ERRNO_RPRT(TaskAsop, errno);
-        }        
-    
+        }
+        
         if (procSleep == 1)
         {
             TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
@@ -1760,7 +1862,13 @@ PAF_ASOT_decodeProcessing(
         // Check forward (ASIT) error here, TBD
         //
         
-        
+        // If writeDECCommandRestart issued, force exit the statemachine
+        if (gCommandOutputTask_SYNC) {
+            TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: writeDECCommandRestart issued in state=0x%x ... exiting core loop", state);
+            errno = ASOP_DP_FORWARD_ERR;
+            break;
+        }
+
         // Check if any change in output SIO, e.g. from Output shortcut.
         // Changes will break FSM and allow Output reconfiguration.
         errno = checkOutSio(pP, pAsotCfg, &outSioUpdate);
@@ -2062,7 +2170,7 @@ PAF_ASOT_encodeCommand(
 } //PAF_ASOT_encodeCommand
 
 //debug -- allow dynamic config
-Int16 gStrFrameLen=DEF_STR_FRAME_LEN; // stream frame length (PCM samples)
+//Int16 gStrFrameLen=DEF_STR_FRAME_LEN; // stream frame length (PCM samples)
 
 //   Purpose:   Decoding Function for reinitializing the decoding process.
 Int
@@ -2086,13 +2194,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); // use pP->frameLength from ASOT params
-        errno = cbInitStreamRead(pCbCtl, z, gStrFrameLen);
+        //errno = cbInitStreamRead(pCbCtl, z, gStrFrameLen);
+        errno = cbInitStreamRead(pCbCtl, z);
         if (errno)
         {
             TRACE_TERSE1("PAF_ASOT_decodeInit:cbInitStreamRead() error=%d", errno);
@@ -2310,7 +2414,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;
 
 
@@ -2326,9 +2430,9 @@ 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);
+        //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))
@@ -2378,7 +2482,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
@@ -2393,17 +2497,19 @@ PAF_ASOT_decodeStream(
             }
 #endif
 
-        // FL: debug
-        // Get circular buffer statistics (debug)
+        // debug, get circular buffer statistics
         //cbGetStats(pCbCtl, z, &cbStats);
         cbGetStats(pCbCtl, z, &gCbStats);
 
         // debug
         cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
-        //if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
-        //{
-        //    Log_info0("capAfWrite() error");
-        //}
+        
+#if 0 // debug, capture audio frame
+        if (capAfWrite(pAfRd, PAF_LEFT) != CAP_AF_SOK)
+        {
+            Log_info0("capAfWrite() error");
+        }
+#endif
     }
             
     TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
@@ -2446,7 +2552,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;
@@ -2472,9 +2579,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);
@@ -2483,7 +2590,7 @@ PAF_ASOT_decodeEncode(
             }
             // TODO: use pC->xOut[z].pOutBuf in following ->encode call
 
-#if 0 // (***) FL: shows timing of Output Rx SIO reclaim
+#if 0 // (***) FL: shows timing of Output Tx SIO reclaim
             // (***) debug // B8
             {
                 static Uint8 toggleState = 0;
@@ -2495,15 +2602,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 
         {
@@ -2602,10 +2709,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);
@@ -2976,14 +3083,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
@@ -3453,7 +3552,7 @@ static Int PAF_ASOT_outputReset(
 }
 
 // FL: debug, allow modification of output frame length via JTAG
-Int16 gOutFrameLen=DEF_STR_FRAME_LEN; // stream frame length (PCM samples)
+Int16 gOutFrameLen=PAF_ASOT_FRAMELENGTH; // output frame length (PCM samples)
 
 //   Purpose:   Init-Sync Dec Info1 state function.
 //              Performes Dec Info1 Init-Sync.
@@ -3710,9 +3809,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;