From f9a290906a901a3b2f0f63854f2ba89f4098d4c7 Mon Sep 17 00:00:00 2001 From: Jianzhong Xu Date: Fri, 16 Feb 2018 16:49:41 -0500 Subject: [PATCH] Fixed loss of SYNC problem and restart problem. ASIT FSM works fine with 100's of PCM/bit streams. --- .../framework/audioStreamInpProcNewIO.c | 107 ++++++++++++------ pasdk/test_dsp/io/ioConfig.h | 8 +- 2 files changed, 75 insertions(+), 40 deletions(-) diff --git a/pasdk/test_dsp/framework/audioStreamInpProcNewIO.c b/pasdk/test_dsp/framework/audioStreamInpProcNewIO.c index cbaa4c2d..9275da7d 100644 --- a/pasdk/test_dsp/framework/audioStreamInpProcNewIO.c +++ b/pasdk/test_dsp/framework/audioStreamInpProcNewIO.c @@ -60,6 +60,8 @@ All rights reserved. #define STRIDE_WORST_CASE 32 // 4-byte (32-bit) word, 2 slots, 4 serializers +//#define DEBUG_SKIP_DECODING + #define SYNC_PC_MASK 0x1F #define SYNC_SUBTYPE_MASK 0x700 #define SYNC_SUBTYPE_SHIFT 8 @@ -455,6 +457,7 @@ Int asitPrepareProcessing(const PAF_ASIT_Params *pP, return TRUE; } /* asitPrepareProcessing */ + /*=========================================================================== * ASIT Source Detection: * ASIT processing for input source identification: @@ -512,7 +515,7 @@ Int asitSourceDetection(const PAF_ASIT_Params *pP, // set to unknown so that we can ensure, for IOS purposes, that // sourceDecode = NONE iff we are in this top level state machine // and specifically not in decodeProcessing -#ifndef PCM_LOOPBACK_TEST +#ifndef DEBUG_SKIP_DECODING pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN); #endif @@ -669,15 +672,19 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP, pDec = &pAsitCfg->inpDec; // Initialization for decode processing when this function is called the first time +#ifndef DEBUG_SKIP_DECODING if(!pDec->initDone) { // Initialize decoder decDecodeInit(pP, pAsitCfg, pInp->sourceSelect); pDec->initDone = TRUE; } +#endif // Process input data if this is a data ready message if(asitEvents & ASIT_EVTMSK_INPDATA) { + TRACE_TERSE0("asitDecodeProcessing: process input data."); + // Marks I/O PHY transfer and I/O BUFF write complete asitPhyTransferComplete(pInp); @@ -699,6 +706,10 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP, pInp->sourceSelect = PAF_SOURCE_NONE; pInp->numFrameReceived = 0; // for debugging TRACE_TERSE0("asitDecodeProcessing: SYNC lost."); + +#ifdef DEBUG_SKIP_DECODING + asitErr = ASIT_ERR_DECODE_QUIT; +#endif } else { pInp->numFrameReceived += 1; // for debugging @@ -706,21 +717,46 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP, // Communicate input stream information to decoder through input // buffer configuration asitUpdateInpBufConfig(pAsitCfg->pAstCfg, pInp); + + // Start next transfer + asitPhyTransferStart(pInp); } // Start next transfer - asitPhyTransferStart(pInp); + //asitPhyTransferStart(pInp); + +#ifdef DEBUG_SKIP_DECODING + return asitErr; +#endif } - else { - // Even though there is error, still need to start next transfer to - // maintain McASP transfer. + else if(asitErr == ASIT_ERR_INPBUF_UNDERFLOW) { + TRACE_TERSE0("asitDecodeProcessing: Input buffer underflows."); + + // When input buffer underflows, it is not an error but decoding needs + // to be skipped as there is not enough data in the buffer. asitPhyTransferStart(pInp); return asitErr; } + else { + // Inform decoder to complete the decoding of previous frame - is this good? + pInp->sourceSelect = PAF_SOURCE_NONE; + pInp->numFrameReceived = 0; // for debugging + TRACE_TERSE1("asitDecodeProcessing: asitInputDataProcess error: %d", asitErr); +#ifdef DEBUG_SKIP_DECODING + return ASIT_ERR_DECODE_QUIT; +#endif + } } /* ASIT_EVTMSK_INPDATA */ +#ifdef DEBUG_SKIP_DECODING + else { + TRACE_TERSE0("asitDecodeProcessing: events error."); + return ASIT_ERR_EVENTS; + } +#endif +#ifndef DEBUG_SKIP_DECODING // Map ASIT events to decode messages decMsg = asitEventsToDecMsg(asitEvents); @@ -747,7 +783,7 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP, else { return ASIT_NO_ERR; } - +#endif } /* asitDecodeProcessing */ @@ -824,36 +860,10 @@ int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo) ioDataParam_t ioDataCfg; ioPhyCtl_t ioPhyCtl; - TRACE_VERBOSE0("Initialize I/O DATA."); -/* 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 - } -*/ - /* Reinitialize I/O DATA every time when ASIT restarts */ - 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 - } - - pInpIo->numPrimeXfers = NUM_PRIME_XFERS; - pInpIo->phyXferSize = INPUT_FRAME_SIZE_DEF; + pInpIo->phyXferSize = INPUT_FRAME_SIZE_DEF; if(pInpIo->firstTimeInit) { - /* Initialize I/O BUFF and I/O PHY only when input interface changes. */ - TRACE_VERBOSE0("Initialize I/O PHY, and prime I/O PHY."); + 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; @@ -871,6 +881,28 @@ int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo) return (ASIT_ERR_IOPYH_INIT); // to remove magic number } + 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 = 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."); + // Start I/O physical layer by priming McASP LLD for input asitIoPhyPrime(pInpIo); @@ -1305,7 +1337,7 @@ Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp *pInp, return ASIT_ERR_NO_MATCHING_SOURCE; } -#ifndef PCM_LOOPBACK_TEST +#ifndef DEBUG_SKIP_DECODING // send source select message to slave *(Int32 *)&asipMsgBuf[0] = sourceSelect; if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE, @@ -1500,7 +1532,7 @@ void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr) if(asitErr == ASIT_ERR_DECODE_QUIT) { TRACE_VERBOSE0("ASIT error handling: DECODE_QUIT - clear INPDATA event."); - +#if 0 // Pend on INPTDATA event that should have been posted before decoding quits. events = Event_pend(asitEvent, ASIT_EVTMSK_NONE, ASIT_EVTMSK_INPDATA, BIOS_WAIT_FOREVER); @@ -1508,6 +1540,9 @@ void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr) // Marks I/O PHY transfer and I/O BUFF write complete asitPhyTransferComplete(&pAsitCfg->pIoInp[0]); + // Keep I/O BUFF read pointers going + asitBypassIoData(&pAsitCfg->pIoInp[0]); +#endif pAsitCfg->pIoInp[0].asipState = ASIT_RESET; pAsitCfg->pIoInp[0].numAsitRestart++; TRACE_VERBOSE0("ASIT error handling finished. Go to state ASIT_RESET."); diff --git a/pasdk/test_dsp/io/ioConfig.h b/pasdk/test_dsp/io/ioConfig.h index ca43abc4..27a67d12 100644 --- a/pasdk/test_dsp/io/ioConfig.h +++ b/pasdk/test_dsp/io/ioConfig.h @@ -68,16 +68,16 @@ // Define McASP transfer element size: number of bytes in one word #define WORD_SIZE_BITSTREAM 2 #define WORD_SIZE_PCM 4 -#define NUM_CYCLE_PER_FRAME 128 +#define NUM_CYCLE_PER_FRAME_DEF 1024 //128 // Input frame length: number of words to be transfered in 1 transfer of McASP LLD Rx // These numbers are according to existing SIO/DEV based I/O. #define INPUT_STRIDE (2*NUM_RX_SERIALIZER) #ifdef INPUT_HDMI_4xI2S -#define INPUT_FRAME_LENGTH (NUM_CYCLE_PER_FRAME*INPUT_STRIDE) // 128 stereo/lane +#define INPUT_FRAME_LENGTH (NUM_CYCLE_PER_FRAME_DEF*INPUT_STRIDE) // 128 stereo/lane #else //#define INPUT_FRAME_LENGTH (64*INPUT_STRIDE) // 64 stereo/lane -#define INPUT_FRAME_LENGTH (NUM_CYCLE_PER_FRAME*INPUT_STRIDE) // 128 stereo/lane +#define INPUT_FRAME_LENGTH (NUM_CYCLE_PER_FRAME_DEF*INPUT_STRIDE) // 128 stereo/lane #endif // Input frame size: number of bytes to be transfered in 1 transfer of McASP LLD Rx @@ -86,7 +86,7 @@ // Output frame length: number of words to be transfered in 1 transfer of McASP LLD Tx #define OUTPUT_STRIDE (2*NUM_TX_SERIALIZER) -#define OUTPUT_FRAME_LENGTH (NUM_CYCLE_PER_FRAME*OUTPUT_STRIDE) // 128 stereo/lane +#define OUTPUT_FRAME_LENGTH (NUM_CYCLE_PER_FRAME_DEF*OUTPUT_STRIDE) // 128 stereo/lane // Output frame size: number of bytes to be transfered in 1 transfer of McASP LLD Tx #define OUTPUT_FRAME_SIZE (OUTPUT_FRAME_LENGTH * WORD_SIZE_PCM) -- 2.39.2