1 /*
2 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
3 All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * Neither the name of Texas Instruments Incorporated nor the names of
18 * its contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34 #if 0
35 /*
36 * ======== audioStreamInpProc.c ========
37 */
39 #include <xdc/std.h>
40 #include <xdc/cfg/global.h>
41 #include <xdc/runtime/Diags.h>
42 #include <xdc/runtime/Error.h>
43 #include <xdc/runtime/Log.h>
44 #include <xdc/runtime/Memory.h>
45 #include <xdc/runtime/System.h>
46 #include <ti/sysbios/BIOS.h>
47 #include <ti/sysbios/hal/Hwi.h>
48 #include <ti/sysbios/hal/Cache.h>
49 #include <ti/sysbios/knl/Clock.h>
50 #include <ti/sysbios/knl/Task.h>
51 #include <ti/ipc/Ipc.h>
52 #include <ti/ipc/MessageQ.h>
53 #include <ti/ipc/MultiProc.h>
55 #include <sio.h>
56 #include <pafsio_ialg.h>
58 #include "common.h"
59 #include "paf_heapMgr.h"
60 #include "aspMsg_common.h"
61 #include "aspMsg_master.h"
62 #include "aspDecOpCircBuf_master.h"
63 #include "audioStreamProc_common.h"
64 #include "audioStreamProc_master.h"
65 #include "audioStreamInpProc.h"
66 #include "mib.h"
68 //#include "fwkPort.h"
69 // FL: debug
70 #include "dbgCapAf.h"
71 #include "dbgDib.h"
72 #include "statusOp_common.h"
75 // -----------------------------------------------------------------------------
76 // Debugging Trace Control, local to this file.
77 //
78 #include "logp.h"
80 // .............................................................................
82 #include <pafsio.h>
83 #include "paferr.h"
85 #include <acp_mds.h>
87 #include <pcm.h>
89 #include <pce.h>
91 #include <doberr.h>
93 #include <diberr.h>
95 #include <stdasp.h>
97 #include "as0.h"
98 #include "asperr.h"
100 #include "audioStreamProc_params.h"
101 #include "audioStreamProc_patchs.h"
102 #include "audioStreamProc_config.h"
103 #include "audioStreamInpProc.h"
105 #include "ioData.h"
106 //#include "../newio/fw/mcasp_cfg.h"
108 #include "ioConfig.h" //JXTODO: to remove compile-time configurations
110 //#include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
113 #define DECSIOMAP(X) \
114 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
117 enum {
118 INFO1,
119 INFO2,
120 DATA
121 };
124 #ifdef RX_MCASP_USE_MULT_SER
125 #define INPUT_STRIDE 8
126 #else
127 #define INPUT_STRIDE 2
128 #endif
130 extern PAF_AST_InpIO *inpIOtemp; /* Input I/O */
131 extern UInt32 gCapIb_cnt;
133 // Functions prototypes only referenced in this file
134 static Int decDecideFrameLength(Int sourceSelect);
135 static Int decDecodeInfo(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
136 PAF_ASIT_Config *pC, asipDecProc_t *pDec, Int frame, Int block);
137 static Int decDecodeData(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
138 PAF_ASIT_Config *pC, Int sourceSelect, Int frame, Int block);
139 //void asipUpdateInpBufConfig(PAF_AST_InpBuf *inpBufConfig, ioDataHandle_t ioDataHandle);
141 // -----------------------------------------------------------------------------
142 // ASIT Decoding Function - Reinitialization of Decode
143 //
144 // Name: PAF_ASIT_decodeInit
145 // Purpose: Decoding Function for reinitializing the decoding process.
146 // From: AST Parameter Function -> decodeProcessing
147 // Uses: See code.
148 // States: x
149 // Return: Error number in standard or SIO form (0 on success).
150 // Trace: Message Log "trace" in Debug Project Configuration reports:
151 // * State information as per parent.
152 //
153 Int asipDecodeInit(
154 const PAF_ASIT_Params *pP,
155 PAF_ASIT_Config *pC,
156 asipDecProc_t *pD,
157 Int sourceSelect)
158 {
159 PAF_AST_Config *pAstCfg;
160 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
161 Int as; /* Audio Stream Number (1, 2, etc.) */
162 Int z; /* decode/encode counter */
163 Int errno; /* error number */
164 Int zI, zS;
165 Int8 tempVar8;
166 ioPhyCtl_t ioPhyCtl;
167 ioDataCtl_t ioDataCtl;
169 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
170 as = pAstCfg->as;
171 (void)as; // clear compiler warning in case not used with tracing disabled
173 pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
175 // reset frameCount
176 for (z=DECODE1; z < DECODEN; z++)
177 {
178 if (readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode))) {
179 writeSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.frameCount), 0);
180 }
181 }
183 // loop through all supported inputs
184 for (z=DECODE1; z < DECODEN; z++)
185 {
186 zI = pP->inputsFromDecodes[z];
187 zS = pP->streamsFromDecodes[z];
188 (void)zS; // clear compiler warning in case not used with tracing disabled
190 if ( inpIOtemp[zI].hIoPhy
191 && readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))
192 {
193 Uns gear;
194 Int frameLength;
195 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
197 // write back Dec configuration
198 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
199 Cache_wait();
201 // FL: send dec activate message to slave
202 asipSendMsgToDecoder(ASP_SLAVE_DEC_ACTIVATE, z, ASP_MASTER_DEC_ACTIVATE_DONE, NULL);
204 // FL: send dec reset message to slave
205 errno = 0;
206 errno = asipSendMsgToDecoder(ASP_SLAVE_DEC_RESET, z, ASP_MASTER_DEC_RESET_DONE, NULL);
208 // (***) FL: revisit
209 // invalidate Dec configuration
210 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
211 Cache_wait();
213 if (errno != 0) {
214 return ASIP_DECODE_ERR_MSG_SEND;
215 }
217 gear = readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.aspGearControl));
218 tempVar8 = gear < GEARS ? gear : 0;
219 writeSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.aspGearStatus), tempVar8);
221 frameLength = decDecideFrameLength(sourceSelect);
223 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
224 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
225 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
227 // (***) FL: revisit. Count samples for DDP.
228 // Add framework frame length and running sample count to decoder control.
229 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
230 //pC->xDec[z].decodeControl.rdSampleCount = 0;
232 // Initialize decoder output circular buffer for selected source
233 //errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
234 if (errno) {
235 SW_BREAKPOINT; // FL: debug
236 return ASIP_DECODE_ERR_INIT_CB;
237 }
238 // FL: debug
239 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
241 /*
242 if (z != zMD) { // JXTODO: implement similar thing with new I/O
243 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
244 return errno;
245 }
246 }
247 */
248 /*
249 //JXTODO: do we need to update input status here again?
250 if (errno = asipUpdateInputStatus(inpIOtemp[0].pRxParams,
251 &pAstCfg->xInp[zI].inpBufStatus,
252 &pAstCfg->xInp[zI].inpBufConfig)) {
253 return errno;
254 }
255 */
256 } /* end of if(hIoPhy && decodeStatus.mode) */
257 } /* end of for (z=DECODE1; z < DECODEN; z++) */
259 pD->frame = 0;
260 pD->block = 0;
261 pD->state = INFO1;
263 return ASIP_DECODE_NO_ERR;
264 } /* asipDecodeInit */
266 // -----------------------------------------------------------------------------
267 // ASIT Processing Function - Decode Processing
268 //
269 // Name: asipDecodeProcessing
270 // Purpose: Audio Stream Input Task Function for processing audio data.
271 // Return: Error number in standard form (0 on success).
272 //
273 #if 0
274 Int asipDecodeProcessing(
275 const PAF_ASIT_Params *pP,
276 const PAF_ASIT_Patchs *pQ,
277 PAF_ASIT_Config *pC,
278 asipDecProc_t *pD,
279 Int sourceSelect)
280 {
281 PAF_AST_Config *pAstCfg;
282 Int errno, retVal; /* error number */
283 Int zMD;
285 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
286 zMD = pAstCfg->masterDec;
288 retVal = ASIP_DECODE_NO_ERR;
290 //!! to add data read from I/O buffer
291 switch(pD->state)
292 {
293 case INFO1:
294 if (errno = decDecodeInfo(pP, pQ, pC, pD, pD->frame, pD->block)) {
295 //gAsipInfo1_PrimaryErrCnt++;
296 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
297 retVal = ASIP_DECODE_ERR_INFO1;
298 }
299 else {
300 // Don't start decode until major access unit is found.
301 Int8 sourceDecode, sampleRate;
302 sourceDecode = readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode));
303 sampleRate = readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sampleRate));
304 if ( ( (sourceDecode == PAF_SOURCE_THD) ||
305 (sourceDecode == PAF_SOURCE_DXP) ||
306 (sourceDecode == PAF_SOURCE_DTSHD) ) &&
307 ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
308 pD->state = INFO1;
309 }
310 else {
311 pD->state = DATA;
312 }
313 }
314 break;
316 case INFO2:
317 if (errno = decDecodeInfo(pP, pQ, pC, pD, pD->frame, pD->block)) {
318 //gAsipInfo1_PrimaryErrCnt++;
319 TRACE_TERSE1("INFO2: errno 0x%x after decodeInfo, primary timing", errno);
320 retVal = ASIP_DECODE_ERR_INFO2;
321 }
322 else {
323 pD->state = DATA;
324 }
325 break;
327 case DATA:
328 if (errno = decDecodeData(pP, pQ, pC, sourceSelect, pD->frame, pD->block)) {
329 //gAsipDecodeErrCnt++;
330 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DATA. decodeDecode err 0x%04x", errno);
331 retVal = ASIP_DECODE_ERR_DATA;
332 }
333 else {
334 if (pP->fxns->decodeFinalTest(pP, pQ, pC, pD->frame, pD->block)) {
335 retVal = ASIP_DECODE_ERR_FINAL;
336 }
337 else {
338 pD->state = INFO2;
339 }
340 }
341 break;
343 default:
344 break;
346 }
348 return retVal;
349 } /* asipDecodeProcessing */
350 #endif
353 Int asipDecodeProcessing(
354 const PAF_ASIT_Params *pP,
355 const PAF_ASIT_Patchs *pQ,
356 PAF_ASIT_Config *pC,
357 asipDecProc_t *pD,
358 Int sourceSelect)
359 {
360 PAF_AST_Config *pAstCfg;
361 Int errno, retVal; /* error number */
362 Int zMD;
364 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
365 zMD = pAstCfg->masterDec;
366 retVal = ASIP_DECODE_NO_ERR;
368 //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ; //JXTODO: make this correct
369 errno = decDecodeInfo(pP, pQ, pC, pD, pD->frame, pD->block);
370 if (errno != ASIP_DECODE_NO_ERR) {
371 //gAsipInfo1_PrimaryErrCnt++;
372 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
373 retVal = ASIP_DECODE_ERR_INFO;
374 }
375 else {
376 // Don't start decode until major access unit is found.
377 Int8 sourceDecode, sampleRate;
378 sourceDecode = readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode));
379 sampleRate = readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sampleRate));
380 if ( ( (sourceDecode == PAF_SOURCE_THD) ||
381 (sourceDecode == PAF_SOURCE_DXP) ||
382 (sourceDecode == PAF_SOURCE_DTSHD) ) &&
383 ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
384 /* do nothing and return - waiting for major access unit */;
385 retVal = ASIP_DECODE_NO_ERR;
386 }
387 else {
388 errno = decDecodeData(pP, pQ, pC, sourceSelect, pD->frame, pD->block);
389 if (errno != ASIP_DECODE_NO_ERR) {
390 //gAsipDecodeErrCnt++;
391 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DATA. decodeDecode err 0x%04x", errno);
392 retVal = ASIP_DECODE_ERR_DATA;
393 }
394 else {
395 errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pD->frame, pD->block);
396 if (errno) {
397 retVal = ASIP_DECODE_ERR_FINAL;
398 }
399 else {
400 retVal = ASIP_DECODE_NO_ERR;
401 }
402 }
403 }
404 }
406 return retVal;
407 } /* asipDecodeProcessing */
409 // -----------------------------------------------------------------------------
410 // ASIT Decoding Function - Info Processing, Common
411 //
412 // Name: PAF_ASIT_decodeInfo
413 // Purpose: Decoding Function for processing information in a manner that
414 // is common for both initial and subsequent frames of input data.
415 // From: AST Parameter Function -> decodeProcessing
416 // Uses: See code.
417 // States: x
418 // Return: Error number in standard form (0 on success).
419 // Trace: Message Log "trace" in Debug Project Configuration reports:
420 // * State information as per parent.
421 // -----------------------------------------------------------------------------
422 Int
423 decDecodeInfo(
424 const PAF_ASIT_Params *pP,
425 const PAF_ASIT_Patchs *pQ,
426 PAF_ASIT_Config *pC,
427 asipDecProc_t *pD,
428 Int frame,
429 Int block
430 )
431 {
432 PAF_AST_Config *pAstCfg;
433 Int as; /* Audio Stream Number (1, 2, etc.) */
434 Int z; /* input/decode/stream counter */
435 Int errno; /* error number */
436 Int zD, zI, zS, zX;
437 Int zMD;
438 //Int zMI;
439 Int8 tempVar8;
440 Int tempVar;
442 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
443 zMD = pAstCfg->masterDec;
444 //zMI = pP->zone.master;
446 // Set decode control: sample rate, emphasis
447 for (z=INPUT1; z < INPUTN; z++)
448 {
449 zD = z;
450 for (zX = DECODE1; zX < DECODEN; zX++)
451 {
452 if (pP->inputsFromDecodes[zX] == z) {
453 zD = zX;
454 break;
455 }
456 }
458 if (inpIOtemp[z].hIoPhy) {
459 //determine associated decoder
460 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
461 pAstCfg->xDec[zD].decodeControl.sampleRate) {
462 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
463 pAstCfg->xDec[zD].decodeControl.sampleRate =
464 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
465 }
466 else {
467 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
468 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
469 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
470 pAstCfg->xDec[zD].decodeControl.sampleRate);
471 // return (ASPERR_INFO_RATECHANGE);
472 }
473 }
475 tempVar8 = readSharedMem((Int8 *)&(pAstCfg->xDec[zD].decodeStatus.sourceDecode));
476 pAstCfg->xDec[zD].decodeControl.emphasis =
477 tempVar8 != PAF_SOURCE_PCM
478 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
479 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
480 }
481 else {
482 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
483 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
484 }
485 } /* end of for (z=INPUT1; z < INPUTN; z++) */
487 // Wait for info input: (JX) all SIO_reclaim does is pend on data, and do sync scan or sync check,
488 // which is done in autoDetection routine now.
489 //if (pAstCfg->xInp[zMI].hRxSio)
490 // sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
491 // FL: debug, capture input buffer
492 //capIb(pAstCfg->xInp[zMI].pInpBuf);
493 //gCapIb_cnt++;
495 // Decode info
496 for (z=DECODE1; z < DECODEN; z++)
497 {
498 zI = pP->inputsFromDecodes[z];
499 zS = pP->streamsFromDecodes[z];
500 (void)zS; // clear compiler warning in case not used with tracing disabled
502 if ( inpIOtemp[zI].hIoPhy &&
503 readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))
504 {
505 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
507 if (errno = asipUpdateInputStatus(inpIOtemp[zI].pRxParams,
508 &pAstCfg->xInp[zI].inpBufStatus,
509 &pAstCfg->xInp[zI].inpBufConfig)) {
510 TRACE_TERSE1("return error errno 0x%x.", errno);
511 return errno;
512 }
514 // debug, capture input buffer
515 capIb(pAstCfg->xInp[zI].pInpBuf);
516 gCapIb_cnt++;
518 // write back Inp configuration
519 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
520 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
521 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
522 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
523 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
524 // write back Dec configuration
525 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
526 Cache_wait();
528 errno = asipSendMsgToDecoder(ASP_SLAVE_DEC_INFO, z, ASP_MASTER_DEC_INFO_DONE, NULL);
530 // (***) FL: revisit
531 // invalidate Dec configuration
532 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
533 Cache_wait();
535 if (errno) {
536 TRACE_TERSE1("return error errno 0x%x.", errno);
537 return errno;
538 }
540 tempVar = readSharedMemInt((Int *)&(pAstCfg->xDec[z].decodeStatus.frameCount));
541 // increment decoded frame count
542 tempVar += 1;
543 writeSharedMemInt((Int *)&(pAstCfg->xDec[z].decodeStatus.frameCount), tempVar);
544 }
545 } // z=DECODE1 to DECODEN
547 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
548 if (readSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.mode))) {
549 #if 0
550 //JXTODO: implement ioDataControl
551 ioDataCtl_t ioDataCtl;
552 ioDataCtl.code = IODATA_CTL_GET_SOURCEPROGRAM;
553 if (errno = ioDataControl(inpIOtemp->hIoData, &ioDataCtl)) {
554 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
555 return ASPERR_AUTO_PROGRAM;
556 }
557 #endif
558 writeSharedMem((Int8 *)&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
559 (Int8)pD->sourceProgram);
560 //(Int8)ioDataCtl.param.sourceProgram);
561 }
563 // since now decoding update decode status for all enabled decoders
564 for (z=DECODE1; z < DECODEN; z++)
565 {
566 if (readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode))) {
567 tempVar8 = readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.sourceProgram));
568 writeSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.sourceDecode), tempVar8);
569 tempVar8 = readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.sourceSelect));
570 if (tempVar8 == PAF_SOURCE_SNG) {
571 writeSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.sourceDecode), tempVar8);
572 }
573 }
574 }
576 return ASIP_DECODE_NO_ERR;
577 } /* decDecodeInfo */
580 // -----------------------------------------------------------------------------
581 // ASIT Decoding Function - Decode Processing
582 //
583 // Name: PAF_ASIT_decodeDecode
584 // Purpose: Decoding Function for processing of input data by the
585 // Decode Algorithm.
586 // From: AST Parameter Function -> decodeProcessing
587 // Uses: See code.
588 // States: x
589 // Return: Error number in standard form (0 on success).
590 // Trace: Message Log "trace" in Debug Project Configuration reports:
591 // * State information as per parent.
592 // -----------------------------------------------------------------------------
593 Int
594 decDecodeData(
595 const PAF_ASIT_Params *pP,
596 const PAF_ASIT_Patchs *pQ,
597 PAF_ASIT_Config *pC,
598 Int sourceSelect,
599 Int frame,
600 Int block
601 )
602 {
603 PAF_AST_Config *pAstCfg;
604 Int as; /* Audio Stream Number (1, 2, etc.) */
605 Int z; /* decode/stream counter */
606 Int errno; /* error number */
607 //Int ch;
608 Int cbErrno;
609 Int frameLength;
610 ioPhyCtl_t ioPhyCtl;
612 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
613 as = pAstCfg->as;
614 (void)as; // clear compiler warning in case not used with tracing disabled
616 // Decode data
617 for (z=DECODE1; z < DECODEN; z++)
618 {
619 Int zI = pP->inputsFromDecodes[z];
620 Int zS = pP->streamsFromDecodes[z];
621 (void)zS; // clear compiler warning in case not used with tracing disabled
622 if ( inpIOtemp[zI].hIoPhy &&
623 readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))
624 {
625 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
627 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
628 as+zS,
629 (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
630 (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
632 // FL: debug, capture input buffer
633 //capIbPcm(pAstCfg->xInp[z].pInpBuf);
635 // (***) FL: revisit
636 // write back Dec configuration
637 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
638 Cache_wait();
640 errno = asipSendMsgToDecoder(ASP_SLAVE_DEC_DECODE, z, ASP_MASTER_DEC_DECODE_DONE, &cbErrno);
641 if (cbErrno != 0) {
642 //gCbWrtAfErrCnt++;
643 TRACE_TERSE1("CB write error=%d", cbErrno);
644 //SW_BREAKPOINT; // temporary
645 }
647 // (***) FL: revisit
648 // invalidate Dec configuration
649 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
650 Cache_wait();
652 if (errno) {
653 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
654 return errno;
655 }
657 frameLength = decDecideFrameLength(sourceSelect);
659 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
660 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
662 //JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
663 } // hIoPhy && decodeStatus.mode
664 else {
665 TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
666 }
667 } // z=DECODE1 to DECODEN
669 return ASIP_DECODE_NO_ERR;
670 } /* decDecodeData */
672 //JXTODO: what does this frame length have to with IECframeLength[23]
673 Int decDecideFrameLength(Int sourceSelect)
674 {
675 Int frameLength;
677 if (sourceSelect == PAF_SOURCE_PCM) {
678 frameLength = PAF_SYS_FRAMELENGTH;
679 }
680 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3)) {
681 frameLength = 1536; //JXTODO: replace 1536 with macro
682 }
683 else if (sourceSelect == PAF_SOURCE_THD) {
684 frameLength = 1536; //JXTODO: replace 1536 with macro
685 }
686 else {
687 frameLength = 256; //JXTODO: replace 256 with macro
688 }
690 return frameLength;
691 } /* decDecideFrameLength */
694 // -----------------------------------------------------------------------------
695 // ASIT Decoding Function - Stream-Final Processing
696 //
697 // Name: PAF_ASIT_decodeComplete
698 // Purpose: Decoding Function for terminating the decoding process.
699 // From: AST Parameter Function -> decodeProcessing
700 // Uses: See code.
701 // States: x
702 // Return: 0.
703 // Trace: Message Log "trace" in Debug Project Configuration reports:
704 // * State information as per parent.
705 //
706 Int
707 asipDecodeComplete(
708 const PAF_ASIT_Params *pP,
709 const PAF_ASIT_Patchs *pQ,
710 PAF_ASIT_Config *pC,
711 ALG_Handle decAlg[]
712 )
713 {
714 PAF_AST_Config *pAstCfg;
715 Int as; /* Audio Stream Number (1, 2, etc.) */
716 Int z; /* decode/encode counter */
718 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
719 as = pAstCfg->as;
720 (void)as; // clear compiler warning in case not used with tracing disabled
722 #ifdef PAF_ASP_FINAL
723 /* This material is currently not utilized */
724 #endif /* PAF_ASP_FINAL */
725 for (z=DECODE1; z < DECODEN; z++)
726 {
727 #ifdef PAF_ASP_FINAL
728 DEC_Handle dec = (DEC_Handle )decAlg[z];
729 #endif /* PAF_ASP_FINAL */
731 Int zI = pP->inputsFromDecodes[z];
732 if ( inpIOtemp[zI].hIoPhy &&
733 readSharedMem((Int8 *)&(pAstCfg->xDec[z].decodeStatus.mode)))
734 {
735 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
737 #ifdef PAF_ASP_FINAL
738 if (dec->fxns->final)
739 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
740 &pAstCfg->xDec[z].decodeStatus);
741 #endif /* PAF_ASP_FINAL */
743 // FL: send dec deactivate message to slave
744 asipSendMsgToDecoder(ASP_SLAVE_DEC_DEACTIVATE, z, ASP_MASTER_DEC_DEACTIVATE_DONE, NULL);
745 }
746 else {
747 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
748 }
749 }
750 return 0;
751 } //asipDecodeComplete
753 #endif
754 /* Nothing past this line */