PASDK-218:Update ASOT top-level State Machine.
authorFrank Livingston <frank-livingston@ti.com>
Tue, 11 Jul 2017 03:19:41 +0000 (22:19 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Tue, 11 Jul 2017 03:19:41 +0000 (22:19 -0500)
Allow state transitions to skip Task sleep and output device selection.
This can be improved with a state transition function (and perhaps state
transition table).

pasdk/test_dsp/framework/audioStreamOutProc.c

index 21cc1172655204b3d7993027b4a3e28ba5b28234..3eb5658f6f564e15cd8d74399320ca5ca1955136 100644 (file)
@@ -274,16 +274,18 @@ Void taskAsopFxn(
     Int as;                         /* Audio Stream Number (1, 2, etc.) */
     Int z;                          /* input/encode/stream/decode/output counter */
     Int i;                          /* phase */
-    Int errno;                      /* error number */
     Int zMS;
-    Int loopCount = 0;  // used to stop trace to see startup behavior.        
-    Int outSel;
+    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()");    
@@ -381,8 +383,10 @@ Void taskAsopFxn(
         TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
     }
     
-    state = INIT_OUT_PROC_STATE;    // initialize state
-    errno = 0;                      // reset error indicator
+    errno = 0;                      // init error indicator -- no error
+    procSleep = 1;                  // init sleep flag -- sleep
+    procOutDevSel = 1;              // init device output selection flag -- perform output device selection
+    state = INIT_OUT_PROC_STATE;    // init state
     for (;;)
     {
         loopCount++;
@@ -406,30 +410,48 @@ Void taskAsopFxn(
             TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
             ERRNO_RPRT(TaskAsop, errno);
         }        
-        
-        TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
-        Task_sleep(1);
-
-        // select output devices
-        TRACE_GEN1("TaskAsop: AS%d: Output device selection ...", as+zMS);
-        errno = pP->fxns->selectDevices(pP, pQ, pAsotCfg);
-        if (errno)
+    
+        if (procSleep == 1)
         {
-            TRACE_TERSE2("TaskAsop: AS%d: selectDevices returned errno = 0x%04x", as+zMS, errno);
-            continue;
+            TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
+            Task_sleep(1);
         }
 
-        // if no output selected skip remaining processing
-        errno = checkOutSel(pP, pAsotCfg, &outSel);
-        if (errno < 0)
-        {
-            TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
-            continue;
-        }
-        else if (!outSel)
+        if (procOutDevSel == 1)
         {
-            TRACE_VERBOSE1("TaskAsop: AS%d: No output selected...", as+zMS);            
-            continue;
+            // select output devices
+            TRACE_GEN1("TaskAsop: AS%d: Output device selection ...", as+zMS);
+            errno = pP->fxns->selectDevices(pP, pQ, pAsotCfg);
+            if (errno)
+            {
+                TRACE_TERSE2("TaskAsop: AS%d: selectDevices returned errno = 0x%04x", as+zMS, errno);
+
+                procSleep = 1;
+                procOutDevSel = 1;
+
+                continue;
+            }
+
+            // if no output selected skip remaining processing
+            errno = checkOutSel(pP, pAsotCfg, &outSel);
+            if (errno < 0)
+            {
+                TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
+
+                procSleep = 1;
+                procOutDevSel = 1;
+
+                continue;
+            }
+            else if (!outSel)
+            {
+                TRACE_VERBOSE1("TaskAsop: AS%d: No output selected...", as+zMS);
+
+                procSleep = 1;
+                procOutDevSel = 1;
+                
+                continue;
+            }
         }
         
         switch (state)
@@ -445,10 +467,14 @@ Void taskAsopFxn(
                 if (errno < 0)
                 {
                     state = INIT_OUT_PROC_STATE;
+                    procSleep = 1;
+                    procOutDevSel = 1;
                 }
                 else
                 {
                     state = INITSYNC_DEC_RESET_STATE;
+                    procSleep = 0;
+                    procOutDevSel = 0;
                 }
             
                 break;
@@ -467,21 +493,30 @@ Void taskAsopFxn(
                 if (errno < 0)
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE errno=%d", errno);
+
                     // sync error -- start over
                     state = INIT_OUT_PROC_STATE;
+                    procSleep = 1;
+                    procOutDevSel = 1;
                 }
                 else if (errno == ASOP_INITSYNC_NOTREADY)
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE not sync'd errno=%d", errno);
+
                     // sync not ready -- try again
                     state = INITSYNC_DEC_RESET_STATE;
                     errno=0; // FL: temp hack
+                    procSleep = 1;
+                    procOutDevSel = 1;
                 }
                 else // errno==0
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE sync'd, errno=%d", errno);
+
                     // sync'd -- move on
                     state = INITSYNC_DEC_INFO1_STATE;
+                    procSleep = 0;
+                    procOutDevSel = 0;
                 }
                 
                 break;
@@ -500,21 +535,30 @@ Void taskAsopFxn(
                 if (errno < 0)
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE errno=%d", errno);
+                    
                     // sync error -- start over
                     state = INIT_OUT_PROC_STATE;
+                    procSleep = 1;
+                    procOutDevSel = 1;
                 }
                 else if (errno == ASOP_INITSYNC_NOTREADY)
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE not sync'd errno=%d", errno);
+
                     // sync not ready -- try again
                     state = INITSYNC_DEC_INFO1_STATE;
                     errno=0; // FL: temp hack
+                    procSleep = 1;
+                    procOutDevSel = 0;
                 }
                 else // errno = 0
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE sync'd errno=%d", errno);
+
                     // sync'd -- move on
                     state = INITSYNC_DEC_DECODE1_STATE;
+                    procSleep = 0;
+                    procOutDevSel = 0;
                 }
                 
                 break;
@@ -533,21 +577,30 @@ Void taskAsopFxn(
                 if (errno < 0)
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE errno=%d", errno);
+
                     // sync error -- start over
                     state = INIT_OUT_PROC_STATE;
+                    procSleep = 1;
+                    procOutDevSel = 1;
                 }
                 else if (errno == ASOP_INITSYNC_NOTREADY)
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE not sync'd errno=%d", errno);
+
                     // sync not ready -- try again
                     state = INITSYNC_DEC_DECODE1_STATE;
                     errno=0; // FL: temp hack
+                    procSleep = 1;
+                    procOutDevSel = 0;
                 }
                 else // errno = 0
                 {
                     Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE sync'd errno=%d", errno);
+
                     // sync'd -- move on
                     state = OUT_PROC_STATE;
+                    procSleep = 0;
+                    procOutDevSel = 0;
                 }
                 
                 break;
@@ -568,14 +621,20 @@ Void taskAsopFxn(
                 if (errno < 0)
                 {
                     Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE errno=%d", errno);
+
                     // sync error -- start over
                     state = INIT_OUT_PROC_STATE;
+                    procSleep = 1;
+                    procOutDevSel = 1;
                 }
                 else
                 {
                     Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE sync'd errno=%d", errno);
+
                     // re-sync'd -- move on
                     state = OUT_PROC_STATE;
+                    procSleep = 0;
+                    procOutDevSel = 0;
                 }
                     
                 break;
@@ -603,11 +662,15 @@ Void taskAsopFxn(
                     {
                         // forward (ASIT) error -- start over
                         state = INIT_OUT_PROC_STATE;
+                        procSleep = 1;
+                        procOutDevSel = 1;
                     }
                     else
                     {
                         // local (ASOT) error
                         state = INITSYNC_RESYNC_STATE;    
+                        procSleep = 1;
+                        procOutDevSel = 0; // disallow device re-select if local error during output processing
                     }        
                 }
                 else if (errno > 0)
@@ -624,6 +687,8 @@ Void taskAsopFxn(
                         // skip re-sync
                         // resume output processing after new output selected
                         state = OUT_PROC_STATE;
+                        procSleep = 1;
+                        procOutDevSel = 1;
                     }
                 }
                 else
@@ -639,6 +704,8 @@ Void taskAsopFxn(
                     // no error returned if CB drained 
                     // (i.e. CB drained is normal behavior)
                     state = INIT_OUT_PROC_STATE;
+                    procSleep = 1;
+                    procOutDevSel = 1;
                 }
                 
                 break;
@@ -2864,6 +2931,7 @@ PAF_ASOT_stopOutput(
     return errno;
 } //PAF_ASOT_stopOutput
 
+
 // -----------------------------------------------------------------------------
 // ASOT Decoding Function Helper - SIO Driver Change
 //
@@ -2912,7 +2980,6 @@ PAF_ASOT_setCheckRateX(
     {
         if (pAstCfg->xOut[z].hTxSio && (pAstCfg->xOut[z].outBufStatus.clock & 0x01)) 
         {
-
             // determine associated encoder
             zE = z;
             for (zX = ENCODE1; zX < ENCODEN; zX++) 
@@ -2938,10 +3005,10 @@ PAF_ASOT_setCheckRateX(
             }
             else
             {
-                return ( ASPERR_INFO_RATERATIO );
+                return ASPERR_INFO_RATERATIO;
             }
 
-            getVal = SIO_ctrl (pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_RATEX, (Arg) &rateX);
+            getVal = SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_RATEX, (Arg)&rateX);
             if (getVal == DOBERR_RATECHANGE) 
             {
                 for (zx=OUTPUT1; zx < OUTPUTN; zx++)
@@ -2958,7 +3025,7 @@ PAF_ASOT_setCheckRateX(
                 // exit this loop /function early.
                 return ASPERR_INFO_RATECHANGE;
             }
-            else if( getVal != SYS_OK )
+            else if (getVal != SYS_OK)
             {
                 return ((getVal & 0xff) | ASPERR_RATE_CHECK);
             }