[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / audioStreamInpProc.c
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37 * ======== audioStreamInpProc.c ========
38 */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Diags.h>
43 #include <xdc/runtime/Error.h>
44 #include <xdc/runtime/Log.h>
45 #include <xdc/runtime/Memory.h>
46 #include <xdc/runtime/System.h>
47 #include <ti/sysbios/BIOS.h>
48 #include <ti/sysbios/hal/Hwi.h>
49 #include <ti/sysbios/hal/Cache.h>
50 #include <ti/sysbios/knl/Clock.h>
51 #include <ti/sysbios/knl/Task.h>
52 #include <ti/ipc/Ipc.h>
53 #include <ti/ipc/MessageQ.h>
54 #include <ti/ipc/MultiProc.h>
56 #include <sio.h>
57 #include <pafsio_ialg.h>
59 #include "common.h"
60 #include "paf_heapMgr.h"
61 #include "aspMsg_common.h"
62 #include "aspMsg_master.h"
63 #include "aspDecOpCircBuf_master.h"
64 #include "audioStreamProc_common.h"
65 #include "audioStreamProc_master.h"
66 #include "audioStreamInpProc.h"
68 // FL: porting
69 #include "fwkSim.h"
70 //#include "fwkPort.h"
71 // FL: debug
72 #include "dbgCapAf.h"
75 // -----------------------------------------------------------------------------
76 // Debugging Trace Control, local to this file.
77 //
78 #include "logp.h"
80 #define TRACE_ARC(a)
82 // allows you to set a different trace module in pa.cfg
83 #define TR_MOD trace
85 // Allow a developer to selectively enable tracing.
86 #define CURRENT_TRACE_MASK 0x21
88 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
89 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
90 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
91 #define TRACE_MASK_DATA 0x08 // Show data
92 #define TRACE_MASK_TIME 0x10 // Timing related traces
93 #define TRACE_MASK_MSG 0x20 // Message related traces
95 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
96 #undef TRACE_TERSE0
97 #undef TRACE_TERSE1
98 #undef TRACE_TERSE2
99 #undef TRACE_TERSE3
100 #undef TRACE_TERSE4
101 #define TRACE_TERSE0(a)
102 #define TRACE_TERSE1(a,b)
103 #define TRACE_TERSE2(a,b,c)
104 #define TRACE_TERSE3(a,b,c,d)
105 #define TRACE_TERSE4(a,b,c,d,e)
106 #endif
108 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
109 #undef TRACE_GEN0
110 #undef TRACE_GEN1
111 #undef TRACE_GEN2
112 #undef TRACE_GEN3
113 #undef TRACE_GEN4
114 #define TRACE_GEN0(a)
115 #define TRACE_GEN1(a,b)
116 #define TRACE_GEN2(a,b,c)
117 #define TRACE_GEN3(a,b,c,d)
118 #define TRACE_GEN4(a,b,c,d,e)
119 #endif
121 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
122 // consolidate list of processing strings, indexed by PAF_SOURCE
123 static char *procName[] =
124 {
125 "", //PAF_SOURCE_UNKNOWN
126 "", //PAF_SOURCE_NONE
127 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
128 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
129 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
130 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
131 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
132 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
133 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
134 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
135 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
136 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
137 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
138 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
139 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
140 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
141 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
142 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
143 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
144 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
145 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
146 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
147 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
148 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
149 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
150 "AS%d: THD processing ...", //PAF_SOURCE_THD
151 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
152 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
153 };
155 #else
156 #undef TRACE_VERBOSE0
157 #undef TRACE_VERBOSE1
158 #undef TRACE_VERBOSE2
159 #undef TRACE_VERBOSE3
160 #undef TRACE_VERBOSE4
161 #define TRACE_VERBOSE0(a)
162 #define TRACE_VERBOSE1(a,b)
163 #define TRACE_VERBOSE2(a,b,c)
164 #define TRACE_VERBOSE3(a,b,c,d)
165 #define TRACE_VERBOSE4(a,b,c,d,e)
166 #endif
168 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
169 #define TRACE_DATA(a) LOG_printf a
170 #else
171 #define TRACE_DATA(a)
172 #endif
174 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
175 #define TRACE_TIME(a) LOG_printf a
176 #define TIME_MOD trace // this could be different
177 static Int dtime()
178 {
179 static Int old_time = 0;
180 Int time = TSK_time();
181 Int delta_time = time - old_time;
182 old_time = time;
183 return( delta_time);
184 }
186 static char *stateName[11] =
187 {
188 "INIT",
189 "INFO1",
190 "AGAIN",
191 "INFO2",
192 "CONT",
193 "TIME",
194 "DECODE",
195 "STREAM",
196 "ENCODE",
197 "FINAL",
198 "QUIT"
199 };
201 #else
202 #define TRACE_TIME(a)
203 #endif
205 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
206 #undef TRACE_MSG0
207 #undef TRACE_MSG1
208 #undef TRACE_MSG2
209 #undef TRACE_MSG3
210 #undef TRACE_MSG4
211 #define TRACE_MSG0(a)
212 #define TRACE_MSG1(a,b)
213 #define TRACE_MSG2(a,b,c)
214 #define TRACE_MSG3(a,b,c,d)
215 #define TRACE_MSG4(a,b,c,d,e)
216 #endif
219 // .............................................................................
221 #include <pafsio.h>
222 #include "paferr.h"
224 #include <acp_mds.h>
226 #include <pcm.h>
228 #include <pce.h>
230 #include <doberr.h>
232 #include <diberr.h>
234 #include <stdasp.h>
236 #include "as0.h"
237 #include "asperr.h"
239 #include "audioStreamProc_params.h"
240 #include "audioStreamProc_patchs.h"
241 #include "audioStreamProc_config.h"
242 #include "audioStreamInpProc.h"
244 //
245 // Audio Stream Definitions
246 //
248 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
249 #define MINFRAMELENGTH 24
250 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
253 //
254 // Decoder Definitions
255 //
256 //#define decLinkInit pQ->i_decLinkInit
258 //
259 // Audio Stream Processing Definitions
260 //
261 //#define aspLinkInit pQ->i_aspLinkInit
263 //
264 // Encoder Definitions
265 //
266 #define encLinkInit pQ->i_encLinkInit
268 //
269 // Input, Output Definitions
270 //
271 #define inpLinkInit pP->i_inpLinkInit
272 //#define outLinkInit pP->i_outLinkInit
274 /* ---------------------------------------------------------------- */
275 /* Parameter macro definitions end here. */
276 /* ---------------------------------------------------------------- */
278 //
279 // Standardized Definitions
280 //
282 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
283 //#define ENC_Handle PCE_Handle /* works for all: PCE */
285 #define __TASK_NAME__ "TaskAsip"
287 LINNO_DEFN(TaskAsip); /* Line number macros */
288 ERRNO_DEFN(TaskAsip); /* Error number macros */
290 // ASIT configuration
291 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
292 PAF_ASIT_Config gPAF_ASIT_config = {
293 NULL, // acp
294 &gPAF_ASPM_config, // pAspmCfg, shared ASIT/ASOT configuration
295 &gPAF_AST_config // pAstCfg, shared ASIT/ASOT/ASDT configuration
296 };
298 // Global debug counters */
299 UInt32 gTaskAsipCnt=0; // debug
300 UInt32 gAsipInitCnt =0;
301 UInt32 gAsipInfo1Cnt =0;
302 UInt32 gAsipInfo2Cnt =0;
303 UInt32 gAsipDecodeCnt =0;
304 UInt32 gAsipFinalCnt =0;
305 UInt32 gAsipQuitCnt =0;
306 #include "dbgDib.h"
308 extern struct {
309 Int size;
310 IALG_Status *pStatus[512];
311 } IACP_STD_BETA_TABLE;
314 /*
315 * ======== taskAsipFxn ========
316 * Audio Stream Input Processing task function
317 */
318 Void taskAsipFxn(
319 // Int betaPrimeValue, // FL: revisit
320 const PAF_ASIT_Params *pP,
321 const PAF_ASIT_Patchs *pQ
322 )
323 {
324 PAF_ASIT_Config *pC; /* Local configuration pointer */
325 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
326 Int as; /* Audio Stream Number (1, 2, etc.) */
327 Int z; /* input/encode/stream/decode/output counter */
328 Int i; /* phase */
329 Int errno; /* error number */
330 Int zMD, zMI, zMS, zX;
331 Int loopCount = 0; // used to stop trace to see startup behavior.
332 UInt32 curTime;
333 Int size;
334 // Messaging
335 ASP_Msg *pAspMsg;
336 Int status;
338 Log_info0("Enter taskAsipFxn()");
340 #ifdef SIMULATE_SIO
341 /* Start simulation */
342 simStart();
343 #endif // SIMULATE_SIO
345 //
346 // Audio Framework Parameters & Patch (*pP, *pQ)
347 //
348 if (!pP)
349 {
350 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
351 LINNO_RPRT(TaskAsip, -1);
352 return;
353 }
355 if (!pQ)
356 {
357 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
358 LINNO_RPRT(TaskAsip, -1);
359 return;
360 }
362 //
363 // Audio Framework Configuration (*pC):
364 //
365 pC = &gPAF_ASIT_config;
366 pAstCfg = pC->pAstCfg;
368 /* Set Audio Stream Number (1, 2, etc.) */
369 as = gBetaPrimeValue + 1;
370 pAstCfg->as = as;
371 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
373 //
374 // Initialize message log trace and line number reporting
375 //
376 for (z=STREAM1; z < STREAMN; z++)
377 {
378 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
379 }
380 LINNO_RPRT(TaskAsip, -1);
382 //
383 // Determine decoder and stream indices associated with the master input
384 //
385 zMI = pP->zone.master;
386 pAstCfg->masterDec = zMI;
387 pAstCfg->masterStr = zMI;
388 for (zX = DECODE1; zX < DECODEN; zX++)
389 {
390 if (pP->inputsFromDecodes[zX] == zMI)
391 {
392 pAstCfg->masterDec = zX;
393 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
394 break;
395 }
396 }
397 zMD = pAstCfg->masterDec;
398 zMS = pAstCfg->masterStr;
400 // Initialize as per parametrized phases:
401 //
402 // In standard form these are:
403 // - Malloc: Memory Allocation
404 // - Config: Configuration Initialization
405 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
406 // - Common: Common Memory Initialization
407 // - AlgKey: Dec/Enc chain to Array Initialization
408 // - Device: I/O Device Initialization
409 // - DecOpCircBuf: Decoder Output Circular Buffer
410 // - Unused: (available)
411 //
412 LINNO_RPRT(TaskAsip, -2);
413 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
414 {
415 Int linno;
416 if (pP->fxns->initPhase[i])
417 {
418 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
419 {
420 LINNO_RPRT(TaskAsip, linno);
421 return;
422 }
423 }
424 else
425 {
426 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
427 }
428 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
429 LINNO_RPRT(TaskAsip, -i-3);
430 }
432 //
433 // End of Initialization -- display memory usage report.
434 //
435 if (pP->fxns->memStatusPrint)
436 {
437 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
438 }
440 // (***) FL: revisit
441 // write back AST shared configuration
442 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
443 // FL: no need to share this pointer, can be local
444 //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
445 Cache_wait();
447 // (***) FL: revisit
448 // write back Dec configuration
449 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
450 Cache_wait();
452 // (***) FL: revisit
453 // write back entire beta table
454 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
455 Cache_wait();
457 // FL: send start initialization message to slave
458 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
459 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
460 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
461 pAspMsg->procId = hAspMsgMaster->masterProcId;
462 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
463 pAspMsg->expectResp = TRUE;
464 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
465 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
466 if (status != MessageQ_S_SUCCESS)
467 {
468 SW_BREAKPOINT;
469 }
470 // wait for initialization complete message from slave
471 do {
472 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
473 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
474 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
475 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
476 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
477 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
478 {
479 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
480 SW_BREAKPOINT;
481 }
482 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
483 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
484 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
485 if (status != MessageQ_S_SUCCESS)
486 {
487 SW_BREAKPOINT;
488 }
490 // (***) FL: revisit
491 // invalidate Status structure addresses for Beta Units initialized on Slave
492 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
493 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
494 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
495 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
496 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
497 Cache_wait();
498 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
499 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
500 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
501 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
502 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
504 // (***) FL: revisit
505 // invalidate Status structures for Beta Units initialized on Slave
506 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
507 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
508 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
509 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
510 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
511 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
512 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
513 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
514 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
515 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
516 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
517 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
518 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
519 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
520 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
521 Cache_wait();
523 // (***) FL: revisit
524 // invalidate Dec configuration
525 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
526 Cache_wait();
528 //
529 // Main processing loop
530 //
531 for (z=STREAM1; z < STREAMN; z++)
532 {
533 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
534 }
536 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
538 errno = 0;
539 for (;;)
540 {
541 Int sourceSelect;
542 XDAS_Int8 sourceProgram;
544 loopCount++;
546 #if 0 // enable and tune to see startup behavior.
547 // this is an alternative to fixed/circular setting in pa.cfg.
548 // If you are searching for a memory allocation failure, disable on first round.
549 // All allocation has already happened.
550 // This is the outer loop. This loop count goes up when the stream resets.
551 // If the stream is running without problems, this does not increment.
552 // If the stream is repeatedly resetting, this loop count will go up rapidly.
553 if (loopCount > 10) // see traces for a few of the passes through the main loop.
554 {
555 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
556 LOG_disable(&TR_MOD); // stop tracing
557 }
558 #endif
560 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
561 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
563 // since not decoding indicate such
564 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
566 // any error forces idling of input
567 if (errno)
568 {
569 for (z=INPUT1; z < INPUTN; z++)
570 {
571 if (pAstCfg->xInp[z].hRxSio)
572 {
573 SIO_idle(pAstCfg->xInp[z].hRxSio);
574 }
575 }
577 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
578 ERRNO_RPRT(TaskAsip, errno);
579 }
581 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
582 // up to allow lower priority tasks to run. This may seem odd to be at the top
583 // of the state machine but provides for a cleaner flow even though the very
584 // first time we enter we do a sleep which is non-intuitive.
585 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
586 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
587 Task_sleep(1);
589 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
590 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
591 {
592 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
593 continue;
594 }
596 // if no master input selected then we don't know what may be at the input
597 // so set to unknown and skip any remaining processing
598 if (!pAstCfg->xInp[zMI].hRxSio)
599 {
600 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
601 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
602 continue;
603 }
605 // if here then we have a valid input so query its status
606 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
607 {
608 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
609 continue;
610 }
612 // If master decoder is not enabled, or the input is unlocked, then do nothing
613 if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
614 {
615 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
616 continue;
617 }
619 // If no source selected then do nothing
620 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
621 {
622 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
623 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
624 continue;
625 }
627 // If we want pass processing then proceed directly
628 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
629 {
630 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
631 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
632 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
633 if (pP->fxns->passProcessing)
634 {
635 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
636 }
637 else
638 {
639 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
640 errno = ASPERR_PASS;
641 }
642 TRACE_VERBOSE0("TaskAsip: continue");
643 continue;
644 }
646 // .....................................................................
647 // At this point we have an enabled input and want to decode something.
648 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
649 // when no decoder is selected there are no calls to IB
650 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
651 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pAstCfg->xDec[zMD].decodeStatus.sourceSelect, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
652 {
653 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
654 continue;
655 }
657 // query for input type
658 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
659 {
660 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
661 errno = ASPERR_AUTO_PROGRAM;
662 continue;
663 }
664 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
666 // if input is unclassifiable then do nothing
667 if (sourceProgram == PAF_SOURCE_UNKNOWN)
668 {
669 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
670 continue;
671 }
673 // now that we have some input classification, and possibly an outstanding
674 // input frame, we determine whether or not to call decodeProcessing and with
675 // what decAlg.
676 sourceSelect = PAF_SOURCE_NONE;
677 switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect)
678 {
679 // If autodetecting, decoding everything, and input is something
680 // (i.e. bitstream or PCM) then decode.
681 case PAF_SOURCE_AUTO:
682 if (sourceProgram >= PAF_SOURCE_PCM)
683 {
684 sourceSelect = sourceProgram;
685 }
686 break;
688 // If autodetecting, decoding only PCM, and input is PCM then decode.
689 case PAF_SOURCE_PCMAUTO:
690 if (sourceProgram == PAF_SOURCE_PCM)
691 {
692 sourceSelect = sourceProgram;
693 }
694 break;
696 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
697 case PAF_SOURCE_BITSTREAM:
698 if (sourceProgram >= PAF_SOURCE_AC3)
699 {
700 sourceSelect = sourceProgram;
701 }
702 break;
704 // If autodetecting, decoding only DTS, and input is DTS then decode.
705 case PAF_SOURCE_DTSALL:
706 switch (sourceProgram)
707 {
708 case PAF_SOURCE_DTS11:
709 case PAF_SOURCE_DTS12:
710 case PAF_SOURCE_DTS13:
711 case PAF_SOURCE_DTS14:
712 case PAF_SOURCE_DTS16:
713 case PAF_SOURCE_DTSHD:
714 sourceSelect = sourceProgram;
715 break;
716 }
717 break;
719 // All others, e.g., force modes, fall through to here.
720 // If user made specific selection then program must match select.
721 // (NB: this compare relies on ordering of PAF_SOURCE)
722 default:
723 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
724 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
725 {
726 if (sourceProgram != sourceSelect)
727 {
728 sourceSelect = PAF_SOURCE_NONE;
729 }
730 }
731 break;
732 }
734 // if we didn't find any matches then skip
735 if (sourceSelect == PAF_SOURCE_NONE)
736 {
737 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
738 continue;
739 }
741 // FL: debug, reset IB capture buffer
742 //capIbReset();
743 //Log_info0("capIbReset()");
745 // FL: send source select message to slave
746 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
747 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
748 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
749 pAspMsg->procId = hAspMsgMaster->masterProcId;
750 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
751 pAspMsg->expectResp = TRUE;
752 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
753 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
754 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
755 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
756 if (status != MessageQ_S_SUCCESS)
757 {
758 SW_BREAKPOINT;
759 }
760 // wait for source select complete message from slave
761 //do {
762 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
763 //} while (status != MessageQ_S_SUCCESS);
764 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
765 if (status != MessageQ_S_SUCCESS)
766 {
767 TRACE_TERSE0("MessageQ_get() failure.");
768 SW_BREAKPOINT; // temporary
769 }
770 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
771 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
772 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
773 {
774 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
775 SW_BREAKPOINT;
776 }
777 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
778 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
779 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
780 if (status != MessageQ_S_SUCCESS)
781 {
782 SW_BREAKPOINT;
783 }
785 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
786 // iff we are in this top level state machine and specifically not in decodeProcessing
787 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
789 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
791 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
792 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
793 if (errno)
794 {
795 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
796 }
797 else
798 {
799 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
800 }
802 // FL: send dec exit message to slave
803 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
804 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
805 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
806 pAspMsg->procId = hAspMsgMaster->masterProcId;
807 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
808 pAspMsg->expectResp = TRUE;
809 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
810 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
811 if (status != MessageQ_S_SUCCESS)
812 {
813 SW_BREAKPOINT;
814 }
815 // wait for dec exit complete message from slave
816 //do {
817 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
818 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
819 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
820 if (status != MessageQ_S_SUCCESS)
821 {
822 TRACE_TERSE0("MessageQ_get() failure.");
823 SW_BREAKPOINT; // temporary
824 }
825 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
826 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
827 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
828 {
829 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
830 SW_BREAKPOINT;
831 }
832 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
833 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
834 // free the message
835 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
836 if (status != MessageQ_S_SUCCESS)
837 {
838 SW_BREAKPOINT;
839 }
840 } // End of main processing loop for (;;)
842 Log_info0("Exit taskAsipFxn()");
843 }
845 // -----------------------------------------------------------------------------
846 // ASIT Initialization Function - Memory Allocation
847 //
848 // Name: PAF_ASIT_initPhaseMalloc
849 // Purpose: Audio Stream Input Task Function for initialization of data pointers
850 // by allocation of memory.
851 // From: audioStream1Task or equivalent
852 // Uses: See code.
853 // States: x
854 // Return: 0 on success.
855 // Source code line number on MEM_calloc failure.
856 // Trace: Message Log "trace" in Debug Project Configuration reports:
857 // * State information as per parent.
858 // * Memory allocation errors.
859 //
860 Int
861 PAF_ASIT_initPhaseMalloc(
862 const PAF_ASIT_Params *pP,
863 const PAF_ASIT_Patchs *pQ,
864 PAF_ASIT_Config *pC
865 )
866 {
867 PAF_AST_Config *pAstCfg;
868 Int as; /* Audio Stream Number (1, 2, etc.) */
869 Int zMS;
870 Error_Block eb;
872 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
873 as = pAstCfg->as;
874 zMS = pAstCfg->masterStr;
876 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
878 // Initialize error block
879 Error_init(&eb);
881 /* Input memory */
882 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
883 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
884 {
885 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
886 SW_BREAKPOINT;
887 return __LINE__;
888 }
889 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
890 INPUTN * sizeof (*pAstCfg->xInp),
891 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
893 /* Decode memory */
894 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
895 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
896 {
897 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
898 SW_BREAKPOINT;
899 return __LINE__;
900 }
901 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
902 DECODEN * sizeof (*pAstCfg->xDec),
903 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
905 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
906 return 0;
907 } //PAF_ASIT_initPhaseMalloc
909 // -----------------------------------------------------------------------------
910 // ASIT Initialization Function - Memory Initialization from Configuration
911 //
912 // Name: PAF_ASIT_initPhaseConfig
913 // Purpose: Audio Stream Task Function for initialization of data values
914 // from parameters.
915 // From: audioStream1Task or equivalent
916 // Uses: See code.
917 // States: x
918 // Return: 0 on success.
919 // Other as per initFrame0 and initFrame1.
920 // Trace: Message Log "trace" in Debug Project Configuration reports:
921 // * State information as per parent.
922 //
923 Int
924 PAF_ASIT_initPhaseConfig(
925 const PAF_ASIT_Params *pP,
926 const PAF_ASIT_Patchs *pQ,
927 PAF_ASIT_Config *pC
928 )
929 {
930 PAF_AST_Config *pAstCfg;
931 Int as; /* Audio Stream Number (1, 2, etc.) */
932 Int z; /* input/encode/stream/decode/output counter */
933 Int zMS;
935 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
936 as = pAstCfg->as;
937 zMS = pAstCfg->masterStr;
939 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
941 //
942 // Unspecified elements have been initialized to zero during alloc
943 //
945 for (z=INPUT1; z < INPUTN; z++)
946 {
947 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
948 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
949 }
951 for (z=DECODE1; z < DECODEN; z++)
952 {
953 Int zI = pP->inputsFromDecodes[z];
954 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
955 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
956 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
957 }
959 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
960 return 0;
961 } //PAF_ASIT_initPhaseConfig
963 // -----------------------------------------------------------------------------
964 // ASIT Initialization Function - ACP Algorithm Instantiation
965 //
966 // Name: PAF_ASIT_initPhaseAcpAlg
967 // Purpose: Audio Stream Input Task Function for initialization of ACP by
968 // instantiation of the algorithm.
969 // From: audioStream1Task or equivalent
970 // Uses: See code.
971 // States: x
972 // Return: 0 on success.
973 // Source code line number on ACP Algorithm creation failure.
974 // Trace: Message Log "trace" in Debug Project Configuration reports:
975 // * State information as per parent.
976 // * Memory allocation errors.
977 //
978 Int
979 PAF_ASIT_initPhaseAcpAlg(
980 const PAF_ASIT_Params *pP,
981 const PAF_ASIT_Patchs *pQ,
982 PAF_ASIT_Config *pC
983 )
984 {
985 PAF_AST_Config *pAstCfg;
986 Int as; /* Audio Stream Number (1, 2, etc.) */
987 Int z; /* input/encode/stream/decode/output counter */
988 Int betaPrimeOffset;
989 ACP_Handle acp;
990 Int zMS;
991 Int zS, zX;
993 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
994 as = pAstCfg->as;
995 zMS = pAstCfg->masterStr;
997 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
999 ACP_MDS_init();
1001 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1002 {
1003 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1004 return __LINE__;
1005 }
1006 pC->acp = acp;
1008 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1009 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1011 for (z=INPUT1; z < INPUTN; z++)
1012 {
1013 zS = z;
1014 for (zX = DECODE1; zX < DECODEN; zX++)
1015 {
1016 if (pP->inputsFromDecodes[zX] == z)
1017 {
1018 zS = pP->streamsFromDecodes[zX];
1019 break;
1020 }
1021 }
1022 acp->fxns->attach(acp, ACP_SERIES_STD,
1023 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1024 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1025 /* Ignore errors, not reported. */
1026 }
1028 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1030 return 0;
1031 } //PAF_ASIT_initPhaseAcpAlg
1033 // -----------------------------------------------------------------------------
1034 // ASIT Initialization Function - Common Memory
1035 //
1036 // Name: PAF_ASIT_initPhaseCommon
1037 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1038 // From: audioStream1Task or equivalent
1039 // Uses: See code.
1040 // States: x
1041 // Return: 0 on success.
1042 // Source code line number on PAF_ALG_alloc failure.
1043 // Source code line number on PAF_ALG_mallocMemory failure.
1044 // Source code line number on Decode Chain initialization failure.
1045 // Source code line number on ASP Chain initialization failure.
1046 // Source code line number on Encode Chain initialization failure.
1047 // Trace: Message Log "trace" in Debug Project Configuration reports:
1048 // * State information as per parent.
1049 // * Memory allocation errors.
1050 //
1051 Int
1052 PAF_ASIT_initPhaseCommon(
1053 const PAF_ASIT_Params *pP,
1054 const PAF_ASIT_Patchs *pQ,
1055 PAF_ASIT_Config *pC
1056 )
1057 {
1058 PAF_AST_Config *pAstCfg;
1059 Int as; /* Audio Stream Number (1, 2, etc.) */
1060 Int z; /* stream counter */
1061 ACP_Handle acp;
1062 PAF_IALG_Config pafAlgConfig;
1063 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1065 acp = pC->acp;
1066 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1067 as = pAstCfg->as;
1069 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1071 //
1072 // Determine memory needs and instantiate algorithms across audio streams
1073 //
1074 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1075 PAF_ALG_setup(&pafAlgConfig,
1076 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1077 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1078 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1079 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1080 HEAP_CLEAR);
1082 if (pP->fxns->headerPrint)
1083 {
1084 pP->fxns->headerPrint();
1085 }
1087 for (z = STREAM1; z < STREAMN; z++)
1088 {
1089 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1091 //
1092 // Determine common memory for:
1093 // (1) Logical Input drivers
1094 //
1095 // Decode Algorithms common memory determined in ASP Slave.
1096 //
1097 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1099 //
1100 // Determine common memory needs of Logical Input driver
1101 //
1103 // really need to loop over all inputs for this stream using the tables
1104 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1105 // patch, and not needed for FS11, since there is only one input.
1106 if (INPUT1 <= z && z < INPUTN)
1107 {
1108 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1109 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1110 {
1111 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1112 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1113 SW_BREAKPOINT;
1114 return __LINE__;
1115 }
1116 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1117 if (pP->fxns->allocPrint)
1118 {
1119 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1120 }
1121 }
1122 }
1123 {
1124 // Changes made to share scratch between zones
1125 // Assume maximum 3 zones and scratch common memory is at offset 0;
1126 int max=0;
1127 for (z=STREAM1; z<STREAMN; z++)
1128 {
1129 if (max < common[z][0].size)
1130 {
1131 max = common[z][0].size;
1132 }
1133 }
1134 common[STREAM1][0].size=max;
1135 for (z=STREAM1+1; z<STREAMN; z++)
1136 {
1137 common[z][0].size = 0;
1138 }
1139 }
1141 //
1142 // Allocate common memory for:
1143 // (1) Logical Input drivers
1144 //
1145 for (z = STREAM1; z < STREAMN; z++)
1146 {
1147 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1148 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1149 {
1150 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1151 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1152 SW_BREAKPOINT;
1153 return __LINE__;
1154 }
1155 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1156 // share zone0 scratch with all zones
1157 common[z][0].base = common[0][0].base;
1158 if (pP->fxns->commonPrint)
1159 {
1160 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1161 }
1163 //
1164 // Allocate non-common memories for Logical IO drivers
1165 // Since these structures are used at run-time we allocate from external memory
1166 if (INPUT1 <= z && z < INPUTN)
1167 {
1168 PAF_ASP_Chain *chain;
1169 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1170 as+z, z);
1171 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1172 HEAP_EXTERNAL, as+z, acp, &trace,
1173 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1174 if (!chain)
1175 {
1176 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1177 return __LINE__;
1178 }
1179 }
1180 }
1181 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1183 return 0;
1184 } //PAF_ASIT_initPhaseCommon
1186 // (***) FL: candidate for removal
1187 // -----------------------------------------------------------------------------
1188 // ASIT Initialization Function - Algorithm Keys
1189 //
1190 // Name: PAF_ASIT_initPhaseAlgKey
1191 // Purpose: Audio Stream Input Task Function for initialization of data values
1192 // from parameters for Algorithm Keys.
1193 // From: audioStream1Task or equivalent
1194 // Uses: See code.
1195 // States: x
1196 // Return: 0.
1197 // Trace: Message Log "trace" in Debug Project Configuration reports:
1198 // * State information as per parent.
1199 //
1200 // .............................................................................
1201 Int
1202 PAF_ASIT_initPhaseAlgKey(
1203 const PAF_ASIT_Params *pP,
1204 const PAF_ASIT_Patchs *pQ,
1205 PAF_ASIT_Config *pC
1206 )
1207 {
1208 PAF_AST_Config *pAstCfg;
1209 Int as; /* Audio Stream Number (1, 2, etc.) */
1212 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1213 as = pAstCfg->as;
1214 (void)as; // clear compiler warning in case not used with tracing disabled
1216 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1218 #if 0 // FL: slave
1219 for (z=DECODE1; z < DECODEN; z++)
1220 {
1221 for (s=0; s < pP->pDecAlgKey->length; s++)
1222 {
1223 if ((pP->pDecAlgKey->code[s].full != 0) &&
1224 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1225 {
1226 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1227 /* Cast in interface, for now --Kurt */
1228 }
1229 else
1230 {
1231 pC->xDec[z].decAlg[s] = NULL;
1232 }
1233 }
1234 }
1235 #endif
1237 return 0;
1238 } //PAF_ASIT_initPhaseAlgKey
1240 // -----------------------------------------------------------------------------
1241 // ASIT Initialization Function - I/O Devices
1242 //
1243 // Name: PAF_ASIT_initPhaseDevice
1244 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1245 // From: audioStream1Task or equivalent
1246 // Uses: See code.
1247 // States: x
1248 // Return: 0 on success.
1249 // Source code line number on device allocation failure.
1250 // Trace: Message Log "trace" in Debug Project Configuration reports:
1251 // * State information as per parent.
1252 // * Memory allocation errors.
1253 //
1254 Int
1255 PAF_ASIT_initPhaseDevice(
1256 const PAF_ASIT_Params *pP,
1257 const PAF_ASIT_Patchs *pQ,
1258 PAF_ASIT_Config *pC
1259 )
1260 {
1261 PAF_AST_Config *pAstCfg;
1262 Int as; /* Audio Stream Number (1, 2, etc.) */
1263 Int z; /* input/output counter */
1264 PAF_SIO_IALG_Obj *pObj;
1265 PAF_SIO_IALG_Config *pAlgConfig;
1266 PAF_IALG_Config pafAlgConfig;
1269 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1270 as = pAstCfg->as;
1271 (void)as; // clear compiler warning in case not used with tracing disabled
1273 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1275 if (pP->fxns->bufMemPrint)
1276 {
1277 PAF_ALG_setup (&pafAlgConfig,
1278 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1279 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1280 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1281 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1282 HEAP_CLEAR);
1283 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1284 }
1286 for (z=INPUT1; z < INPUTN; z++)
1287 {
1288 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1290 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1291 pAlgConfig = &pObj->config;
1293 pAstCfg->xInp[z].hRxSio = NULL;
1295 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1296 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1297 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1298 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1299 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1300 pConfig->sizeofElement = 2;
1301 pConfig->precision = 16;
1303 if (pP->fxns->bufMemPrint)
1304 {
1305 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1306 }
1307 }
1309 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1311 return 0;
1312 } //PAF_ASIT_initPhaseDevice
1314 // -----------------------------------------------------------------------------
1315 // ASIT Initialization Function - Decoder Output Circular Buffer
1316 //
1317 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1318 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1319 // From: audioStream1Task or equivalent
1320 // Uses: See code.
1321 // States: x
1322 // Return: 0 on success.
1323 // Source code line number on device allocation failure.
1324 // Trace: Message Log "trace" in Debug Project Configuration reports:
1325 // * State information as per parent.
1326 // * Memory allocation errors.
1327 //
1328 Int
1329 PAF_ASIT_initPhaseDecOpCircBuf(
1330 const PAF_ASIT_Params *pP,
1331 const PAF_ASIT_Patchs *pQ,
1332 PAF_ASIT_Config *pC
1333 )
1334 {
1335 PAF_AST_Config *pAstCfg;
1336 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1337 Int as; /* Audio Stream Number (1, 2, etc.) */
1338 Int zMS;
1339 Int z; /* decode counter */
1340 Int errno; /* error number */
1341 Error_Block eb;
1342 Int i;
1344 // FL: (***)revisit
1345 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1346 as = pAstCfg->as;
1347 zMS = pAstCfg->masterStr;
1349 /* Decode output circular buffer memory */
1350 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1351 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1352 {
1353 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1354 SW_BREAKPOINT;
1355 return __LINE__;
1356 }
1357 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1358 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1359 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1361 for (z=DECODE1; z < DECODEN; z++)
1362 {
1363 pCb = &pAstCfg->xDecOpCb[z];
1365 // allocate audio frame circular buffer
1366 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1367 {
1368 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1369 SW_BREAKPOINT;
1370 }
1371 // allocate audio frame PCM sample pointer array
1372 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1373 {
1374 if (!(pCb->afCb[i].data.sample = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH * sizeof(PAF_AudioData *), 4, &eb)))
1375 {
1376 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1377 SW_BREAKPOINT;
1378 }
1379 if (!(pCb->afCb[i].data.samsiz = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH * sizeof(PAF_AudioSize), 4, &eb)))
1380 {
1381 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1382 SW_BREAKPOINT;
1383 }
1384 }
1385 // allocate PCM sample buffer
1386 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1387 {
1388 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1389 SW_BREAKPOINT;
1390 }
1391 // allocate Metadata buffers //QIN
1392 if (!(pCb->metaBuf = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
1393 {
1394 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1395 SW_BREAKPOINT;
1396 }
1398 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
1399 // Initialize decoder output circular buffer for PCM
1400 errno = cbInit(pCb);
1401 if (errno)
1402 {
1403 SW_BREAKPOINT; // FL: debug
1404 return errno;
1405 }
1406 }
1408 return 0;
1409 } //PAF_ASIT_initPhaseDecOpCircBuf
1412 #if 0
1413 // -----------------------------------------------------------------------------
1414 // AST Processing Function - Pass-Through Processing
1415 //
1416 // Name: PAF_AST_passProcessing
1417 // Purpose: Audio Stream Task Function for processing audio data as a
1418 // pass-through from the input driver to the output driver
1419 // for development and testing.
1420 // From: audioStream1Task or equivalent
1421 // Uses: See code.
1422 // States: x
1423 // Return: Error number in standard form (0 on success).
1424 // Trace: Message Log "trace" in Debug Project Configuration reports:
1425 // * State information on initialization.
1426 // * State information on processing.
1427 //
1429 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1430 /* Pass Processing is often omitted from builds to save memory, */
1431 /* and CODE_SECTION/clink constructs facilitate this omission. */
1433 Int
1434 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1435 {
1436 Int z; /* input/output counter */
1437 Int errno = 0; /* error number */
1438 Int getVal;
1439 Int rxNumChan, txNumChan;
1440 Int first;
1441 Int zMD = pC->masterDec;
1442 Int zMI = pP->zone.master;
1445 #ifndef __TI_EABI__
1446 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1447 #endif
1449 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1451 //
1452 // Determine that receive/transmit channels are compatible
1453 //
1455 // Can handle handle only master input
1456 for (z=INPUT1; z < INPUTN; z++) {
1457 if (z != zMI && pC->xInp[z].hRxSio)
1458 return (ASPERR_PASS + 0x01);
1459 }
1461 /* Number of receive/transmit channels */
1463 if (! pC->xInp[zMI].hRxSio)
1464 return (ASPERR_PASS + 0x11);
1465 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1466 return (ASPERR_PASS + 0x12);
1467 if (rxNumChan > NUM_TX_CHAN(zMI))
1468 return (ASPERR_PASS + 0x13);
1470 for (z=OUTPUT1; z < OUTPUTN; z++) {
1471 if (! pC->xOut[zMI].hTxSio)
1472 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1473 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1474 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1475 if (txNumChan > NUM_TX_CHAN(zMI))
1476 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1477 }
1479 //
1480 // Set up receive/transmit
1481 //
1483 SIO_idle (pC->xInp[zMI].hRxSio);
1484 for (z=OUTPUT1; z < OUTPUTN; z++) {
1485 if(SIO_idle (pC->xOut[z].hTxSio))
1486 return ASPERR_IDLE;
1487 }
1489 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1490 return (ASPERR_PASS + 0x14);
1492 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1493 return (ASPERR_PASS + 0x15);
1495 for (z=OUTPUT1; z < OUTPUTN; z++)
1496 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1498 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1499 return ASPERR_PASS + 0x16;
1501 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1502 return ASPERR_PASS + 0x17;
1504 //
1505 // Receive and transmit the data in single-frame buffers
1506 //
1508 first = 1;
1509 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1510 PAF_OutBufConfig *pOutBuf;
1511 PAF_InpBufConfig *pInpBuf;
1513 if (first) {
1514 first = 0;
1516 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1518 for (z=OUTPUT1; z < OUTPUTN; z++) {
1519 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1520 if (getVal > 0) {
1521 errno = ASPERR_ISSUE;
1522 break;
1523 }
1524 else if (getVal < 0) {
1525 errno = -getVal;
1526 break;
1527 }
1529 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1530 return (getVal & 0xff) | ASPERR_MUTE;
1531 }
1532 if (errno)
1533 break;
1535 }
1537 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1538 if (getVal > 0) {
1539 errno = ASPERR_ISSUE;
1540 break;
1541 }
1543 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1545 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1546 if (getVal < 0) {
1547 errno = -getVal;
1548 break;
1549 }
1551 for (z=OUTPUT1; z < OUTPUTN; z++) {
1552 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1553 if (getVal < 0) {
1554 errno = -getVal;
1555 break;
1556 }
1557 }
1558 if( errno )
1559 break;
1561 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1563 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1564 break;
1566 for (z=OUTPUT1; z < OUTPUTN; z++) {
1567 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1568 if (getVal > 0) {
1569 errno = ASPERR_ISSUE;
1570 break;
1571 }
1572 else if (getVal < 0) {
1573 errno = -getVal;
1574 break;
1575 }
1576 }
1577 if( errno )
1578 break;
1579 }
1581 //
1582 // Close down receive/transmit
1583 //
1585 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1587 for (z=OUTPUT1; z < OUTPUTN; z++) {
1588 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1589 if (! errno)
1590 errno = (getVal & 0xff) | ASPERR_MUTE;
1591 /* convert to sensical errno */
1592 }
1593 }
1595 SIO_idle (pC->xInp[zMI].hRxSio);
1596 for (z=OUTPUT1; z < OUTPUTN; z++)
1597 SIO_idle (pC->xOut[z].hTxSio);
1599 return errno;
1601 } //PAF_AST_passProcessing
1602 #endif // #if 0
1604 #if 0
1605 // -----------------------------------------------------------------------------
1606 // AST Processing Function Helper - Pass-Through Processing Patch Point
1607 //
1608 // Name: PAF_AST_passProcessingCopy
1609 // Purpose: Pass-Through Processing Function for copying audio data
1610 // from the input buffer to the output buffer.
1611 // From: AST Parameter Function -> passProcessing
1612 // Uses: See code.
1613 // States: x
1614 // Return: Error number in standard form (0 on success).
1615 // Trace: Message Log "trace" in Debug Project Configuration reports:
1616 // x
1617 //
1619 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1620 /* Pass Processing is often omitted from builds to save memory, */
1621 /* and CODE_SECTION/clink constructs facilitate this omission. */
1623 Int
1624 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1625 {
1626 Int z; /* output counter */
1627 Int errno; /* error number */
1628 Int i;
1629 Int rxNumChan, txNumChan;
1630 Int zMI = pP->zone.master;
1633 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1635 // Copy data from input channels to output channels one of two ways:
1637 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1638 return (ASPERR_PASS + 0x12);
1640 for (z=OUTPUT1; z < OUTPUTN; z++) {
1641 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1642 return (ASPERR_PASS + 0x22);
1644 if( txNumChan <= rxNumChan ) {
1646 // Copy one to one, ignoring later rx channels as needed.
1648 for( i=0; i < txNumChan; i++ ) {
1649 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1650 if( errno )
1651 return errno;
1652 }
1653 }
1654 else {
1656 // Copy one to many, repeating earlier rx channels as needed.
1658 Int from, to;
1660 from = 0;
1661 to = 0;
1662 while( to < txNumChan ) {
1663 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1664 if( errno )
1665 return errno;
1667 from++;
1668 to++;
1669 if( from == rxNumChan )
1670 from = 0;
1671 }
1672 }
1673 }
1675 return 0;
1676 } //PAF_AST_passProcessingCopy
1677 #endif // #if 0
1679 // -----------------------------------------------------------------------------
1680 // ASIT Processing Function - Auto Processing
1681 //
1682 // Name: PAF_ASIT_autoProcessing
1683 // Purpose: Audio Stream Input Task Function for processing audio data to
1684 // determine the input type without output.
1685 // From: audioStream1Task or equivalent
1686 // Uses: See code.
1687 // States: x
1688 // Return: Error number in standard or SIO form (0 on success).
1689 // Trace: Message Log "trace" in Debug Project Configuration reports:
1690 // * State information on initialization.
1691 //
1693 #define DECSIOMAP(X) \
1694 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1696 Int
1697 PAF_ASIT_autoProcessing(
1698 const PAF_ASIT_Params *pP,
1699 const PAF_ASIT_Patchs *pQ,
1700 PAF_ASIT_Config *pC,
1701 Int inputTypeSelect,
1702 ALG_Handle pcmAlgMaster
1703 )
1704 {
1705 PAF_AST_Config *pAstCfg;
1706 Int as; /* Audio Stream Number (1, 2, etc.) */
1707 Int errno = 0; /* error number */
1708 Int nbytes;
1709 Int frameLength;
1710 Int zMD;
1711 Int zMI;
1712 Int zMS;
1714 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1715 as = pAstCfg->as;
1716 zMD = pAstCfg->masterDec;
1717 zMS = pAstCfg->masterStr;
1718 zMI = pP->zone.master;
1720 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1722 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1723 PAF_SIO_CONTROL_SET_SOURCESELECT,
1724 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1725 {
1726 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1727 return errno;
1728 }
1729 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1730 // pC->xDec[zMD].decodeStatus.bufferRatio);
1731 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1733 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1734 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1735 {
1736 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1737 errno, ASPERR_AUTO_LENGTH);
1738 return ASPERR_AUTO_LENGTH;
1739 }
1741 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1742 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1743 PAF_SIO_REQUEST_SYNC))
1744 {
1745 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1746 errno, ASPERR_ISSUE);
1747 return ASPERR_ISSUE;
1748 }
1750 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1752 // all of the sync scan work is done in this call. If the error returned
1753 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1754 // error so we mask it off.
1755 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1756 if (nbytes == -DIBERR_SYNC)
1757 {
1758 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1759 return 0;
1760 }
1761 if (nbytes != sizeof(PAF_InpBufConfig))
1762 {
1763 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1764 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1765 return ASPERR_RECLAIM;
1766 }
1767 if (errno)
1768 {
1769 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1770 }
1771 return errno;
1772 } //PAF_ASIT_autoProcessing
1774 // -----------------------------------------------------------------------------
1775 // ASIT Processing Function - Decode Processing
1776 //
1777 // Name: PAF_ASIT_decodeProcessing
1778 // Purpose: Audio Stream Input Task Function for processing audio data.
1779 // From: audioStream1Task or equivalent
1780 // Uses: See code.
1781 // States: x
1782 // Return: Error number in standard form (0 on success).
1783 // Trace: Message Log "trace" in Debug Project Configuration reports:
1784 // * State information on initialization (via children).
1785 // * State information on processing (via children).
1786 // * Decode warnings.
1787 //
1788 // When "writeDECModeContinuous" is used for zMI input/decode:
1789 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1790 // (a) if "writeDECCommandRestart" is used
1791 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1792 // (b) if "writeDECSourceSelectNone" is used
1793 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1794 // (c) if an error occurs in
1795 // INIT
1796 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1797 // -> PAF_AST_decodeCont(): "Await slave inputs"
1798 // STREAM (errno |= PAF_COMPONENT_ASP)
1799 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1800 // [ the latter errors lead to "switch_break:"
1801 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1802 //
1803 // [ Notably, in FINAL ("frame-finalization state")
1804 // -> PAF_AST_decodeFinalTest() is *not* called,
1805 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1806 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1807 //
1808 // States in which error can't occur:
1809 // AGAIN ("subsequent initial state")
1810 //
1811 // States in which (some) errors must be handled:
1812 // INFO1 ("first frame state")
1813 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1814 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1815 // ?*? but what about ASPERR_RESYNC from same call ?*?
1816 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1817 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1818 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1819 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1820 // - enc->fxns->info()
1821 // - pP->fxns->setCheckRateX()
1822 // - pP->fxns->startOutput()
1823 // - "Start slave inputs if necessary"
1824 // INFO2 ("subsequent frame state")
1825 // -> PAF_AST_decodeInfo(): (see above)
1826 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1827 // - pP->fxns->setCheckRateX()
1828 // TIME ("timing state")
1829 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1830 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1831 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1832 // (*OK* don't try to recover from this*)
1833 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1834 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1835 // possibly in PAF_AST_decodeProcessing() itself **
1836 // DECODE ("decode state")
1837 // -> PAF_AST_decodeDecode(): pass on error from
1838 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1839 // - dec->fxns->reset()
1840 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
1841 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
1842 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
1843 Int
1844 PAF_ASIT_decodeProcessing(
1845 const PAF_ASIT_Params *pP,
1846 const PAF_ASIT_Patchs *pQ,
1847 PAF_ASIT_Config *pC,
1848 Int sourceSelect
1849 )
1850 {
1851 PAF_AST_Config *pAstCfg;
1852 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
1853 Int z; /* decode counter */
1854 Int errno; /* error number */
1855 Int getVal;
1856 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
1857 ALG_Handle alg[DECODEN_MAX];
1858 Int zMD;
1859 Int zMS;
1860 Int size;
1861 //PAF_InpBufConfig *pIpBufConfig;
1862 Int frame; // decoder input frame count
1863 Int block; // (***) FL: formerly -- decoder output block count / input frame
1866 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1867 zMD = pAstCfg->masterDec;
1868 zMS = pAstCfg->masterStr;
1870 for (z=DECODE1; z < DECODEN; z++)
1871 {
1872 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
1873 }
1874 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
1876 //
1877 // Receive and process the data in single-frame buffers
1878 //
1880 state = INIT;
1881 errno = 0; /* error number */
1883 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
1885 for (;;)
1886 {
1887 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
1888 {
1889 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1890 state = QUIT;
1891 }
1893 // Process commands (decode)
1894 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
1895 {
1896 if (state != INIT) // no need to restart/abort if not yet started
1897 {
1898 if (getVal == ASPERR_QUIT)
1899 {
1900 state = QUIT;
1901 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1902 }
1903 else if (getVal == ASPERR_ABORT)
1904 {
1905 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1906 return getVal;
1907 }
1908 else
1909 {
1910 /* ignore */;
1911 }
1912 }
1913 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
1914 }
1916 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
1917 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
1919 // Process state (decode)
1920 switch (state)
1921 {
1922 case INIT: // initial state
1923 gAsipInitCnt++;
1924 Log_info0("TaskAsip: state=INIT");
1926 // (***) FL: revisit
1927 #if 1 // status for shared beta units can change (e.g. at-boot or alpha)
1928 // write back Status structures for shared Beta Units
1929 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1930 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1931 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1932 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1933 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1934 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1935 Cache_wait();
1936 #endif
1937 #if 0
1938 ////size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1939 ////Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1940 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1941 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1942 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1943 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1944 //Cache_wait();
1945 #endif
1947 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
1948 {
1949 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
1950 break;
1951 }
1953 #if 1
1954 // (***) FL: revisit
1955 // invalidate Status structures for shared Beta Units
1956 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
1957 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
1958 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
1959 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
1960 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
1961 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
1962 Cache_wait();
1963 #endif
1965 frame = 0;
1966 block = 0;
1968 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
1969 state = INFO1;
1970 continue;
1972 case INFO1: // first frame state
1973 gAsipInfo1Cnt++;
1974 Log_info0("TaskAsip: state=INFO1");
1976 #if 0
1977 //// (***) FL: revisit
1978 //// write back Inp configuration
1979 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
1980 //// write back input data
1981 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
1982 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
1983 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
1984 //// write back Dec configuration
1985 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
1986 //Cache_wait();
1987 #endif
1989 // Establish primary timing
1990 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
1991 {
1992 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
1993 break;
1994 }
1996 #if 0
1997 //// (***) FL: revisit
1998 //// invalidate Dec configuration
1999 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2000 //Cache_wait();
2001 #endif
2003 // Don't start decode until major access unit is found.
2004 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
2005 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
2006 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2007 (pAstCfg->xStr[zMS].pAudioFrame->sampleRate == PAF_SAMPLERATE_UNKNOWN))
2008 {
2009 Int z;
2010 for (z=DECODE1; z < DECODEN; z++)
2011 {
2012 Int zI = pP->inputsFromDecodes[z];
2013 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2014 {
2015 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2016 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2017 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2018 {
2019 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2020 return (ASPERR_ISSUE);
2021 }
2022 }
2023 }
2024 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2025 frame++;
2026 state = INFO1;
2027 continue;
2028 }
2029 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2031 // Establish secondary timing
2032 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2033 {
2034 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2035 break;
2036 }
2038 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2039 state = DECODE;
2040 continue;
2042 case INFO2: // subsequent frame state
2043 gAsipInfo2Cnt++;
2044 Log_info0("TaskAsip: state=INFO2");
2046 #if 0
2047 //// (***) FL: revisit
2048 //// write back Inp configuration
2049 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2050 //// write back input data
2051 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2052 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2053 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2054 //// write back Dec configuration
2055 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2056 //Cache_wait();
2057 #endif
2059 // Establish primary timing
2060 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2061 {
2062 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2063 break;
2064 }
2066 #if 0
2067 //// (***) FL: revisit
2068 //// invalidate Dec configuration
2069 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2070 //Cache_wait();
2071 #endif
2073 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2074 {
2075 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2076 break;
2077 }
2079 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2080 state = DECODE;
2081 continue;
2083 case DECODE: // decode state
2084 gAsipDecodeCnt++;
2085 Log_info0("TaskAsip: state=DECODE");
2087 #if 0
2088 //// (***) FL: revisit
2089 //// write back Dec configuration
2090 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2091 //Cache_wait();
2092 #endif
2094 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2095 {
2096 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2097 break;
2098 }
2100 #if 0
2101 //// (***) FL: revisit
2102 //// invalidate Dec configuration
2103 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2104 //Cache_wait();
2105 #endif
2107 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2108 state = FINAL;
2109 continue;
2111 case FINAL: // frame-finalization state
2112 gAsipFinalCnt++;
2113 Log_info0("TaskAsip: state=FINAL");
2115 // Check for final frame, and if indicated:
2116 // - Exit state machine to "complete" processing.
2117 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2118 {
2119 break;
2120 }
2122 frame++;
2123 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2124 state = INFO2;
2125 continue;
2127 case QUIT: // exit state
2128 gAsipQuitCnt++;
2129 Log_info0("TaskAsip: state=QUIT");
2131 // Quit:
2132 // - Set error number registers.
2133 // - Exit state machine to "decode complete" processing.
2134 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2135 errno = ASPERR_QUIT;
2136 break;
2138 default: // unknown state
2140 // Unknown:
2141 // - Set error number registers.
2142 // - Exit state machine to "decode complete" processing.
2144 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2145 errno = ASPERR_UNKNOWNSTATE;
2146 break;
2148 } // End of switch (state).
2150 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2151 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2152 {
2153 /* ignored? */;
2154 }
2156 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2158 return errno;
2159 } // End of for (;;) to Receive, process, and transmit the data.
2160 } //PAF_ASIT_decodeProcessing
2162 // -----------------------------------------------------------------------------
2163 // ASIT Decoding Function - Decode Command Processing
2164 //
2165 // Name: PAF_ASIT_decodeCommand
2166 // Purpose: Decoding Function for processing Decode Commands.
2167 // From: AST Parameter Function -> decodeProcessing
2168 // Uses: See code.
2169 // States: x
2170 // Return: Error number in standard form (0 on success).
2171 // Trace: Message Log "trace" in Debug Project Configuration reports:
2172 // * Command execution.
2173 //
2175 Int
2176 PAF_ASIT_decodeCommand(
2177 const PAF_ASIT_Params *pP,
2178 const PAF_ASIT_Patchs *pQ,
2179 PAF_ASIT_Config *pC
2180 )
2181 {
2182 PAF_AST_Config *pAstCfg;
2183 Int as; /* Audio Stream Number (1, 2, etc.) */
2184 Int z; /* decode counter */
2185 Int zS;
2187 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2188 as = pAstCfg->as;
2190 for (z=DECODE1; z < DECODEN; z++)
2191 {
2192 zS = pP->streamsFromDecodes[z];
2193 if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2194 {
2195 switch (pAstCfg->xDec[z].decodeStatus.command2)
2196 {
2197 case 0: // command none - process
2198 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2199 break;
2200 case 1: // command abort - leave now
2201 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2202 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2203 return (ASPERR_ABORT);
2204 case 2: // command restart - leave later
2205 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2206 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2207 return (ASPERR_QUIT);
2208 default: // command unknown - ignore
2209 break;
2210 }
2211 }
2212 }
2214 return 0;
2215 } //PAF_ASIT_decodeCommand
2217 // -----------------------------------------------------------------------------
2218 // ASIT Decoding Function - Reinitialization of Decode
2219 //
2220 // Name: PAF_ASIT_decodeInit
2221 // Purpose: Decoding Function for reinitializing the decoding process.
2222 // From: AST Parameter Function -> decodeProcessing
2223 // Uses: See code.
2224 // States: x
2225 // Return: Error number in standard or SIO form (0 on success).
2226 // Trace: Message Log "trace" in Debug Project Configuration reports:
2227 // * State information as per parent.
2228 //
2229 Int
2230 PAF_ASIT_decodeInit(
2231 const PAF_ASIT_Params *pP,
2232 const PAF_ASIT_Patchs *pQ,
2233 PAF_ASIT_Config *pC,
2234 Int sourceSelect
2235 )
2236 {
2237 PAF_AST_Config *pAstCfg;
2238 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2239 Int as; /* Audio Stream Number (1, 2, etc.) */
2240 Int z; /* decode/encode counter */
2241 Int errno; /* error number */
2242 Int zI, zS;
2243 Int zMD;
2244 Int zMI;
2245 ASP_Msg* pAspMsg; /* Messaging */
2246 Int argIdx;
2247 Int decErrno;
2248 Int status;
2250 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2251 as = pAstCfg->as;
2252 zMD = pAstCfg->masterDec;
2253 zMI = pP->zone.master;
2254 (void)as; // clear compiler warning in case not used with tracing disabled
2256 pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2258 // reset frameCount
2259 for (z=DECODE1; z < DECODEN; z++)
2260 {
2261 if (pAstCfg->xDec[z].decodeStatus.mode)
2262 {
2263 pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2264 }
2265 }
2267 for (z=DECODE1; z < DECODEN; z++)
2268 {
2269 zI = pP->inputsFromDecodes[z];
2270 zS = pP->streamsFromDecodes[z];
2271 (void)zS; // clear compiler warning in case not used with tracing disabled
2272 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2273 {
2274 Uns gear;
2275 Int frameLength;
2276 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2278 // write back Dec configuration
2279 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2280 Cache_wait();
2282 // FL: send dec activate message to slave
2283 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2284 if (pAspMsg == NULL)
2285 {
2286 TRACE_TERSE0("MessageQ_alloc() failure.");
2287 SW_BREAKPOINT; // temporary
2288 return -1; // temporary
2289 }
2290 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2291 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2292 pAspMsg->procId = hAspMsgMaster->masterProcId;
2293 pAspMsg->expectResp = TRUE;
2294 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2295 argIdx = 0; // set decIdx (zone index)
2296 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2297 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2298 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2299 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2300 if (status != MessageQ_S_SUCCESS)
2301 {
2302 SW_BREAKPOINT;
2303 }
2304 // wait for dec activate complete message from slave
2305 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2306 if (status != MessageQ_S_SUCCESS)
2307 {
2308 TRACE_TERSE0("MessageQ_get() failure.");
2309 SW_BREAKPOINT; // temporary
2310 return -1; // temporary
2311 }
2312 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2313 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2314 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2315 {
2316 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2317 SW_BREAKPOINT; // temporary
2318 return -1; // temporary
2319 }
2320 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2321 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2322 // free the message
2323 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2324 if (status != MessageQ_S_SUCCESS)
2325 {
2326 SW_BREAKPOINT;
2327 }
2329 #if 0 // FL: decoder activate call, slave
2330 if (decAlg[z]->fxns->algActivate)
2331 decAlg[z]->fxns->algActivate (decAlg[z]);
2332 #endif
2334 // FL: send dec reset message to slave
2335 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2336 if (pAspMsg == NULL)
2337 {
2338 TRACE_TERSE0("MessageQ_alloc() failure.");
2339 SW_BREAKPOINT; // temporary
2340 return -1; // temporary
2341 }
2342 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2343 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2344 pAspMsg->procId = hAspMsgMaster->masterProcId;
2345 pAspMsg->expectResp = TRUE;
2346 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2347 argIdx = 0; // set decIdx
2348 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2349 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2350 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2351 // wait for dec reset complete message from slave
2352 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2353 if (status != MessageQ_S_SUCCESS)
2354 {
2355 SW_BREAKPOINT;
2356 }
2357 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2358 if (status != MessageQ_S_SUCCESS)
2359 {
2360 TRACE_TERSE0("MessageQ_get() failure.");
2361 SW_BREAKPOINT; // temporary
2362 return -1; // temporary
2363 }
2364 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2365 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2366 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2367 {
2368 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2369 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2370 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2372 argIdx = 0; // get decErrno
2373 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2374 if (decErrno != 0)
2375 {
2376 return decErrno;
2377 }
2378 }
2379 else
2380 {
2381 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2382 SW_BREAKPOINT; // temporary
2383 return -1; // temporary
2384 }
2385 // free the message
2386 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2387 if (status != MessageQ_S_SUCCESS)
2388 {
2389 SW_BREAKPOINT;
2390 }
2392 // (***) FL: revisit
2393 // invalidate Dec configuration
2394 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2395 Cache_wait();
2397 #if 0 // FL: decoder reset call, slave
2398 if (dec->fxns->reset
2399 && (errno = dec->fxns->reset (dec, NULL,
2400 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2401 return errno;
2402 #endif
2404 gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2405 pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2407 #if 0 // FL: change handle to decIdx (zone index)
2408 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2409 FRAMELENGTH,
2410 pC->xDec[z].decodeStatus.bufferRatio);
2411 #endif
2412 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2413 frameLength = pP->fxns->computeFrameLength(z,
2414 FRAMELENGTH,
2415 pC->xDec[z].decodeStatus.bufferRatio);
2416 #else
2417 if (sourceSelect == PAF_SOURCE_PCM)
2418 {
2419 frameLength = 256;
2420 }
2421 else if (sourceSelect == PAF_SOURCE_DDP)
2422 {
2423 frameLength = 1536;
2424 }
2425 else
2426 {
2427 frameLength = 256;
2428 }
2429 #endif
2431 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2432 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2433 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2435 // (***) FL: revisit. Count samples for DDP.
2436 // Add framework frame length and running sample count to decoder control.
2437 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2438 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2440 // Initialize decoder output circular buffer for selected source
2441 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2442 if (errno)
2443 {
2444 SW_BREAKPOINT; // FL: debug
2445 return errno;
2446 }
2447 // FL: debug
2448 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2450 if (z != zMD)
2451 {
2452 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2453 {
2454 return errno;
2455 }
2456 }
2458 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2459 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2460 {
2461 return errno;
2462 }
2463 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2464 frameLength))
2465 {
2466 return errno;
2467 }
2468 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2469 &pAstCfg->xInp[zI].inpBufConfig))
2470 {
2471 return errno;
2472 }
2473 }
2474 }
2476 if (pAstCfg->xInp[zMI].hRxSio)
2477 {
2478 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2479 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2480 if (errno)
2481 {
2482 return errno;
2483 }
2484 }
2486 return 0;
2487 } //PAF_AST_decodeInit
2489 // -----------------------------------------------------------------------------
2490 // ASIT Decoding Function - Info Processing, Common
2491 //
2492 // Name: PAF_ASIT_decodeInfo
2493 // Purpose: Decoding Function for processing information in a manner that
2494 // is common for both initial and subsequent frames of input data.
2495 // From: AST Parameter Function -> decodeProcessing
2496 // Uses: See code.
2497 // States: x
2498 // Return: Error number in standard form (0 on success).
2499 // Trace: Message Log "trace" in Debug Project Configuration reports:
2500 // * State information as per parent.
2501 //
2502 Int
2503 PAF_ASIT_decodeInfo(
2504 const PAF_ASIT_Params *pP,
2505 const PAF_ASIT_Patchs *pQ,
2506 PAF_ASIT_Config *pC,
2507 Int frame,
2508 Int block
2509 )
2510 {
2511 PAF_AST_Config *pAstCfg;
2512 Int as; /* Audio Stream Number (1, 2, etc.) */
2513 Int z; /* input/decode/stream counter */
2514 Int errno; /* error number */
2515 Int sioErr; /* error number, SIO */
2516 Int zD, zI, zS, zX;
2517 Int zMD;
2518 Int zMI;
2519 Int zMS;
2520 UInt32 curTime;
2521 ASP_Msg *pAspMsg; /* Messaging */
2522 Int argIdx;
2523 Int status;
2524 // FL: revisit
2525 //Int size;
2526 //PAF_InpBufConfig *pIpBufConfig;
2528 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2529 as = pAstCfg->as;
2530 zMD = pAstCfg->masterDec;
2531 zMS = pAstCfg->masterStr;
2532 zMI = pP->zone.master;
2533 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2535 // Set decode control: sample rate, emphasis
2536 for (z=INPUT1; z < INPUTN; z++)
2537 {
2538 zD = z;
2539 for (zX = DECODE1; zX < DECODEN; zX++)
2540 {
2541 if (pP->inputsFromDecodes[zX] == z)
2542 {
2543 zD = zX;
2544 break;
2545 }
2546 }
2548 if (pAstCfg->xInp[z].hRxSio)
2549 {
2550 //determine associated decoder
2551 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2552 pAstCfg->xDec[zD].decodeControl.sampleRate)
2553 {
2554 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2555 {
2556 pAstCfg->xDec[zD].decodeControl.sampleRate =
2557 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2558 }
2559 else
2560 {
2561 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2562 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2563 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2564 pAstCfg->xDec[zD].decodeControl.sampleRate);
2565 // return (ASPERR_INFO_RATECHANGE);
2566 }
2567 }
2568 pAstCfg->xDec[zD].decodeControl.emphasis =
2569 pAstCfg->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2570 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2571 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2572 }
2573 else
2574 {
2575 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2576 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2577 }
2578 }
2580 // Wait for info input
2581 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2582 if (pAstCfg->xInp[zMI].hRxSio)
2583 {
2584 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2585 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2586 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2587 {
2588 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2589 return ASPERR_RECLAIM;
2590 }
2592 // FL: debug, capture input buffer
2593 //capIb(pAstCfg->xInp[zMI].pInpBuf);
2595 //
2596 // Simulate Rx SIO_reclaim() pend
2597 //
2598 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2599 gTaskAsipCnt++;
2600 curTime = Clock_getTicks();
2601 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
2602 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2603 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2604 } //pC->xInp[zMI].hRxSio
2606 // Decode info
2607 for (z=DECODE1; z < DECODEN; z++)
2608 {
2609 zI = pP->inputsFromDecodes[z];
2610 zS = pP->streamsFromDecodes[z];
2611 (void)zS; // clear compiler warning in case not used with tracing disabled
2612 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2613 {
2614 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2616 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2617 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2618 {
2619 TRACE_TERSE1("return error errno 0x%x.", errno);
2620 return errno;
2621 }
2623 #if 1
2624 // (***) FL: revisit
2625 // write back Inp configuration
2626 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2627 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2628 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2629 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2630 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2631 // write back Dec configuration
2632 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2633 Cache_wait();
2634 #endif
2636 // FL: send info message to slave
2637 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2638 if (pAspMsg == NULL)
2639 {
2640 TRACE_TERSE0("MessageQ_alloc() failure.");
2641 SW_BREAKPOINT; // temporary
2642 return -1; // temporary
2643 }
2644 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2645 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
2646 pAspMsg->procId = hAspMsgMaster->masterProcId;
2647 pAspMsg->expectResp = TRUE;
2648 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2649 argIdx = 0; // set decIdx
2650 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2651 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2652 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2653 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
2654 if (status != MessageQ_S_SUCCESS)
2655 {
2656 SW_BREAKPOINT;
2657 }
2658 // wait for dec info complete message from slave -- temporary
2659 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2660 if (status != MessageQ_S_SUCCESS)
2661 {
2662 TRACE_TERSE0("MessageQ_get() failure.");
2663 SW_BREAKPOINT;
2664 return -1; // temporary
2665 }
2666 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2667 (pAspMsg->cmd != ASP_MASTER_DEC_INFO_DONE) ||
2668 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2669 &nbs