]> 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 84d525c83631c5869794344ccac9edb3121db9df..7aec882afcf7ddb68b12db930d0c509e88dc515c 100644 (file)
@@ -57,6 +57,7 @@ All rights reserved.
 #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
 
@@ -113,6 +114,7 @@ extern Void taskAsipFxnInit(const PAF_ASIT_Params *pP,const PAF_ASIT_Patchs *pQ)
 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
@@ -511,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;
@@ -545,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
@@ -560,8 +563,12 @@ 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. ");
             }
         }
     }
@@ -620,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
@@ -733,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
@@ -741,7 +752,12 @@ 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 -- this was moved inside decDecodeFsm
@@ -770,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
@@ -916,7 +933,7 @@ int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
             ioBuffParams.size         = pInpBuf->inpBufConfig.allocation / STRIDE_WORST_CASE
                                                                          * STRIDE_WORST_CASE;
             ioBuffParams.sync         = IOBUFF_WRITE_SYNC;
-            ioBuffParams.nominalDelay = INPUT_FRAME_SIZE_DEF;
+            ioBuffParams.nominalDelay = pInpIo->phyXferSize;
             if (ioBuffInit(pInpIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) {
                 return (ASIT_ERR_IOBUFF_INIT);   // to remove magic number
             }
@@ -992,7 +1009,8 @@ void asitProcInit(PAF_AST_IoInp  *pInp, asipDecProc_t *pDec)
 //    pInp->swapData = TRUE;
     pInp->pcmSwitchHangOver = INPUT_SWITCH_HANGOVER;
     pDec->initDone = FALSE;
-    pInp->numFrameReceived = 0;
+    pInp->numFrameReceived    = 0;    // for debugging
+    pInp->numPcmFrameReceived = 0;    // for debugging
 }
 
 /*======================================================================================
@@ -1058,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
     }
 }
@@ -1101,6 +1121,7 @@ void asitPhyTransferStart(PAF_AST_IoInp *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){
@@ -1134,7 +1155,8 @@ Int asitSelectDevices(
     PAF_AST_IoInp *pInp
 )
 {
-    Aud_STATUS status;
+    Int32 status;
+    Aud_STATUS audStatus;
     const PAF_SIO_Params *pInPrms;
     mcaspLLDconfig *pLldCfg;
     mcaspLLDconfig *pReqLldCfg;
@@ -1167,13 +1189,18 @@ Int asitSelectDevices(
         {
             d10Initialized = 0; // indicate no Input selected
             
-            // check McASP LLD control API
-            mcaspControlChan(pInp->hMcaspChan, MCASP_CHAN_RESET, NULL);   // Rx reset channel
-            //mcaspControlChan(pInp->hMcaspChan, MCASP_DEVICE_RESET, NULL); // Reset Tx/Rx channel
+            // 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 != Aud_EOK)
+            if (status != MCASP_COMPLETED)
             {
                 Log_info0("asitSelectDevices(): McASP channel deletion failed!\n");
                 return ASIP_ERR_MCASP_CFG;
@@ -1211,6 +1238,10 @@ Int asitSelectDevices(
             //
             // Requested device is other than InNone
             //
+            if((interface == DEVINP_HDMI) || (interface == DEVINP_HDMI_STEREO))
+            {
+                D10_initHDMI();
+            }
             
             // Initialize Tx clock mux
             D10_initClkMux((void *)pD10Params);
@@ -1220,8 +1251,8 @@ Int asitSelectDevices(
             {
                 // Create McASP LLD channel
                 mcaspChanHandle = NULL;
-                status = mcasplldChanCreate(pReqLldCfg, &mcaspChanHandle);
-                if (status != Aud_EOK) 
+                audStatus = mcasplldChanCreate(pReqLldCfg, &mcaspChanHandle);
+                if (audStatus != Aud_EOK) 
                 {
                     Log_info0("asitSelectDevices(): McASP channel creation failed!\n");
                     return ASIP_ERR_MCASP_CFG;
@@ -1440,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];
     }
 
@@ -1585,28 +1616,13 @@ 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 = pInp->stride;   // common for PCM and bitstream
@@ -1620,24 +1636,7 @@ 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);