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