]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamInpProcNewIO.c
PASDK-577:Dynamic Input device selection
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProcNewIO.c
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37  *  ======== audioStreamInpProcNewIo.c ========
38  */
39 #include <xdc/runtime/Log.h>
40 #include <ti/sysbios/BIOS.h>
41 #include <xdc/runtime/Error.h>
42 #include <ti/sysbios/knl/Event.h>
44 #include "procsdk_audio_typ.h"
45 #include "audioStreamInpProc.h"
46 #include "audioStreamProc_common.h"
47 #include "aspMsg_common.h"
48 #include "aspMsg_master.h"
49 #include "asperr.h"
50 #include "common.h"
52 #include "aud.h"
53 #include "aud_audio.h"
54 #include "mcasp_cfg.h"
55 #include "ioConfig.h"    //TODO: remove this header
56 #include "ioBuff.h"
57 #include "ioPhy.h"
58 #include "ioData.h"
61 #define STRIDE_WORST_CASE 32  // 4-byte (32-bit) word, 2 slots, 4 serializers
63 //#define DEBUG_SKIP_DECODING
65 #define SYNC_PC_MASK         0x1F
66 #define SYNC_SUBTYPE_MASK    0x700
67 #define SYNC_SUBTYPE_SHIFT   8
68 #define SYNC_SUBTYPE_DTSHD   0x11
69 #define SYNC_DDP             0x15
70 #define SYNC_THD             0x16
72 #define IEC_HEADER_LENGTH    4
74 #define INPUT_SWITCH_HANGOVER 8
76 //table needed until PAF_SOURCE is reordered to match IEC numbering
77 const SmUns IECpafSource[23] =
78 {
79     PAF_SOURCE_UNKNOWN,  // 0: IEC NULL Type
80     PAF_SOURCE_AC3,      // 1: Comments on 1-15 match IEC 61937 part 2.
81     PAF_SOURCE_UNKNOWN,  // 2: IEC reserved
82     PAF_SOURCE_UNKNOWN,  // 3: IEC pause
83     PAF_SOURCE_UNKNOWN,  // 4: MPEG 1 layer 1
84     PAF_SOURCE_MP3,      // 5: MPEG layer 2 or 3
85     PAF_SOURCE_UNKNOWN,  // 6: MPEG 2 data with extension
86     PAF_SOURCE_AAC,      // 7: MPEG-2 AAC ADTS
87     PAF_SOURCE_UNKNOWN,  // 8: MPEG 2 layer 1 low sampling frequency
88     PAF_SOURCE_UNKNOWN,  // 9: MPEG 2 layer 2 or 3 low sampling frequency
89     PAF_SOURCE_UNKNOWN,  // 10: reserved
90     PAF_SOURCE_DTS,      // 11: DTS type 1 (11 bit: 512 sample repeat period)
91     PAF_SOURCE_DTS12,    // 12: DTS type 2 (12 bit: 1024 sample repeat period)
92     PAF_SOURCE_DTS13,    // 13: DTS type 3 (13 bit: 2048 sample repeat period)
93     PAF_SOURCE_DTS14,    // 14: ATRAC
94     PAF_SOURCE_UNKNOWN,  // 15: ATRAC 2/3
95     PAF_SOURCE_THD,      // 16
96     PAF_SOURCE_DTSHD,    // 17
97     PAF_SOURCE_WMA9PRO,  // 18
98     PAF_SOURCE_UNKNOWN,  // 19
99     PAF_SOURCE_UNKNOWN,  // 20
100     PAF_SOURCE_DDP,      // 21
101     PAF_SOURCE_THD,      // 22
102 };
104 /*
105  * Functions defined in other files and to be put into proper header files
106  */
107 extern Void taskAsipFxnInit(const PAF_ASIT_Params *pP,const PAF_ASIT_Patchs *pQ);
110 // avoid including sap_d10.h, which would cause symbol redefinition
111 // warning (MCASP_PFUNC_XXX)
112 extern XDAS_Int32 D10_init(void * pD10Params);
114 extern XDAS_Int32 D10_RxControl(const void *pD10RxParams,
115                                 XDAS_Int32 code, XDAS_Int32 arg);
117 /*
118  * Functions only used in this file
119  */
120 int asitPrepareProcessing();
121 int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo);
122 void asitProcInit(PAF_AST_IoInp  *pInp, asipDecProc_t *pDec);
123 void asitIoPhyPrime(PAF_AST_IoInp *pInpIo);
124 void asitPhyTransferComplete(PAF_AST_IoInp * pInpIo);
125 void asitPhyTransferStart(PAF_AST_IoInp *pInpIo);
126 Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize);
128 // Select Input devices
129 Int asitSelectDevices(
130     const PAF_ASIT_Patchs *pQ, 
131     PAF_AST_Config *pAstCfg, 
132     PAF_AST_IoInp *pInp
133 );
135 Int asitUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
136                           PAF_InpBufConfig *pInpBuf);
138 Int asitSourceDetection(const PAF_ASIT_Params *pP,
139                         const PAF_ASIT_Patchs *pQ,
140                         PAF_ASIT_Config       *pAsitCfg);
142 Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
143                      ioDataAutoDetStat_t *autoDetStatus);
144 Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
145                       PAF_AST_IoInp  *pInp, ioDataAutoDetStat_t *autoDetStatus);
146 Int asitBypassIoData(PAF_AST_IoInp *pInp);
147 Int asitPcmTransition(PAF_ASIT_Config *pAsitCfg);
149 void asitUpdateInpBufConfig(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp);
150 Int asitInputDataProcess(PAF_AST_IoInp *pInp, ioDataAutoDetStat_t *pAutoDetStats);
152 UInt asitEventsToDecMsg(UInt asitEvents);
153 void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr);
154 Int asitEvtErrCheck(UInt actualEvents, UInt expectedEvents);
156 void asitPostInfoEvent();
157 void asitPostDecEvent();
159 /*
160  * variables/structures to be put into proper global structures
161  */
162 extern PAF_ASIT_Config gPAF_ASIT_config;
163 extern const MdUns iecFrameLength[23];
164 extern Ptr hMcaspRxChan;
166 // temp for simulation
167 //#define ASIT_ALL_EVENTS (  ASIT_EVTMSK_INPDATA \
168 //                         + ASIT_EVTMSK_INFOACK \
169 //                         + ASIT_EVTMSK_DECACK )
170 #define ASIT_ALL_EVENTS (  ASIT_EVTMSK_INPDATA \
171                          + ASIT_EVTMSK_RXACK )
173 // temp for simulation
174 //#define ASIT_DEC_EVENTS (  ASIT_EVTMSK_INPDATA \
175 //                         + ASIT_EVTMSK_INFOACK \
176 //                         + ASIT_EVTMSK_DECACK )
177 #define ASIT_DEC_EVENTS (  ASIT_EVTMSK_INPDATA \
178                          + ASIT_EVTMSK_RXACK )
180 #define ASIP_DEBUG
182 #ifdef ASIP_DEBUG
183 /* define the following as global variables for easy debugging */
184 int asipLoopCount1, asipLoopCount2;
185 Int asipErrno;
186 Int inputReadyForProcessing;
188 // debug
189 #include "evmc66x_gpio_dbg.h"
190 #endif
192 Event_Handle gAsitEvtHandle;            // ASIT event handle
193 Int eventsOn;                           // flag indicating whether to process events
195 SyncEvent_Handle gAsitSyncEvtHandle;    // ASIT Sync event handle
197 /*
198  *  ======== taskAsipFxn ========
199  *  Audio Stream Input Processing task function
200  */
201 #ifndef PASDK_SIO_DEV
202 #ifndef IO_LOOPBACK_TEST
203 Void taskAsipFxn(                  // ASIP task function for new I/O
204 #else
205 Void taskAsipFxn_NewIO_Not_Used(   // not used for loopback test
206 #endif
207 #else
208 Void taskAsipFxn_NewIO_Not_USED(   // not used for SIO/DEV based I/O
209 #endif
210     const PAF_ASIT_Params *pP,
211         const PAF_ASIT_Patchs *pQ)
213     PAF_ASIT_Config *pAsitCfg;      /* ASIT configuration pointer */
214     PAF_AST_Config  *pAstCfg;       /* AST Common (shared) configuration pointer */
215     PAF_AST_IoInp *pInp;            /* Input I/O components */
216     Int as;                         /* Audio Stream Number (1, 2, etc.) */
217     Int z;                          /* input/encode/stream/decode/output counter */
218     Int zMI;
219 #ifndef ASIP_DEBUG
220 int asipLoopCount1, asipLoopCount2;
221 Int asipErrno;
222 Int inputReadyForProcessing;
223 #endif
224     Int asitErr;
225     UInt events;
226 //    Int eventsOn;
227 //    Error_Block  eb;
229     Log_info0("Enter taskAsipFxn()");
231     taskAsipFxnInit(pP, pQ);  // initialization of input task
232     
233     //
234     // Audio Stream Input Task Configuration (*pAsitCfg):
235     //
236     pAsitCfg = &gPAF_ASIT_config;       // initialize pointer to task configuration
237     pAstCfg  = pAsitCfg->pAstCfg;       // pointer to AST common (shared) configuration
239     /* Set Audio Stream Number (1, 2, etc.) */
240     as = pAstCfg->as;
242     //
243     // Determine decoder and stream indices associated with the master input
244     //
245     zMI  = pP->zone.master;
246     pInp = &pAsitCfg->pIoInp[zMI];        // pointer to input I/O components
248     for (z=STREAM1; z < STREAMN; z++)
249     {
250         TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
251     }
253     Log_info0("TaskAsip: Entering Main Loop.");
255     //
256     // Main processing loop
257     //
258     asipLoopCount1 = 0;
259     asipLoopCount2 = 0;
260     asitErr = ASIT_NO_ERR;
262     // The events_on flag will be removed if the RESTART state is changed to
263     // event-based scheduling instead of polling
264     eventsOn = FALSE;
266     for (;;)
267     {
268         asipLoopCount1++;
270         if(eventsOn) {
271             events = Event_pend(gAsitEvtHandle, ASIT_EVTMSK_NONE, ASIT_ALL_EVENTS,
272                                 BIOS_WAIT_FOREVER);
273         }
274         switch (pInp->asipState)
275         {
276         case ASIT_RESET:    // No events pending in this state
277             // Indicate decoder no decoding yet
278             pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
280             // 5 system tick, or 5 msec. Should remove this later when implementing
281             // event based scheduling.
282             Task_sleep(5);
284             inputReadyForProcessing = asitPrepareProcessing(pP, pQ, pAsitCfg, &asipErrno);
285             if (inputReadyForProcessing) {
286                 TRACE_VERBOSE0("TaskAsip: Input is ready. Initialize I/O components.");
287                 // Input is ready for processing, so we initialize the I/O components.
288                 // Note that the I/O components init. and I/O PHY prime are performed only
289                 // at the first time. This should be changed later - init. and prime
290                 // should be done whenever input interface has changed.
291                 asitErr = asitIoCompsInit(&pAstCfg->xInp[zMI], pInp);
293                 // Initialize ASIT processing
294                 asitProcInit(pInp, &pAsitCfg->inpDec);
295                 pInp->asipState = ASIT_SOURCE_DETECTION;
296                 eventsOn = TRUE;   // turn on events pending
297                 TRACE_VERBOSE0("TaskAsip: turn on events and go to source detection.");
298             }
299             break;
301         case ASIT_SOURCE_DETECTION:
302             // Source unknown - to detect & identify source
303             if(events == ASIT_EVTMSK_INPDATA) {  
304                 // Only this event is expected. If any other event, it's error.
305                 // Input data is ready - perform source detection.
306                 // New state will be decided inside the function
307                 asitErr = asitSourceDetection(pP, pQ, pAsitCfg);
308             }
309             else {
310                 //Error checking & debug
311                 asitErr = asitEvtErrCheck(events, ASIT_EVTMSK_INPDATA);
312             }
314             break;
316         case ASIT_PCM_TRANSITION:
317             // Source is PCM - transition to PCM decoding
318             if(events == ASIT_EVTMSK_INPDATA) {
319                 // Only this event is expected. If any other event, it's error.
320                 // Input data is ready - transition to PCM decoding
321                 // New state will be decided inside the function
322                 asitErr = asitPcmTransition(pAsitCfg);
323             }
324             else {
325                 //Error checking & debug
326                 asitErr = asitEvtErrCheck(events, ASIT_EVTMSK_INPDATA);
327             }
328             break;
330         case ASIT_DECODE_PROCESSING:
331             if(events & ASIT_DEC_EVENTS) {
332                 
333 #if 1 // debug 
334                 if (events & ASIT_EVTMSK_INPDATA)
335                 {
336                     // shows timing of Input (Rx McASP EDMA)
337                     // ADC B5
338                     {
339                         static Uint8 toggleState = 0;
340                         if (toggleState == 0)
341                             GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
342                         else
343                             GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
344                         toggleState = ~(toggleState);
345                     }
346                 }
347 #endif           
348                 
349                 // Decode processing for either PCM or bitstream
350                 // New state will be decided inside the function
351                 asitErr = asitDecodeProcessing(pP, pQ, pAsitCfg, events);
352             }
353             else {
354                 //Error checking & debug
355                 asitErr = asitEvtErrCheck(events, ASIT_DEC_EVENTS);
356             }
357             break;
359         default:
360             break;
361         }
363         if(asitErr) {
364             asitErrorHandling(pAsitCfg, asitErr);
366             if(pInp->asipState == ASIT_RESET) {
367                 eventsOn = FALSE;
368             }
370             asitErr = ASIT_NO_ERR;
371         }
373     }  // for (;;)
375 }  /* taskAsipFxn */
378 /*===========================================================================
379  * ASIT Processing Preparation
380  * Output:
381  *        - return        TRUE (input is ready) or FALSE (input is not ready)
382  *        - *asipErrno    Error number
383 ============================================================================*/
384 Int asitPrepareProcessing(const PAF_ASIT_Params *pP,
385                           const PAF_ASIT_Patchs *pQ,
386                           PAF_ASIT_Config       *pC,
387                           Int                   *asipErrno)
389     Int as, zMS, zMI, zMD;
390     Int sourceConfig, mode;
391     PAF_AST_Config  *pAstCfg;
392     PAF_AST_IoInp *pInp;            /* I/O components for input */
394     pAstCfg  = pC->pAstCfg;         // pointer to AST common (shared) configuration
395     as  = pAstCfg->as;
396     zMI = pP->zone.master;
397     zMD = pAstCfg->masterDec;
398     zMS = pAstCfg->masterStr;
399     pInp = pC->pIoInp;              // pointer to input I/O components
401     *asipErrno = 0;
403     // Select source and initialize physical layer / HW interface
404     *asipErrno = asitSelectDevices(pQ, pAstCfg, pInp);
405     if (*asipErrno) {
406         TRACE_TERSE2("asitSelectDevices returned asipErrno = 0x%04x at line %d. AS%d",
407                      *asipErrno, as+zMS);
408         return FALSE;    // Input is not ready for processing due to error
409     }
411     // If no master input selected then we don't know what may be at the input,
412     // so set to unknown and skip any remaining processing
413     if (!pInp[zMI].pRxParams) {
414         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
415                            (Int8)PAF_SOURCE_UNKNOWN, GATEMP_INDEX_DEC);
417         TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
418         return FALSE;    // No error, but input is not ready for processing
419     }
421     // If here then we have a valid input so query its status
422     *asipErrno = asitUpdateInputStatus(pInp[zMI].pRxParams,
423                                    &pAstCfg->xInp[zMI].inpBufStatus,
424                                    &pAstCfg->xInp[zMI].inpBufConfig);
425     if(*asipErrno) {
426         TRACE_VERBOSE1("TaskAsip: updateInputStatus returns 0x%x", *asipErrno);
427         return FALSE;   // Input is not ready for processing due to error
428     }
430     // If master decoder is not enabled, or the input is unlocked, then do nothing
431     mode = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
432                                   GATEMP_INDEX_DEC);
433     if (!mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
434     {
435         TRACE_VERBOSE0("TaskAsip: Not locked, continue");
436         return FALSE;  // No error, but input is not ready for processing
437     }
439     // Check selected source: sourceSelect is set by another task, AIP or AFP
440     sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
441                                           GATEMP_INDEX_DEC);
442     // If no source selected then do nothing
443     if(sourceConfig == PAF_SOURCE_NONE) {
444         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
445                            (Int8)PAF_SOURCE_NONE, GATEMP_INDEX_DEC);
446         TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
447         return FALSE;  // No error, but input is not ready for processing
448     }
450     // If we want pass processing then proceed directly
451     if (sourceConfig == PAF_SOURCE_PASS)
452     {
453         TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
454         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
455                            (Int8)PAF_SOURCE_PASS, GATEMP_INDEX_DEC);
457         pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
458         if (pP->fxns->passProcessing) {
459             *asipErrno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
460         }
461         else {
462             TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, asipErrno 0x%x",
463                          as+zMS, ASPERR_PASS);
464             *asipErrno = ASPERR_PASS;
465         }
467         TRACE_VERBOSE0("TaskAsip: continue");
468         return FALSE;  // Error or not, input is not ready for processing
469     }
471     // No error and input processing is ready
472     return TRUE;
473 } /* asitPrepareProcessing */
476 /*===========================================================================
477  * ASIT Source Detection:
478  *     ASIT processing for input source identification:
479  *     - mark I/O PHY transfer completion
480  *     - run auto-detection via I/O DATA in asitInputDataProcess
481  *     - mark I/O DATA read completion
482  *     - check auto-detection status and take corresponding actions if either
483  *       PCM or bitstream is identified:
484  *       - decide input source
485  *       - update I/O components
486  *       - reconfigure McASP LLD if it is PCM
487  *     - start next I/O PHY transfer
488 ============================================================================*/
489 Int asitSourceDetection(const PAF_ASIT_Params *pP,
490                         const PAF_ASIT_Patchs *pQ,
491                         PAF_ASIT_Config       *pAsitCfg)
493     PAF_AST_Config  *pAstCfg;
494     PAF_AST_IoInp *pInp;                // I/O components for input
495     Int zMD, mcaspErr, asitErr;
496     ioDataAutoDetStat_t autoDetStatus;
498     pAstCfg  = pAsitCfg->pAstCfg;               // pointer to AST common (shared) configuration
499     zMD = pAstCfg->masterDec;
500     pInp = &pAsitCfg->pIoInp[zMD];              // pointer to input I/O components
502     // Marks I/O PHY transfer and I/O BUFF write complete
503     asitPhyTransferComplete(pInp);
505     // Process input data - either searching SYNC for PCM or checking SYNC for bitstream
506     asitErr = asitInputDataProcess(pInp, &autoDetStatus);
507     if(asitErr != ASIT_NO_ERR) {
508         // Even though there is error, still need to start next transfer to
509         // maintain McASP transfer.
510         asitPhyTransferStart(pInp);
512         return asitErr;
513     }
515     // Mark input data read complete
516     ioDataReadComplete(pInp->hIoData);
518     // Check if bitstream or PCM is detected
519     if(   autoDetStatus.syncState == IODATA_SYNC_BITSTREAM
520        || autoDetStatus.syncState == IODATA_SYNC_PCM) {
521         // Decide input source and inform decoder
522         asitErr = asitDecideSource(pAstCfg, pInp, &autoDetStatus);
523         if(asitErr != ASIT_NO_ERR) {
524             return asitErr;
525         }
526         else {
527             // Update I/O components and input buffer config
528             asitUpdateIoComps(pP, pAstCfg, pInp, &autoDetStatus);
530             // set to unknown so that we can ensure, for IOS purposes, that
531             // sourceDecode = NONE iff we are in this top level state machine
532             // and specifically not in decodeProcessing
533 #ifndef DEBUG_SKIP_DECODING
534             pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN);
535 #endif
537             if(autoDetStatus.syncState == IODATA_SYNC_BITSTREAM) {
538                 // Input is bit stream: go to decoding
539                 pInp->asipState = ASIT_DECODE_PROCESSING;
540             }
541             else  {
542                 // Input is PCM: stop swapping data
543                 pInp->swapData = FALSE;
545                 // Reconfigure McASP LLD to transfer 32-bit unpacked data
546                 mcaspErr = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_32);
547                 if(mcaspErr != Aud_EOK) {
548                     return ASIT_ERR_MCASP_CFG;
549                 }
551                 // Adjust I/O BUFF delay and read pointer - to make sure read pointers
552                 // always point to PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
553                 ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
555                 // Go to transition state to switch to PCM
556                 pInp->asipState = ASIT_PCM_TRANSITION;
557             }
558         }
559     }
561     // Start next transfer
562     asitPhyTransferStart(pInp);
564     return (ASIT_NO_ERR);
565 }  /* asitSourceDetection */
568 /*===========================================================================
569     //
570     // which will cause all 0's in one McASP LLD transfer. This will
571     // be detected as loss of SYNC by auto detection. To prevent that,
572     // skip I/O DATA process for hangover period so that this all 0's
573     // frame will not be seen by auto-detection. Also, playing out PCM
574     // needs to be skipped as well, to prevent from playing out garbage
575     // (16-bit packed data).
576  *
577  * ASIT Transition to PCM decoding.
578  *     When PCM is detected, McASP LLD will be reconfigured to transmit 32-bit
579  *     words, which will modify the RFMT register. This will cause all 0's in
580  *     one McASP LLD transfer, which would be detected as loss of SYNC by auto
581  *     detection (performed by I/O DATA). To prevent that, skip I/O DATA process
582  *     for hangover period so that this all-0's frame will not be seen by the
583  *     auto-detection.
584  *
585  *     In addition, playing out PCM should be skipped as well to prevent from
586  *     playing out the 16-bit packed data that's still in the input buffer.
587  *
588  *     This function does the following:
589  *     - mark I/O PHY transfer completion
590  *     - bypass I/O DATA
591  *     - start next I/O PHY transfer
592 ============================================================================*/
593 Int asitPcmTransition(PAF_ASIT_Config *pAsitCfg)
595     Int asitErr;
596     PAF_AST_IoInp *pInp;                  // I/O components for input
597     Int zMD;
599     zMD = pAsitCfg->pAstCfg->masterDec;   // pointer to AST common (shared) configuration
600     pInp = &pAsitCfg->pIoInp[zMD];        // pointer to input I/O components
602     // Marks I/O PHY transfer and I/O BUFF write complete
603     asitPhyTransferComplete(pInp);
605     // Bypass I/O data processing due to McASP LLD work around
606     // (refer to comments inside the function)
607     asitErr = asitBypassIoData(pInp);
609     pInp->pcmSwitchHangOver--;
610     if(pInp->pcmSwitchHangOver == 0) {
611         pInp->asipState = ASIT_DECODE_PROCESSING;
612     }
613     else {
614         ; // stay in this state
615     }
617     // Start next transfer
618     asitPhyTransferStart(pInp);
620     return asitErr;
622 } /* asitPcmTransition */
624 /*============================================================================
625  * ASIT Bypass I/O DATA Processing
626  *     This function bypasses the I/O DATA processing. It maintains the read
627  *     operation of I/O BUFF by directly calling I/O BUFF APIs. When I/O DATA
628  *     is not bypassed, I/O BUFF read operation is invoked by I/O DATA.
629  *
630 ============================================================================*/
631 Int asitBypassIoData(PAF_AST_IoInp *pInp)
633     void *buff1, *buff2;
634     size_t size1, size2;
636     // Get read pointers (or sub-buffers) of the input buffer
637     if (ioBuffGetReadPtrs(pInp->hIoBuff, pInp->phyXferSize,
638                           &buff1, &size1, &buff2, &size2)
639         == IOBUFF_ERR_UNDERFLOW) {
640         pInp->numUnderflow += 1;
642         // Return since there is no enough data to process
643         return ASIT_ERR_INPBUF_UNDERFLOW;
644     }
646     ioBuffReadComplete(pInp->hIoBuff, buff1, size1);
648     if(buff2 != NULL) {
649         ioBuffReadComplete(pInp->hIoBuff, buff2, size2);
650     }
652     return ASIT_NO_ERR;
653 } /* asitBypassIoData */
656 /*============================================================================
657  * ASIT Decode Processing
658  *     This function performs the decode processing and does the following based
659  *     on the ASIT events:
660  *     - initialize the decode processing if it is the first time
661  *     - if there is ASIT INPUT DATA event (ASIT_EVTMSK_INPDATA):
662  *        - mark I/O PHY transfer completion
663  *        - run auto-detection via I/O DATA in asitInputDataProcess
664  *        - check auto-detection status and take corresponding actions if SYNC
665  *          is lost.
666  *        - start next I/O PHY transfer
667  *     - map ASIT events to decoding messages
668  *     - invoke decDecodeFsm() and pass the mapped decoding messages
669  *     - if there is ASIT DECODE ACK event (ASIT_EVTMSK_DECACK)
670  *        - mark I/O DATA read completion
671  *     - error handling
672 ============================================================================*/
673 Int asitDecodeProcessing(const PAF_ASIT_Params *pP,
674                          const PAF_ASIT_Patchs *pQ,
675                          PAF_ASIT_Config       *pAsitCfg,
676                          UInt asitEvents)
678     Int asitErr, decErr;
679     PAF_AST_IoInp *pInp;                  // I/O components for input
680     AspMsgMaster_Handle hAspMsgMaster;    // ASIT message master handle
681     asipDecProc_t *pDec;
682     ioDataAutoDetStat_t autoDetStatus;
683     Int zMD;
684     UInt decMsg;
685     Int status;
687     zMD = pAsitCfg->pAstCfg->masterDec;         // pointer to AST common (shared) configuration
688     pInp = &pAsitCfg->pIoInp[zMD];              // pointer to input I/O components
689     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get ASIT message master handle
690     pDec = &pAsitCfg->inpDec;
692     // Initialization for decode processing when this function is called the first time
693 #ifndef DEBUG_SKIP_DECODING
694     if(!pDec->initDone) {
695         // Initialize decoder
696         decDecodeInit(pP, pAsitCfg, pInp->sourceSelect);
698         pDec->initDone = TRUE;
699     }
700 #endif
702     // Process input data if this is a data ready message
703     if(asitEvents & ASIT_EVTMSK_INPDATA) {
704         TRACE_TERSE0("asitDecodeProcessing: process input data.");
706         // Marks I/O PHY transfer and I/O BUFF write complete
707         asitPhyTransferComplete(pInp);
709         // Process input data - either search SYNC for PCM or check SYNC for bitstream
710         asitErr = asitInputDataProcess(pInp, &autoDetStatus);
712         if(asitErr == ASIT_NO_ERR) {
713             ioDataReadComplete(pInp->hIoData);
715             // Check if SYNC is maintained or lost (stream stops or format changes)
716             if(autoDetStatus.syncState == IODATA_SYNC_NONE) {
717                 // SYNC lost: change I/O PHY transfer size to default for auto-detection
718                 //asitErr = asitRecfgPhyXfer(pInp, INPUT_FRAME_SIZE_DEF);
719                 //if(asitErr != ASIT_NO_ERR) {
720                 //    return asitErr;
721                 //}
723                 // Inform decoder to complete the decoding of previous frame - is this good?
724                 pInp->sourceSelect = PAF_SOURCE_NONE;
725                 pInp->numFrameReceived = 0;    // for debugging
726                 TRACE_TERSE0("asitDecodeProcessing: SYNC lost.");
728 #ifdef DEBUG_SKIP_DECODING
729                 asitErr = ASIT_ERR_DECODE_QUIT;
730 #endif
731             }
732             else {
733                 pInp->numFrameReceived += 1;    // for debugging
735                 // Communicate input stream information to decoder through input
736                 // buffer configuration -- this was moved inside decDecodeFsm
737                 //asitUpdateInpBufConfig(pAsitCfg->pAstCfg, pInp);
739                 // Start next transfer
740                 asitPhyTransferStart(pInp);
741             }
743             // Start next transfer
744             //asitPhyTransferStart(pInp);
746 #ifdef DEBUG_SKIP_DECODING
747             return asitErr;
748 #endif
749         }
750         else if(asitErr == ASIT_ERR_INPBUF_UNDERFLOW) {
751             TRACE_TERSE0("asitDecodeProcessing: Input buffer underflows.");
753             // When input buffer underflows, it is not an error but decoding needs
754             // to be skipped as there is not enough data in the buffer.
755             asitPhyTransferStart(pInp);
757             return asitErr;
758         }
759         else {
760             // Inform decoder to complete the decoding of previous frame - is this good?
761             pInp->sourceSelect = PAF_SOURCE_NONE;
762             pInp->numFrameReceived = 0;    // for debugging
763             TRACE_TERSE1("asitDecodeProcessing: asitInputDataProcess error: %d", asitErr);
765 #ifdef DEBUG_SKIP_DECODING
766             return ASIT_ERR_DECODE_QUIT;
767 #endif
768         }
769     } /* ASIT_EVTMSK_INPDATA */
770 #ifdef DEBUG_SKIP_DECODING
771     else {
772         TRACE_TERSE0("asitDecodeProcessing: events error.");
773         return ASIT_ERR_EVENTS;
774     }
775 #endif
777 #ifndef DEBUG_SKIP_DECODING
778     // Map ASIT events to decode messages
779     decMsg = asitEventsToDecMsg(asitEvents);
781     // Pass messages (corresponding to events) to decode FSM
782     decErr = decDecodeFsm(pP, pQ, pAsitCfg, pInp->sourceSelect, decMsg);
784     // Mark I/O DATA read complete if decoder indicates decoding is done.
785     if((asitEvents & ASIT_EVTMSK_DECACK)) {  // DECACK -> decoding done
786         //ioDataReadComplete(pInp->hIoData);
787     }
789     if(decErr != DEC_NO_ERR) {
790         TRACE_VERBOSE0("TaskAsip: send DEC_EXIT message to slave decoder.");
792         // Send dec exit message to slave decoder
793         status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_EXIT, NULL);
794         if (status != ASP_MSG_NO_ERR)
795         {
796             TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
797             SW_BREAKPOINT;
798         }
799         status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_EXIT_DONE, NULL, TRUE);
800         if (status != ASP_MSG_NO_ERR) 
801         {
802             TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
803             SW_BREAKPOINT;
804         }
806         return ASIT_ERR_DECODE_QUIT;  // This is not necessarily an error
807     }
808     else {
809         return ASIT_NO_ERR;
810     }
811 #endif
812 }  /* asitDecodeProcessing */
815 /*============================================================================
816  * ASIT Input Data Processing:
817  *    - invoke ioDataProcess() to inspect input data for
818  *       - initial auto-detection,  or
819  *       - background scanning for PCM data, or
820  *       - SYNC check for bitstream
821  *    - return auto-detection status (SYNC detected, SYNC loss, etc)
822 ============================================================================*/
823 Int asitInputDataProcess(PAF_AST_IoInp *pInp, ioDataAutoDetStat_t *pAutoDetStats)
825     Int ioDataErr, retVal;
826     ioDataCtl_t ioDataCtl;
828     // Perform auto-detection inside I/O DATA component
829     ioDataErr = ioDataProcess(pInp->hIoData);
831     if(ioDataErr == IODATA_NO_ERR) {
832         // Normal operation - check auto-detection status
833         ioDataCtl.code = IODATA_CTL_GET_AUTODET_STATUS;
834         ioDataControl(pInp->hIoData, &ioDataCtl);
836         *pAutoDetStats = ioDataCtl.param.autoDetStats;
838         retVal = ASIT_NO_ERR;
839     }
840     else if(ioDataErr == IODATA_ERR_IOBUF_UNDERFLOW) {
841         // Input buffer underflows - there is no enough data to process.
842         // This is not error and no action is needed.
843         pInp->numUnderflow += 1; // debug
845         retVal = ASIT_ERR_INPBUF_UNDERFLOW;
846     }
847     else {
848         // Something is wrong: print error log and return
849         //printf("IODATA processing error!\n");
850         retVal = ASIT_ERR_INPDATA_PROC;
851     }
853     return retVal;
854 } /* asitInputDataProcess */
856 /*============================================================================
857  * Mapping ASIT Events to Decoding Messages
858 ============================================================================*/
859 UInt asitEventsToDecMsg(UInt asitEvents)
861     UInt decMsg = 0;
863     if (asitEvents & ASIT_EVTMSK_INPDATA) {
864         // Input data event
865         decMsg |= DEC_MSGMSK_INPDATA;
866     }
868     // temp, simulation
869     //if(asitEvents & ASIT_EVTMSK_INFOACK) {
870     //    decMsg |= DEC_MSGMSK_INFOACK;
871     //}
873     // temp, simulation
874     //if(asitEvents & ASIT_EVTMSK_DECACK) {
875     //    decMsg |= DEC_MSGMSK_DECACK;
876     //}
878     if (asitEvents & ASIT_EVTMSK_RXACK)
879     {
880        // Receive acknowledge message event
881         decMsg |= DEC_MSGMSK_RXACK;
882     }
883     
884     return decMsg;
885 } /* asitEventsToDecMsg */
887 /*===========================================================================
888  * Initialize I/O components for input processing
889 ============================================================================*/
890 int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
892     ioBuffParams_t ioBuffParams;
893     ioPhyParams_t  ioPhyParams;
894     ioDataParam_t  ioDataCfg;
895     ioPhyCtl_t     ioPhyCtl;
897     //pInpIo->phyXferSize = INPUT_FRAME_SIZE_DEF;
898     pInpIo->phyXferSize = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF * WORD_SIZE_BITSTREAM;
900     if(pInpIo->firstTimeInit) {
901         TRACE_VERBOSE0("Initialize I/O BUFF and I/O PHY.");
902         ioBuffParams.base         = pInpBuf->inpBufConfig.base.pVoid;
903         ioBuffParams.size         = pInpBuf->inpBufConfig.allocation / STRIDE_WORST_CASE
904                                                                      * STRIDE_WORST_CASE;
905         ioBuffParams.sync         = IOBUFF_WRITE_SYNC;
906         ioBuffParams.nominalDelay = INPUT_FRAME_SIZE_DEF;
907         if(ioBuffInit(pInpIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) {
908             return (ASIT_ERR_IOBUFF_INIT);   // to remove magic number
909         }
911         ioPhyParams.ioBuffHandle    = pInpIo->hIoBuff;
912         ioPhyParams.xferFrameSize   = pInpIo->phyXferSize;
913         ioPhyParams.mcaspChanHandle = pInpIo->hMcaspChan;
914         ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_WRITE;
915         if(ioPhyInit(pInpIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) {
916             return (ASIT_ERR_IOPYH_INIT);   // to remove magic number
917         }
919         pInpIo->numPrimeXfers = NUM_PRIME_XFERS;
920     }
922     /* Reinitialize I/O DATA every time when ASIT restarts */
923     TRACE_VERBOSE0("Initialize I/O DATA.");
924     ioDataCfg.ioBuffHandle         = pInpIo->hIoBuff;
925     ioDataCfg.unknownSourceTimeOut = pInpBuf->inpBufConfig.pBufStatus->unknownTimeout;
926     ioDataCfg.frameLengthsIEC      = (uint_least16_t *)&iecFrameLength[0];
927     ioDataCfg.frameLengthPCM       = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF;
928     ioDataCfg.frameLengthDef       = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF;
929     ioDataCfg.ibMode               = pInpBuf->inpBufConfig.pBufStatus->mode;
930     ioDataCfg.zeroRunRestart       = pInpBuf->inpBufConfig.pBufStatus->zeroRunRestart;
931     ioDataCfg.zeroRunTrigger       = pInpBuf->inpBufConfig.pBufStatus->zeroRunTrigger;
933     if(ioDataInit(pInpIo->hIoData, &ioDataCfg) != IODATA_NO_ERR) {
934         return (ASIT_ERR_IODATA_INIT);   // to remove magic number
935     }
937     if(pInpIo->firstTimeInit) {
938         /* Initialize I/O BUFF and I/O PHY only when input interface changes. */
939         TRACE_VERBOSE0("Prime I/O PHY.");
941         // Start I/O physical layer by priming McASP LLD for input
942         asitIoPhyPrime(pInpIo);
944         pInpIo->firstTimeInit = FALSE;
945     }
946     else {
947         // Reconfigure I/O PHY transfer size
948         ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
949         ioPhyCtl.params.xferFrameSize = pInpIo->phyXferSize;
950         ioPhyControl(pInpIo->hIoPhy, &ioPhyCtl);
951 #if 0
952         // If previous stream before reset was PCM, reconfigure McASP LLD to receive 16-bit packed bits
953         if(!pInpIo->swapData) {
954             Int mcaspErr;
955             mcaspErr = mcaspRecfgWordWidth(pInpIo->hMcaspChan, Mcasp_WordLength_16);
956             if(mcaspErr != Aud_EOK) {
957                 return ASIT_ERR_MCASP_CFG;
958             }
960             // Start swapping data
961             pInpIo->swapData = TRUE;
962             TRACE_VERBOSE0("Reconfigure McASP word length and start swapping data.");
963         }
964 #endif
965         // Start PHY transfer
966         TRACE_VERBOSE0("Start I/O PHY transfer.");
967         asitPhyTransferStart(pInpIo);
968     }
970     return 0;
971 } /* asitIoCompsInit */
973 /*======================================================================================
974  *  This function initializes ASIT processing
975  *====================================================================================*/
976 void asitProcInit(PAF_AST_IoInp  *pInp, asipDecProc_t *pDec)
978 //    pInp->swapData = TRUE;
979     pInp->pcmSwitchHangOver = INPUT_SWITCH_HANGOVER;
980     pDec->initDone = FALSE;
981     pInp->numFrameReceived = 0;
984 /*======================================================================================
985  *  I/O physical layer prime operation required by McASP LLD
986  *====================================================================================*/
987 void asitIoPhyPrime(PAF_AST_IoInp *pInp)
989     Int32        count;
991     for(count = 0; count < pInp->numPrimeXfers; count++)
992     {
993         ioPhyXferSubmit(pInp->hIoPhy);
994 #ifdef ASIP_DEBUG
995         //pInp->numXferStart++;
996 #endif
997     }
998 } /* asitIoPhyPrime */
1001 /*======================================================================================
1002  *  This function marks the I/O PHY transfer as complete
1003  *====================================================================================*/
1004 void asitPhyTransferComplete(PAF_AST_IoInp * pInpIo)
1006     // Mark underlining I/O BUFF write complete and swap data if needed
1007     ioPhyXferComplete(pInpIo->hIoPhy, pInpIo->swapData);
1008 } /* asitPhyTransferComplete */
1010 #if 0
1011 Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize)
1013     ioPhyCtl_t ioPhyCtl;
1014     Int mcaspErr;
1016     ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
1017     ioPhyCtl.params.xferFrameSize = xferSize;
1018     ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
1020     pInp->phyXferSize  = ioPhyCtl.params.xferFrameSize;
1022     if(!pInp->swapData) {
1023         // If it was PCM, reconfigure McASP LLD to receive 16-bit packed bits
1024         mcaspErr = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_16);
1025         if(mcaspErr != Aud_EOK) {
1026             return ASIT_ERR_MCASP_CFG;
1027         }
1029         // Start swapping data
1030         pInp->swapData = TRUE;
1031     }
1033     return ASIT_NO_ERR;
1035 } /* asitRecfgPhyXfer */
1036 #endif
1038 /*======================================================================================
1039  *  McASP LLD call back function
1040  *====================================================================================*/
1041 void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
1043     /* post semaphore */
1044     if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
1045         //Semaphore_post(asipSemRx);
1046         Event_post(gAsitEvtHandle, ASIT_EVTMSK_INPDATA);
1047     } else {
1048         ;    // intermediate packet due to buffer wrapping around
1049     }
1052 /*======================================================================================
1053  *  This function checks if McASP Rx for input overruns
1054  *====================================================================================*/
1055 int asipCheckMcaspRxOverrun(Ptr mcaspChanHandle)
1057     Mcasp_errCbStatus mcaspErrStat;
1059     mcaspControlChan(mcaspChanHandle, Mcasp_IOCTL_CHAN_QUERY_ERROR_STATS, &mcaspErrStat);
1061     return (mcaspErrStat.isRcvOvrRunOrTxUndRunErr);
1064 #if 0
1065 /*======================================================================================
1066  *  This function restarts McASP LLD channel for input
1067  *====================================================================================*/
1068 void asipMcaspRxRestart(PAF_AST_IoInp *pInpIo)
1070     mcaspRxReset();
1071     mcaspRxCreate();
1073 #endif
1075 /*======================================================================================
1076  *  This function starts an I/O PHY transfer
1077  *====================================================================================*/
1078 void asitPhyTransferStart(PAF_AST_IoInp *pInpIo)
1080     Int ioPhyErr;
1082     if(asipCheckMcaspRxOverrun(pInpIo->hMcaspChan)) {
1083 #ifdef ASIP_DEBUG
1084         pInpIo->numInputOverrun++;
1085 #endif
1086         //asipMcaspRxRestart(pInpIo);
1087         System_abort("\nMcASP for input overruns! %d!\n");
1088     }
1089     else {
1090         ioPhyErr = ioPhyXferSubmit(pInpIo->hIoPhy);
1091         //if(ioPhyXferSubmit(pInpIo->hIoPhy)==IOPHY_ERR_BUFF_OVERFLOW) {
1092         if(ioPhyErr!=IOPHY_NOERR){
1093             printf("\n I/O PHY ioPhyXferSubmit fails with error %d!\n", ioPhyErr);
1094             // Input buffer overflows!
1095             //printf("\nInput buffer overflows!\n");
1096             exit(0);
1097         }
1098         else {
1099             // Input buffer operates normally
1100             ;
1101         }
1102 #ifdef ASIP_DEBUG
1103         //pInpIo->numXferStart++;
1104 #endif
1105     }
1108 Int d10Initialized = 0;
1109 //extern Aud_STATUS mcaspAudioConfig(void);
1110 extern void McaspDevice_init(void);
1112 /*======================================================================================
1113  *  This function initializes HW interface and selects the right device for input
1114  *====================================================================================*/
1115 Int asitSelectDevices(
1116     const PAF_ASIT_Patchs *pQ, 
1117     PAF_AST_Config *pAstCfg, 
1118     PAF_AST_IoInp *pInp
1121     Aud_STATUS status;
1122     const PAF_SIO_Params *pInPrms;
1123     mcaspLLDconfig *pLldCfg;
1124     mcaspLLDconfig *pReqLldCfg;
1125     Ptr mcaspChanHandle;
1126     Int zMD;
1127     Int interface;
1128     const PAF_SIO_Params *pD10Params;
1130     zMD = pAstCfg->masterDec;
1131     
1132     interface = pAstCfg->xInp[zMD].inpBufStatus.sioSelect; // obtain SIO select for input
1133     
1134     if (interface >= 0)
1135     {
1136         // Positive value for interface: new Input SIO update request has been received via alpha command.
1137         // Negative value for interface: no new Input SIO update request has been received,
1138         //                               previous requests have been processed.
1139         
1140         // check for valid index into device array
1141         if (interface >= pQ->devinp->n)    // DEVINP_N
1142         {
1143             interface = 0; // treat as device InNone
1144         }
1145         
1146         //
1147         // Deactivate currently active interface
1148         //
1149         if (pInp->hMcaspChan != NULL)   // non-NULL McASP LLD channel handle indicates there's an active interface
1150         {
1151             // Delete McASP LLD channel
1152             status = mcaspDeleteChan(pInp->hMcaspChan);
1153             if (status != Aud_EOK)
1154             {
1155                 Log_info0("asitSelectDevices(): McASP channel deletion failed!\n");
1156                 return ASIP_ERR_MCASP_CFG;
1157             }
1158             
1159             pInp->hMcaspChan = NULL;        // reset active McASP LLD handle
1160             if (pInp->pRxParams != NULL)    // sanity check, pInp->pRxParams should be non NULL if pInp->hMcaspChan is non NULL
1161             {
1162                 pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
1163                 pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig; // get pointer to active McASP LLD configuration
1164                 pLldCfg->hMcaspChan = NULL; // reset McASP LLD handle for active McASP LLD configuration
1165                 pInp->pRxParams = NULL;     // reset pointer to active D10 parameters
1166             }
1167             else 
1168             {
1169                 // This is a programming error
1170                 SW_BREAKPOINT;  // debug
1171             }
1172         }
1174         //
1175         // Activate requested interface
1176         //
1177         pD10Params = (const PAF_SIO_Params *)pQ->devinp->x[interface];  // get D10 parameters for selected interface
1178         if (pD10Params != NULL)
1179         {
1180             //
1181             // Requested device is other than InNone
1182             //
1183             
1184             //if (!d10Initialized)
1185             //{
1186                 // FL: probably no harm in calling this for every new i/f request.
1187                 //     However, it can probably be moved to main() or sys init task.
1188                 // Initialize McASP HW details
1189                 McaspDevice_init();
1190                 
1191                 // Initialize Rx hardware
1192                 D10_init((void *)pD10Params);
1193                 
1194             //    d10Initialized=1;
1195             //}
1196             
1197             if (!d10Initialized)
1198             {
1199                 d10Initialized=1; // global flag indicating D10 init completed
1200             }
1202             pReqLldCfg = (mcaspLLDconfig *)pD10Params->sio.pConfig;
1203             if (pReqLldCfg->hMcaspChan == NULL)
1204             {
1205                 // Create McASP LLD channel
1206                 mcaspChanHandle = NULL;
1207                 status = mcasplldChanCreate(pReqLldCfg, &mcaspChanHandle);
1208                 if (status != Aud_EOK) 
1209                 {
1210                     Log_info0("asitSelectDevices(): McASP channel creation failed!\n");
1211                     return ASIP_ERR_MCASP_CFG;
1212                 }
1213                 
1214                 pReqLldCfg->hMcaspChan = mcaspChanHandle;   // set McASP LLD handle for requested McASP LLD configuration
1215                 pInp->pRxParams = (const void *)pD10Params; // set pointer to active D10 parameters
1216                 pInp->hMcaspChan = pReqLldCfg->hMcaspChan;  // set active McASP LLD handle
1217                 
1218                 // configure stride according to selected McASP LLD configuration
1219                 pInp->stride = pReqLldCfg->mcaspChanParams->noOfSerRequested * 
1220                     pReqLldCfg->mcaspChanParams->noOfChannels;
1221             }
1222         }
1223         else
1224         {
1225             //
1226             // Requested device is InNone
1227             //
1228             pInp->hMcaspChan = NULL;    // reset active McASP LLD handle
1229             pInp->pRxParams = NULL;     // reset pointer to active D10 parameters
1230         }
1231         
1232         // indicate SIO update request processed
1233         pAstCfg->xInp[zMD].inpBufStatus.sioSelect = interface | 0x80;
1234     }
1236     if (pInp->hMcaspChan != NULL)       // non NULL indicates there's an active interface
1237     {
1238         if (pInp->pRxParams != NULL)    // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
1239         {
1240             pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
1241             pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig;   // get currently active McASP LLD configuration
1242             if (pLldCfg != NULL)        // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
1243             {
1244                 // Configure McASP to receive 16/32-bit data according to default configuration
1245                 mcaspRecfgWordWidth(pInp->hMcaspChan, pLldCfg->mcaspChanParams->wordWidth);
1246                 
1247                 // Set flag to swap HDMI data if it is 4xI2S and word length is 16
1248                 if ((pLldCfg->mcaspChanParams->wordWidth == Mcasp_WordLength_16) &&
1249                     (pLldCfg->mcaspChanParams->noOfSerRequested == 4)) 
1250                 {
1251                     pInp->swapData = TRUE;
1252                 }
1253                 else 
1254                 {
1255                     pInp->swapData = FALSE;
1256                 }
1257             }
1258             else
1259             {
1260                 // This is a programming error
1261                 SW_BREAKPOINT;  // debug
1262             }
1264         }
1265         else
1266         {
1267             // This is a programming error
1268             SW_BREAKPOINT;  // debug
1269         }
1270     }
1271     
1272     return ASIT_NO_ERR;
1273 }  /* asitSelectDevices */
1275 /*======================================================================================
1276  *  This function updates input status
1277  *====================================================================================*/
1278 Int asitUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
1279                           PAF_InpBufConfig *pInpBuf)
1281     Int asipErrno;
1283     PAF_SIO_InputStatus inputStatus;
1285     // initialize all values to unknown so that device specific
1286     //   driver layer need only fill in those entries that it is aware of.
1287     //   This allows extensibility of the structure without requiring users
1288     //   to re-code.
1289     inputStatus.lock = 0;
1290     inputStatus.sampleRateData = PAF_SAMPLERATE_UNKNOWN;
1291     inputStatus.sampleRateMeasured = PAF_SAMPLERATE_UNKNOWN;
1292     inputStatus.nonaudio = PAF_IEC_AUDIOMODE_UNKNOWN;
1293     inputStatus.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
1295     //more configuration is needed to abstract out D10
1296     asipErrno = D10_RxControl(pRxParams,
1297                           (Uns)PAF_SIO_CONTROL_GET_INPUT_STATUS,
1298                           (Arg) &inputStatus);
1299     if (asipErrno) {
1300         return asipErrno;
1301     }
1302     pStatus->sampleRateData = inputStatus.sampleRateData;
1303     pStatus->sampleRateMeasured = inputStatus.sampleRateMeasured;
1304     pStatus->nonaudio = inputStatus.nonaudio;
1305     pStatus->emphasisData = inputStatus.emphasis;
1307     // if MSB of override clear then use as reported lock
1308     // if = 0x80 then use default [0x81]
1309     // if = 0x81 then use measured (from device)
1310     // others not defined or implemented
1311     if ((pStatus->lockOverride & (XDAS_Int8)0x80) == 0)
1312         pStatus->lock = pStatus->lockOverride;
1313     else if (pStatus->lockOverride == (XDAS_Int8)0x80)
1314         pStatus->lock = inputStatus.lock;
1315     else if (pStatus->lockOverride == (XDAS_Int8)0x81)
1316         pStatus->lock = inputStatus.lock;
1318     // if MSB of override clear then use it as sample rate for system,
1319     // if = 0x80 then use default [0x82]
1320     // if = 0x81 then use data
1321     // if = 0x82 then use measured
1322     // others not defined or implemented
1323     if ((pStatus->sampleRateOverride & (XDAS_Int8)0x80) == 0)
1324         pStatus->sampleRateStatus = pStatus->sampleRateOverride;
1325     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x80)
1326         pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
1327     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x81)
1328         pStatus->sampleRateStatus = pStatus->sampleRateData;
1329     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x82)
1330         pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
1332     // Update emphasis status:
1333     if ((pStatus->emphasisOverride & (XDAS_Int8)0x80) == 0) {
1334         if (pStatus->emphasisData == PAF_IEC_PREEMPHASIS_YES)
1335             pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
1336         else
1337             pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
1338     }
1339     else if (pStatus->emphasisOverride ==
1340              (XDAS_Int8 )(0x80+PAF_IEC_PREEMPHASIS_YES))
1341         pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
1342     else /* IBEmphasisOverrideNo or other */
1343         pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
1345     // Update precision control
1346     pInpBuf->precision = pStatus->precisionInput =
1347         pStatus->precisionOverride < 0
1348         ? pStatus->precisionDefault
1349         : pStatus->precisionOverride > 0
1350         ? pStatus->precisionOverride
1351         : pStatus->precisionDetect > 0
1352         ? pStatus->precisionDetect
1353         : pStatus->precisionDefault;
1355     return 0;
1359 /*==============================================================================
1360  * This function updates input buffer config based on frame information provided
1361  * by I/O DATA.
1362  ==============================================================================*/
1363 void asitUpdateInpBufConfig(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp)
1365     PAF_InpBufConfig *pBufConfig;
1366     ioDataCtl_t ioDataCtl;
1368     /* Get information for reading input data */
1369     ioDataCtl.code = IODATA_CTL_GET_INPBUFFINFO;
1370     ioDataControl(pInp->hIoData, &ioDataCtl);
1372     if(ioDataCtl.param.dataReadInfo.frameSize != pInp->phyXferSize) {
1373         // Fatal error!
1374         TRACE_VERBOSE0("TaskAsip: error in updating I/O");
1375         SW_BREAKPOINT;
1376     }
1378     pBufConfig = &(pAstCfg->xInp[pAstCfg->masterDec].inpBufConfig);
1380     //JXTODO: do we need to gate here?
1381     //key = GateMP_enter(gateHandle);
1383     pBufConfig->base.pVoid   = ioDataCtl.param.dataReadInfo.buffBase;
1384     pBufConfig->sizeofBuffer = ioDataCtl.param.dataReadInfo.buffSize;
1385     pBufConfig->pntr.pSmInt  = ioDataCtl.param.dataReadInfo.startAddress;
1387     // Leave the gate
1388     //GateMP_leave(gateHandle, key);
1390     TRACE_TERSE2("Frame start address: 0x%x., preamble: 0x%x",
1391                  (UInt)ioDataCtl.param.dataReadInfo.startAddress,
1392                  *(UInt *)ioDataCtl.param.dataReadInfo.startAddress);
1395 /*==============================================================================
1396  * Decide source after SYNC is found, i.e. either bitstream preamble is detected
1397  * or it times out to PCM.
1398  ==============================================================================*/
1399 Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp, 
1400                      ioDataAutoDetStat_t *autoDetStatus)
1402     Int sourceConfig, sourceSelect, sourceProgram;
1403     Int zMD;
1404     char asipMsgBuf[ASP_MSG_BUF_LEN];
1405     Int status;
1407     // Get the configured source
1408     zMD = pAstCfg->masterDec;
1409     sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1410                                           GATEMP_INDEX_DEC);
1412     if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
1413         if (sourceConfig == PAF_SOURCE_DSD1 || sourceConfig == PAF_SOURCE_DSD2 ||
1414             sourceConfig == PAF_SOURCE_DSD3) {
1415             sourceProgram = sourceConfig;
1416         }
1417         else {
1418             sourceProgram = PAF_SOURCE_PCM;
1419         }
1420     }
1422     if(autoDetStatus->syncState == IODATA_SYNC_BITSTREAM) {
1423         uint_least16_t pc = autoDetStatus->bitStreamInfo & SYNC_PC_MASK; //0x001F
1424         sourceProgram = IECpafSource[pc];
1425     }
1427     // write the decided source program to memory
1428     sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), sourceProgram,
1429                        GATEMP_INDEX_DEC);
1431     // now that we have some input classification, and possibly an outstanding
1432     // input frame, we determine whether or not to call decodeProcessing and with
1433     // what decAlg.
1434     sourceSelect = PAF_SOURCE_NONE;
1436     switch (sourceConfig)
1437     {
1438         // If autodetecting, decoding everything, and input is something
1439         // (i.e. bitstream or PCM) then decode.
1440         case PAF_SOURCE_AUTO:
1441             if (sourceProgram >= PAF_SOURCE_PCM)  {
1442                 sourceSelect = sourceProgram; // use whatever from autodet
1443             }
1444             break;
1446         // If autodetecting, decoding only PCM, and input is PCM then decode.
1447         case PAF_SOURCE_PCMAUTO:
1448             if (sourceProgram == PAF_SOURCE_PCM) {
1449                 // only expect autodet to give PAF_SOURCE_PCM, otherwise set to NONE
1450                 sourceSelect = sourceProgram;
1451             }
1452             break;
1454         // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
1455         case PAF_SOURCE_BITSTREAM:
1456             if (sourceProgram >= PAF_SOURCE_AC3) {
1457                 sourceSelect = sourceProgram;
1458             }
1459             break;
1461         // If autodetecting, decoding only DTS, and input is DTS then decode.
1462         case PAF_SOURCE_DTSALL:
1463             switch (sourceProgram)
1464             {
1465                 case PAF_SOURCE_DTS11:
1466                 case PAF_SOURCE_DTS12:
1467                 case PAF_SOURCE_DTS13:
1468                 case PAF_SOURCE_DTS14:
1469                 case PAF_SOURCE_DTS16:
1470                 case PAF_SOURCE_DTSHD:
1471                     sourceSelect = sourceProgram;
1472                     break;
1473             }
1474             break;
1476         // All others, e.g., force modes, fall through to here.
1477         // If user made specific selection then program must match select.
1478         // (NB: this compare relies on ordering of PAF_SOURCE)
1479         default:
1480             sourceSelect = sourceConfig;
1481             if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N)) {
1482                 if (sourceProgram != sourceSelect) {
1483                     sourceSelect = PAF_SOURCE_NONE;
1484                 }
1485             }
1486             break;
1487     }
1489     // if we didn't find any matches then skip
1490     if (sourceSelect == PAF_SOURCE_NONE) {
1491         TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
1492         return ASIT_ERR_NO_MATCHING_SOURCE;
1493     }
1495 #ifndef DEBUG_SKIP_DECODING
1496     // send source select message to slave
1497     *(Int32 *)&asipMsgBuf[0] = sourceSelect;
1498     status = AspMsgSnd(gPAF_ASIT_config.hAspMsgMaster, ASP_SLAVE_DEC_SOURCE_SELECT, asipMsgBuf);
1499     if (status != ASP_MSG_NO_ERR) 
1500     {
1501         TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
1502         SW_BREAKPOINT;
1503     }
1504     status = AspMsgRcvAck(gPAF_ASIT_config.hAspMsgMaster, ASP_MASTER_DEC_SOURCE_SELECT_DONE, NULL, TRUE);
1505     if (status != ASP_MSG_NO_ERR)
1506     {
1507         TRACE_VERBOSE0("TaskAsip: error in receiving SOURCE_SELECT ack message");
1508         SW_BREAKPOINT;
1509     }
1510 #endif
1512     pInp->sourceSelect  = sourceSelect;
1513     pInp->sourceProgram = sourceProgram;
1515     return ASIT_NO_ERR;
1516 } /* asitDecideSource */
1518 /*==============================================================================
1519  * After SYNC is found, i.e. either bitstream preamble is detected or it times
1520  * out to PCM, update input buffer config and I/o components accordingly.
1521  ==============================================================================*/
1522 Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
1523                       PAF_AST_IoInp  *pInp, ioDataAutoDetStat_t *autoDetStatus)
1525     Int sourceConfig;
1526     Int zMD, deliverZeros;
1527     int ioFrameLength, decFrameLength;
1528     PAF_InpBufConfig *pBufConfig;
1529     ioPhyCtl_t  ioPhyCtl;
1530     ioDataCtl_t ioDataCtl;
1532     zMD = pAstCfg->masterDec;
1533     pBufConfig = &pAstCfg->xInp[zMD].inpBufConfig;
1535     // Compute decoder frame length based on source selection
1536     decFrameLength = getFrameLengthSourceSel(pP, pInp->sourceSelect);
1538     pAstCfg->xDec[zMD].decodeControl.frameLength  = decFrameLength;
1539     pAstCfg->xDec[zMD].decodeInStruct.sampleCount = decFrameLength;
1540     pAstCfg->xDec[zMD].decodeControl.sampleRate   = PAF_SAMPLERATE_UNKNOWN;
1542     // Decide frame length for I/O DATA and I/O PHY
1543     if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
1544         // For PCM, I/O frame length is decode frame length multiplied by stride
1545         ioFrameLength = decFrameLength * pInp->stride;
1547         pBufConfig->sizeofElement = WORD_SIZE_PCM;
1548         pBufConfig->frameLength   = pBufConfig->lengthofData = ioFrameLength;
1550         // Configure I/O DATA PCM frame length
1551         ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
1552         ioDataCtl.param.frameLengthPcm = ioFrameLength;
1553         ioDataControl(pInp->hIoData, &ioDataCtl);
1555         // Change I/O PHY transfer size to PCM frame size
1556         pInp->phyXferSize = ioFrameLength*(WORD_SIZE_PCM);
1558         // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
1559         // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
1560         // Adjust delay and don't mark input buffer as read complete
1561         //ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
1563         // Stop swapping data
1564         //pInp->swapData = FALSE;
1565     }
1566     else {
1567         // For bitstream, I/O frame length is the frame length of the bitstream
1568         uint_least16_t pc = autoDetStatus->bitStreamInfo & SYNC_PC_MASK; //0x001F
1569         ioFrameLength = iecFrameLength[pc];
1571 /*
1572         if(   (pc == 0x11) && (DTSHDSubType == 3)
1573            && (PAF_ASP_sampleRateHzTable[pBufConfig->pBufStatus->sampleRateStatus][PAF_SAMPLERATEHZ_STD] <=48000.0))
1574             pDevExt->sourceProgram = PAF_SOURCE_DXP;    // LBR is 23
1576         if (pc == 1)
1577             pDevExt->elementSize = 4288;
1578         else if (pc == 0x11) {
1579             pDevExt->frameLength = (pDevExt->pIECFrameLength[pc] << DTSHDSubType);
1580             pDevExt->lengthofData = pDevExt->frameLength;
1581         }
1582 */
1584         pBufConfig->sizeofElement = WORD_SIZE_BITSTREAM;
1585         pBufConfig->frameLength   = ioFrameLength;
1586         pBufConfig->lengthofData  = ioFrameLength - IEC_HEADER_LENGTH;
1588         // Change I/O PHY transfer size to bitstream frame size
1589         pInp->phyXferSize = ioFrameLength*WORD_SIZE_BITSTREAM;
1590     }
1592     pBufConfig->stride = pInp->stride;   // common for PCM and bitstream
1594     // Configure I/O PHY transfer size
1595     ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
1596     ioPhyCtl.params.xferFrameSize = pInp->phyXferSize;
1597     ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
1599     // Decide if zeros should be delivered based on the configured source
1600     sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1601                                           GATEMP_INDEX_DEC);
1603     if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
1604         // Bitstream preamble is not found and it times out -> assume this is PCM
1605         deliverZeros = autoDetStatus->deliverZeros;
1606         if (sourceConfig == PAF_SOURCE_PCM || sourceConfig == PAF_SOURCE_DSD1 ||
1607             sourceConfig == PAF_SOURCE_DSD2 || sourceConfig == PAF_SOURCE_DSD3) {
1608             // set to one -- ensures that PCM decode calls made before data is
1609             // available will result in zero output.
1610             // (mostly needed for PA15 since, currently, all other frameworks
1611             // require a frame of data before the first decode call.
1612             deliverZeros = TRUE;  // override deliverZeros returned by ioDataControl
1613         }
1615         // update input buffer config structure
1616         pBufConfig->deliverZeros  = deliverZeros;
1617     }
1619     //JXTODO: decide what to do with hRxSio
1620     //temporary - does ARM use hRxSio or just check if it is not NULL?
1621     pAstCfg->xInp[zMD].hRxSio = pInp->hIoData;
1622     pAstCfg->xInp[zMD].pInpBuf = &(pAstCfg->xInp[zMD].inpBufConfig);
1624     return ASIT_NO_ERR;
1625 } /* asitUpdateIoComps */
1627 #if 0
1628 #ifndef IO_LOOPBACK_TEST
1629 #if OUTPUT_FRAME_LENGTH == INPUT_FRAME_LENGTH
1630 U8 pcmbuf[OUTPUT_FRAME_SIZE];
1631 #else
1632 #error Input frame length is not equal to output frame length!
1633 #endif
1635 Int rxDecodePcm(PAF_AST_IoInp  *pInp)
1637     ioDataCtl_t ioDataCtl;
1638     void *buffBase;
1639     void *dataStartAddress;
1640     size_t buffSize, frameSize, size1, size2;
1642     /* Get information for reading input data */
1643     ioDataCtl.code = IODATA_CTL_GET_INPBUFFINFO;
1644     ioDataControl(pInp->hIoData, &ioDataCtl);
1646     buffBase = ioDataCtl.param.dataReadInfo.buffBase;
1647     buffSize = ioDataCtl.param.dataReadInfo.buffSize;
1648     dataStartAddress = ioDataCtl.param.dataReadInfo.startAddress;
1649     frameSize        = ioDataCtl.param.dataReadInfo.frameSize;
1651     // Copy PCM data to output buffer
1652     if(((size_t)dataStartAddress+frameSize) <= ((size_t)buffBase+buffSize)) {
1653         // Input buffer doesn't wrap around
1654         Cache_inv(dataStartAddress, frameSize, Cache_Type_ALL, TRUE);
1655         memcpy((void *)&pcmbuf[0], dataStartAddress, frameSize);
1656     }
1657     else {
1658         // Input buffer wraps around
1659         size1 = (size_t)buffBase + buffSize - (size_t)dataStartAddress;
1660         size2 = frameSize - size1;
1661         Cache_inv(dataStartAddress, size1, Cache_Type_ALL, TRUE);
1662         memcpy((void *)&pcmbuf[0], dataStartAddress, size1);
1664         Cache_inv(buffBase, size2, Cache_Type_ALL, TRUE);
1665         memcpy((void *)&pcmbuf[size1], buffBase, size2);
1666     }
1669     return ASIT_NO_ERR;
1673 Int rxDecodePlayZero(PAF_AST_IoInp  *pInp)
1675     return ASIT_NO_ERR;
1677 #endif
1679 #endif
1681 Int asitEvtErrCheck(UInt actualEvents, UInt expectedEvents)
1683     TRACE_VERBOSE2("ASIT events error: actual events are: %d, expected events are: %d.",
1684                    actualEvents, expectedEvents);
1686     return ASIT_ERR_EVENTS;
1689 void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr)
1691     //UInt events;
1693     if(asitErr == ASIT_ERR_INPBUF_UNDERFLOW) {
1694         TRACE_VERBOSE0("ASIT error handling: input buffer underflows. No actions needed.");
1695     }
1697     if(asitErr == ASIT_ERR_DECODE_QUIT) {
1698         TRACE_VERBOSE0("ASIT error handling: DECODE_QUIT - clear INPDATA event.");
1699 #if 0
1700         // Pend on INPTDATA event that should have been posted before decoding quits.
1701         events = Event_pend(asitEvent, ASIT_EVTMSK_NONE, ASIT_EVTMSK_INPDATA,
1702                             BIOS_WAIT_FOREVER);
1704         // Marks I/O PHY transfer and I/O BUFF write complete
1705         asitPhyTransferComplete(&pAsitCfg->pIoInp[0]);
1707         // Keep I/O BUFF read pointers going
1708         asitBypassIoData(&pAsitCfg->pIoInp[0]);
1709 #endif
1710         pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
1711         pAsitCfg->pIoInp[0].numAsitRestart++;
1712         TRACE_VERBOSE0("ASIT error handling finished. Go to state ASIT_RESET.");
1713     }
1715     if(asitErr == ASIT_ERR_EVENTS) {
1716         pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
1717         pAsitCfg->pIoInp[0].numAsitRestart++;
1718         TRACE_VERBOSE0("ASIT error handling: events error. Go to state ASIT_RESET.");
1719     }
1721     return;
1722 }  /* asitErrorHandling */
1725 //////////////////////////////////////////////////////////////////////////////
1726 void asitPostInfoEvent()
1728     Event_post(gAsitEvtHandle, ASIT_EVTMSK_INFOACK);
1731 void asitPostDecEvent()
1733     Event_post(gAsitEvtHandle, ASIT_EVTMSK_DECACK);
1735 //////////////////////////////////////////////////////////////////////////////
1737 /* Nothing past this line */