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