PASDK-183: merged latest framework updates.
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProc.c
index a00036d99b443cbdcf335bb4a3fabb573c2ebb55..264e929bbb8ad0be7a2597f222e1bbc11678dc31 100644 (file)
@@ -298,13 +298,21 @@ PAF_ASIT_Config gPAF_ASIT_config = {
 };
 
 // Global debug counters */
-UInt32 gTaskAsipCnt=0; // debug
-UInt32 gAsipInitCnt     =0;
-UInt32 gAsipInfo1Cnt    =0;
-UInt32 gAsipInfo2Cnt    =0;
-UInt32 gAsipDecodeCnt   =0;
-UInt32 gAsipFinalCnt    =0;
-UInt32 gAsipQuitCnt     =0;
+UInt32 gTaskAsipCnt             =0;
+UInt32 gAsipInitCnt             =0;
+UInt32 gAsipInfo1Cnt            =0;
+UInt32 gAsipInfo2Cnt            =0;
+UInt32 gAsipDecodeCnt           =0;
+UInt32 gAsipDecodeErrCnt        =0;
+UInt32 gAsipFinalCnt            =0;
+UInt32 gAsipQuitCnt             =0;
+UInt32 gAsipInfo1_PrimaryErrCnt =0;
+UInt32 gAsipInfo1_ErrCnt        =0;
+UInt32 gAsipInfo2_PrimaryErrCnt =0;
+UInt32 gAsipInfo2_ErrCnt        =0;
+UInt32 gCapIbReset_cnt          =0;
+UInt32 gCapIb_cnt               =0;
+UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count (returned from ARM to DSP)
 #include "dbgDib.h"
 
 extern struct {
@@ -339,13 +347,9 @@ Void taskAsipFxn(
 #ifdef NON_CACHE_STATUS
     Int8 tempVar8;
 #endif
+    Task_Handle taskHandle;
 
     Log_info0("Enter taskAsipFxn()");
-    
-#ifdef SIMULATE_SIO
-    /* Start simulation */
-    simStart();
-#endif // SIMULATE_SIO
 
     //
     // Audio Framework Parameters & Patch (*pP, *pQ)
@@ -375,6 +379,8 @@ Void taskAsipFxn(
     pAstCfg->as = as;    
     TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
 
+    taskHandle = Task_self();
+    
     //
     // Initialize message log trace and line number reporting
     //
@@ -874,8 +880,9 @@ Void taskAsipFxn(
 
         // FL: debug, reset IB capture buffer
         capIbReset();
+        gCapIbReset_cnt++;
         Log_info0("capIbReset()");
-        
+
         // FL: send source select message to slave
         pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
         MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
@@ -922,6 +929,9 @@ Void taskAsipFxn(
         
         TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
 
+        // Reduce priority level since autodetection complete
+        Task_setPri(taskHandle, Task_getPri(taskHandle)-1);
+        
         TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
         errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
         if (errno) 
@@ -933,6 +943,9 @@ Void taskAsipFxn(
             TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
         }        
 
+        // Increase priority level since decoding complete
+        Task_setPri(taskHandle, Task_getPri(taskHandle)+1);
+
         // FL: send dec exit message to slave
         pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
         MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
@@ -1922,6 +1935,10 @@ PAF_ASIT_autoProcessing(
     return errno;
 } //PAF_ASIT_autoProcessing
 
+UInt32 gProbe1Err=0;
+UInt32 gProbe2Err=0;
+UInt32 gMajorAuMissed=0;
+
 // -----------------------------------------------------------------------------
 // ASIT Processing Function - Decode Processing
 //
@@ -2013,7 +2030,7 @@ PAF_ASIT_decodeProcessing(
     Int frame; // decoder input frame count
     Int block; // (***) FL: formerly  -- decoder output block count / input frame
 #ifdef NON_CACHE_STATUS
-    Int8 tempVar8, tempVar8_2;
+    Int8 tempVar8, temp2Var8;
 #endif
     
     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
@@ -2042,6 +2059,10 @@ PAF_ASIT_decodeProcessing(
 
     for (;;) 
     {
+        statusOp_read(&tempVar8,
+                      &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
+                      sizeof(tempVar8),
+                      GATEMP_INDEX_DEC);
         if (tempVar8 == PAF_SOURCE_NONE)
         {
 #else
@@ -2161,6 +2182,7 @@ PAF_ASIT_decodeProcessing(
                 // Establish primary timing
                 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
                 {
+                    gAsipInfo1_PrimaryErrCnt++;
                     TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
                     break;
                 }
@@ -2178,19 +2200,15 @@ PAF_ASIT_decodeProcessing(
                               &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
                               sizeof(tempVar8),
                               GATEMP_INDEX_DEC);
-
-                statusOp_read(&tempVar8_2,
+                statusOp_read(&temp2Var8,
                               &(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
                               sizeof(tempVar8),
                               GATEMP_INDEX_DEC);
                 // Don't start decode until major access unit is found.
                 if (((tempVar8 == PAF_SOURCE_THD)    ||
                      (tempVar8 == PAF_SOURCE_DXP)    ||
-                     (tempVar8 == PAF_SOURCE_DTSHD))
-                        &&
-                     //(pAstCfg->xStr[zMS].pAudioFrame->sampleRate == PAF_SAMPLERATE_UNKNOWN)
-                     (tempVar8_2 == PAF_SAMPLERATE_UNKNOWN)  // debug chitresh as per govind
-                        )
+                     (tempVar8 == PAF_SOURCE_DTSHD)) &&
+                     (temp2Var8 == PAF_SAMPLERATE_UNKNOWN)) 
 #else
                 // Don't start decode until major access unit is found.
                 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD)    ||
@@ -2218,12 +2236,14 @@ PAF_ASIT_decodeProcessing(
                             if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
                                 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
                             {
+                                gProbe2Err++;
                                 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
                                 return (ASPERR_ISSUE);
                             }
                         }
                     }
                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
+                    gMajorAuMissed++; // debug
                     frame++;
                     state = INFO1;
                     continue;
@@ -2234,6 +2254,7 @@ PAF_ASIT_decodeProcessing(
                 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
                 {
                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x.  break after decodeInfo1", errno);
+                    gAsipInfo1_ErrCnt++;
                     break;
                 }
 
@@ -2262,6 +2283,7 @@ PAF_ASIT_decodeProcessing(
                 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
                 {
                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
+                    gAsipInfo2_PrimaryErrCnt++;
                     break;
                 }
 
@@ -2275,6 +2297,7 @@ PAF_ASIT_decodeProcessing(
                 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
                 {
                     TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
+                    gAsipInfo2_ErrCnt++;
                     break;
                 }
 
@@ -2295,6 +2318,7 @@ PAF_ASIT_decodeProcessing(
             
                 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
                 {
+                    gAsipDecodeErrCnt++;
                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
                     break;
                 }
@@ -2487,7 +2511,6 @@ PAF_ASIT_decodeInit(
     Int zMI;
     ASP_Msg* pAspMsg;                   /* Messaging */
     Int argIdx;
-    Int decErrno;
     Int status;
 #ifdef NON_CACHE_STATUS
     Int8 tempVar8;
@@ -2647,14 +2670,13 @@ PAF_ASIT_decodeInit(
                 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
 
                 argIdx = 0; // get decErrno
-                decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
-                if (decErrno != 0)
-                {
-                    return decErrno;
-                }
+                errno = *(Int32 *)&pAspMsg->buf[argIdx];
             }
             else
             {
+                //
+                // Invalid message received
+                //
                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
                 SW_BREAKPOINT; // temporary
                 return -1; // temporary
@@ -2665,11 +2687,11 @@ PAF_ASIT_decodeInit(
             {
                 SW_BREAKPOINT;
             }
-
+            
             // (***) FL: revisit
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
-            Cache_wait();                            
+            Cache_wait();
             
 #if 0 // FL: decoder reset call, slave
             if (dec->fxns->reset
@@ -2677,6 +2699,10 @@ PAF_ASIT_decodeInit(
                                               &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
                 return errno;
 #endif
+            if (errno != 0)
+            {
+                return errno;
+            }
             
 #ifdef NON_CACHE_STATUS
             gear = 0;  // due to size difference
@@ -3004,15 +3030,26 @@ PAF_ASIT_decodeInfo(
                 SW_BREAKPOINT;
                 return -1; // temporary
             }
-            if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) || 
-                (pAspMsg->cmd != ASP_MASTER_DEC_INFO_DONE) || 
-                (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
+            if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
+                (pAspMsg->cmd == ASP_MASTER_DEC_INFO_DONE) && 
+                (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
+            {
+                hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
+                TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
+                TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
+                
+                argIdx = 0; // get decErrno
+                errno = *(Int32 *)&pAspMsg->buf[argIdx];
+            }
+            else
             {
+                //
+                // Invalid message received
+                //
                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
                 SW_BREAKPOINT; // temporary
-            }           
-            hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
-            TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
+                return -1; // temporary
+            }
             // free the message
             status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
             if (status != MessageQ_S_SUCCESS)
@@ -3037,6 +3074,7 @@ PAF_ASIT_decodeInfo(
                 TRACE_TERSE1("return error errno 0x%x.", errno);
                 return errno;
             }
+
 #ifdef NON_CACHE_STATUS
             statusOp_read(&tempVar,
                           &(pAstCfg->xDec[z].decodeStatus.frameCount),
@@ -3397,18 +3435,22 @@ PAF_ASIT_decodeDecode(
                 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
                 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
                 
-                argIdx = 0;
+                argIdx = 0; // get decErrno
                 errno = *(Int32 *)&pAspMsg->buf[argIdx];
-                argIdx += sizeof(Int32);
+                argIdx += sizeof(Int32); // get cbErrno
                 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
                 if (cbErrno != 0)
                 {
+                    gCbWrtAfErrCnt++;
                     TRACE_TERSE1("CB write error=%d", cbErrno);
                     SW_BREAKPOINT; // temporary
                 }
             }
             else
             {
+                //
+                // Invalid message received
+                //
                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
                 SW_BREAKPOINT; // temporary
             }