]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamInpProc.c
Add capIb at DSP Rx SIO reclaim
[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; // debug
302 UInt32 gAsipInitCnt     =0;
303 UInt32 gAsipInfo1Cnt    =0;
304 UInt32 gAsipInfo2Cnt    =0;
305 UInt32 gAsipDecodeCnt   =0;
306 UInt32 gAsipDecodeErrCnt   =0;
307 UInt32 gAsipFinalCnt    =0;
308 UInt32 gAsipQuitCnt     =0;
309 UInt32 gIbReset_cnt     =0;
310 UInt32 gcapIb_cnt        =0;
311 UInt32 gAsipInfo2_PrimaryErrCnt =0;
312 UInt32 gAsipInfo2_ErrCnt        =0;
314 #include "dbgDib.h"
316 extern struct {
317     Int size;
318     IALG_Status *pStatus[512];
319 } IACP_STD_BETA_TABLE;
322 /*
323  *  ======== taskAsipFxn ========
324  *  Audio Stream Input Processing task function
325  */
326 Void taskAsipFxn(
327 //    Int betaPrimeValue, // FL: revisit
328     const PAF_ASIT_Params *pP,
329     const PAF_ASIT_Patchs *pQ
332     PAF_ASIT_Config *pC;            /* Local configuration pointer */
333     PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
334     Int as;                         /* Audio Stream Number (1, 2, etc.) */
335     Int z;                          /* input/encode/stream/decode/output counter */
336     Int i;                          /* phase */
337     Int errno;                      /* error number */
338     Int zMD, zMI, zMS, zX;
339     Int loopCount = 0;  // used to stop trace to see startup behavior.        
340     UInt32 curTime;
341     Int size;
342     // Messaging
343     ASP_Msg *pAspMsg;              
344     Int status;
345 #ifdef NON_CACHE_STATUS
346     Int8 tempVar8;
347 #endif
349     Log_info0("Enter taskAsipFxn()");
350     
351 #ifdef SIMULATE_SIO
352     /* Start simulation */
353     simStart();
354 #endif // SIMULATE_SIO
356     //
357     // Audio Framework Parameters & Patch (*pP, *pQ)
358     //
359     if (!pP) 
360     {
361         TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
362         LINNO_RPRT(TaskAsip, -1);
363         return;
364     }
366     if (!pQ)
367     {
368         TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
369         LINNO_RPRT(TaskAsip, -1);
370         return;
371     }    
372     
373     //
374     // Audio Framework Configuration (*pC):
375     //
376     pC = &gPAF_ASIT_config;
377     pAstCfg = pC->pAstCfg;
379     /* Set Audio Stream Number (1, 2, etc.) */
380     as = gBetaPrimeValue + 1;
381     pAstCfg->as = as;    
382     TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
384     //
385     // Initialize message log trace and line number reporting
386     //
387     for (z=STREAM1; z < STREAMN; z++)
388     {
389         TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
390     }
391     LINNO_RPRT(TaskAsip, -1);
392     
393     //
394     // Determine decoder and stream indices associated with the master input
395     //
396     zMI = pP->zone.master;
397     pAstCfg->masterDec = zMI;
398     pAstCfg->masterStr = zMI;
399     for (zX = DECODE1; zX < DECODEN; zX++)
400     {
401         if (pP->inputsFromDecodes[zX] == zMI)
402         {
403             pAstCfg->masterDec = zX;
404             pAstCfg->masterStr = pP->streamsFromDecodes[zX];
405             break;
406         }
407     }
408     zMD = pAstCfg->masterDec;
409     zMS = pAstCfg->masterStr;
411     // Initialize as per parametrized phases:
412     //
413     //   In standard form these are:
414     //      - Malloc: Memory Allocation
415     //      - Config: Configuration Initialization
416     //      - AcpAlg: ACP Algorithm Initialization and Local Attachment
417     //      - Common: Common Memory Initialization
418     //      - AlgKey: Dec/Enc chain to Array Initialization
419     //      - Device: I/O Device Initialization
420     //      - DecOpCircBuf: Decoder Output Circular Buffer
421     //      - Unused: (available)
422     //
423     LINNO_RPRT(TaskAsip, -2);
424     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
425     {
426         Int linno;
427         if (pP->fxns->initPhase[i])
428         {
429             if (linno = pP->fxns->initPhase[i](pP, pQ, pC)) 
430             {
431                 LINNO_RPRT(TaskAsip, linno);
432                 return;
433             }
434         }
435         else 
436         {
437             TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
438         }
439         TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
440         LINNO_RPRT(TaskAsip, -i-3);
441     }
443     //
444     // End of Initialization -- display memory usage report.
445     //
446     if (pP->fxns->memStatusPrint)
447     {
448         pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
449     }
450     
451     // (***) FL: revisit
452     // write back AST shared configuration
453     Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
454     // FL: no need to share this pointer, can be local
455     //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
456     Cache_wait();
458     // (***) FL: revisit
459     // write back Dec configuration
460     Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
461     Cache_wait();
463     // (***) FL: revisit
464     // write back entire beta table
465     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
466     Cache_wait();
467     
468     // FL: send start initialization message to slave
469     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
470     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
471     pAspMsg->cmd = ASP_SLAVE_START;                                                     /* fill in message payload */
472     pAspMsg->procId = hAspMsgMaster->masterProcId;
473     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
474     pAspMsg->expectResp = TRUE;
475     TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
476     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
477     if (status != MessageQ_S_SUCCESS)
478     {
479         SW_BREAKPOINT;
480     }
481     // wait for initialization complete message from slave
482     do {
483         //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
484         status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
485     } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
486     if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
487         (pAspMsg->cmd != ASP_MASTER_START_DONE) || 
488         (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
489     {
490         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
491         SW_BREAKPOINT;
492     }
493     hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
494     TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
495     status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
496     if (status != MessageQ_S_SUCCESS)
497     {
498         SW_BREAKPOINT;
499     }
501     // (***) FL: revisit
502     // invalidate Status structure addresses for Beta Units initialized on Slave
503     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
504     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
505     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
506     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
507     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
508     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
509     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
510     Cache_wait();
511     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
512     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
513     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
514     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
515     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
516     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
517     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
518     
519     // (***) FL: revisit
520     // invalidate Status structures for Beta Units initialized on Slave
521     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
522     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
523     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
524     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
525     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
526     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
527     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
528     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
529     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
530     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
531     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
532     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
533     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
534     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
535     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
536     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
537     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
538     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
539     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
540     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
541     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
542     Cache_wait();
543     
544 #ifdef NON_CACHE_STATUS
545     // Get the shared status structure GateMP handles. Initialized at slave.
546     if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
547     {
548         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
549     }
550     if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
551     {
552         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
553     }
554     if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
555     {
556         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
557     }
558     if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
559     {
560         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
561     }
562 #endif
564     // (***) FL: revisit
565     // invalidate Dec configuration
566     Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
567     Cache_wait();
568     
569     //
570     // Main processing loop
571     //   
572     for (z=STREAM1; z < STREAMN; z++)
573     {
574         TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
575     }
577     TRACE_TERSE0("TaskAsip: Entering Main Loop.");
578     
579     errno = 0;
580     for (;;)
581     {
582         Int sourceSelect;
583         XDAS_Int8 sourceProgram;
585         loopCount++;
587 #if 0   // enable and tune to see startup behavior.
588         // this is an alternative to fixed/circular setting in pa.cfg.
589         // If you are searching for a memory allocation failure, disable on first round.
590         // All allocation has already happened.
591         // This is the outer loop.  This loop count goes up when the stream resets.
592         // If the stream is running without problems, this does not increment.
593         // If the stream is repeatedly resetting, this loop count will go up rapidly.
594         if (loopCount > 10)  // see traces for a few of the passes through the main loop.
595         {
596              TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
597              LOG_disable(&TR_MOD);  // stop tracing
598         }
599 #endif
601         TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
602         TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
603         
604         // since not decoding indicate such
605         pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
607         // any error forces idling of input
608         if (errno) 
609         {
610             for (z=INPUT1; z < INPUTN; z++)
611             {
612                 if (pAstCfg->xInp[z].hRxSio)
613                 {
614                     SIO_idle(pAstCfg->xInp[z].hRxSio);
615                 }
616             }
617         
618             TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
619             ERRNO_RPRT(TaskAsip, errno);
620         }
621         
622         // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
623         // up to allow lower priority tasks to run. This may seem odd to be at the top
624         // of the state machine but provides for a cleaner flow even though the very
625         // first time we enter we do a sleep which is non-intuitive.
626         TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
627         TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
628         Task_sleep(1);
630         TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
631         if (errno = pP->fxns->selectDevices(pP, pQ, pC))
632         {
633             TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
634             continue;
635         }
637         // if no master input selected then we don't know what may be at the input
638         // so set to unknown and skip any remaining processing
639         if (!pAstCfg->xInp[zMI].hRxSio)
640         {
641 #ifdef NON_CACHE_STATUS
642             tempVar8 = PAF_SOURCE_UNKNOWN;
643             statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
644                            &tempVar8,
645                            sizeof(tempVar8),
646                            GATEMP_INDEX_DEC);
647 #else
648             pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
649 #endif
650             TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
651             continue;
652         }
653         
654         // if here then we have a valid input so query its status
655         if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
656         {
657             TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
658             continue;
659         }
660         
661 #ifdef NON_CACHE_STATUS
662         statusOp_read(&tempVar8,
663                       &(pAstCfg->xDec[zMD].decodeStatus.mode),
664                       sizeof(tempVar8),
665                       GATEMP_INDEX_DEC);
666         // If master decoder is not enabled, or the input is unlocked, then do nothing
667         if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
668         {
669             TRACE_VERBOSE0("TaskAsip: Not locked, continue");
670             continue;
671         }
672 #else
673         // If master decoder is not enabled, or the input is unlocked, then do nothing
674         if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
675         {
676             TRACE_VERBOSE0("TaskAsip: Not locked, continue");
677             continue;
678         }
679 #endif
680         
681 #ifdef NON_CACHE_STATUS
682         statusOp_read(&tempVar8,
683                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
684                       sizeof(tempVar8),
685                       GATEMP_INDEX_DEC);
686         // If no source selected then do nothing
687         if (tempVar8 == PAF_SOURCE_NONE)
688         {
689             tempVar8 = PAF_SOURCE_NONE;
690             statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
691                            &tempVar8,
692                            sizeof(tempVar8),
693                            GATEMP_INDEX_DEC);
694             TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
695             continue;
696         }
697 #else
698         // If no source selected then do nothing
699         if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE) 
700         {
701             pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
702             TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
703             continue;
704         }
705 #endif
707 #ifdef NON_CACHE_STATUS
708         statusOp_read(&tempVar8,
709                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
710                       sizeof(tempVar8),
711                       GATEMP_INDEX_DEC);
712         // If we want pass processing then proceed directly
713         if (tempVar8 == PAF_SOURCE_PASS)
714         {
715             TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
717             tempVar8 = PAF_SOURCE_PASS;
718             statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
719                            &tempVar8,
720                            sizeof(tempVar8),
721                            GATEMP_INDEX_DEC);
722 #else
723         // If we want pass processing then proceed directly
724         if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) 
725         {
726             TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
727             pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
728 #endif
729             pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
730             if (pP->fxns->passProcessing)
731             {
732                 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);                
733             }
734             else 
735             {
736                 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
737                 errno = ASPERR_PASS;
738             }
739             TRACE_VERBOSE0("TaskAsip: continue");
740             continue;
741         }
743 #ifdef NON_CACHE_STATUS
744         statusOp_read(&tempVar8,
745                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
746                       sizeof(tempVar8),
747                       GATEMP_INDEX_DEC);
748         // .....................................................................
749         // At this point we have an enabled input and want to decode something.
750         // If no decoder selected then do nothing. Need to reset the sourceProgram, since
751         // when no decoder is selected there are no calls to IB
752         //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
753         if (errno = pP->fxns->autoProcessing(pP, pQ, pC, tempVar8, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
754         {
755             TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
756             continue;
757         }
758 #else
759         // .....................................................................
760         // At this point we have an enabled input and want to decode something.
761         // If no decoder selected then do nothing. Need to reset the sourceProgram, since
762         // when no decoder is selected there are no calls to IB
763         //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
764         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
765         {
766             TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
767             continue;
768         }
769 #endif
770         
771         // query for input type
772         if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
773         {
774             TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
775             errno = ASPERR_AUTO_PROGRAM;
776             continue;
777         }
778 #ifdef NON_CACHE_STATUS
779         statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
780                       &(sourceProgram),
781                       sizeof(sourceProgram),
782                       GATEMP_INDEX_DEC);
783 #else
784         pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
785 #endif
787         // if input is unclassifiable then do nothing
788         if (sourceProgram == PAF_SOURCE_UNKNOWN)
789         {
790             TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
791             continue;
792         }
794         // now that we have some input classification, and possibly an outstanding
795         // input frame, we determine whether or not to call decodeProcessing and with
796         // what decAlg.
797         sourceSelect = PAF_SOURCE_NONE;
798 #ifdef NON_CACHE_STATUS
799         statusOp_read(&tempVar8,
800                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
801                       sizeof(tempVar8),
802                       GATEMP_INDEX_DEC);
803         switch (tempVar8)
804         {
805 #else
806         switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect) 
807         {
808 #endif
809             // If autodetecting, decoding everything, and input is something
810             // (i.e. bitstream or PCM) then decode.
811             case PAF_SOURCE_AUTO:
812                 if (sourceProgram >= PAF_SOURCE_PCM)
813                 {
814                     sourceSelect = sourceProgram;                    
815                 }
816                 break;
818             // If autodetecting, decoding only PCM, and input is PCM then decode.
819             case PAF_SOURCE_PCMAUTO:
820                 if (sourceProgram == PAF_SOURCE_PCM)
821                 {
822                     sourceSelect = sourceProgram;                    
823                 }
824                 break;
826             // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
827             case PAF_SOURCE_BITSTREAM:
828                 if (sourceProgram >= PAF_SOURCE_AC3)
829                 {
830                     sourceSelect = sourceProgram;                    
831                 }
832                 break;
834             // If autodetecting, decoding only DTS, and input is DTS then decode.
835             case PAF_SOURCE_DTSALL:
836                 switch (sourceProgram) 
837                 {
838                     case PAF_SOURCE_DTS11:
839                     case PAF_SOURCE_DTS12:
840                     case PAF_SOURCE_DTS13:
841                     case PAF_SOURCE_DTS14:
842                     case PAF_SOURCE_DTS16:
843                     case PAF_SOURCE_DTSHD:
844                         sourceSelect = sourceProgram;
845                         break;
846                 }
847                 break;
849             // All others, e.g., force modes, fall through to here.
850             // If user made specific selection then program must match select.
851             // (NB: this compare relies on ordering of PAF_SOURCE)
852             default:
853 #ifdef NON_CACHE_STATUS
854                 sourceSelect = 0; // due to size difference
855                 statusOp_read(&sourceSelect,
856                               &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
857                               sizeof(Int8),
858                               GATEMP_INDEX_DEC);
859 #else
860                 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
861 #endif
862                 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
863                 {
864                     if (sourceProgram != sourceSelect)
865                     {
866                         sourceSelect = PAF_SOURCE_NONE;                        
867                     }
868                 }
869                 break;
870         }
872         // if we didn't find any matches then skip
873         if (sourceSelect == PAF_SOURCE_NONE)
874         {
875             TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
876             continue;
877         }
879         // FL: debug, reset IB capture buffer
880         capIbReset();
881         gIbReset_cnt++;
882         Log_info0("capIbReset()");
883         
884         // FL: send source select message to slave
885         pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
886         MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
887         pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT;                                         /* fill in message payload */
888         pAspMsg->procId = hAspMsgMaster->masterProcId;
889         pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
890         pAspMsg->expectResp = TRUE;
891         *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
892         TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
893         TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
894         status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
895         if (status != MessageQ_S_SUCCESS)
896         {
897             SW_BREAKPOINT;
898         }
899         // wait for source select complete message from slave
900         //do {
901         //    status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
902         //} while (status != MessageQ_S_SUCCESS);
903         status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
904         if (status != MessageQ_S_SUCCESS)
905         {
906             TRACE_TERSE0("MessageQ_get() failure.");
907             SW_BREAKPOINT; // temporary
908         }
909         if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
910             (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
911             (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
912         {
913             TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
914             SW_BREAKPOINT;
915         }
916         hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
917         TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
918         status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
919         if (status != MessageQ_S_SUCCESS)
920         {
921             SW_BREAKPOINT;
922         }
923         
924         // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
925         // iff we are in this top level state machine and specifically not in decodeProcessing
926         pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
927         
928         TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
930         TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
931         errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
932         if (errno) 
933         {
934             TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
935         }
936         else
937         {
938             TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
939         }        
941         // FL: send dec exit message to slave
942         pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
943         MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
944         pAspMsg->cmd = ASP_SLAVE_DEC_EXIT;                                                  /* fill in message payload */
945         pAspMsg->procId = hAspMsgMaster->masterProcId;
946         pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
947         pAspMsg->expectResp = TRUE;
948         TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
949         status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
950         if (status != MessageQ_S_SUCCESS)
951         {
952             SW_BREAKPOINT;
953         }
954         // wait for dec exit complete message from slave
955         //do {
956         //    status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
957         //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
958         status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
959         if (status != MessageQ_S_SUCCESS)
960         {
961             TRACE_TERSE0("MessageQ_get() failure.");
962             SW_BREAKPOINT; // temporary
963         }
964         if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) || 
965             (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
966             (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
967         {
968             TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
969             SW_BREAKPOINT;
970         }
971         hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
972         TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
973         // free the message
974         status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
975         if (status != MessageQ_S_SUCCESS)
976         {
977             SW_BREAKPOINT;
978         }
979     } // End of main processing loop for (;;)
980     
981     Log_info0("Exit taskAsipFxn()");
984 // -----------------------------------------------------------------------------
985 // ASIT Initialization Function - Memory Allocation
986 //
987 //   Name:      PAF_ASIT_initPhaseMalloc
988 //   Purpose:   Audio Stream Input Task Function for initialization of data pointers
989 //              by allocation of memory.
990 //   From:      audioStream1Task or equivalent
991 //   Uses:      See code.
992 //   States:    x
993 //   Return:    0 on success.
994 //              Source code line number on MEM_calloc failure.
995 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
996 //              * State information as per parent.
997 //              * Memory allocation errors.
998 //
999 Int
1000 PAF_ASIT_initPhaseMalloc(
1001     const PAF_ASIT_Params *pP, 
1002     const PAF_ASIT_Patchs *pQ, 
1003     PAF_ASIT_Config *pC
1006     PAF_AST_Config *pAstCfg;
1007     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1008     Int zMS;
1009     Error_Block    eb;
1011     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1012     as = pAstCfg->as;
1013     zMS = pAstCfg->masterStr;
1014     
1015     TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1017     // Initialize error block
1018     Error_init(&eb); 
1020     /* Input memory */
1021     if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
1022         INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
1023     {
1024         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1025         SW_BREAKPOINT;
1026         return __LINE__;
1027     }
1028     TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
1029         INPUTN * sizeof (*pAstCfg->xInp),
1030         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
1032 #ifdef NON_CACHE_STATUS
1033     /* Decode memory */
1034     if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM,
1035         DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1036     {
1037         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1038         SW_BREAKPOINT;
1039         return __LINE__;
1040     }
1041 #else
1042     /* Decode memory */
1043     if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
1044         DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1045     {
1046         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1047         SW_BREAKPOINT;
1048         return __LINE__;
1049     }
1050 #endif
1051     TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
1052         DECODEN * sizeof (*pAstCfg->xDec),
1053         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
1054                 
1055     TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1056     return 0;
1057 } //PAF_ASIT_initPhaseMalloc
1059 // -----------------------------------------------------------------------------
1060 // ASIT Initialization Function - Memory Initialization from Configuration
1061 //
1062 //   Name:      PAF_ASIT_initPhaseConfig
1063 //   Purpose:   Audio Stream Task Function for initialization of data values
1064 //              from parameters.
1065 //   From:      audioStream1Task or equivalent
1066 //   Uses:      See code.
1067 //   States:    x
1068 //   Return:    0 on success.
1069 //              Other as per initFrame0 and initFrame1.
1070 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1071 //              * State information as per parent.
1072 //
1073 Int
1074 PAF_ASIT_initPhaseConfig(
1075     const PAF_ASIT_Params *pP, 
1076     const PAF_ASIT_Patchs *pQ, 
1077     PAF_ASIT_Config *pC
1080     PAF_AST_Config *pAstCfg;
1081     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1082     Int z;                     /* input/encode/stream/decode/output counter */
1083     Int zMS;
1085     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1086     as = pAstCfg->as;
1087     zMS = pAstCfg->masterStr;
1088     
1089     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1091     //
1092     // Unspecified elements have been initialized to zero during alloc
1093     //
1094     
1095     for (z=INPUT1; z < INPUTN; z++) 
1096     {
1097         pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
1098         pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
1099     }
1101     for (z=DECODE1; z < DECODEN; z++) 
1102     {
1103         Int zI = pP->inputsFromDecodes[z];
1104         pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
1105         pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
1106         //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
1107     }
1109     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1110     return 0;
1111 } //PAF_ASIT_initPhaseConfig
1113 // -----------------------------------------------------------------------------
1114 // ASIT Initialization Function - ACP Algorithm Instantiation
1115 //
1116 //   Name:      PAF_ASIT_initPhaseAcpAlg
1117 //   Purpose:   Audio Stream Input Task Function for initialization of ACP by
1118 //              instantiation of the algorithm.
1119 //   From:      audioStream1Task or equivalent
1120 //   Uses:      See code.
1121 //   States:    x
1122 //   Return:    0 on success.
1123 //              Source code line number on ACP Algorithm creation failure.
1124 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1125 //              * State information as per parent.
1126 //              * Memory allocation errors.
1127 //
1128 Int
1129 PAF_ASIT_initPhaseAcpAlg(
1130     const PAF_ASIT_Params *pP, 
1131     const PAF_ASIT_Patchs *pQ, 
1132     PAF_ASIT_Config *pC
1135     PAF_AST_Config *pAstCfg;
1136     Int as;                 /* Audio Stream Number (1, 2, etc.) */
1137     Int z;                  /* input/encode/stream/decode/output counter */
1138     Int betaPrimeOffset;
1139     ACP_Handle acp;
1140     Int zMS;
1141     Int zS, zX;
1143     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1144     as = pAstCfg->as;
1145     zMS = pAstCfg->masterStr;
1146     
1147     TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1149     ACP_MDS_init();
1151     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1152     {
1153         TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1154         return __LINE__;
1155     }
1156     pC->acp = acp;
1158     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1159         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1161     for (z=INPUT1; z < INPUTN; z++) 
1162     {
1163         zS = z;
1164         for (zX = DECODE1; zX < DECODEN; zX++) 
1165         {
1166             if (pP->inputsFromDecodes[zX] == z) 
1167             {
1168                 zS = pP->streamsFromDecodes[zX];
1169                 break;
1170             }
1171         }
1172         acp->fxns->attach(acp, ACP_SERIES_STD,
1173             STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1174             (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1175         /* Ignore errors, not reported. */
1176     }
1178     TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1180     return 0;
1181 } //PAF_ASIT_initPhaseAcpAlg
1183 // -----------------------------------------------------------------------------
1184 // ASIT Initialization Function - Common Memory
1185 //
1186 //   Name:      PAF_ASIT_initPhaseCommon
1187 //   Purpose:   Audio Stream Input Task Function for allocation of common memory.
1188 //   From:      audioStream1Task or equivalent
1189 //   Uses:      See code.
1190 //   States:    x
1191 //   Return:    0 on success.
1192 //              Source code line number on PAF_ALG_alloc failure.
1193 //              Source code line number on PAF_ALG_mallocMemory failure.
1194 //              Source code line number on Decode Chain initialization failure.
1195 //              Source code line number on ASP Chain initialization failure.
1196 //              Source code line number on Encode Chain initialization failure.
1197 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1198 //              * State information as per parent.
1199 //              * Memory allocation errors.
1200 //
1201 Int
1202 PAF_ASIT_initPhaseCommon(
1203     const PAF_ASIT_Params *pP, 
1204     const PAF_ASIT_Patchs *pQ, 
1205     PAF_ASIT_Config *pC
1208     PAF_AST_Config *pAstCfg;
1209     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1210     Int z;                      /* stream counter */
1211     ACP_Handle acp;
1212     PAF_IALG_Config pafAlgConfig;
1213     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1214    
1215     acp = pC->acp;
1216     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1217     as = pAstCfg->as;
1218     
1219     TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1221     //
1222     // Determine memory needs and instantiate algorithms across audio streams
1223     //
1224     TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1225     PAF_ALG_setup(&pafAlgConfig, 
1226         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1227         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1228         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1229         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1230         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1231         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1232         HEAP_CLEAR);
1234     if (pP->fxns->headerPrint)
1235     {
1236         pP->fxns->headerPrint();        
1237     }
1239     for (z = STREAM1; z < STREAMN; z++) 
1240     {
1241         TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1243         //
1244         // Determine common memory for:
1245         //  (1) Logical Input drivers
1246         //
1247         // Decode Algorithms common memory determined in ASP Slave.
1248         //
1249         PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1251         //
1252         // Determine common memory needs of Logical Input driver
1253         //
1255         // really need to loop over all inputs for this stream using the tables
1256         // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1257         // patch, and not needed for FS11, since there is only one input.
1258         if (INPUT1 <= z && z < INPUTN) 
1259         {
1260             TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1261             if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1262             {
1263                 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1264                 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1265                 SW_BREAKPOINT;
1266                 return __LINE__;
1267             }
1268             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1269             if (pP->fxns->allocPrint)
1270             {
1271                 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1272             }
1273         }
1274     }
1275     {
1276         // Changes made to share scratch between zones
1277         // Assume maximum 3 zones and scratch common memory is at offset 0;
1278         int max=0;
1279         for (z=STREAM1; z<STREAMN; z++)
1280         {
1281             if (max < common[z][0].size)
1282             {
1283                 max = common[z][0].size;
1284             }
1285         }
1286         common[STREAM1][0].size=max;
1287         for (z=STREAM1+1; z<STREAMN; z++)
1288         {
1289             common[z][0].size = 0;            
1290         }
1291     }
1292         
1293     //
1294     // Allocate common memory for:
1295     //  (1) Logical Input drivers
1296     //
1297     for (z = STREAM1; z < STREAMN; z++) 
1298     {
1299         TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1300         if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig)) 
1301         {
1302             TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1303             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1304             SW_BREAKPOINT;
1305             return __LINE__;
1306         }
1307         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1308         // share zone0 scratch with all zones 
1309         common[z][0].base = common[0][0].base;
1310         if (pP->fxns->commonPrint)
1311         {
1312             pP->fxns->commonPrint(common[z], &pafAlgConfig);
1313         }
1315         //
1316         // Allocate non-common memories for Logical IO drivers
1317         //    Since these structures are used at run-time we allocate from external memory
1318         if (INPUT1 <= z && z < INPUTN) 
1319         {
1320             PAF_ASP_Chain *chain;
1321             TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1322                            as+z, z);
1323             chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1324                         HEAP_EXTERNAL, as+z, acp, &trace,
1325                         inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1326             if (!chain) 
1327             {
1328                 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1329                 return __LINE__;
1330             }
1331         }
1332     }
1333     TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1335     return 0;
1336 } //PAF_ASIT_initPhaseCommon
1338 // (***) FL: candidate for removal
1339 // -----------------------------------------------------------------------------
1340 // ASIT Initialization Function - Algorithm Keys
1341 //
1342 //   Name:      PAF_ASIT_initPhaseAlgKey
1343 //   Purpose:   Audio Stream Input Task Function for initialization of data values
1344 //              from parameters for Algorithm Keys.
1345 //   From:      audioStream1Task or equivalent
1346 //   Uses:      See code.
1347 //   States:    x
1348 //   Return:    0.
1349 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1350 //              * State information as per parent.
1351 //
1352 // .............................................................................
1353 Int
1354 PAF_ASIT_initPhaseAlgKey(
1355     const PAF_ASIT_Params *pP, 
1356     const PAF_ASIT_Patchs *pQ, 
1357     PAF_ASIT_Config *pC
1360     PAF_AST_Config *pAstCfg;
1361     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1363     
1364     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1365     as = pAstCfg->as;
1366     (void)as;  // clear compiler warning in case not used with tracing disabled
1368     TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1370 #if 0 // FL: slave    
1371     for (z=DECODE1; z < DECODEN; z++) 
1372     {
1373         for (s=0; s < pP->pDecAlgKey->length; s++) 
1374         {
1375             if ((pP->pDecAlgKey->code[s].full != 0) &&
1376                 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s]))) 
1377             {
1378                 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1379                 /* Cast in interface, for now --Kurt */
1380             }
1381             else
1382             {
1383                 pC->xDec[z].decAlg[s] = NULL;
1384             }
1385         }
1386     }
1387 #endif
1389     return 0;
1390 } //PAF_ASIT_initPhaseAlgKey
1392 // -----------------------------------------------------------------------------
1393 // ASIT Initialization Function - I/O Devices
1394 //
1395 //   Name:      PAF_ASIT_initPhaseDevice
1396 //   Purpose:   Audio Stream Input Task Function for initialization of I/O Devices.
1397 //   From:      audioStream1Task or equivalent
1398 //   Uses:      See code.
1399 //   States:    x
1400 //   Return:    0 on success.
1401 //              Source code line number on device allocation failure.
1402 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1403 //              * State information as per parent.
1404 //              * Memory allocation errors.
1405 //
1406 Int
1407 PAF_ASIT_initPhaseDevice(
1408     const PAF_ASIT_Params *pP, 
1409     const PAF_ASIT_Patchs *pQ, 
1410     PAF_ASIT_Config *pC
1413     PAF_AST_Config *pAstCfg;
1414     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1415     Int z;                              /* input/output counter */
1416     PAF_SIO_IALG_Obj    *pObj;
1417     PAF_SIO_IALG_Config *pAlgConfig;
1418     PAF_IALG_Config pafAlgConfig;
1421     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1422     as = pAstCfg->as;
1423     (void)as; // clear compiler warning in case not used with tracing disabled
1425     TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1427     if (pP->fxns->bufMemPrint)
1428     {
1429         PAF_ALG_setup (&pafAlgConfig, 
1430             HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1431             HEAP_ID_INTERNAL1,              HEAP_INTERNAL1,
1432             HEAP_ID_EXTERNAL,               HEAP_EXTERNAL,
1433             HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM,
1434             HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM,
1435             HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1436             HEAP_CLEAR);
1437         TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1438     }
1440     for (z=INPUT1; z < INPUTN; z++) 
1441     {
1442         PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1444         pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1445         pAlgConfig = &pObj->config;
1447         pAstCfg->xInp[z].hRxSio = NULL;
1449         pConfig->base.pVoid       = pAlgConfig->pMemRec[0].base;
1450         pConfig->pntr.pVoid       = pAlgConfig->pMemRec[0].base;
1451         pConfig->head.pVoid       = pAlgConfig->pMemRec[0].base;
1452         pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1453         pConfig->allocation       = pAlgConfig->pMemRec[0].size;
1454         pConfig->sizeofElement    = 2;
1455         pConfig->precision        = 16;
1457         if (pP->fxns->bufMemPrint)
1458         {
1459             pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1460         }
1461     }
1463     TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1465     return 0;
1466 } //PAF_ASIT_initPhaseDevice
1468 // -----------------------------------------------------------------------------
1469 // ASIT Initialization Function - Decoder Output Circular Buffer
1470 //
1471 //   Name:      PAF_ASIT_initPhaseDecOpCircBuf
1472 //   Purpose:   Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1473 //   From:      audioStream1Task or equivalent
1474 //   Uses:      See code.
1475 //   States:    x
1476 //   Return:    0 on success.
1477 //              Source code line number on device allocation failure.
1478 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1479 //              * State information as per parent.
1480 //              * Memory allocation errors.
1481 //
1482 Int
1483 PAF_ASIT_initPhaseDecOpCircBuf(
1484     const PAF_ASIT_Params *pP, 
1485     const PAF_ASIT_Patchs *pQ, 
1486     PAF_ASIT_Config *pC
1489     PAF_AST_Config *pAstCfg;
1490     PAF_AST_DecOpCircBuf *pCb;          /* Decoder output circular buffer */
1491     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1492     Int zMS;
1493     Int z;                              /* decode counter */
1494     Int errno;                          /* error number */
1495     Error_Block    eb;
1496     Int i;
1498     // FL: (***)revisit
1499     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1500     as = pAstCfg->as;
1501     zMS = pAstCfg->masterStr;
1503     /* Decode output circular buffer memory */
1504     if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
1505         DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1506     {
1507         TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1508         SW_BREAKPOINT;
1509         return __LINE__;
1510     }
1512     TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1513         DECODEN * sizeof (*pAstCfg->xDecOpCb),
1514         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1515         
1516     for (z=DECODE1; z < DECODEN; z++)
1517     {
1518         pCb = &pAstCfg->xDecOpCb[z];
1519         
1520         // allocate audio frame circular buffer
1521         if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1522         {
1523             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1524             SW_BREAKPOINT;
1525         }
1526         // allocate audio frame PCM sample pointer array
1527         for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1528         {
1529             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)))
1530             {
1531                 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1532                 SW_BREAKPOINT;
1533             }
1534             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)))
1535             {
1536                 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1537                 SW_BREAKPOINT;
1538             }                
1539         }
1540         // allocate PCM sample buffer
1541         if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1542         {
1543             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1544             SW_BREAKPOINT;
1545         }
1546         pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1547         // allocate Metadata buffers //QIN
1548         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)))
1549         {
1550             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1551             SW_BREAKPOINT;
1552         }
1553         pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1554         // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length        
1555         // Initialize decoder output circular buffer for PCM
1556         errno = cbInit(pCb);
1557         if (errno)
1558         {
1559             SW_BREAKPOINT; // FL: debug
1560             return errno;
1561         }
1562     }
1564     return 0;
1565 } //PAF_ASIT_initPhaseDecOpCircBuf
1568 #if 0
1569 // -----------------------------------------------------------------------------
1570 // AST Processing Function - Pass-Through Processing
1571 //
1572 //   Name:      PAF_AST_passProcessing
1573 //   Purpose:   Audio Stream Task Function for processing audio data as a
1574 //              pass-through from the input driver to the output driver
1575 //              for development and testing.
1576 //   From:      audioStream1Task or equivalent
1577 //   Uses:      See code.
1578 //   States:    x
1579 //   Return:    Error number in standard form (0 on success).
1580 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1581 //              * State information on initialization.
1582 //              * State information on processing.
1583 //
1585 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1586 /* Pass Processing is often omitted from builds to save memory, */
1587 /* and CODE_SECTION/clink constructs facilitate this omission.  */
1589 Int
1590 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1592     Int z;                              /* input/output counter */
1593     Int errno = 0;                      /* error number */
1594     Int getVal;
1595     Int rxNumChan, txNumChan;
1596     Int first;
1597     Int zMD = pC->masterDec;
1598     Int zMI = pP->zone.master;
1601 #ifndef __TI_EABI__
1602     asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1603 #endif    
1605     TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1607     //
1608     // Determine that receive/transmit channels are compatible
1609     //
1611     // Can handle handle only master input
1612     for (z=INPUT1; z < INPUTN; z++) {
1613         if (z != zMI && pC->xInp[z].hRxSio)
1614             return (ASPERR_PASS + 0x01);
1615     }
1617     /* Number of receive/transmit channels */
1619     if (! pC->xInp[zMI].hRxSio)
1620         return (ASPERR_PASS + 0x11);
1621     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1622         return (ASPERR_PASS + 0x12);
1623     if (rxNumChan > NUM_TX_CHAN(zMI))
1624         return (ASPERR_PASS + 0x13);
1626     for (z=OUTPUT1; z < OUTPUTN; z++) {
1627         if (! pC->xOut[zMI].hTxSio)
1628             return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1629         if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1630             return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1631         if (txNumChan > NUM_TX_CHAN(zMI))
1632             return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1633     }
1635     //
1636     // Set up receive/transmit
1637     //
1639     SIO_idle (pC->xInp[zMI].hRxSio);
1640     for (z=OUTPUT1; z < OUTPUTN; z++) {
1641         if(SIO_idle (pC->xOut[z].hTxSio))
1642             return ASPERR_IDLE;
1643     }
1645     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1646         return (ASPERR_PASS + 0x14);
1648     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1649         return (ASPERR_PASS + 0x15);
1651     for (z=OUTPUT1; z < OUTPUTN; z++)
1652         pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1654     if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1655         return ASPERR_PASS + 0x16;
1657     if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1658         return ASPERR_PASS + 0x17;
1660     //
1661     // Receive and transmit the data in single-frame buffers
1662     //
1664     first = 1;
1665     while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1666         PAF_OutBufConfig *pOutBuf;
1667         PAF_InpBufConfig *pInpBuf;
1669         if (first) {
1670             first = 0;
1672             TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1674             for (z=OUTPUT1; z < OUTPUTN; z++) {
1675                 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1676                 if (getVal > 0) {
1677                     errno = ASPERR_ISSUE;
1678                     break;
1679                 }
1680                 else if (getVal < 0) {
1681                     errno = -getVal;
1682                     break;
1683                 }
1685                 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1686                     return (getVal & 0xff) | ASPERR_MUTE;
1687             }
1688             if (errno)
1689                 break;
1691         }
1693         getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1694         if (getVal > 0) {
1695             errno = ASPERR_ISSUE;
1696             break;
1697         }
1699         TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1701         getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1702         if (getVal < 0) {
1703             errno = -getVal;
1704             break;
1705         }
1707         for (z=OUTPUT1; z < OUTPUTN; z++) {
1708             getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1709             if (getVal < 0) {
1710                 errno = -getVal;
1711                 break;
1712             }
1713         }
1714         if( errno )
1715             break;
1717         TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1719         if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1720             break;
1722         for (z=OUTPUT1; z < OUTPUTN; z++) {
1723             getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1724             if (getVal > 0) {
1725                 errno = ASPERR_ISSUE;
1726                 break;
1727             }
1728             else if (getVal < 0) {
1729                 errno = -getVal;
1730                 break;
1731             }
1732         }
1733         if( errno )
1734             break;
1735     }
1737     //
1738     // Close down receive/transmit
1739     //
1741     TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1743     for (z=OUTPUT1; z < OUTPUTN; z++) {
1744         if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1745             if (! errno)
1746                 errno = (getVal & 0xff) | ASPERR_MUTE;
1747             /* convert to sensical errno */
1748         }
1749     }
1751     SIO_idle (pC->xInp[zMI].hRxSio);
1752     for (z=OUTPUT1; z < OUTPUTN; z++)
1753         SIO_idle (pC->xOut[z].hTxSio);
1755     return errno;
1757 } //PAF_AST_passProcessing
1758 #endif // #if 0
1760 #if 0
1761 // -----------------------------------------------------------------------------
1762 // AST Processing Function Helper - Pass-Through Processing Patch Point
1763 //
1764 //   Name:      PAF_AST_passProcessingCopy
1765 //   Purpose:   Pass-Through Processing Function for copying audio data
1766 //              from the input buffer to the output buffer.
1767 //   From:      AST Parameter Function -> passProcessing
1768 //   Uses:      See code.
1769 //   States:    x
1770 //   Return:    Error number in standard form (0 on success).
1771 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1772 //              x
1773 //
1775 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1776 /* Pass Processing is often omitted from builds to save memory, */
1777 /* and CODE_SECTION/clink constructs facilitate this omission.  */
1779 Int
1780 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1782     Int z;                              /* output counter */
1783     Int errno;                          /* error number */
1784     Int i;
1785     Int rxNumChan, txNumChan;
1786     Int zMI = pP->zone.master;
1789     asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1791     // Copy data from input channels to output channels one of two ways:
1793     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1794         return (ASPERR_PASS + 0x12);
1796     for (z=OUTPUT1; z < OUTPUTN; z++) {
1797         if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1798             return (ASPERR_PASS + 0x22);
1800         if( txNumChan <= rxNumChan ) {
1802             // Copy one to one, ignoring later rx channels as needed.
1804             for( i=0; i < txNumChan; i++ ) {
1805                 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1806                 if( errno )
1807                     return errno;
1808             }
1809         }
1810         else {
1812             // Copy one to many, repeating earlier rx channels as needed.
1814             Int from, to;
1816             from = 0;
1817             to   = 0;
1818             while( to < txNumChan ) {
1819                 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1820                 if( errno )
1821                     return errno;
1823                 from++;
1824                 to++;
1825                 if( from == rxNumChan )
1826                     from = 0;
1827             }
1828         }
1829     }
1831     return 0;
1832 } //PAF_AST_passProcessingCopy
1833 #endif // #if 0
1835 // -----------------------------------------------------------------------------
1836 // ASIT Processing Function - Auto Processing
1837 //
1838 //   Name:      PAF_ASIT_autoProcessing
1839 //   Purpose:   Audio Stream Input Task Function for processing audio data to
1840 //              determine the input type without output.
1841 //   From:      audioStream1Task or equivalent
1842 //   Uses:      See code.
1843 //   States:    x
1844 //   Return:    Error number in standard or SIO form (0 on success).
1845 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1846 //              * State information on initialization.
1847 //
1849 #define DECSIOMAP(X)                                                \
1850     pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1852 Int
1853 PAF_ASIT_autoProcessing(
1854     const PAF_ASIT_Params *pP, 
1855     const PAF_ASIT_Patchs *pQ, 
1856     PAF_ASIT_Config *pC, 
1857     Int inputTypeSelect, 
1858     ALG_Handle pcmAlgMaster
1861     PAF_AST_Config *pAstCfg;
1862     Int as;                 /* Audio Stream Number (1, 2, etc.) */
1863     Int errno = 0;          /* error number */
1864     Int nbytes;
1865     Int frameLength;
1866     Int zMD;
1867     Int zMI;
1868     Int zMS;
1869     
1870     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1871     as = pAstCfg->as;
1872     zMD = pAstCfg->masterDec;
1873     zMS = pAstCfg->masterStr;    
1874     zMI = pP->zone.master;    
1875     
1876     TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1878     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1879                          PAF_SIO_CONTROL_SET_SOURCESELECT,
1880                          DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1881     {
1882         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1883         return errno;
1884     }
1885     //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1886     //                                            pC->xDec[zMD].decodeStatus.bufferRatio);
1887     frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1889     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1890                          PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1891     {
1892         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1893             errno, ASPERR_AUTO_LENGTH);
1894         return ASPERR_AUTO_LENGTH;
1895     }
1897     if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1898                           &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1899                           PAF_SIO_REQUEST_SYNC))
1900     {
1901         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1902             errno, ASPERR_ISSUE);
1903         return ASPERR_ISSUE;
1904     }
1906     TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1908     // all of the sync scan work is done in this call. If the error returned
1909     // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1910     // error so we mask it off.
1911     nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1912     if (nbytes == -DIBERR_SYNC)
1913     {
1914         TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1915         return 0;
1916     }
1917     if (nbytes != sizeof(PAF_InpBufConfig))
1918     {
1919         TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1920             nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1921         return ASPERR_RECLAIM;
1922     }
1923     if (errno)
1924     {
1925         TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1926     }
1927     return errno;
1928 } //PAF_ASIT_autoProcessing
1930 UInt32 gProbe1Err=0;
1931 UInt32 gProbe2Err=0;
1932 UInt32 gMajorAuMissed=0;
1934 // -----------------------------------------------------------------------------
1935 // ASIT Processing Function - Decode Processing
1936 //
1937 //   Name:      PAF_ASIT_decodeProcessing
1938 //   Purpose:   Audio Stream Input Task Function for processing audio data.
1939 //   From:      audioStream1Task or equivalent
1940 //   Uses:      See code.
1941 //   States:    x
1942 //   Return:    Error number in standard form (0 on success).
1943 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1944 //              * State information on initialization (via children).
1945 //              * State information on processing (via children).
1946 //              * Decode warnings.
1947 //
1948 // When "writeDECModeContinuous" is used for zMI input/decode:
1949 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1950 // (a) if "writeDECCommandRestart" is used
1951 //    (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1952 // (b) if "writeDECSourceSelectNone" is used
1953 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1954 // (c) if an error occurs in
1955 //     INIT
1956 //     CONT ("subsequent block state", which "Establish[es] secondary timing")
1957 //         -> PAF_AST_decodeCont(): "Await slave inputs"
1958 //     STREAM (errno |= PAF_COMPONENT_ASP)
1959 //     ENCODE (errno |= PAF_COMPONENT_ENCODE)
1960 // [ the latter errors lead to "switch_break:"
1961 //         -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1962 //
1963 // [ Notably, in FINAL ("frame-finalization state")
1964 //         -> PAF_AST_decodeFinalTest() is *not* called,
1965 //   and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1966 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1967 //
1968 // States in which error can't occur:
1969 //     AGAIN ("subsequent initial state")
1970 //
1971 // States in which (some) errors must be handled:
1972 //     INFO1 ("first frame state")
1973 //         -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1974 //            -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1975 //               ?*? but what about ASPERR_RESYNC from same call ?*?
1976 //            -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1977 //            -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1978 //         -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1979 //            - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1980 //            - enc->fxns->info()
1981 //            - pP->fxns->setCheckRateX()
1982 //            - pP->fxns->startOutput()
1983 //            - "Start slave inputs if necessary"
1984 //     INFO2 ("subsequent frame state")
1985 //         -> PAF_AST_decodeInfo(): (see above)
1986 //         -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1987 //            - pP->fxns->setCheckRateX()
1988 //     TIME ("timing state")
1989 //         -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1990 //         -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1991 //         -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1992 //            (*OK* don't try to recover from this*)
1993 //         -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1994 //         -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1995 //            possibly in PAF_AST_decodeProcessing() itself **
1996 //     DECODE ("decode state")
1997 //         -> PAF_AST_decodeDecode(): pass on error from
1998 //            - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1999 //            - dec->fxns->reset()
2000 //            - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
2001 //         -> *DONE* must catch error from (zMI) dec->fxns->decode()
2002 //         -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
2003 Int
2004 PAF_ASIT_decodeProcessing(
2005     const PAF_ASIT_Params *pP, 
2006     const PAF_ASIT_Patchs *pQ, 
2007     PAF_ASIT_Config *pC, 
2008     Int sourceSelect
2011     PAF_AST_Config *pAstCfg;
2012     //Int as = pC->as;                    /* Audio Stream Number (1, 2, etc.) */
2013     Int z;                              /* decode counter */
2014     Int errno;                          /* error number */
2015     Int getVal;
2016     enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
2017     ALG_Handle alg[DECODEN_MAX];
2018     Int zMD;
2019     Int zMS;
2020     Int size;
2021     //PAF_InpBufConfig *pIpBufConfig;
2022     Int frame; // decoder input frame count
2023     Int block; // (***) FL: formerly  -- decoder output block count / input frame
2024 #ifdef NON_CACHE_STATUS
2025     Int8 tempVar8, temp2Var8;
2026 #endif
2027     
2028     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2029     zMD = pAstCfg->masterDec;
2030     zMS = pAstCfg->masterStr;
2031         
2032     for (z=DECODE1; z < DECODEN; z++)
2033     {
2034         alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];        
2035     }
2036     alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
2038     //
2039     // Receive and process the data in single-frame buffers
2040     //
2042     state = INIT;
2043     errno = 0; /* error number */
2045 #ifdef NON_CACHE_STATUS
2046     statusOp_read(&tempVar8,
2047                   &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2048                   sizeof(tempVar8),
2049                   GATEMP_INDEX_DEC);
2050     TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
2052     for (;;) 
2053     {
2054         if (tempVar8 == PAF_SOURCE_NONE)
2055         {
2056 #else
2057     TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
2059     for (;;)
2060     {
2061         if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
2062         {
2063 #endif
2064             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
2065             state = QUIT;
2066         }
2068         // Process commands (decode)
2069         if (getVal = pP->fxns->decodeCommand(pP, pQ, pC)) 
2070         {
2071             if (state != INIT)   // no need to restart/abort if not yet started
2072             {
2073                 if (getVal == ASPERR_QUIT)
2074                 {
2075                     state = QUIT;
2076                     TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
2077                 }
2078                 else if (getVal == ASPERR_ABORT)
2079                 {
2080                     TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
2081                     return getVal;
2082                 }
2083                 else
2084                 {
2085                     /* ignore */;
2086                 }
2087             }
2088             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
2089         }
2091         TRACE_TIME((&TIME_MOD,         "... + %d = %d ->", dtime(), TSK_time()));
2092         TRACE_TIME((&TIME_MOD,         "                 state = %s", stateName[state]));
2094         // Process state (decode)
2095         switch (state) 
2096         {
2097             case INIT: // initial state
2098                 gAsipInitCnt++;
2099                 Log_info0("TaskAsip: state=INIT");
2101                 // (***) FL: revisit
2102 #if 1 // status for shared beta units can change (e.g. at-boot or alpha)
2103                 // write back Status structures for shared Beta Units
2104                 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2105                 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2106                 /*size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2107                 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2108                 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2109                 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2110                 Cache_wait();*/
2111 #endif
2112 #if 0
2113                 ////size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2114                 ////Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2115                 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2116                 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2117                 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2118                 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2119                 //Cache_wait();                
2120 #endif                
2121                 
2122                 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
2123                 {
2124                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x.  break after decodeInit", errno);
2125                     break;
2126                 }
2127                 
2128 #if 1
2129                 // (***) FL: revisit
2130                 // invalidate Status structures for shared Beta Units
2131                 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2132                 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2133                /* size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2134                 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2135                 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2136                 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2137                 Cache_wait();*/
2138 #endif
2139                 
2140                 frame = 0;
2141                 block = 0;
2143                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2144                 state = INFO1;
2145                 continue;
2147             case INFO1: // first frame state
2148                 gAsipInfo1Cnt++;
2149                 Log_info0("TaskAsip: state=INFO1");
2150                 
2151 #if 0
2152                 //// (***) FL: revisit
2153                 //// write back Inp configuration
2154                 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2155                 //// write back input data
2156                 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2157                 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2158                 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2159                 //// write back Dec configuration
2160                 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2161                 //Cache_wait();            
2162 #endif                
2164                 // Establish primary timing
2165                 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2166                 {
2167                     gProbe1Err++;
2168                     TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2169                     break;
2170                 }
2171                 
2172 #if 0
2173                 //// (***) FL: revisit
2174                 //// invalidate Dec configuration
2175                 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2176                 //Cache_wait();                            
2177 #endif                
2180 #ifdef NON_CACHE_STATUS
2181                 statusOp_read(&tempVar8,
2182                               &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2183                               sizeof(tempVar8),
2184                               GATEMP_INDEX_DEC);
2185                 statusOp_read(&temp2Var8,
2186                               &(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
2187                               sizeof(tempVar8),
2188                               GATEMP_INDEX_DEC);
2189                 // Don't start decode until major access unit is found.
2190                 if (((tempVar8 == PAF_SOURCE_THD)    ||
2191                      (tempVar8 == PAF_SOURCE_DXP)    ||
2192                      (tempVar8 == PAF_SOURCE_DTSHD)) &&
2193                      (temp2Var8 == PAF_SAMPLERATE_UNKNOWN)) 
2194 #else
2195                 // Don't start decode until major access unit is found.
2196                 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD)    ||
2197                      (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP)    ||
2198                      (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2199                      (pAstCfg->xDec[zMD].decodeStatus.sampleRate == PAF_SAMPLERATE_UNKNOWN))
2200 #endif
2201                 {
2202                     Int z;
2203                     for (z=DECODE1; z < DECODEN; z++) 
2204                     {
2205                         Int zI = pP->inputsFromDecodes[z];
2206 #ifdef NON_CACHE_STATUS
2207                         statusOp_read(&tempVar8,
2208                                       &(pAstCfg->xDec[z].decodeStatus.mode),
2209                                       sizeof(tempVar8),
2210                                       GATEMP_INDEX_DEC);
2211                         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2212                         {
2213 #else
2214                         if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2215                         {
2216 #endif
2217                             TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2218                             if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2219                                 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2220                             {
2221                                 gProbe2Err++;
2222                                 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2223                                 return (ASPERR_ISSUE);
2224                             }
2225                         }
2226                     }
2227                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2228                     gMajorAuMissed++; // debug
2229                     frame++;
2230                     state = INFO1;
2231                     continue;
2232                 }
2233                 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2235                 // Establish secondary timing
2236                 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2237                 {
2238                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x.  break after decodeInfo1", errno);
2239                     break;
2240                 }
2242                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2243                 state = DECODE;
2244                 continue;
2246             case INFO2: // subsequent frame state
2247                 gAsipInfo2Cnt++;
2248                 Log_info0("TaskAsip: state=INFO2");
2250 #if 0            
2251                 //// (***) FL: revisit
2252                 //// write back Inp configuration
2253                 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2254                 //// write back input data
2255                 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2256                 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2257                 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2258                 //// write back Dec configuration
2259                 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2260                 //Cache_wait();
2261 #endif                
2263                 // Establish primary timing
2264                 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2265                 {
2266                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2267                     gAsipInfo2_PrimaryErrCnt++;
2268                     break;
2269                 }
2271 #if 0            
2272                 //// (***) FL: revisit
2273                 //// invalidate Dec configuration
2274                 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2275                 //Cache_wait();                                            
2276 #endif                
2277                 
2278                 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2279                 {
2280                     TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2281                     gAsipInfo2_ErrCnt++;
2282                     break;
2283                 }
2285                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2286                 state = DECODE;
2287                 continue;
2289             case DECODE: // decode state
2290                 gAsipDecodeCnt++;
2291                 Log_info0("TaskAsip: state=DECODE");
2293 #if 0
2294                 //// (***) FL: revisit
2295                 //// write back Dec configuration
2296                 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2297                 //Cache_wait();                        
2298 #endif
2299             
2300                 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2301                 {
2302                     gAsipDecodeErrCnt++;
2303                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
2304                     break;
2305                 }
2306       
2307 #if 0      
2308                 //// (***) FL: revisit
2309                 //// invalidate Dec configuration
2310                 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2311                 //Cache_wait();                                            
2312 #endif                
2313                 
2314                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2315                 state = FINAL;
2316                 continue;
2318             case FINAL: // frame-finalization state
2319                 gAsipFinalCnt++;
2320                 Log_info0("TaskAsip: state=FINAL");
2322                 // Check for final frame, and if indicated:
2323                 // - Exit state machine to "complete" processing.
2324                 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block)) 
2325                 {
2326                     break;
2327                 }
2329                 frame++;
2330                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2331                 state = INFO2;
2332                 continue;
2334             case QUIT: // exit state
2335                 gAsipQuitCnt++;
2336                 Log_info0("TaskAsip: state=QUIT");
2338                 // Quit:
2339                 // - Set error number registers.
2340                 // - Exit state machine to "decode complete" processing.
2341                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2342                 errno = ASPERR_QUIT;
2343                 break;
2345             default: // unknown state
2347                 // Unknown:
2348                 // - Set error number registers.
2349                 // - Exit state machine to "decode complete" processing.
2351                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2352                 errno = ASPERR_UNKNOWNSTATE;
2353                 break;
2355         }  // End of switch (state).
2357         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2358         if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2359         {
2360             /* ignored? */;
2361         }
2363         TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2365         return errno;
2366     }  // End of for (;;) to Receive, process, and transmit the data.
2367 } //PAF_ASIT_decodeProcessing
2369 // -----------------------------------------------------------------------------
2370 // ASIT Decoding Function - Decode Command Processing
2371 //
2372 //   Name:      PAF_ASIT_decodeCommand
2373 //   Purpose:   Decoding Function for processing Decode Commands.
2374 //   From:      AST Parameter Function -> decodeProcessing
2375 //   Uses:      See code.
2376 //   States:    x
2377 //   Return:    Error number in standard form (0 on success).
2378 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2379 //              * Command execution.
2380 //
2382 Int
2383 PAF_ASIT_decodeCommand(
2384     const PAF_ASIT_Params *pP, 
2385     const PAF_ASIT_Patchs *pQ, 
2386     PAF_ASIT_Config *pC
2389     PAF_AST_Config *pAstCfg;
2390     Int as;                 /* Audio Stream Number (1, 2, etc.) */
2391     Int z;                  /* decode counter */
2392     Int zS;
2393 #ifdef NON_CACHE_STATUS
2394     Int8 tempVar8;
2395 #endif
2397     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2398     as = pAstCfg->as;
2400     for (z=DECODE1; z < DECODEN; z++) 
2401     {
2402         zS = pP->streamsFromDecodes[z];
2403 #ifdef NON_CACHE_STATUS
2404         statusOp_read(&tempVar8,
2405                       &(pAstCfg->xDec[z].decodeStatus.command2),
2406                       sizeof(tempVar8),
2407                       GATEMP_INDEX_DEC);
2408         if (!(tempVar8 & 0x80))
2409         {
2410             switch (tempVar8)
2411             {
2412                 case 0: // command none - process
2413                     tempVar8 |= 0x80;
2414                     statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2415                                    &tempVar8,
2416                                    sizeof(tempVar8),
2417                                    GATEMP_INDEX_DEC);
2418                     break;
2419                 case 1: // command abort - leave now
2420                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2421                     tempVar8 |= 0x80;
2422                     statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2423                                    &tempVar8,
2424                                    sizeof(tempVar8),
2425                                    GATEMP_INDEX_DEC);
2426                     return (ASPERR_ABORT);
2427                 case 2: // command restart - leave later
2428                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2429                     tempVar8 |= 0x80;
2430                     statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2431                                    &tempVar8,
2432                                    sizeof(tempVar8),
2433                                    GATEMP_INDEX_DEC);
2434                     return (ASPERR_QUIT);
2435                 default: // command unknown - ignore
2436                     break;
2437             }
2438         }
2439 #else
2440         if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2441         {
2442             switch (pAstCfg->xDec[z].decodeStatus.command2)
2443             {
2444                 case 0: // command none - process
2445                     pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2446                     break;
2447                 case 1: // command abort - leave now
2448                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2449                     pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2450                     return (ASPERR_ABORT);
2451                 case 2: // command restart - leave later
2452                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2453                     pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2454                     return (ASPERR_QUIT);
2455                 default: // command unknown - ignore
2456                     break;
2457             }
2458         }
2459 #endif
2460     }
2462     return 0;
2463 } //PAF_ASIT_decodeCommand
2465 // -----------------------------------------------------------------------------
2466 // ASIT Decoding Function - Reinitialization of Decode
2467 //
2468 //   Name:      PAF_ASIT_decodeInit
2469 //   Purpose:   Decoding Function for reinitializing the decoding process.
2470 //   From:      AST Parameter Function -> decodeProcessing
2471 //   Uses:      See code.
2472 //   States:    x
2473 //   Return:    Error number in standard or SIO form (0 on success).
2474 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2475 //              * State information as per parent.
2476 //
2477 Int
2478 PAF_ASIT_decodeInit(
2479     const PAF_ASIT_Params *pP, 
2480     const PAF_ASIT_Patchs *pQ, 
2481     PAF_ASIT_Config *pC, 
2482     Int sourceSelect
2485     PAF_AST_Config *pAstCfg;
2486     PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
2487     Int as;                             /* Audio Stream Number (1, 2, etc.) */
2488     Int z;                              /* decode/encode counter */
2489     Int errno;                          /* error number */
2490     Int zI, zS;
2491     Int zMD;
2492     Int zMI;
2493     ASP_Msg* pAspMsg;                   /* Messaging */
2494     Int argIdx;
2495     Int decErrno;
2496     Int status;
2497 #ifdef NON_CACHE_STATUS
2498     Int8 tempVar8;
2499 #endif
2500     
2501     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2502     as = pAstCfg->as;
2503     zMD = pAstCfg->masterDec;
2504     zMI = pP->zone.master;
2505     (void)as;  // clear compiler warning in case not used with tracing disabled
2506     
2507     pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2509 #ifdef NON_CACHE_STATUS
2510     // reset frameCount
2511     for (z=DECODE1; z < DECODEN; z++)
2512     {
2513         statusOp_read(&tempVar8,
2514                       &(pAstCfg->xDec[z].decodeStatus.mode),
2515                       sizeof(tempVar8),
2516                       GATEMP_INDEX_DEC);
2517         if (tempVar8)
2518         {
2519             tempVar8 = 0;
2520             statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2521                           &tempVar8,
2522                           sizeof(tempVar8),
2523                           GATEMP_INDEX_DEC);
2524         }
2525     }
2527     for (z=DECODE1; z < DECODEN; z++) 
2528     {
2529         zI = pP->inputsFromDecodes[z];
2530         zS = pP->streamsFromDecodes[z];
2531         (void)zS; // clear compiler warning in case not used with tracing disabled
2532         statusOp_read(&tempVar8,
2533                       &(pAstCfg->xDec[z].decodeStatus.mode),
2534                       sizeof(tempVar8),
2535                       GATEMP_INDEX_DEC);
2536         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2537         {
2538 #else
2539     // reset frameCount
2540     for (z=DECODE1; z < DECODEN; z++)
2541     {
2542         if (pAstCfg->xDec[z].decodeStatus.mode)
2543         {
2544             pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2545         }
2546     }
2548     for (z=DECODE1; z < DECODEN; z++)
2549     {
2550         zI = pP->inputsFromDecodes[z];
2551         zS = pP->streamsFromDecodes[z];
2552         (void)zS; // clear compiler warning in case not used with tracing disabled
2553         if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2554         {
2555 #endif
2556             Uns gear;
2557             Int frameLength;
2558             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2560             // write back Dec configuration
2561             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2562             Cache_wait();
2563             
2564             // FL: send dec activate message to slave
2565             pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);  /* allocate message */
2566             if (pAspMsg == NULL)
2567             {
2568                 TRACE_TERSE0("MessageQ_alloc() failure.");
2569                 SW_BREAKPOINT; // temporary
2570                 return -1; // temporary
2571             }
2572             MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
2573             pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE;                                              /* fill in message payload */
2574             pAspMsg->procId = hAspMsgMaster->masterProcId;
2575             pAspMsg->expectResp = TRUE;
2576             pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2577             argIdx = 0; // set decIdx (zone index)
2578             *(Int32 *)&pAspMsg->buf[argIdx] = z;
2579             TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2580             TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2581             status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);                       /* send message */
2582             if (status != MessageQ_S_SUCCESS)
2583             {
2584                 SW_BREAKPOINT;
2585             }
2586             // wait for dec activate complete message from slave
2587             status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2588             if (status != MessageQ_S_SUCCESS)
2589             {
2590                 TRACE_TERSE0("MessageQ_get() failure.");
2591                 SW_BREAKPOINT; // temporary
2592                 return -1; // temporary
2593             }
2594             if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) || 
2595                 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2596                 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2597             {
2598                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2599                 SW_BREAKPOINT; // temporary
2600                 return -1; // temporary
2601             }      
2602             hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2603             TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2604             // free the message
2605             status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2606             if (status != MessageQ_S_SUCCESS)
2607             {
2608                 SW_BREAKPOINT;
2609             }
2610             
2611 #if 0 // FL: decoder activate call, slave
2612             if (decAlg[z]->fxns->algActivate)
2613                 decAlg[z]->fxns->algActivate (decAlg[z]);
2614 #endif
2616             // FL: send dec reset message to slave
2617             pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);  /* allocate message */
2618             if (pAspMsg == NULL)
2619             {
2620                 TRACE_TERSE0("MessageQ_alloc() failure.");
2621                 SW_BREAKPOINT; // temporary
2622                 return -1; // temporary
2623             }
2624             MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
2625             pAspMsg->cmd = ASP_SLAVE_DEC_RESET;                                                 /* fill in message payload */
2626             pAspMsg->procId = hAspMsgMaster->masterProcId;
2627             pAspMsg->expectResp = TRUE;
2628             pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2629             argIdx = 0; // set decIdx
2630             *(Int32 *)&pAspMsg->buf[argIdx] = z;
2631             TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2632             TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2633             // wait for dec reset complete message from slave
2634             status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
2635             if (status != MessageQ_S_SUCCESS)
2636             {
2637                 SW_BREAKPOINT;
2638             }
2639             status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2640             if (status != MessageQ_S_SUCCESS)
2641             {
2642                 TRACE_TERSE0("MessageQ_get() failure.");
2643                 SW_BREAKPOINT; // temporary
2644                 return -1; // temporary
2645             }
2646             if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2647                 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) && 
2648                 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2649             {
2650                 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2651                 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2652                 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2654                 argIdx = 0; // get decErrno
2655                 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2656                 if (decErrno != 0)
2657                 {
2658                     return decErrno;
2659                 }
2660             }
2661             else
2662             {
2663                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2664                 SW_BREAKPOINT; // temporary
2665                 return -1; // temporary
2666             }
2667             // free the message
2668             status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2669             if (status != MessageQ_S_SUCCESS)
2670             {
2671                 SW_BREAKPOINT;
2672             }
2674             // (***) FL: revisit
2675             // invalidate Dec configuration
2676             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2677             Cache_wait();                            
2678             
2679 #if 0 // FL: decoder reset call, slave
2680             if (dec->fxns->reset
2681                 && (errno = dec->fxns->reset (dec, NULL,
2682                                               &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2683                 return errno;
2684 #endif
2685             
2686 #ifdef NON_CACHE_STATUS
2687             gear = 0;  // due to size difference
2688             statusOp_read(&gear,
2689                           &(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2690                           sizeof(Int8),
2691                           GATEMP_INDEX_DEC);
2692             tempVar8 = gear < GEARS ? gear : 0;
2693             statusOp_write(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2694                            &tempVar8,
2695                            sizeof(tempVar8),
2696                            GATEMP_INDEX_DEC);
2697 #else
2698             gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2699             pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2700 #endif
2701             
2702 #if 0 // FL: change handle to decIdx (zone index)
2703             frameLength = pP->fxns->computeFrameLength(decAlg[z], 
2704                 FRAMELENGTH,
2705                 pC->xDec[z].decodeStatus.bufferRatio);
2706 #endif
2707 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2708             frameLength = pP->fxns->computeFrameLength(z, 
2709                 FRAMELENGTH, 
2710                 pC->xDec[z].decodeStatus.bufferRatio);
2711 #else
2712             if (sourceSelect == PAF_SOURCE_PCM)
2713             {
2714                 frameLength = 256;
2715             }
2716             else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2717             {
2718                 frameLength = 1536;
2719             }
2720             else if (sourceSelect == PAF_SOURCE_THD)
2721             {
2722                 frameLength = 1536; //QIN FIX ME
2723             }
2724             else
2725             {
2726                 frameLength = 256;
2727             }
2728 #endif    
2729             
2730             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2731             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2732             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2733             
2734             // (***) FL: revisit. Count samples for DDP.
2735             // Add framework frame length and running sample count to decoder control.
2736             //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2737             //pC->xDec[z].decodeControl.rdSampleCount = 0;
2739             // Initialize decoder output circular buffer for selected source
2740             errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2741             if (errno)
2742             {
2743                 SW_BREAKPOINT; // FL: debug
2744                 return errno;
2745             }
2746             // FL: debug
2747             cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2748             
2749             if (z != zMD) 
2750             {
2751                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2752                 {
2753                     return errno;
2754                 }
2755             }
2757 #ifdef NON_CACHE_STATUS
2758             statusOp_read(&tempVar8,
2759                           &(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2760                           sizeof(Int8),
2761                           GATEMP_INDEX_DEC);
2762             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2763                 DECSIOMAP(tempVar8)))
2764             {
2765                 return errno;
2766             }
2767 #else
2768             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2769                 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2770             {
2771                 return errno;
2772             }
2773 #endif
2774             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, 
2775                 frameLength))
2776             {
2777                 return errno;
2778             }
2779             if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus, 
2780                 &pAstCfg->xInp[zI].inpBufConfig))
2781             {
2782                 return errno;
2783             }
2784         }
2785     }
2787     if (pAstCfg->xInp[zMI].hRxSio) 
2788     {
2789         errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2790             sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2791         if (errno)
2792         {
2793             return errno;
2794         }
2795     }
2797     return 0;
2798 } //PAF_AST_decodeInit
2800 // -----------------------------------------------------------------------------
2801 // ASIT Decoding Function - Info Processing, Common
2802 //
2803 //   Name:      PAF_ASIT_decodeInfo
2804 //   Purpose:   Decoding Function for processing information in a manner that
2805 //              is common for both initial and subsequent frames of input data.
2806 //   From:      AST Parameter Function -> decodeProcessing
2807 //   Uses:      See code.
2808 //   States:    x
2809 //   Return:    Error number in standard form (0 on success).
2810 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2811 //              * State information as per parent.
2812 //
2813 Int
2814 PAF_ASIT_decodeInfo(
2815     const PAF_ASIT_Params *pP, 
2816     const PAF_ASIT_Patchs *pQ, 
2817     PAF_ASIT_Config *pC, 
2818     Int frame, 
2819     Int block
2822     PAF_AST_Config *pAstCfg;
2823     Int as;                    /* Audio Stream Number (1, 2, etc.) */
2824     Int z;                     /* input/decode/stream counter */
2825     Int errno;                 /* error number */
2826     Int sioErr;                /* error number, SIO */
2827     Int zD, zI, zS, zX;
2828     Int zMD;
2829     Int zMI;
2830     Int zMS;
2831     UInt32 curTime;
2832     ASP_Msg *pAspMsg;          /* Messaging */
2833     Int argIdx;
2834     Int status;
2835 #ifdef NON_CACHE_STATUS
2836     Int8 tempVar8;
2837     Int tempVar;
2838 #endif
2839     // FL: revisit
2840     //Int size;
2841     //PAF_InpBufConfig *pIpBufConfig;
2843     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2844     as = pAstCfg->as;
2845     zMD = pAstCfg->masterDec;
2846     zMS = pAstCfg->masterStr;
2847     zMI = pP->zone.master;
2848     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
2849     
2850     // Set decode control: sample rate, emphasis
2851     for (z=INPUT1; z < INPUTN; z++)
2852     {
2853         zD = z;
2854         for (zX = DECODE1; zX < DECODEN; zX++) 
2855         {
2856             if (pP->inputsFromDecodes[zX] == z) 
2857             {
2858                 zD = zX;
2859                 break;
2860             }
2861         }
2863         if (pAstCfg->xInp[z].hRxSio) 
2864         {
2865             //determine associated decoder
2866             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus != 
2867                 pAstCfg->xDec[zD].decodeControl.sampleRate) 
2868             {
2869                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) 
2870                 {
2871                     pAstCfg->xDec[zD].decodeControl.sampleRate = 
2872                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2873                 }
2874                 else
2875                 {
2876                     TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2877                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2878                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus, 
2879                         pAstCfg->xDec[zD].decodeControl.sampleRate);
2880                     // return (ASPERR_INFO_RATECHANGE);
2881                 }
2882             }
2883 #ifdef NON_CACHE_STATUS
2884             statusOp_read(&tempVar8,
2885                           &(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
2886                           sizeof(Int8),
2887                           GATEMP_INDEX_DEC);
2888             pAstCfg->xDec[zD].decodeControl.emphasis = 
2889                 tempVar8 != PAF_SOURCE_PCM
2890                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2891                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2892 #else
2893             pAstCfg->xDec[zD].decodeControl.emphasis =
2894                 pAstCfg->xDec[zD].decodeStatus.sourceDecode != PAF_SOURCE_PCM
2895                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2896                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;