]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamInpProcNewIO.c
f1cae7a354de1c32e3f6491b575d252033e8ac27
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProcNewIO.c
2 /*
3 Copyright (c) 2018, 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"
60 #include <pa_i13_evmk2g_io_a.h>
62 #define STRIDE_WORST_CASE 32  // 4-byte (32-bit) word, 2 slots, 4 serializers
64 //#define DEBUG_SKIP_DECODING
66 #define SYNC_PC_MASK         0x1F
67 #define SYNC_SUBTYPE_MASK    0x700
68 #define SYNC_SUBTYPE_SHIFT   8
69 #define SYNC_SUBTYPE_DTSHD   0x11
70 #define SYNC_DDP             0x15
71 #define SYNC_THD             0x16
73 #define IEC_HEADER_LENGTH    4
75 #define INPUT_SWITCH_HANGOVER 8
77 //table needed until PAF_SOURCE is reordered to match IEC numbering
78 const SmUns IECpafSource[23] =
79 {
80     PAF_SOURCE_UNKNOWN,  // 0: IEC NULL Type
81     PAF_SOURCE_AC3,      // 1: Comments on 1-15 match IEC 61937 part 2.
82     PAF_SOURCE_UNKNOWN,  // 2: IEC reserved
83     PAF_SOURCE_UNKNOWN,  // 3: IEC pause
84     PAF_SOURCE_UNKNOWN,  // 4: MPEG 1 layer 1
85     PAF_SOURCE_MP3,      // 5: MPEG layer 2 or 3
86     PAF_SOURCE_UNKNOWN,  // 6: MPEG 2 data with extension
87     PAF_SOURCE_AAC,      // 7: MPEG-2 AAC ADTS
88     PAF_SOURCE_UNKNOWN,  // 8: MPEG 2 layer 1 low sampling frequency
89     PAF_SOURCE_UNKNOWN,  // 9: MPEG 2 layer 2 or 3 low sampling frequency
90     PAF_SOURCE_UNKNOWN,  // 10: reserved
91     PAF_SOURCE_DTS,      // 11: DTS type 1 (11 bit: 512 sample repeat period)
92     PAF_SOURCE_DTS12,    // 12: DTS type 2 (12 bit: 1024 sample repeat period)
93     PAF_SOURCE_DTS13,    // 13: DTS type 3 (13 bit: 2048 sample repeat period)
94     PAF_SOURCE_DTS14,    // 14: ATRAC
95     PAF_SOURCE_UNKNOWN,  // 15: ATRAC 2/3
96     PAF_SOURCE_THD,      // 16
97     PAF_SOURCE_DTSHD,    // 17
98     PAF_SOURCE_WMA9PRO,  // 18
99     PAF_SOURCE_UNKNOWN,  // 19
100     PAF_SOURCE_UNKNOWN,  // 20
101     PAF_SOURCE_DDP,      // 21
102     PAF_SOURCE_THD,      // 22
103 };
105 /*
106  * Functions defined in other files and to be put into proper header files
107  */
108 extern Void taskAsipFxnInit(const PAF_ASIT_Params *pP,const PAF_ASIT_Patchs *pQ);
111 // avoid including sap_d10.h, which would cause symbol redefinition
112 // warning (MCASP_PFUNC_XXX)
113 //extern XDAS_Int32 D10_init(void * pD10Params);
114 extern XDAS_Int32 D10_initClkMux(void *pD10Params);
115 extern XDAS_Int32 D10_RxControl(const void *pD10RxParams,
116                                 XDAS_Int32 code, XDAS_Int32 arg);
117 extern Aud_STATUS D10_initHDMI(void);
119 /*
120  * Functions only used in this file
121  */
122 int asitPrepareProcessing();
123 int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo);
124 void asitProcInit(PAF_AST_IoInp  *pInp, asipDecProc_t *pDec);
125 void asitIoPhyPrime(PAF_AST_IoInp *pInpIo);
126 void asitPhyTransferComplete(PAF_AST_IoInp * pInpIo);
127 void asitPhyTransferStart(PAF_AST_IoInp *pInpIo);
128 Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize);
130 // Select Input devices
131 Int asitSelectDevices(
132     const PAF_ASIT_Patchs *pQ, 
133     PAF_AST_Config *pAstCfg, 
134     PAF_AST_IoInp *pInp
135 );
137 Int asitUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
138                           PAF_InpBufConfig *pInpBuf);
140 Int asitSourceDetection(const PAF_ASIT_Params *pP,
141                         const PAF_ASIT_Patchs *pQ,
142                         PAF_ASIT_Config       *pAsitCfg);
144 Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
145                      ioDataAutoDetStat_t *autoDetStatus);
146 Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
147                       PAF_AST_IoInp  *pInp, ioDataAutoDetStat_t *autoDetStatus);
148 Int asitBypassIoData(PAF_AST_IoInp *pInp);
149 Int asitPcmTransition(PAF_ASIT_Config *pAsitCfg);
151 void asitUpdateInpBufConfig(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp);
152 Int asitInputDataProcess(PAF_AST_IoInp *pInp, ioDataAutoDetStat_t *pAutoDetStats);
154 UInt asitEventsToDecMsg(UInt asitEvents);
155 void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr);
156 Int asitEvtErrCheck(UInt actualEvents, UInt expectedEvents);
158 void asitPostInfoEvent();
159 void asitPostDecEvent();
161 /*
162  * variables/structures to be put into proper global structures
163  */
164 extern PAF_ASIT_Config gPAF_ASIT_config;
165 extern const MdUns iecFrameLength[23];
166 extern Ptr hMcaspRxChan;
168 // temp for simulation
169 //#define ASIT_ALL_EVENTS (  ASIT_EVTMSK_INPDATA \
170 //                         + ASIT_EVTMSK_INFOACK \
171 //                         + ASIT_EVTMSK_DECACK )
172 #define ASIT_ALL_EVENTS (  ASIT_EVTMSK_INPDATA \
173                          + ASIT_EVTMSK_RXACK )
175 // temp for simulation
176 //#define ASIT_DEC_EVENTS (  ASIT_EVTMSK_INPDATA \
177 //                         + ASIT_EVTMSK_INFOACK \
178 //                         + ASIT_EVTMSK_DECACK )
179 #define ASIT_DEC_EVENTS (  ASIT_EVTMSK_INPDATA \
180                          + ASIT_EVTMSK_RXACK )
182 #define ASIP_DEBUG
184 #ifdef ASIP_DEBUG
185 /* define the following as global variables for easy debugging */
186 int asipLoopCount1, asipLoopCount2;
187 Int asipErrno;
188 Int inputReadyForProcessing;
190 // debug
191 #include "evmc66x_gpio_dbg.h"
192 #endif
194 Event_Handle gAsitEvtHandle;            // ASIT event handle
195 Int eventsOn;                           // flag indicating whether to process events
197 SyncEvent_Handle gAsitSyncEvtHandle;    // ASIT Sync event handle
199 /*
200  *  ======== taskAsipFxn ========
201  *  Audio Stream Input Processing task function
202  */
203 #ifndef PASDK_SIO_DEV
204 #ifndef IO_LOOPBACK_TEST
205 Void taskAsipFxn(                  // ASIP task function for new I/O
206 #else
207 Void taskAsipFxn_NewIO_Not_Used(   // not used for loopback test
208 #endif
209 #else
210 Void taskAsipFxn_NewIO_Not_USED(   // not used for SIO/DEV based I/O
211 #endif
212     const PAF_ASIT_Params *pP,
213         const PAF_ASIT_Patchs *pQ)
215     PAF_ASIT_Config *pAsitCfg;      /* ASIT configuration pointer */
216     PAF_AST_Config  *pAstCfg;       /* AST Common (shared) configuration pointer */
217     PAF_AST_IoInp *pInp;            /* Input I/O components */
218     Int as;                         /* Audio Stream Number (1, 2, etc.) */
219     Int z;                          /* input/encode/stream/decode/output counter */
220     Int zMI;
221 #ifndef ASIP_DEBUG
222 int asipLoopCount1, asipLoopCount2;
223 Int asipErrno;
224 Int inputReadyForProcessing;
225 #endif
226     Int asitErr;
227     UInt events;
228 //    Int eventsOn;
229 //    Error_Block  eb;
231     Log_info0("Enter taskAsipFxn()");
233     taskAsipFxnInit(pP, pQ);  // initialization of input task
234     
235     //
236     // Audio Stream Input Task Configuration (*pAsitCfg):
237     //
238     pAsitCfg = &gPAF_ASIT_config;       // initialize pointer to task configuration
239     pAstCfg  = pAsitCfg->pAstCfg;       // pointer to AST common (shared) configuration
241     /* Set Audio Stream Number (1, 2, etc.) */
242     as = pAstCfg->as;
244     //
245     // Determine decoder and stream indices associated with the master input
246     //
247     zMI  = pP->zone.master;
248     pInp = &pAsitCfg->pIoInp[zMI];        // pointer to input I/O components
250     for (z=STREAM1; z < STREAMN; z++)
251     {
252         TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
253     }
255     Log_info0("TaskAsip: Entering Main Loop.");
257     //
258     // Main processing loop
259     //
260     asipLoopCount1 = 0;
261     asipLoopCount2 = 0;
262     asitErr = ASIT_NO_ERR;
264     // The events_on flag will be removed if the RESTART state is changed to
265     // event-based scheduling instead of polling
266     eventsOn = FALSE;
268     for (;;)
269     {
270         asipLoopCount1++;
272         if(eventsOn) {
273             events = Event_pend(gAsitEvtHandle, ASIT_EVTMSK_NONE, ASIT_ALL_EVENTS,
274                                 BIOS_WAIT_FOREVER);
275         }
276         switch (pInp->asipState)
277         {
278         case ASIT_RESET:    // No events pending in this state
279             // Indicate decoder no decoding yet
280             pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
282             // 5 system tick, or 5 msec. Should remove this later when implementing
283             // event based scheduling.
284             Task_sleep(5);
286             inputReadyForProcessing = asitPrepareProcessing(pP, pQ, pAsitCfg, &asipErrno);
287             if (inputReadyForProcessing) {
288                 TRACE_VERBOSE0("TaskAsip: Input is ready. Initialize I/O components.");
289                 // Input is ready for processing, so we initialize the I/O components.
290                 // Note that the I/O components init. and I/O PHY prime are performed only
291                 // at the first time. This should be changed later - init. and prime
292                 // should be done whenever input interface has changed.
293                 asitErr = asitIoCompsInit(&pAstCfg->xInp[zMI], pInp);
295                 // Initialize ASIT processing
296                 asitProcInit(pInp, &pAsitCfg->inpDec);
297                 pInp->asipState = ASIT_SOURCE_DETECTION;
298                 eventsOn = TRUE;   // turn on events pending
299                 TRACE_VERBOSE0("TaskAsip: turn on events and go to source detection.");
300             }
301             break;
303         case ASIT_SOURCE_DETECTION:
304             // Source unknown - to detect & identify source
305             if(events == ASIT_EVTMSK_INPDATA) {  
306                 // Only this event is expected. If any other event, it's error.
307                 // Input data is ready - perform source detection.
308                 // New state will be decided inside the function
309                 asitErr = asitSourceDetection(pP, pQ, pAsitCfg);
311                 if(asitErr == ASIT_AUTODET_TIME_OUT) {
312                     // Should restart if new interface is selected.
313                     TRACE_VERBOSE0("TaskAsip: auto-detection time out.");
314                 }
315             }
316             else {
317                 //Error checking & debug
318                 asitErr = asitEvtErrCheck(events, ASIT_EVTMSK_INPDATA);
319             }
321             break;
323         case ASIT_PCM_TRANSITION:
324             // Source is PCM - transition to PCM decoding
325             if(events == ASIT_EVTMSK_INPDATA) {
326                 // Only this event is expected. If any other event, it's error.
327                 // Input data is ready - transition to PCM decoding
328                 // New state will be decided inside the function
329                 asitErr = asitPcmTransition(pAsitCfg);
330             }
331             else {
332                 //Error checking & debug
333                 asitErr = asitEvtErrCheck(events, ASIT_EVTMSK_INPDATA);
334             }
335             break;
337         case ASIT_DECODE_PROCESSING:
338             if(events & ASIT_DEC_EVENTS) {
339                 
340 #if 1 // debug 
341                 if (events & ASIT_EVTMSK_INPDATA)
342                 {
343                     // shows timing of Input (Rx McASP EDMA)
344                     // ADC B5
345                     {
346                         static Uint8 toggleState = 0;
347                         if (toggleState == 0)
348                             GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
349                         else
350                             GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
351                         toggleState = ~(toggleState);
352                     }
353                 }
354 #endif           
355                 
356                 // Decode processing for either PCM or bitstream
357                 // New state will be decided inside the function
358                 asitErr = asitDecodeProcessing(pP, pQ, pAsitCfg, events);
359             }
360             else {
361                 //Error checking & debug
362                 asitErr = asitEvtErrCheck(events, ASIT_DEC_EVENTS);
363             }
364             break;
366         default:
367             break;
368         }
370         if(asitErr) {
371             asitErrorHandling(pAsitCfg, asitErr);
373             if(pInp->asipState == ASIT_RESET) {
374                 eventsOn = FALSE;
375             }
377             asitErr = ASIT_NO_ERR;
378         }
380     }  // for (;;)
382 }  /* taskAsipFxn */
385 /*===========================================================================
386  * ASIT Processing Preparation
387  * Output:
388  *        - return        TRUE (input is ready) or FALSE (input is not ready)
389  *        - *asipErrno    Error number
390 ============================================================================*/
391 Int asitPrepareProcessing(const PAF_ASIT_Params *pP,
392                           const PAF_ASIT_Patchs *pQ,
393                           PAF_ASIT_Config       *pC,
394                           Int                   *asipErrno)
396     Int as, zMS, zMI, zMD;
397     Int sourceConfig, mode;
398     PAF_AST_Config  *pAstCfg;
399     PAF_AST_IoInp *pInp;            /* I/O components for input */
401     pAstCfg  = pC->pAstCfg;         // pointer to AST common (shared) configuration
402     as  = pAstCfg->as;
403     zMI = pP->zone.master;
404     zMD = pAstCfg->masterDec;
405     zMS = pAstCfg->masterStr;
406     pInp = pC->pIoInp;              // pointer to input I/O components
408     *asipErrno = 0;
410     // Select source and initialize physical layer / HW interface
411     *asipErrno = asitSelectDevices(pQ, pAstCfg, pInp);
412     if (*asipErrno) {
413         TRACE_TERSE2("asitSelectDevices returned asipErrno = 0x%04x at line %d. AS%d",
414                      *asipErrno, as+zMS);
415         return FALSE;    // Input is not ready for processing due to error
416     }
418     // If no master input selected then we don't know what may be at the input,
419     // so set to unknown and skip any remaining processing
420     if (!pInp[zMI].pRxParams) {
421         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
422                            (Int8)PAF_SOURCE_UNKNOWN, GATEMP_INDEX_DEC);
424         TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
425         return FALSE;    // No error, but input is not ready for processing
426     }
428     // If here then we have a valid input so query its status
429     *asipErrno = asitUpdateInputStatus(pInp[zMI].pRxParams,
430                                    &pAstCfg->xInp[zMI].inpBufStatus,
431                                    &pAstCfg->xInp[zMI].inpBufConfig);
432     if(*asipErrno) {
433         TRACE_VERBOSE1("TaskAsip: updateInputStatus returns 0x%x", *asipErrno);
434         return FALSE;   // Input is not ready for processing due to error
435     }
437     // If master decoder is not enabled, or the input is unlocked, then do nothing
438     mode = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
439                                   GATEMP_INDEX_DEC);
440     if (!mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
441     {
442         TRACE_VERBOSE0("TaskAsip: Not locked, continue");
443         return FALSE;  // No error, but input is not ready for processing
444     }
446     // Check selected source: sourceSelect is set by another task, AIP or AFP
447     sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
448                                           GATEMP_INDEX_DEC);
449     // If no source selected then do nothing
450     if(sourceConfig == PAF_SOURCE_NONE) {
451         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
452                            (Int8)PAF_SOURCE_NONE, GATEMP_INDEX_DEC);
453         TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
454         return FALSE;  // No error, but input is not ready for processing
455     }
457     // If we want pass processing then proceed directly
458     if (sourceConfig == PAF_SOURCE_PASS)
459     {
460         TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
461         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
462                            (Int8)PAF_SOURCE_PASS, GATEMP_INDEX_DEC);
464         pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
465         if (pP->fxns->passProcessing) {
466             *asipErrno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
467         }
468         else {
469             TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, asipErrno 0x%x",
470                          as+zMS, ASPERR_PASS);
471             *asipErrno = ASPERR_PASS;
472         }
474         TRACE_VERBOSE0("TaskAsip: continue");
475         return FALSE;  // Error or not, input is not ready for processing
476     }
478     // No error and input processing is ready
479     return TRUE;
480 } /* asitPrepareProcessing */
483 /*===========================================================================
484  * ASIT Source Detection:
485  *     ASIT processing for input source identification:
486  *     - mark I/O PHY transfer completion
487  *     - run auto-detection via I/O DATA in asitInputDataProcess
488  *     - mark I/O DATA read completion
489  *     - check auto-detection status and take corresponding actions if either
490  *       PCM or bitstream is identified:
491  *       - decide input source
492  *       - update I/O components
493  *       - reconfigure McASP LLD if it is PCM
494  *     - start next I/O PHY transfer
495 ============================================================================*/
496 Int asitSourceDetection(const PAF_ASIT_Params *pP,
497                         const PAF_ASIT_Patchs *pQ,
498                         PAF_ASIT_Config       *pAsitCfg)
500     PAF_AST_Config  *pAstCfg;
501     PAF_AST_IoInp *pInp;                // I/O components for input
502     Int zMD, mcaspErr, asitErr;
503     ioDataAutoDetStat_t autoDetStatus;
505     pAstCfg  = pAsitCfg->pAstCfg;               // pointer to AST common (shared) configuration
506     zMD = pAstCfg->masterDec;
507     pInp = &pAsitCfg->pIoInp[zMD];              // pointer to input I/O components
509     // Marks I/O PHY transfer and I/O BUFF write complete
510     asitPhyTransferComplete(pInp);
512     // Process input data - either searching SYNC for PCM or checking SYNC for bitstream
513     asitErr = asitInputDataProcess(pInp, &autoDetStatus);
514     if(asitErr != ASIT_NO_ERR) {
515         // Even though there is error, still need to start next transfer to
516         // maintain McASP transfer, before returning error.
517         asitPhyTransferStart(pInp);
519         return asitErr;
520     }
522     // Mark input data read complete
523     ioDataReadComplete(pInp->hIoData);
525     if(autoDetStatus.syncTimeOut) {
526         return ASIT_AUTODET_TIME_OUT;
527     }
528     // Check if bitstream or PCM is detected
529     else if(   autoDetStatus.syncState == IODATA_SYNC_BITSTREAM
530        || autoDetStatus.syncState == IODATA_SYNC_PCM) {
531         // Decide input source and inform decoder
532         asitErr = asitDecideSource(pAstCfg, pInp, &autoDetStatus);
533         if(asitErr != ASIT_NO_ERR) {
534             return asitErr;
535         }
536         else {
537             // Update I/O components and input buffer config
538             asitUpdateIoComps(pP, pAstCfg, pInp, &autoDetStatus);
540             // set to unknown so that we can ensure, for IOS purposes, that
541             // sourceDecode = NONE iff we are in this top level state machine
542             // and specifically not in decodeProcessing
543 #ifndef DEBUG_SKIP_DECODING
544             pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN);
545 #endif
547             if(autoDetStatus.syncState == IODATA_SYNC_BITSTREAM) {
548                 // Input is bit stream: go to decoding
549                 pInp->asipState = ASIT_DECODE_PROCESSING;
550                 TRACE_VERBOSE0("Bit stream detected. Go to decoding. ");
551             }
552             else  {
553                 // Input is PCM: stop swapping data
554                 pInp->swapData = FALSE;
556                 // Reconfigure McASP LLD to transfer 32-bit unpacked data
557                 mcaspErr = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_32);
558                 if(mcaspErr != Aud_EOK) {
559                     return ASIT_ERR_MCASP_CFG;
560                 }
562                 // Adjust I/O BUFF delay and read pointer - to make sure read pointers
563                 // always point to PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
564                 ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
566                 // Mute decoder output during PCM transition
567                 pAstCfg->xInp[zMD].inpBufConfig.deliverZeros = TRUE;
569                 // Go to transition state to switch to PCM
570                 pInp->asipState = ASIT_PCM_TRANSITION;
571                 TRACE_VERBOSE0("PCM stream detected. Go to PCM transition. ");
572             }
573         }
574     }
575     else {
576         // SYNC search ongoing, no action is needed
577     }
579     // Start next transfer
580     asitPhyTransferStart(pInp);
582     return (ASIT_NO_ERR);
583 }  /* asitSourceDetection */
586 /*===========================================================================
587     //
588     // which will cause all 0's in one McASP LLD transfer. This will
589     // be detected as loss of SYNC by auto detection. To prevent that,
590     // skip I/O DATA process for hangover period so that this all 0's
591     // frame will not be seen by auto-detection. Also, playing out PCM
592     // needs to be skipped as well, to prevent from playing out garbage
593     // (16-bit packed data).
594  *
595  * ASIT Transition to PCM decoding.
596  *     When PCM is detected, McASP LLD will be reconfigured to transmit 32-bit
597  *     words, which will modify the RFMT register. This will cause all 0's in
598  *     one McASP LLD transfer, which would be detected as loss of SYNC by auto
599  *     detection (performed by I/O DATA). To prevent that, skip I/O DATA process
600  *     for hangover period so that this all-0's frame will not be seen by the
601  *     auto-detection.
602  *
603  *     In addition, playing out PCM should be skipped as well to prevent from
604  *     playing out the 16-bit packed data that's still in the input buffer.
605  *
606  *     This function does the following:
607  *     - mark I/O PHY transfer completion
608  *     - bypass I/O DATA
609  *     - start next I/O PHY transfer
610 ============================================================================*/
611 Int asitPcmTransition(PAF_ASIT_Config *pAsitCfg)
613     Int asitErr;
614     PAF_AST_IoInp *pInp;                  // I/O components for input
615     Int zMD;
617     zMD = pAsitCfg->pAstCfg->masterDec;   // pointer to AST common (shared) configuration
618     pInp = &pAsitCfg->pIoInp[zMD];        // pointer to input I/O components
620     // Marks I/O PHY transfer and I/O BUFF write complete
621     asitPhyTransferComplete(pInp);
623     // Bypass I/O data processing due to McASP LLD work around
624     // (refer to comments inside the function)
625     asitErr = asitBypassIoData(pInp);
627     pInp->pcmSwitchHangOver--;
628     if(pInp->pcmSwitchHangOver == 0) {
629         pInp->asipState = ASIT_DECODE_PROCESSING;
631         // Unmute decoder output after PCM transition
632         pAsitCfg->pAstCfg->xInp[zMD].inpBufConfig.deliverZeros = FALSE;
633     }
634     else {
635         ; // stay in this state
636     }
638     // Start next transfer
639     asitPhyTransferStart(pInp);
641     return asitErr;
643 } /* asitPcmTransition */
645 /*============================================================================
646  * ASIT Bypass I/O DATA Processing
647  *     This function bypasses the I/O DATA processing. It maintains the read
648  *     operation of I/O BUFF by directly calling I/O BUFF APIs. When I/O DATA
649  *     is not bypassed, I/O BUFF read operation is invoked by I/O DATA.
650  *
651 ============================================================================*/
652 Int asitBypassIoData(PAF_AST_IoInp *pInp)
654     void *buff1, *buff2;
655     size_t size1, size2;
657     // Get read pointers (or sub-buffers) of the input buffer
658     if (ioBuffGetReadPtrs(pInp->hIoBuff, pInp->phyXferSize,
659                           &buff1, &size1, &buff2, &size2)
660         == IOBUFF_ERR_UNDERFLOW) {
661         pInp->numUnderflow += 1;
663         // Return since there is no enough data to process
664         return ASIT_ERR_INPBUF_UNDERFLOW;
665     }
667     ioBuffReadComplete(pInp->hIoBuff, buff1, size1);
669     if(buff2 != NULL) {
670         ioBuffReadComplete(pInp->hIoBuff, buff2, size2);
671     }
673     return ASIT_NO_ERR;
674 } /* asitBypassIoData */
677 /*============================================================================
678  * ASIT Decode Processing
679  *     This function performs the decode processing and does the following based
680  *     on the ASIT events:
681  *     - initialize the decode processing if it is the first time
682  *     - if there is ASIT INPUT DATA event (ASIT_EVTMSK_INPDATA):
683  *        - mark I/O PHY transfer completion
684  *        - run auto-detection via I/O DATA in asitInputDataProcess
685  *        - check auto-detection status and take corresponding actions if SYNC
686  *          is lost.
687  *        - start next I/O PHY transfer
688  *     - map ASIT events to decoding messages
689  *     - invoke decDecodeFsm() and pass the mapped decoding messages
690  *     - if there is ASIT DECODE ACK event (ASIT_EVTMSK_DECACK)
691  *        - mark I/O DATA read completion
692  *     - error handling
693 ============================================================================*/
694 Int asitDecodeProcessing(const PAF_ASIT_Params *pP,
695                          const PAF_ASIT_Patchs *pQ,
696                          PAF_ASIT_Config       *pAsitCfg,
697                          UInt asitEvents)
699     Int asitErr, decErr;
700     PAF_AST_IoInp *pInp;                  // I/O components for input
701     AspMsgMaster_Handle hAspMsgMaster;    // ASIT message master handle
702     asipDecProc_t *pDec;
703     ioDataAutoDetStat_t autoDetStatus;
704     Int zMD;
705     UInt decMsg;
706     Int status;
708     zMD = pAsitCfg->pAstCfg->masterDec;         // pointer to AST common (shared) configuration
709     pInp = &pAsitCfg->pIoInp[zMD];              // pointer to input I/O components
710     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get ASIT message master handle
711     pDec = &pAsitCfg->inpDec;
713     // Initialization for decode processing when this function is called the first time
714 #ifndef DEBUG_SKIP_DECODING
715     if(!pDec->initDone) {
716         // Initialize decoder
717         decDecodeInit(pP, pAsitCfg, pInp->sourceSelect);
719         pDec->initDone = TRUE;
720     }
721 #endif
723     // Process input data if this is a data ready message
724     if(asitEvents & ASIT_EVTMSK_INPDATA) {
725         TRACE_TERSE0("asitDecodeProcessing: process input data.");
727         // Marks I/O PHY transfer and I/O BUFF write complete
728         asitPhyTransferComplete(pInp);
730         // Process input data - either search SYNC for PCM or check SYNC for bitstream
731         asitErr = asitInputDataProcess(pInp, &autoDetStatus);
733         if(asitErr == ASIT_NO_ERR) {
734             ioDataReadComplete(pInp->hIoData);
736             // Check if SYNC is maintained or lost (stream stops or format changes)
737             if(autoDetStatus.syncState == IODATA_SYNC_NONE) {
738                 // SYNC lost: change I/O PHY transfer size to default for auto-detection
739                 //asitErr = asitRecfgPhyXfer(pInp, INPUT_FRAME_SIZE_DEF);
740                 //if(asitErr != ASIT_NO_ERR) {
741                 //    return asitErr;
742                 //}
744                 // Inform decoder to complete the decoding of previous frame - is this good?
745                 pInp->sourceSelect = PAF_SOURCE_NONE;
746                 pInp->numFrameReceived    = 0;    // for debugging
747                 pInp->numPcmFrameReceived = 0;    // for debugging
748                 TRACE_TERSE0("asitDecodeProcessing: SYNC lost.");
750 #ifdef DEBUG_SKIP_DECODING
751                 asitErr = ASIT_ERR_DECODE_QUIT;
752 #endif
753             }
754             else {
755                 if(autoDetStatus.syncState == IODATA_SYNC_PCM) {
756                     pInp->numPcmFrameReceived += 1;  // for debugging
757                 }
758                 else {
759                     pInp->numFrameReceived += 1;     // for debugging
760                 }
762                 // Communicate input stream information to decoder through input
763                 // buffer configuration -- this was moved inside decDecodeFsm
764                 //asitUpdateInpBufConfig(pAsitCfg->pAstCfg, pInp);
766                 // Start next transfer
767                 asitPhyTransferStart(pInp);
768             }
770             // Start next transfer
771             //asitPhyTransferStart(pInp);
773 #ifdef DEBUG_SKIP_DECODING
774             return asitErr;
775 #endif
776         }
777         else if(asitErr == ASIT_ERR_INPBUF_UNDERFLOW) {
778             TRACE_TERSE0("asitDecodeProcessing: Input buffer underflows.");
780             // When input buffer underflows, it is not an error but decoding needs
781             // to be skipped as there is not enough data in the buffer.
782             asitPhyTransferStart(pInp);
784             return asitErr;
785         }
786         else {
787             // Inform decoder to complete the decoding of previous frame - is this good?
788             pInp->sourceSelect = PAF_SOURCE_NONE;
789             pInp->numFrameReceived    = 0;    // for debugging
790             pInp->numPcmFrameReceived = 0;    // for debugging
791             TRACE_TERSE1("asitDecodeProcessing: asitInputDataProcess error: %d", asitErr);
793 #ifdef DEBUG_SKIP_DECODING
794             return ASIT_ERR_DECODE_QUIT;
795 #endif
796         }
797     } /* ASIT_EVTMSK_INPDATA */
798 #ifdef DEBUG_SKIP_DECODING
799     else {
800         TRACE_TERSE0("asitDecodeProcessing: events error.");
801         return ASIT_ERR_EVENTS;
802     }
803 #endif
805 #ifndef DEBUG_SKIP_DECODING
806     // Map ASIT events to decode messages
807     decMsg = asitEventsToDecMsg(asitEvents);
809     // Pass messages (corresponding to events) to decode FSM
810     decErr = decDecodeFsm(pP, pQ, pAsitCfg, pInp->sourceSelect, decMsg);
812     // Mark I/O DATA read complete if decoder indicates decoding is done.
813     if((asitEvents & ASIT_EVTMSK_DECACK)) {  // DECACK -> decoding done
814         //ioDataReadComplete(pInp->hIoData);
815     }
817     if(decErr != DEC_NO_ERR) {
818         TRACE_VERBOSE0("TaskAsip: send DEC_EXIT message to slave decoder.");
820         // Send dec exit message to slave decoder
821         status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_EXIT, NULL);
822         if (status != ASP_MSG_NO_ERR)
823         {
824             TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
825             SW_BREAKPOINT;
826         }
827         status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_EXIT_DONE, NULL, TRUE);
828         if (status != ASP_MSG_NO_ERR) 
829         {
830             TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
831             SW_BREAKPOINT;
832         }
834         return ASIT_ERR_DECODE_QUIT;  // This is not necessarily an error
835     }
836     else {
837         return ASIT_NO_ERR;
838     }
839 #endif
840 }  /* asitDecodeProcessing */
843 /*============================================================================
844  * ASIT Input Data Processing:
845  *    - invoke ioDataProcess() to inspect input data for
846  *       - initial auto-detection,  or
847  *       - background scanning for PCM data, or
848  *       - SYNC check for bitstream
849  *    - return auto-detection status (SYNC detected, SYNC loss, etc)
850 ============================================================================*/
851 Int asitInputDataProcess(PAF_AST_IoInp *pInp, ioDataAutoDetStat_t *pAutoDetStats)
853     Int ioDataErr, retVal;
854     ioDataCtl_t ioDataCtl;
856     // Perform auto-detection inside I/O DATA component
857     ioDataErr = ioDataProcess(pInp->hIoData);
859     if(ioDataErr == IODATA_NO_ERR) {
860         // Normal operation - check auto-detection status
861         ioDataCtl.code = IODATA_CTL_GET_AUTODET_STATUS;
862         ioDataControl(pInp->hIoData, &ioDataCtl);
864         *pAutoDetStats = ioDataCtl.param.autoDetStats;
866         retVal = ASIT_NO_ERR;
867     }
868     else if(ioDataErr == IODATA_ERR_IOBUF_UNDERFLOW) {
869         // Input buffer underflows - there is no enough data to process.
870         // This is not error and no action is needed.
871         pInp->numUnderflow += 1; // debug
873         retVal = ASIT_ERR_INPBUF_UNDERFLOW;
874     }
875     else {
876         // Something is wrong: print error log and return
877         //printf("IODATA processing error!\n");
878         retVal = ASIT_ERR_INPDATA_PROC;
879     }
881     return retVal;
882 } /* asitInputDataProcess */
884 /*============================================================================
885  * Mapping ASIT Events to Decoding Messages
886 ============================================================================*/
887 UInt asitEventsToDecMsg(UInt asitEvents)
889     UInt decMsg = 0;
891     if (asitEvents & ASIT_EVTMSK_INPDATA) {
892         // Input data event
893         decMsg |= DEC_MSGMSK_INPDATA;
894     }
896     // temp, simulation
897     //if(asitEvents & ASIT_EVTMSK_INFOACK) {
898     //    decMsg |= DEC_MSGMSK_INFOACK;
899     //}
901     // temp, simulation
902     //if(asitEvents & ASIT_EVTMSK_DECACK) {
903     //    decMsg |= DEC_MSGMSK_DECACK;
904     //}
906     if (asitEvents & ASIT_EVTMSK_RXACK)
907     {
908        // Receive acknowledge message event
909         decMsg |= DEC_MSGMSK_RXACK;
910     }
911     
912     return decMsg;
913 } /* asitEventsToDecMsg */
915 /*===========================================================================
916  * Initialize I/O components for input processing
917 ============================================================================*/
918 int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
920     ioBuffParams_t ioBuffParams;
921     ioPhyParams_t  ioPhyParams;
922     ioDataParam_t  ioDataCfg;
923     ioPhyCtl_t     ioPhyCtl;
925     if (pInpIo->hMcaspChan != NULL)
926     {
927         //pInpIo->phyXferSize = INPUT_FRAME_SIZE_DEF;
928         pInpIo->phyXferSize = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF * WORD_SIZE_BITSTREAM;
930         if (pInpIo->firstTimeInit) {
931             TRACE_VERBOSE0("Initialize I/O BUFF and I/O PHY.");
932             ioBuffParams.base         = pInpBuf->inpBufConfig.base.pVoid;
933             ioBuffParams.size         = pInpBuf->inpBufConfig.allocation / STRIDE_WORST_CASE
934                                                                          * STRIDE_WORST_CASE;
935             ioBuffParams.sync         = IOBUFF_WRITE_SYNC;
936             ioBuffParams.nominalDelay = pInpIo->phyXferSize;
937             if (ioBuffInit(pInpIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) {
938                 return (ASIT_ERR_IOBUFF_INIT);   // to remove magic number
939             }
941             ioPhyParams.ioBuffHandle    = pInpIo->hIoBuff;
942             ioPhyParams.xferFrameSize   = pInpIo->phyXferSize;
943             ioPhyParams.mcaspChanHandle = pInpIo->hMcaspChan;
944             ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_WRITE;
945             if (ioPhyInit(pInpIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) {
946                 return (ASIT_ERR_IOPHY_INIT);   // to remove magic number
947             }
949             pInpIo->numPrimeXfers = NUM_PRIME_XFERS;
950         }
952         /* Reinitialize I/O DATA every time when ASIT restarts */
953         TRACE_VERBOSE0("Initialize I/O DATA.");
954         ioDataCfg.ioBuffHandle         = pInpIo->hIoBuff;
955         ioDataCfg.unknownSourceTimeOut = pInpBuf->inpBufConfig.pBufStatus->unknownTimeout;
956         ioDataCfg.frameLengthsIEC      = (uint_least16_t *)&iecFrameLength[0];
957         ioDataCfg.frameLengthPCM       = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF;
958         ioDataCfg.frameLengthDef       = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF;
959         ioDataCfg.ibMode               = pInpBuf->inpBufConfig.pBufStatus->mode;
960         ioDataCfg.zeroRunRestart       = pInpBuf->inpBufConfig.pBufStatus->zeroRunRestart;
961         ioDataCfg.zeroRunTrigger       = pInpBuf->inpBufConfig.pBufStatus->zeroRunTrigger;
963         if (ioDataInit(pInpIo->hIoData, &ioDataCfg) != IODATA_NO_ERR) {
964             return (ASIT_ERR_IODATA_INIT);   // to remove magic number
965         }
967         if (pInpIo->firstTimeInit) {
968             /* Initialize I/O BUFF and I/O PHY only when input interface changes. */
969             TRACE_VERBOSE0("Prime I/O PHY.");
971             // Start I/O physical layer by priming McASP LLD for input
972             asitIoPhyPrime(pInpIo);
974             pInpIo->firstTimeInit = FALSE;
975         }
976         else {
977             // Reconfigure I/O PHY transfer size
978             ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
979             ioPhyCtl.params.xferFrameSize = pInpIo->phyXferSize;
980             ioPhyControl(pInpIo->hIoPhy, &ioPhyCtl);
981     #if 0
982             // If previous stream before reset was PCM, reconfigure McASP LLD to receive 16-bit packed bits
983             if (!pInpIo->swapData) {
984                 Int mcaspErr;
985                 mcaspErr = mcaspRecfgWordWidth(pInpIo->hMcaspChan, Mcasp_WordLength_16);
986                 if(mcaspErr != Aud_EOK) {
987                     return ASIT_ERR_MCASP_CFG;
988                 }
990                 // Start swapping data
991                 pInpIo->swapData = TRUE;
992                 TRACE_VERBOSE0("Reconfigure McASP word length and start swapping data.");
993             }
994     #endif
995             // Start PHY transfer
996             TRACE_VERBOSE0("Start I/O PHY transfer.");
997             asitPhyTransferStart(pInpIo);
998         }
999     }
1001     return 0;
1002 } /* asitIoCompsInit */
1004 /*======================================================================================
1005  *  This function initializes ASIT processing
1006  *====================================================================================*/
1007 void asitProcInit(PAF_AST_IoInp  *pInp, asipDecProc_t *pDec)
1009 //    pInp->swapData = TRUE;
1010     pInp->pcmSwitchHangOver = INPUT_SWITCH_HANGOVER;
1011     pDec->initDone = FALSE;
1012     pInp->numFrameReceived    = 0;    // for debugging
1013     pInp->numPcmFrameReceived = 0;    // for debugging
1016 /*======================================================================================
1017  *  I/O physical layer prime operation required by McASP LLD
1018  *====================================================================================*/
1019 void asitIoPhyPrime(PAF_AST_IoInp *pInp)
1021     Int32        count;
1023     for(count = 0; count < pInp->numPrimeXfers; count++)
1024     {
1025         ioPhyXferSubmit(pInp->hIoPhy);
1026 #ifdef ASIP_DEBUG
1027         //pInp->numXferStart++;
1028 #endif
1029     }
1030 } /* asitIoPhyPrime */
1033 /*======================================================================================
1034  *  This function marks the I/O PHY transfer as complete
1035  *====================================================================================*/
1036 void asitPhyTransferComplete(PAF_AST_IoInp * pInpIo)
1038     // Mark underlining I/O BUFF write complete and swap data if needed
1039     ioPhyXferComplete(pInpIo->hIoPhy, pInpIo->swapData);
1040 } /* asitPhyTransferComplete */
1042 #if 0
1043 Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize)
1045     ioPhyCtl_t ioPhyCtl;
1046     Int mcaspErr;
1048     ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
1049     ioPhyCtl.params.xferFrameSize = xferSize;
1050     ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
1052     pInp->phyXferSize  = ioPhyCtl.params.xferFrameSize;
1054     if(!pInp->swapData) {
1055         // If it was PCM, reconfigure McASP LLD to receive 16-bit packed bits
1056         mcaspErr = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_16);
1057         if(mcaspErr != Aud_EOK) {
1058             return ASIT_ERR_MCASP_CFG;
1059         }
1061         // Start swapping data
1062         pInp->swapData = TRUE;
1063     }
1065     return ASIT_NO_ERR;
1067 } /* asitRecfgPhyXfer */
1068 #endif
1070 /*======================================================================================
1071  *  McASP LLD call back function
1072  *====================================================================================*/
1073 void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
1075     /* post semaphore */
1076     if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
1077         //Semaphore_post(asipSemRx);
1078         Event_post(gAsitEvtHandle, ASIT_EVTMSK_INPDATA);
1079         //Log_info0("asipMcaspCallback: final packet - event posted.\n");
1080     } else {
1081         //Log_info0("asipMcaspCallback: intermediate packet.\n");
1082         ;    // intermediate packet due to buffer wrapping around
1083     }
1086 /*======================================================================================
1087  *  This function checks if McASP Rx for input overruns
1088  *====================================================================================*/
1089 int asipCheckMcaspRxOverrun(Ptr mcaspChanHandle)
1091     Mcasp_errCbStatus mcaspErrStat;
1093     mcaspControlChan(mcaspChanHandle, Mcasp_IOCTL_CHAN_QUERY_ERROR_STATS, &mcaspErrStat);
1095     return (mcaspErrStat.isRcvOvrRunOrTxUndRunErr);
1098 #if 0
1099 /*======================================================================================
1100  *  This function restarts McASP LLD channel for input
1101  *====================================================================================*/
1102 void asipMcaspRxRestart(PAF_AST_IoInp *pInpIo)
1104     mcaspRxReset();
1105     mcaspRxCreate();
1107 #endif
1109 /*======================================================================================
1110  *  This function starts an I/O PHY transfer
1111  *====================================================================================*/
1112 void asitPhyTransferStart(PAF_AST_IoInp *pInpIo)
1114     Int ioPhyErr;
1116     if(asipCheckMcaspRxOverrun(pInpIo->hMcaspChan)) {
1117 #ifdef ASIP_DEBUG
1118         pInpIo->numInputOverrun++;
1119 #endif
1120         //asipMcaspRxRestart(pInpIo);
1121         System_abort("\nMcASP for input overruns! %d!\n");
1122     }
1123     else {
1124         //TRACE_VERBOSE0("asitPhyTransferStart: submit a transfer");
1125         ioPhyErr = ioPhyXferSubmit(pInpIo->hIoPhy);
1126         //if(ioPhyXferSubmit(pInpIo->hIoPhy)==IOPHY_ERR_BUFF_OVERFLOW) {
1127         if(ioPhyErr!=IOPHY_NOERR){
1128             printf("\n I/O PHY ioPhyXferSubmit fails with error %d!\n", ioPhyErr);
1129             // Input buffer overflows!
1130             //printf("\nInput buffer overflows!\n");
1131             exit(0);
1132         }
1133         else {
1134             // Input buffer operates normally
1135             ;
1136         }
1137 #ifdef ASIP_DEBUG
1138         //pInpIo->numXferStart++;
1139 #endif
1140     }
1143 // Indicates whether Input has been selected
1144 Int d10Initialized = 0;
1146 //extern Aud_STATUS mcaspAudioConfig(void);
1147 //extern void McaspDevice_init(void);
1149 /*======================================================================================
1150  *  This function initializes HW interface and selects the right device for input
1151  *====================================================================================*/
1152 Int asitSelectDevices(
1153     const PAF_ASIT_Patchs *pQ, 
1154     PAF_AST_Config *pAstCfg, 
1155     PAF_AST_IoInp *pInp
1158     Int32 status;
1159     Aud_STATUS audStatus;
1160     const PAF_SIO_Params *pInPrms;
1161     mcaspLLDconfig *pLldCfg;
1162     mcaspLLDconfig *pReqLldCfg;
1163     Ptr mcaspChanHandle;
1164     Int zMD;
1165     Int interface;
1166     const PAF_SIO_Params *pD10Params;
1167     UInt postedEvents;
1169     zMD = pAstCfg->masterDec;
1170     
1171     interface = pAstCfg->xInp[zMD].inpBufStatus.sioSelect; // obtain SIO select for input
1172     
1173     if (interface >= 0)
1174     {
1175         // Positive value for interface: new Input SIO update request has been received via alpha command.
1176         // Negative value for interface: no new Input SIO update request has been received,
1177         //                               previous requests have been processed.
1178         
1179         // check for valid index into device array
1180         if (interface >= pQ->devinp->n)    // DEVINP_N
1181         {
1182             interface = 0; // treat as device InNone
1183         }
1184         
1185         //
1186         // Deactivate currently active interface
1187         //
1188         if (pInp->hMcaspChan != NULL)   // non-NULL McASP LLD channel handle indicates there's an active interface
1189         {
1190             d10Initialized = 0; // indicate no Input selected
1191             
1192             // Reset channel
1193             status = mcaspControlChan(pInp->hMcaspChan, MCASP_CHAN_RESET, NULL);   // Rx reset channel
1194             //status = mcaspControlChan(pInp->hMcaspChan, MCASP_DEVICE_RESET, NULL); // Reset Tx/Rx channel
1195             if (status != MCASP_COMPLETED)
1196             {
1197                 Log_info0("asitSelectDevices(): McASP channel reset failed!\n");
1198                 return ASIP_ERR_MCASP_CFG;            
1199             }
1200             
1201             // Delete McASP LLD channel
1202             status = mcaspDeleteChan(pInp->hMcaspChan);
1203             if (status != MCASP_COMPLETED)
1204             {
1205                 Log_info0("asitSelectDevices(): McASP channel deletion failed!\n");
1206                 return ASIP_ERR_MCASP_CFG;
1207             }
1208             
1209             // Clear (drop) already posted Input data events
1210             postedEvents = Event_getPostedEvents(gAsitEvtHandle);
1211             while ((postedEvents & ASIT_EVTMSK_INPDATA) != 0)
1212             {
1213                 Event_pend(gAsitEvtHandle, ASIT_EVTMSK_NONE, ASIT_EVTMSK_INPDATA, 0);
1214                 postedEvents = Event_getPostedEvents(gAsitEvtHandle);
1215             }
1217             pInp->hMcaspChan = NULL;        // reset active McASP LLD handle
1218             if (pInp->pRxParams != NULL)    // sanity check, pInp->pRxParams should be non NULL if pInp->hMcaspChan is non NULL
1219             {
1220                 pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
1221                 pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig; // get pointer to active McASP LLD configuration
1222                 pLldCfg->hMcaspChan = NULL; // reset McASP LLD handle for active McASP LLD configuration
1223                 pInp->pRxParams = NULL;     // reset pointer to active D10 parameters
1224             }
1225             else 
1226             {
1227                 // This is a programming error
1228                 SW_BREAKPOINT;  // debug
1229             }
1230         }
1232         //
1233         // Activate requested interface
1234         //
1235         pD10Params = (const PAF_SIO_Params *)pQ->devinp->x[interface];  // get D10 parameters for selected interface
1236         if (pD10Params != NULL)
1237         {
1238             //
1239             // Requested device is other than InNone
1240             //
1241             if((interface == DEVINP_HDMI) || (interface == DEVINP_HDMI_STEREO))
1242             {
1243                 D10_initHDMI();
1244             }
1245             
1246             // Initialize Tx clock mux
1247             D10_initClkMux((void *)pD10Params);
1248                 
1249             pReqLldCfg = (mcaspLLDconfig *)pD10Params->sio.pConfig;
1250             if (pReqLldCfg->hMcaspChan == NULL)
1251             {
1252                 // Create McASP LLD channel
1253                 mcaspChanHandle = NULL;
1254                 audStatus = mcasplldChanCreate(pReqLldCfg, &mcaspChanHandle);
1255                 if (audStatus != Aud_EOK) 
1256                 {
1257                     Log_info0("asitSelectDevices(): McASP channel creation failed!\n");
1258                     return ASIP_ERR_MCASP_CFG;
1259                 }
1260                 
1261                 pReqLldCfg->hMcaspChan = mcaspChanHandle;   // set McASP LLD handle for requested McASP LLD configuration
1262                 pInp->pRxParams = (const void *)pD10Params; // set pointer to active D10 parameters
1263                 pInp->hMcaspChan = pReqLldCfg->hMcaspChan;  // set active McASP LLD handle
1264                 
1265                 // configure stride according to selected McASP LLD configuration
1266                 pInp->stride = pReqLldCfg->mcaspChanParams->noOfSerRequested * 
1267                     pReqLldCfg->mcaspChanParams->noOfChannels;
1268                 
1269                 pInp->firstTimeInit = TRUE; // set flag for IO Phy & Buff initialization
1270                 
1271                 d10Initialized = 1; // indicate Input selected
1272             }
1273         }
1274         else
1275         {
1276             //
1277             // Requested device is InNone
1278             //
1279             pInp->hMcaspChan = NULL;    // reset active McASP LLD handle
1280             pInp->pRxParams = NULL;     // reset pointer to active D10 parameters
1281         }
1282         
1283         // indicate SIO update request processed
1284         pAstCfg->xInp[zMD].inpBufStatus.sioSelect = interface | 0x80;
1285     }
1287     if (pInp->hMcaspChan != NULL)       // non NULL indicates there's an active interface
1288     {
1289         if (pInp->pRxParams != NULL)    // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
1290         {
1291             pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
1292             pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig;   // get currently active McASP LLD configuration
1293             if (pLldCfg != NULL)        // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
1294             {
1295                 // Configure McASP to receive 16/32-bit data according to default configuration
1296                 mcaspRecfgWordWidth(pInp->hMcaspChan, pLldCfg->mcaspChanParams->wordWidth);
1297                 
1298                 // Set flag to swap HDMI data if it is 4xI2S and word length is 16
1299                 if ((pLldCfg->mcaspChanParams->wordWidth == Mcasp_WordLength_16) &&
1300                     (pLldCfg->mcaspChanParams->noOfSerRequested == 4)) 
1301                 {
1302                     pInp->swapData = TRUE;
1303                 }
1304                 else 
1305                 {
1306                     pInp->swapData = FALSE;
1307                 }
1308             }
1309             else
1310             {
1311                 // This is a programming error
1312                 SW_BREAKPOINT;  // debug
1313             }
1315         }
1316         else
1317         {
1318             // This is a programming error
1319             SW_BREAKPOINT;  // debug
1320         }
1321     }
1322     
1323     return ASIP_NO_ERR;
1324 }  /* asitSelectDevices */
1326 /*======================================================================================
1327  *  This function updates input status
1328  *====================================================================================*/
1329 Int asitUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
1330                           PAF_InpBufConfig *pInpBuf)
1332     Int asipErrno;
1334     PAF_SIO_InputStatus inputStatus;
1336     // initialize all values to unknown so that device specific
1337     //   driver layer need only fill in those entries that it is aware of.
1338     //   This allows extensibility of the structure without requiring users
1339     //   to re-code.
1340     inputStatus.lock = 0;
1341     inputStatus.sampleRateData = PAF_SAMPLERATE_UNKNOWN;
1342     inputStatus.sampleRateMeasured = PAF_SAMPLERATE_UNKNOWN;
1343     inputStatus.nonaudio = PAF_IEC_AUDIOMODE_UNKNOWN;
1344     inputStatus.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
1346     //more configuration is needed to abstract out D10
1347     asipErrno = D10_RxControl(pRxParams,
1348                           (Uns)PAF_SIO_CONTROL_GET_INPUT_STATUS,
1349                           (Arg) &inputStatus);
1350     if (asipErrno) {
1351         return asipErrno;
1352     }
1353     pStatus->sampleRateData = inputStatus.sampleRateData;
1354     pStatus->sampleRateMeasured = inputStatus.sampleRateMeasured;
1355     pStatus->nonaudio = inputStatus.nonaudio;
1356     pStatus->emphasisData = inputStatus.emphasis;
1358     // if MSB of override clear then use as reported lock
1359     // if = 0x80 then use default [0x81]
1360     // if = 0x81 then use measured (from device)
1361     // others not defined or implemented
1362     if ((pStatus->lockOverride & (XDAS_Int8)0x80) == 0)
1363         pStatus->lock = pStatus->lockOverride;
1364     else if (pStatus->lockOverride == (XDAS_Int8)0x80)
1365         pStatus->lock = inputStatus.lock;
1366     else if (pStatus->lockOverride == (XDAS_Int8)0x81)
1367         pStatus->lock = inputStatus.lock;
1369     // if MSB of override clear then use it as sample rate for system,
1370     // if = 0x80 then use default [0x82]
1371     // if = 0x81 then use data
1372     // if = 0x82 then use measured
1373     // others not defined or implemented
1374     if ((pStatus->sampleRateOverride & (XDAS_Int8)0x80) == 0)
1375         pStatus->sampleRateStatus = pStatus->sampleRateOverride;
1376     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x80)
1377         pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
1378     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x81)
1379         pStatus->sampleRateStatus = pStatus->sampleRateData;
1380     else if (pStatus->sampleRateOverride == (XDAS_Int8)0x82)
1381         pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
1383     // Update emphasis status:
1384     if ((pStatus->emphasisOverride & (XDAS_Int8)0x80) == 0) {
1385         if (pStatus->emphasisData == PAF_IEC_PREEMPHASIS_YES)
1386             pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
1387         else
1388             pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
1389     }
1390     else if (pStatus->emphasisOverride ==
1391              (XDAS_Int8 )(0x80+PAF_IEC_PREEMPHASIS_YES))
1392         pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
1393     else /* IBEmphasisOverrideNo or other */
1394         pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
1396     // Update precision control
1397     pInpBuf->precision = pStatus->precisionInput =
1398         pStatus->precisionOverride < 0
1399         ? pStatus->precisionDefault
1400         : pStatus->precisionOverride > 0
1401         ? pStatus->precisionOverride
1402         : pStatus->precisionDetect > 0
1403         ? pStatus->precisionDetect
1404         : pStatus->precisionDefault;
1406     return 0;
1410 /*==============================================================================
1411  * This function updates input buffer config based on frame information provided
1412  * by I/O DATA.
1413  ==============================================================================*/
1414 void asitUpdateInpBufConfig(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp)
1416     PAF_InpBufConfig *pBufConfig;
1417     ioDataCtl_t ioDataCtl;
1419     /* Get information for reading input data */
1420     ioDataCtl.code = IODATA_CTL_GET_INPBUFFINFO;
1421     ioDataControl(pInp->hIoData, &ioDataCtl);
1423     if(ioDataCtl.param.dataReadInfo.frameSize != pInp->phyXferSize) {
1424         // Fatal error!
1425         TRACE_VERBOSE0("TaskAsip: error in updating I/O");
1426         SW_BREAKPOINT;
1427     }
1429     pBufConfig = &(pAstCfg->xInp[pAstCfg->masterDec].inpBufConfig);
1431     //JXTODO: do we need to gate here?
1432     //key = GateMP_enter(gateHandle);
1434     pBufConfig->base.pVoid   = ioDataCtl.param.dataReadInfo.buffBase;
1435     pBufConfig->sizeofBuffer = ioDataCtl.param.dataReadInfo.buffSize;
1436     pBufConfig->pntr.pSmInt  = ioDataCtl.param.dataReadInfo.startAddress;
1438     // Leave the gate
1439     //GateMP_leave(gateHandle, key);
1441     TRACE_TERSE2("Frame start address: 0x%x., preamble: 0x%x",
1442                  (UInt)ioDataCtl.param.dataReadInfo.startAddress,
1443                  *(UInt *)ioDataCtl.param.dataReadInfo.startAddress);
1446 /*==============================================================================
1447  * Decide source after SYNC is found, i.e. either bitstream preamble is detected
1448  * or it times out to PCM.
1449  ==============================================================================*/
1450 Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp, 
1451                      ioDataAutoDetStat_t *autoDetStatus)
1453     Int sourceConfig, sourceSelect, sourceProgram;
1454     Int zMD;
1455     char asipMsgBuf[ASP_MSG_BUF_LEN];
1456     Int status;
1458     // Get the configured source
1459     zMD = pAstCfg->masterDec;
1460     sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1461                                           GATEMP_INDEX_DEC);
1463     if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
1464         if (sourceConfig == PAF_SOURCE_DSD1 || sourceConfig == PAF_SOURCE_DSD2 ||
1465             sourceConfig == PAF_SOURCE_DSD3) {
1466             sourceProgram = sourceConfig;
1467         }
1468         else {
1469             sourceProgram = PAF_SOURCE_PCM;
1470         }
1471     }
1473     if(autoDetStatus->syncState == IODATA_SYNC_BITSTREAM) {
1474         uint_least16_t pc = autoDetStatus->streamInfo.IEC_PC;
1475         sourceProgram = IECpafSource[pc];
1476     }
1478     // write the decided source program to memory
1479     sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), sourceProgram,
1480                        GATEMP_INDEX_DEC);
1482     // now that we have some input classification, and possibly an outstanding
1483     // input frame, we determine whether or not to call decodeProcessing and with
1484     // what decAlg.
1485     sourceSelect = PAF_SOURCE_NONE;
1487     switch (sourceConfig)
1488     {
1489         // If autodetecting, decoding everything, and input is something
1490         // (i.e. bitstream or PCM) then decode.
1491         case PAF_SOURCE_AUTO:
1492             if (sourceProgram >= PAF_SOURCE_PCM)  {
1493                 sourceSelect = sourceProgram; // use whatever from autodet
1494             }
1495             break;
1497         // If autodetecting, decoding only PCM, and input is PCM then decode.
1498         case PAF_SOURCE_PCMAUTO:
1499             if (sourceProgram == PAF_SOURCE_PCM) {
1500                 // only expect autodet to give PAF_SOURCE_PCM, otherwise set to NONE
1501                 sourceSelect = sourceProgram;
1502             }
1503             break;
1505         // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
1506         case PAF_SOURCE_BITSTREAM:
1507             if (sourceProgram >= PAF_SOURCE_AC3) {
1508                 sourceSelect = sourceProgram;
1509             }
1510             break;
1512         // If autodetecting, decoding only DTS, and input is DTS then decode.
1513         case PAF_SOURCE_DTSALL:
1514             switch (sourceProgram)
1515             {
1516                 case PAF_SOURCE_DTS11:
1517                 case PAF_SOURCE_DTS12:
1518                 case PAF_SOURCE_DTS13:
1519                 case PAF_SOURCE_DTS14:
1520                 case PAF_SOURCE_DTS16:
1521                 case PAF_SOURCE_DTSHD:
1522                     sourceSelect = sourceProgram;
1523                     break;
1524             }
1525             break;
1527         // All others, e.g., force modes, fall through to here.
1528         // If user made specific selection then program must match select.
1529         // (NB: this compare relies on ordering of PAF_SOURCE)
1530         default:
1531             sourceSelect = sourceConfig;
1532             if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N)) {
1533                 if (sourceProgram != sourceSelect) {
1534                     sourceSelect = PAF_SOURCE_NONE;
1535                 }
1536             }
1537             break;
1538     }
1540     // if we didn't find any matches then skip
1541     if (sourceSelect == PAF_SOURCE_NONE) {
1542         TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
1543         return ASIT_ERR_NO_MATCHING_SOURCE;
1544     }
1546 #ifndef DEBUG_SKIP_DECODING
1547     // send source select message to slave
1548     *(Int32 *)&asipMsgBuf[0] = sourceSelect;
1549     status = AspMsgSnd(gPAF_ASIT_config.hAspMsgMaster, ASP_SLAVE_DEC_SOURCE_SELECT, asipMsgBuf);
1550     if (status != ASP_MSG_NO_ERR) 
1551     {
1552         TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
1553         SW_BREAKPOINT;
1554     }
1555     status = AspMsgRcvAck(gPAF_ASIT_config.hAspMsgMaster, ASP_MASTER_DEC_SOURCE_SELECT_DONE, NULL, TRUE);
1556     if (status != ASP_MSG_NO_ERR)
1557     {
1558         TRACE_VERBOSE0("TaskAsip: error in receiving SOURCE_SELECT ack message");
1559         SW_BREAKPOINT;
1560     }
1561 #endif
1563     pInp->sourceSelect  = sourceSelect;
1564     pInp->sourceProgram = sourceProgram;
1566     return ASIT_NO_ERR;
1567 } /* asitDecideSource */
1569 /*==============================================================================
1570  * After SYNC is found, i.e. either bitstream preamble is detected or it times
1571  * out to PCM, update input buffer config and I/o components accordingly.
1572  ==============================================================================*/
1573 Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
1574                       PAF_AST_IoInp  *pInp, ioDataAutoDetStat_t *autoDetStatus)
1576     Int sourceConfig;
1577     Int zMD, deliverZeros;
1578     int ioFrameLength, decFrameLength;
1579     PAF_InpBufConfig *pBufConfig;
1580     ioPhyCtl_t  ioPhyCtl;
1581     ioDataCtl_t ioDataCtl;
1583     zMD = pAstCfg->masterDec;
1584     pBufConfig = &pAstCfg->xInp[zMD].inpBufConfig;
1586     // Compute decoder frame length based on source selection
1587     decFrameLength = getFrameLengthSourceSel(pP, pInp->sourceSelect);
1589     pAstCfg->xDec[zMD].decodeControl.frameLength  = decFrameLength;
1590     pAstCfg->xDec[zMD].decodeInStruct.sampleCount = decFrameLength;
1591     pAstCfg->xDec[zMD].decodeControl.sampleRate   = PAF_SAMPLERATE_UNKNOWN;
1593     // Decide frame length for I/O DATA and I/O PHY
1594     if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
1595         // For PCM, I/O frame length is decode frame length multiplied by stride
1596         ioFrameLength = decFrameLength * pInp->stride;
1598         pBufConfig->sizeofElement = WORD_SIZE_PCM;
1599         pBufConfig->frameLength   = pBufConfig->lengthofData = ioFrameLength;
1601         // Configure I/O DATA PCM frame length
1602         ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
1603         ioDataCtl.param.frameLengthPcm = ioFrameLength;
1604         ioDataControl(pInp->hIoData, &ioDataCtl);
1606         // Change I/O PHY transfer size to PCM frame size
1607         pInp->phyXferSize = ioFrameLength*(WORD_SIZE_PCM);
1609         // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
1610         // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
1611         // Adjust delay and don't mark input buffer as read complete
1612         //ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
1614         // Stop swapping data
1615         //pInp->swapData = FALSE;
1616     }
1617     else {
1618         // For bitstream, I/O frame length is the frame length of the bitstream
1619         pBufConfig->sizeofElement = WORD_SIZE_BITSTREAM;
1620         pBufConfig->frameLength   = autoDetStatus->streamInfo.frameLength;
1621         pBufConfig->lengthofData  = autoDetStatus->streamInfo.dataLength;
1622         ioFrameLength = autoDetStatus->streamInfo.frameLength;
1624         // Change I/O PHY transfer size to bitstream frame size
1625         pInp->phyXferSize = ioFrameLength*(WORD_SIZE_BITSTREAM);
1626     }
1628     pBufConfig->stride = pInp->stride;   // common for PCM and bitstream
1630     // Configure I/O PHY transfer size
1631     ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
1632     ioPhyCtl.params.xferFrameSize = pInp->phyXferSize;
1633     ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
1635     // Decide if zeros should be delivered based on the configured source
1636     sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1637                                           GATEMP_INDEX_DEC);
1639     // temporary - does ARM use hRxSio or just check if it is not NULL?
1640     pAstCfg->xInp[zMD].hRxSio = pInp->hIoData;
1641     pAstCfg->xInp[zMD].pInpBuf = &(pAstCfg->xInp[zMD].inpBufConfig);
1643     return ASIT_NO_ERR;
1644 } /* asitUpdateIoComps */
1646 #if 0
1647 #ifndef IO_LOOPBACK_TEST
1648 #if OUTPUT_FRAME_LENGTH == INPUT_FRAME_LENGTH
1649 U8 pcmbuf[OUTPUT_FRAME_SIZE];
1650 #else
1651 #error Input frame length is not equal to output frame length!
1652 #endif
1654 Int rxDecodePcm(PAF_AST_IoInp  *pInp)
1656     ioDataCtl_t ioDataCtl;
1657     void *buffBase;
1658     void *dataStartAddress;
1659     size_t buffSize, frameSize, size1, size2;
1661     /* Get information for reading input data */
1662     ioDataCtl.code = IODATA_CTL_GET_INPBUFFINFO;
1663     ioDataControl(pInp->hIoData, &ioDataCtl);
1665     buffBase = ioDataCtl.param.dataReadInfo.buffBase;
1666     buffSize = ioDataCtl.param.dataReadInfo.buffSize;
1667     dataStartAddress = ioDataCtl.param.dataReadInfo.startAddress;
1668     frameSize        = ioDataCtl.param.dataReadInfo.frameSize;
1670     // Copy PCM data to output buffer
1671     if(((size_t)dataStartAddress+frameSize) <= ((size_t)buffBase+buffSize)) {
1672         // Input buffer doesn't wrap around
1673         Cache_inv(dataStartAddress, frameSize, Cache_Type_ALL, TRUE);
1674         memcpy((void *)&pcmbuf[0], dataStartAddress, frameSize);
1675     }
1676     else {
1677         // Input buffer wraps around
1678         size1 = (size_t)buffBase + buffSize - (size_t)dataStartAddress;
1679         size2 = frameSize - size1;
1680         Cache_inv(dataStartAddress, size1, Cache_Type_ALL, TRUE);
1681         memcpy((void *)&pcmbuf[0], dataStartAddress, size1);
1683         Cache_inv(buffBase, size2, Cache_Type_ALL, TRUE);
1684         memcpy((void *)&pcmbuf[size1], buffBase, size2);
1685     }
1688     return ASIT_NO_ERR;
1692 Int rxDecodePlayZero(PAF_AST_IoInp  *pInp)
1694     return ASIT_NO_ERR;
1696 #endif
1698 #endif
1700 Int asitEvtErrCheck(UInt actualEvents, UInt expectedEvents)
1702     TRACE_VERBOSE2("ASIT events error: actual events are: %d, expected events are: %d.",
1703                    actualEvents, expectedEvents);
1705     return ASIT_ERR_EVENTS;
1708 void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr)
1710     //UInt events;
1712     if(asitErr == ASIT_ERR_INPBUF_UNDERFLOW) {
1713         TRACE_VERBOSE0("ASIT error handling: input buffer underflows. No actions needed.");
1714     }
1716     if(asitErr == ASIT_AUTODET_TIME_OUT) {
1717         pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
1718         pAsitCfg->pIoInp[0].numAsitRestart++;
1719         TRACE_VERBOSE1("ASIT error %d handling finished. Go to state ASIT_RESET.", asitErr);
1720     }
1721     
1722     if(asitErr == ASIT_ERR_DECODE_QUIT) {
1723         TRACE_VERBOSE0("ASIT error handling: DECODE_QUIT - clear INPDATA event.");
1724 #if 0
1725         // Pend on INPTDATA event that should have been posted before decoding quits.
1726         events = Event_pend(asitEvent, ASIT_EVTMSK_NONE, ASIT_EVTMSK_INPDATA,
1727                             BIOS_WAIT_FOREVER);
1729         // Marks I/O PHY transfer and I/O BUFF write complete
1730         asitPhyTransferComplete(&pAsitCfg->pIoInp[0]);
1732         // Keep I/O BUFF read pointers going
1733         asitBypassIoData(&pAsitCfg->pIoInp[0]);
1734 #endif
1735         pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
1736         pAsitCfg->pIoInp[0].numAsitRestart++;
1737         TRACE_VERBOSE1("ASIT error %d handling finished. Go to state ASIT_RESET.", asitErr);
1738     }
1740     if(asitErr == ASIT_ERR_EVENTS) {
1741         pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
1742         pAsitCfg->pIoInp[0].numAsitRestart++;
1743         TRACE_VERBOSE1("ASIT error %d handling: events error. Go to state ASIT_RESET.", asitErr);
1744     }
1746     return;
1747 }  /* asitErrorHandling */
1750 //////////////////////////////////////////////////////////////////////////////
1751 void asitPostInfoEvent()
1753     Event_post(gAsitEvtHandle, ASIT_EVTMSK_INFOACK);
1756 void asitPostDecEvent()
1758     Event_post(gAsitEvtHandle, ASIT_EVTMSK_DECACK);
1760 //////////////////////////////////////////////////////////////////////////////
1762 /* Nothing past this line */