Started refactoring input task. New code works up to auto-detection which detects
authorJianzhong Xu <a0869574@ti.com>
Thu, 4 Jan 2018 20:44:26 +0000 (15:44 -0500)
committerJianzhong Xu <a0869574@ti.com>
Thu, 4 Jan 2018 20:44:26 +0000 (15:44 -0500)
input format reliably when input switches between PCM and bit stream.

18 files changed:
pasdk/test_arm/.cproject
pasdk/test_dsp/.cproject
pasdk/test_dsp/application/itopo/evmk2g/mcasp_cfg.c
pasdk/test_dsp/application/itopo/evmk2g/mcasp_cfg.h
pasdk/test_dsp/application/itopo/evmk2g/sap_d10.c
pasdk/test_dsp/framework/audioStreamInpDec.c [new file with mode: 0644]
pasdk/test_dsp/framework/audioStreamInpProc.c
pasdk/test_dsp/framework/audioStreamInpProc.h
pasdk/test_dsp/framework/audioStreamInpProcNewIO.c [new file with mode: 0644]
pasdk/test_dsp/framework/audioStreamOutDec.c [new file with mode: 0644]
pasdk/test_dsp/framework/audioStreamOutProc.c
pasdk/test_dsp/framework/audioStreamOutProcNewIO.c [new file with mode: 0644]
pasdk/test_dsp/framework/itopo/params.c
pasdk/test_dsp/framework/systemInit.c
pasdk/test_dsp/io/ioConfig.h
pasdk/test_dsp/io/test/audio_tsk.c
pasdk/test_dsp/io/test/frame_work.c
pasdk/test_dsp/io/test/frame_work.h

index 8f30fa89d42b64719eb6effa3a0ef6fb5c350e06..242a25fb6a7aa25658f4d3501d55d4ee65c71ec6 100644 (file)
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES.111979217" name="Java properties (-D)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES" valueType="stringList">
                                                                        <listOptionValue builtIn="false" value="xdc.platform.custom.check=false"/>
                                                                        <listOptionValue builtIn="false" value="ProjName=pa_i13_evmk2g_arm"/>
-                                                                       <listOptionValue builtIn="false" value="HsDevBuild=1"/>
+                                                                       <listOptionValue builtIn="false" value="HsDevBuild=0"/>
                                                                </option>
                                                        </tool>
                                                </toolChain>
index 0ec0ad6e592cf8e416ae9ad8db1ef8554ac8ac9d..86f93bbc903875d4617bd6aacd31ba5174411de8 100644 (file)
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES.1168868732" name="Java properties (-D)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES" valueType="stringList">
                                                                        <listOptionValue builtIn="false" value="xdc.platform.custom.check=false"/>
                                                                        <listOptionValue builtIn="false" value="ProjName=pa_i13_evmk2g_c66x"/>
-                                                                       <listOptionValue builtIn="false" value="HsDevBuild=1"/>
+                                                                       <listOptionValue builtIn="false" value="HsDevBuild=0"/>
                                                                </option>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.596568674" name="Additional compiler options (--compileOptions)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;-g --optimize_with_debug&quot;" valueType="string"/>
                                                        </tool>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES.1106143106" name="Java properties (-D)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES" valueType="stringList">
                                                                        <listOptionValue builtIn="false" value="xdc.platform.custom.check=false"/>
                                                                        <listOptionValue builtIn="false" value="ProjName=pa_i13_evmk2g_c66x"/>
-                                                                       <listOptionValue builtIn="false" value="HsDevBuild=1"/>
+                                                                       <listOptionValue builtIn="false" value="HsDevBuild=0"/>
                                                                </option>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.117771061" name="Additional compiler options (--compileOptions)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;-g --optimize_with_debug&quot;" valueType="string"/>
                                                        </tool>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES.1528336416" name="Java properties (-D)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES" valueType="stringList">
                                                                        <listOptionValue builtIn="false" value="xdc.platform.custom.check=false"/>
                                                                        <listOptionValue builtIn="false" value="ProjName=pa_i13_evmk2g_c66x"/>
-                                                                       <listOptionValue builtIn="false" value="HsDevBuild=1"/>
+                                                                       <listOptionValue builtIn="false" value="HsDevBuild=0"/>
                                                                </option>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.66964221" name="Additional compiler options (--compileOptions)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;-g --optimize_with_debug&quot;" valueType="string"/>
                                                        </tool>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES.126239795" name="Java properties (-D)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES" valueType="stringList">
                                                                        <listOptionValue builtIn="false" value="xdc.platform.custom.check=false"/>
                                                                        <listOptionValue builtIn="false" value="ProjName=pa_i13_evmk2g_c66x"/>
-                                                                       <listOptionValue builtIn="false" value="HsDevBuild=1"/>
+                                                                       <listOptionValue builtIn="false" value="HsDevBuild=0"/>
                                                                </option>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.1857138411" name="Additional compiler options (--compileOptions)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;-g --optimize_with_debug&quot;" valueType="string"/>
                                                        </tool>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES.1994440010" name="Java properties (-D)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES" valueType="stringList">
                                                                        <listOptionValue builtIn="false" value="xdc.platform.custom.check=false"/>
                                                                        <listOptionValue builtIn="false" value="ProjName=pa_i13_evmk2g_c66x"/>
-                                                                       <listOptionValue builtIn="false" value="HsDevBuild=1"/>
+                                                                       <listOptionValue builtIn="false" value="HsDevBuild=0"/>
                                                                </option>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.1812107894" name="Additional compiler options (--compileOptions)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;-g --optimize_with_debug&quot;" valueType="string"/>
                                                        </tool>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES.1242157342" name="Java properties (-D)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES" valueType="stringList">
                                                                        <listOptionValue builtIn="false" value="xdc.platform.custom.check=false"/>
                                                                        <listOptionValue builtIn="false" value="ProjName=pa_i13_evmk2g_c66x"/>
-                                                                       <listOptionValue builtIn="false" value="HsDevBuild=1"/>
+                                                                       <listOptionValue builtIn="false" value="HsDevBuild=0"/>
                                                                </option>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.1216126854" name="Additional compiler options (--compileOptions)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;-g --optimize_with_debug&quot;" valueType="string"/>
                                                        </tool>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES.1319643304" name="Java properties (-D)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.JAVA_PROPERTIES" valueType="stringList">
                                                                        <listOptionValue builtIn="false" value="xdc.platform.custom.check=false"/>
                                                                        <listOptionValue builtIn="false" value="ProjName=pa_i13_evmk2g_c66x"/>
-                                                                       <listOptionValue builtIn="false" value="HsDevBuild=1"/>
+                                                                       <listOptionValue builtIn="false" value="HsDevBuild=0"/>
                                                                </option>
                                                                <option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.1429136493" name="Additional compiler options (--compileOptions)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;-g --optimize_with_debug&quot;" valueType="string"/>
                                                        </tool>
index 2028dff2faf86a5c45c2b4056f8b6dd5143138d4..d7ff9850c092cf6f6d4d8c140cbab36aa6ffe6a6 100644 (file)
@@ -74,14 +74,9 @@ extern signed char*  getGlobalAddr(signed char* addr);
 extern void mcaspAppCallbackRx(void* arg, MCASP_Packet *mcasp_packet);
 extern void mcaspAppCallbackTx(void* arg, MCASP_Packet *mcasp_packet);
 #else
-void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
-{
-    // to be moved to and defined in asip processing
-}
-void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
-{
-    // to be moved to and defined in asop processing
-}
+extern void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet);
+extern void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet);
+
 #endif
 
 /* McASP HW setup for receive */
@@ -340,7 +335,7 @@ void configAudioDAC(void)
  */
 Audk2g_STATUS mcaspAudioConfig(void)
 {
-       Int status;
+    int32_t status;
 
        hMcaspDevTx  = NULL;
        hMcaspDevRx  = NULL;
@@ -471,7 +466,7 @@ Audk2g_STATUS mcaspRxReset(void)
 
 Audk2g_STATUS mcaspRxCreate(void)
 {
-       Int status;
+    int32_t status;
 
        /* Create McASP channel for Rx */
        status = mcaspCreateChan(&hMcaspRxChan, hMcaspDevRx,
@@ -504,7 +499,7 @@ Audk2g_STATUS mcaspTxReset(void)
 
 Audk2g_STATUS mcaspTxCreate(void)
 {
-       Int status;
+    int32_t status;
 
        /* Create McASP channel for Tx */
        status = mcaspCreateChan(&hMcaspTxChan, hMcaspDevTx,
@@ -524,40 +519,22 @@ Audk2g_STATUS mcaspTxCreate(void)
        return (Audk2g_EOK);
 }
 
-Audk2g_STATUS mcaspRxCfgPCM(void)
-{
-    Int status = Audk2g_EOK;
-
-    if(  (mcaspRxChanParam.wordWidth      != Mcasp_WordLength_32)
-      /*|| (mcaspRxChanParam.wordBitsSelect != Mcasp_WordBitsSelect_LSB)*/ )
-    {
-        mcaspRxReset();
 
-        mcaspRxChanParam.wordWidth      = Mcasp_WordLength_32;
-        //mcaspRxChanParam.wordBitsSelect = Mcasp_WordBitsSelect_LSB;
-
-        status = mcaspRxCreate();
-    }
-
-    return status;
-} // mcaspRxCfgPCM
-
-Audk2g_STATUS mcaspRxCfgBitstream(void)
+Audk2g_STATUS mcaspRecfgWordWidth(Ptr hMcaspChan, uint16_t wordWidth)
 {
-    Int status = Audk2g_EOK;
+    Mcasp_ChanParams chanParams;
+    int32_t status;
 
-    if(  (mcaspRxChanParam.wordWidth      != Mcasp_WordLength_16)
-      /*|| (mcaspRxChanParam.wordBitsSelect != Mcasp_WordBitsSelect_MSB)*/ )
-    {
-        mcaspRxReset();
+    chanParams.wordWidth = wordWidth;  //to do: change mcaspControlChan to have wordWidth as the parameter instead of chanParams!!
 
-        mcaspRxChanParam.wordWidth      = Mcasp_WordLength_16;
-        //mcaspRxChanParam.wordBitsSelect = Mcasp_WordBitsSelect_MSB;
+    status = mcaspControlChan(hMcaspChan, Mcasp_IOCTL_CHAN_PARAMS_WORD_WIDTH, &chanParams);
 
-        status = mcaspRxCreate();
+    if((status != MCASP_COMPLETED)) {
+        return (Audk2g_EFAIL);
     }
-
-    return status;
-} // mcaspRxCfgBitstream
+    else {
+        return (Audk2g_EOK);
+    }
+} /* mcaspRecfgWordWidth */
 
 /* Nothing past this point */
index 5cb33ef1679045534541050c415dd195479eb476..709043f928fa7d59d7cca6c4950b696adc319c59 100644 (file)
@@ -122,5 +122,6 @@ Audk2g_STATUS mcaspTxCreate(void);
 Audk2g_STATUS mcaspTxReset(void);
 Audk2g_STATUS mcaspRxCreate(void);
 Audk2g_STATUS mcaspRxReset(void);
+Audk2g_STATUS mcaspRecfgWordWidth(Ptr hMcaspChan, uint16_t wordWidth);
 
 #endif /* _MCASP_CONFIG_H_ */
index 27b25a64066222a5c62158f2b831ec07c39bfe73..d76dd468b44a45009e00e5baec0101641d922d32 100644 (file)
@@ -1232,4 +1232,23 @@ XDAS_Int32 D10_init()
 
     return 0;
 }
+
+XDAS_Int32 D10_RxControl(const void *pD10RxParams,
+                         XDAS_Int32 code, XDAS_Int32 arg)
+{
+    XDAS_Int32 result = 0;
+
+    switch (code) {
+        case PAF_SIO_CONTROL_GET_INPUT_STATUS:
+            manageInput(NULL, (const SAP_D10_Rx_Params *)pD10RxParams,
+                        (PAF_SIO_InputStatus *)arg);
+        break;
+
+        default:
+        break;
+    }
+
+    return result;
+}
+
 // EOF
diff --git a/pasdk/test_dsp/framework/audioStreamInpDec.c b/pasdk/test_dsp/framework/audioStreamInpDec.c
new file mode 100644 (file)
index 0000000..6768e7b
--- /dev/null
@@ -0,0 +1,754 @@
+/*
+Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+#if 0
+/*
+ *  ======== audioStreamInpProc.c ========
+ */
+
+#include <xdc/std.h>
+#include <xdc/cfg/global.h>
+#include <xdc/runtime/Diags.h>
+#include <xdc/runtime/Error.h>
+#include <xdc/runtime/Log.h>
+#include <xdc/runtime/Memory.h>
+#include <xdc/runtime/System.h>
+#include <ti/sysbios/BIOS.h>
+#include <ti/sysbios/hal/Hwi.h>
+#include <ti/sysbios/hal/Cache.h>
+#include <ti/sysbios/knl/Clock.h>
+#include <ti/sysbios/knl/Task.h>
+#include <ti/ipc/Ipc.h>
+#include <ti/ipc/MessageQ.h>
+#include <ti/ipc/MultiProc.h>
+
+#include <sio.h>
+#include <pafsio_ialg.h>
+
+#include "common.h"
+#include "paf_heapMgr.h"
+#include "aspMsg_common.h"
+#include "aspMsg_master.h"
+#include "aspDecOpCircBuf_master.h"
+#include "audioStreamProc_common.h"
+#include "audioStreamProc_master.h"
+#include "audioStreamInpProc.h"
+#include "mib.h"
+
+//#include "fwkPort.h"
+// FL: debug
+#include "dbgCapAf.h"
+#include "dbgDib.h"
+#include "statusOp_common.h"
+
+
+// -----------------------------------------------------------------------------
+// Debugging Trace Control, local to this file.
+//
+#include "logp.h"
+
+// .............................................................................
+
+#include <pafsio.h>
+#include "paferr.h"
+
+#include <acp_mds.h>
+
+#include <pcm.h>
+
+#include <pce.h>
+
+#include <doberr.h>
+
+#include <diberr.h>
+
+#include <stdasp.h>
+
+#include "as0.h"
+#include "asperr.h"
+
+#include "audioStreamProc_params.h"
+#include "audioStreamProc_patchs.h"
+#include "audioStreamProc_config.h"
+#include "audioStreamInpProc.h"
+
+#include "ioData.h"
+//#include "../newio/fw/mcasp_cfg.h"
+
+#include "ioConfig.h"                //JXTODO: to remove compile-time configurations
+
+//#include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
+
+
+#define DECSIOMAP(X)                                                \
+    pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
+
+
+enum {
+       INFO1,
+       INFO2,
+       DATA
+};
+
+
+#ifdef RX_MCASP_USE_MULT_SER
+#define INPUT_STRIDE 8
+#else
+#define INPUT_STRIDE 2
+#endif
+
+extern PAF_AST_InpIO *inpIOtemp;    /* Input I/O */
+extern UInt32 gCapIb_cnt;
+
+// Functions prototypes only referenced in this file
+static Int decDecideFrameLength(Int sourceSelect);
+static Int decDecodeInfo(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
+                          PAF_ASIT_Config *pC, asipDecProc_t *pDec, Int frame, Int block);
+static Int decDecodeData(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
+                            PAF_ASIT_Config *pC, Int sourceSelect, Int frame, Int block);
+//void asipUpdateInpBufConfig(PAF_AST_InpBuf *inpBufConfig, ioDataHandle_t ioDataHandle);
+
+// -----------------------------------------------------------------------------
+// ASIT Decoding Function - Reinitialization of Decode
+//
+//   Name:      PAF_ASIT_decodeInit
+//   Purpose:   Decoding Function for reinitializing the decoding process.
+//   From:      AST Parameter Function -> decodeProcessing
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard or SIO form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//
+Int asipDecodeInit(
+           const PAF_ASIT_Params *pP,
+           PAF_ASIT_Config *pC,
+               asipDecProc_t *pD,
+               Int sourceSelect)
+{
+    PAF_AST_Config *pAstCfg;
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    Int z;                              /* decode/encode counter */
+    Int errno;                          /* error number */
+    Int zI, zS;
+    Int8 tempVar8;
+    ioPhyCtl_t ioPhyCtl;
+    ioDataCtl_t ioDataCtl;
+
+    pAstCfg = pC->pAstCfg;   // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    (void)as;  // clear compiler warning in case not used with tracing disabled
+
+    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+
+    // reset frameCount
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        if (readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))  {
+               writeSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.frameCount), 0);
+        }
+    }
+
+    // loop through all supported inputs
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        zI = pP->inputsFromDecodes[z];
+        zS = pP->streamsFromDecodes[z];
+        (void)zS; // clear compiler warning in case not used with tracing disabled
+
+        if (   inpIOtemp[zI].hIoPhy
+            && readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))
+        {
+            Uns gear;
+            Int frameLength;
+            TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
+
+            // write back Dec configuration
+            Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+            Cache_wait();
+
+            // FL: send dec activate message to slave
+            asipSendMsgToDecoder(ASP_SLAVE_DEC_ACTIVATE, z, ASP_MASTER_DEC_ACTIVATE_DONE, NULL);
+
+            // FL: send dec reset message to slave
+            errno = 0;
+            errno = asipSendMsgToDecoder(ASP_SLAVE_DEC_RESET, z, ASP_MASTER_DEC_RESET_DONE, NULL);
+
+            // (***) FL: revisit
+            // invalidate Dec configuration
+            Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+            Cache_wait();
+
+            if (errno != 0) {
+                return ASIP_DECODE_ERR_MSG_SEND;
+            }
+
+            gear = readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.aspGearControl));
+            tempVar8 = gear < GEARS ? gear : 0;
+            writeSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.aspGearStatus), tempVar8);
+
+            frameLength = decDecideFrameLength(sourceSelect);
+
+            pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
+            pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
+            pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
+
+            // (***) FL: revisit. Count samples for DDP.
+            // Add framework frame length and running sample count to decoder control.
+            //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
+            //pC->xDec[z].decodeControl.rdSampleCount = 0;
+
+            // Initialize decoder output circular buffer for selected source
+            //errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
+            if (errno) {
+                SW_BREAKPOINT; // FL: debug
+                return ASIP_DECODE_ERR_INIT_CB;
+            }
+            // FL: debug
+            cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
+
+/*
+            if (z != zMD) {    // JXTODO: implement similar thing with new I/O
+                if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
+                    return errno;
+                }
+            }
+*/
+/*
+            //JXTODO: do we need to update input status here again?
+            if (errno = asipUpdateInputStatus(inpIOtemp[0].pRxParams,
+                                                 &pAstCfg->xInp[zI].inpBufStatus,
+                                              &pAstCfg->xInp[zI].inpBufConfig)) {
+                return errno;
+            }
+*/
+        } /* end of if(hIoPhy && decodeStatus.mode) */
+    } /* end of for (z=DECODE1; z < DECODEN; z++) */
+
+    pD->frame = 0;
+    pD->block = 0;
+    pD->state = INFO1;
+    
+    return ASIP_DECODE_NO_ERR;
+}  /* asipDecodeInit */
+
+// -----------------------------------------------------------------------------
+// ASIT Processing Function - Decode Processing
+//
+//   Name:      asipDecodeProcessing
+//   Purpose:   Audio Stream Input Task Function for processing audio data.
+//   Return:    Error number in standard form (0 on success).
+//
+#if 0
+Int asipDecodeProcessing(
+           const PAF_ASIT_Params *pP,
+           const PAF_ASIT_Patchs *pQ,
+           PAF_ASIT_Config *pC,
+               asipDecProc_t *pD,
+               Int sourceSelect)
+{
+    PAF_AST_Config *pAstCfg;
+    Int errno, retVal;                          /* error number */
+    Int zMD;
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    zMD = pAstCfg->masterDec;
+
+    retVal = ASIP_DECODE_NO_ERR;
+
+    //!! to add data read from I/O buffer
+    switch(pD->state)
+    {
+        case INFO1:
+            if (errno = decDecodeInfo(pP, pQ, pC, pD, pD->frame, pD->block)) {
+                //gAsipInfo1_PrimaryErrCnt++;
+                TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
+               retVal = ASIP_DECODE_ERR_INFO1;
+            }
+            else {
+               // Don't start decode until major access unit is found.
+               Int8 sourceDecode, sampleRate;
+               sourceDecode = readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode));
+               sampleRate   = readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sampleRate));
+                if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
+                       (sourceDecode == PAF_SOURCE_DXP)     ||
+                       (sourceDecode == PAF_SOURCE_DTSHD) ) &&
+                     ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
+                       pD->state = INFO1;
+                }
+                else {
+                       pD->state = DATA;
+                }
+            }
+            break;
+
+        case INFO2:
+            if (errno = decDecodeInfo(pP, pQ, pC, pD, pD->frame, pD->block)) {
+                //gAsipInfo1_PrimaryErrCnt++;
+                TRACE_TERSE1("INFO2: errno 0x%x after decodeInfo, primary timing", errno);
+               retVal = ASIP_DECODE_ERR_INFO2;
+            }
+            else {
+                pD->state = DATA;
+            }
+            break;
+
+        case DATA:
+            if (errno = decDecodeData(pP, pQ, pC, sourceSelect, pD->frame, pD->block)) {
+                //gAsipDecodeErrCnt++;
+                TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DATA.  decodeDecode err 0x%04x", errno);
+               retVal = ASIP_DECODE_ERR_DATA;
+            } 
+            else {
+                if (pP->fxns->decodeFinalTest(pP, pQ, pC, pD->frame, pD->block)) {
+                       retVal = ASIP_DECODE_ERR_FINAL;
+                }
+                else {
+                    pD->state = INFO2;
+                }                
+            }
+            break;
+
+        default:
+               break;
+        
+    }
+
+    return retVal;
+}  /* asipDecodeProcessing */
+#endif
+
+
+Int asipDecodeProcessing(
+           const PAF_ASIT_Params *pP,
+           const PAF_ASIT_Patchs *pQ,
+           PAF_ASIT_Config *pC,
+               asipDecProc_t *pD,
+               Int sourceSelect)
+{
+    PAF_AST_Config *pAstCfg;
+    Int errno, retVal;                          /* error number */
+    Int zMD;
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    zMD = pAstCfg->masterDec;
+    retVal = ASIP_DECODE_NO_ERR;
+
+    //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ;  //JXTODO: make this correct
+    errno = decDecodeInfo(pP, pQ, pC, pD, pD->frame, pD->block);
+    if (errno != ASIP_DECODE_NO_ERR) {
+        //gAsipInfo1_PrimaryErrCnt++;
+        TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
+        retVal =  ASIP_DECODE_ERR_INFO;
+    }
+    else {
+       // Don't start decode until major access unit is found.
+       Int8 sourceDecode, sampleRate;
+       sourceDecode = readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode));
+       sampleRate   = readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sampleRate));
+        if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
+               (sourceDecode == PAF_SOURCE_DXP)     ||
+               (sourceDecode == PAF_SOURCE_DTSHD) ) &&
+             ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
+               /* do nothing and return - waiting for major access unit */;
+            retVal =  ASIP_DECODE_NO_ERR;
+        }
+        else {
+               errno = decDecodeData(pP, pQ, pC, sourceSelect, pD->frame, pD->block);
+            if (errno != ASIP_DECODE_NO_ERR) {
+                //gAsipDecodeErrCnt++;
+                TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DATA.  decodeDecode err 0x%04x", errno);
+               retVal = ASIP_DECODE_ERR_DATA;
+            }
+            else {
+               errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pD->frame, pD->block);
+                if (errno) {
+                       retVal = ASIP_DECODE_ERR_FINAL;
+                }
+                else {
+                    retVal = ASIP_DECODE_NO_ERR;
+                }
+            }
+        }
+    }
+
+    return retVal;
+}  /* asipDecodeProcessing */
+
+// -----------------------------------------------------------------------------
+// ASIT Decoding Function - Info Processing, Common
+//
+//   Name:      PAF_ASIT_decodeInfo
+//   Purpose:   Decoding Function for processing information in a manner that
+//              is common for both initial and subsequent frames of input data.
+//   From:      AST Parameter Function -> decodeProcessing
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+// -----------------------------------------------------------------------------
+Int
+decDecodeInfo(
+    const PAF_ASIT_Params *pP,
+    const PAF_ASIT_Patchs *pQ,
+    PAF_ASIT_Config *pC,
+       asipDecProc_t *pD,
+    Int frame,
+    Int block
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                    /* Audio Stream Number (1, 2, etc.) */
+    Int z;                     /* input/decode/stream counter */
+    Int errno;                 /* error number */
+    Int zD, zI, zS, zX;
+    Int zMD;
+    //Int zMI;
+    Int8 tempVar8;
+    Int tempVar;
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    zMD = pAstCfg->masterDec;
+    //zMI = pP->zone.master;
+
+    // Set decode control: sample rate, emphasis
+    for (z=INPUT1; z < INPUTN; z++)
+    {
+        zD = z;
+        for (zX = DECODE1; zX < DECODEN; zX++)
+        {
+            if (pP->inputsFromDecodes[zX] == z) {
+                zD = zX;
+                break;
+            }
+        }
+
+        if (inpIOtemp[z].hIoPhy) {
+            //determine associated decoder
+            if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
+                pAstCfg->xDec[zD].decodeControl.sampleRate) {
+                if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
+                    pAstCfg->xDec[zD].decodeControl.sampleRate =
+                        pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
+                }
+                else {
+                    TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
+                    TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
+                        pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
+                        pAstCfg->xDec[zD].decodeControl.sampleRate);
+                    // return (ASPERR_INFO_RATECHANGE);
+                }
+            }
+
+            tempVar8 = readSharedMem((Int8 *)&(pAstCfg->xDec[zD].decodeStatus.sourceDecode));
+            pAstCfg->xDec[zD].decodeControl.emphasis =
+                tempVar8 != PAF_SOURCE_PCM
+                ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
+                : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
+        }
+        else {
+            pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
+            pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
+        }
+    } /* end of for (z=INPUT1; z < INPUTN; z++) */
+
+    // Wait for info input: (JX) all SIO_reclaim does is pend on data, and do sync scan or sync check,
+    //                           which is done in autoDetection routine now.
+    //if (pAstCfg->xInp[zMI].hRxSio)
+    //    sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
+    // FL: debug, capture input buffer
+    //capIb(pAstCfg->xInp[zMI].pInpBuf);
+    //gCapIb_cnt++;
+
+    // Decode info
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        zI = pP->inputsFromDecodes[z];
+        zS = pP->streamsFromDecodes[z];
+        (void)zS; // clear compiler warning in case not used with tracing disabled
+
+        if ( inpIOtemp[zI].hIoPhy &&
+             readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))
+        {
+            TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
+
+            if (errno = asipUpdateInputStatus(inpIOtemp[zI].pRxParams,
+                                              &pAstCfg->xInp[zI].inpBufStatus,
+                                                                                         &pAstCfg->xInp[zI].inpBufConfig)) {
+                TRACE_TERSE1("return error errno 0x%x.", errno);
+                return errno;
+            }
+
+            // debug, capture input buffer
+            capIb(pAstCfg->xInp[zI].pInpBuf);
+            gCapIb_cnt++;
+
+            // write back Inp configuration
+            Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
+            // write back input data //  (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
+            //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
+            //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
+            //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
+            // write back Dec configuration
+            Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+            Cache_wait();
+
+            errno = asipSendMsgToDecoder(ASP_SLAVE_DEC_INFO, z, ASP_MASTER_DEC_INFO_DONE, NULL);
+
+            // (***) FL: revisit
+            // invalidate Dec configuration
+            Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+            Cache_wait();
+
+            if (errno) {
+                TRACE_TERSE1("return error errno 0x%x.", errno);
+                return errno;
+            }
+
+            tempVar = readSharedMemInt((Int *)&(pAstCfg->xDec[z].decodeStatus.frameCount));
+            // increment decoded frame count
+            tempVar += 1;
+            writeSharedMemInt((Int *)&(pAstCfg->xDec[z].decodeStatus.frameCount), tempVar);
+        }
+    } // z=DECODE1 to DECODEN
+
+    // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
+    if (readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.mode))) {
+#if 0
+        //JXTODO: implement ioDataControl
+       ioDataCtl_t ioDataCtl;
+       ioDataCtl.code = IODATA_CTL_GET_SOURCEPROGRAM;
+        if (errno = ioDataControl(inpIOtemp->hIoData, &ioDataCtl)) {
+            TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
+            return ASPERR_AUTO_PROGRAM;
+        }
+#endif
+        writeSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
+                              (Int8)pD->sourceProgram);
+                              //(Int8)ioDataCtl.param.sourceProgram);
+    }
+
+    // since now decoding update decode status for all enabled decoders
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        if (readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode))) {
+               tempVar8 = readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.sourceProgram));
+            writeSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.sourceDecode), tempVar8);
+            tempVar8 = readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.sourceSelect));
+            if (tempVar8 == PAF_SOURCE_SNG) {
+                writeSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.sourceDecode), tempVar8);
+            }
+        }
+    }
+
+       return ASIP_DECODE_NO_ERR;
+} /* decDecodeInfo */
+
+
+// -----------------------------------------------------------------------------
+// ASIT Decoding Function - Decode Processing
+//
+//   Name:      PAF_ASIT_decodeDecode
+//   Purpose:   Decoding Function for processing of input data by the
+//              Decode Algorithm.
+//   From:      AST Parameter Function -> decodeProcessing
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+// -----------------------------------------------------------------------------
+Int
+decDecodeData(
+    const PAF_ASIT_Params *pP,
+    const PAF_ASIT_Patchs *pQ,
+    PAF_ASIT_Config *pC,
+    Int sourceSelect,
+    Int frame,
+    Int block
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* decode/stream counter */
+    Int errno;                  /* error number */
+    //Int ch;
+    Int cbErrno;
+    Int frameLength;
+    ioPhyCtl_t ioPhyCtl;
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    (void)as; // clear compiler warning in case not used with tracing disabled
+
+    // Decode data
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        Int zI = pP->inputsFromDecodes[z];
+        Int zS = pP->streamsFromDecodes[z];
+        (void)zS; // clear compiler warning in case not used with tracing disabled
+        if ( inpIOtemp[zI].hIoPhy &&
+             readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))
+        {
+            TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
+
+            TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
+                    as+zS,
+                    (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
+                    (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
+
+            // FL: debug, capture input buffer
+            //capIbPcm(pAstCfg->xInp[z].pInpBuf);
+
+            // (***) FL: revisit
+            // write back Dec configuration
+            Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+            Cache_wait();
+
+            errno = asipSendMsgToDecoder(ASP_SLAVE_DEC_DECODE, z, ASP_MASTER_DEC_DECODE_DONE, &cbErrno);
+            if (cbErrno != 0) {
+                //gCbWrtAfErrCnt++;
+                TRACE_TERSE1("CB write error=%d", cbErrno);
+                //SW_BREAKPOINT; // temporary
+            }
+
+            // (***) FL: revisit
+            // invalidate Dec configuration
+            Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
+            Cache_wait();
+
+            if (errno) {
+                TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
+                return errno;
+            }
+
+            frameLength = decDecideFrameLength(sourceSelect);
+
+            pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
+            pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
+
+            //JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
+        } // hIoPhy && decodeStatus.mode
+        else {
+            TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
+        }
+    } // z=DECODE1 to DECODEN
+
+       return ASIP_DECODE_NO_ERR;
+} /* decDecodeData */
+
+//JXTODO: what does this frame length have to with IECframeLength[23]
+Int decDecideFrameLength(Int sourceSelect)
+{
+       Int frameLength;
+
+    if (sourceSelect == PAF_SOURCE_PCM) {
+       frameLength = PAF_SYS_FRAMELENGTH;
+    }
+    else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3)) {
+        frameLength = 1536;   //JXTODO: replace 1536 with macro
+    }
+    else if (sourceSelect == PAF_SOURCE_THD) {
+        frameLength = 1536;   //JXTODO: replace 1536 with macro
+    }
+    else {
+        frameLength = 256;   //JXTODO: replace 256 with macro
+    }
+
+    return frameLength;
+} /* decDecideFrameLength */
+
+
+// -----------------------------------------------------------------------------
+// ASIT Decoding Function - Stream-Final Processing
+//
+//   Name:      PAF_ASIT_decodeComplete
+//   Purpose:   Decoding Function for terminating the decoding process.
+//   From:      AST Parameter Function -> decodeProcessing
+//   Uses:      See code.
+//   States:    x
+//   Return:    0.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//
+Int
+asipDecodeComplete(
+    const PAF_ASIT_Params *pP,
+    const PAF_ASIT_Patchs *pQ,
+    PAF_ASIT_Config *pC,
+    ALG_Handle decAlg[]
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* decode/encode counter */
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    (void)as;  // clear compiler warning in case not used with tracing disabled
+
+#ifdef PAF_ASP_FINAL
+    /* This material is currently not utilized */
+#endif /* PAF_ASP_FINAL */
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+#ifdef PAF_ASP_FINAL
+        DEC_Handle dec = (DEC_Handle )decAlg[z];
+#endif /* PAF_ASP_FINAL */
+
+        Int zI = pP->inputsFromDecodes[z];
+        if ( inpIOtemp[zI].hIoPhy &&
+             readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))
+        {
+            TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
+
+#ifdef PAF_ASP_FINAL
+            if (dec->fxns->final)
+                dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
+                                 &pAstCfg->xDec[z].decodeStatus);
+#endif /* PAF_ASP_FINAL */
+
+            // FL: send dec deactivate message to slave
+            asipSendMsgToDecoder(ASP_SLAVE_DEC_DEACTIVATE, z, ASP_MASTER_DEC_DEACTIVATE_DONE, NULL);
+        }
+        else {
+            TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
+        }
+    }
+    return 0;
+} //asipDecodeComplete
+
+#endif
+/* Nothing past this line */
index 7449c0779cb931933b0133c79eef76548e65c5eb..19c7eba584272a9b79380322e911fb77ce85b8bb 100644 (file)
@@ -3830,44 +3830,3 @@ static Int getFrameLengthSourceSel(
     
     return frameLength;
 }
-#define STRIDE_WORST_CASE 32  // 4-byte (32-bit) word, 2 slots, 4 serializers
-
-extern const MdUns iecFrameLength[23];
-extern void * hMcaspRxChan;
-
-void asipInitIoComps(const PAF_ASIT_Params *pP, PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
-{
-  ioBuffParams_t ioBuffParams;
-  ioPhyParams_t  ioPhyParams;
-  ioDataParam_t  ioDataCfg;
-
-  ioBuffParams.base         = pInpBuf->inpBufConfig.base.pVoid;
-  ioBuffParams.size         = pInpBuf->inpBufConfig.allocation/STRIDE_WORST_CASE*STRIDE_WORST_CASE;
-  ioBuffParams.sync         = IOBUFF_WRITE_SYNC;
-  ioBuffParams.nominalDelay = 30720*2;   // to remove magic number
-  if(ioBuffInit(pInpIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) {
-      SW_BREAKPOINT;
-  }
-
-  ioPhyParams.ioBuffHandle    = pInpIo->hIoBuff;
-  ioPhyParams.xferFrameSize   = 128*8*2; // to remove magic number
-  ioPhyParams.mcaspChanHandle = hMcaspRxChan;
-  ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_WRITE;
-  if(ioPhyInit(pInpIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) {
-      SW_BREAKPOINT;
-  }
-
-  ioDataCfg.ioBuffHandle         = pInpIo->hIoBuff;
-  ioDataCfg.unknownSourceTimeOut = pInpBuf->inpBufConfig.pBufStatus->unknownTimeout;
-  ioDataCfg.frameLengthsIEC      = (uint_least16_t *)&iecFrameLength[0];
-  ioDataCfg.frameLengthPCM       = 512;      // to remove magic number
-  ioDataCfg.frameLengthDef       = 128*8;    // to remove magic number
-  ioDataCfg.ibMode               = pInpBuf->inpBufConfig.pBufStatus->mode;
-  ioDataCfg.zeroRunRestart       = pInpBuf->inpBufConfig.pBufStatus->zeroRunRestart;
-  ioDataCfg.zeroRunTrigger       = pInpBuf->inpBufConfig.pBufStatus->zeroRunTrigger;
-
-  if(ioDataInit(&pInpIo->hIoData, &ioDataCfg) != IODATA_NO_ERR) {
-      SW_BREAKPOINT;
-  }
-
-} /* asipInitIoComps */
index 490fc2200003d44df0d55f015ff34bf8a758f2fb..a53c38602755d5349743d62e3f5fff7df8321bc1 100644 (file)
@@ -180,13 +180,19 @@ typedef struct PAF_ASIT_Patchs {
     //const PAF_ASP_LinkInit * const (*i_encLinkInit);
 } PAF_ASIT_Patchs;
 
+enum {
+    ASIP_NO_ERR,
+    ASIP_ERR_AUTO_DETECION,
+    ASIP_ERR_SWITCH_TO_PCM,
+    ASIP_ERR_MCASP_CFG
+};
+
 // Input I/O structure
 typedef struct PAF_AST_InpIO {
     ioPhyHandle_t        hIoPhy;     /* handle to I/O physical layer */
     ioBuffHandle_t       hIoBuff;    /* handle to I/O buffer management */
     ioDataHandle_t       hIoData;    /* handle to I/O data processing */
     const void           *pRxParams; /* pointer to D10 Rx Params */
-    Int                  swapData;
 
     Int       syncState;
     Int       numPrimeXfers;
@@ -203,10 +209,20 @@ typedef struct PAF_AST_InpIO {
     //uint32_t numXferFinish;
     //uint32_t numXferInterm;
     uint32_t numInputOverrun;
+    uint32_t numUnderflow;
     uint32_t numAsipRestart;
     uint32_t numAsipDecodeQuit;
-
+    uint32_t numFrameReceived;
+    uint32_t numPcmFrameReceived;
+
+    size_t         phyXferSize;
+    int_fast32_t   switchHangOver;
+    uint_least16_t asipState;
+    uint_least16_t asipProcState;
+    bool           buffReadComplete;
+    bool           swapData;
 } PAF_AST_IoInp;
+
 // Audio Stream Input Task (ASIT) configuration
 typedef struct PAF_ASIT_Config {
     Task_Handle taskHandle;     // ASIT handle
@@ -520,4 +536,11 @@ static inline Int sharedMemReadInt(volatile XDAS_Int32 *address, Int gateIdx)
 #endif
 }
 
+
+Int rxDecodePcm(PAF_AST_IoInp  *pInp);
+
+Int rxDecodeBitStream(PAF_AST_IoInp  *pInp);
+
+Int rxDecodePlayZero(PAF_AST_IoInp  *pInp);
+
 #endif /* _ASIP_H_ */
diff --git a/pasdk/test_dsp/framework/audioStreamInpProcNewIO.c b/pasdk/test_dsp/framework/audioStreamInpProcNewIO.c
new file mode 100644 (file)
index 0000000..9c37ea1
--- /dev/null
@@ -0,0 +1,985 @@
+
+/*
+Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without 
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+/*
+ *  ======== audioStreamInpProcNewIo.c ========
+ */
+#include <xdc/runtime/Log.h>
+#include <ti/sysbios/BIOS.h>
+
+#include "audioStreamInpProc.h"
+#include "audioStreamProc_common.h"
+#include "asperr.h"
+
+#include "audk2g.h"
+#include "audk2g_audio.h"
+#include "mcasp_cfg.h"
+#include "ioConfig.h"    //TODO: remove this header
+#include "ioBuff.h"
+#include "ioPhy.h"
+#include "ioData.h"
+
+
+
+#define SYNC_PC_MASK         0x1F
+#define SYNC_SUBTYPE_MASK    0x700
+#define SYNC_SUBTYPE_SHIFT   8
+#define SYNC_SUBTYPE_DTSHD   0x11
+#define SYNC_DDP             0x15
+#define SYNC_THD             0x16
+
+#define IEC_HEADER_LENGTH    4
+
+
+//table needed until PAF_SOURCE is reordered to match IEC numbering
+const SmUns IECpafSource[23] =
+{
+    PAF_SOURCE_UNKNOWN,  // 0: IEC NULL Type
+    PAF_SOURCE_AC3,      // 1: Comments on 1-15 match IEC 61937 part 2.
+    PAF_SOURCE_UNKNOWN,  // 2: IEC reserved
+    PAF_SOURCE_UNKNOWN,  // 3: IEC pause
+    PAF_SOURCE_UNKNOWN,  // 4: MPEG 1 layer 1
+    PAF_SOURCE_MP3,      // 5: MPEG layer 2 or 3
+    PAF_SOURCE_UNKNOWN,  // 6: MPEG 2 data with extension
+    PAF_SOURCE_AAC,      // 7: MPEG-2 AAC ADTS
+    PAF_SOURCE_UNKNOWN,  // 8: MPEG 2 layer 1 low sampling frequency
+    PAF_SOURCE_UNKNOWN,  // 9: MPEG 2 layer 2 or 3 low sampling frequency
+    PAF_SOURCE_UNKNOWN,  // 10: reserved
+    PAF_SOURCE_DTS,      // 11: DTS type 1 (11 bit: 512 sample repeat period)
+    PAF_SOURCE_DTS12,    // 12: DTS type 2 (12 bit: 1024 sample repeat period)
+    PAF_SOURCE_DTS13,    // 13: DTS type 3 (13 bit: 2048 sample repeat period)
+    PAF_SOURCE_DTS14,    // 14: ATRAC
+    PAF_SOURCE_UNKNOWN,  // 15: ATRAC 2/3
+    PAF_SOURCE_THD,      // 16
+    PAF_SOURCE_DTSHD,    // 17
+    PAF_SOURCE_WMA9PRO,  // 18
+    PAF_SOURCE_UNKNOWN,  // 19
+    PAF_SOURCE_UNKNOWN,  // 20
+    PAF_SOURCE_DDP,      // 21
+    PAF_SOURCE_THD,      // 22
+};
+
+/*
+ * Functions defined in other files and to be put into proper header files
+ */
+extern Void taskAsipFxnInit(const PAF_ASIT_Params *pP,const PAF_ASIT_Patchs *pQ);
+
+
+// avoid including sap_d10.h, which would cause symbol redefinition
+// warning (MCASP_PFUNC_XXX)
+extern XDAS_Int32 D10_init();
+extern XDAS_Int32 D10_RxControl(const void *pD10RxParams,
+                                XDAS_Int32 code, XDAS_Int32 arg);
+
+/*
+ * Functions only used in this file
+ */
+int asipPrepareProcessing();
+int asipIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo);
+void asipProcInit(PAF_AST_IoInp  *pInp);
+void asipIoPhyPrime(PAF_AST_IoInp *pInpIo);
+void asipPhyTransferPend(void);
+void asipPhyTransferComplete(PAF_AST_IoInp * pInpIo);
+void asipPhyTransferStart(PAF_AST_IoInp *pInpIo);
+Int asipSelectDevices(const PAF_ASIT_Patchs *pQ, PAF_AST_IoInp *pInp);
+Int asipUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
+                          PAF_InpBufConfig *pInpBuf);
+
+Int asipProcessing(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp);
+void asipErrorHandling(PAF_AST_Config *pAstCfg, int asipErrno);
+
+/*
+ * variables/structures to be put into proper global structures
+ */
+extern Semaphore_Handle asipSemRx;
+extern PAF_ASIT_Config gPAF_ASIT_config;
+
+enum
+{
+    ASIP_SOURCE_DETECTION,
+    ASIP_DECODE_BITSTREAM,
+    ASIP_SWITCH_TO_PCM,
+    ASIP_DECODE_PCM
+};
+
+enum
+{
+    ASIP_INPUT_PREPARATION,
+    ASIP_INPUT_PROCESSING
+};
+
+#define ASIP_DEBUG
+
+#ifdef ASIP_DEBUG
+/* define the following as global variables for easy debugging */
+int asipLoopCount1, asipLoopCount2;
+Int asipErrno;
+Int inputReadyForProcessing;
+#endif
+
+/*
+ *  ======== taskAsipFxn ========
+ *  Audio Stream Input Processing task function
+ */
+#ifndef PASDK_SIO_DEV
+#ifndef IO_LOOPBACK_TEST
+Void taskAsipFxn(                  // ASIP task function for new I/O
+#else
+Void taskAsipFxn_NewIO_Not_Used(   // not used for loopback test
+#endif
+#else
+Void taskAsipFxn_NewIO_Not_USED(   // not used for SIO/DEV based I/O
+#endif
+    const PAF_ASIT_Params *pP,
+       const PAF_ASIT_Patchs *pQ)
+{
+    PAF_ASIT_Config *pAsitCfg;      /* ASIT configuration pointer */
+    PAF_AST_Config  *pAstCfg;       /* AST Common (shared) configuration pointer */
+    PAF_AST_IoInp *pInp;            /* Input I/O components */
+    Int as;                         /* Audio Stream Number (1, 2, etc.) */
+    Int z;                          /* input/encode/stream/decode/output counter */
+    Int zMI;
+#ifndef ASIP_DEBUG
+int asipLoopCount1, asipLoopCount2;
+Int asipErrno;
+Int inputReadyForProcessing;
+#endif
+
+    Log_info0("Enter taskAsipFxn()");
+
+    taskAsipFxnInit(pP, pQ);  // initialization of input task
+    
+    //
+    // Audio Stream Input Task Configuration (*pAsitCfg):
+    //
+    pAsitCfg = &gPAF_ASIT_config;       // initialize pointer to task configuration
+    pAstCfg  = pAsitCfg->pAstCfg;       // pointer to AST common (shared) configuration
+    pInp     = pAsitCfg->pIoInp;        // pointer to input I/O components
+
+    /* Set Audio Stream Number (1, 2, etc.) */
+    as = pAstCfg->as;
+
+    //
+    // Determine decoder and stream indices associated with the master input
+    //
+    zMI = pP->zone.master;
+
+    pInp[zMI].numPrimeXfers = NUM_PRIME_XFERS;
+    //asipInitDebug(&pInp[zMI]);
+
+    for (z=STREAM1; z < STREAMN; z++)
+    {
+        TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
+    }
+
+    TRACE_TERSE0("TaskAsip: Entering Main Loop.");
+
+#if 0
+    // Wait until input device is ready - change this to event based scheduling
+    asipErrno = 0;
+    while (!inputReadyForProcessing)
+    {
+        // Indicate decoder no decoding yet
+        pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
+
+        Task_sleep(5);  // 5 system tick, or 5 msec. Should remove this later when implementing event based scheduling.
+
+        inputReadyForProcessing = asipPrepareProcessing(pP, pQ, pAsitCfg, &asipErrno);
+
+        if(asipErrno) {
+            asipErrorHandling(pAstCfg, asipErrno);
+        }
+    }
+
+    // .....................................................................
+    // At this point we have an enabled input and want to decode something.
+    // If no decoder selected then do nothing. Need to reset the sourceProgram, since
+    // when no decoder is selected there are no calls to IB
+    asipErrno = asipIoCompsInit(&pAstCfg->xInp[zMI], &pInp[zMI]);
+    if(asipErrno) {
+        printf("ASIP IO components init error!\n");
+        exit(0);
+    }
+
+    asipProcInit(&pInp[zMI]);
+
+    // start I/O physical layer by priming McASP LLD for input
+    asipIoPhyPrime(&pInp[zMI]);
+
+    //
+    // Main processing loop
+    //
+    asipErrno = 0;
+    for (;;)
+    {
+        // Pending on I/O PHY transfer
+        asipPhyTransferPend();
+
+        // Marks I/O PHY transfer and I/O BUFF write complete
+        asipPhyTransferComplete(&pInp[zMI]);
+
+        // Main function to process input data
+        asipErrno = asipProcessing(pAstCfg, &pInp[zMI]);
+
+        // Start next transfer
+        asipPhyTransferStart(&pInp[zMI]);
+
+        if(asipErrno) {
+            asipErrorHandling(pAstCfg, asipErrno);
+        }
+    }
+#endif
+
+#if 0
+    //
+    // Main processing loop
+    //
+    asipLoopCount1 = 0;
+    asipLoopCount2 = 0;
+    asipErrno = 0;
+    inputReadyForProcessing = FALSE;
+    for (;;)
+    {
+        asipLoopCount1++;
+
+        if(asipErrno) {
+            asipErrorHandling(pAstCfg, asipErrno);
+
+            inputReadyForProcessing = FALSE;
+        }
+
+        // Wait until input device is ready - change this to event based scheduling
+        if(!inputReadyForProcessing) {
+            // Indicate decoder no decoding yet
+            pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
+
+            // 5 system tick, or 5 msec. Should remove this later when implementing
+            // event based scheduling.
+            Task_sleep(5);
+
+            inputReadyForProcessing = asipPrepareProcessing(pP, pQ, pAsitCfg, &asipErrno);
+
+            if (inputReadyForProcessing) {
+                // Input is ready for processing, so we initialize the I/O components
+                asipIoCompsInit(&pAstCfg->xInp[zMI], &pInp[zMI]);
+
+                // Initialize ASIP processing
+                asipProcInit(&pInp[zMI]);
+
+                // Start I/O physical layer by priming McASP LLD for input
+                asipIoPhyPrime(&pInp[zMI]);
+            }
+            else {
+                // Input is not ready, so go back to the beginning of the loop
+                continue;
+            }
+        }  /* if(!inputReadyForProcessing) */
+
+        // Pending on I/O PHY transfer
+        asipPhyTransferPend();
+
+        // Marks I/O PHY transfer and I/O BUFF write complete
+        asipPhyTransferComplete(&pInp[zMI]);
+
+        // Main function to process input data
+        asipErrno = asipProcessing(pAstCfg, &pInp[zMI]);
+
+        // Start next transfer
+        asipPhyTransferStart(&pInp[zMI]);
+
+        asipLoopCount2++;
+    }  // for (;;)
+#endif
+
+    //
+    // Main processing loop
+    //
+    asipLoopCount1 = 0;
+    asipLoopCount2 = 0;
+    asipErrno = 0;
+    inputReadyForProcessing = FALSE;
+    pInp->asipState = ASIP_INPUT_PREPARATION;
+
+    for (;;)
+    {
+        asipLoopCount1++;
+
+        switch (pInp->asipState)
+        {
+        case ASIP_INPUT_PREPARATION:
+            // Indicate decoder no decoding yet
+            pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
+
+            // 5 system tick, or 5 msec. Should remove this later when implementing
+            // event based scheduling.
+            Task_sleep(5);
+
+            inputReadyForProcessing = asipPrepareProcessing(pP, pQ, pAsitCfg, &asipErrno);
+
+            if (inputReadyForProcessing) {
+                // Input is ready for processing, so we initialize the I/O components
+                asipIoCompsInit(&pAstCfg->xInp[zMI], &pInp[zMI]);
+
+                // Initialize ASIP processing
+                asipProcInit(&pInp[zMI]);
+
+                // Start I/O physical layer by priming McASP LLD for input
+                asipIoPhyPrime(&pInp[zMI]);
+
+                pInp->asipState = ASIP_INPUT_PROCESSING;
+            }
+            break;
+
+        case ASIP_INPUT_PROCESSING:
+            // Pending on I/O PHY transfer
+            asipPhyTransferPend();
+
+            // Marks I/O PHY transfer and I/O BUFF write complete
+            asipPhyTransferComplete(&pInp[zMI]);
+
+            // Main function to process input data
+            asipErrno = asipProcessing(pAstCfg, &pInp[zMI]);
+
+            // Start next transfer
+            asipPhyTransferStart(&pInp[zMI]);
+
+            if(asipErrno) {
+                asipErrorHandling(pAstCfg, asipErrno);
+
+                pInp->asipState = ASIP_INPUT_PREPARATION;
+            }
+
+            break;
+
+        default:
+            break;
+        }
+    }  // for (;;)
+
+}  /* taskAsipFxn */
+
+extern const MdUns iecFrameLength[23];
+extern Ptr hMcaspRxChan;
+#define STRIDE_WORST_CASE 32  // 4-byte (32-bit) word, 2 slots, 4 serializers
+
+
+/*===========================================================================
+ * ASIP processing preparation
+ * Output:
+ *        - return        TRUE (input is ready) or FALSE (input is not ready)
+ *        - *asipErrno        Error number
+============================================================================*/
+Int asipPrepareProcessing(const PAF_ASIT_Params *pP,
+                          const PAF_ASIT_Patchs *pQ,
+                          PAF_ASIT_Config       *pC,
+                          Int                   *asipErrno)
+{
+    Int as, zMS, zMI, zMD;
+    Int sourceConfig, mode;
+    PAF_AST_Config  *pAstCfg;
+    PAF_AST_IoInp *pInp;            /* I/O components for input */
+
+    pAstCfg  = pC->pAstCfg;         // pointer to AST common (shared) configuration
+    as  = pAstCfg->as;
+    zMI = pP->zone.master;
+    zMD = pAstCfg->masterDec;
+    zMS = pAstCfg->masterStr;
+    pInp = pC->pIoInp;              // pointer to input I/O components
+
+    *asipErrno = 0;
+
+    // Select source and initialize physical layer / HW interface
+    *asipErrno = asipSelectDevices(pQ, pInp);
+    if (*asipErrno) {
+        TRACE_TERSE2("TaskAsip: selectDevices returned asipErrno = 0x%04x at line %d. AS%d", *asipErrno, as+zMS);
+        return FALSE;    // Input is not ready for processing due to error
+    }
+
+    // If no master input selected then we don't know what may be at the input,
+    // so set to unknown and skip any remaining processing
+    if (!pInp[zMI].pRxParams) {
+        sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
+                           (Int8)PAF_SOURCE_UNKNOWN, GATEMP_INDEX_DEC);
+
+        TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
+        return FALSE;    // No error, but input is not ready for processing
+    }
+
+    // If here then we have a valid input so query its status
+    *asipErrno = asipUpdateInputStatus(pInp[zMI].pRxParams,
+                                   &pAstCfg->xInp[zMI].inpBufStatus,
+                                   &pAstCfg->xInp[zMI].inpBufConfig);
+    if(*asipErrno) {
+        TRACE_VERBOSE1("TaskAsip: updateInputStatus returns 0x%x", *asipErrno);
+        return FALSE;   // Input is not ready for processing due to error
+    }
+
+    // If master decoder is not enabled, or the input is unlocked, then do nothing
+    mode = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
+                                  GATEMP_INDEX_DEC);
+    if (!mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
+    {
+        TRACE_VERBOSE0("TaskAsip: Not locked, continue");
+        return FALSE;  // No error, but input is not ready for processing
+    }
+
+    // Check selected source: sourceSelect is set by another task, AIP or AFP
+    sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
+                                          GATEMP_INDEX_DEC);
+    // If no source selected then do nothing
+    if(sourceConfig == PAF_SOURCE_NONE) {
+        sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
+                           (Int8)PAF_SOURCE_NONE, GATEMP_INDEX_DEC);
+        TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
+        return FALSE;  // No error, but input is not ready for processing
+    }
+
+    // If we want pass processing then proceed directly
+    if (sourceConfig == PAF_SOURCE_PASS)
+    {
+        TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
+        sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
+                           (Int8)PAF_SOURCE_PASS, GATEMP_INDEX_DEC);
+
+        pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
+        if (pP->fxns->passProcessing) {
+            *asipErrno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
+        }
+        else {
+            TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, asipErrno 0x%x", as+zMS, ASPERR_PASS);
+            *asipErrno = ASPERR_PASS;
+        }
+
+        TRACE_VERBOSE0("TaskAsip: continue");
+        return FALSE;  // Error or not, input is not ready for processing
+    }
+
+    // No error and input processing is ready
+    return TRUE;
+} /* asipPrepareProcessing */
+
+/*===========================================================================
+ * Initialize I/O components for input processing
+============================================================================*/
+int asipIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
+{
+    // Initialize I/O BUFF and I/O PHY components for input task
+    ioBuffParams_t ioBuffParams;
+    ioPhyParams_t  ioPhyParams;
+    ioDataParam_t  ioDataCfg;
+
+    ioBuffParams.base         = pInpBuf->inpBufConfig.base.pVoid;
+    ioBuffParams.size         = pInpBuf->inpBufConfig.allocation/STRIDE_WORST_CASE*STRIDE_WORST_CASE;
+    ioBuffParams.sync         = IOBUFF_WRITE_SYNC;
+    ioBuffParams.nominalDelay = INPUT_FRAME_SIZE_DEF;
+    if(ioBuffInit(pInpIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) {
+        return (-1);   // to remove magic number
+    }
+
+    ioPhyParams.ioBuffHandle    = pInpIo->hIoBuff;
+    ioPhyParams.xferFrameSize   = INPUT_FRAME_SIZE_DEF;
+    ioPhyParams.mcaspChanHandle = hMcaspRxChan;
+    ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_WRITE;
+    if(ioPhyInit(pInpIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) {
+        return (-1);   // to remove magic number
+    }
+
+    ioDataCfg.ioBuffHandle         = pInpIo->hIoBuff;
+    ioDataCfg.unknownSourceTimeOut = pInpBuf->inpBufConfig.pBufStatus->unknownTimeout;
+    ioDataCfg.frameLengthsIEC      = (uint_least16_t *)&iecFrameLength[0];
+    ioDataCfg.frameLengthPCM       = INPUT_FRAME_SIZE_PCM / WORD_SIZE_PCM;
+    ioDataCfg.frameLengthDef       = INPUT_FRAME_SIZE_DEF / WORD_SIZE_BITSTREAM;
+    ioDataCfg.ibMode               = pInpBuf->inpBufConfig.pBufStatus->mode;
+    ioDataCfg.zeroRunRestart       = pInpBuf->inpBufConfig.pBufStatus->zeroRunRestart;
+    ioDataCfg.zeroRunTrigger       = pInpBuf->inpBufConfig.pBufStatus->zeroRunTrigger;
+
+    if(ioDataInit(pInpIo->hIoData, &ioDataCfg) != IODATA_NO_ERR) {
+        return (-1);   // to remove magic number
+    }
+
+    pInpIo->phyXferSize    = ioPhyParams.xferFrameSize;
+    pInpIo->switchHangOver = 0;
+    pInpIo->syncState      = IODATA_SYNC_NONE;
+
+    return 0;
+} /* asipIoCompsInit */
+
+/*======================================================================================
+ *  This function initializes ASIP processing
+ *====================================================================================*/
+void asipProcInit(PAF_AST_IoInp  *pInp)
+{
+    pInp->swapData = SWAP_INPUT_DATA;
+    pInp->asipProcState = ASIP_SOURCE_DETECTION;
+    pInp->switchHangOver = 0;
+}
+
+/*======================================================================================
+ *  I/O physical layer prime operation required by McASP LLD
+ *====================================================================================*/
+void asipIoPhyPrime(PAF_AST_IoInp *pInp)
+{
+    Int32        count;
+
+    for(count = 0; count < pInp->numPrimeXfers; count++)
+    {
+        ioPhyXferSubmit(pInp->hIoPhy);
+#ifdef ASIP_DEBUG
+        //pInp->numXferStart++;
+#endif
+    }
+} /* asipIoPhyPrime */
+
+/*======================================================================================
+ *  This function pends on I/O PHY transfer for the input task
+ *====================================================================================*/
+void asipPhyTransferPend()
+{
+    // asipSemRx needs to be placed into some data structure
+    Semaphore_pend(asipSemRx, BIOS_WAIT_FOREVER);
+} /* asipPhyTransferPend */
+
+/*======================================================================================
+ *  This function marks the I/O PHY transfer as complete
+ *====================================================================================*/
+void asipPhyTransferComplete(PAF_AST_IoInp * pInpIo)
+{
+    // Mark underlining I/O BUFF write complete and swap data if needed
+    ioPhyXferComplete(pInpIo->hIoPhy, pInpIo->swapData);
+} /* asipPhyTransferComplete */
+
+
+/*======================================================================================
+ *  McASP LLD call back function
+ *====================================================================================*/
+void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
+{
+    /* post semaphore */
+    if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
+        Semaphore_post(asipSemRx);
+    } else {
+        ;    // intermediate packet due to buffer wrapping around
+    }
+}
+
+/*======================================================================================
+ *  This function checks if McASP Rx for input overruns
+ *====================================================================================*/
+int asipCheckMcaspRxOverrun(void)
+{
+    Mcasp_errCbStatus mcaspErrStat;
+
+    mcaspControlChan(hMcaspRxChan, Mcasp_IOCTL_CHAN_QUERY_ERROR_STATS, &mcaspErrStat);
+
+    return (mcaspErrStat.isRcvOvrRunOrTxUndRunErr);
+}
+
+/*======================================================================================
+ *  This function restarts McASP LLD channel for input
+ *====================================================================================*/
+void asipMcaspRxRestart(void)
+{
+    mcaspRxReset();
+    mcaspRxCreate();
+}
+
+/*======================================================================================
+ *  This function starts an I/O PHY transfer
+ *====================================================================================*/
+void asipPhyTransferStart(PAF_AST_IoInp *pInpIo)
+{
+    if(asipCheckMcaspRxOverrun()) {
+#ifdef ASIP_DEBUG
+        pInpIo->numInputOverrun++;
+#endif
+        asipMcaspRxRestart();
+    }
+    else {
+        if(ioPhyXferSubmit(pInpIo->hIoPhy)==IOPHY_ERR_BUFF_OVERFLOW) {
+            // Input buffer overflows!
+            printf("\nInput buffer overflows!\n");
+            exit(0);
+        }
+        else {
+            // Input buffer operates normally
+            ;
+        }
+#ifdef ASIP_DEBUG
+        //pInpIo->numXferStart++;
+#endif
+    }
+}
+
+Int d10Initialized = 0;
+//extern Audk2g_STATUS mcaspAudioConfig(void);
+extern void McaspDevice_init(void);
+
+/*======================================================================================
+ *  This function initializes HW interface and selects the right device for input
+ *====================================================================================*/
+Int asipSelectDevices(const PAF_ASIT_Patchs *pQ, PAF_AST_IoInp *pInp)
+{
+    Audk2g_STATUS status;
+
+    //more configuration is needed to abstract out D10
+    if(!d10Initialized) {
+        /* Initialize McASP HW details */
+        McaspDevice_init();
+
+        D10_init();
+
+#ifdef INPUT_SPDIF
+        // Input is DIR
+        status = audk2g_AudioSelectClkSrc(AUDK2G_AUDIO_CLK_SRC_DIR);
+#else
+        // Input is HDMI
+        status = audk2g_AudioSelectClkSrc(AUDK2G_AUDIO_CLK_SRC_I2S);
+#endif
+        if(status != Audk2g_EOK) {
+            Log_info0("audk2g_AudioSelectClkSrc Failed!\n");
+        }
+        audk2g_delay(50000); // Without delay between these 2 calls system aborts.
+
+        /* Initialize McASP module */
+        status = mcaspAudioConfig(); //defined in newio\fw\mcasp_cfg.c
+        if(status != Audk2g_EOK) {
+            TRACE_TERSE0("McASP Configuration Failed!\n");
+        }
+
+        d10Initialized = 1;
+    }
+
+    /////////////// TODO: HW interface selection and initialization //////////////
+#ifdef IO_HW_INTERFACE
+    pInp->pRxParams = pQ->devinp->x[IO_HW_INTERFACE];
+#else
+    pInp->pRxParams = NULL;
+#endif
+
+    return 0;
+}  /* asipSelectDevices */
+
+/*======================================================================================
+ *  This function updates input status
+ *====================================================================================*/
+Int asipUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
+                          PAF_InpBufConfig *pInpBuf)
+{
+    Int asipErrno;
+
+    PAF_SIO_InputStatus inputStatus;
+
+    // initialize all values to unknown so that device specific
+    //   driver layer need only fill in those entries that it is aware of.
+    //   This allows extensibility of the structure without requiring users
+    //   to re-code.
+    inputStatus.lock = 0;
+    inputStatus.sampleRateData = PAF_SAMPLERATE_UNKNOWN;
+    inputStatus.sampleRateMeasured = PAF_SAMPLERATE_UNKNOWN;
+    inputStatus.nonaudio = PAF_IEC_AUDIOMODE_UNKNOWN;
+    inputStatus.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
+
+    //more configuration is needed to abstract out D10
+    asipErrno = D10_RxControl(pRxParams,
+                          (Uns)PAF_SIO_CONTROL_GET_INPUT_STATUS,
+                          (Arg) &inputStatus);
+    if (asipErrno)
+        return asipErrno;
+    pStatus->sampleRateData = inputStatus.sampleRateData;
+    pStatus->sampleRateMeasured = inputStatus.sampleRateMeasured;
+    pStatus->nonaudio = inputStatus.nonaudio;
+    pStatus->emphasisData = inputStatus.emphasis;
+
+    // if MSB of override clear then use as reported lock
+    // if = 0x80 then use default [0x81]
+    // if = 0x81 then use measured (from device)
+    // others not defined or implemented
+    if ((pStatus->lockOverride & (XDAS_Int8)0x80) == 0)
+        pStatus->lock = pStatus->lockOverride;
+    else if (pStatus->lockOverride == (XDAS_Int8)0x80)
+        pStatus->lock = inputStatus.lock;
+    else if (pStatus->lockOverride == (XDAS_Int8)0x81)
+        pStatus->lock = inputStatus.lock;
+
+    // if MSB of override clear then use it as sample rate for system,
+    // if = 0x80 then use default [0x82]
+    // if = 0x81 then use data
+    // if = 0x82 then use measured
+    // others not defined or implemented
+    if ((pStatus->sampleRateOverride & (XDAS_Int8)0x80) == 0)
+        pStatus->sampleRateStatus = pStatus->sampleRateOverride;
+    else if (pStatus->sampleRateOverride == (XDAS_Int8)0x80)
+        pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
+    else if (pStatus->sampleRateOverride == (XDAS_Int8)0x81)
+        pStatus->sampleRateStatus = pStatus->sampleRateData;
+    else if (pStatus->sampleRateOverride == (XDAS_Int8)0x82)
+        pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
+
+    // Update emphasis status:
+    if ((pStatus->emphasisOverride & (XDAS_Int8)0x80) == 0) {
+        if (pStatus->emphasisData == PAF_IEC_PREEMPHASIS_YES)
+            pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
+        else
+            pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
+    }
+    else if (pStatus->emphasisOverride ==
+             (XDAS_Int8 )(0x80+PAF_IEC_PREEMPHASIS_YES))
+        pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
+    else /* IBEmphasisOverrideNo or other */
+        pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
+
+    // Update precision control
+    pInpBuf->precision = pStatus->precisionInput =
+        pStatus->precisionOverride < 0
+        ? pStatus->precisionDefault
+        : pStatus->precisionOverride > 0
+        ? pStatus->precisionOverride
+        : pStatus->precisionDetect > 0
+        ? pStatus->precisionDetect
+        : pStatus->precisionDefault;
+
+    return 0;
+}
+
+
+/*=============================================================================
+ *  Main function of ASIP processing
+ *============================================================================*/
+#define INPUT_SWITCH_HANGOVER 8
+
+Int asipProcessing(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp)
+{
+    int autoDetstatus, syncState;
+    Audk2g_STATUS mcaspStatus;
+
+    ioDataCtl_t ioDataCtl;
+    ioPhyCtl_t  ioPhyCtl;
+
+    if(pInp->asipProcState == ASIP_SWITCH_TO_PCM) {
+        // When switching to PCM, McASP RFMT register will be modified,
+        // which will cause all 0's in one McASP LLD transfer. This will
+        // be detected as loss of SYNC by auto detection. To prevent that,
+        // skip I/O DATA process for hangover period so that this all 0's
+        // frame will not be seen by auto-detection. Also, playing out PCM
+        // needs to be skipped as well, to prevent from playing out garbage
+        // (16-bit packed data).
+        void *buff1, *buff2;
+        size_t size1, size2;
+
+        // Get read pointers (or sub-buffers) of the input buffer
+        if (ioBuffGetReadPtrs(pInp->hIoBuff, pInp->phyXferSize,
+                              &buff1, &size1, &buff2, &size2)
+            == IOBUFF_ERR_UNDERFLOW) {
+            //printf("Input buffer underflows during switch hangover!\n");
+            return ASIP_ERR_SWITCH_TO_PCM;
+        }
+
+        ioBuffReadComplete(pInp->hIoBuff, buff1, size1);
+
+        if(buff2 != NULL) {
+            ioBuffReadComplete(pInp->hIoBuff, buff2, size2);
+        }
+    }
+    else {
+        // Perform auto-detection when not switching
+        autoDetstatus = ioDataProcess(pInp->hIoData);
+        if(autoDetstatus == IODATA_ERR_IOBUF_UNDERFLOW) {
+            // Input buffer underflows - no action is needed
+            //printf("Input buffer underflows.\n");
+            pInp->numUnderflow += 1;
+
+            // Return since there is no enough data to process
+            return ASIP_NO_ERR;
+        }
+        else if(autoDetstatus != IODATA_NO_ERR) {
+            // Something run happens: print error log and return
+            //printf("IODATA processing error!\n");
+            return ASIP_ERR_AUTO_DETECION;
+        }
+        else {
+            // Normal operation - check auto-detection status
+            ioDataCtl.code = IODATA_CTL_GET_AUTODET_STATUS;
+            ioDataControl(pInp->hIoData, &ioDataCtl);
+
+            syncState = ioDataCtl.param.autoDetStats.syncState;
+        }
+    }
+
+    switch(pInp->asipProcState)
+    {
+    case ASIP_SOURCE_DETECTION:
+        // zero out the output buffer
+        rxDecodePlayZero(pInp);
+
+        ioDataReadComplete(pInp->hIoData);
+
+        if(syncState == IODATA_SYNC_BITSTREAM) {
+            // Change I/O PHY transfer size to be the same as the bitstream frame size
+            int frameSize;
+            uint_least16_t pc = ioDataCtl.param.autoDetStats.bitStreamInfo & SYNC_PC_MASK; //0x001F
+            frameSize = iecFrameLength[pc] * WORD_SIZE_BITSTREAM;
+
+            ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
+            ioPhyCtl.params.xferFrameSize = frameSize;
+            ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
+            pInp->phyXferSize = ioPhyCtl.params.xferFrameSize;
+
+            pInp->asipProcState = ASIP_DECODE_BITSTREAM;
+            pInp->numFrameReceived = 1;
+        }
+        else if(syncState == IODATA_SYNC_PCM) {
+            // reconfigure McASP LLD to transfer 32-bit unpacked data
+            mcaspStatus = mcaspRecfgWordWidth(hMcaspRxChan, Mcasp_WordLength_32);
+            if(mcaspStatus != Audk2g_EOK) {
+                return ASIP_ERR_MCASP_CFG;
+            }
+
+            // Change I/O PHY transfer size to PCM frame size
+            ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
+            ioPhyCtl.params.xferFrameSize = INPUT_FRAME_SIZE_PCM;
+            ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
+            pInp->phyXferSize = ioPhyCtl.params.xferFrameSize;
+
+            // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
+            // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
+            // Adjust delay and don't mark input buffer as read complete
+            ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
+
+            // Stop swapping data
+            pInp->swapData = FALSE;
+
+            // Go to transition state to switch to PCM
+            pInp->asipProcState = ASIP_SWITCH_TO_PCM;
+            pInp->switchHangOver = INPUT_SWITCH_HANGOVER;
+
+            pInp->numPcmFrameReceived = 0;
+        }
+        else {
+            // Source is still unknown - take no action
+            ;
+        }
+        break;
+
+    case ASIP_DECODE_BITSTREAM:
+        if (syncState == IODATA_SYNC_NONE) {
+            // Change I/O PHY transfer size to default
+            ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
+            ioPhyCtl.params.xferFrameSize = INPUT_FRAME_SIZE_DEF;
+            ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
+            pInp->phyXferSize  = ioPhyCtl.params.xferFrameSize;
+
+            pInp->numFrameReceived = 0;
+            pInp->asipProcState  = ASIP_SOURCE_DETECTION;
+        }
+        else {
+            pInp->numFrameReceived += 1;
+
+            rxDecodeBitStream(pInp);
+
+            ioDataReadComplete(pInp->hIoData);
+        }
+        break;
+
+    case ASIP_SWITCH_TO_PCM:
+        // zero out the output buffer
+        rxDecodePlayZero(pInp);
+
+        pInp->switchHangOver--;
+        if(pInp->switchHangOver == 0) {
+            pInp->asipProcState = ASIP_DECODE_PCM;
+            // send message to decoder
+        }
+        break;
+
+    case ASIP_DECODE_PCM:
+        if (syncState == IODATA_SYNC_NONE) {
+            // reconfigure McASP LLD to receive 16-bit packed bits
+            mcaspStatus = mcaspRecfgWordWidth(hMcaspRxChan, Mcasp_WordLength_16);
+            if(mcaspStatus != Audk2g_EOK) {
+                return ASIP_ERR_MCASP_CFG;
+            }
+
+            // Change I/O PHY transfer size to default
+            ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
+            ioPhyCtl.params.xferFrameSize = INPUT_FRAME_SIZE_DEF;
+            ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
+            pInp->phyXferSize  = ioPhyCtl.params.xferFrameSize;
+
+            // Start swapping data
+            pInp->swapData = TRUE;
+            pInp->numPcmFrameReceived = 0;
+
+            pInp->asipProcState = ASIP_SOURCE_DETECTION;
+        }
+        else {
+            pInp->numPcmFrameReceived += 1;
+
+            rxDecodePcm(pInp);
+
+            ioDataReadComplete(pInp->hIoData);
+        }
+
+        break;
+
+    default:
+        break;
+    }
+
+    return 0;
+} /* asipProcessing */
+
+#ifndef IO_LOOPBACK_TEST
+Int rxDecodePcm(PAF_AST_IoInp  *pInp)
+{
+    return ASIP_NO_ERR;
+}
+
+Int rxDecodeBitStream(PAF_AST_IoInp  *pInp)
+{
+    return ASIP_NO_ERR;
+}
+
+Int rxDecodePlayZero(PAF_AST_IoInp  *pInp)
+{
+    return ASIP_NO_ERR;
+}
+#endif
+
+void asipErrorHandling(PAF_AST_Config *pAstCfg, int asipErrno)
+{
+
+}
+
+/* Nothing past this line */
diff --git a/pasdk/test_dsp/framework/audioStreamOutDec.c b/pasdk/test_dsp/framework/audioStreamOutDec.c
new file mode 100644 (file)
index 0000000..ff4c54e
--- /dev/null
@@ -0,0 +1,815 @@
+
+/*
+Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+#if 0
+/*
+ *  ======== audioStreamOutProc.c ========
+ */
+
+#include <string.h> // for memset
+#include <xdc/runtime/Log.h>
+#include <xdc/runtime/Error.h>
+#include <xdc/runtime/Memory.h>
+#include <ti/sysbios/knl/Clock.h>
+#include <ti/sysbios/knl/Task.h>
+
+#include "paferr.h"
+#include <acp_mds.h>
+#include <pcm.h>
+#include <pce.h>
+#include <pafsio_ialg.h>
+#include <stdasp.h>
+#include <doberr.h>
+#include "asperr.h"
+
+#include "common.h"
+#include "aspMsg_common.h"
+#include "aspMsg_master.h"
+#include "aspDecOpCircBuf_master.h"
+#include "audioStreamProc_common.h"
+#include "audioStreamOutProc.h"
+
+// FL: debug
+#include "evmc66x_gpio_dbg.h"
+#define ENC_Handle PCE_Handle /* works for all: PCE */
+
+extern UInt32 gCbReadAfErr      ; // read circular buffer error count, not including underflows
+extern UInt32 gDecOpCbRdAfUnd   ; // decoder output circular buffer underflow count
+extern UInt32 gMaxDecOpCbRdAfUnd; // max (consecutive) decoder output circular buffer underflow count
+
+extern PAF_AST_OutIO *outIOtemp;    /* Output I/O */
+
+Int
+asopDecodeInit(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pC,
+       asopDecProc_t *dec
+)
+{
+    PAF_AST_Config *pAstCfg;
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    Int z;                              /* decode counter */
+    Int errno;                          /* error number */
+    Int zO, zS;
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+
+    // Reset audio frame pointers to original values
+    // (may be needed if error occurred).
+    for (z=STREAM1; z < STREAMN; z++)
+    {
+        Int ch;
+        for (ch=PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++)
+        {
+            if (pAstCfg->xStr[z].audioFrameChannelPointers[ch])
+            {
+                pAstCfg->xStr[z].audioFrameChannelPointers[ch] =
+                    pAstCfg->xStr[z].origAudioFrameChannelPointers[ch];
+            }
+        }
+    }
+
+    // Reset audio frame meta data elements
+    {
+        Int i;
+
+        for (z=STREAM1; z < STREAMN; z++)
+        {
+            pAstCfg->xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
+            pAstCfg->xStr[z].pAudioFrame->numPrivateMetadata = 0;
+            pAstCfg->xStr[z].pAudioFrame->bsMetadata_offset = 0;
+            pAstCfg->xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
+
+            for (i=0; i<pP->pMetadataBufStatus->NumBuf; i++)
+            {
+                pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
+                pAstCfg->xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
+            }
+        }
+    }
+
+    as = pAstCfg->as;
+    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        // Start decoder output circular buffer reads
+        errno = cbReadStart(pCbCtl, z);
+        if (errno) {
+            TRACE_TERSE1("PAF_ASOT_decodeInit:cbReadStart() error=%d", errno);
+            SW_BREAKPOINT; // FL: 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
+
+        // FL: debug
+        //cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
+    }
+
+    // TODO: move this to start of this function so that it doesn't affect IO timing
+    for (z=ENCODE1; z < ENCODEN; z++)
+    {
+        zO = pP->outputsFromEncodes[z];
+        zS = pP->streamsFromEncodes[z];
+        //if (pAstCfg->xOut[zO].hTxSio && pAstCfg->xEnc[z].encodeStatus.mode)
+        if (outIOtemp[zO].hIoPhy && 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;
+            TRACE_VERBOSE1("AS%d: PAF_ASOT_decodeInit: initializing encode", as+zS);
+            if (encAlg->fxns->algActivate)
+            {
+                encAlg->fxns->algActivate (encAlg);
+            }
+            if (enc->fxns->reset
+                && (errno = enc->fxns->reset(enc, NULL,
+                    &pAstCfg->xEnc[z].encodeControl, &pAstCfg->xEnc[z].encodeStatus)))
+            {
+                return errno;
+            }
+        }
+    }
+
+    //JXTODO: move decodeInfo1 to output task state machine
+    /*if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
+    {
+        TRACE_VERBOSE1("PAF_ASOT_decodeProcessing: INIT, errno 0x%x.  break after decodeInfo1", errno);
+        break;
+    }*/
+
+    dec->frame = 0;
+    dec->block = 0;
+
+       return ASOP_DECODE_NO_ERR;
+} /* asopDecodeInit */
+
+
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function - Info Processing, Initial
+//
+//   Name:      PAF_ASOT_decodeInfo1
+//   Purpose:   Decoding Function for processing information in a manner that
+//              is unique to initial frames of input data.
+//   From:      AST Parameter Function -> decodeProcessing
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard or SIO form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//
+// (***) FL: setup output (ASP chain reset, ENC reset, setCheckRateX, start output)
+//           Contained in INFO1 in combined FSM.
+// Establish secondary timing
+Int
+asopDecodeInfo1(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pC,
+    Int frame
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int z;                              /* decode/encode counter */
+    Int errno;                          /* error number */
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+
+    // run the chain of ASP's on the stream.
+    TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling streamChainFunction.");
+    if (errno = pP->fxns->streamChainFunction(pP, pQ, pC,
+        PAF_ASP_CHAINFRAMEFXNS_RESET, 1, frame))
+    {
+        TRACE_TERSE1("PAF_ASOT_decodeInfo1: streamChainFunction returns errno 0x%x ", errno);
+        return errno;
+    }
+
+    TRACE_VERBOSE0("PAF_ASOT_decodeInfo1: calling enc->info.");
+    for (z=ENCODE1; z < ENCODEN; z++)
+    {
+        Int zO = pP->outputsFromEncodes[z];
+        if (outIOtemp[zO].hIoPhy && 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)))
+            {
+                TRACE_TERSE1("PAF_ASOT_decodeInfo1: info returns errno 0x%x ", errno);
+                return errno;
+            }
+        }
+    }
+
+    if (errno = pP->fxns->setCheckRateX(pP, pQ, pC, 0))
+    {
+        // ignore if rateX has changed since we haven't, but are about to,
+        // start the output. If we didn't ignore this case then the state machine
+        // would restart unnecessarily, e.g. in the case of SRC, resulting in
+        // added latency.
+        if (errno != ASPERR_INFO_RATECHANGE)
+        {
+            TRACE_TERSE1("PAF_ASOT_decodeInfo1: setCheckRateX returns errno 0x%x, not RATECHANGE", errno);
+            return errno;
+        }
+        else
+        {
+            TRACE_TERSE0("PAF_ASOT_decodeInfo1: RATECHANGE returns RATECHANGE, ignoring");
+        }
+    }
+/*
+    if (errno = pP->fxns->startOutput(pP, pQ, pC)) // PAF_ASOT_startOutput, SIO_issue() call inside
+    {
+        if (errno == 0x105)
+        {
+            TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns RING BUFFER FULL (0x%x)", errno);
+        }
+        else
+        {
+            TRACE_TERSE1("PAF_ASOT_decodeInfo1: startOutput returns errno 0x%x", errno);
+        }
+        return errno;
+    }
+*/
+    return ASOP_DECODE_NO_ERR;
+} /* asopDecodeInfo1 */
+
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function Helper - SIO Driver Start
+//
+//   Name:      PAF_ASOT_startOutput
+//   Purpose:   Decoding Function for initiating output.
+//   From:      AST Parameter Function -> decodeInfo1
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard or SIO form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//              * SIO control errors.
+//
+#define DEC_OUTNUMBUF_MAP(X) \
+      pP->poutNumBufMap[z]->map[(X) >= pP->poutNumBufMap[z]->length ? 0 : (X)]
+
+Int
+asopStartOutput(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pC
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* output counter */
+    Int nbufs;
+    Int zE, zS, zX;
+    Int zMD;
+    PAF_SIO_IALG_Obj    *pObj;
+    PAF_SIO_IALG_Config *pAlgConfig;
+
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    zMD = pAstCfg->masterDec;
+
+    for (z=OUTPUT1; z < OUTPUTN; z++)
+    {
+        if (outIOtemp[z].hIoPhy)
+        {
+            // determine associated encoder and stream
+            zE = z;
+            zS = z;
+            for (zX = ENCODE1; zX < ENCODEN; zX++)
+            {
+                if (pP->outputsFromEncodes[zX] == z)
+                {
+                    zE = zX;
+                    zS = pP->streamsFromEncodes[zE];
+                    break;
+                }
+            }
+
+            // Set sample count so that DOB knows how much data to send
+            pAstCfg->xOut[z].outBufConfig.lengthofFrame =
+                pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
+
+            if (pAstCfg->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
+            {
+                pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
+                pAlgConfig = &pObj->config;
+                memset(pAstCfg->xOut[z].outBufConfig.base.pVoid, 0xAA,
+                    pAlgConfig->pMemRec[0].size);
+            }
+
+            // The index to DEC_OUTNUMBUF_MAP will always come from the primary/master
+            // decoder. How should we handle the sourceProgram for multiple decoders?
+            // Override as needed
+            nbufs = DEC_OUTNUMBUF_MAP(pAstCfg->xDec[zMD].decodeStatus.sourceProgram);
+            if (pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram] > 0)
+            {
+                nbufs = pAstCfg->xOut[z].outBufStatus.numBufOverride[pAstCfg->xDec[zMD].decodeStatus.sourceProgram];
+            }
+            //JXTODO: add similar thing to be figured out
+            //SIO_ctrl(pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_SET_NUMBUF, nbufs);
+
+            //JXTODO: data transfer start to be moved to output task state machine
+            /*if (errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
+                &pAstCfg->xOut[z].outBufConfig, sizeof(pAstCfg->xOut[z].outBufConfig), 0))
+            {
+                SIO_idle(pAstCfg->xOut[z].hTxSio);
+                TRACE_TERSE2("PAF_ASOT_startOutput: AS%d: SIO_issue failed (0x%x)", as+zS, errno);
+                return errno;
+            } */
+
+            //JXTODO: add similar thing to be figured out
+#if 0
+            if (!(pAstCfg->xOut[z].outBufStatus.audio & 0xf0) &&
+                (errno =  SIO_ctrl (pAstCfg->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0)))
+            {
+                errno = (errno & 0xff) | ASPERR_MUTE;
+                /* convert to sensical errno */
+                TRACE_TERSE2("as1-f2: PAF_ASOT_startOutput: AS%d: SIO control failed (unmute) 0x%x", as+zS, errno);
+                return (errno);
+            }
+            else
+            {
+                pAstCfg->xOut[z].outBufStatus.audio
+                    = (pAstCfg->xOut[z].outBufStatus.audio & 0xf0) | PAF_OB_AUDIO_SOUND;
+            }
+#endif
+            TRACE_VERBOSE1("PAF_ASOT_startOutput: AS%d: output started", as+zS);
+        }
+    }
+
+    return ASOP_DECODE_NO_ERR;
+} /* asopStartOutput */
+
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function - Encode Processing
+//
+//   Name:      PAF_ASOT_decodeEncode
+//   Purpose:   Decoding Function for processing of audio frame data by the
+//              Encode Algorithm.
+//   From:      AST Parameter Function -> decodeProcessing
+//   Uses:      See code.
+//   States:    x
+//   Return:    Error number in standard or SIO form (0 on success).
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//
+Int
+asopDecodeEncode(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pC,
+    Int frame,
+    Int block
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    Int z;                      /* encode/output counter */
+    Int errno;                  /* error number */
+    Int zX, zE, zS;
+    ioPhyCtl_t ioPhyCtl;
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+
+    // Await output buffers (but not first time)
+    for (z=OUTPUT1; z < OUTPUTN; z++)
+    {
+        // determine encoder associated with this output
+        zE = z;
+        for (zX = ENCODE1; zX < ENCODEN; zX++)
+        {
+            if (pP->outputsFromEncodes[zX] == z)
+            {
+                zE = zX;
+                break;
+            }
+        }
+        zS = pP->streamsFromEncodes[zE];
+
+        if (outIOtemp[z].hIoPhy)   // TODO: put hIoPhy into structure or replace with API call to check if I/O is ready
+        {
+            // update length (e.g. ARC may have changed)
+            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);
+
+            ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
+            ioPhyCtl.params.xferFrameSize = pAstCfg->xOut[z].outBufConfig.lengthofFrame
+                                               * ASOP_OUTBUF_STRIDE * ASOP_NUM_BYTES_PCM_SAMPLE;
+            ioPhyControl(outIOtemp[z].hIoPhy, &ioPhyCtl);
+
+#if 0
+            errno = SIO_reclaim(pAstCfg->xOut[z].hTxSio,(Ptr *) &pAstCfg->xOut[z].pOutBuf, NULL);
+            if (errno < 0)
+            {
+                SIO_idle(pAstCfg->xOut[z].hTxSio);
+                TRACE_TERSE2("PAF_ASOT_decodeEncode: AS%d: SIO_reclaim returns error %d", as+zS, -errno);
+                return -errno; // SIO negates error codes
+            }
+#endif
+            // TODO: use pC->xOut[z].pOutBuf in following ->encode call
+
+#if 0 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
+            // (***) debug // B8
+            {
+                static Uint8 toggleState = 0;
+                if (toggleState == 0)
+                    GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
+                else
+                    GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
+                toggleState = ~(toggleState);
+            }
+#endif
+
+            //
+            // Simulate Tx SIO_reclaim() pend
+            //
+            //Semaphore_pend(semaphoreTxAudio, BIOS_WAIT_FOREVER);
+            gTaskAsopCnt++;
+            //curTime = Clock_getTicks();
+            //System_printf("System time in TaskAsipFxn Tx audio = %lu\n", (ULong)curTime);
+            //Log_info1("outputEncode():Tx SIO reclaim(), system time = %u", curTime);
+        }
+        else
+        {
+            TRACE_VERBOSE2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- idle <ignored>", as+zS, block);
+        }
+    }
+
+    // Encode data
+    for (z=ENCODE1; z < ENCODEN; z++)
+    {
+        Int zO = pP->outputsFromEncodes[z];
+        Int zS = pP->streamsFromEncodes[z];
+        (void)zS; // clear compiler warning in case not used with tracing disabled
+        if (outIOtemp[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode)    // TODO: put hIoPhy into structure or replace with API call to check if I/O is ready
+        {
+            Int select = pAstCfg->xEnc[z].encodeStatus.select;
+            ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
+            ENC_Handle enc = (ENC_Handle )encAlg;
+            if (select != pAstCfg->xEnc[z].encodeControl.encActive)
+            {
+                pAstCfg->xEnc[z].encodeControl.encActive = select;
+                TRACE_TERSE0("PAF_ASOT_decodeEncode: return error");
+                return (-1);
+            }
+            TRACE_GEN2("AS%d: PAF_ASOT_decodeEncode: processing block %d -- encode", as+zS, block);
+
+            // (MID 1933) temp. workaround for PCE2
+            //pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = PAF_MAXNUMCHAN;
+            pAstCfg->xEnc[z].encodeInStruct.pAudioFrame->data.nChannels = 2;   //JXTODO: make this correct
+
+          /*
+          #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
+            {
+                PAF_AudioFrame *pAudioFrame = pC->xEnc[z].encodeInStruct.pAudioFrame;
+                int *wp;
+                wp = (int*)pAudioFrame->data.sample[0];
+                TRACE_DATA((&TR_MOD, "as1-f2: AS%d PAF_ASOT_outputEncode: encoding from ch 0 0x%x. line %d", z, wp, __LINE__));
+                TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch0)", wp[0], wp[16], wp[99]));
+                wp = (int*)pAudioFrame->data.sample[1];
+                TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 1 0x%x. line %d", wp, __LINE__));
+                TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch1)", wp[0], wp[16], wp[99]));
+                wp = (int*)pAudioFrame->data.sample[2];
+                TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoding from ch 2 0x%x. line %d", wp, __LINE__));
+                TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x (ch2)", wp[0], wp[16], wp[99]));
+            }
+          #endif
+          */
+
+            if (enc->fxns->encode)
+            {
+                pAstCfg->xEnc[z].encodeOutStruct.bypassFlag =
+                        pP->z_pEncodeStatus[z]->encBypass;
+                if (errno = enc->fxns->encode(enc, NULL,
+                    &pAstCfg->xEnc[z].encodeInStruct, &pAstCfg->xEnc[z].encodeOutStruct))
+                {
+                    if (errno != PCEERR_OUTPUT_POINTERNULL)    // errno = PCEERR_OUTPUT_RESULTRANGE
+                    {
+                        TRACE_TERSE1("PAF_ASOT_decodeEncode: return error %d line %d", errno);
+                        return errno;
+                    }
+                }
+            /*  #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
+                else
+                {
+                    int *wp = (int*)pC->xOut[z].pOutBuf->pntr.pVoid;
+                    TRACE_DATA((&TR_MOD, "as1-f2: PAF_ASOT_outputEncode: encoded to 0x%x. line %d", wp, __LINE__));
+                    TRACE_DATA((&TR_MOD, "as1-f2: [0]: 0x%x, [16]: 0x%x, [99]: 0x%x", wp[0], wp[16], wp[99]));
+                }
+              #endif
+              */
+            }
+        }
+        else
+        {
+            TRACE_VERBOSE2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- encode <ignored>",
+                as+pP->streamsFromEncodes[z], block);
+        }
+    }
+
+    // add debug code to dump output samples to memory
+
+    // Transmit data
+    for (z=OUTPUT1; z < OUTPUTN; z++)
+    {
+        // determine encoder associated with this output
+        zE = z;
+        for (zX = ENCODE1; zX < ENCODEN; zX++)
+        {
+            if (pP->outputsFromEncodes[zX] == z)
+            {
+                zE = zX;
+                break;
+            }
+        }
+        zS = pP->streamsFromEncodes[zE];
+
+#if 0
+        if (pAstCfg->xOut[z].hTxSio)
+        {
+            TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output", as+zS, block);
+            errno = SIO_issue(pAstCfg->xOut[z].hTxSio,
+                &pAstCfg->xOut[z].outBufConfig, sizeof (pAstCfg->xOut[z].outBufConfig), 0);
+            if (errno)
+            {
+                SIO_idle(pAstCfg->xOut[z].hTxSio);
+                if (errno == 0x105)     // 0x105 == RINGIO_EBUFFULL
+                {
+//                    statStruct_LogFullRing(STATSTRUCT_AS1_F2);
+                    TRACE_TERSE1("PAF_ASOT_decodeEncode: SIO_idle returned RINGIO_EBUFFULL (0x%x)", errno);
+                }
+                if (errno > 0)
+                {
+                    TRACE_TERSE1("PAF_ASOT_decodeEncode: return error 0x%x line %d", errno);
+                    return (ASPERR_ISSUE + (z << 4));
+                }
+                else if (errno < 0)
+                {
+                    TRACE_TERSE1("PAF_ASOT_decodeEncode: return neg error 0x%x line %d", -errno);
+                    return -errno; // SIO negates error codes
+                }
+            }
+            if (errno > 0)
+            {
+                return (ASPERR_ISSUE + (z << 4));
+            }
+            else if (errno < 0)
+            {
+                return -errno; // SIO negates error codes
+            }
+        }
+        else
+        {
+            TRACE_GEN2("PAF_ASOT_decodeEncode: AS%d: processing block %d -- output <ignored>", as+zS, block);
+        }
+#endif
+    }
+
+    return ASOP_DECODE_NO_ERR;
+} /* asopDecodeEncode */
+
+
+// -----------------------------------------------------------------------------
+// ASOT Decoding Function - Stream-Final Processing
+//
+//   Name:      PAF_ASOT_decodeComplete
+//   Purpose:   Decoding Function for terminating the decoding process.
+//   From:      AST Parameter Function -> decodeProcessing
+//   Uses:      See code.
+//   States:    x
+//   Return:    0.
+//   Trace:     Message Log "trace" in Debug Project Configuration reports:
+//              * State information as per parent.
+//
+Int
+asopDecodeComplete(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pC,
+    ALG_Handle decAlg[],
+    Int frame,
+    Int block
+)
+{
+    PAF_AST_Config *pAstCfg;
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    Int z;                              /* decode/encode counter */
+    Int errno;                          /* error number */
+
+
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    as = pAstCfg->as;
+    (void)as;  // clear compiler warning in case not used with tracing disabled
+
+    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        // Stop decoder output circular buffer reads
+        errno = cbReadStop(pCbCtl, z);
+        if (errno)
+        {
+            TRACE_TERSE1("PAF_ASOT_decodeComplete:cbReadStop() error=%d", errno);
+            SW_BREAKPOINT; // FL: debug
+            return errno;
+        }
+        // FL: debug
+        cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeComplete:cbReadStop");
+    }
+
+    pP->fxns->streamChainFunction(pP, pQ, pC, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
+
+    for (z=ENCODE1; z < ENCODEN; z++)
+    {
+        Int zO = pP->outputsFromEncodes[z];
+        if (outIOtemp[zO].hIoPhy && pAstCfg->xEnc[z].encodeStatus.mode)
+        {
+            Int select = pAstCfg->xEnc[z].encodeStatus.select;
+            ALG_Handle encAlg = pAstCfg->xEnc[z].encAlg[select];
+#ifdef PAF_ASP_FINAL
+            ENC_Handle enc = (ENC_Handle)encAlg;
+#endif /* PAF_ASP_FINAL */
+            TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode", as+z);
+#ifdef PAF_ASP_FINAL
+            if (enc->fxns->final)
+                enc->fxns->final(enc, NULL, &pAstCfg->xEnc[z].encodeControl,
+                                 &pAstCfg->xEnc[z].encodeStatus);
+#endif /* PAF_ASP_FINAL */
+            if (encAlg->fxns->algDeactivate)
+            {
+                encAlg->fxns->algDeactivate(encAlg);
+            }
+        }
+        else
+        {
+            TRACE_VERBOSE1("PAF_ASOT_decodeComplete: AS%d: finalizing encode <ignored>", as+z);
+        }
+    }
+
+    // wait for remaining data to be output
+    //pP->fxns->stopOutput(pP, pQ, pC);    //JXTODO: implement similar function using new I/O components
+
+    return 0;
+} //asopDecodeComplete
+
+Int
+asotDecodeStream(
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ,
+    PAF_ASOT_Config *pAsotCfg,
+    Int frame,
+    Int block
+)
+{
+    PAF_AST_Config *pAstCfg;
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    Int z;                              /* decode/stream counter */
+    PAF_AudioFrame *pAfRd;
+    Int cbErrno;
+    Int errno;
+
+
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+
+    pCbCtl = &pAsotCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+
+    for (z=DECODE1; z < DECODEN; z++)
+    {
+        Int zS = pP->streamsFromDecodes[z];
+
+        //
+        // Read decoder output circular buffer
+        //
+        pAfRd = pAstCfg->xStr[zS].pAudioFrame;
+        GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
+        cbErrno = cbReadAf(pCbCtl, z, pAfRd);
+        if ((cbErrno < 0) && (cbErrno != ASP_DECOP_CB_READ_UNDERFLOW))
+        {
+            gCbReadAfErr++;
+            TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
+            //SW_BREAKPOINT; // FL: debug
+            return cbErrno;
+        }
+
+        // Handle underflows
+        if (cbErrno == ASP_DECOP_CB_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().
+            // 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)
+            {
+                // Underflow count above threshold.
+                // (1) set max underflow count to threshold
+                // (2) reset underflow count
+                // (3) reset circular buffer
+
+                gMaxDecOpCbRdAfUnd = DEC_OP_CB_RDAF_UND_THR; // update max underflow count
+                gDecOpCbRdAfUnd = 0; // reset underflow count
+
+                // Reset circular buffer
+                cbReset(pCbCtl, z);
+                Log_info0("PAF_ASOT_decodeStream:cbReset");
+
+                return cbErrno;
+            }
+        }
+        else if ((cbErrno == ASP_DECOP_CB_SOK) && (gDecOpCbRdAfUnd > 0))
+        {
+            // No underflow detected.
+            // update max underflow count,
+            // reset underflow count
+
+            // update max underflow count
+            if (gDecOpCbRdAfUnd > gMaxDecOpCbRdAfUnd)
+            {
+                gMaxDecOpCbRdAfUnd = gDecOpCbRdAfUnd;
+            }
+            gDecOpCbRdAfUnd = 0; // reset circular buffer underflow count
+        }
+        //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
+        GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
+        Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
+
+#if 0 // (***) FL: shows timing of CB read
+            // (***) debug // B8
+            {
+                static Uint8 toggleState = 0;
+                if (toggleState == 0)
+                    GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
+                else
+                    GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
+                toggleState = ~(toggleState);
+            }
+#endif
+
+        // FL: debug
+        cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
+        //if (capAfWrite(pAfRd, 0) != CAP_AF_SOK)
+        //{
+        //    Log_info0("capAfWrite() error");
+        //}
+    }
+/*
+    TRACE_VERBOSE0("PAF_ASOT_outputStream: calling streamChainFunction.");
+    errno = pP->fxns->streamChainFunction(pP, pQ, pAsotCfg,
+        PAF_ASP_CHAINFRAMEFXNS_APPLY, 1, block);
+    if (errno)
+    {
+        TRACE_TERSE1("PAF_ASOT_outputStream: streamChainFunction returns errno 0x%x ", errno);
+        return errno;
+    }
+*/
+    return 0;
+
+} //asotDecodeStream
+/* nothing past this point */
+#endif
index 3812270780926c9b68fc4587f3ea142e4d7f8e85..d5538a6465cea7841121891978c76fd0f257396b 100644 (file)
@@ -429,7 +429,11 @@ Void taskAsopFxnInit(
 #ifdef PASDK_SIO_DEV
 Void taskAsopFxn(
 #else
+#ifndef IO_LOOPBACK_TEST
+Void taskAsopFxn(   // still use this for new I/O before it is refactored.
+#else
 Void taskAsopFxn_Not_Used(
+#endif
 #endif
     const PAF_ASOT_Params *pP,
     const PAF_ASOT_Patchs *pQ
diff --git a/pasdk/test_dsp/framework/audioStreamOutProcNewIO.c b/pasdk/test_dsp/framework/audioStreamOutProcNewIO.c
new file mode 100644 (file)
index 0000000..205d64b
--- /dev/null
@@ -0,0 +1,84 @@
+
+/*
+Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without 
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+/*
+ *  ======== audioStreamOutProc.c ========
+ */
+
+#include "audioStreamOutProc.h"
+#include "ioConfig.h"    //TODO: remove this header
+#include "ioBuff.h"
+#include "ioPhy.h"
+#include "ioData.h"
+
+extern Semaphore_Handle asopSemTx;
+
+extern Void taskAsopFxnInit(const PAF_ASOT_Params *pP, const PAF_ASOT_Patchs *pQ);
+
+/*
+ *  ======== taskAsopFxn ========
+ *  Audio Stream Output Processing task function
+ */
+#ifndef PASDK_SIO_DEV
+#ifndef IO_LOOPBACK_TEST
+Void taskAsopFxn_Not_Used(                 // ASOP task function for new I/O
+#else
+Void taskAsopFxn_NewIO_Not_Used(  // not used for loopback test
+#endif
+#else
+Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
+#endif
+    const PAF_ASOT_Params *pP,
+    const PAF_ASOT_Patchs *pQ
+)
+{
+//    Log_info0("Enter taskAsopFxn()");
+
+    taskAsopFxnInit(pP, pQ);    // initialization of output task
+
+} /* taskAsopFxn */
+
+
+void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
+{
+    /* post semaphore */
+    if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
+        Semaphore_post(asopSemTx);
+    } else {
+        ;    // intermediate packet due to buffer wrapping around
+    }
+}
+
+/* Nothing past this line */
index 309f3f43d686ddb5fb88900424c386d38efcacac..3bed11a6a14117c1e4f17d9570fdfe4fe06f04e5 100644 (file)
@@ -631,7 +631,7 @@ const IALG_MemRec inpMemTabPrimary[] =
     // SDRAM circular buffer
     // 2 buffers * 256 samples/buffer * 8 words/sample * 3 bytes/word
     {
-        (3 * 60 * 1024) + 2,                                    // size 184320 + 1 16-bit word for EDMA padding
+        (4 * 60 * 1024) + 2,                                    // size 184320 + 1 16-bit word for EDMA padding
         //180 * 1024,                                           // size
         //6 * 60 * 1024,                                        // size
         128,                                                    // alignment
index 04e4bbfb3892e25bec140b339d918bb5b1320a5e..b2c03518dae2c30b8a7f54f45332c095ac4320b2 100644 (file)
@@ -99,6 +99,10 @@ Int gTaskInitFlag[NUM_SYS_TASKS];
 // PAF Hidden Jump Table (HJT) pointer
 const PAFHJT_t *pafhjt;
 
+/* Semaphore handles for Tx and Rx - to put in structures */
+Semaphore_Handle asipSemRx;
+Semaphore_Handle asopSemTx;
+void sysCreateSemaphores(void);
 
 /*
  *  ======== taskSysInitFxn ========
@@ -244,6 +248,8 @@ Void taskSysInitFxn(Void)
     Task_setPri(TaskAsip, TASK_ASIP_PRI);
     Task_setPri(TaskAsop, TASK_ASOP_PRI);
 
+    sysCreateSemaphores();
+
 #ifdef MEMSTAT_REPORT
     // Output current heap memory usage
     PAF_ALG_memStatusPrint("System Initialization, Final MEMSTAT REPORT",
@@ -253,3 +259,13 @@ Void taskSysInitFxn(Void)
     
     Log_info0("Exit taskSysInitFxn()");
 }
+
+void sysCreateSemaphores(void)
+{
+    Semaphore_Params SemParams;
+
+    Semaphore_Params_init(&SemParams);
+
+    asipSemRx = Semaphore_create(0, &SemParams, NULL);
+    asopSemTx = Semaphore_create(0, &SemParams, NULL);
+}
index d50cf0d15766de1e59e51ed52729a409e6c54b69..960c4b6a1816b8ec6db76b18102592baa691d1df 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef IO_CONFIG_H
 #define IO_CONFIG_H
 
-#define PASDK_SIO_DEV         // define this to use the legacy SIO/DEV based I/O driver
+//#define PASDK_SIO_DEV         // define this to use the legacy SIO/DEV based I/O driver
 
 //#define IO_LOOPBACK_TEST        // define this to run a loopback test bypassing PASDK processing
 
 
 //#define INPUT_PCM_ONLY        // debugging, input fixed to PCM
 
+#ifdef INPUT_PCM_ONLY
+#define SWAP_INPUT_DATA        FALSE
+#else
+#define SWAP_INPUT_DATA        TRUE
+#endif
+
 #ifdef INPUT_HDMI_4xI2S
 #define RX_MCASP_USE_MULT_SER
 #define TX_MCASP_USE_MULT_SER   // This is the normal operation. Undefine this for debugging and loopback
+#define IO_HW_INTERFACE          2
 //#define ASIP_ELEMENT_SIZE      2
 //#define ASIP_STRIDE            8    // 4 lane, stereo
 #endif
 #ifdef INPUT_HDMI_STEREO
 //#define ASIP_ELEMENT_SIZE      4
 //#define ASIP_STRIDE            2    // 1 lane, stereo
+#define IO_HW_INTERFACE          1
 #endif
 
 #ifdef INPUT_SPDIF
 //#define ASIP_ELEMENT_SIZE      4
 //#define ASIP_STRIDE            2    // 1 lane, stereo
+#define IO_HW_INTERFACE          3
 #endif
 
 // two options regarding I/O PHY transfer size and I/O DATA read size:
index 01805dcf665b614a3770703aa0742fcb2b290b31..f43c35fd51fb5c164bcbe7f745e453820bea3942 100644 (file)
@@ -8,6 +8,8 @@
 #include "mcasp_cfg.h"
 #include "ioConfig.h"
 
+#ifdef IO_LOOPBACK_TEST
+
 //#define TEST_OVERFLOW_UNDERFLOW
 //#define TEST_OVERFLOW_OVERFLOW
 #define NUM_BUFS_USED  8
@@ -74,13 +76,15 @@ int check_mcasp_rx_overrun(void);
 void mcasp_rx_restart(void);
 int check_mcasp_tx_underrun(void);
 void mcasp_tx_restart(void);
-void ioRecfgRxPhyForPcm(void);
-void ioRecfgRxPhyForBitStream();
+
+void mcaspRecfgFor16BitPacked(Ptr hMcaspChan, Mcasp_ChanParams *chanParams);
+void mcaspRecfgFor32Bit(Ptr hMcaspChan, Mcasp_ChanParams *chanParams);
 
 extern void ioCompsInitInput();
 extern void ioCompsInitOutput();
 
 
+
 #ifndef USE_IO_COMPONENTS
 /**
  *  \brief   McASP callback function called up on the data transfer completion
@@ -148,8 +152,6 @@ void mcaspAppCallbackTx(void* arg, MCASP_Packet *mcasp_packet)
 #endif
 
 
-#ifdef IO_LOOPBACK_TEST
-
 #ifndef USE_IO_COMPONENTS
 
 /**
@@ -374,6 +376,19 @@ Void taskAsopFxn_1tsk(
 
 #else    // else of #ifndef USE_IO_COMPONENTS
 
+enum
+{
+    ASIP_SOURCE_DETECTION,
+    ASIP_DECODE_BITSTREAM,
+    ASIP_SWITCH_TO_PCM,
+    ASIP_DECODE_PCM
+};
+
+int numFrameReceived, numPcmFrameReceived, numSyncLost, numUnderflow;
+extern const MdUns iecFrameLength[23];
+
+#define SYNC_PC_MASK    0x001F
+
 void audio_rx_proc()
 {
     void *buff1, *buff2;
@@ -449,7 +464,7 @@ void audio_tx_proc()
     }
 }  /* audio_tx_proc */
 
-void rxDecodeProcess()
+Int rxDecodePcm(PAF_AST_IoInp  *pInp)
 {
     ioDataCtl_t ioDataCtl;
     void *buffBase;
@@ -468,60 +483,51 @@ void rxDecodeProcess()
     /* Depending on source information, either decode bit stream or simply
      * copy PCM data to output buffer.
      */
-    if(fwInst.syncState == IODATA_SYNC_PCM) {
-        // Copy PCM data to output buffer
-        if(((size_t)dataStartAddress+frameSize) <= ((size_t)buffBase+buffSize)) {
-            // Input buffer doesn't wrap around
-            Cache_inv(dataStartAddress, frameSize, Cache_Type_ALL, TRUE);
-            memcpy(databuf[0], dataStartAddress, frameSize);
-        }
-        else {
-            // Input buffer wraps around
-            size1 = (size_t)buffBase + buffSize - (size_t)dataStartAddress;
-            size2 = frameSize - size1;
-            Cache_inv(dataStartAddress, size1, Cache_Type_ALL, TRUE);
-            memcpy(databuf[0], dataStartAddress, size1);
-
-            Cache_inv(buffBase, size2, Cache_Type_ALL, TRUE);
-            memcpy((void *)((size_t)databuf[0]+size1), buffBase, size2);
-        }
+    // Copy PCM data to output buffer
+    if(((size_t)dataStartAddress+frameSize) <= ((size_t)buffBase+buffSize)) {
+        // Input buffer doesn't wrap around
+        Cache_inv(dataStartAddress, frameSize, Cache_Type_ALL, TRUE);
+        memcpy(databuf[0], dataStartAddress, frameSize);
     }
-    else if(fwInst.syncState == IODATA_SYNC_BITSTREAM) {
-        // Do nothing - there is no decoder
+    else {
+        // Input buffer wraps around
+        size1 = (size_t)buffBase + buffSize - (size_t)dataStartAddress;
+        size2 = frameSize - size1;
+        Cache_inv(dataStartAddress, size1, Cache_Type_ALL, TRUE);
+        memcpy(databuf[0], dataStartAddress, size1);
+
+        Cache_inv(buffBase, size2, Cache_Type_ALL, TRUE);
+        memcpy((void *)((size_t)databuf[0]+size1), buffBase, size2);
     }
-} /* rxDecodeProcess */
 
-int numFrameReceived, numPcmFrameReceived, numSyncLost, numUnderflow;
-extern const MdUns iecFrameLength[23];
+    return ASIP_NO_ERR;
 
-#define SYNC_PC_MASK    0x001F
+} /* rxDecodeProcessing */
+
+Int rxDecodeBitStream(PAF_AST_IoInp  *pInp)
+{
+    return ASIP_NO_ERR;
+}
+
+Int rxDecodePlayZero(PAF_AST_IoInp  *pInp)
+{
+    memset(databuf[0], 0, OUTPUT_FRAME_SIZE);
+}
+
+extern void asipProcInit(PAF_AST_IoInp  *pInp);
+extern Int asipProcessing(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp);
 
 Void taskAsipFxn(
     const PAF_ASIT_Params *pP,  //JX: asip_params_PAi defined in itopo/params.c
     const PAF_ASIT_Patchs *pQ   //JX: asop_patchs_PAi defined in itopo/patchs.c
 )
 {
-       int autoDetstatus;
-    ioDataCtl_t ioDataCtl;
-    ioPhyCtl_t  ioPhyCtl;
+    Int asipStatus;
 
     /* Initialize I/O components for input */
     ioCompsInitInput();
 
-#ifdef INPUT_HDMI_4xI2S             // HDMI 4xI2S, bit stream or PCM
-#ifdef INPUT_PCM_ONLY
-    fwInst.ioInp.swapData = FALSE;  // initialized to receive PCM
-#else
-    fwInst.ioInp.swapData = TRUE;   // initialized to receive bit stream
-#endif
-#else
-    fwInst.ioInp.swapData = FALSE;  // initialized to receive PCM
-#endif
-
-    fwInst.syncState     = IODATA_SYNC_NONE;
-    fwInst.syncStatePrev = IODATA_SYNC_NONE;
-    fwInst.switchHangOver = 0;
-    fwInst.ioDelayAdjust  = FALSE;
+    asipProcInit(&fwInst.ioInp);
 
        /* Start McASP LLD  for input transfer */
        inputXferStart();
@@ -545,175 +551,33 @@ Void taskAsipFxn(
         ioPhyXferComplete(fwInst.ioInp.hIoPhy, fwInst.ioInp.swapData);
 
 #ifndef INPUT_PCM_ONLY
-        if(fwInst.switchHangOver)
-        {
-            void *buff1, *buff2;
-            size_t size1, size2;
-
-            // Get read pointers (or sub-buffers) of the input buffer
-            if (ioBuffGetReadPtrs(fwInst.ioInp.hIoBuff, fwInst.phyXferSize,
-                                  &buff1, &size1, &buff2, &size2)
-                == IOBUFF_ERR_UNDERFLOW) {
-                printf("Input buffer underflows during switch hangover!\n");
-                exit(0);
-            }
+//        rxAutoProcessing();
 
-            ioBuffReadComplete(fwInst.ioInp.hIoBuff, buff1, size1);
+//        rxDecodeProcessing();
 
-            if(buff2 != NULL) {
-                ioBuffReadComplete(fwInst.ioInp.hIoBuff, buff2, size2);
-            }
+        // Mark the input as read complete
+//        if(fwInst.ioInp.autoProcState != ASIP_SWITCH_TO_PCM) {
+//            ioDataReadComplete(fwInst.ioInp.hIoData);
+//        }
 
-            memset(databuf[0], 0, OUTPUT_FRAME_SIZE);
-            fwInst.switchHangOver--;
-        }
-        else {
-            // Input format is unknown, perform auto-detection
-            autoDetstatus = ioDataProcess(fwInst.ioInp.hIoData);
-            if(autoDetstatus == IODATA_ERR_IOBUF_UNDERFLOW) {
-                // Input buffer underflows - no action is needed
-                //printf("Input buffer underflows.\n");
-                numUnderflow += 1;
-            }
-            else if(autoDetstatus != IODATA_NO_ERR) {
-                // print error log and return
-                printf("IODATA processing error!\n");
-                exit(0);
-            }
-            else {
-                // Check auto-detection status
-                ioDataCtl.code = IODATA_CTL_GET_AUTODET_STATUS;
-                ioDataControl(fwInst.ioInp.hIoData, &ioDataCtl);
-
-                fwInst.syncState = ioDataCtl.param.autoDetStats.syncState;
-
-                if(fwInst.syncState == IODATA_SYNC_BITSTREAM) {
-                    if(fwInst.syncStatePrev != IODATA_SYNC_BITSTREAM) {
-                        // Change I/O PHY transfer size
-                        int frameSize;
-                        uint_least16_t pc = ioDataCtl.param.autoDetStats.bitStreamInfo & SYNC_PC_MASK; //0x001F
-                        frameSize = iecFrameLength[pc] * WORD_SIZE_BITSTREAM;
-
-                        ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
-                        ioPhyCtl.params.xferFrameSize = frameSize;
-                        ioPhyControl(fwInst.ioInp.hIoPhy, &ioPhyCtl);
-                        fwInst.phyXferSize = ioPhyCtl.params.xferFrameSize;
-                    }
-
-                    numFrameReceived += 1;
-                }
-                else if(fwInst.syncState == IODATA_SYNC_PCM) {
-                    // reconfigure McASP LLD if necessary
-                    if(fwInst.syncStatePrev != IODATA_SYNC_PCM) {
-                        ioRecfgRxPhyForPcm();
-
-                        // Change I/O PHY transfer size
-                        ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
-                        ioPhyCtl.params.xferFrameSize = INPUT_FRAME_SIZE_PCM;
-                        ioPhyControl(fwInst.ioInp.hIoPhy, &ioPhyCtl);
-
-                        // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
-                        // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
-                        //ioBuffAdjustDelay(fwInst.ioInp.hIoBuff, INPUT_FRAME_SIZE*2);
-                        fwInst.ioInp.swapData = FALSE;
-                        fwInst.phyXferSize = ioPhyCtl.params.xferFrameSize;
-
-                        fwInst.switchHangOver = INPUT_SWITCH_HANGOVER;
-                        fwInst.ioDelayAdjust  = TRUE;
-                    }
-
-                    numPcmFrameReceived += 1;
-                }
-                else if (fwInst.syncState == IODATA_SYNC_NONE) {
-
-                    if(fwInst.syncStatePrev != IODATA_SYNC_NONE) {
-                        numSyncLost += 1;
-                        numUnderflow = 0;
-                    }
-
-                    if(fwInst.syncStatePrev == IODATA_SYNC_PCM) {
-                        // reconfigure McASP LLD to 16-bit packed bits
-                        ioRecfgRxPhyForBitStream();
-
-                        // Change I/O PHY transfer size
-                        ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
-                        ioPhyCtl.params.xferFrameSize = INPUT_FRAME_SIZE_DEF;
-                        ioPhyControl(fwInst.ioInp.hIoPhy, &ioPhyCtl);
-
-                        // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
-                        // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
-                        //ioBuffAdjustDelay(fwInst.ioInp.hIoBuff, INPUT_FRAME_SIZE*2);
-
-                        fwInst.ioInp.swapData = TRUE;
-                        fwInst.phyXferSize  = ioPhyCtl.params.xferFrameSize;
-                        numPcmFrameReceived = 0;
-
-                        fwInst.switchHangOver = INPUT_SWITCH_HANGOVER;  // don't need hangover, since data is all 0's anyway
-                        fwInst.ioDelayAdjust  = TRUE;                   // no need to adjust delay since read size doesn't change during PCM
-                    }
-                    else if(fwInst.syncStatePrev == IODATA_SYNC_BITSTREAM) {
-                        numFrameReceived = 0;
-
-                        // Change I/O PHY transfer size
-                        ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
-                        ioPhyCtl.params.xferFrameSize = INPUT_FRAME_SIZE_DEF;
-                        ioPhyControl(fwInst.ioInp.hIoPhy, &ioPhyCtl);
-                    }
-                    else {
-                        // SYNC has not been detected
-                        ;
-                    }
-                }
-
-                fwInst.syncStatePrev = ioDataCtl.param.autoDetStats.syncState;
-
-                // Receive processing: decoding bitstream or simply passing PCM to output
-                // To add proper processing for HDMI 4xlane interface: bitstream or PCM
-                /*if ((fwInst.syncState != IODATA_SYNC_NONE) && (fwInst.switchHangOver == 0)) {
-                    rxDecodeProcess();
-                }
-                else {
-                    if(fwInst.switchHangOver > 0) {
-                        fwInst.switchHangOver--;
-                    }
-                    memset(databuf[0], 0, OUTPUT_FRAME_SIZE);
-                }*/
-
-                if(fwInst.syncState == IODATA_SYNC_NONE) {
-                    memset(databuf[0], 0, OUTPUT_FRAME_SIZE);
-                }
-                else {
-                    if(fwInst.switchHangOver) {
-                        memset(databuf[0], 0, OUTPUT_FRAME_SIZE);
-                        fwInst.switchHangOver--;
-                    }
-                    else {
-                        rxDecodeProcess();
-                    }
-                }
-
-                // Mark the input as read complete
-                if(fwInst.ioDelayAdjust) {
-                    // don't mark input buffer as read complete
-                    ioBuffAdjustDelay(fwInst.ioInp.hIoBuff, fwInst.phyXferSize);
-                    fwInst.ioDelayAdjust = FALSE;
-                }
-                else {
-                    ioDataReadComplete(fwInst.ioInp.hIoData);
-                }
-            }
+        asipStatus = asipProcessing(&fwInst.astCfg, &fwInst.ioInp);
+
+        if(asipStatus != ASIP_NO_ERR) {
+            printf("ASIP processing error! Error code is %d\n", asipStatus);
+            exit(0);
         }
+
 #else
         // Input is configured to PCM data
         audio_rx_proc();
 
         rxCount++;
         if(rxCount == 2000) {
-            ioRecfgRxPhyForPcm();
+            mcaspRecfgFor32Bit();
         }
 
         if(rxCount == 4000) {
-            ioRecfgRxPhyForBitStream();
+            mcaspRecfgFor16BitPacked();
             rxCount = 0;
         }
 
@@ -753,6 +617,7 @@ Void taskAsipFxn(
 
 } /* taskAsipFxn */
 
+
 Void taskAsopFxn(const PAF_ASOT_Params *pP, const PAF_ASOT_Patchs *pQ)
 {
     /* Initialize I/O components for output */
@@ -820,7 +685,6 @@ Void taskAsopFxn(const PAF_ASOT_Params *pP, const PAF_ASOT_Patchs *pQ)
 
 #endif  // end of #ifndef USE_IO_COMPONENTS
 
-#endif  // end of #ifdef IO_LOOPBACK_TEST
 
 
 extern const uint_least16_t IECframeLength[23];
@@ -948,43 +812,5 @@ void ioSemaphoreCreate(void)
     semT = Semaphore_create(0, &SemParams, NULL);
 }
 
-void ioRecfgRxPhyForBitStream()
-{
-    Int status = Audk2g_EOK;
-
-    if(mcaspRxChanParam.wordWidth != Mcasp_WordLength_16) {
-        //mcaspRxReset();
-
-        mcaspRxChanParam.wordWidth = Mcasp_WordLength_16;
-        status = mcaspControlChan(hMcaspRxChan, Mcasp_IOCTL_CHAN_PARAMS_WORD_WIDTH, &mcaspRxChanParam);
-
-        //status = mcaspRxCreate();
-
-        if(status != Audk2g_EOK) {
-            printf("McASP LLD reconfiguration for bitstream fails!\n");
-            exit(0);
-        }
-
-        //ioPhyXferErrRecover(fwInst.ioInp.hIoPhy);
-    }
-} /* ioRecfgRxPhyForBitStream */
-
-void ioRecfgRxPhyForPcm(void)
-{
-    Int status = Audk2g_EOK;
-
-    if(mcaspRxChanParam.wordWidth != Mcasp_WordLength_32) {
-        //mcaspRxReset();
-
-        mcaspRxChanParam.wordWidth = Mcasp_WordLength_32;
-
-        status = mcaspControlChan(hMcaspRxChan, Mcasp_IOCTL_CHAN_PARAMS_WORD_WIDTH, &mcaspRxChanParam);
-        //status = mcaspRxCreate();
-        if(status != Audk2g_EOK) {
-            printf("McASP LLD reconfiguration for PCM fails!\n");
-            exit(0);
-        }
+#endif  // end of #ifdef IO_LOOPBACK_TEST
 
-        //ioPhyXferErrRecover(fwInst.ioInp.hIoPhy);
-    }
-} /* ioRecfgRxPhyForPcm */
index 9216d330b437515a7620910e76173d54b532cad2..fbff6c7c78f9fc9fcc891bc64b558e61a9a41d70 100644 (file)
@@ -9,6 +9,7 @@
 #include "mcasp_cfg.h"
 #include "ioConfig.h"
 
+#ifdef IO_LOOPBACK_TEST
 
 fwInst_t fwInst;
 
@@ -204,4 +205,5 @@ void ioCompsInitOutput()
 } /* ioCompsInitOutput */
 
 
+#endif //#ifdef IO_LOOPBACK_TEST
 
index 71b3174df6d7f15e409b5a189b179929ecaf17fe..9c27f59492b9724f672abb08706b05f7ce5c9d7c 100644 (file)
@@ -38,44 +38,22 @@ enum {
   FW_IOBUF_OVERFLOW
 };
 
-#if 0
-typedef struct fw_inst_s {
-  void *       mcasp_chan_handle_input;
-  void *       mcasp_chan_handle_output;
-  ioPhyHandle_t  iophy_handle_input;
-  ioPhyHandle_t  iophy_handle_output;
-  ioBuffHandle_t iobuf_handle_input;
-  ioBuffHandle_t iobuf_handle_output;
-  ioDataHandle_t iodata_handle;
-  void *       iomem_pool_input_base;
-  size_t       iomem_pool_input_size;
-  void *       iomem_pool_output_base;
-  size_t       iomem_pool_output_size;
-
-  uint_fast16_t  buf_status_in;
-  uint_fast16_t  buf_status_out;
-} fw_inst_t;
-
-extern void io_create(void *mcasp_chan_handle_rx, void *mcasp_chan_handle_tx);
-#endif
 
 typedef struct fwInst_s {
+    PAF_AST_Config astCfg;
     PAF_AST_IoInp  ioInp;
     PAF_AST_IoOut  ioOut;
     void *       iomem_pool_input_base;
     size_t       iomem_pool_input_size;
     void *       iomem_pool_output_base;
     size_t       iomem_pool_output_size;
-    size_t       phyXferSize;
 
     void *       hMcaspRxChan;
-
-    int_fast32_t   switchHangOver;
     uint_fast16_t  buf_status_in;
     uint_fast16_t  buf_status_out;
-    uint_least16_t syncState;
-    uint_least16_t syncStatePrev;
-    uint_fast16_t  ioDelayAdjust;
+
+    //uint_least16_t syncState;
+    //uint_least16_t syncStatePrev;
 
 }fwInst_t;