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