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"
74 #include "statusOp_common.h"
77 // -----------------------------------------------------------------------------
78 // Debugging Trace Control, local to this file.
79 //
80 #include "logp.h"
82 #define TRACE_ARC(a)
84 // allows you to set a different trace module in pa.cfg
85 #define TR_MOD trace
87 // Allow a developer to selectively enable tracing.
88 #define CURRENT_TRACE_MASK 0x21
90 #define TRACE_MASK_TERSE 0x01 // only flag errors and show init
91 #define TRACE_MASK_GENERAL 0x02 // half dozen lines per frame
92 #define TRACE_MASK_VERBOSE 0x04 // trace full operation
93 #define TRACE_MASK_DATA 0x08 // Show data
94 #define TRACE_MASK_TIME 0x10 // Timing related traces
95 #define TRACE_MASK_MSG 0x20 // Message related traces
97 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
98 #undef TRACE_TERSE0
99 #undef TRACE_TERSE1
100 #undef TRACE_TERSE2
101 #undef TRACE_TERSE3
102 #undef TRACE_TERSE4
103 #define TRACE_TERSE0(a)
104 #define TRACE_TERSE1(a,b)
105 #define TRACE_TERSE2(a,b,c)
106 #define TRACE_TERSE3(a,b,c,d)
107 #define TRACE_TERSE4(a,b,c,d,e)
108 #endif
110 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
111 #undef TRACE_GEN0
112 #undef TRACE_GEN1
113 #undef TRACE_GEN2
114 #undef TRACE_GEN3
115 #undef TRACE_GEN4
116 #define TRACE_GEN0(a)
117 #define TRACE_GEN1(a,b)
118 #define TRACE_GEN2(a,b,c)
119 #define TRACE_GEN3(a,b,c,d)
120 #define TRACE_GEN4(a,b,c,d,e)
121 #endif
123 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
124 // consolidate list of processing strings, indexed by PAF_SOURCE
125 static char *procName[] =
126 {
127 "", //PAF_SOURCE_UNKNOWN
128 "", //PAF_SOURCE_NONE
129 "AS%d: Pass processing ...", //PAF_SOURCE_PASS
130 "AS%d: SNG processing ...", //PAF_SOURCE_SNG
131 "AS%d: Auto processing ...", //PAF_SOURCE_AUTO
132 "AS%d: Auto processing ...", //PAF_SOURCE_BITSTREAM
133 "AS%d: DTS processing ...", //PAF_SOURCE_DTSALL
134 "AS%d: PCM processing ...", //PAF_SOURCE_PCMAUTO
135 "AS%d: PCM processing ...", //PAF_SOURCE_PCM
136 "AS%d: PCN processing ...", //PAF_SOURCE_PC8
137 "AS%d: AC3 processing ...", //PAF_SOURCE_AC3
138 "AS%d: DTS processing ...", //PAF_SOURCE_DTS
139 "AS%d: AAC processing ...", //PAF_SOURCE_AAC
140 "AS%d: MPG processing ...", //PAF_SOURCE_MPEG
141 "AS%d: DTS processing ...", //PAF_SOURCE_DTS12
142 "AS%d: DTS processing ...", //PAF_SOURCE_DTS13
143 "AS%d: DTS processing ...", //PAF_SOURCE_DTS14
144 "AS%d: DTS processing ...", //PAF_SOURCE_DTS16
145 "AS%d: WMP processing ...", //PAF_SOURCE_WMA9PRO
146 "AS%d: MP3 processing ...", //PAF_SOURCE_MP3
147 "AS%d: DSD processing ...", //PAF_SOURCE_DSD1
148 "AS%d: DSD processing ...", //PAF_SOURCE_DSD2
149 "AS%d: DSD processing ...", //PAF_SOURCE_DSD3
150 "AS%d: DDP processing ...", //PAF_SOURCE_DDP
151 "AS%d: DTSHD processing ...", //PAF_SOURCE_DTSHD
152 "AS%d: THD processing ...", //PAF_SOURCE_THD
153 "AS%d: DXP processing ...", //PAF_SOURCE_DXP
154 "AS%d: WMA processing ...", //PAF_SOURCE_WMA
155 };
157 #else
158 #undef TRACE_VERBOSE0
159 #undef TRACE_VERBOSE1
160 #undef TRACE_VERBOSE2
161 #undef TRACE_VERBOSE3
162 #undef TRACE_VERBOSE4
163 #define TRACE_VERBOSE0(a)
164 #define TRACE_VERBOSE1(a,b)
165 #define TRACE_VERBOSE2(a,b,c)
166 #define TRACE_VERBOSE3(a,b,c,d)
167 #define TRACE_VERBOSE4(a,b,c,d,e)
168 #endif
170 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
171 #define TRACE_DATA(a) LOG_printf a
172 #else
173 #define TRACE_DATA(a)
174 #endif
176 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
177 #define TRACE_TIME(a) LOG_printf a
178 #define TIME_MOD trace // this could be different
179 static Int dtime()
180 {
181 static Int old_time = 0;
182 Int time = TSK_time();
183 Int delta_time = time - old_time;
184 old_time = time;
185 return( delta_time);
186 }
188 static char *stateName[11] =
189 {
190 "INIT",
191 "INFO1",
192 "AGAIN",
193 "INFO2",
194 "CONT",
195 "TIME",
196 "DECODE",
197 "STREAM",
198 "ENCODE",
199 "FINAL",
200 "QUIT"
201 };
203 #else
204 #define TRACE_TIME(a)
205 #endif
207 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
208 #undef TRACE_MSG0
209 #undef TRACE_MSG1
210 #undef TRACE_MSG2
211 #undef TRACE_MSG3
212 #undef TRACE_MSG4
213 #define TRACE_MSG0(a)
214 #define TRACE_MSG1(a,b)
215 #define TRACE_MSG2(a,b,c)
216 #define TRACE_MSG3(a,b,c,d)
217 #define TRACE_MSG4(a,b,c,d,e)
218 #endif
221 // .............................................................................
223 #include <pafsio.h>
224 #include "paferr.h"
226 #include <acp_mds.h>
228 #include <pcm.h>
230 #include <pce.h>
232 #include <doberr.h>
234 #include <diberr.h>
236 #include <stdasp.h>
238 #include "as0.h"
239 #include "asperr.h"
241 #include "audioStreamProc_params.h"
242 #include "audioStreamProc_patchs.h"
243 #include "audioStreamProc_config.h"
244 #include "audioStreamInpProc.h"
247 //#define PROFILER
249 #ifdef PROFILER
250 extern UInt32 start_profiling;
251 #endif
253 //
254 // Audio Stream Definitions
255 //
257 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
258 #define MINFRAMELENGTH 24
259 #define PA_MODULO 8 // also defined independently in ARC2 code, and may be hard coded other places.
262 //
263 // Decoder Definitions
264 //
265 //#define decLinkInit pQ->i_decLinkInit
267 //
268 // Audio Stream Processing Definitions
269 //
270 //#define aspLinkInit pQ->i_aspLinkInit
272 //
273 // Encoder Definitions
274 //
275 #define encLinkInit pQ->i_encLinkInit
277 //
278 // Input, Output Definitions
279 //
280 #define inpLinkInit pP->i_inpLinkInit
281 //#define outLinkInit pP->i_outLinkInit
283 /* ---------------------------------------------------------------- */
284 /* Parameter macro definitions end here. */
285 /* ---------------------------------------------------------------- */
287 //
288 // Standardized Definitions
289 //
291 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
292 //#define ENC_Handle PCE_Handle /* works for all: PCE */
294 #define __TASK_NAME__ "TaskAsip"
296 LINNO_DEFN(TaskAsip); /* Line number macros */
297 ERRNO_DEFN(TaskAsip); /* Error number macros */
299 // ASIT configuration
300 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
301 PAF_ASIT_Config gPAF_ASIT_config = {
302 NULL, // acp
303 &gPAF_ASPM_config, // pAspmCfg, shared ASIT/ASOT configuration
304 &gPAF_AST_config // pAstCfg, shared ASIT/ASOT/ASDT configuration
305 };
307 // Global debug counters */
308 UInt32 gTaskAsipCnt =0;
309 UInt32 gAsipInitCnt =0;
310 UInt32 gAsipInfo1Cnt =0;
311 UInt32 gAsipInfo2Cnt =0;
312 UInt32 gAsipDecodeCnt =0;
313 UInt32 gAsipDecodeErrCnt =0;
314 UInt32 gAsipFinalCnt =0;
315 UInt32 gAsipQuitCnt =0;
316 UInt32 gAsipInfo1_PrimaryErrCnt =0;
317 UInt32 gAsipInfo1_ErrCnt =0;
318 UInt32 gAsipInfo2_PrimaryErrCnt =0;
319 UInt32 gAsipInfo2_ErrCnt =0;
320 UInt32 gCapIbReset_cnt =0;
321 UInt32 gCapIb_cnt =0;
322 // debug
323 UInt32 gCbWrtAfErrCnt =0; // decoder output circular buffer write error count (returned from ARM to DSP)
326 #include "dbgDib.h" // debug
328 extern struct {
329 Int size;
330 IALG_Status *pStatus[512];
331 } IACP_STD_BETA_TABLE;
333 // FL: debug
334 #include "evmc66x_gpio_dbg.h"
336 /*
337 * ======== taskAsipFxn ========
338 * Audio Stream Input Processing task function
339 */
340 Void taskAsipFxn(
341 // Int betaPrimeValue, // FL: revisit
342 const PAF_ASIT_Params *pP,
343 const PAF_ASIT_Patchs *pQ
344 )
345 {
346 PAF_ASIT_Config *pC; /* Local configuration pointer */
347 PAF_AST_Config *pAstCfg; /* Common (shared) configuration pointer */
348 Int as; /* Audio Stream Number (1, 2, etc.) */
349 Int z; /* input/encode/stream/decode/output counter */
350 Int i; /* phase */
351 Int errno; /* error number */
352 Int zMD, zMI, zMS, zX;
353 Int loopCount = 0; // used to stop trace to see startup behavior.
354 UInt32 curTime;
355 Int size;
356 // Messaging
357 ASP_Msg *pAspMsg;
358 Int status;
359 #ifdef NON_CACHE_STATUS
360 Int8 tempVar8;
361 #endif
362 Task_Handle taskHandle;
364 Log_info0("Enter taskAsipFxn()");
366 #ifdef SIMULATE_SIO
367 /* Start simulation */
368 simStart();
369 #endif // SIMULATE_SIO
371 //
372 // Audio Framework Parameters & Patch (*pP, *pQ)
373 //
374 if (!pP)
375 {
376 TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
377 LINNO_RPRT(TaskAsip, -1);
378 return;
379 }
381 if (!pQ)
382 {
383 TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
384 LINNO_RPRT(TaskAsip, -1);
385 return;
386 }
388 //
389 // Audio Framework Configuration (*pC):
390 //
391 pC = &gPAF_ASIT_config;
392 pAstCfg = pC->pAstCfg;
394 /* Set Audio Stream Number (1, 2, etc.) */
395 as = gBetaPrimeValue + 1;
396 pAstCfg->as = as;
397 TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
399 taskHandle = Task_self();
401 //
402 // Initialize message log trace and line number reporting
403 //
404 for (z=STREAM1; z < STREAMN; z++)
405 {
406 TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
407 }
408 LINNO_RPRT(TaskAsip, -1);
410 //
411 // Determine decoder and stream indices associated with the master input
412 //
413 zMI = pP->zone.master;
414 pAstCfg->masterDec = zMI;
415 pAstCfg->masterStr = zMI;
416 for (zX = DECODE1; zX < DECODEN; zX++)
417 {
418 if (pP->inputsFromDecodes[zX] == zMI)
419 {
420 pAstCfg->masterDec = zX;
421 pAstCfg->masterStr = pP->streamsFromDecodes[zX];
422 break;
423 }
424 }
425 zMD = pAstCfg->masterDec;
426 zMS = pAstCfg->masterStr;
428 // Initialize as per parametrized phases:
429 //
430 // In standard form these are:
431 // - Malloc: Memory Allocation
432 // - Config: Configuration Initialization
433 // - AcpAlg: ACP Algorithm Initialization and Local Attachment
434 // - Common: Common Memory Initialization
435 // - AlgKey: Dec/Enc chain to Array Initialization
436 // - Device: I/O Device Initialization
437 // - DecOpCircBuf: Decoder Output Circular Buffer
438 // - Unused: (available)
439 //
440 LINNO_RPRT(TaskAsip, -2);
441 for (i=0; i < lengthof(pP->fxns->initPhase); i++)
442 {
443 Int linno;
444 if (pP->fxns->initPhase[i])
445 {
446 if (linno = pP->fxns->initPhase[i](pP, pQ, pC))
447 {
448 LINNO_RPRT(TaskAsip, linno);
449 return;
450 }
451 }
452 else
453 {
454 TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
455 }
456 TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
457 LINNO_RPRT(TaskAsip, -i-3);
458 }
460 //
461 // End of Initialization -- display memory usage report.
462 //
463 if (pP->fxns->memStatusPrint)
464 {
465 pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
466 }
468 // (***) FL: revisit
469 // write back AST shared configuration
470 Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
471 // FL: no need to share this pointer, can be local
472 //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
473 Cache_wait();
475 // (***) FL: revisit
476 // write back Dec configuration
477 Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
478 Cache_wait();
480 // (***) FL: revisit
481 // write back entire beta table
482 Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
483 Cache_wait();
485 // FL: send start initialization message to slave
486 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
487 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
488 pAspMsg->cmd = ASP_SLAVE_START; /* fill in message payload */
489 pAspMsg->procId = hAspMsgMaster->masterProcId;
490 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
491 pAspMsg->expectResp = TRUE;
492 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
493 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
494 if (status != MessageQ_S_SUCCESS)
495 {
496 SW_BREAKPOINT;
497 }
498 // wait for initialization complete message from slave
499 do {
500 //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
501 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
502 } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
503 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
504 (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
505 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
506 {
507 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
508 SW_BREAKPOINT;
509 }
510 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
511 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
512 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
513 if (status != MessageQ_S_SUCCESS)
514 {
515 SW_BREAKPOINT;
516 }
518 // (***) FL: revisit
519 // invalidate Status structure addresses for Beta Units initialized on Slave
520 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
521 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
522 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
523 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
524 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
525 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
526 Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
527 Cache_wait();
528 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
529 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
530 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
531 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
532 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
533 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
534 if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
536 // (***) FL: revisit
537 // invalidate Status structures for Beta Units initialized on Slave
538 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
539 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
540 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
541 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
542 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
543 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
544 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
545 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
546 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
547 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
548 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
549 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
550 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
551 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
552 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
553 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
554 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
555 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
556 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
557 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
558 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
559 Cache_wait();
561 #ifdef NON_CACHE_STATUS
562 // Get the shared status structure GateMP handles. Initialized at slave.
563 if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
564 {
565 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
566 }
567 if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
568 {
569 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
570 }
571 if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
572 {
573 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
574 }
575 if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
576 {
577 Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
578 }
579 #endif
581 // (***) FL: revisit
582 // invalidate Dec configuration
583 Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
584 Cache_wait();
586 //
587 // Main processing loop
588 //
589 for (z=STREAM1; z < STREAMN; z++)
590 {
591 TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
592 }
594 TRACE_TERSE0("TaskAsip: Entering Main Loop.");
596 errno = 0;
597 for (;;)
598 {
599 Int sourceSelect;
600 XDAS_Int8 sourceProgram;
602 loopCount++;
604 #if 0 // enable and tune to see startup behavior.
605 // this is an alternative to fixed/circular setting in pa.cfg.
606 // If you are searching for a memory allocation failure, disable on first round.
607 // All allocation has already happened.
608 // This is the outer loop. This loop count goes up when the stream resets.
609 // If the stream is running without problems, this does not increment.
610 // If the stream is repeatedly resetting, this loop count will go up rapidly.
611 if (loopCount > 10) // see traces for a few of the passes through the main loop.
612 {
613 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
614 LOG_disable(&TR_MOD); // stop tracing
615 }
616 #endif
618 TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
619 TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
621 // since not decoding indicate such
622 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
624 // any error forces idling of input
625 if (errno)
626 {
627 for (z=INPUT1; z < INPUTN; z++)
628 {
629 if (pAstCfg->xInp[z].hRxSio)
630 {
631 SIO_idle(pAstCfg->xInp[z].hRxSio);
632 }
633 }
635 TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
636 ERRNO_RPRT(TaskAsip, errno);
637 }
639 // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
640 // up to allow lower priority tasks to run. This may seem odd to be at the top
641 // of the state machine but provides for a cleaner flow even though the very
642 // first time we enter we do a sleep which is non-intuitive.
643 TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
644 TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
645 Task_sleep(1);
647 TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
648 if (errno = pP->fxns->selectDevices(pP, pQ, pC))
649 {
650 TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
651 continue;
652 }
654 // if no master input selected then we don't know what may be at the input
655 // so set to unknown and skip any remaining processing
656 if (!pAstCfg->xInp[zMI].hRxSio)
657 {
658 #ifdef NON_CACHE_STATUS
659 tempVar8 = PAF_SOURCE_UNKNOWN;
660 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
661 &tempVar8,
662 sizeof(tempVar8),
663 GATEMP_INDEX_DEC);
664 #else
665 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
666 #endif
667 TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
668 continue;
669 }
671 // if here then we have a valid input so query its status
672 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
673 {
674 TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
675 continue;
676 }
678 #ifdef NON_CACHE_STATUS
679 statusOp_read(&tempVar8,
680 &(pAstCfg->xDec[zMD].decodeStatus.mode),
681 sizeof(tempVar8),
682 GATEMP_INDEX_DEC);
683 // If master decoder is not enabled, or the input is unlocked, then do nothing
684 if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
685 {
686 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
687 continue;
688 }
689 #else
690 // If master decoder is not enabled, or the input is unlocked, then do nothing
691 if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
692 {
693 TRACE_VERBOSE0("TaskAsip: Not locked, continue");
694 continue;
695 }
696 #endif
698 #ifdef NON_CACHE_STATUS
699 statusOp_read(&tempVar8,
700 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
701 sizeof(tempVar8),
702 GATEMP_INDEX_DEC);
703 // If no source selected then do nothing
704 if (tempVar8 == PAF_SOURCE_NONE)
705 {
706 tempVar8 = PAF_SOURCE_NONE;
707 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
708 &tempVar8,
709 sizeof(tempVar8),
710 GATEMP_INDEX_DEC);
711 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
712 continue;
713 }
714 #else
715 // If no source selected then do nothing
716 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
717 {
718 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
719 TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
720 continue;
721 }
722 #endif
724 #ifdef NON_CACHE_STATUS
725 statusOp_read(&tempVar8,
726 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
727 sizeof(tempVar8),
728 GATEMP_INDEX_DEC);
729 // If we want pass processing then proceed directly
730 if (tempVar8 == PAF_SOURCE_PASS)
731 {
732 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
734 tempVar8 = PAF_SOURCE_PASS;
735 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
736 &tempVar8,
737 sizeof(tempVar8),
738 GATEMP_INDEX_DEC);
739 #else
740 // If we want pass processing then proceed directly
741 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS)
742 {
743 TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
744 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
745 #endif
746 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
747 if (pP->fxns->passProcessing)
748 {
749 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);
750 }
751 else
752 {
753 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
754 errno = ASPERR_PASS;
755 }
756 TRACE_VERBOSE0("TaskAsip: continue");
757 continue;
758 }
760 #ifdef NON_CACHE_STATUS
761 statusOp_read(&tempVar8,
762 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
763 sizeof(tempVar8),
764 GATEMP_INDEX_DEC);
765 // .....................................................................
766 // At this point we have an enabled input and want to decode something.
767 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
768 // when no decoder is selected there are no calls to IB
769 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
770 if (errno = pP->fxns->autoProcessing(pP, pQ, pC, tempVar8, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
771 {
772 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
773 continue;
774 }
775 #else
776 // .....................................................................
777 // At this point we have an enabled input and want to decode something.
778 // If no decoder selected then do nothing. Need to reset the sourceProgram, since
779 // when no decoder is selected there are no calls to IB
780 //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
781 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
782 {
783 TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
784 continue;
785 }
786 #endif
788 // query for input type
789 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
790 {
791 TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
792 errno = ASPERR_AUTO_PROGRAM;
793 continue;
794 }
795 #ifdef NON_CACHE_STATUS
796 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
797 &(sourceProgram),
798 sizeof(sourceProgram),
799 GATEMP_INDEX_DEC);
800 #else
801 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
802 #endif
804 // if input is unclassifiable then do nothing
805 if (sourceProgram == PAF_SOURCE_UNKNOWN)
806 {
807 TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
808 continue;
809 }
811 // now that we have some input classification, and possibly an outstanding
812 // input frame, we determine whether or not to call decodeProcessing and with
813 // what decAlg.
814 sourceSelect = PAF_SOURCE_NONE;
815 #ifdef NON_CACHE_STATUS
816 statusOp_read(&tempVar8,
817 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
818 sizeof(tempVar8),
819 GATEMP_INDEX_DEC);
820 switch (tempVar8)
821 {
822 #else
823 switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect)
824 {
825 #endif
826 // If autodetecting, decoding everything, and input is something
827 // (i.e. bitstream or PCM) then decode.
828 case PAF_SOURCE_AUTO:
829 if (sourceProgram >= PAF_SOURCE_PCM)
830 {
831 sourceSelect = sourceProgram;
832 }
833 break;
835 // If autodetecting, decoding only PCM, and input is PCM then decode.
836 case PAF_SOURCE_PCMAUTO:
837 if (sourceProgram == PAF_SOURCE_PCM)
838 {
839 sourceSelect = sourceProgram;
840 }
841 break;
843 // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
844 case PAF_SOURCE_BITSTREAM:
845 if (sourceProgram >= PAF_SOURCE_AC3)
846 {
847 sourceSelect = sourceProgram;
848 }
849 break;
851 // If autodetecting, decoding only DTS, and input is DTS then decode.
852 case PAF_SOURCE_DTSALL:
853 switch (sourceProgram)
854 {
855 case PAF_SOURCE_DTS11:
856 case PAF_SOURCE_DTS12:
857 case PAF_SOURCE_DTS13:
858 case PAF_SOURCE_DTS14:
859 case PAF_SOURCE_DTS16:
860 case PAF_SOURCE_DTSHD:
861 sourceSelect = sourceProgram;
862 break;
863 }
864 break;
866 // All others, e.g., force modes, fall through to here.
867 // If user made specific selection then program must match select.
868 // (NB: this compare relies on ordering of PAF_SOURCE)
869 default:
870 #ifdef NON_CACHE_STATUS
871 sourceSelect = 0; // due to size difference
872 statusOp_read(&sourceSelect,
873 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
874 sizeof(Int8),
875 GATEMP_INDEX_DEC);
876 #else
877 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
878 #endif
879 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
880 {
881 if (sourceProgram != sourceSelect)
882 {
883 sourceSelect = PAF_SOURCE_NONE;
884 }
885 }
886 break;
887 }
889 // if we didn't find any matches then skip
890 if (sourceSelect == PAF_SOURCE_NONE)
891 {
892 TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
893 continue;
894 }
896 // FL: debug, reset IB capture buffer
897 capIbReset();
898 gCapIbReset_cnt++;
899 Log_info0("capIbReset()");
901 // FL: send source select message to slave
902 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
903 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
904 pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT; /* fill in message payload */
905 pAspMsg->procId = hAspMsgMaster->masterProcId;
906 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
907 pAspMsg->expectResp = TRUE;
908 *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
909 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
910 TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
911 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
912 if (status != MessageQ_S_SUCCESS)
913 {
914 SW_BREAKPOINT;
915 }
916 // wait for source select complete message from slave
917 //do {
918 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
919 //} while (status != MessageQ_S_SUCCESS);
920 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
921 if (status != MessageQ_S_SUCCESS)
922 {
923 TRACE_TERSE0("MessageQ_get() failure.");
924 SW_BREAKPOINT; // temporary
925 }
926 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
927 (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
928 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
929 {
930 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
931 SW_BREAKPOINT;
932 }
933 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
934 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
935 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
936 if (status != MessageQ_S_SUCCESS)
937 {
938 SW_BREAKPOINT;
939 }
941 // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
942 // iff we are in this top level state machine and specifically not in decodeProcessing
943 pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
945 TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
947 // Reduce priority level since autodetection complete
948 Task_setPri(taskHandle, Task_getPri(taskHandle)-1);
950 TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
951 errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
952 if (errno)
953 {
954 TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
955 }
956 else
957 {
958 TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
959 }
961 // Increase priority level since decoding complete
962 Task_setPri(taskHandle, Task_getPri(taskHandle)+1);
964 // FL: send dec exit message to slave
965 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
966 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
967 pAspMsg->cmd = ASP_SLAVE_DEC_EXIT; /* fill in message payload */
968 pAspMsg->procId = hAspMsgMaster->masterProcId;
969 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
970 pAspMsg->expectResp = TRUE;
971 TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
972 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
973 if (status != MessageQ_S_SUCCESS)
974 {
975 SW_BREAKPOINT;
976 }
977 // wait for dec exit complete message from slave
978 //do {
979 // status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
980 //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
981 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
982 if (status != MessageQ_S_SUCCESS)
983 {
984 TRACE_TERSE0("MessageQ_get() failure.");
985 SW_BREAKPOINT; // temporary
986 }
987 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
988 (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
989 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
990 {
991 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
992 SW_BREAKPOINT;
993 }
994 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
995 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
996 // free the message
997 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
998 if (status != MessageQ_S_SUCCESS)
999 {
1000 SW_BREAKPOINT;
1001 }
1002 } // End of main processing loop for (;;)
1004 Log_info0("Exit taskAsipFxn()");
1005 }
1007 // -----------------------------------------------------------------------------
1008 // ASIT Initialization Function - Memory Allocation
1009 //
1010 // Name: PAF_ASIT_initPhaseMalloc
1011 // Purpose: Audio Stream Input Task Function for initialization of data pointers
1012 // by allocation of memory.
1013 // From: audioStream1Task or equivalent
1014 // Uses: See code.
1015 // States: x
1016 // Return: 0 on success.
1017 // Source code line number on MEM_calloc failure.
1018 // Trace: Message Log "trace" in Debug Project Configuration reports:
1019 // * State information as per parent.
1020 // * Memory allocation errors.
1021 //
1022 Int
1023 PAF_ASIT_initPhaseMalloc(
1024 const PAF_ASIT_Params *pP,
1025 const PAF_ASIT_Patchs *pQ,
1026 PAF_ASIT_Config *pC
1027 )
1028 {
1029 PAF_AST_Config *pAstCfg;
1030 Int as; /* Audio Stream Number (1, 2, etc.) */
1031 Int zMS;
1032 Error_Block eb;
1034 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1035 as = pAstCfg->as;
1036 zMS = pAstCfg->masterStr;
1038 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1040 // Initialize error block
1041 Error_init(&eb);
1043 /* Input memory */
1044 if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1045 INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
1046 {
1047 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1048 SW_BREAKPOINT;
1049 return __LINE__;
1050 }
1051 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
1052 INPUTN * sizeof (*pAstCfg->xInp),
1053 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
1055 #ifdef NON_CACHE_STATUS
1056 /* Decode memory */
1057 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM,
1058 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1059 {
1060 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1061 SW_BREAKPOINT;
1062 return __LINE__;
1063 }
1064 #else
1065 /* Decode memory */
1066 if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1067 DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1068 {
1069 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1070 SW_BREAKPOINT;
1071 return __LINE__;
1072 }
1073 #endif
1074 TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
1075 DECODEN * sizeof (*pAstCfg->xDec),
1076 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
1078 TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1079 return 0;
1080 } //PAF_ASIT_initPhaseMalloc
1082 // -----------------------------------------------------------------------------
1083 // ASIT Initialization Function - Memory Initialization from Configuration
1084 //
1085 // Name: PAF_ASIT_initPhaseConfig
1086 // Purpose: Audio Stream Task Function for initialization of data values
1087 // from parameters.
1088 // From: audioStream1Task or equivalent
1089 // Uses: See code.
1090 // States: x
1091 // Return: 0 on success.
1092 // Other as per initFrame0 and initFrame1.
1093 // Trace: Message Log "trace" in Debug Project Configuration reports:
1094 // * State information as per parent.
1095 //
1096 Int
1097 PAF_ASIT_initPhaseConfig(
1098 const PAF_ASIT_Params *pP,
1099 const PAF_ASIT_Patchs *pQ,
1100 PAF_ASIT_Config *pC
1101 )
1102 {
1103 PAF_AST_Config *pAstCfg;
1104 Int as; /* Audio Stream Number (1, 2, etc.) */
1105 Int z; /* input/encode/stream/decode/output counter */
1106 Int zMS;
1108 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1109 as = pAstCfg->as;
1110 zMS = pAstCfg->masterStr;
1112 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1114 //
1115 // Unspecified elements have been initialized to zero during alloc
1116 //
1118 for (z=INPUT1; z < INPUTN; z++)
1119 {
1120 pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
1121 pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
1122 }
1124 for (z=DECODE1; z < DECODEN; z++)
1125 {
1126 Int zI = pP->inputsFromDecodes[z];
1127 pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
1128 pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
1129 //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
1130 }
1132 TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1133 return 0;
1134 } //PAF_ASIT_initPhaseConfig
1136 // -----------------------------------------------------------------------------
1137 // ASIT Initialization Function - ACP Algorithm Instantiation
1138 //
1139 // Name: PAF_ASIT_initPhaseAcpAlg
1140 // Purpose: Audio Stream Input Task Function for initialization of ACP by
1141 // instantiation of the algorithm.
1142 // From: audioStream1Task or equivalent
1143 // Uses: See code.
1144 // States: x
1145 // Return: 0 on success.
1146 // Source code line number on ACP Algorithm creation failure.
1147 // Trace: Message Log "trace" in Debug Project Configuration reports:
1148 // * State information as per parent.
1149 // * Memory allocation errors.
1150 //
1151 Int
1152 PAF_ASIT_initPhaseAcpAlg(
1153 const PAF_ASIT_Params *pP,
1154 const PAF_ASIT_Patchs *pQ,
1155 PAF_ASIT_Config *pC
1156 )
1157 {
1158 PAF_AST_Config *pAstCfg;
1159 Int as; /* Audio Stream Number (1, 2, etc.) */
1160 Int z; /* input/encode/stream/decode/output counter */
1161 Int betaPrimeOffset;
1162 ACP_Handle acp;
1163 Int zMS;
1164 Int zS, zX;
1166 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1167 as = pAstCfg->as;
1168 zMS = pAstCfg->masterStr;
1170 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1172 ACP_MDS_init();
1174 if (!(acp = (ACP_Handle)ACP_MDS_create(NULL)))
1175 {
1176 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1177 return __LINE__;
1178 }
1179 pC->acp = acp;
1181 ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1182 ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1184 for (z=INPUT1; z < INPUTN; z++)
1185 {
1186 zS = z;
1187 for (zX = DECODE1; zX < DECODEN; zX++)
1188 {
1189 if (pP->inputsFromDecodes[zX] == z)
1190 {
1191 zS = pP->streamsFromDecodes[zX];
1192 break;
1193 }
1194 }
1195 acp->fxns->attach(acp, ACP_SERIES_STD,
1196 STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1197 (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1198 /* Ignore errors, not reported. */
1199 }
1201 TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1203 return 0;
1204 } //PAF_ASIT_initPhaseAcpAlg
1206 // -----------------------------------------------------------------------------
1207 // ASIT Initialization Function - Common Memory
1208 //
1209 // Name: PAF_ASIT_initPhaseCommon
1210 // Purpose: Audio Stream Input Task Function for allocation of common memory.
1211 // From: audioStream1Task or equivalent
1212 // Uses: See code.
1213 // States: x
1214 // Return: 0 on success.
1215 // Source code line number on PAF_ALG_alloc failure.
1216 // Source code line number on PAF_ALG_mallocMemory failure.
1217 // Source code line number on Decode Chain initialization failure.
1218 // Source code line number on ASP Chain initialization failure.
1219 // Source code line number on Encode Chain initialization failure.
1220 // Trace: Message Log "trace" in Debug Project Configuration reports:
1221 // * State information as per parent.
1222 // * Memory allocation errors.
1223 //
1224 Int
1225 PAF_ASIT_initPhaseCommon(
1226 const PAF_ASIT_Params *pP,
1227 const PAF_ASIT_Patchs *pQ,
1228 PAF_ASIT_Config *pC
1229 )
1230 {
1231 PAF_AST_Config *pAstCfg;
1232 Int as; /* Audio Stream Number (1, 2, etc.) */
1233 Int z; /* stream counter */
1234 ACP_Handle acp;
1235 PAF_IALG_Config pafAlgConfig;
1236 IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1238 acp = pC->acp;
1239 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1240 as = pAstCfg->as;
1242 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1244 //
1245 // Determine memory needs and instantiate algorithms across audio streams
1246 //
1247 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1248 PAF_ALG_setup(&pafAlgConfig,
1249 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1250 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1251 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1252 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1253 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1254 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1255 HEAP_CLEAR);
1257 if (pP->fxns->headerPrint)
1258 {
1259 pP->fxns->headerPrint();
1260 }
1262 for (z = STREAM1; z < STREAMN; z++)
1263 {
1264 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1266 //
1267 // Determine common memory for:
1268 // (1) Logical Input drivers
1269 //
1270 // Decode Algorithms common memory determined in ASP Slave.
1271 //
1272 PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1274 //
1275 // Determine common memory needs of Logical Input driver
1276 //
1278 // really need to loop over all inputs for this stream using the tables
1279 // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1280 // patch, and not needed for FS11, since there is only one input.
1281 if (INPUT1 <= z && z < INPUTN)
1282 {
1283 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1284 if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1285 {
1286 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1287 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1288 SW_BREAKPOINT;
1289 return __LINE__;
1290 }
1291 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1292 if (pP->fxns->allocPrint)
1293 {
1294 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1295 }
1296 }
1297 }
1298 {
1299 // Changes made to share scratch between zones
1300 // Assume maximum 3 zones and scratch common memory is at offset 0;
1301 int max=0;
1302 for (z=STREAM1; z<STREAMN; z++)
1303 {
1304 if (max < common[z][0].size)
1305 {
1306 max = common[z][0].size;
1307 }
1308 }
1309 common[STREAM1][0].size=max;
1310 for (z=STREAM1+1; z<STREAMN; z++)
1311 {
1312 common[z][0].size = 0;
1313 }
1314 }
1316 //
1317 // Allocate common memory for:
1318 // (1) Logical Input drivers
1319 //
1320 for (z = STREAM1; z < STREAMN; z++)
1321 {
1322 TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1323 if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig))
1324 {
1325 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1326 TRACE_TERSE3("AS%d: z: %d. Size 0x%x", as+z, z, common[z][0].size);
1327 SW_BREAKPOINT;
1328 return __LINE__;
1329 }
1330 TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1331 // share zone0 scratch with all zones
1332 common[z][0].base = common[0][0].base;
1333 if (pP->fxns->commonPrint)
1334 {
1335 pP->fxns->commonPrint(common[z], &pafAlgConfig);
1336 }
1338 //
1339 // Allocate non-common memories for Logical IO drivers
1340 // Since these structures are used at run-time we allocate from external memory
1341 if (INPUT1 <= z && z < INPUTN)
1342 {
1343 PAF_ASP_Chain *chain;
1344 TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1345 as+z, z);
1346 chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1347 HEAP_EXTERNAL, as+z, acp, &trace,
1348 inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1349 if (!chain)
1350 {
1351 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1352 return __LINE__;
1353 }
1354 }
1355 }
1356 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1358 return 0;
1359 } //PAF_ASIT_initPhaseCommon
1361 // (***) FL: candidate for removal
1362 // -----------------------------------------------------------------------------
1363 // ASIT Initialization Function - Algorithm Keys
1364 //
1365 // Name: PAF_ASIT_initPhaseAlgKey
1366 // Purpose: Audio Stream Input Task Function for initialization of data values
1367 // from parameters for Algorithm Keys.
1368 // From: audioStream1Task or equivalent
1369 // Uses: See code.
1370 // States: x
1371 // Return: 0.
1372 // Trace: Message Log "trace" in Debug Project Configuration reports:
1373 // * State information as per parent.
1374 //
1375 // .............................................................................
1376 Int
1377 PAF_ASIT_initPhaseAlgKey(
1378 const PAF_ASIT_Params *pP,
1379 const PAF_ASIT_Patchs *pQ,
1380 PAF_ASIT_Config *pC
1381 )
1382 {
1383 PAF_AST_Config *pAstCfg;
1384 Int as; /* Audio Stream Number (1, 2, etc.) */
1387 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1388 as = pAstCfg->as;
1389 (void)as; // clear compiler warning in case not used with tracing disabled
1391 TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1393 #if 0 // FL: slave
1394 for (z=DECODE1; z < DECODEN; z++)
1395 {
1396 for (s=0; s < pP->pDecAlgKey->length; s++)
1397 {
1398 if ((pP->pDecAlgKey->code[s].full != 0) &&
1399 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s])))
1400 {
1401 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1402 /* Cast in interface, for now --Kurt */
1403 }
1404 else
1405 {
1406 pC->xDec[z].decAlg[s] = NULL;
1407 }
1408 }
1409 }
1410 #endif
1412 return 0;
1413 } //PAF_ASIT_initPhaseAlgKey
1415 // -----------------------------------------------------------------------------
1416 // ASIT Initialization Function - I/O Devices
1417 //
1418 // Name: PAF_ASIT_initPhaseDevice
1419 // Purpose: Audio Stream Input Task Function for initialization of I/O Devices.
1420 // From: audioStream1Task or equivalent
1421 // Uses: See code.
1422 // States: x
1423 // Return: 0 on success.
1424 // Source code line number on device allocation failure.
1425 // Trace: Message Log "trace" in Debug Project Configuration reports:
1426 // * State information as per parent.
1427 // * Memory allocation errors.
1428 //
1429 Int
1430 PAF_ASIT_initPhaseDevice(
1431 const PAF_ASIT_Params *pP,
1432 const PAF_ASIT_Patchs *pQ,
1433 PAF_ASIT_Config *pC
1434 )
1435 {
1436 PAF_AST_Config *pAstCfg;
1437 Int as; /* Audio Stream Number (1, 2, etc.) */
1438 Int z; /* input/output counter */
1439 PAF_SIO_IALG_Obj *pObj;
1440 PAF_SIO_IALG_Config *pAlgConfig;
1441 PAF_IALG_Config pafAlgConfig;
1444 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1445 as = pAstCfg->as;
1446 (void)as; // clear compiler warning in case not used with tracing disabled
1448 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1450 if (pP->fxns->bufMemPrint)
1451 {
1452 PAF_ALG_setup (&pafAlgConfig,
1453 HEAP_ID_INTERNAL, HEAP_INTERNAL,
1454 HEAP_ID_INTERNAL1, HEAP_INTERNAL1,
1455 HEAP_ID_EXTERNAL, HEAP_EXTERNAL,
1456 HEAP_ID_INTERNAL1_SHM, HEAP_INTERNAL1_SHM,
1457 HEAP_ID_EXTERNAL_SHM, HEAP_EXTERNAL_SHM,
1458 HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1459 HEAP_CLEAR);
1460 TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1461 }
1463 for (z=INPUT1; z < INPUTN; z++)
1464 {
1465 PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1467 pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1468 pAlgConfig = &pObj->config;
1470 pAstCfg->xInp[z].hRxSio = NULL;
1472 pConfig->base.pVoid = pAlgConfig->pMemRec[0].base;
1473 pConfig->pntr.pVoid = pAlgConfig->pMemRec[0].base;
1474 pConfig->head.pVoid = pAlgConfig->pMemRec[0].base;
1475 pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1476 pConfig->allocation = pAlgConfig->pMemRec[0].size;
1477 pConfig->sizeofElement = 2;
1478 pConfig->precision = 16;
1480 if (pP->fxns->bufMemPrint)
1481 {
1482 pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1483 }
1484 }
1486 TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1488 return 0;
1489 } //PAF_ASIT_initPhaseDevice
1491 // -----------------------------------------------------------------------------
1492 // ASIT Initialization Function - Decoder Output Circular Buffer
1493 //
1494 // Name: PAF_ASIT_initPhaseDecOpCircBuf
1495 // Purpose: Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1496 // From: audioStream1Task or equivalent
1497 // Uses: See code.
1498 // States: x
1499 // Return: 0 on success.
1500 // Source code line number on device allocation failure.
1501 // Trace: Message Log "trace" in Debug Project Configuration reports:
1502 // * State information as per parent.
1503 // * Memory allocation errors.
1504 //
1505 Int
1506 PAF_ASIT_initPhaseDecOpCircBuf(
1507 const PAF_ASIT_Params *pP,
1508 const PAF_ASIT_Patchs *pQ,
1509 PAF_ASIT_Config *pC
1510 )
1511 {
1512 PAF_AST_Config *pAstCfg;
1513 PAF_AST_DecOpCircBuf *pCb; /* Decoder output circular buffer */
1514 Int as; /* Audio Stream Number (1, 2, etc.) */
1515 Int zMS;
1516 Int z; /* decode counter */
1517 Int errno; /* error number */
1518 Error_Block eb;
1519 Int i;
1521 // FL: (***)revisit
1522 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1523 as = pAstCfg->as;
1524 zMS = pAstCfg->masterStr;
1526 /* Decode output circular buffer memory */
1527 if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM,
1528 DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1529 {
1530 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1531 SW_BREAKPOINT;
1532 return __LINE__;
1533 }
1535 TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1536 DECODEN * sizeof (*pAstCfg->xDecOpCb),
1537 HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1539 for (z=DECODE1; z < DECODEN; z++)
1540 {
1541 pCb = &pAstCfg->xDecOpCb[z];
1543 // allocate audio frame circular buffer
1544 if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1545 {
1546 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1547 SW_BREAKPOINT;
1548 }
1549 // allocate audio frame PCM sample pointer array
1550 for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1551 {
1552 if (!(pCb->afCb[i].data.sample = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * sizeof(PAF_AudioData *), 4, &eb)))
1553 {
1554 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1555 SW_BREAKPOINT;
1556 }
1557 if (!(pCb->afCb[i].data.samsiz = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_PCM_CH_MAT * sizeof(PAF_AudioSize), 4, &eb)))
1558 {
1559 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1560 SW_BREAKPOINT;
1561 }
1562 }
1563 // allocate PCM sample buffer
1564 if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1565 {
1566 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1567 SW_BREAKPOINT;
1568 }
1569 pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1570 // allocate Metadata buffers //QIN
1571 if (!(pCb->metaBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD * sizeof(Int8), 4, &eb)))
1572 {
1573 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1574 SW_BREAKPOINT;
1575 }
1576 pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1577 // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length
1578 // Initialize decoder output circular buffer for PCM
1579 errno = cbInit(pCb);
1580 if (errno)
1581 {
1582 SW_BREAKPOINT; // FL: debug
1583 return errno;
1584 }
1585 }
1587 return 0;
1588 } //PAF_ASIT_initPhaseDecOpCircBuf
1591 #if 0
1592 // -----------------------------------------------------------------------------
1593 // AST Processing Function - Pass-Through Processing
1594 //
1595 // Name: PAF_AST_passProcessing
1596 // Purpose: Audio Stream Task Function for processing audio data as a
1597 // pass-through from the input driver to the output driver
1598 // for development and testing.
1599 // From: audioStream1Task or equivalent
1600 // Uses: See code.
1601 // States: x
1602 // Return: Error number in standard form (0 on success).
1603 // Trace: Message Log "trace" in Debug Project Configuration reports:
1604 // * State information on initialization.
1605 // * State information on processing.
1606 //
1608 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1609 /* Pass Processing is often omitted from builds to save memory, */
1610 /* and CODE_SECTION/clink constructs facilitate this omission. */
1612 Int
1613 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1614 {
1615 Int z; /* input/output counter */
1616 Int errno = 0; /* error number */
1617 Int getVal;
1618 Int rxNumChan, txNumChan;
1619 Int first;
1620 Int zMD = pC->masterDec;
1621 Int zMI = pP->zone.master;
1624 #ifndef __TI_EABI__
1625 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1626 #endif
1628 TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1630 //
1631 // Determine that receive/transmit channels are compatible
1632 //
1634 // Can handle handle only master input
1635 for (z=INPUT1; z < INPUTN; z++) {
1636 if (z != zMI && pC->xInp[z].hRxSio)
1637 return (ASPERR_PASS + 0x01);
1638 }
1640 /* Number of receive/transmit channels */
1642 if (! pC->xInp[zMI].hRxSio)
1643 return (ASPERR_PASS + 0x11);
1644 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1645 return (ASPERR_PASS + 0x12);
1646 if (rxNumChan > NUM_TX_CHAN(zMI))
1647 return (ASPERR_PASS + 0x13);
1649 for (z=OUTPUT1; z < OUTPUTN; z++) {
1650 if (! pC->xOut[zMI].hTxSio)
1651 return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1652 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1653 return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1654 if (txNumChan > NUM_TX_CHAN(zMI))
1655 return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1656 }
1658 //
1659 // Set up receive/transmit
1660 //
1662 SIO_idle (pC->xInp[zMI].hRxSio);
1663 for (z=OUTPUT1; z < OUTPUTN; z++) {
1664 if(SIO_idle (pC->xOut[z].hTxSio))
1665 return ASPERR_IDLE;
1666 }
1668 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1669 return (ASPERR_PASS + 0x14);
1671 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1672 return (ASPERR_PASS + 0x15);
1674 for (z=OUTPUT1; z < OUTPUTN; z++)
1675 pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1677 if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1678 return ASPERR_PASS + 0x16;
1680 if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1681 return ASPERR_PASS + 0x17;
1683 //
1684 // Receive and transmit the data in single-frame buffers
1685 //
1687 first = 1;
1688 while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1689 PAF_OutBufConfig *pOutBuf;
1690 PAF_InpBufConfig *pInpBuf;
1692 if (first) {
1693 first = 0;
1695 TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1697 for (z=OUTPUT1; z < OUTPUTN; z++) {
1698 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1699 if (getVal > 0) {
1700 errno = ASPERR_ISSUE;
1701 break;
1702 }
1703 else if (getVal < 0) {
1704 errno = -getVal;
1705 break;
1706 }
1708 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1709 return (getVal & 0xff) | ASPERR_MUTE;
1710 }
1711 if (errno)
1712 break;
1714 }
1716 getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1717 if (getVal > 0) {
1718 errno = ASPERR_ISSUE;
1719 break;
1720 }
1722 TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1724 getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1725 if (getVal < 0) {
1726 errno = -getVal;
1727 break;
1728 }
1730 for (z=OUTPUT1; z < OUTPUTN; z++) {
1731 getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1732 if (getVal < 0) {
1733 errno = -getVal;
1734 break;
1735 }
1736 }
1737 if( errno )
1738 break;
1740 TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1742 if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1743 break;
1745 for (z=OUTPUT1; z < OUTPUTN; z++) {
1746 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1747 if (getVal > 0) {
1748 errno = ASPERR_ISSUE;
1749 break;
1750 }
1751 else if (getVal < 0) {
1752 errno = -getVal;
1753 break;
1754 }
1755 }
1756 if( errno )
1757 break;
1758 }
1760 //
1761 // Close down receive/transmit
1762 //
1764 TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1766 for (z=OUTPUT1; z < OUTPUTN; z++) {
1767 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1768 if (! errno)
1769 errno = (getVal & 0xff) | ASPERR_MUTE;
1770 /* convert to sensical errno */
1771 }
1772 }
1774 SIO_idle (pC->xInp[zMI].hRxSio);
1775 for (z=OUTPUT1; z < OUTPUTN; z++)
1776 SIO_idle (pC->xOut[z].hTxSio);
1778 return errno;
1780 } //PAF_AST_passProcessing
1781 #endif // #if 0
1783 #if 0
1784 // -----------------------------------------------------------------------------
1785 // AST Processing Function Helper - Pass-Through Processing Patch Point
1786 //
1787 // Name: PAF_AST_passProcessingCopy
1788 // Purpose: Pass-Through Processing Function for copying audio data
1789 // from the input buffer to the output buffer.
1790 // From: AST Parameter Function -> passProcessing
1791 // Uses: See code.
1792 // States: x
1793 // Return: Error number in standard form (0 on success).
1794 // Trace: Message Log "trace" in Debug Project Configuration reports:
1795 // x
1796 //
1798 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1799 /* Pass Processing is often omitted from builds to save memory, */
1800 /* and CODE_SECTION/clink constructs facilitate this omission. */
1802 Int
1803 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1804 {
1805 Int z; /* output counter */
1806 Int errno; /* error number */
1807 Int i;
1808 Int rxNumChan, txNumChan;
1809 Int zMI = pP->zone.master;
1812 asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1814 // Copy data from input channels to output channels one of two ways:
1816 if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1817 return (ASPERR_PASS + 0x12);
1819 for (z=OUTPUT1; z < OUTPUTN; z++) {
1820 if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1821 return (ASPERR_PASS + 0x22);
1823 if( txNumChan <= rxNumChan ) {
1825 // Copy one to one, ignoring later rx channels as needed.
1827 for( i=0; i < txNumChan; i++ ) {
1828 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1829 if( errno )
1830 return errno;
1831 }
1832 }
1833 else {
1835 // Copy one to many, repeating earlier rx channels as needed.
1837 Int from, to;
1839 from = 0;
1840 to = 0;
1841 while( to < txNumChan ) {
1842 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1843 if( errno )
1844 return errno;
1846 from++;
1847 to++;
1848 if( from == rxNumChan )
1849 from = 0;
1850 }
1851 }
1852 }
1854 return 0;
1855 } //PAF_AST_passProcessingCopy
1856 #endif // #if 0
1858 // -----------------------------------------------------------------------------
1859 // ASIT Processing Function - Auto Processing
1860 //
1861 // Name: PAF_ASIT_autoProcessing
1862 // Purpose: Audio Stream Input Task Function for processing audio data to
1863 // determine the input type without output.
1864 // From: audioStream1Task or equivalent
1865 // Uses: See code.
1866 // States: x
1867 // Return: Error number in standard or SIO form (0 on success).
1868 // Trace: Message Log "trace" in Debug Project Configuration reports:
1869 // * State information on initialization.
1870 //
1872 #define DECSIOMAP(X) \
1873 pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1875 Int
1876 PAF_ASIT_autoProcessing(
1877 const PAF_ASIT_Params *pP,
1878 const PAF_ASIT_Patchs *pQ,
1879 PAF_ASIT_Config *pC,
1880 Int inputTypeSelect,
1881 ALG_Handle pcmAlgMaster
1882 )
1883 {
1884 PAF_AST_Config *pAstCfg;
1885 Int as; /* Audio Stream Number (1, 2, etc.) */
1886 Int errno = 0; /* error number */
1887 Int nbytes;
1888 Int frameLength;
1889 Int zMD;
1890 Int zMI;
1891 Int zMS;
1893 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1894 as = pAstCfg->as;
1895 zMD = pAstCfg->masterDec;
1896 zMS = pAstCfg->masterStr;
1897 zMI = pP->zone.master;
1899 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1901 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1902 PAF_SIO_CONTROL_SET_SOURCESELECT,
1903 DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1904 {
1905 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1906 return errno;
1907 }
1908 //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1909 // pC->xDec[zMD].decodeStatus.bufferRatio);
1910 frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1912 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1913 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1914 {
1915 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1916 errno, ASPERR_AUTO_LENGTH);
1917 return ASPERR_AUTO_LENGTH;
1918 }
1920 if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1921 &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1922 PAF_SIO_REQUEST_SYNC))
1923 {
1924 TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1925 errno, ASPERR_ISSUE);
1926 return ASPERR_ISSUE;
1927 }
1929 TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1931 // all of the sync scan work is done in this call. If the error returned
1932 // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1933 // error so we mask it off.
1934 nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1935 if (nbytes == -DIBERR_SYNC)
1936 {
1937 #if 0 // (***) FL: shows timing of autosync restart
1938 // (***) debug // B5
1939 {
1940 static Uint8 toggleState = 0;
1941 if (toggleState == 0)
1942 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
1943 else
1944 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
1945 toggleState = ~(toggleState);
1946 }
1947 #endif
1949 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1950 return nbytes;
1951 }
1952 if (nbytes != sizeof(PAF_InpBufConfig))
1953 {
1954 TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1955 nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1956 return ASPERR_RECLAIM;
1957 }
1958 if (errno)
1959 {
1960 TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1961 }
1962 return errno;
1963 } //PAF_ASIT_autoProcessing
1965 UInt32 gProbe1Err=0;
1966 UInt32 gProbe2Err=0;
1967 UInt32 gMajorAuMissed=0;
1969 // -----------------------------------------------------------------------------
1970 // ASIT Processing Function - Decode Processing
1971 //
1972 // Name: PAF_ASIT_decodeProcessing
1973 // Purpose: Audio Stream Input Task Function for processing audio data.
1974 // From: audioStream1Task or equivalent
1975 // Uses: See code.
1976 // States: x
1977 // Return: Error number in standard form (0 on success).
1978 // Trace: Message Log "trace" in Debug Project Configuration reports:
1979 // * State information on initialization (via children).
1980 // * State information on processing (via children).
1981 // * Decode warnings.
1982 //
1983 // When "writeDECModeContinuous" is used for zMI input/decode:
1984 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1985 // (a) if "writeDECCommandRestart" is used
1986 // (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1987 // (b) if "writeDECSourceSelectNone" is used
1988 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1989 // (c) if an error occurs in
1990 // INIT
1991 // CONT ("subsequent block state", which "Establish[es] secondary timing")
1992 // -> PAF_AST_decodeCont(): "Await slave inputs"
1993 // STREAM (errno |= PAF_COMPONENT_ASP)
1994 // ENCODE (errno |= PAF_COMPONENT_ENCODE)
1995 // [ the latter errors lead to "switch_break:"
1996 // -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1997 //
1998 // [ Notably, in FINAL ("frame-finalization state")
1999 // -> PAF_AST_decodeFinalTest() is *not* called,
2000 // and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
2001 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
2002 //
2003 // States in which error can't occur:
2004 // AGAIN ("subsequent initial state")
2005 //
2006 // States in which (some) errors must be handled:
2007 // INFO1 ("first frame state")
2008 // -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
2009 // -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
2010 // ?*? but what about ASPERR_RESYNC from same call ?*?
2011 // -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
2012 // -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
2013 // -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
2014 // - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
2015 // - enc->fxns->info()
2016 // - pP->fxns->setCheckRateX()
2017 // - pP->fxns->startOutput()
2018 // - "Start slave inputs if necessary"
2019 // INFO2 ("subsequent frame state")
2020 // -> PAF_AST_decodeInfo(): (see above)
2021 // -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
2022 // - pP->fxns->setCheckRateX()
2023 // TIME ("timing state")
2024 // -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
2025 // -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
2026 // -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
2027 // (*OK* don't try to recover from this*)
2028 // -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
2029 // -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
2030 // possibly in PAF_AST_decodeProcessing() itself **
2031 // DECODE ("decode state")
2032 // -> PAF_AST_decodeDecode(): pass on error from
2033 // - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
2034 // - dec->fxns->reset()
2035 // - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
2036 // -> *DONE* must catch error from (zMI) dec->fxns->decode()
2037 // -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
2038 Int
2039 PAF_ASIT_decodeProcessing(
2040 const PAF_ASIT_Params *pP,
2041 const PAF_ASIT_Patchs *pQ,
2042 PAF_ASIT_Config *pC,
2043 Int sourceSelect
2044 )
2045 {
2046 PAF_AST_Config *pAstCfg;
2047 //Int as = pC->as; /* Audio Stream Number (1, 2, etc.) */
2048 Int z; /* decode counter */
2049 Int errno; /* error number */
2050 Int getVal;
2051 enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
2052 ALG_Handle alg[DECODEN_MAX];
2053 Int zMD;
2054 Int zMS;
2055 Int size;
2056 //PAF_InpBufConfig *pIpBufConfig;
2057 Int frame; // decoder input frame count
2058 Int block; // (***) FL: formerly -- decoder output block count / input frame
2059 #ifdef NON_CACHE_STATUS
2060 Int8 tempVar8, temp2Var8;
2061 #endif
2063 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2064 zMD = pAstCfg->masterDec;
2065 zMS = pAstCfg->masterStr;
2067 for (z=DECODE1; z < DECODEN; z++)
2068 {
2069 alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];
2070 }
2071 alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
2073 //
2074 // Receive and process the data in single-frame buffers
2075 //
2077 state = INIT;
2078 errno = 0; /* error number */
2080 #ifdef NON_CACHE_STATUS
2081 statusOp_read(&tempVar8,
2082 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2083 sizeof(tempVar8),
2084 GATEMP_INDEX_DEC);
2085 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
2087 for (;;)
2088 {
2089 statusOp_read(&tempVar8,
2090 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2091 sizeof(tempVar8),
2092 GATEMP_INDEX_DEC);
2093 if (tempVar8 == PAF_SOURCE_NONE)
2094 {
2095 #else
2096 TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
2098 for (;;)
2099 {
2100 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
2101 {
2102 #endif
2103 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
2104 state = QUIT;
2105 }
2107 // Process commands (decode)
2108 if (getVal = pP->fxns->decodeCommand(pP, pQ, pC))
2109 {
2110 if (state != INIT) // no need to restart/abort if not yet started
2111 {
2112 if (getVal == ASPERR_QUIT)
2113 {
2114 state = QUIT;
2115 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
2116 }
2117 else if (getVal == ASPERR_ABORT)
2118 {
2119 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
2120 return getVal;
2121 }
2122 else
2123 {
2124 /* ignore */;
2125 }
2126 }
2127 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
2128 }
2130 TRACE_TIME((&TIME_MOD, "... + %d = %d ->", dtime(), TSK_time()));
2131 TRACE_TIME((&TIME_MOD, " state = %s", stateName[state]));
2133 // Process state (decode)
2134 switch (state)
2135 {
2136 case INIT: // initial state
2137 gAsipInitCnt++;
2138 Log_info0("TaskAsip: state=INIT");
2140 #if 0 // Not necessary since decoder status is in uncached memory
2141 // status for shared beta units can change (e.g. at-boot or alpha)
2143 // write back Status structures for shared Beta Units
2144 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2145 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2146 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2147 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2148 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2149 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2150 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
2151 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
2152 Cache_wait();
2153 #endif
2154 #if 0 // Not necessary since decoder status is in uncached memory
2155 ////size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2156 ////Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2157 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2158 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2159 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2160 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2161 //Cache_wait();
2162 #endif
2164 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
2165 {
2166 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x. break after decodeInit", errno);
2167 break;
2168 }
2170 //
2171 // Not necessary since decoder status is in uncached memory
2172 //
2174 #if 0 // Not necessary since decoder status is in uncached memory
2175 // invalidate Status structures for shared Beta Units
2176 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2177 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2178 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2179 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2180 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2181 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2182 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
2183 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
2184 Cache_wait();
2185 #endif
2187 frame = 0;
2188 block = 0;
2190 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2191 state = INFO1;
2192 continue;
2194 case INFO1: // first frame state
2195 gAsipInfo1Cnt++;
2196 Log_info0("TaskAsip: state=INFO1");
2198 #if 0
2199 //// (***) FL: revisit
2200 //// write back Inp configuration
2201 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2202 //// write back input data
2203 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2204 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2205 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2206 //// write back Dec configuration
2207 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2208 //Cache_wait();
2209 #endif
2211 // Establish primary timing
2212 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2213 {
2214 gAsipInfo1_PrimaryErrCnt++;
2215 TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2216 break;
2217 }
2219 #if 0
2220 //// (***) FL: revisit
2221 //// invalidate Dec configuration
2222 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2223 //Cache_wait();
2224 #endif
2227 #ifdef NON_CACHE_STATUS
2228 statusOp_read(&tempVar8,
2229 &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2230 sizeof(tempVar8),
2231 GATEMP_INDEX_DEC);
2232 statusOp_read(&temp2Var8,
2233 &(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
2234 sizeof(tempVar8),
2235 GATEMP_INDEX_DEC);
2236 // Don't start decode until major access unit is found.
2237 if (((tempVar8 == PAF_SOURCE_THD) ||
2238 (tempVar8 == PAF_SOURCE_DXP) ||
2239 (tempVar8 == PAF_SOURCE_DTSHD)) &&
2240 (temp2Var8 == PAF_SAMPLERATE_UNKNOWN))
2241 #else
2242 // Don't start decode until major access unit is found.
2243 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD) ||
2244 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP) ||
2245 (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2246 (pAstCfg->xDec[zMD].decodeStatus.sampleRate == PAF_SAMPLERATE_UNKNOWN))
2247 #endif
2248 {
2249 Int z;
2250 for (z=DECODE1; z < DECODEN; z++)
2251 {
2252 Int zI = pP->inputsFromDecodes[z];
2253 #ifdef NON_CACHE_STATUS
2254 statusOp_read(&tempVar8,
2255 &(pAstCfg->xDec[z].decodeStatus.mode),
2256 sizeof(tempVar8),
2257 GATEMP_INDEX_DEC);
2258 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2259 {
2260 #else
2261 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2262 {
2263 #endif
2264 TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2265 if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2266 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2267 {
2268 gProbe2Err++;
2269 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2270 return (ASPERR_ISSUE);
2271 }
2272 }
2273 }
2274 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2275 gMajorAuMissed++; // debug
2276 frame++;
2277 state = INFO1;
2278 continue;
2279 }
2280 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2282 // Establish secondary timing
2283 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2284 {
2285 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x. break after decodeInfo1", errno);
2286 gAsipInfo1_ErrCnt++;
2287 break;
2288 }
2290 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2291 state = DECODE;
2292 continue;
2294 case INFO2: // subsequent frame state
2295 gAsipInfo2Cnt++;
2296 Log_info0("TaskAsip: state=INFO2");
2298 #if 0
2299 //// (***) FL: revisit
2300 //// write back Inp configuration
2301 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2302 //// write back input data
2303 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2304 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2305 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2306 //// write back Dec configuration
2307 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2308 //Cache_wait();
2309 #endif
2311 // Establish primary timing
2312 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2313 {
2314 TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2315 gAsipInfo2_PrimaryErrCnt++;
2316 break;
2317 }
2319 #if 0
2320 //// (***) FL: revisit
2321 //// invalidate Dec configuration
2322 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2323 //Cache_wait();
2324 #endif
2326 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2327 {
2328 TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2329 gAsipInfo2_ErrCnt++;
2330 break;
2331 }
2333 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2334 state = DECODE;
2335 continue;
2337 case DECODE: // decode state
2338 gAsipDecodeCnt++;
2339 Log_info0("TaskAsip: state=DECODE");
2341 #if 0
2342 //// (***) FL: revisit
2343 //// write back Dec configuration
2344 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2345 //Cache_wait();
2346 #endif
2348 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2349 {
2350 gAsipDecodeErrCnt++;
2351 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE. decodeDecode err 0x%04x", errno);
2352 break;
2353 }
2355 #if 0
2356 //// (***) FL: revisit
2357 //// invalidate Dec configuration
2358 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2359 //Cache_wait();
2360 #endif
2362 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2363 state = FINAL;
2364 continue;
2366 case FINAL: // frame-finalization state
2367 gAsipFinalCnt++;
2368 Log_info0("TaskAsip: state=FINAL");
2370 // Check for final frame, and if indicated:
2371 // - Exit state machine to "complete" processing.
2372 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block))
2373 {
2374 break;
2375 }
2377 frame++;
2378 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2379 state = INFO2;
2380 continue;
2382 case QUIT: // exit state
2383 gAsipQuitCnt++;
2384 Log_info0("TaskAsip: state=QUIT");
2386 // Quit:
2387 // - Set error number registers.
2388 // - Exit state machine to "decode complete" processing.
2389 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2390 errno = ASPERR_QUIT;
2391 break;
2393 default: // unknown state
2395 // Unknown:
2396 // - Set error number registers.
2397 // - Exit state machine to "decode complete" processing.
2399 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2400 errno = ASPERR_UNKNOWNSTATE;
2401 break;
2403 } // End of switch (state).
2405 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2406 if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2407 {
2408 /* ignored? */;
2409 }
2411 TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2413 return errno;
2414 } // End of for (;;) to Receive, process, and transmit the data.
2415 } //PAF_ASIT_decodeProcessing
2417 // -----------------------------------------------------------------------------
2418 // ASIT Decoding Function - Decode Command Processing
2419 //
2420 // Name: PAF_ASIT_decodeCommand
2421 // Purpose: Decoding Function for processing Decode Commands.
2422 // From: AST Parameter Function -> decodeProcessing
2423 // Uses: See code.
2424 // States: x
2425 // Return: Error number in standard form (0 on success).
2426 // Trace: Message Log "trace" in Debug Project Configuration reports:
2427 // * Command execution.
2428 //
2430 Int
2431 PAF_ASIT_decodeCommand(
2432 const PAF_ASIT_Params *pP,
2433 const PAF_ASIT_Patchs *pQ,
2434 PAF_ASIT_Config *pC
2435 )
2436 {
2437 PAF_AST_Config *pAstCfg;
2438 Int as; /* Audio Stream Number (1, 2, etc.) */
2439 Int z; /* decode counter */
2440 Int zS;
2441 #ifdef NON_CACHE_STATUS
2442 Int8 tempVar8;
2443 #endif
2445 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2446 as = pAstCfg->as;
2448 for (z=DECODE1; z < DECODEN; z++)
2449 {
2450 zS = pP->streamsFromDecodes[z];
2451 #ifdef NON_CACHE_STATUS
2452 statusOp_read(&tempVar8,
2453 &(pAstCfg->xDec[z].decodeStatus.command2),
2454 sizeof(tempVar8),
2455 GATEMP_INDEX_DEC);
2456 if (!(tempVar8 & 0x80))
2457 {
2458 switch (tempVar8)
2459 {
2460 case 0: // command none - process
2461 tempVar8 |= 0x80;
2462 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2463 &tempVar8,
2464 sizeof(tempVar8),
2465 GATEMP_INDEX_DEC);
2466 break;
2467 case 1: // command abort - leave now
2468 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2469 tempVar8 |= 0x80;
2470 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2471 &tempVar8,
2472 sizeof(tempVar8),
2473 GATEMP_INDEX_DEC);
2474 return (ASPERR_ABORT);
2475 case 2: // command restart - leave later
2476 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2477 tempVar8 |= 0x80;
2478 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2479 &tempVar8,
2480 sizeof(tempVar8),
2481 GATEMP_INDEX_DEC);
2482 return (ASPERR_QUIT);
2483 default: // command unknown - ignore
2484 break;
2485 }
2486 }
2487 #else
2488 if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2489 {
2490 switch (pAstCfg->xDec[z].decodeStatus.command2)
2491 {
2492 case 0: // command none - process
2493 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2494 break;
2495 case 1: // command abort - leave now
2496 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2497 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2498 return (ASPERR_ABORT);
2499 case 2: // command restart - leave later
2500 TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2501 pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2502 return (ASPERR_QUIT);
2503 default: // command unknown - ignore
2504 break;
2505 }
2506 }
2507 #endif
2508 }
2510 return 0;
2511 } //PAF_ASIT_decodeCommand
2513 // -----------------------------------------------------------------------------
2514 // ASIT Decoding Function - Reinitialization of Decode
2515 //
2516 // Name: PAF_ASIT_decodeInit
2517 // Purpose: Decoding Function for reinitializing the decoding process.
2518 // From: AST Parameter Function -> decodeProcessing
2519 // Uses: See code.
2520 // States: x
2521 // Return: Error number in standard or SIO form (0 on success).
2522 // Trace: Message Log "trace" in Debug Project Configuration reports:
2523 // * State information as per parent.
2524 //
2525 Int
2526 PAF_ASIT_decodeInit(
2527 const PAF_ASIT_Params *pP,
2528 const PAF_ASIT_Patchs *pQ,
2529 PAF_ASIT_Config *pC,
2530 Int sourceSelect
2531 )
2532 {
2533 PAF_AST_Config *pAstCfg;
2534 PAF_AST_DecOpCircBufCtl *pCbCtl; /* Decoder output circular buffer control */
2535 Int as; /* Audio Stream Number (1, 2, etc.) */
2536 Int z; /* decode/encode counter */
2537 Int errno; /* error number */
2538 Int zI, zS;
2539 Int zMD;
2540 Int zMI;
2541 ASP_Msg* pAspMsg; /* Messaging */
2542 Int argIdx;
2543 Int status;
2544 #ifdef NON_CACHE_STATUS
2545 Int8 tempVar8;
2546 #endif
2548 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2549 as = pAstCfg->as;
2550 zMD = pAstCfg->masterDec;
2551 zMI = pP->zone.master;
2552 (void)as; // clear compiler warning in case not used with tracing disabled
2554 pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2556 #ifdef NON_CACHE_STATUS
2557 // reset frameCount
2558 for (z=DECODE1; z < DECODEN; z++)
2559 {
2560 statusOp_read(&tempVar8,
2561 &(pAstCfg->xDec[z].decodeStatus.mode),
2562 sizeof(tempVar8),
2563 GATEMP_INDEX_DEC);
2564 if (tempVar8)
2565 {
2566 tempVar8 = 0;
2567 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2568 &tempVar8,
2569 sizeof(tempVar8),
2570 GATEMP_INDEX_DEC);
2571 }
2572 }
2574 for (z=DECODE1; z < DECODEN; z++)
2575 {
2576 zI = pP->inputsFromDecodes[z];
2577 zS = pP->streamsFromDecodes[z];
2578 (void)zS; // clear compiler warning in case not used with tracing disabled
2579 statusOp_read(&tempVar8,
2580 &(pAstCfg->xDec[z].decodeStatus.mode),
2581 sizeof(tempVar8),
2582 GATEMP_INDEX_DEC);
2583 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2584 {
2585 #else
2586 // reset frameCount
2587 for (z=DECODE1; z < DECODEN; z++)
2588 {
2589 if (pAstCfg->xDec[z].decodeStatus.mode)
2590 {
2591 pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2592 }
2593 }
2595 for (z=DECODE1; z < DECODEN; z++)
2596 {
2597 zI = pP->inputsFromDecodes[z];
2598 zS = pP->streamsFromDecodes[z];
2599 (void)zS; // clear compiler warning in case not used with tracing disabled
2600 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2601 {
2602 #endif
2603 Uns gear;
2604 Int frameLength;
2605 TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2607 // write back Dec configuration
2608 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2609 Cache_wait();
2611 // FL: send dec activate message to slave
2612 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2613 if (pAspMsg == NULL)
2614 {
2615 TRACE_TERSE0("MessageQ_alloc() failure.");
2616 SW_BREAKPOINT; // temporary
2617 return -1; // temporary
2618 }
2619 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2620 pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE; /* fill in message payload */
2621 pAspMsg->procId = hAspMsgMaster->masterProcId;
2622 pAspMsg->expectResp = TRUE;
2623 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2624 argIdx = 0; // set decIdx (zone index)
2625 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2626 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2627 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2628 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2629 if (status != MessageQ_S_SUCCESS)
2630 {
2631 SW_BREAKPOINT;
2632 }
2633 // wait for dec activate complete message from slave
2634 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2635 if (status != MessageQ_S_SUCCESS)
2636 {
2637 TRACE_TERSE0("MessageQ_get() failure.");
2638 SW_BREAKPOINT; // temporary
2639 return -1; // temporary
2640 }
2641 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
2642 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2643 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2644 {
2645 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2646 SW_BREAKPOINT; // temporary
2647 return -1; // temporary
2648 }
2649 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2650 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2651 // free the message
2652 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2653 if (status != MessageQ_S_SUCCESS)
2654 {
2655 SW_BREAKPOINT;
2656 }
2658 #if 0 // FL: decoder activate call, slave
2659 if (decAlg[z]->fxns->algActivate)
2660 decAlg[z]->fxns->algActivate (decAlg[z]);
2661 #endif
2663 // FL: send dec reset message to slave
2664 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
2665 if (pAspMsg == NULL)
2666 {
2667 TRACE_TERSE0("MessageQ_alloc() failure.");
2668 SW_BREAKPOINT; // temporary
2669 return -1; // temporary
2670 }
2671 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
2672 pAspMsg->cmd = ASP_SLAVE_DEC_RESET; /* fill in message payload */
2673 pAspMsg->procId = hAspMsgMaster->masterProcId;
2674 pAspMsg->expectResp = TRUE;
2675 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2676 argIdx = 0; // set decIdx
2677 *(Int32 *)&pAspMsg->buf[argIdx] = z;
2678 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2679 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2680 // wait for dec reset complete message from slave
2681 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
2682 if (status != MessageQ_S_SUCCESS)
2683 {
2684 SW_BREAKPOINT;
2685 }
2686 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2687 if (status != MessageQ_S_SUCCESS)
2688 {
2689 TRACE_TERSE0("MessageQ_get() failure.");
2690 SW_BREAKPOINT; // temporary
2691 return -1; // temporary
2692 }
2693 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2694 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) &&
2695 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2696 {
2697 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2698 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2699 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2701 argIdx = 0; // get decErrno
2702 errno = *(Int32 *)&pAspMsg->buf[argIdx];
2703 }
2704 else
2705 {
2706 //
2707 // Invalid message received
2708 //
2709 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2710 SW_BREAKPOINT; // temporary
2711 return -1; // temporary
2712 }
2713 // free the message
2714 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2715 if (status != MessageQ_S_SUCCESS)
2716 {
2717 SW_BREAKPOINT;
2718 }
2720 // (***) FL: revisit
2721 // invalidate Dec configuration
2722 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2723 Cache_wait();
2725 #if 0 // FL: decoder reset call, slave
2726 if (dec->fxns->reset
2727 && (errno = dec->fxns->reset (dec, NULL,
2728 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2729 return errno;
2730 #endif
2731 if (errno != 0)
2732 {
2733 return errno;
2734 }
2736 #ifdef NON_CACHE_STATUS
2737 gear = 0; // due to size difference
2738 statusOp_read(&gear,
2739 &(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2740 sizeof(Int8),
2741 GATEMP_INDEX_DEC);
2742 tempVar8 = gear < GEARS ? gear : 0;
2743 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2744 &tempVar8,
2745 sizeof(tempVar8),
2746 GATEMP_INDEX_DEC);
2747 #else
2748 gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2749 pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2750 #endif
2752 #if 0 // FL: change handle to decIdx (zone index)
2753 frameLength = pP->fxns->computeFrameLength(decAlg[z],
2754 FRAMELENGTH,
2755 pC->xDec[z].decodeStatus.bufferRatio);
2756 #endif
2757 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2758 frameLength = pP->fxns->computeFrameLength(z,
2759 FRAMELENGTH,
2760 pC->xDec[z].decodeStatus.bufferRatio);
2761 #else
2762 if (sourceSelect == PAF_SOURCE_PCM)
2763 {
2764 frameLength = PAF_SYS_FRAMELENGTH;
2765 }
2766 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2767 {
2768 frameLength = 1536;
2769 }
2770 else if (sourceSelect == PAF_SOURCE_THD)
2771 {
2772 frameLength = 1536; //QIN FIX ME
2773 }
2774 else
2775 {
2776 frameLength = 256;
2777 }
2778 #endif
2780 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2781 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2782 pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2784 // (***) FL: revisit. Count samples for DDP.
2785 // Add framework frame length and running sample count to decoder control.
2786 //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2787 //pC->xDec[z].decodeControl.rdSampleCount = 0;
2789 // Initialize decoder output circular buffer for selected source
2790 errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2791 if (errno)
2792 {
2793 SW_BREAKPOINT; // FL: debug
2794 return errno;
2795 }
2796 // FL: debug
2797 cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2799 if (z != zMD)
2800 {
2801 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2802 {
2803 return errno;
2804 }
2805 }
2807 #ifdef NON_CACHE_STATUS
2808 statusOp_read(&tempVar8,
2809 &(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2810 sizeof(Int8),
2811 GATEMP_INDEX_DEC);
2812 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2813 DECSIOMAP(tempVar8)))
2814 {
2815 return errno;
2816 }
2817 #else
2818 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2819 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2820 {
2821 return errno;
2822 }
2823 #endif
2824 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH,
2825 frameLength))
2826 {
2827 return errno;
2828 }
2829 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus,
2830 &pAstCfg->xInp[zI].inpBufConfig))
2831 {
2832 return errno;
2833 }
2834 }
2835 }
2837 if (pAstCfg->xInp[zMI].hRxSio)
2838 {
2839 errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2840 sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2841 if (errno)
2842 {
2843 return errno;
2844 }
2845 }
2847 return 0;
2848 } //PAF_AST_decodeInit
2850 // -----------------------------------------------------------------------------
2851 // ASIT Decoding Function - Info Processing, Common
2852 //
2853 // Name: PAF_ASIT_decodeInfo
2854 // Purpose: Decoding Function for processing information in a manner that
2855 // is common for both initial and subsequent frames of input data.
2856 // From: AST Parameter Function -> decodeProcessing
2857 // Uses: See code.
2858 // States: x
2859 // Return: Error number in standard form (0 on success).
2860 // Trace: Message Log "trace" in Debug Project Configuration reports:
2861 // * State information as per parent.
2862 //
2863 Int
2864 PAF_ASIT_decodeInfo(
2865 const PAF_ASIT_Params *pP,
2866 const PAF_ASIT_Patchs *pQ,
2867 PAF_ASIT_Config *pC,
2868 Int frame,
2869 Int block
2870 )
2871 {
2872 PAF_AST_Config *pAstCfg;
2873 Int as; /* Audio Stream Number (1, 2, etc.) */
2874 Int z; /* input/decode/stream counter */
2875 Int errno; /* error number */
2876 Int sioErr; /* error number, SIO */
2877 Int zD, zI, zS, zX;
2878 Int zMD;
2879 Int zMI;
2880 Int zMS;
2881 UInt32 curTime;
2882 ASP_Msg *pAspMsg; /* Messaging */
2883 Int argIdx;
2884 Int status;
2885 #ifdef NON_CACHE_STATUS
2886 Int8 tempVar8;
2887 Int tempVar;
2888 #endif
2889 // FL: revisit
2890 //Int size;
2891 //PAF_InpBufConfig *pIpBufConfig;
2893 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2894 as = pAstCfg->as;
2895 zMD = pAstCfg->masterDec;
2896 zMS = pAstCfg->masterStr;
2897 zMI = pP->zone.master;
2898 (void)zMS; (void)as; // clear compiler warning in case not used with tracing disabled
2900 // Set decode control: sample rate, emphasis
2901 for (z=INPUT1; z < INPUTN; z++)
2902 {
2903 zD = z;
2904 for (zX = DECODE1; zX < DECODEN; zX++)
2905 {
2906 if (pP->inputsFromDecodes[zX] == z)
2907 {
2908 zD = zX;
2909 break;
2910 }
2911 }
2912 #ifdef PROFILER
2913 // modify for different sampling rate
2914 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus == PAF_SAMPLERATE_96000HZ)
2915 {
2916 start_profiling = 1;
2917 }
2918 else
2919 {
2920 start_profiling = 0;
2921 }
2922 #endif
2923 if (pAstCfg->xInp[z].hRxSio)
2924 {
2925 //determine associated decoder
2926 if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
2927 pAstCfg->xDec[zD].decodeControl.sampleRate)
2928 {
2929 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN)
2930 {
2931 pAstCfg->xDec[zD].decodeControl.sampleRate =
2932 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2933 }
2934 else
2935 {
2936 TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2937 TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2938 pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
2939 pAstCfg->xDec[zD].decodeControl.sampleRate);
2940 // return (ASPERR_INFO_RATECHANGE);
2941 }
2942 }
2943 #ifdef NON_CACHE_STATUS
2944 statusOp_read(&tempVar8,
2945 &(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
2946 sizeof(Int8),
2947 GATEMP_INDEX_DEC);
2948 pAstCfg->xDec[zD].decodeControl.emphasis =
2949 tempVar8 != PAF_SOURCE_PCM
2950 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2951 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2952 #else
2953 pAstCfg->xDec[zD].decodeControl.emphasis =
2954 pAstCfg->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2955 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2956 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2957 #endif
2958 }
2959 else
2960 {
2961 pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2962 pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2963 }
2964 }
2966 // Wait for info input
2967 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2968 if (pAstCfg->xInp[zMI].hRxSio)
2969 {
2970 TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2971 sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2972 if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2973 {
2974 TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM. sioErr: 0x%x", sioErr);
2975 return ASPERR_RECLAIM;
2976 }
2978 // FL: debug, capture input buffer
2979 capIb(pAstCfg->xInp[zMI].pInpBuf);
2980 gCapIb_cnt++;
2982 #if 0 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
2983 // (***) debug // B5
2984 {
2985 static Uint8 toggleState = 0;
2986 if (toggleState == 0)
2987 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
2988 else
2989 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
2990 toggleState = ~(toggleState);
2991 }
2992 #endif
2994 //
2995 // Simulate Rx SIO_reclaim() pend
2996 //
2997 //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER);
2998 gTaskAsipCnt++;
2999 curTime = Clock_getTicks();
3000 //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);
3001 //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
3002 //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
3003 } //pC->xInp[zMI].hRxSio
3005 // Decode info
3006 for (z=DECODE1; z < DECODEN; z++)
3007 {
3008 zI = pP->inputsFromDecodes[z];
3009 zS = pP->streamsFromDecodes[z];
3010 (void)zS; // clear compiler warning in case not used with tracing disabled
3011 #ifdef NON_CACHE_STATUS
3012 statusOp_read(&tempVar8,
3013 &(pAstCfg->xDec[z].decodeStatus.mode),
3014 sizeof(Int8),
3015 GATEMP_INDEX_DEC);
3016 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
3017 {
3018 #else
3019 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3020 {
3021 #endif
3022 TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
3024 if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
3025 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
3026 {
3027 TRACE_TERSE1("return error errno 0x%x.", errno);
3028 return errno;
3029 }
3031 #if 1
3032 // (***) FL: revisit
3033 // write back Inp configuration
3034 Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
3035 // write back input data // (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
3036 //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
3037 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
3038 //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
3039 // write back Dec configuration
3040 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3041 Cache_wait();
3042 #endif
3044 // FL: send info message to slave
3045 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3046 if (pAspMsg == NULL)
3047 {
3048 TRACE_TERSE0("MessageQ_alloc() failure.");
3049 SW_BREAKPOINT; // temporary
3050 return -1; // temporary
3051 }
3052 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3053 pAspMsg->cmd = ASP_SLAVE_DEC_INFO; /* fill in message payload */
3054 pAspMsg->procId = hAspMsgMaster->masterProcId;
3055 pAspMsg->expectResp = TRUE;
3056 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3057 argIdx = 0; // set decIdx
3058 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3059 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3060 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3061 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message to slave */
3062 if (status != MessageQ_S_SUCCESS)
3063 {
3064 SW_BREAKPOINT;
3065 }
3066 // wait for dec info complete message from slave -- temporary
3067 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3068 if (status != MessageQ_S_SUCCESS)
3069 {
3070 TRACE_TERSE0("MessageQ_get() failure.");
3071 SW_BREAKPOINT;
3072 return -1; // temporary
3073 }
3074 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
3075 (pAspMsg->cmd == ASP_MASTER_DEC_INFO_DONE) &&
3076 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3077 {
3078 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3079 TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3080 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
3082 argIdx = 0; // get decErrno
3083 errno = *(Int32 *)&pAspMsg->buf[argIdx];
3084 }
3085 else
3086 {
3087 //
3088 // Invalid message received
3089 //
3090 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3091 SW_BREAKPOINT; // temporary
3092 return -1; // temporary
3093 }
3094 // free the message
3095 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3096 if (status != MessageQ_S_SUCCESS)
3097 {
3098 SW_BREAKPOINT;
3099 }
3101 #if 1
3102 // (***) FL: revisit
3103 // invalidate Dec configuration
3104 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3105 Cache_wait();
3106 #endif
3108 #if 0 // FL: decoder info call, slave
3109 if (dec->fxns->info
3110 && (errno = dec->fxns->info (dec, NULL,
3111 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3112 #endif
3113 if (errno)
3114 {
3115 TRACE_TERSE1("return error errno 0x%x.", errno);
3116 return errno;
3117 }
3119 #ifdef NON_CACHE_STATUS
3120 statusOp_read(&tempVar,
3121 &(pAstCfg->xDec[z].decodeStatus.frameCount),
3122 sizeof(Int),
3123 GATEMP_INDEX_DEC);
3124 // increment decoded frame count
3125 tempVar += 1;
3126 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
3127 &tempVar,
3128 sizeof(Int),
3129 GATEMP_INDEX_DEC);
3130 #else
3131 // increment decoded frame count
3132 pAstCfg->xDec[z].decodeStatus.frameCount += 1;
3133 #endif
3134 }
3135 } // z=DECODE1 to DECODEN
3137 #ifdef NON_CACHE_STATUS
3138 statusOp_read(&tempVar8,
3139 &(pAstCfg->xDec[zMD].decodeStatus.mode),
3140 sizeof(Int8),
3141 GATEMP_INDEX_DEC);
3142 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
3143 if (tempVar8)
3144 {
3145 XDAS_Int8 sourceProgram;
3146 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
3147 (Arg)&sourceProgram))
3148 {
3149 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
3150 return ASPERR_AUTO_PROGRAM;
3151 }
3152 statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3153 &(sourceProgram),
3154 sizeof(Int8),
3155 GATEMP_INDEX_DEC);
3156 }
3158 // since now decoding update decode status for all enabled decoders
3159 for (z=DECODE1; z < DECODEN; z++)
3160 {
3161 statusOp_read(&tempVar8,
3162 &(pAstCfg->xDec[z].decodeStatus.mode),
3163 sizeof(Int8),
3164 GATEMP_INDEX_DEC);
3165 if (tempVar8)
3166 {
3167 statusOp_read(&tempVar8,
3168 &(pAstCfg->xDec[z].decodeStatus.sourceProgram),
3169 sizeof(Int8),
3170 GATEMP_INDEX_DEC);
3171 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3172 &tempVar8,
3173 sizeof(Int8),
3174 GATEMP_INDEX_DEC);
3175 statusOp_read(&tempVar8,
3176 &(pAstCfg->xDec[z].decodeStatus.sourceSelect),
3177 sizeof(Int8),
3178 GATEMP_INDEX_DEC);
3179 if (tempVar8 == PAF_SOURCE_SNG)
3180 {
3181 tempVar8 = PAF_SOURCE_SNG;
3182 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3183 &tempVar8,
3184 sizeof(Int8),
3185 GATEMP_INDEX_DEC);
3186 }
3187 }
3188 }
3189 #else
3190 // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
3191 if (pAstCfg->xDec[zMD].decodeStatus.mode)
3192 {
3193 XDAS_Int8 sourceProgram;
3194 if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
3195 (Arg)&sourceProgram))
3196 {
3197 TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
3198 return ASPERR_AUTO_PROGRAM;
3199 }
3200 pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
3201 }
3203 // since now decoding update decode status for all enabled decoders
3204 for (z=DECODE1; z < DECODEN; z++)
3205 {
3206 if (pAstCfg->xDec[z].decodeStatus.mode)
3207 {
3208 pAstCfg->xDec[z].decodeStatus.sourceDecode = pAstCfg->xDec[z].decodeStatus.sourceProgram;
3209 if (pAstCfg->xDec[z].decodeStatus.sourceSelect == PAF_SOURCE_SNG)
3210 {
3211 pAstCfg->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_SNG;
3212 }
3213 }
3214 }
3215 #endif
3217 #if 0 // FL: ASDT (slave)
3218 // TODO: move this to start of this function so that it doesn't affect IO timing
3219 // Initialize audio frame(s)
3220 // Re-initialize audio frame if there is an associated decode and
3221 // that decode doesn't have a valid input or is turned off
3222 for (z=STREAM1; z < STREAMN; z++)
3223 {
3224 Int reset = 0;
3225 for (zX = DECODE1; zX < DECODEN; zX++)
3226 {
3227 if (pP->streamsFromDecodes[zX] == z)
3228 {
3229 zI = pP->inputsFromDecodes[zX];
3230 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3231 {
3232 reset = 1;
3233 }
3234 }
3235 }
3236 if (reset)
3237 {
3238 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
3239 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3240 }
3241 else
3242 {
3243 TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
3244 }
3245 }
3246 #endif
3248 return 0;
3249 } //PAF_ASIT_decodeInfo
3251 // -----------------------------------------------------------------------------
3252 // ASIT Decoding Function - Info Processing, Initial
3253 //
3254 // Name: PAF_ASIT_decodeInfo1
3255 // Purpose: Decoding Function for processing information in a manner that
3256 // is unique to initial frames of input data.
3257 // From: AST Parameter Function -> decodeProcessing
3258 // Uses: See code.
3259 // States: x
3260 // Return: Error number in standard or SIO form (0 on success).
3261 // Trace: Message Log "trace" in Debug Project Configuration reports:
3262 // * State information as per parent.
3263 //
3264 Int
3265 PAF_ASIT_decodeInfo1(
3266 const PAF_ASIT_Params *pP,
3267 const PAF_ASIT_Patchs *pQ,
3268 PAF_ASIT_Config *pC,
3269 Int frame,
3270 Int block
3271 )
3272 {
3273 return 0;
3274 } //PAF_ASIT_decodeInfo1
3276 // -----------------------------------------------------------------------------
3277 // AST Decoding Function - Info Processing, Subsequent
3278 //
3279 // Name: PAF_AST_decodeInfo2
3280 // Purpose: Decoding Function for processing information in a manner that
3281 // is unique to frames of input data other than the initial one.
3282 // From: AST Parameter Function -> decodeProcessing
3283 // Uses: See code.
3284 // States: x
3285 // Return: Error number in standard form (0 on success).
3286 // Trace: None.
3287 //
3288 Int
3289 PAF_ASIT_decodeInfo2(
3290 const PAF_ASIT_Params *pP,
3291 const PAF_ASIT_Patchs *pQ,
3292 PAF_ASIT_Config *pC,
3293 Int frame,
3294 Int block
3295 )
3296 {
3297 return 0;
3298 } //PAF_ASIT_decodeInfo2
3300 // -----------------------------------------------------------------------------
3301 // AST Decoding Function - Continuation Processing
3302 //
3303 // Name: PAF_AST_decodeCont
3304 // Purpose: Decoding Function for processing that occurs subsequent to
3305 // information processing but antecedent to timing processing
3306 // for frames of input data other than the initial one.
3307 // From: AST Parameter Function -> decodeProcessing
3308 // Uses: See code.
3309 // States: x
3310 // Return: Error number in standard form (0 on success).
3311 // Trace: Message Log "trace" in Debug Project Configuration reports:
3312 // * State information as per parent.
3313 //
3315 Int
3316 PAF_AST_decodeCont(
3317 const PAF_ASIT_Params *pP,
3318 const PAF_ASIT_Patchs *pQ,
3319 PAF_ASIT_Config *pC,
3320 ALG_Handle decAlg[],
3321 Int frame,
3322 Int block
3323 )
3324 {
3325 PAF_AST_Config *pAstCfg;
3326 Int as; /* Audio Stream Number (1, 2, etc.) */
3327 Int z; /* decode counter */
3328 Int zI, zS;
3329 Int zMD;
3330 #ifdef NON_CACHE_STATUS
3331 Int8 tempVar8;
3332 #endif
3335 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3336 as = pAstCfg->as;
3337 zMD = pAstCfg->masterDec;
3338 (void)as; // clear compiler warning in case not used with tracing disabled
3340 // Await slave inputs
3341 for (z=DECODE1; z < DECODEN; z++)
3342 {
3343 zI = pP->inputsFromDecodes[z];
3344 zS = pP->streamsFromDecodes[z];
3345 (void)zS;
3346 #ifdef NON_CACHE_STATUS
3347 statusOp_read(&tempVar8,
3348 &(pAstCfg->xDec[z].decodeStatus.mode),
3349 sizeof(Int8),
3350 GATEMP_INDEX_DEC);
3351 if (z == zMD
3352 || ! pAstCfg->xInp[zI].hRxSio
3353 || ! tempVar8)
3354 continue;
3355 #else
3356 if (z == zMD
3357 || ! pAstCfg->xInp[zI].hRxSio
3358 || ! pAstCfg->xDec[z].decodeStatus.mode)
3359 continue;
3360 #endif
3361 TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
3362 if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
3363 != sizeof (pAstCfg->xInp[zI].inpBufConfig))
3364 return (ASPERR_RECLAIM);
3365 }
3367 return 0;
3368 } //PAF_AST_decodeCont
3370 // -----------------------------------------------------------------------------
3371 // ASIT Decoding Function - Decode Processing
3372 //
3373 // Name: PAF_ASIT_decodeDecode
3374 // Purpose: Decoding Function for processing of input data by the
3375 // Decode Algorithm.
3376 // From: AST Parameter Function -> decodeProcessing
3377 // Uses: See code.
3378 // States: x
3379 // Return: Error number in standard form (0 on success).
3380 // Trace: Message Log "trace" in Debug Project Configuration reports:
3381 // * State information as per parent.
3382 //
3383 Int
3384 PAF_ASIT_decodeDecode(
3385 const PAF_ASIT_Params *pP,
3386 const PAF_ASIT_Patchs *pQ,
3387 PAF_ASIT_Config *pC,
3388 Int sourceSelect,
3389 Int frame,
3390 Int block
3391 )
3392 {
3393 PAF_AST_Config *pAstCfg;
3394 Int as; /* Audio Stream Number (1, 2, etc.) */
3395 Int z; /* decode/stream counter */
3396 Int errno; /* error number */
3397 //Int ch;
3398 ASP_Msg *pAspMsg; /* Messaging */
3399 Int argIdx;
3400 Int status;
3401 Int cbErrno;
3402 Int frameLength;
3404 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3405 as = pAstCfg->as;
3406 (void)as; // clear compiler warning in case not used with tracing disabled
3408 #if 0 // FL: slave
3409 // Clear samsiz for all channels - MID 208.
3410 for (z=STREAM1; z < STREAMN; z++)
3411 {
3412 for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++)
3413 {
3414 pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
3415 }
3416 }
3417 #endif
3419 // Decode data
3420 for (z=DECODE1; z < DECODEN; z++)
3421 {
3422 Int zI = pP->inputsFromDecodes[z];
3423 Int zS = pP->streamsFromDecodes[z];
3424 (void)zS; // clear compiler warning in case not used with tracing disabled
3425 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3426 {
3427 TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
3429 TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
3430 as+zS,
3431 (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
3432 (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
3434 // FL: debug, capture input buffer
3435 //capIbPcm(pAstCfg->xInp[z].pInpBuf);
3437 // (***) FL: revisit
3438 // write back Dec configuration
3439 Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3440 Cache_wait();
3442 // FL: send decode message to slave
3443 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3444 if (pAspMsg == NULL)
3445 {
3446 TRACE_TERSE0("MessageQ_alloc() failure.");
3447 SW_BREAKPOINT; // temporary
3448 return -1; // temporary
3449 }
3450 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3451 pAspMsg->cmd = ASP_SLAVE_DEC_DECODE; /* fill in message payload */
3452 pAspMsg->procId = hAspMsgMaster->masterProcId;
3453 pAspMsg->expectResp = TRUE;
3454 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3455 argIdx = 0; // set decIdx
3456 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3457 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3458 TRACE_MSG1("decIdx=%d", pAspMsg->buf[argIdx]);
3459 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3460 if (status != MessageQ_S_SUCCESS)
3461 {
3462 SW_BREAKPOINT;
3463 }
3464 // wait for decode complete message from slave -- temporary
3465 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3466 if (status != MessageQ_S_SUCCESS)
3467 {
3468 TRACE_TERSE0("MessageQ_get() failure.");
3469 SW_BREAKPOINT; // temporary
3470 return -1; // temporary
3471 }
3472 if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
3473 (pAspMsg->cmd == ASP_MASTER_DEC_DECODE_DONE) &&
3474 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3475 {
3476 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3477 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3479 argIdx = 0; // get decErrno
3480 errno = *(Int32 *)&pAspMsg->buf[argIdx];
3481 argIdx += sizeof(Int32); // get cbErrno
3482 cbErrno = *(Int32 *)&pAspMsg->buf[argIdx];
3483 if (cbErrno != 0)
3484 {
3485 gCbWrtAfErrCnt++;
3486 TRACE_TERSE1("CB write error=%d", cbErrno);
3487 //SW_BREAKPOINT; // temporary
3488 }
3489 }
3490 else
3491 {
3492 //
3493 // Invalid message received
3494 //
3495 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3496 SW_BREAKPOINT; // temporary
3497 }
3498 // free the message
3499 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3500 if (status != MessageQ_S_SUCCESS)
3501 {
3502 SW_BREAKPOINT;
3503 }
3505 // (***) FL: revisit
3506 // invalidate Dec configuration
3507 Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
3508 Cache_wait();
3510 #if 0 // FL: decoder decode call, slave
3511 if (dec->fxns->decode
3512 && (errno = dec->fxns->decode (dec, NULL,
3513 &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct)))
3514 #endif
3515 if (errno)
3516 {
3517 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
3518 return errno;
3519 }
3521 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3522 as_traceChannels(pC, z);
3523 #endif
3525 #if 0 // FL: change handle to decIdx (zone index)
3526 frameLength = pP->fxns->computeFrameLength(decAlg[z],
3527 FRAMELENGTH,
3528 pC->xDec[z].decodeStatus.bufferRatio);
3529 #endif
3530 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
3531 frameLength = pP->fxns->computeFrameLength(z,
3532 FRAMELENGTH,
3533 pC->xDec[z].decodeStatus.bufferRatio);
3534 #else
3535 if (sourceSelect == PAF_SOURCE_PCM)
3536 {
3537 frameLength = PAF_SYS_FRAMELENGTH;
3538 }
3539 else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
3540 {
3541 frameLength = 1536;
3542 }
3543 else if (sourceSelect == PAF_SOURCE_THD)
3544 {
3545 frameLength = 1536; //QIN FIX ME
3546 }
3547 else
3548 {
3549 frameLength = 256;
3550 }
3551 #endif
3554 //#ifdef PROFILER
3555 // // modify for different decoders
3556 // if (sourceSelect == PAF_SOURCE_THD)
3557 // {
3558 // start_profiling = 1;
3559 // }
3560 // else
3561 // {
3562 // start_profiling = 0;
3563 // }
3564 //#endif
3567 // ............................................................................
3569 pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
3570 pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
3571 if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio,
3572 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3573 {
3574 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3575 return errno;
3576 }
3578 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3579 if (errno = SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
3580 sizeof(pAstCfg->xInp[zI].inpBufConfig),
3581 PAF_SIO_REQUEST_NEWFRAME))
3582 {
3583 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3584 return (ASPERR_ISSUE);
3585 }
3586 } // hRxSio && decodeStatus.mode
3587 else
3588 {
3589 TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3590 }
3591 } // z=DECODE1 to DECODEN
3593 #if 0 // FL: ASDT (slave)
3594 // Set up audio frames not decoded into
3595 // Re-initialize audio frame if there is an assocatiated decode and
3596 // that decode doesn't have a valid input or is turned off
3597 for (z=STREAM1; z < STREAMN; z++)
3598 {
3599 Int zX;
3600 Int reset = 0;
3601 for (zX = DECODE1; zX < DECODEN; zX++)
3602 {
3603 if (pP->streamsFromDecodes[zX] == z)
3604 {
3605 Int zI = pP->inputsFromDecodes[zX];
3606 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3607 reset = 1;
3608 }
3609 }
3610 if (reset)
3611 {
3612 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3613 pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3614 }
3615 else
3616 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3617 }
3618 #endif
3620 return 0;
3621 } //PAF_ASIT_decodeDecode
3623 // -----------------------------------------------------------------------------
3624 // ASIT Decoding Function - Frame-Final Processing
3625 //
3626 // Name: PAF_ASIT_decodeFinalTest
3627 // Purpose: Decoding Function for determining whether processing of the
3628 // current frame is complete.
3629 // From: AST Parameter Function -> decodeProcessing
3630 // Uses: See code.
3631 // States: x
3632 // Return: 0 if incomplete, and 1 if complete.
3633 // Trace: None.
3634 //
3636 Int
3637 PAF_ASIT_decodeFinalTest(
3638 const PAF_ASIT_Params *pP,
3639 const PAF_ASIT_Patchs *pQ,
3640 PAF_ASIT_Config *pC,
3641 Int frame,
3642 Int block
3643 )
3644 {
3645 PAF_AST_Config *pAstCfg;
3646 Int zMD;
3647 Int sourceSelect;
3648 Int sourceProgram;
3649 #ifdef NON_CACHE_STATUS
3650 Int8 tempVar8, temp2Var8;
3651 #endif
3653 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3654 zMD = pAstCfg->masterDec;
3656 #ifdef NON_CACHE_STATUS
3657 statusOp_read(&tempVar8,
3658 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3659 sizeof(Int8),
3660 GATEMP_INDEX_DEC);
3661 sourceSelect = tempVar8;
3662 statusOp_read(&tempVar8,
3663 &(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3664 sizeof(Int8),
3665 GATEMP_INDEX_DEC);
3666 sourceProgram = tempVar8;
3667 #else
3668 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
3669 sourceProgram = pAstCfg->xDec[zMD].decodeStatus.sourceProgram;
3670 #endif
3672 if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3673 {
3674 return 1;
3675 }
3677 // The following allows for Force modes to switch without command deferral. This might
3678 // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3679 if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
3680 {
3681 if (sourceSelect == PAF_SOURCE_DTSALL)
3682 {
3683 if (sourceProgram != PAF_SOURCE_DTS11 &&
3684 sourceProgram != PAF_SOURCE_DTS12 &&
3685 sourceProgram != PAF_SOURCE_DTS13 &&
3686 sourceProgram != PAF_SOURCE_DTS14 &&
3687 sourceProgram != PAF_SOURCE_DTS16 &&
3688 sourceProgram != PAF_SOURCE_DTSHD)
3689 {
3690 return 1;
3691 }
3692 }
3693 else if (sourceSelect == PAF_SOURCE_PCMAUTO)
3694 {
3695 if (sourceProgram != PAF_SOURCE_PCM)
3696 {
3697 return 1;
3698 }
3699 }
3700 else
3701 {
3702 #ifdef NON_CACHE_STATUS
3703 statusOp_read(&tempVar8,
3704 &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
3705 sizeof(Int8),
3706 GATEMP_INDEX_DEC);
3707 statusOp_read(&temp2Var8,
3708 &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3709 sizeof(Int8),
3710 GATEMP_INDEX_DEC);
3711 if (temp2Var8 != tempVar8)
3712 {
3713 return 1;
3714 }
3715 #else
3716 if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect != pAstCfg->xDec[zMD].decodeStatus.sourceDecode)
3717 {
3718 return 1;
3719 }
3720 #endif
3721 }
3722 }
3724 return 0;
3725 } //PAF_ASIT_decodeFinalTest
3727 // -----------------------------------------------------------------------------
3728 // ASIT Decoding Function - Stream-Final Processing
3729 //
3730 // Name: PAF_ASIT_decodeComplete
3731 // Purpose: Decoding Function for terminating the decoding process.
3732 // From: AST Parameter Function -> decodeProcessing
3733 // Uses: See code.
3734 // States: x
3735 // Return: 0.
3736 // Trace: Message Log "trace" in Debug Project Configuration reports:
3737 // * State information as per parent.
3738 //
3739 Int
3740 PAF_ASIT_decodeComplete(
3741 const PAF_ASIT_Params *pP,
3742 const PAF_ASIT_Patchs *pQ,
3743 PAF_ASIT_Config *pC,
3744 ALG_Handle decAlg[],
3745 Int frame,
3746 Int block
3747 )
3748 {
3749 PAF_AST_Config *pAstCfg;
3750 Int as; /* Audio Stream Number (1, 2, etc.) */
3751 Int z; /* decode/encode counter */
3752 ASP_Msg* pAspMsg;
3753 Int argIdx;
3754 Int errno; /* error number */
3755 Int status;
3756 #ifdef NON_CACHE_STATUS
3757 Int8 tempVar8;
3758 #endif
3761 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3762 as = pAstCfg->as;
3763 (void)as; // clear compiler warning in case not used with tracing disabled
3765 #ifdef PAF_ASP_FINAL
3766 /* This material is currently not utilized */
3767 #endif /* PAF_ASP_FINAL */
3768 for (z=DECODE1; z < DECODEN; z++)
3769 {
3770 #ifdef PAF_ASP_FINAL
3771 DEC_Handle dec = (DEC_Handle )decAlg[z];
3772 #endif /* PAF_ASP_FINAL */
3773 Int zI = pP->inputsFromDecodes[z];
3774 #ifdef NON_CACHE_STATUS
3775 statusOp_read(&tempVar8,
3776 &(pAstCfg->xDec[z].decodeStatus.mode),
3777 sizeof(Int8),
3778 GATEMP_INDEX_DEC);
3779 if (pAstCfg->xInp[zI].hRxSio && tempVar8)
3780 {
3781 #else
3782 if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
3783 {
3784 #endif
3785 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3786 #ifdef PAF_ASP_FINAL
3787 if (dec->fxns->final)
3788 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
3789 &pAstCfg->xDec[z].decodeStatus);
3790 #endif /* PAF_ASP_FINAL */
3791 // FL: send dec deactivate message to slave
3792 pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
3793 if (pAspMsg == NULL)
3794 {
3795 TRACE_TERSE0("MessageQ_alloc() failure.");
3796 errno = -1; // temporary
3797 return errno;
3798 }
3799 MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg); /* set the return address in the message header */
3800 pAspMsg->cmd = ASP_SLAVE_DEC_DEACTIVATE; /* fill in message payload */
3801 pAspMsg->procId = hAspMsgMaster->masterProcId;
3802 pAspMsg->expectResp = TRUE;
3803 pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
3804 argIdx = 0; // set decIdx
3805 *(Int32 *)&pAspMsg->buf[argIdx] = z;
3806 TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3807 TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
3808 status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg); /* send message */
3809 if (status != MessageQ_S_SUCCESS)
3810 {
3811 SW_BREAKPOINT;
3812 }
3813 // wait for dec deactivate complete message from slave
3814 status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
3815 if (status != MessageQ_S_SUCCESS)
3816 {
3817 TRACE_TERSE0("MessageQ_get() failure.");
3818 return errno;
3819 }
3820 if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
3821 (pAspMsg->cmd != ASP_MASTER_DEC_DEACTIVATE_DONE) ||
3822 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
3823 {
3824 TRACE_MSG3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3825 SW_BREAKPOINT; // temporary
3826 }
3827 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
3828 TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
3829 // free the message
3830 status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
3831 if (status != MessageQ_S_SUCCESS)
3832 {
3833 SW_BREAKPOINT;
3834 }
3836 #if 0 // FL: decoder deactivate call, slave
3837 if (decAlg[z]->fxns->algDeactivate)
3838 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3839 #endif
3840 }
3841 else
3842 {
3843 TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3844 }
3845 }
3846 return 0;
3847 } //PAF_ASIT_decodeComplete
3849 // -----------------------------------------------------------------------------
3850 // ASIT Selection Function - Input Device Selection
3851 //
3852 // Name: PAF_ASIT_selectDevices
3853 // Purpose: Audio Stream Input Task Function for selecting the devices used
3854 // for input.
3855 // From: audioStream1Task or equivalent
3856 // Uses: See code.
3857 // States: x
3858 // Return: Error number in standard form (0 on success).
3859 // Trace: Message Log "trace" in Debug Project Configuration reports:
3860 // * State information as per parent.
3861 //
3862 Int
3863 PAF_ASIT_selectDevices(
3864 const PAF_ASIT_Params *pP,
3865 const PAF_ASIT_Patchs *pQ,
3866 PAF_ASIT_Config *pC
3867 )
3868 {
3869 PAF_AST_Config *pAstCfg;
3870 Int as; /* Audio Stream Number (1, 2, etc.) */
3871 Int z; /* input/output counter */
3872 Int errno = 0; /* error number */
3873 Int errme; /* error number, local */
3874 Int device;
3875 Int zMD;
3877 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3878 as = pAstCfg->as;
3879 zMD = pAstCfg->masterDec;
3880 (void)as; // clear compiler warning in case not used with tracing disabled
3882 // Select input devices
3883 for (z=INPUT1; z < INPUTN; z++)
3884 {
3885 if ((device = pAstCfg->xInp[z].inpBufStatus.sioSelect) >= 0)
3886 {
3887 TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3889 // check for valid index into device array
3890 if (device >= pQ->devinp->n)
3891 {
3892 device = 0; /* treat as device None */
3893 }
3895 errme = pP->fxns->deviceSelect(&pAstCfg->xInp[z].hRxSio, SIO_INPUT,
3896 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3898 if (errme)
3899 {
3900 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3901 if (!errno)
3902 {
3903 errno = ASPERR_DEVINP + errme;
3904 }
3905 pAstCfg->xInp[z].inpBufStatus.sioSelect = 0x80;
3906 }
3907 else
3908 {
3909 pAstCfg->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3910 // register decodeStatus pointer with input devices
3911 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3912 // Use zMIs decodeStatus for all inputs
3913 if (pAstCfg->xInp[z].hRxSio)
3914 {
3915 // register PAF_SIO_IALG object address
3916 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR,
3917 (Arg)pAstCfg->xInp[z].inpChainData.head->alg);
3918 SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR,
3919 (Arg)&pAstCfg->xDec[zMD].decodeStatus);
3920 }
3921 }
3922 }
3923 }
3925 return errno;
3926 } //PAF_ASIT_selectDevices
3928 // -----------------------------------------------------------------------------
3929 // ASIT Selection Function - Source Selection
3930 //
3931 // Name: PAF_ASIT_sourceDecode
3932 // Purpose: Audio Input Stream Task Function for selecting the sources used
3933 // for decoding of input to output.
3934 // From: audioStream1Task or equivalent
3935 // Uses: See code.
3936 // States: x
3937 // Return: 0.
3938 // Trace: None.
3939 //
3940 Int
3941 PAF_ASIT_sourceDecode(
3942 const PAF_ASIT_Params *pP,
3943 const PAF_ASIT_Patchs *pQ,
3944 PAF_ASIT_Config *pC,
3945 Int x
3946 )
3947 {
3948 PAF_AST_Config *pAstCfg;
3949 Int z; /* decode counter */
3950 #ifdef NON_CACHE_STATUS
3951 Int8 tempVar8;
3952 #endif
3954 pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
3956 for (z=DECODE1; z < DECODEN; z++)
3957 {
3958 #ifdef NON_CACHE_STATUS
3959 statusOp_read(&tempVar8,
3960 &(pAstCfg->xDec[z].decodeStatus.mode),
3961 sizeof(Int8),
3962 GATEMP_INDEX_DEC);
3963 if (tempVar8)
3964 {
3965 tempVar8 = x;
3966 statusOp_write(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3967 &tempVar8,
3968 sizeof(Int8),
3969 GATEMP_INDEX_DEC);
3970 }
3971 #else
3972 if (pAstCfg->xDec[z].decodeStatus.mode)
3973 {
3974 pAstCfg->xDec[z].decodeStatus.sourceDecode = x;
3975 }
3976 #endif
3977 }
3979 return 0;
3980 } //PAF_ASIT_sourceDecode
3982 // -----------------------------------------------------------------------------
3984 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3985 Int
3986 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3987 {
3988 Int errno = 0;
3989 Int zMD = pC->masterDec;
3990 Int zI = pP->inputsFromDecodes[z];
3992 // only handle real errors, on primary input, for writeDECModeContinuous
3993 if ( !( error &&
3994 z == zMD ))
3995 return error;
3997 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3998 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
4000 if (pC->xInp[zI].hRxSio) {
4001 DEC_Handle dec;
4003 if (errno = SIO_idle (pC->xInp[zI].hRxSio))
4004 return errno;
4006 // indicates (primary) input not running
4007 pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
4009 pC->xInp[zI].inpBufConfig.deliverZeros = 1;
4011 // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
4012 pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
4014 if (decAlg[z]->fxns->algDeactivate)
4015 decAlg[z]->fxns->algDeactivate (decAlg[z]);
4017 decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
4018 dec = (DEC_Handle )decAlg[z];
4020 TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
4021 pC->as+z));
4023 if (decAlg[z]->fxns->algActivate)
4024 decAlg[z]->fxns->algActivate (decAlg[z]);
4026 if (dec->fxns->reset
4027 && (errno = dec->fxns->reset (dec, NULL,
4028 &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
4029 return errno;
4030 }
4032 return errno;
4033 } //PAF_AST_decodeHandleErrorInput
4034 #endif
4036 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
4038 //------------------------------------------------------------------------------
4039 static int sSkipCount = 0;
4040 int gReportBuffers = 0;
4041 void as_traceChannels(PAF_AST_Config *pC, int z)
4042 {
4043 PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
4044 int i;
4046 // #ifdef THIS_IS_DSPA
4047 sSkipCount++;
4048 if (sSkipCount<1)
4049 return;
4050 sSkipCount = 0;
4051 // #endif
4053 #ifdef THIS_IS_DSPB
4054 if (!gReportBuffers)
4055 return;
4056 gReportBuffers = 0;
4057 #endif
4059 dp(NULL, "\n");
4060 for (i=0; i<PAF_MAXNUMCHAN; i++)
4061 {
4062 if (pAudioFrame->data.sample[i] != 0)
4063 {
4064 float *wp = (float*)pAudioFrame->data.sample[i];
4065 dp(NULL, "i: %d. p: 0x%x. %f, %f, %f, %f\n",
4066 i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
4067 }
4068 }
4069 }
4070 #endif