]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/test_dsp/framework/audioStreamInpProcNewIO.c
Merge remote-tracking branch 'origin/dev_pasdk_frank_pasdk577RunTimeAudioIoCfg' into...
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProcNewIO.c
index 65278a73dbc908b13ca3812f22da83c7ebea5c7b..7aec882afcf7ddb68b12db930d0c509e88dc515c 100644 (file)
@@ -49,14 +49,15 @@ All rights reserved.
 #include "asperr.h"
 #include "common.h"
 
-#include "audk2g.h"
-#include "audk2g_audio.h"
+#include "aud.h"
+#include "aud_audio.h"
 #include "mcasp_cfg.h"
 #include "ioConfig.h"    //TODO: remove this header
 #include "ioBuff.h"
 #include "ioPhy.h"
 #include "ioData.h"
 
+#include <pa_i13_evmk2g_io_a.h>
 
 #define STRIDE_WORST_CASE 32  // 4-byte (32-bit) word, 2 slots, 4 serializers
 
@@ -109,9 +110,11 @@ 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_init(void * pD10Params);
+extern XDAS_Int32 D10_initClkMux(void *pD10Params);
 extern XDAS_Int32 D10_RxControl(const void *pD10RxParams,
                                 XDAS_Int32 code, XDAS_Int32 arg);
+extern Aud_STATUS D10_initHDMI(void);
 
 /*
  * Functions only used in this file
@@ -123,7 +126,14 @@ void asitIoPhyPrime(PAF_AST_IoInp *pInpIo);
 void asitPhyTransferComplete(PAF_AST_IoInp * pInpIo);
 void asitPhyTransferStart(PAF_AST_IoInp *pInpIo);
 Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize);
-Int asitSelectDevices(const PAF_ASIT_Patchs *pQ, PAF_AST_IoInp *pInp);
+
+// Select Input devices
+Int asitSelectDevices(
+    const PAF_ASIT_Patchs *pQ, 
+    PAF_AST_Config *pAstCfg, 
+    PAF_AST_IoInp *pInp
+);
+
 Int asitUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
                           PAF_InpBufConfig *pInpBuf);
 
@@ -155,13 +165,6 @@ extern PAF_ASIT_Config gPAF_ASIT_config;
 extern const MdUns iecFrameLength[23];
 extern Ptr hMcaspRxChan;
 
-enum {
-    ASIT_RESET,
-    ASIT_SOURCE_DETECTION,
-    ASIT_PCM_TRANSITION,
-    ASIT_DECODE_PROCESSING
-};
-
 // temp for simulation
 //#define ASIT_ALL_EVENTS (  ASIT_EVTMSK_INPDATA \
 //                         + ASIT_EVTMSK_INFOACK \
@@ -257,9 +260,6 @@ Int inputReadyForProcessing;
     asipLoopCount1 = 0;
     asipLoopCount2 = 0;
     asitErr = ASIT_NO_ERR;
-    pInp->asipState = ASIT_RESET;
-    pInp->firstTimeInit = TRUE;
-    pInp->numAsitRestart = 0;
 
     // The events_on flag will be removed if the RESTART state is changed to
     // event-based scheduling instead of polling
@@ -307,6 +307,11 @@ Int inputReadyForProcessing;
                 // Input data is ready - perform source detection.
                 // New state will be decided inside the function
                 asitErr = asitSourceDetection(pP, pQ, pAsitCfg);
+
+                if(asitErr == ASIT_AUTODET_TIME_OUT) {
+                    // Should restart if new interface is selected.
+                    TRACE_VERBOSE0("TaskAsip: auto-detection time out.");
+                }
             }
             else {
                 //Error checking & debug
@@ -331,6 +336,23 @@ Int inputReadyForProcessing;
 
         case ASIT_DECODE_PROCESSING:
             if(events & ASIT_DEC_EVENTS) {
+                
+#if 1 // debug 
+                if (events & ASIT_EVTMSK_INPDATA)
+                {
+                    // shows timing of Input (Rx McASP EDMA)
+                    // ADC B5
+                    {
+                        static Uint8 toggleState = 0;
+                        if (toggleState == 0)
+                            GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
+                        else
+                            GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
+                        toggleState = ~(toggleState);
+                    }
+                }
+#endif           
+                
                 // Decode processing for either PCM or bitstream
                 // New state will be decided inside the function
                 asitErr = asitDecodeProcessing(pP, pQ, pAsitCfg, events);
@@ -386,7 +408,7 @@ Int asitPrepareProcessing(const PAF_ASIT_Params *pP,
     *asipErrno = 0;
 
     // Select source and initialize physical layer / HW interface
-    *asipErrno = asitSelectDevices(pQ, pInp);
+    *asipErrno = asitSelectDevices(pQ, pAstCfg, pInp);
     if (*asipErrno) {
         TRACE_TERSE2("asitSelectDevices returned asipErrno = 0x%04x at line %d. AS%d",
                      *asipErrno, as+zMS);
@@ -491,7 +513,7 @@ Int asitSourceDetection(const PAF_ASIT_Params *pP,
     asitErr = asitInputDataProcess(pInp, &autoDetStatus);
     if(asitErr != ASIT_NO_ERR) {
         // Even though there is error, still need to start next transfer to
-        // maintain McASP transfer.
+        // maintain McASP transfer, before returning error.
         asitPhyTransferStart(pInp);
 
         return asitErr;
@@ -500,8 +522,11 @@ Int asitSourceDetection(const PAF_ASIT_Params *pP,
     // Mark input data read complete
     ioDataReadComplete(pInp->hIoData);
 
+    if(autoDetStatus.syncTimeOut) {
+        return ASIT_AUTODET_TIME_OUT;
+    }
     // Check if bitstream or PCM is detected
-    if(   autoDetStatus.syncState == IODATA_SYNC_BITSTREAM
+    else if(   autoDetStatus.syncState == IODATA_SYNC_BITSTREAM
        || autoDetStatus.syncState == IODATA_SYNC_PCM) {
         // Decide input source and inform decoder
         asitErr = asitDecideSource(pAstCfg, pInp, &autoDetStatus);
@@ -522,6 +547,7 @@ Int asitSourceDetection(const PAF_ASIT_Params *pP,
             if(autoDetStatus.syncState == IODATA_SYNC_BITSTREAM) {
                 // Input is bit stream: go to decoding
                 pInp->asipState = ASIT_DECODE_PROCESSING;
+                TRACE_VERBOSE0("Bit stream detected. Go to decoding. ");
             }
             else  {
                 // Input is PCM: stop swapping data
@@ -529,7 +555,7 @@ Int asitSourceDetection(const PAF_ASIT_Params *pP,
 
                 // Reconfigure McASP LLD to transfer 32-bit unpacked data
                 mcaspErr = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_32);
-                if(mcaspErr != Audk2g_EOK) {
+                if(mcaspErr != Aud_EOK) {
                     return ASIT_ERR_MCASP_CFG;
                 }
 
@@ -537,11 +563,18 @@ Int asitSourceDetection(const PAF_ASIT_Params *pP,
                 // always point to PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
                 ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
 
+                // Mute decoder output during PCM transition
+                pAstCfg->xInp[zMD].inpBufConfig.deliverZeros = TRUE;
+
                 // Go to transition state to switch to PCM
                 pInp->asipState = ASIT_PCM_TRANSITION;
+                TRACE_VERBOSE0("PCM stream detected. Go to PCM transition. ");
             }
         }
     }
+    else {
+        // SYNC search ongoing, no action is needed
+    }
 
     // Start next transfer
     asitPhyTransferStart(pInp);
@@ -594,6 +627,9 @@ Int asitPcmTransition(PAF_ASIT_Config *pAsitCfg)
     pInp->pcmSwitchHangOver--;
     if(pInp->pcmSwitchHangOver == 0) {
         pInp->asipState = ASIT_DECODE_PROCESSING;
+
+        // Unmute decoder output after PCM transition
+        pAsitCfg->pAstCfg->xInp[zMD].inpBufConfig.deliverZeros = FALSE;
     }
     else {
         ; // stay in this state
@@ -634,7 +670,7 @@ Int asitBypassIoData(PAF_AST_IoInp *pInp)
         ioBuffReadComplete(pInp->hIoBuff, buff2, size2);
     }
 
-    return ASIP_NO_ERR;
+    return ASIT_NO_ERR;
 } /* asitBypassIoData */
 
 
@@ -707,7 +743,8 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP,
 
                 // Inform decoder to complete the decoding of previous frame - is this good?
                 pInp->sourceSelect = PAF_SOURCE_NONE;
-                pInp->numFrameReceived = 0;    // for debugging
+                pInp->numFrameReceived    = 0;    // for debugging
+                pInp->numPcmFrameReceived = 0;    // for debugging
                 TRACE_TERSE0("asitDecodeProcessing: SYNC lost.");
 
 #ifdef DEBUG_SKIP_DECODING
@@ -715,11 +752,16 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP,
 #endif
             }
             else {
-                pInp->numFrameReceived += 1;    // for debugging
+                if(autoDetStatus.syncState == IODATA_SYNC_PCM) {
+                    pInp->numPcmFrameReceived += 1;  // for debugging
+                }
+                else {
+                    pInp->numFrameReceived += 1;     // for debugging
+                }
 
                 // Communicate input stream information to decoder through input
-                // buffer configuration
-                asitUpdateInpBufConfig(pAsitCfg->pAstCfg, pInp);
+                // buffer configuration -- this was moved inside decDecodeFsm
+                //asitUpdateInpBufConfig(pAsitCfg->pAstCfg, pInp);
 
                 // Start next transfer
                 asitPhyTransferStart(pInp);
@@ -744,7 +786,8 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP,
         else {
             // Inform decoder to complete the decoding of previous frame - is this good?
             pInp->sourceSelect = PAF_SOURCE_NONE;
-            pInp->numFrameReceived = 0;    // for debugging
+            pInp->numFrameReceived    = 0;    // for debugging
+            pInp->numPcmFrameReceived = 0;    // for debugging
             TRACE_TERSE1("asitDecodeProcessing: asitInputDataProcess error: %d", asitErr);
 
 #ifdef DEBUG_SKIP_DECODING
@@ -879,76 +922,80 @@ int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
     ioDataParam_t  ioDataCfg;
     ioPhyCtl_t     ioPhyCtl;
 
-    pInpIo->phyXferSize = INPUT_FRAME_SIZE_DEF;
-
-    if(pInpIo->firstTimeInit) {
-        TRACE_VERBOSE0("Initialize I/O BUFF and I/O PHY.");
-        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 (ASIT_ERR_IOBUFF_INIT);   // to remove magic number
-        }
+    if (pInpIo->hMcaspChan != NULL)
+    {
+        //pInpIo->phyXferSize = INPUT_FRAME_SIZE_DEF;
+        pInpIo->phyXferSize = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF * WORD_SIZE_BITSTREAM;
+
+        if (pInpIo->firstTimeInit) {
+            TRACE_VERBOSE0("Initialize I/O BUFF and I/O PHY.");
+            ioBuffParams.base         = pInpBuf->inpBufConfig.base.pVoid;
+            ioBuffParams.size         = pInpBuf->inpBufConfig.allocation / STRIDE_WORST_CASE
+                                                                         * STRIDE_WORST_CASE;
+            ioBuffParams.sync         = IOBUFF_WRITE_SYNC;
+            ioBuffParams.nominalDelay = pInpIo->phyXferSize;
+            if (ioBuffInit(pInpIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) {
+                return (ASIT_ERR_IOBUFF_INIT);   // to remove magic number
+            }
+
+            ioPhyParams.ioBuffHandle    = pInpIo->hIoBuff;
+            ioPhyParams.xferFrameSize   = pInpIo->phyXferSize;
+            ioPhyParams.mcaspChanHandle = pInpIo->hMcaspChan;
+            ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_WRITE;
+            if (ioPhyInit(pInpIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) {
+                return (ASIT_ERR_IOPHY_INIT);   // to remove magic number
+            }
 
-        ioPhyParams.ioBuffHandle    = pInpIo->hIoBuff;
-        ioPhyParams.xferFrameSize   = pInpIo->phyXferSize;
-        ioPhyParams.mcaspChanHandle = pInpIo->hMcaspChan;
-        ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_WRITE;
-        if(ioPhyInit(pInpIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) {
-            return (ASIT_ERR_IOPYH_INIT);   // to remove magic number
+            pInpIo->numPrimeXfers = NUM_PRIME_XFERS;
         }
 
-        pInpIo->numPrimeXfers = NUM_PRIME_XFERS;
-    }
+        /* Reinitialize I/O DATA every time when ASIT restarts */
+        TRACE_VERBOSE0("Initialize I/O DATA.");
+        ioDataCfg.ioBuffHandle         = pInpIo->hIoBuff;
+        ioDataCfg.unknownSourceTimeOut = pInpBuf->inpBufConfig.pBufStatus->unknownTimeout;
+        ioDataCfg.frameLengthsIEC      = (uint_least16_t *)&iecFrameLength[0];
+        ioDataCfg.frameLengthPCM       = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF;
+        ioDataCfg.frameLengthDef       = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF;
+        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 (ASIT_ERR_IODATA_INIT);   // to remove magic number
+        }
 
-    /* Reinitialize I/O DATA every time when ASIT restarts */
-    TRACE_VERBOSE0("Initialize I/O DATA.");
-    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 (ASIT_ERR_IODATA_INIT);   // to remove magic number
-    }
+        if (pInpIo->firstTimeInit) {
+            /* Initialize I/O BUFF and I/O PHY only when input interface changes. */
+            TRACE_VERBOSE0("Prime I/O PHY.");
 
-    if(pInpIo->firstTimeInit) {
-        /* Initialize I/O BUFF and I/O PHY only when input interface changes. */
-        TRACE_VERBOSE0("Prime I/O PHY.");
+            // Start I/O physical layer by priming McASP LLD for input
+            asitIoPhyPrime(pInpIo);
 
-        // Start I/O physical layer by priming McASP LLD for input
-        asitIoPhyPrime(pInpIo);
+            pInpIo->firstTimeInit = FALSE;
+        }
+        else {
+            // Reconfigure I/O PHY transfer size
+            ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
+            ioPhyCtl.params.xferFrameSize = pInpIo->phyXferSize;
+            ioPhyControl(pInpIo->hIoPhy, &ioPhyCtl);
+    #if 0
+            // If previous stream before reset was PCM, reconfigure McASP LLD to receive 16-bit packed bits
+            if (!pInpIo->swapData) {
+                Int mcaspErr;
+                mcaspErr = mcaspRecfgWordWidth(pInpIo->hMcaspChan, Mcasp_WordLength_16);
+                if(mcaspErr != Aud_EOK) {
+                    return ASIT_ERR_MCASP_CFG;
+                }
 
-        pInpIo->firstTimeInit = FALSE;
-    }
-    else {
-        // Reconfigure I/O PHY transfer size
-        ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
-        ioPhyCtl.params.xferFrameSize = pInpIo->phyXferSize;
-        ioPhyControl(pInpIo->hIoPhy, &ioPhyCtl);
-
-        // If previous stream before reset was PCM, reconfigure McASP LLD to receive 16-bit packed bits
-        if(!pInpIo->swapData) {
-            Int mcaspErr;
-            mcaspErr = mcaspRecfgWordWidth(pInpIo->hMcaspChan, Mcasp_WordLength_16);
-            if(mcaspErr != Audk2g_EOK) {
-                return ASIT_ERR_MCASP_CFG;
+                // Start swapping data
+                pInpIo->swapData = TRUE;
+                TRACE_VERBOSE0("Reconfigure McASP word length and start swapping data.");
             }
-
-            // Start swapping data
-            pInpIo->swapData = TRUE;
-            TRACE_VERBOSE0("Reconfigure McASP word length and start swapping data.");
+    #endif
+            // Start PHY transfer
+            TRACE_VERBOSE0("Start I/O PHY transfer.");
+            asitPhyTransferStart(pInpIo);
         }
-
-        // Start PHY transfer
-        TRACE_VERBOSE0("Start I/O PHY transfer.");
-        asitPhyTransferStart(pInpIo);
     }
 
     return 0;
@@ -959,10 +1006,11 @@ int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
  *====================================================================================*/
 void asitProcInit(PAF_AST_IoInp  *pInp, asipDecProc_t *pDec)
 {
-    pInp->swapData = TRUE;
+//    pInp->swapData = TRUE;
     pInp->pcmSwitchHangOver = INPUT_SWITCH_HANGOVER;
     pDec->initDone = FALSE;
-    pInp->numFrameReceived = 0;
+    pInp->numFrameReceived    = 0;    // for debugging
+    pInp->numPcmFrameReceived = 0;    // for debugging
 }
 
 /*======================================================================================
@@ -991,6 +1039,7 @@ void asitPhyTransferComplete(PAF_AST_IoInp * pInpIo)
     ioPhyXferComplete(pInpIo->hIoPhy, pInpIo->swapData);
 } /* asitPhyTransferComplete */
 
+#if 0
 Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize)
 {
     ioPhyCtl_t ioPhyCtl;
@@ -1005,7 +1054,7 @@ Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize)
     if(!pInp->swapData) {
         // If it was PCM, reconfigure McASP LLD to receive 16-bit packed bits
         mcaspErr = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_16);
-        if(mcaspErr != Audk2g_EOK) {
+        if(mcaspErr != Aud_EOK) {
             return ASIT_ERR_MCASP_CFG;
         }
 
@@ -1016,6 +1065,7 @@ Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize)
     return ASIT_NO_ERR;
 
 } /* asitRecfgPhyXfer */
+#endif
 
 /*======================================================================================
  *  McASP LLD call back function
@@ -1026,7 +1076,9 @@ void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
     if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
         //Semaphore_post(asipSemRx);
         Event_post(gAsitEvtHandle, ASIT_EVTMSK_INPDATA);
+        //Log_info0("asipMcaspCallback: final packet - event posted.\n");
     } else {
+        //Log_info0("asipMcaspCallback: intermediate packet.\n");
         ;    // intermediate packet due to buffer wrapping around
     }
 }
@@ -1043,14 +1095,16 @@ int asipCheckMcaspRxOverrun(Ptr mcaspChanHandle)
     return (mcaspErrStat.isRcvOvrRunOrTxUndRunErr);
 }
 
+#if 0
 /*======================================================================================
  *  This function restarts McASP LLD channel for input
  *====================================================================================*/
-void asipMcaspRxRestart(void)
+void asipMcaspRxRestart(PAF_AST_IoInp *pInpIo)
 {
     mcaspRxReset();
     mcaspRxCreate();
 }
+#endif
 
 /*======================================================================================
  *  This function starts an I/O PHY transfer
@@ -1063,9 +1117,11 @@ void asitPhyTransferStart(PAF_AST_IoInp *pInpIo)
 #ifdef ASIP_DEBUG
         pInpIo->numInputOverrun++;
 #endif
-        asipMcaspRxRestart();
+        //asipMcaspRxRestart(pInpIo);
+        System_abort("\nMcASP for input overruns! %d!\n");
     }
     else {
+        //TRACE_VERBOSE0("asitPhyTransferStart: submit a transfer");
         ioPhyErr = ioPhyXferSubmit(pInpIo->hIoPhy);
         //if(ioPhyXferSubmit(pInpIo->hIoPhy)==IOPHY_ERR_BUFF_OVERFLOW) {
         if(ioPhyErr!=IOPHY_NOERR){
@@ -1084,57 +1140,187 @@ void asitPhyTransferStart(PAF_AST_IoInp *pInpIo)
     }
 }
 
+// Indicates whether Input has been selected
 Int d10Initialized = 0;
-//extern Audk2g_STATUS mcaspAudioConfig(void);
-extern void McaspDevice_init(void);
+
+//extern Aud_STATUS mcaspAudioConfig(void);
+//extern void McaspDevice_init(void);
 
 /*======================================================================================
  *  This function initializes HW interface and selects the right device for input
  *====================================================================================*/
-Int asitSelectDevices(const PAF_ASIT_Patchs *pQ, PAF_AST_IoInp *pInp)
+Int asitSelectDevices(
+    const PAF_ASIT_Patchs *pQ, 
+    PAF_AST_Config *pAstCfg, 
+    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();
+    Int32 status;
+    Aud_STATUS audStatus;
+    const PAF_SIO_Params *pInPrms;
+    mcaspLLDconfig *pLldCfg;
+    mcaspLLDconfig *pReqLldCfg;
+    Ptr mcaspChanHandle;
+    Int zMD;
+    Int interface;
+    const PAF_SIO_Params *pD10Params;
+    UInt postedEvents;
 
-#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");
-            return ASIT_ERR_D10_CFG;
+    zMD = pAstCfg->masterDec;
+    
+    interface = pAstCfg->xInp[zMD].inpBufStatus.sioSelect; // obtain SIO select for input
+    
+    if (interface >= 0)
+    {
+        // Positive value for interface: new Input SIO update request has been received via alpha command.
+        // Negative value for interface: no new Input SIO update request has been received,
+        //                               previous requests have been processed.
+        
+        // check for valid index into device array
+        if (interface >= pQ->devinp->n)    // DEVINP_N
+        {
+            interface = 0; // treat as device InNone
         }
-        audk2g_delay(50000); // Without delay between these 2 calls system aborts.
+        
+        //
+        // Deactivate currently active interface
+        //
+        if (pInp->hMcaspChan != NULL)   // non-NULL McASP LLD channel handle indicates there's an active interface
+        {
+            d10Initialized = 0; // indicate no Input selected
+            
+            // Reset channel
+            status = mcaspControlChan(pInp->hMcaspChan, MCASP_CHAN_RESET, NULL);   // Rx reset channel
+            //status = mcaspControlChan(pInp->hMcaspChan, MCASP_DEVICE_RESET, NULL); // Reset Tx/Rx channel
+            if (status != MCASP_COMPLETED)
+            {
+                Log_info0("asitSelectDevices(): McASP channel reset failed!\n");
+                return ASIP_ERR_MCASP_CFG;            
+            }
+            
+            // Delete McASP LLD channel
+            status = mcaspDeleteChan(pInp->hMcaspChan);
+            if (status != MCASP_COMPLETED)
+            {
+                Log_info0("asitSelectDevices(): McASP channel deletion failed!\n");
+                return ASIP_ERR_MCASP_CFG;
+            }
+            
+            // Clear (drop) already posted Input data events
+            postedEvents = Event_getPostedEvents(gAsitEvtHandle);
+            while ((postedEvents & ASIT_EVTMSK_INPDATA) != 0)
+            {
+                Event_pend(gAsitEvtHandle, ASIT_EVTMSK_NONE, ASIT_EVTMSK_INPDATA, 0);
+                postedEvents = Event_getPostedEvents(gAsitEvtHandle);
+            }
 
-        /* Initialize McASP module */
-        status = mcaspAudioConfig(); //defined in newio\fw\mcasp_cfg.c
-        if(status != Audk2g_EOK) {
-            Log_info0("McASP Configuration Failed!\n");
-            return ASIT_ERR_MCASP_CFG;
+            pInp->hMcaspChan = NULL;        // reset active McASP LLD handle
+            if (pInp->pRxParams != NULL)    // sanity check, pInp->pRxParams should be non NULL if pInp->hMcaspChan is non NULL
+            {
+                pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
+                pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig; // get pointer to active McASP LLD configuration
+                pLldCfg->hMcaspChan = NULL; // reset McASP LLD handle for active McASP LLD configuration
+                pInp->pRxParams = NULL;     // reset pointer to active D10 parameters
+            }
+            else 
+            {
+                // This is a programming error
+                SW_BREAKPOINT;  // debug
+            }
         }
 
-        pInp->hMcaspChan = hMcaspRxChan;
-        d10Initialized = 1;
+        //
+        // Activate requested interface
+        //
+        pD10Params = (const PAF_SIO_Params *)pQ->devinp->x[interface];  // get D10 parameters for selected interface
+        if (pD10Params != NULL)
+        {
+            //
+            // Requested device is other than InNone
+            //
+            if((interface == DEVINP_HDMI) || (interface == DEVINP_HDMI_STEREO))
+            {
+                D10_initHDMI();
+            }
+            
+            // Initialize Tx clock mux
+            D10_initClkMux((void *)pD10Params);
+                
+            pReqLldCfg = (mcaspLLDconfig *)pD10Params->sio.pConfig;
+            if (pReqLldCfg->hMcaspChan == NULL)
+            {
+                // Create McASP LLD channel
+                mcaspChanHandle = NULL;
+                audStatus = mcasplldChanCreate(pReqLldCfg, &mcaspChanHandle);
+                if (audStatus != Aud_EOK) 
+                {
+                    Log_info0("asitSelectDevices(): McASP channel creation failed!\n");
+                    return ASIP_ERR_MCASP_CFG;
+                }
+                
+                pReqLldCfg->hMcaspChan = mcaspChanHandle;   // set McASP LLD handle for requested McASP LLD configuration
+                pInp->pRxParams = (const void *)pD10Params; // set pointer to active D10 parameters
+                pInp->hMcaspChan = pReqLldCfg->hMcaspChan;  // set active McASP LLD handle
+                
+                // configure stride according to selected McASP LLD configuration
+                pInp->stride = pReqLldCfg->mcaspChanParams->noOfSerRequested * 
+                    pReqLldCfg->mcaspChanParams->noOfChannels;
+                
+                pInp->firstTimeInit = TRUE; // set flag for IO Phy & Buff initialization
+                
+                d10Initialized = 1; // indicate Input selected
+            }
+        }
+        else
+        {
+            //
+            // Requested device is InNone
+            //
+            pInp->hMcaspChan = NULL;    // reset active McASP LLD handle
+            pInp->pRxParams = NULL;     // reset pointer to active D10 parameters
+        }
+        
+        // indicate SIO update request processed
+        pAstCfg->xInp[zMD].inpBufStatus.sioSelect = interface | 0x80;
     }
 
-    /////////////// TODO: HW interface selection and initialization //////////////
-    ////// to add what PAF_ASIT_selectDevices() does /////////
-#ifdef IO_HW_INTERFACE
-    pInp->pRxParams = pQ->devinp->x[IO_HW_INTERFACE];
-#else
-    pInp->pRxParams = NULL;
-#endif
+    if (pInp->hMcaspChan != NULL)       // non NULL indicates there's an active interface
+    {
+        if (pInp->pRxParams != NULL)    // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
+        {
+            pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
+            pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig;   // get currently active McASP LLD configuration
+            if (pLldCfg != NULL)        // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
+            {
+                // Configure McASP to receive 16/32-bit data according to default configuration
+                mcaspRecfgWordWidth(pInp->hMcaspChan, pLldCfg->mcaspChanParams->wordWidth);
+                
+                // Set flag to swap HDMI data if it is 4xI2S and word length is 16
+                if ((pLldCfg->mcaspChanParams->wordWidth == Mcasp_WordLength_16) &&
+                    (pLldCfg->mcaspChanParams->noOfSerRequested == 4)) 
+                {
+                    pInp->swapData = TRUE;
+                }
+                else 
+                {
+                    pInp->swapData = FALSE;
+                }
+            }
+            else
+            {
+                // This is a programming error
+                SW_BREAKPOINT;  // debug
+            }
 
-    return 0;
+        }
+        else
+        {
+            // This is a programming error
+            SW_BREAKPOINT;  // debug
+        }
+    }
+    
+    return ASIP_NO_ERR;
 }  /* asitSelectDevices */
 
 /*======================================================================================
@@ -1285,7 +1471,7 @@ Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
     }
 
     if(autoDetStatus->syncState == IODATA_SYNC_BITSTREAM) {
-        uint_least16_t pc = autoDetStatus->bitStreamInfo & SYNC_PC_MASK; //0x001F
+        uint_least16_t pc = autoDetStatus->streamInfo.IEC_PC;
         sourceProgram = IECpafSource[pc];
     }
 
@@ -1407,7 +1593,7 @@ Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
     // Decide frame length for I/O DATA and I/O PHY
     if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
         // For PCM, I/O frame length is decode frame length multiplied by stride
-        ioFrameLength = decFrameLength * INPUT_STRIDE;
+        ioFrameLength = decFrameLength * pInp->stride;
 
         pBufConfig->sizeofElement = WORD_SIZE_PCM;
         pBufConfig->frameLength   = pBufConfig->lengthofData = ioFrameLength;
@@ -1430,31 +1616,16 @@ Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
     }
     else {
         // For bitstream, I/O frame length is the frame length of the bitstream
-        uint_least16_t pc = autoDetStatus->bitStreamInfo & SYNC_PC_MASK; //0x001F
-        ioFrameLength = iecFrameLength[pc];
-
-/*
-        if(   (pc == 0x11) && (DTSHDSubType == 3)
-           && (PAF_ASP_sampleRateHzTable[pBufConfig->pBufStatus->sampleRateStatus][PAF_SAMPLERATEHZ_STD] <=48000.0))
-            pDevExt->sourceProgram = PAF_SOURCE_DXP;    // LBR is 23
-
-        if (pc == 1)
-            pDevExt->elementSize = 4288;
-        else if (pc == 0x11) {
-            pDevExt->frameLength = (pDevExt->pIECFrameLength[pc] << DTSHDSubType);
-            pDevExt->lengthofData = pDevExt->frameLength;
-        }
-*/
-
         pBufConfig->sizeofElement = WORD_SIZE_BITSTREAM;
-        pBufConfig->frameLength   = ioFrameLength;
-        pBufConfig->lengthofData  = ioFrameLength - IEC_HEADER_LENGTH;
+        pBufConfig->frameLength   = autoDetStatus->streamInfo.frameLength;
+        pBufConfig->lengthofData  = autoDetStatus->streamInfo.dataLength;
+        ioFrameLength = autoDetStatus->streamInfo.frameLength;
 
         // Change I/O PHY transfer size to bitstream frame size
-        pInp->phyXferSize = ioFrameLength*WORD_SIZE_BITSTREAM;
+        pInp->phyXferSize = ioFrameLength*(WORD_SIZE_BITSTREAM);
     }
 
-    pBufConfig->stride = INPUT_STRIDE;   // common for PCM and bitstream
+    pBufConfig->stride = pInp->stride;   // common for PCM and bitstream
 
     // Configure I/O PHY transfer size
     ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
@@ -1465,31 +1636,14 @@ Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
     sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
                                           GATEMP_INDEX_DEC);
 
-    if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
-        // Bitstream preamble is not found and it times out -> assume this is PCM
-        deliverZeros = autoDetStatus->deliverZeros;
-        if (sourceConfig == PAF_SOURCE_PCM || sourceConfig == PAF_SOURCE_DSD1 ||
-            sourceConfig == PAF_SOURCE_DSD2 || sourceConfig == PAF_SOURCE_DSD3) {
-            // set to one -- ensures that PCM decode calls made before data is
-            // available will result in zero output.
-            // (mostly needed for PA15 since, currently, all other frameworks
-            // require a frame of data before the first decode call.
-            deliverZeros = TRUE;  // override deliverZeros returned by ioDataControl
-        }
-
-        // update input buffer config structure
-        pBufConfig->deliverZeros  = deliverZeros;
-    }
-
-    //JXTODO: decide what to do with hRxSio
-    //temporary - does ARM use hRxSio or just check if it is not NULL?
+    // temporary - does ARM use hRxSio or just check if it is not NULL?
     pAstCfg->xInp[zMD].hRxSio = pInp->hIoData;
     pAstCfg->xInp[zMD].pInpBuf = &(pAstCfg->xInp[zMD].inpBufConfig);
 
     return ASIT_NO_ERR;
 } /* asitUpdateIoComps */
 
-
+#if 0
 #ifndef IO_LOOPBACK_TEST
 #if OUTPUT_FRAME_LENGTH == INPUT_FRAME_LENGTH
 U8 pcmbuf[OUTPUT_FRAME_SIZE];
@@ -1541,6 +1695,8 @@ Int rxDecodePlayZero(PAF_AST_IoInp  *pInp)
 }
 #endif
 
+#endif
+
 Int asitEvtErrCheck(UInt actualEvents, UInt expectedEvents)
 {
     TRACE_VERBOSE2("ASIT events error: actual events are: %d, expected events are: %d.",
@@ -1557,6 +1713,12 @@ void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr)
         TRACE_VERBOSE0("ASIT error handling: input buffer underflows. No actions needed.");
     }
 
+    if(asitErr == ASIT_AUTODET_TIME_OUT) {
+        pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
+        pAsitCfg->pIoInp[0].numAsitRestart++;
+        TRACE_VERBOSE1("ASIT error %d handling finished. Go to state ASIT_RESET.", asitErr);
+    }
+    
     if(asitErr == ASIT_ERR_DECODE_QUIT) {
         TRACE_VERBOSE0("ASIT error handling: DECODE_QUIT - clear INPDATA event.");
 #if 0
@@ -1572,13 +1734,13 @@ void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr)
 #endif
         pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
         pAsitCfg->pIoInp[0].numAsitRestart++;
-        TRACE_VERBOSE0("ASIT error handling finished. Go to state ASIT_RESET.");
+        TRACE_VERBOSE1("ASIT error %d handling finished. Go to state ASIT_RESET.", asitErr);
     }
 
     if(asitErr == ASIT_ERR_EVENTS) {
         pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
         pAsitCfg->pIoInp[0].numAsitRestart++;
-        TRACE_VERBOSE0("ASIT error handling: events error. Go to state ASIT_RESET.");
+        TRACE_VERBOSE1("ASIT error %d handling: events error. Go to state ASIT_RESET.", asitErr);
     }
 
     return;