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);
113 extern XDAS_Int32 D10_initClkMux(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)
212 {
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
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);
309 if(asitErr == ASIT_AUTODET_TIME_OUT) {
310 // Should restart if new interface is selected.
311 TRACE_VERBOSE0("TaskAsip: auto-detection time out.");
312 }
313 }
314 else {
315 //Error checking & debug
316 asitErr = asitEvtErrCheck(events, ASIT_EVTMSK_INPDATA);
317 }
319 break;
321 case ASIT_PCM_TRANSITION:
322 // Source is PCM - transition to PCM decoding
323 if(events == ASIT_EVTMSK_INPDATA) {
324 // Only this event is expected. If any other event, it's error.
325 // Input data is ready - transition to PCM decoding
326 // New state will be decided inside the function
327 asitErr = asitPcmTransition(pAsitCfg);
328 }
329 else {
330 //Error checking & debug
331 asitErr = asitEvtErrCheck(events, ASIT_EVTMSK_INPDATA);
332 }
333 break;
335 case ASIT_DECODE_PROCESSING:
336 if(events & ASIT_DEC_EVENTS) {
338 #if 1 // debug
339 if (events & ASIT_EVTMSK_INPDATA)
340 {
341 // shows timing of Input (Rx McASP EDMA)
342 // ADC B5
343 {
344 static Uint8 toggleState = 0;
345 if (toggleState == 0)
346 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
347 else
348 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
349 toggleState = ~(toggleState);
350 }
351 }
352 #endif
354 // Decode processing for either PCM or bitstream
355 // New state will be decided inside the function
356 asitErr = asitDecodeProcessing(pP, pQ, pAsitCfg, events);
357 }
358 else {
359 //Error checking & debug
360 asitErr = asitEvtErrCheck(events, ASIT_DEC_EVENTS);
361 }
362 break;
364 default:
365 break;
366 }
368 if(asitErr) {
369 asitErrorHandling(pAsitCfg, asitErr);
371 if(pInp->asipState == ASIT_RESET) {
372 eventsOn = FALSE;
373 }
375 asitErr = ASIT_NO_ERR;
376 }
378 } // for (;;)
380 } /* taskAsipFxn */
383 /*===========================================================================
384 * ASIT Processing Preparation
385 * Output:
386 * - return TRUE (input is ready) or FALSE (input is not ready)
387 * - *asipErrno Error number
388 ============================================================================*/
389 Int asitPrepareProcessing(const PAF_ASIT_Params *pP,
390 const PAF_ASIT_Patchs *pQ,
391 PAF_ASIT_Config *pC,
392 Int *asipErrno)
393 {
394 Int as, zMS, zMI, zMD;
395 Int sourceConfig, mode;
396 PAF_AST_Config *pAstCfg;
397 PAF_AST_IoInp *pInp; /* I/O components for input */
399 pAstCfg = pC->pAstCfg; // pointer to AST common (shared) configuration
400 as = pAstCfg->as;
401 zMI = pP->zone.master;
402 zMD = pAstCfg->masterDec;
403 zMS = pAstCfg->masterStr;
404 pInp = pC->pIoInp; // pointer to input I/O components
406 *asipErrno = 0;
408 // Select source and initialize physical layer / HW interface
409 *asipErrno = asitSelectDevices(pQ, pAstCfg, pInp);
410 if (*asipErrno) {
411 TRACE_TERSE2("asitSelectDevices returned asipErrno = 0x%04x at line %d. AS%d",
412 *asipErrno, as+zMS);
413 return FALSE; // Input is not ready for processing due to error
414 }
416 // If no master input selected then we don't know what may be at the input,
417 // so set to unknown and skip any remaining processing
418 if (!pInp[zMI].pRxParams) {
419 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
420 (Int8)PAF_SOURCE_UNKNOWN, GATEMP_INDEX_DEC);
422 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
423 return FALSE; // No error, but input is not ready for processing
424 }
426 // If here then we have a valid input so query its status
427 *asipErrno = asitUpdateInputStatus(pInp[zMI].pRxParams,
428 &pAstCfg->xInp[zMI].inpBufStatus,
429 &pAstCfg->xInp[zMI].inpBufConfig);
430 if(*asipErrno) {
431 TRACE_VERBOSE1("TaskAsip: updateInputStatus returns 0x%x", *asipErrno);
432 return FALSE; // Input is not ready for processing due to error
433 }
435 // If master decoder is not enabled, or the input is unlocked, then do nothing
436 mode = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
437 GATEMP_INDEX_DEC);
438 if (!mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
439 {
440 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
441 return FALSE; // No error, but input is not ready for processing
442 }
444 // Check selected source: sourceSelect is set by another task, AIP or AFP
445 sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
446 GATEMP_INDEX_DEC);
447 // If no source selected then do nothing
448 if(sourceConfig == PAF_SOURCE_NONE) {
449 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
450 (Int8)PAF_SOURCE_NONE, GATEMP_INDEX_DEC);
451 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
452 return FALSE; // No error, but input is not ready for processing
453 }
455 // If we want pass processing then proceed directly
456 if (sourceConfig == PAF_SOURCE_PASS)
457 {
458 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
459 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
460 (Int8)PAF_SOURCE_PASS, GATEMP_INDEX_DEC);
462 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
463 if (pP->fxns->passProcessing) {
464 *asipErrno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
465 }
466 else {
467 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, asipErrno 0x%x",
468 as+zMS, ASPERR_PASS);
469 *asipErrno = ASPERR_PASS;
470 }
472 TRACE_VERBOSE0("TaskAsip: continue");
473 return FALSE; // Error or not, input is not ready for processing
474 }
476 // No error and input processing is ready
477 return TRUE;
478 } /* asitPrepareProcessing */
481 /*===========================================================================
482 * ASIT Source Detection:
483 * ASIT processing for input source identification:
484 * - mark I/O PHY transfer completion
485 * - run auto-detection via I/O DATA in asitInputDataProcess
486 * - mark I/O DATA read completion
487 * - check auto-detection status and take corresponding actions if either
488 * PCM or bitstream is identified:
489 * - decide input source
490 * - update I/O components
491 * - reconfigure McASP LLD if it is PCM
492 * - start next I/O PHY transfer
493 ============================================================================*/
494 Int asitSourceDetection(const PAF_ASIT_Params *pP,
495 const PAF_ASIT_Patchs *pQ,
496 PAF_ASIT_Config *pAsitCfg)
497 {
498 PAF_AST_Config *pAstCfg;
499 PAF_AST_IoInp *pInp; // I/O components for input
500 Int zMD, mcaspErr, asitErr;
501 ioDataAutoDetStat_t autoDetStatus;
503 pAstCfg = pAsitCfg->pAstCfg; // pointer to AST common (shared) configuration
504 zMD = pAstCfg->masterDec;
505 pInp = &pAsitCfg->pIoInp[zMD]; // pointer to input I/O components
507 // Marks I/O PHY transfer and I/O BUFF write complete
508 asitPhyTransferComplete(pInp);
510 // Process input data - either searching SYNC for PCM or checking SYNC for bitstream
511 asitErr = asitInputDataProcess(pInp, &autoDetStatus);
512 if(asitErr != ASIT_NO_ERR) {
513 // Even though there is error, still need to start next transfer to
514 // maintain McASP transfer.
515 asitPhyTransferStart(pInp);
517 return asitErr;
518 }
520 // Mark input data read complete
521 ioDataReadComplete(pInp->hIoData);
523 if(autoDetStatus.syncTimeOut) {
524 return ASIT_AUTODET_TIME_OUT;
525 }
526 // Check if bitstream or PCM is detected
527 else if( autoDetStatus.syncState == IODATA_SYNC_BITSTREAM
528 || autoDetStatus.syncState == IODATA_SYNC_PCM) {
529 // Decide input source and inform decoder
530 asitErr = asitDecideSource(pAstCfg, pInp, &autoDetStatus);
531 if(asitErr != ASIT_NO_ERR) {
532 return asitErr;
533 }
534 else {
535 // Update I/O components and input buffer config
536 asitUpdateIoComps(pP, pAstCfg, pInp, &autoDetStatus);
538 // set to unknown so that we can ensure, for IOS purposes, that
539 // sourceDecode = NONE iff we are in this top level state machine
540 // and specifically not in decodeProcessing
541 #ifndef DEBUG_SKIP_DECODING
542 pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN);
543 #endif
545 if(autoDetStatus.syncState == IODATA_SYNC_BITSTREAM) {
546 // Input is bit stream: go to decoding
547 pInp->asipState = ASIT_DECODE_PROCESSING;
548 }
549 else {
550 // Input is PCM: stop swapping data
551 pInp->swapData = FALSE;
553 // Reconfigure McASP LLD to transfer 32-bit unpacked data
554 mcaspErr = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_32);
555 if(mcaspErr != Aud_EOK) {
556 return ASIT_ERR_MCASP_CFG;
557 }
559 // Adjust I/O BUFF delay and read pointer - to make sure read pointers
560 // always point to PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
561 ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
563 // Go to transition state to switch to PCM
564 pInp->asipState = ASIT_PCM_TRANSITION;
565 }
566 }
567 }
568 else {
569 // SYNC search ongoing, no action is needed
570 }
572 // Start next transfer
573 asitPhyTransferStart(pInp);
575 return (ASIT_NO_ERR);
576 } /* asitSourceDetection */
579 /*===========================================================================
580 //
581 // which will cause all 0's in one McASP LLD transfer. This will
582 // be detected as loss of SYNC by auto detection. To prevent that,
583 // skip I/O DATA process for hangover period so that this all 0's
584 // frame will not be seen by auto-detection. Also, playing out PCM
585 // needs to be skipped as well, to prevent from playing out garbage
586 // (16-bit packed data).
587 *
588 * ASIT Transition to PCM decoding.
589 * When PCM is detected, McASP LLD will be reconfigured to transmit 32-bit
590 * words, which will modify the RFMT register. This will cause all 0's in
591 * one McASP LLD transfer, which would be detected as loss of SYNC by auto
592 * detection (performed by I/O DATA). To prevent that, skip I/O DATA process
593 * for hangover period so that this all-0's frame will not be seen by the
594 * auto-detection.
595 *
596 * In addition, playing out PCM should be skipped as well to prevent from
597 * playing out the 16-bit packed data that's still in the input buffer.
598 *
599 * This function does the following:
600 * - mark I/O PHY transfer completion
601 * - bypass I/O DATA
602 * - start next I/O PHY transfer
603 ============================================================================*/
604 Int asitPcmTransition(PAF_ASIT_Config *pAsitCfg)
605 {
606 Int asitErr;
607 PAF_AST_IoInp *pInp; // I/O components for input
608 Int zMD;
610 zMD = pAsitCfg->pAstCfg->masterDec; // pointer to AST common (shared) configuration
611 pInp = &pAsitCfg->pIoInp[zMD]; // pointer to input I/O components
613 // Marks I/O PHY transfer and I/O BUFF write complete
614 asitPhyTransferComplete(pInp);
616 // Bypass I/O data processing due to McASP LLD work around
617 // (refer to comments inside the function)
618 asitErr = asitBypassIoData(pInp);
620 pInp->pcmSwitchHangOver--;
621 if(pInp->pcmSwitchHangOver == 0) {
622 pInp->asipState = ASIT_DECODE_PROCESSING;
623 }
624 else {
625 ; // stay in this state
626 }
628 // Start next transfer
629 asitPhyTransferStart(pInp);
631 return asitErr;
633 } /* asitPcmTransition */
635 /*============================================================================
636 * ASIT Bypass I/O DATA Processing
637 * This function bypasses the I/O DATA processing. It maintains the read
638 * operation of I/O BUFF by directly calling I/O BUFF APIs. When I/O DATA
639 * is not bypassed, I/O BUFF read operation is invoked by I/O DATA.
640 *
641 ============================================================================*/
642 Int asitBypassIoData(PAF_AST_IoInp *pInp)
643 {
644 void *buff1, *buff2;
645 size_t size1, size2;
647 // Get read pointers (or sub-buffers) of the input buffer
648 if (ioBuffGetReadPtrs(pInp->hIoBuff, pInp->phyXferSize,
649 &buff1, &size1, &buff2, &size2)
650 == IOBUFF_ERR_UNDERFLOW) {
651 pInp->numUnderflow += 1;
653 // Return since there is no enough data to process
654 return ASIT_ERR_INPBUF_UNDERFLOW;
655 }
657 ioBuffReadComplete(pInp->hIoBuff, buff1, size1);
659 if(buff2 != NULL) {
660 ioBuffReadComplete(pInp->hIoBuff, buff2, size2);
661 }
663 return ASIT_NO_ERR;
664 } /* asitBypassIoData */
667 /*============================================================================
668 * ASIT Decode Processing
669 * This function performs the decode processing and does the following based
670 * on the ASIT events:
671 * - initialize the decode processing if it is the first time
672 * - if there is ASIT INPUT DATA event (ASIT_EVTMSK_INPDATA):
673 * - mark I/O PHY transfer completion
674 * - run auto-detection via I/O DATA in asitInputDataProcess
675 * - check auto-detection status and take corresponding actions if SYNC
676 * is lost.
677 * - start next I/O PHY transfer
678 * - map ASIT events to decoding messages
679 * - invoke decDecodeFsm() and pass the mapped decoding messages
680 * - if there is ASIT DECODE ACK event (ASIT_EVTMSK_DECACK)
681 * - mark I/O DATA read completion
682 * - error handling
683 ============================================================================*/
684 Int asitDecodeProcessing(const PAF_ASIT_Params *pP,
685 const PAF_ASIT_Patchs *pQ,
686 PAF_ASIT_Config *pAsitCfg,
687 UInt asitEvents)
688 {
689 Int asitErr, decErr;
690 PAF_AST_IoInp *pInp; // I/O components for input
691 AspMsgMaster_Handle hAspMsgMaster; // ASIT message master handle
692 asipDecProc_t *pDec;
693 ioDataAutoDetStat_t autoDetStatus;
694 Int zMD;
695 UInt decMsg;
696 Int status;
698 zMD = pAsitCfg->pAstCfg->masterDec; // pointer to AST common (shared) configuration
699 pInp = &pAsitCfg->pIoInp[zMD]; // pointer to input I/O components
700 hAspMsgMaster = pAsitCfg->hAspMsgMaster; // get ASIT message master handle
701 pDec = &pAsitCfg->inpDec;
703 // Initialization for decode processing when this function is called the first time
704 #ifndef DEBUG_SKIP_DECODING
705 if(!pDec->initDone) {
706 // Initialize decoder
707 decDecodeInit(pP, pAsitCfg, pInp->sourceSelect);
709 pDec->initDone = TRUE;
710 }
711 #endif
713 // Process input data if this is a data ready message
714 if(asitEvents & ASIT_EVTMSK_INPDATA) {
715 TRACE_TERSE0("asitDecodeProcessing: process input data.");
717 // Marks I/O PHY transfer and I/O BUFF write complete
718 asitPhyTransferComplete(pInp);
720 // Process input data - either search SYNC for PCM or check SYNC for bitstream
721 asitErr = asitInputDataProcess(pInp, &autoDetStatus);
723 if(asitErr == ASIT_NO_ERR) {
724 ioDataReadComplete(pInp->hIoData);
726 // Check if SYNC is maintained or lost (stream stops or format changes)
727 if(autoDetStatus.syncState == IODATA_SYNC_NONE) {
728 // SYNC lost: change I/O PHY transfer size to default for auto-detection
729 //asitErr = asitRecfgPhyXfer(pInp, INPUT_FRAME_SIZE_DEF);
730 //if(asitErr != ASIT_NO_ERR) {
731 // return asitErr;
732 //}
734 // Inform decoder to complete the decoding of previous frame - is this good?
735 pInp->sourceSelect = PAF_SOURCE_NONE;
736 pInp->numFrameReceived = 0; // for debugging
737 TRACE_TERSE0("asitDecodeProcessing: SYNC lost.");
739 #ifdef DEBUG_SKIP_DECODING
740 asitErr = ASIT_ERR_DECODE_QUIT;
741 #endif
742 }
743 else {
744 pInp->numFrameReceived += 1; // for debugging
746 // Communicate input stream information to decoder through input
747 // buffer configuration -- this was moved inside decDecodeFsm
748 //asitUpdateInpBufConfig(pAsitCfg->pAstCfg, pInp);
750 // Start next transfer
751 asitPhyTransferStart(pInp);
752 }
754 // Start next transfer
755 //asitPhyTransferStart(pInp);
757 #ifdef DEBUG_SKIP_DECODING
758 return asitErr;
759 #endif
760 }
761 else if(asitErr == ASIT_ERR_INPBUF_UNDERFLOW) {
762 TRACE_TERSE0("asitDecodeProcessing: Input buffer underflows.");
764 // When input buffer underflows, it is not an error but decoding needs
765 // to be skipped as there is not enough data in the buffer.
766 asitPhyTransferStart(pInp);
768 return asitErr;
769 }
770 else {
771 // Inform decoder to complete the decoding of previous frame - is this good?
772 pInp->sourceSelect = PAF_SOURCE_NONE;
773 pInp->numFrameReceived = 0; // for debugging
774 TRACE_TERSE1("asitDecodeProcessing: asitInputDataProcess error: %d", asitErr);
776 #ifdef DEBUG_SKIP_DECODING
777 return ASIT_ERR_DECODE_QUIT;
778 #endif
779 }
780 } /* ASIT_EVTMSK_INPDATA */
781 #ifdef DEBUG_SKIP_DECODING
782 else {
783 TRACE_TERSE0("asitDecodeProcessing: events error.");
784 return ASIT_ERR_EVENTS;
785 }
786 #endif
788 #ifndef DEBUG_SKIP_DECODING
789 // Map ASIT events to decode messages
790 decMsg = asitEventsToDecMsg(asitEvents);
792 // Pass messages (corresponding to events) to decode FSM
793 decErr = decDecodeFsm(pP, pQ, pAsitCfg, pInp->sourceSelect, decMsg);
795 // Mark I/O DATA read complete if decoder indicates decoding is done.
796 if((asitEvents & ASIT_EVTMSK_DECACK)) { // DECACK -> decoding done
797 //ioDataReadComplete(pInp->hIoData);
798 }
800 if(decErr != DEC_NO_ERR) {
801 TRACE_VERBOSE0("TaskAsip: send DEC_EXIT message to slave decoder.");
803 // Send dec exit message to slave decoder
804 status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_EXIT, NULL);
805 if (status != ASP_MSG_NO_ERR)
806 {
807 TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
808 SW_BREAKPOINT;
809 }
810 status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_EXIT_DONE, NULL, TRUE);
811 if (status != ASP_MSG_NO_ERR)
812 {
813 TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
814 SW_BREAKPOINT;
815 }
817 return ASIT_ERR_DECODE_QUIT; // This is not necessarily an error
818 }
819 else {
820 return ASIT_NO_ERR;
821 }
822 #endif
823 } /* asitDecodeProcessing */
826 /*============================================================================
827 * ASIT Input Data Processing:
828 * - invoke ioDataProcess() to inspect input data for
829 * - initial auto-detection, or
830 * - background scanning for PCM data, or
831 * - SYNC check for bitstream
832 * - return auto-detection status (SYNC detected, SYNC loss, etc)
833 ============================================================================*/
834 Int asitInputDataProcess(PAF_AST_IoInp *pInp, ioDataAutoDetStat_t *pAutoDetStats)
835 {
836 Int ioDataErr, retVal;
837 ioDataCtl_t ioDataCtl;
839 // Perform auto-detection inside I/O DATA component
840 ioDataErr = ioDataProcess(pInp->hIoData);
842 if(ioDataErr == IODATA_NO_ERR) {
843 // Normal operation - check auto-detection status
844 ioDataCtl.code = IODATA_CTL_GET_AUTODET_STATUS;
845 ioDataControl(pInp->hIoData, &ioDataCtl);
847 *pAutoDetStats = ioDataCtl.param.autoDetStats;
849 retVal = ASIT_NO_ERR;
850 }
851 else if(ioDataErr == IODATA_ERR_IOBUF_UNDERFLOW) {
852 // Input buffer underflows - there is no enough data to process.
853 // This is not error and no action is needed.
854 pInp->numUnderflow += 1; // debug
856 retVal = ASIT_ERR_INPBUF_UNDERFLOW;
857 }
858 else {
859 // Something is wrong: print error log and return
860 //printf("IODATA processing error!\n");
861 retVal = ASIT_ERR_INPDATA_PROC;
862 }
864 return retVal;
865 } /* asitInputDataProcess */
867 /*============================================================================
868 * Mapping ASIT Events to Decoding Messages
869 ============================================================================*/
870 UInt asitEventsToDecMsg(UInt asitEvents)
871 {
872 UInt decMsg = 0;
874 if (asitEvents & ASIT_EVTMSK_INPDATA) {
875 // Input data event
876 decMsg |= DEC_MSGMSK_INPDATA;
877 }
879 // temp, simulation
880 //if(asitEvents & ASIT_EVTMSK_INFOACK) {
881 // decMsg |= DEC_MSGMSK_INFOACK;
882 //}
884 // temp, simulation
885 //if(asitEvents & ASIT_EVTMSK_DECACK) {
886 // decMsg |= DEC_MSGMSK_DECACK;
887 //}
889 if (asitEvents & ASIT_EVTMSK_RXACK)
890 {
891 // Receive acknowledge message event
892 decMsg |= DEC_MSGMSK_RXACK;
893 }
895 return decMsg;
896 } /* asitEventsToDecMsg */
898 /*===========================================================================
899 * Initialize I/O components for input processing
900 ============================================================================*/
901 int asitIoCompsInit(PAF_AST_InpBuf * pInpBuf, PAF_AST_IoInp * pInpIo)
902 {
903 ioBuffParams_t ioBuffParams;
904 ioPhyParams_t ioPhyParams;
905 ioDataParam_t ioDataCfg;
906 ioPhyCtl_t ioPhyCtl;
908 if (pInpIo->hMcaspChan != NULL)
909 {
910 //pInpIo->phyXferSize = INPUT_FRAME_SIZE_DEF;
911 pInpIo->phyXferSize = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF * WORD_SIZE_BITSTREAM;
913 if (pInpIo->firstTimeInit) {
914 TRACE_VERBOSE0("Initialize I/O BUFF and I/O PHY.");
915 ioBuffParams.base = pInpBuf->inpBufConfig.base.pVoid;
916 ioBuffParams.size = pInpBuf->inpBufConfig.allocation / STRIDE_WORST_CASE
917 * STRIDE_WORST_CASE;
918 ioBuffParams.sync = IOBUFF_WRITE_SYNC;
919 ioBuffParams.nominalDelay = INPUT_FRAME_SIZE_DEF;
920 if (ioBuffInit(pInpIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) {
921 return (ASIT_ERR_IOBUFF_INIT); // to remove magic number
922 }
924 ioPhyParams.ioBuffHandle = pInpIo->hIoBuff;
925 ioPhyParams.xferFrameSize = pInpIo->phyXferSize;
926 ioPhyParams.mcaspChanHandle = pInpIo->hMcaspChan;
927 ioPhyParams.ioBuffOp = IOPHY_IOBUFFOP_WRITE;
928 if (ioPhyInit(pInpIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) {
929 return (ASIT_ERR_IOPHY_INIT); // to remove magic number
930 }
932 pInpIo->numPrimeXfers = NUM_PRIME_XFERS;
933 }
935 /* Reinitialize I/O DATA every time when ASIT restarts */
936 TRACE_VERBOSE0("Initialize I/O DATA.");
937 ioDataCfg.ioBuffHandle = pInpIo->hIoBuff;
938 ioDataCfg.unknownSourceTimeOut = pInpBuf->inpBufConfig.pBufStatus->unknownTimeout;
939 ioDataCfg.frameLengthsIEC = (uint_least16_t *)&iecFrameLength[0];
940 ioDataCfg.frameLengthPCM = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF;
941 ioDataCfg.frameLengthDef = pInpIo->stride * NUM_CYCLE_PER_FRAME_DEF;
942 ioDataCfg.ibMode = pInpBuf->inpBufConfig.pBufStatus->mode;
943 ioDataCfg.zeroRunRestart = pInpBuf->inpBufConfig.pBufStatus->zeroRunRestart;
944 ioDataCfg.zeroRunTrigger = pInpBuf->inpBufConfig.pBufStatus->zeroRunTrigger;
946 if (ioDataInit(pInpIo->hIoData, &ioDataCfg) != IODATA_NO_ERR) {
947 return (ASIT_ERR_IODATA_INIT); // to remove magic number
948 }
950 if (pInpIo->firstTimeInit) {
951 /* Initialize I/O BUFF and I/O PHY only when input interface changes. */
952 TRACE_VERBOSE0("Prime I/O PHY.");
954 // Start I/O physical layer by priming McASP LLD for input
955 asitIoPhyPrime(pInpIo);
957 pInpIo->firstTimeInit = FALSE;
958 }
959 else {
960 // Reconfigure I/O PHY transfer size
961 ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
962 ioPhyCtl.params.xferFrameSize = pInpIo->phyXferSize;
963 ioPhyControl(pInpIo->hIoPhy, &ioPhyCtl);
964 #if 0
965 // If previous stream before reset was PCM, reconfigure McASP LLD to receive 16-bit packed bits
966 if (!pInpIo->swapData) {
967 Int mcaspErr;
968 mcaspErr = mcaspRecfgWordWidth(pInpIo->hMcaspChan, Mcasp_WordLength_16);
969 if(mcaspErr != Aud_EOK) {
970 return ASIT_ERR_MCASP_CFG;
971 }
973 // Start swapping data
974 pInpIo->swapData = TRUE;
975 TRACE_VERBOSE0("Reconfigure McASP word length and start swapping data.");
976 }
977 #endif
978 // Start PHY transfer
979 TRACE_VERBOSE0("Start I/O PHY transfer.");
980 asitPhyTransferStart(pInpIo);
981 }
982 }
984 return 0;
985 } /* asitIoCompsInit */
987 /*======================================================================================
988 * This function initializes ASIT processing
989 *====================================================================================*/
990 void asitProcInit(PAF_AST_IoInp *pInp, asipDecProc_t *pDec)
991 {
992 // pInp->swapData = TRUE;
993 pInp->pcmSwitchHangOver = INPUT_SWITCH_HANGOVER;
994 pDec->initDone = FALSE;
995 pInp->numFrameReceived = 0;
996 }
998 /*======================================================================================
999 * I/O physical layer prime operation required by McASP LLD
1000 *====================================================================================*/
1001 void asitIoPhyPrime(PAF_AST_IoInp *pInp)
1002 {
1003 Int32 count;
1005 for(count = 0; count < pInp->numPrimeXfers; count++)
1006 {
1007 ioPhyXferSubmit(pInp->hIoPhy);
1008 #ifdef ASIP_DEBUG
1009 //pInp->numXferStart++;
1010 #endif
1011 }
1012 } /* asitIoPhyPrime */
1015 /*======================================================================================
1016 * This function marks the I/O PHY transfer as complete
1017 *====================================================================================*/
1018 void asitPhyTransferComplete(PAF_AST_IoInp * pInpIo)
1019 {
1020 // Mark underlining I/O BUFF write complete and swap data if needed
1021 ioPhyXferComplete(pInpIo->hIoPhy, pInpIo->swapData);
1022 } /* asitPhyTransferComplete */
1024 #if 0
1025 Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize)
1026 {
1027 ioPhyCtl_t ioPhyCtl;
1028 Int mcaspErr;
1030 ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
1031 ioPhyCtl.params.xferFrameSize = xferSize;
1032 ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
1034 pInp->phyXferSize = ioPhyCtl.params.xferFrameSize;
1036 if(!pInp->swapData) {
1037 // If it was PCM, reconfigure McASP LLD to receive 16-bit packed bits
1038 mcaspErr = mcaspRecfgWordWidth(pInp->hMcaspChan, Mcasp_WordLength_16);
1039 if(mcaspErr != Aud_EOK) {
1040 return ASIT_ERR_MCASP_CFG;
1041 }
1043 // Start swapping data
1044 pInp->swapData = TRUE;
1045 }
1047 return ASIT_NO_ERR;
1049 } /* asitRecfgPhyXfer */
1050 #endif
1052 /*======================================================================================
1053 * McASP LLD call back function
1054 *====================================================================================*/
1055 void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
1056 {
1057 /* post semaphore */
1058 if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
1059 //Semaphore_post(asipSemRx);
1060 Event_post(gAsitEvtHandle, ASIT_EVTMSK_INPDATA);
1061 } else {
1062 ; // intermediate packet due to buffer wrapping around
1063 }
1064 }
1066 /*======================================================================================
1067 * This function checks if McASP Rx for input overruns
1068 *====================================================================================*/
1069 int asipCheckMcaspRxOverrun(Ptr mcaspChanHandle)
1070 {
1071 Mcasp_errCbStatus mcaspErrStat;
1073 mcaspControlChan(mcaspChanHandle, Mcasp_IOCTL_CHAN_QUERY_ERROR_STATS, &mcaspErrStat);
1075 return (mcaspErrStat.isRcvOvrRunOrTxUndRunErr);
1076 }
1078 #if 0
1079 /*======================================================================================
1080 * This function restarts McASP LLD channel for input
1081 *====================================================================================*/
1082 void asipMcaspRxRestart(PAF_AST_IoInp *pInpIo)
1083 {
1084 mcaspRxReset();
1085 mcaspRxCreate();
1086 }
1087 #endif
1089 /*======================================================================================
1090 * This function starts an I/O PHY transfer
1091 *====================================================================================*/
1092 void asitPhyTransferStart(PAF_AST_IoInp *pInpIo)
1093 {
1094 Int ioPhyErr;
1096 if(asipCheckMcaspRxOverrun(pInpIo->hMcaspChan)) {
1097 #ifdef ASIP_DEBUG
1098 pInpIo->numInputOverrun++;
1099 #endif
1100 //asipMcaspRxRestart(pInpIo);
1101 System_abort("\nMcASP for input overruns! %d!\n");
1102 }
1103 else {
1104 ioPhyErr = ioPhyXferSubmit(pInpIo->hIoPhy);
1105 //if(ioPhyXferSubmit(pInpIo->hIoPhy)==IOPHY_ERR_BUFF_OVERFLOW) {
1106 if(ioPhyErr!=IOPHY_NOERR){
1107 printf("\n I/O PHY ioPhyXferSubmit fails with error %d!\n", ioPhyErr);
1108 // Input buffer overflows!
1109 //printf("\nInput buffer overflows!\n");
1110 exit(0);
1111 }
1112 else {
1113 // Input buffer operates normally
1114 ;
1115 }
1116 #ifdef ASIP_DEBUG
1117 //pInpIo->numXferStart++;
1118 #endif
1119 }
1120 }
1122 // Indicates whether Input has been selected
1123 Int d10Initialized = 0;
1125 //extern Aud_STATUS mcaspAudioConfig(void);
1126 //extern void McaspDevice_init(void);
1128 /*======================================================================================
1129 * This function initializes HW interface and selects the right device for input
1130 *====================================================================================*/
1131 Int asitSelectDevices(
1132 const PAF_ASIT_Patchs *pQ,
1133 PAF_AST_Config *pAstCfg,
1134 PAF_AST_IoInp *pInp
1135 )
1136 {
1137 Int32 status;
1138 Aud_STATUS audStatus;
1139 const PAF_SIO_Params *pInPrms;
1140 mcaspLLDconfig *pLldCfg;
1141 mcaspLLDconfig *pReqLldCfg;
1142 Ptr mcaspChanHandle;
1143 Int zMD;
1144 Int interface;
1145 const PAF_SIO_Params *pD10Params;
1146 UInt postedEvents;
1148 zMD = pAstCfg->masterDec;
1150 interface = pAstCfg->xInp[zMD].inpBufStatus.sioSelect; // obtain SIO select for input
1152 if (interface >= 0)
1153 {
1154 // Positive value for interface: new Input SIO update request has been received via alpha command.
1155 // Negative value for interface: no new Input SIO update request has been received,
1156 // previous requests have been processed.
1158 // check for valid index into device array
1159 if (interface >= pQ->devinp->n) // DEVINP_N
1160 {
1161 interface = 0; // treat as device InNone
1162 }
1164 //
1165 // Deactivate currently active interface
1166 //
1167 if (pInp->hMcaspChan != NULL) // non-NULL McASP LLD channel handle indicates there's an active interface
1168 {
1169 d10Initialized = 0; // indicate no Input selected
1171 // Reset channel
1172 status = mcaspControlChan(pInp->hMcaspChan, MCASP_CHAN_RESET, NULL); // Rx reset channel
1173 //status = mcaspControlChan(pInp->hMcaspChan, MCASP_DEVICE_RESET, NULL); // Reset Tx/Rx channel
1174 if (status != MCASP_COMPLETED)
1175 {
1176 Log_info0("asitSelectDevices(): McASP channel reset failed!\n");
1177 return ASIP_ERR_MCASP_CFG;
1178 }
1180 // Delete McASP LLD channel
1181 status = mcaspDeleteChan(pInp->hMcaspChan);
1182 if (status != MCASP_COMPLETED)
1183 {
1184 Log_info0("asitSelectDevices(): McASP channel deletion failed!\n");
1185 return ASIP_ERR_MCASP_CFG;
1186 }
1188 // Clear (drop) already posted Input data events
1189 postedEvents = Event_getPostedEvents(gAsitEvtHandle);
1190 while ((postedEvents & ASIT_EVTMSK_INPDATA) != 0)
1191 {
1192 Event_pend(gAsitEvtHandle, ASIT_EVTMSK_NONE, ASIT_EVTMSK_INPDATA, 0);
1193 postedEvents = Event_getPostedEvents(gAsitEvtHandle);
1194 }
1196 pInp->hMcaspChan = NULL; // reset active McASP LLD handle
1197 if (pInp->pRxParams != NULL) // sanity check, pInp->pRxParams should be non NULL if pInp->hMcaspChan is non NULL
1198 {
1199 pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
1200 pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig; // get pointer to active McASP LLD configuration
1201 pLldCfg->hMcaspChan = NULL; // reset McASP LLD handle for active McASP LLD configuration
1202 pInp->pRxParams = NULL; // reset pointer to active D10 parameters
1203 }
1204 else
1205 {
1206 // This is a programming error
1207 SW_BREAKPOINT; // debug
1208 }
1209 }
1211 //
1212 // Activate requested interface
1213 //
1214 pD10Params = (const PAF_SIO_Params *)pQ->devinp->x[interface]; // get D10 parameters for selected interface
1215 if (pD10Params != NULL)
1216 {
1217 //
1218 // Requested device is other than InNone
1219 //
1221 // Initialize Tx clock mux
1222 D10_initClkMux((void *)pD10Params);
1224 pReqLldCfg = (mcaspLLDconfig *)pD10Params->sio.pConfig;
1225 if (pReqLldCfg->hMcaspChan == NULL)
1226 {
1227 // Create McASP LLD channel
1228 mcaspChanHandle = NULL;
1229 audStatus = mcasplldChanCreate(pReqLldCfg, &mcaspChanHandle);
1230 if (audStatus != Aud_EOK)
1231 {
1232 Log_info0("asitSelectDevices(): McASP channel creation failed!\n");
1233 return ASIP_ERR_MCASP_CFG;
1234 }
1236 pReqLldCfg->hMcaspChan = mcaspChanHandle; // set McASP LLD handle for requested McASP LLD configuration
1237 pInp->pRxParams = (const void *)pD10Params; // set pointer to active D10 parameters
1238 pInp->hMcaspChan = pReqLldCfg->hMcaspChan; // set active McASP LLD handle
1240 // configure stride according to selected McASP LLD configuration
1241 pInp->stride = pReqLldCfg->mcaspChanParams->noOfSerRequested *
1242 pReqLldCfg->mcaspChanParams->noOfChannels;
1244 pInp->firstTimeInit = TRUE; // set flag for IO Phy & Buff initialization
1246 d10Initialized = 1; // indicate Input selected
1247 }
1248 }
1249 else
1250 {
1251 //
1252 // Requested device is InNone
1253 //
1254 pInp->hMcaspChan = NULL; // reset active McASP LLD handle
1255 pInp->pRxParams = NULL; // reset pointer to active D10 parameters
1256 }
1258 // indicate SIO update request processed
1259 pAstCfg->xInp[zMD].inpBufStatus.sioSelect = interface | 0x80;
1260 }
1262 if (pInp->hMcaspChan != NULL) // non NULL indicates there's an active interface
1263 {
1264 if (pInp->pRxParams != NULL) // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
1265 {
1266 pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
1267 pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig; // get currently active McASP LLD configuration
1268 if (pLldCfg != NULL) // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
1269 {
1270 // Configure McASP to receive 16/32-bit data according to default configuration
1271 mcaspRecfgWordWidth(pInp->hMcaspChan, pLldCfg->mcaspChanParams->wordWidth);
1273 // Set flag to swap HDMI data if it is 4xI2S and word length is 16
1274 if ((pLldCfg->mcaspChanParams->wordWidth == Mcasp_WordLength_16) &&
1275 (pLldCfg->mcaspChanParams->noOfSerRequested == 4))
1276 {
1277 pInp->swapData = TRUE;
1278 }
1279 else
1280 {
1281 pInp->swapData = FALSE;
1282 }
1283 }
1284 else
1285 {
1286 // This is a programming error
1287 SW_BREAKPOINT; // debug
1288 }
1290 }
1291 else
1292 {
1293 // This is a programming error
1294 SW_BREAKPOINT; // debug
1295 }
1296 }
1298 return ASIP_NO_ERR;
1299 } /* asitSelectDevices */
1301 /*======================================================================================
1302 * This function updates input status
1303 *====================================================================================*/
1304 Int asitUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
1305 PAF_InpBufConfig *pInpBuf)
1306 {
1307 Int asipErrno;
1309 PAF_SIO_InputStatus inputStatus;
1311 // initialize all values to unknown so that device specific
1312 // driver layer need only fill in those entries that it is aware of.
1313 // This allows extensibility of the structure without requiring users
1314 // to re-code.
1315 inputStatus.lock = 0;
1316 inputStatus.sampleRateData = PAF_SAMPLERATE_UNKNOWN;
1317 inputStatus.sampleRateMeasured = PAF_SAMPLERATE_UNKNOWN;
1318 inputStatus.nonaudio = PAF_IEC_AUDIOMODE_UNKNOWN;
1319 inputStatus.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
1321 //more configuration is needed to abstract out D10
1322 asipErrno = D10_RxControl(pRxParams,
1323 (Uns)PAF_SIO_CONTROL_GET_INPUT_STATUS,
1324 (Arg) &inputStatus);
1325 if (asipErrno) {
1326 return asipErrno;
1327 }
1328 pStatus->sampleRateData = inputStatus.sampleRateData;
1329 pStatus->sampleRateMeasured = inputStatus.sampleRateMeasured;
1330 pStatus->nonaudio = inputStatus.nonaudio;
1331 pStatus->emphasisData = inputStatus.emphasis;
1333 // if MSB of override clear then use as reported lock
1334 // if = 0x80 then use default [0x81]
1335 // if = 0x81 then use measured (from device)
1336 // others not defined or implemented
1337 if ((pStatus->lockOverride & (XDAS_Int8)0x80) == 0)
1338 pStatus->lock = pStatus->lockOverride;
1339 else if (pStatus->lockOverride == (XDAS_Int8)0x80)
1340 pStatus->lock = inputStatus.lock;
1341 else if (pStatus->lockOverride == (XDAS_Int8)0x81)
1342 pStatus->lock = inputStatus.lock;
1344 // if MSB of override clear then use it as sample rate for system,
1345 // if = 0x80 then use default [0x82]
1346 // if = 0x81 then use data
1347 // if = 0x82 then use measured
1348 // others not defined or implemented
1349 if ((pStatus->sampleRateOverride & (XDAS_Int8)0x80) == 0)
1350 pStatus->sampleRateStatus = pStatus->sampleRateOverride;
1351 else if (pStatus->sampleRateOverride == (XDAS_Int8)0x80)
1352 pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
1353 else if (pStatus->sampleRateOverride == (XDAS_Int8)0x81)
1354 pStatus->sampleRateStatus = pStatus->sampleRateData;
1355 else if (pStatus->sampleRateOverride == (XDAS_Int8)0x82)
1356 pStatus->sampleRateStatus = pStatus->sampleRateMeasured;
1358 // Update emphasis status:
1359 if ((pStatus->emphasisOverride & (XDAS_Int8)0x80) == 0) {
1360 if (pStatus->emphasisData == PAF_IEC_PREEMPHASIS_YES)
1361 pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
1362 else
1363 pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
1364 }
1365 else if (pStatus->emphasisOverride ==
1366 (XDAS_Int8 )(0x80+PAF_IEC_PREEMPHASIS_YES))
1367 pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_YES;
1368 else /* IBEmphasisOverrideNo or other */
1369 pStatus->emphasisStatus = PAF_IEC_PREEMPHASIS_NO;
1371 // Update precision control
1372 pInpBuf->precision = pStatus->precisionInput =
1373 pStatus->precisionOverride < 0
1374 ? pStatus->precisionDefault
1375 : pStatus->precisionOverride > 0
1376 ? pStatus->precisionOverride
1377 : pStatus->precisionDetect > 0
1378 ? pStatus->precisionDetect
1379 : pStatus->precisionDefault;
1381 return 0;
1382 }
1385 /*==============================================================================
1386 * This function updates input buffer config based on frame information provided
1387 * by I/O DATA.
1388 ==============================================================================*/
1389 void asitUpdateInpBufConfig(PAF_AST_Config *pAstCfg, PAF_AST_IoInp *pInp)
1390 {
1391 PAF_InpBufConfig *pBufConfig;
1392 ioDataCtl_t ioDataCtl;
1394 /* Get information for reading input data */
1395 ioDataCtl.code = IODATA_CTL_GET_INPBUFFINFO;
1396 ioDataControl(pInp->hIoData, &ioDataCtl);
1398 if(ioDataCtl.param.dataReadInfo.frameSize != pInp->phyXferSize) {
1399 // Fatal error!
1400 TRACE_VERBOSE0("TaskAsip: error in updating I/O");
1401 SW_BREAKPOINT;
1402 }
1404 pBufConfig = &(pAstCfg->xInp[pAstCfg->masterDec].inpBufConfig);
1406 //JXTODO: do we need to gate here?
1407 //key = GateMP_enter(gateHandle);
1409 pBufConfig->base.pVoid = ioDataCtl.param.dataReadInfo.buffBase;
1410 pBufConfig->sizeofBuffer = ioDataCtl.param.dataReadInfo.buffSize;
1411 pBufConfig->pntr.pSmInt = ioDataCtl.param.dataReadInfo.startAddress;
1413 // Leave the gate
1414 //GateMP_leave(gateHandle, key);
1416 TRACE_TERSE2("Frame start address: 0x%x., preamble: 0x%x",
1417 (UInt)ioDataCtl.param.dataReadInfo.startAddress,
1418 *(UInt *)ioDataCtl.param.dataReadInfo.startAddress);
1419 }
1421 /*==============================================================================
1422 * Decide source after SYNC is found, i.e. either bitstream preamble is detected
1423 * or it times out to PCM.
1424 ==============================================================================*/
1425 Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp *pInp,
1426 ioDataAutoDetStat_t *autoDetStatus)
1427 {
1428 Int sourceConfig, sourceSelect, sourceProgram;
1429 Int zMD;
1430 char asipMsgBuf[ASP_MSG_BUF_LEN];
1431 Int status;
1433 // Get the configured source
1434 zMD = pAstCfg->masterDec;
1435 sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1436 GATEMP_INDEX_DEC);
1438 if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
1439 if (sourceConfig == PAF_SOURCE_DSD1 || sourceConfig == PAF_SOURCE_DSD2 ||
1440 sourceConfig == PAF_SOURCE_DSD3) {
1441 sourceProgram = sourceConfig;
1442 }
1443 else {
1444 sourceProgram = PAF_SOURCE_PCM;
1445 }
1446 }
1448 if(autoDetStatus->syncState == IODATA_SYNC_BITSTREAM) {
1449 uint_least16_t pc = autoDetStatus->bitStreamInfo & SYNC_PC_MASK; //0x001F
1450 sourceProgram = IECpafSource[pc];
1451 }
1453 // write the decided source program to memory
1454 sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), sourceProgram,
1455 GATEMP_INDEX_DEC);
1457 // now that we have some input classification, and possibly an outstanding
1458 // input frame, we determine whether or not to call decodeProcessing and with
1459 // what decAlg.
1460 sourceSelect = PAF_SOURCE_NONE;
1462 switch (sourceConfig)
1463 {
1464 // If autodetecting, decoding everything, and input is something
1465 // (i.e. bitstream or PCM) then decode.
1466 case PAF_SOURCE_AUTO:
1467 if (sourceProgram >= PAF_SOURCE_PCM) {
1468 sourceSelect = sourceProgram; // use whatever from autodet
1469 }
1470 break;
1472 // If autodetecting, decoding only PCM, and input is PCM then decode.
1473 case PAF_SOURCE_PCMAUTO:
1474 if (sourceProgram == PAF_SOURCE_PCM) {
1475 // only expect autodet to give PAF_SOURCE_PCM, otherwise set to NONE
1476 sourceSelect = sourceProgram;
1477 }
1478 break;
1480 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
1481 case PAF_SOURCE_BITSTREAM:
1482 if (sourceProgram >= PAF_SOURCE_AC3) {
1483 sourceSelect = sourceProgram;
1484 }
1485 break;
1487 // If autodetecting, decoding only DTS, and input is DTS then decode.
1488 case PAF_SOURCE_DTSALL:
1489 switch (sourceProgram)
1490 {
1491 case PAF_SOURCE_DTS11:
1492 case PAF_SOURCE_DTS12:
1493 case PAF_SOURCE_DTS13:
1494 case PAF_SOURCE_DTS14:
1495 case PAF_SOURCE_DTS16:
1496 case PAF_SOURCE_DTSHD:
1497 sourceSelect = sourceProgram;
1498 break;
1499 }
1500 break;
1502 // All others, e.g., force modes, fall through to here.
1503 // If user made specific selection then program must match select.
1504 // (NB: this compare relies on ordering of PAF_SOURCE)
1505 default:
1506 sourceSelect = sourceConfig;
1507 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N)) {
1508 if (sourceProgram != sourceSelect) {
1509 sourceSelect = PAF_SOURCE_NONE;
1510 }
1511 }
1512 break;
1513 }
1515 // if we didn't find any matches then skip
1516 if (sourceSelect == PAF_SOURCE_NONE) {
1517 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
1518 return ASIT_ERR_NO_MATCHING_SOURCE;
1519 }
1521 #ifndef DEBUG_SKIP_DECODING
1522 // send source select message to slave
1523 *(Int32 *)&asipMsgBuf[0] = sourceSelect;
1524 status = AspMsgSnd(gPAF_ASIT_config.hAspMsgMaster, ASP_SLAVE_DEC_SOURCE_SELECT, asipMsgBuf);
1525 if (status != ASP_MSG_NO_ERR)
1526 {
1527 TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
1528 SW_BREAKPOINT;
1529 }
1530 status = AspMsgRcvAck(gPAF_ASIT_config.hAspMsgMaster, ASP_MASTER_DEC_SOURCE_SELECT_DONE, NULL, TRUE);
1531 if (status != ASP_MSG_NO_ERR)
1532 {
1533 TRACE_VERBOSE0("TaskAsip: error in receiving SOURCE_SELECT ack message");
1534 SW_BREAKPOINT;
1535 }
1536 #endif
1538 pInp->sourceSelect = sourceSelect;
1539 pInp->sourceProgram = sourceProgram;
1541 return ASIT_NO_ERR;
1542 } /* asitDecideSource */
1544 /*==============================================================================
1545 * After SYNC is found, i.e. either bitstream preamble is detected or it times
1546 * out to PCM, update input buffer config and I/o components accordingly.
1547 ==============================================================================*/
1548 Int asitUpdateIoComps(const PAF_ASIT_Params *pP, PAF_AST_Config *pAstCfg,
1549 PAF_AST_IoInp *pInp, ioDataAutoDetStat_t *autoDetStatus)
1550 {
1551 Int sourceConfig;
1552 Int zMD, deliverZeros;
1553 int ioFrameLength, decFrameLength;
1554 PAF_InpBufConfig *pBufConfig;
1555 ioPhyCtl_t ioPhyCtl;
1556 ioDataCtl_t ioDataCtl;
1558 zMD = pAstCfg->masterDec;
1559 pBufConfig = &pAstCfg->xInp[zMD].inpBufConfig;
1561 // Compute decoder frame length based on source selection
1562 decFrameLength = getFrameLengthSourceSel(pP, pInp->sourceSelect);
1564 pAstCfg->xDec[zMD].decodeControl.frameLength = decFrameLength;
1565 pAstCfg->xDec[zMD].decodeInStruct.sampleCount = decFrameLength;
1566 pAstCfg->xDec[zMD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
1568 // Decide frame length for I/O DATA and I/O PHY
1569 if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
1570 // For PCM, I/O frame length is decode frame length multiplied by stride
1571 ioFrameLength = decFrameLength * pInp->stride;
1573 pBufConfig->sizeofElement = WORD_SIZE_PCM;
1574 pBufConfig->frameLength = pBufConfig->lengthofData = ioFrameLength;
1576 // Configure I/O DATA PCM frame length
1577 ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
1578 ioDataCtl.param.frameLengthPcm = ioFrameLength;
1579 ioDataControl(pInp->hIoData, &ioDataCtl);
1581 // Change I/O PHY transfer size to PCM frame size
1582 pInp->phyXferSize = ioFrameLength*(WORD_SIZE_PCM);
1584 // Adjust I/O BUFF delay and read pointer - to make sure read pointers always point to
1585 // PCM data from 1st I2S (out of 4 for HDMI 4xI2S)
1586 // Adjust delay and don't mark input buffer as read complete
1587 //ioBuffAdjustDelay(pInp->hIoBuff, pInp->phyXferSize);
1589 // Stop swapping data
1590 //pInp->swapData = FALSE;
1591 }
1592 else {
1593 // For bitstream, I/O frame length is the frame length of the bitstream
1594 uint_least16_t pc = autoDetStatus->bitStreamInfo & SYNC_PC_MASK; //0x001F
1595 ioFrameLength = iecFrameLength[pc];
1597 /*
1598 if( (pc == 0x11) && (DTSHDSubType == 3)
1599 && (PAF_ASP_sampleRateHzTable[pBufConfig->pBufStatus->sampleRateStatus][PAF_SAMPLERATEHZ_STD] <=48000.0))
1600 pDevExt->sourceProgram = PAF_SOURCE_DXP; // LBR is 23
1602 if (pc == 1)
1603 pDevExt->elementSize = 4288;
1604 else if (pc == 0x11) {
1605 pDevExt->frameLength = (pDevExt->pIECFrameLength[pc] << DTSHDSubType);
1606 pDevExt->lengthofData = pDevExt->frameLength;
1607 }
1608 */
1610 pBufConfig->sizeofElement = WORD_SIZE_BITSTREAM;
1611 pBufConfig->frameLength = ioFrameLength;
1612 pBufConfig->lengthofData = ioFrameLength - IEC_HEADER_LENGTH;
1614 // Change I/O PHY transfer size to bitstream frame size
1615 pInp->phyXferSize = ioFrameLength*WORD_SIZE_BITSTREAM;
1616 }
1618 pBufConfig->stride = pInp->stride; // common for PCM and bitstream
1620 // Configure I/O PHY transfer size
1621 ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
1622 ioPhyCtl.params.xferFrameSize = pInp->phyXferSize;
1623 ioPhyControl(pInp->hIoPhy, &ioPhyCtl);
1625 // Decide if zeros should be delivered based on the configured source
1626 sourceConfig = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1627 GATEMP_INDEX_DEC);
1629 if(autoDetStatus->syncState == IODATA_SYNC_PCM) {
1630 // Bitstream preamble is not found and it times out -> assume this is PCM
1631 deliverZeros = autoDetStatus->deliverZeros;
1632 if (sourceConfig == PAF_SOURCE_PCM || sourceConfig == PAF_SOURCE_DSD1 ||
1633 sourceConfig == PAF_SOURCE_DSD2 || sourceConfig == PAF_SOURCE_DSD3) {
1634 // set to one -- ensures that PCM decode calls made before data is
1635 // available will result in zero output.
1636 // (mostly needed for PA15 since, currently, all other frameworks
1637 // require a frame of data before the first decode call.
1638 deliverZeros = TRUE; // override deliverZeros returned by ioDataControl
1639 }
1641 // update input buffer config structure
1642 pBufConfig->deliverZeros = deliverZeros;
1643 }
1645 //JXTODO: decide what to do with hRxSio
1646 //temporary - does ARM use hRxSio or just check if it is not NULL?
1647 pAstCfg->xInp[zMD].hRxSio = pInp->hIoData;
1648 pAstCfg->xInp[zMD].pInpBuf = &(pAstCfg->xInp[zMD].inpBufConfig);
1650 return ASIT_NO_ERR;
1651 } /* asitUpdateIoComps */
1653 #if 0
1654 #ifndef IO_LOOPBACK_TEST
1655 #if OUTPUT_FRAME_LENGTH == INPUT_FRAME_LENGTH
1656 U8 pcmbuf[OUTPUT_FRAME_SIZE];
1657 #else
1658 #error Input frame length is not equal to output frame length!
1659 #endif
1661 Int rxDecodePcm(PAF_AST_IoInp *pInp)
1662 {
1663 ioDataCtl_t ioDataCtl;
1664 void *buffBase;
1665 void *dataStartAddress;
1666 size_t buffSize, frameSize, size1, size2;
1668 /* Get information for reading input data */
1669 ioDataCtl.code = IODATA_CTL_GET_INPBUFFINFO;
1670 ioDataControl(pInp->hIoData, &ioDataCtl);
1672 buffBase = ioDataCtl.param.dataReadInfo.buffBase;
1673 buffSize = ioDataCtl.param.dataReadInfo.buffSize;
1674 dataStartAddress = ioDataCtl.param.dataReadInfo.startAddress;
1675 frameSize = ioDataCtl.param.dataReadInfo.frameSize;
1677 // Copy PCM data to output buffer
1678 if(((size_t)dataStartAddress+frameSize) <= ((size_t)buffBase+buffSize)) {
1679 // Input buffer doesn't wrap around
1680 Cache_inv(dataStartAddress, frameSize, Cache_Type_ALL, TRUE);
1681 memcpy((void *)&pcmbuf[0], dataStartAddress, frameSize);
1682 }
1683 else {
1684 // Input buffer wraps around
1685 size1 = (size_t)buffBase + buffSize - (size_t)dataStartAddress;
1686 size2 = frameSize - size1;
1687 Cache_inv(dataStartAddress, size1, Cache_Type_ALL, TRUE);
1688 memcpy((void *)&pcmbuf[0], dataStartAddress, size1);
1690 Cache_inv(buffBase, size2, Cache_Type_ALL, TRUE);
1691 memcpy((void *)&pcmbuf[size1], buffBase, size2);
1692 }
1695 return ASIT_NO_ERR;
1696 }
1699 Int rxDecodePlayZero(PAF_AST_IoInp *pInp)
1700 {
1701 return ASIT_NO_ERR;
1702 }
1703 #endif
1705 #endif
1707 Int asitEvtErrCheck(UInt actualEvents, UInt expectedEvents)
1708 {
1709 TRACE_VERBOSE2("ASIT events error: actual events are: %d, expected events are: %d.",
1710 actualEvents, expectedEvents);
1712 return ASIT_ERR_EVENTS;
1713 }
1715 void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr)
1716 {
1717 //UInt events;
1719 if(asitErr == ASIT_ERR_INPBUF_UNDERFLOW) {
1720 TRACE_VERBOSE0("ASIT error handling: input buffer underflows. No actions needed.");
1721 }
1723 if(asitErr == ASIT_AUTODET_TIME_OUT) {
1724 pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
1725 pAsitCfg->pIoInp[0].numAsitRestart++;
1726 TRACE_VERBOSE1("ASIT error %d handling finished. Go to state ASIT_RESET.", asitErr);
1727 }
1729 if(asitErr == ASIT_ERR_DECODE_QUIT) {
1730 TRACE_VERBOSE0("ASIT error handling: DECODE_QUIT - clear INPDATA event.");
1731 #if 0
1732 // Pend on INPTDATA event that should have been posted before decoding quits.
1733 events = Event_pend(asitEvent, ASIT_EVTMSK_NONE, ASIT_EVTMSK_INPDATA,
1734 BIOS_WAIT_FOREVER);
1736 // Marks I/O PHY transfer and I/O BUFF write complete
1737 asitPhyTransferComplete(&pAsitCfg->pIoInp[0]);
1739 // Keep I/O BUFF read pointers going
1740 asitBypassIoData(&pAsitCfg->pIoInp[0]);
1741 #endif
1742 pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
1743 pAsitCfg->pIoInp[0].numAsitRestart++;
1744 TRACE_VERBOSE1("ASIT error %d handling finished. Go to state ASIT_RESET.", asitErr);
1745 }
1747 if(asitErr == ASIT_ERR_EVENTS) {
1748 pAsitCfg->pIoInp[0].asipState = ASIT_RESET;
1749 pAsitCfg->pIoInp[0].numAsitRestart++;
1750 TRACE_VERBOSE1("ASIT error %d handling: events error. Go to state ASIT_RESET.", asitErr);
1751 }
1753 return;
1754 } /* asitErrorHandling */
1757 //////////////////////////////////////////////////////////////////////////////
1758 void asitPostInfoEvent()
1759 {
1760 Event_post(gAsitEvtHandle, ASIT_EVTMSK_INFOACK);
1761 }
1763 void asitPostDecEvent()
1764 {
1765 Event_post(gAsitEvtHandle, ASIT_EVTMSK_DECACK);
1766 }
1767 //////////////////////////////////////////////////////////////////////////////
1769 /* Nothing past this line */