]> 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-516:Rename ASOT event & event Ids, remove unused code
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutProc.c
index 38e6f342f7af098ee5e88acf0526efafd20cf805..dd2101706aa12f737ce1a21630fe410f2469a862 100644 (file)
@@ -67,10 +67,65 @@ Int32 gNumPfpAsot1=0; // debug
 
 // FL: debug
 #include "evmc66x_gpio_dbg.h"
+#include "dbgCapAf.h"
 
+#include "ioConfig.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
 //
@@ -126,7 +181,6 @@ Int32 gNumPfpAsot1=0; // debug
 #define ASOP_DP_DECFINALTEST_ERR    ( -6 )  // decode final error
 
 
-
 /* Check if at least one output selected */
 static Int checkOutSel(
     const PAF_ASOT_Params *pP, 
@@ -142,20 +196,23 @@ static Int checkOutSio(
 );
 
 // Initialize Output Processing state function
-static Int PAF_ASOT_initOutProc(
+//static Int PAF_ASOT_initOutProc(
+// used by new OutProc.c, will be changed back to static once refactoring is done
+Int PAF_ASOT_initOutProc(
     const PAF_ASOT_Params *pP, 
     PAF_AST_Stream *xStr
 );
 
 // Initialize Output Processing state function
-static Int PAF_ASOT_initSyncDecReset(
+// used by new OutProc.c, will be changed back to static once refactoring is done
+Int PAF_ASOT_initSyncDecReset(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
     PAF_AudioFrame *pDecResetAf
 );
 
-//   Purpose:   ASOT Function for resetting output processing.
+//   Purpose:   ASOT Function for Output reset
 static Int PAF_ASOT_outputReset(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
@@ -163,25 +220,32 @@ static Int PAF_ASOT_outputReset(
 );
 
 //   Purpose:   Init-Sync Dec Info1 state function.
-//              Performes Dec Info1 Init-Sync.
-static Int PAF_ASOT_initSyncDecInfo1(
+//              Performs Dec Info1 Init-Sync.
+Int PAF_ASOT_initSyncDecInfo1(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
     PAF_AudioFrame *pDecInfo1Af
 );
 
+//   Purpose:   ASOT function for ASP chain reset and ENC info
+static Int PAF_ASOT_outputInfo1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+);
+
 //   Purpose:   Init-Sync Dec Decode1 state function.
-//              Performes Dec Decode1 Init-Sync.
-static Int PAF_ASOT_initSyncDecDecode1(
+//              Performs Dec Decode1 Init-Sync.
+Int PAF_ASOT_initSyncDecDecode1(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg
 );
 
 //   Purpose:   Init-Sync Re-Sync state function.
-//              Peformed Init-Sync using stored Dec Reset/Info1 AFs.
-static Int PAF_ASOT_initSyncResync(
+//              Performs Init-Sync using stored Dec Reset/Info1 AFs.
+Int PAF_ASOT_initSyncResync(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
@@ -189,14 +253,6 @@ static Int PAF_ASOT_initSyncResync(
     PAF_AudioFrame *pDecInfo1Af  
 );
 
-#if 0
-// Init-Sync update audio frame
-static Int initSyncUpdateAf(
-    PAF_AudioFrame *dstAf, 
-    PAF_AudioFrame *srcAf
-);
-#endif
-
 // Reset audio frames
 static Void resetAfs(
     const PAF_ASOT_Params *pP, 
@@ -215,6 +271,9 @@ static Void resetAfMetadata(
     PAF_AST_Stream *xStr
 );
 
+// Create ASOT event
+static Int asotCreateEvent(void);
+
 
 LINNO_DEFN(TaskAsop); /* Line number macros */
 ERRNO_DEFN(TaskAsop); /* Error number macros */
@@ -223,12 +282,16 @@ ERRNO_DEFN(TaskAsop); /* Error number macros */
 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
 PAF_ASOT_Config gPAF_ASOT_config = {
     NULL,               // taskHandle
+    0,                  // asotState
     NULL,               // acp
-    0,0,0,              // CB drained flags (size DECODE_MAXN)
+    0,0,0,              // cbDrainedFlag (size DECODE_MAXN)
     &gPAF_ASPM_config,  // pAspmCfg
     &gPAF_AST_config    // pAstCfg
 };
 
+/* ASOT event handle - to put in structure */
+Event_Handle asotEvt;
+
 // 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 gCbReadAfErr         =0; // read circular buffer error count, not including underflows
@@ -236,7 +299,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;
@@ -249,15 +317,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
 )
@@ -267,24 +332,15 @@ 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;
-    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 status;
 
-    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);
@@ -293,10 +349,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):
@@ -305,7 +361,15 @@ 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.) */    
+    // Create ASIT event
+    status = asotCreateEvent();
+    if (status < 0)
+    {
+        TRACE_TERSE0("TaskAsop: unable to initialize event. Exiting.");
+        return;
+    }
+    
+    /* Obtain Audio Stream Number (1, 2, etc.) */
     as = pAstCfg->as;
     TRACE_TERSE1("TaskAsop: Started with AS%d.", as);
 
@@ -317,7 +381,7 @@ Void taskAsopFxn(
         TRACE_TERSE1("TaskAsop: AS%d: initiated", as+z);
     }
     LINNO_RPRT(TaskAsop, -1);
-    
+
     //
     // Determine stream index
     //
@@ -342,40 +406,112 @@ 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 */
+
+/*
+ *  ========asotCreateEvent ========
+ *  Create ASOT event
+ */
+static Int asotCreateEvent(void)
+{
+    Error_Block eb;
+    
+    Error_init(&eb);
+    
+    // Default instance configuration params
+    asotEvt = Event_create(NULL, &eb);
+    if (asotEvt == NULL)
+    {
+        return -1; // error code
+    }
+    
+    return 0;
+} /* asotCreateEvent */
+
+/*
+ *  ======== taskAsopFxn ========
+ *  Audio Stream Output Processing task function
+ */
+#ifdef PASDK_SIO_DEV
+Void taskAsopFxn(
+#else
+#ifndef IO_LOOPBACK_TEST
+Void taskAsopFxn_NOt_Used(
+#else
+Void taskAsopFxn_Not_Used(
+#endif
+#endif
+    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);
     }
     
-    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++;
@@ -385,6 +521,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) 
         {
@@ -398,31 +548,49 @@ 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)
+        if (procOutDevSel == 1)
         {
-            TRACE_TERSE2("TaskAsop: AS%d: checkOutSel returned errno = 0x%04x", as+zMS, errno);
-            continue;
-        }
-        else if (!outSel)
-        {
-            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)
@@ -438,10 +606,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;
@@ -460,21 +632,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;
@@ -493,21 +674,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;
@@ -526,21 +716,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;
@@ -561,14 +760,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;
@@ -596,11 +801,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)
@@ -617,6 +826,8 @@ Void taskAsopFxn(
                         // skip re-sync
                         // resume output processing after new output selected
                         state = OUT_PROC_STATE;
+                        procSleep = 1;
+                        procOutDevSel = 1;
                     }
                 }
                 else
@@ -632,6 +843,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;
@@ -645,6 +858,69 @@ Void taskAsopFxn(
     //Log_info0("Exit taskAsopFxn()");
 }
 
+Int PAF_ASOT_ioCompCreate(PAF_AST_IoOut *pIoOut, int numOut, IHeap_Handle iHeapHandle)
+{
+    int i, j, num_alloc;
+    lib_mem_rec_t   *mem_rec;
+    ioBuffHandle_t  ioBufHandle;
+    ioPhyHandle_t   ioPhyHandle;
+    Error_Block     eb;
+
+    for(i=0; i<numOut; i++)
+    {
+        // Create an I/O BUFF instance
+        // Obtain number of memory blocks required by I/O BUFF
+        num_alloc = ioBuffNumAlloc();
+
+        // Obtain requirements of each memory block
+        mem_rec   = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
+        if(ioBuffAlloc(mem_rec) != IOBUFF_NOERR) {
+            return __LINE__;
+        }
+
+        /* Allocate memory and create I/O BUFF instance */
+        for(j=0; j<num_alloc; j++) {
+            mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
+                                            (1<<mem_rec[j].alignment), &eb);
+        }
+
+        if(ioBuffCreate(&ioBufHandle, mem_rec) != IOBUFF_NOERR) {
+            return __LINE__;
+        }
+
+        pIoOut[i].hIoBuff = ioBufHandle;
+
+        free(mem_rec);
+
+        // Create an I/O PHY instance
+        // Obtain number of memory blocks required by I/O PHY
+        num_alloc = ioPhyNumAlloc();
+
+        // Obtain requirements of each memory block
+        mem_rec   = (lib_mem_rec_t *)malloc(sizeof(lib_mem_rec_t)*num_alloc);
+        if(ioPhyAlloc(mem_rec) != IOBUFF_NOERR) {
+            return __LINE__;
+        }
+
+        /* Allocate memory and create I/O PHY instance */
+        for(j=0; j<num_alloc; j++) {
+            mem_rec[j].base = Memory_calloc(iHeapHandle, mem_rec[j].size,
+                                            (1<<mem_rec[j].alignment), &eb);
+        }
+
+        if(ioPhyCreate(&ioPhyHandle, mem_rec) != IOBUFF_NOERR) {
+            return __LINE__;
+        }
+
+        pIoOut[i].hIoPhy = ioPhyHandle;
+
+        free(mem_rec);
+
+    } // end of for loop
+
+    return 0;
+} // PAF_ASOT_ioCompCreate
+
 // -----------------------------------------------------------------------------
 // AST Initialization Function - Memory Allocation
 //
@@ -670,7 +946,7 @@ PAF_ASOT_initPhaseMalloc (
 {
     PAF_AST_Config *pAstCfg;
     Int as;                     /* Audio Stream Number (1, 2, etc.) */
-    Int zMS;
+    Int zMS, errLineNum;
     Error_Block    eb;
     //Int i;
 
@@ -738,6 +1014,24 @@ PAF_ASOT_initPhaseMalloc (
             OUTPUTN * sizeof (*pAstCfg->xOut),
             HEAP_ID_INTERNAL, (IArg)pAstCfg->xOut);
 
+    /* Output I/O data structure memory */
+    if (!(pAsotCfg->pIoOut = Memory_calloc((IHeap_Handle)HEAP_INTERNAL, OUTPUTN * sizeof (*pAsotCfg->pIoOut), 4, &eb)))
+    {
+        TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
+        SW_BREAKPOINT;
+        return __LINE__;
+    }
+    TRACE_TERSE3("PAF_ASOT_initPhaseMalloc. (pAsotCfg->pIoOut) %d bytes from space %d at 0x%x.",
+                 OUTPUTN * sizeof (*pAsotCfg->pIoOut),
+                 HEAP_ID_INTERNAL, (IArg)pAsotCfg->pIoOut);
+
+    /* I/O components memory for output */
+    errLineNum = PAF_ASOT_ioCompCreate(pAsotCfg->pIoOut, OUTPUTN, (IHeap_Handle)HEAP_INTERNAL);
+    if(errLineNum)
+    {
+        SW_BREAKPOINT;
+        return errLineNum;
+    }
     TRACE_TERSE1("PAF_ASOT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
     return 0;
 } //PAF_ASOT_initPhaseMalloc
@@ -1630,6 +1924,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)) 
@@ -1646,6 +1942,7 @@ PAF_ASOT_selectDevices(
                 }
             }
         }
+#endif
     }
 
     return errno;
@@ -1683,7 +1980,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);
@@ -1731,9 +2034,8 @@ PAF_ASOT_decodeProcessing(
                     break;
                 }
                 
-#if 0 // FL: moved to PAF_ASOT_initSyncDecInfo1()
                 //
-                // Setup output: ASP chain reset, ENC reset, setCheckRateX, start output
+                // Setup output: setCheckRateX, start output
                 //
                 // Establish secondary timing
                 errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, frame, block);
@@ -1742,7 +2044,6 @@ PAF_ASOT_decodeProcessing(
                     TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x.  break after decodeInfo1", errno);
                     break;
                 }
-#endif
                 
                 TRACE_VERBOSE0("PAF_ASOT_decodeProcessing: state: INIT->STREAM");                
                 state = STREAM;
@@ -1986,6 +2287,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(
@@ -2008,6 +2312,16 @@ PAF_ASOT_decodeInit(
 
     for (z=DECODE1; z < DECODEN; z++)
     {
+        // Initialize decoder output circular buffer for stream reads
+        //errno = cbInitStreamRead(pCbCtl, z, gStrFrameLen);
+        errno = cbInitStreamRead(pCbCtl, z);
+        if (errno)
+        {
+            TRACE_TERSE1("PAF_ASOT_decodeInit:cbInitStreamRead() error=%d", errno);
+            SW_BREAKPOINT; // debug
+            return errno;
+        }
+        
         // Start decoder output circular buffer reads
         errno = cbReadStart(pCbCtl, z);
         if (errno)
@@ -2016,6 +2330,7 @@ PAF_ASOT_decodeInit(
             SW_BREAKPOINT; // debug
             return errno;
         }
+        
         gCbReadAfErr=0;         // reset read circular buffer error count
         gDecOpCbRdAfUnd=0;      // reset decoder output circular buffer underflow count
         gMaxDecOpCbRdAfUnd=0;   // reset max decoder output circular buffer underflow count
@@ -2079,10 +2394,11 @@ PAF_ASOT_decodeInfo1(
     Int block
 )
 {
-    PAF_AST_Config *pAstCfg;
-    Int z;                              /* decode/encode counter */
+    //PAF_AST_Config *pAstCfg;
+    //Int z;                              /* decode/encode counter */
     Int errno;                          /* error number */
 
+#if 0 // moved to PAF_ASOT_outputInfo1()
     pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
 
     // run the chain of ASP's on the stream.
@@ -2118,6 +2434,7 @@ PAF_ASOT_decodeInfo1(
             }
         }
     }
+#endif    
 
     errno = pP->fxns->setCheckRateX(pP, pQ, pAsotCfg, 0);
     if (errno)
@@ -2149,7 +2466,7 @@ PAF_ASOT_decodeInfo1(
             TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
         }
         return errno;
-    }    
+    }
     
     return 0;
 }
@@ -2215,7 +2532,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;
 
 
@@ -2231,25 +2548,25 @@ PAF_ASOT_decodeStream(
         // Read decoder output circular buffer
         //
         pAfRd = pAstCfg->xStr[zS].pAudioFrame;
-        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
+        //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);       // debug
         cbErrno = cbReadAf(pCbCtl, z, pAfRd);
-        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) 
             {
@@ -2283,7 +2600,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
@@ -2298,17 +2615,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);
 
-        // FL: debug
+        // debug
         cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
-        //if (capAfWrite(pAfRd, 0) != 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.");
@@ -2351,7 +2670,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;
@@ -2377,7 +2697,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);   // debug
             errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
+            //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);     // debug
             if (errno < 0)
             {
                 SIO_idle(pAstCfg->xOut[z].hTxSio);
@@ -2386,7 +2708,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;
@@ -2398,15 +2720,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 
         {
@@ -2505,8 +2827,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
             errno = SIO_issue(pAstCfg->xOut[z].hTxSio, 
                 &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
+            //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);     // debug
             if (errno)
             {
                 SIO_idle(pAstCfg->xOut[z].hTxSio);
@@ -2654,7 +2978,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;
@@ -2682,6 +3006,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;
@@ -2857,6 +3201,7 @@ PAF_ASOT_stopOutput(
     return errno;
 } //PAF_ASOT_stopOutput
 
+
 // -----------------------------------------------------------------------------
 // ASOT Decoding Function Helper - SIO Driver Change
 //
@@ -2905,7 +3250,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++) 
@@ -2931,10 +3275,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++)
@@ -2951,7 +3295,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);
             }
@@ -3191,7 +3535,8 @@ static Void resetAfMetadata(
 }
 
 // Initialize Output Processing state function
-static Int PAF_ASOT_initOutProc(
+//static Int PAF_ASOT_initOutProc(
+Int PAF_ASOT_initOutProc(
     const PAF_ASOT_Params *pP, 
     PAF_AST_Stream *xStr
 )
@@ -3202,22 +3547,11 @@ static Int PAF_ASOT_initOutProc(
     return ASOP_SOK;
 }
 
-#if 0
-// Init-Sync update audio frame
-static Int initSyncUpdateAf(
-    PAF_AudioFrame *dstAf, 
-    PAF_AudioFrame *srcAf
-)
-{
-    memcpy(dstAf, srcAf, sizeof(PAF_AudioFrame));
-    
-    return ASOP_SOK;
-}
-#endif
-
 //   Purpose:   Init-Sync Dec Reset state function.
 //              Performes Dec Reset Init-Sync.
-static Int PAF_ASOT_initSyncDecReset(
+//static Int PAF_ASOT_initSyncDecReset(
+// used by new OutProc.c, will be changed back to static once refactoring is done
+Int PAF_ASOT_initSyncDecReset(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
@@ -3256,11 +3590,6 @@ static Int PAF_ASOT_initSyncDecReset(
         
         // Update Stream Audio Frame.
         // Copy Dec Reset AF to Stream AF.
-        //errno = initSyncUpdateAf(pStrAf, pDecResetAf);
-        //if (errno < 0)
-        //{
-        //    return errno;
-        //}
         outIsCpyAf(pDecResetAf, pStrAf);
         
         // Enc activate
@@ -3275,7 +3604,7 @@ static Int PAF_ASOT_initSyncDecReset(
     }
 }
 
-//   Purpose:   ASOT Function for resetting output processing.
+//   Purpose:   ASOT Function for Output reset
 static Int PAF_ASOT_outputReset(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
@@ -3325,9 +3654,12 @@ 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(
+//              Performs Dec Info1 Init-Sync.
+Int PAF_ASOT_initSyncDecInfo1(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
@@ -3364,22 +3696,20 @@ static Int PAF_ASOT_initSyncDecInfo1(
         zMS = pAstCfg->masterStr;
         pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
         
+        // Set ASOT output frame length.
+            // THD sets this to 256 (hard-coded in Dec Info)
+            // DDP sets this to 0 (audio frame pass through, 0 from ASDT AF frame length)
+            // PCM sets this to 256 (decodeControl.frameLength)
+        pDecInfo1Af->sampleCount = gOutFrameLen;    // !!!! GJ: Revisit !!!!
+        
         // Update Stream Audio Frame.
         // Copy Dec Reset AF to Stream AF.
-        //errno = initSyncUpdateAf(pStrAf, pDecInfo1Af);
-        //if (errno < 0)
-        //{
-        //    return errno;
-        //}
         outIsCpyAf(pDecInfo1Af, pStrAf);
-        
-        // decodeInfo1():
+
+        // outputInfo1():
         //      - ASP chain reset,
-        //      - Enc Info,
-        //      - setCheckRateX,
-        //      - startOutput
-        // frame and block parameters set to 0
-        errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, 0, 0);
+        //      - Enc Info
+        PAF_ASOT_outputInfo1(pP, pQ, pAsotCfg);
         if (errno)
         {
             return ASOP_DECINFO1_ERR;
@@ -3389,16 +3719,69 @@ static Int PAF_ASOT_initSyncDecInfo1(
     }
 }
 
+//   Purpose:   ASOT function for ASP chain reset and ENC info
+static Int PAF_ASOT_outputInfo1(
+    const PAF_ASOT_Params *pP, 
+    const PAF_ASOT_Patchs *pQ, 
+    PAF_ASOT_Config *pAsotCfg
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int z;                              /* decode/encode counter */
+    Int errno;                          /* error number */
+
+    
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+
+    // FL: frame parameter hard-coded to 0
+    // run the chain of ASP's on the stream.
+    TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
+    errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg, 
+        PAF_ASP_CHAINFRAMEFXNS_RESET, 1, 0);
+    if (errno)
+    {
+        TRACE_TERSE1("PAF_ASOT_outputInfo1: streamChainFunction returns errno 0x%x ", errno);
+        return errno;
+    }
+
+    TRACE_VERBOSE0("PAF_ASOT_outputInfo1: calling enc->info.");
+    for (z=ENCODE1; z < ENCODEN; z++) 
+    {
+        Int zO = pP->outputsFromEncodes[z];
+        if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode) 
+        {
+            Int select = pAstCfg->xEnc[z].encodeStatus.select;
+            ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
+            ENC_Handle enc = (ENC_Handle )encAlg;
+            
+            if (enc->fxns->info)
+            {
+                errno = enc->fxns->info(enc, NULL,
+                    &pAstCfg->xEnc[z].encodeControl, 
+                    &pAstCfg->xEnc[z].encodeStatus);
+                if (errno)
+                {
+                    TRACE_TERSE1("PAF_ASOT_outputInfo1: info returns errno 0x%x ", errno);
+                    return errno;
+                }
+            }
+        }
+    }
+    
+    return 0;
+}
+
 //   Purpose:   Init-Sync Dec Decode1 state function.
-//              Performes Dec Decode1 Init-Sync.
-static Int PAF_ASOT_initSyncDecDecode1(
+//              Performs Dec Decode1 Init-Sync.
+//static Int PAF_ASOT_initSyncDecDecode1(
+Int PAF_ASOT_initSyncDecDecode1(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg
 )
 {
     PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
-    Int zMD, zMS;                       // Dec and Stream Master indices
+    Int zMD;                            // Dec Master index
     PAF_AST_OutInitSyncCtl *pOutIsCtl;  // Output Init-Sync control
     Int8 decFlag;                       // dec stage flag
     Int errno;                          // error number
@@ -3428,8 +3811,8 @@ static Int PAF_ASOT_initSyncDecDecode1(
 }
 
 //   Purpose:   Init-Sync Re-Sync state function.
-//              Peformed Init-Sync using stored Dec Reset/Info1 AFs.
-static Int PAF_ASOT_initSyncResync(
+//              Peforms Init-Sync using stored Dec Reset/Info1 AFs.
+Int PAF_ASOT_initSyncResync(
     const PAF_ASOT_Params *pP, 
     const PAF_ASOT_Patchs *pQ, 
     PAF_ASOT_Config *pAsotCfg,
@@ -3456,11 +3839,6 @@ static Int PAF_ASOT_initSyncResync(
     
     // Update Stream Audio Frame.
     // Copy Dec Reset AF to Stream AF.
-    //errno = initSyncUpdateAf(pStrAf, pDecResetAf);
-    //if (errno < 0)
-    //{
-    //    return errno;
-    //}
     outIsCpyAf(pDecResetAf, pStrAf);
     
     // Enc activate,
@@ -3477,20 +3855,12 @@ static Int PAF_ASOT_initSyncResync(
     
     // Update Stream Audio Frame.
     // Copy Dec Info1 AF to Stream AF.
-    //errno = initSyncUpdateAf(pStrAf, pDecInfo1Af);
-    //if (errno < 0)
-    //{
-    //    return errno;
-    //}
     outIsCpyAf(pDecInfo1Af, pStrAf);
     
     // decodeInfo1():
     //      - ASP chain reset,
-    //      - Enc Info,
-    //      - setCheckRateX,
-    //      - startOutput
-    // frame and block parameters set to 0
-    errno = pP->fxns->decodeInfo1(pP, pQ, pAsotCfg, 0, 0);
+    //      - Enc Info
+    errno = PAF_ASOT_outputInfo1(pP, pQ, pAsotCfg);
     if (errno)
     {
         return errno;
@@ -3520,7 +3890,9 @@ PAF_ASOT_decodeFinalTest(
     zMD = pAsotCfg->pAstCfg->masterDec; // get master Dec index
 
     // Check circular buffer drain state
+    //GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_107);     // debug
     errno = cbCheckDrainState(pCbCtl, zMD, &drainedFlag);
+    //GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);   // debug
     if (errno < 0)
     {
         return errno;