]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamInpProc.c
PASDK-53: Experimental code for circular buffer overflow/underflow handling
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProc.c
2 /*
3 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37  *  ======== audioStreamInpProc.c ========
38  */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Diags.h>
43 #include <xdc/runtime/Error.h>
44 #include <xdc/runtime/Log.h>
45 #include <xdc/runtime/Memory.h>
46 #include <xdc/runtime/System.h>
47 #include <ti/sysbios/BIOS.h>
48 #include <ti/sysbios/hal/Hwi.h>
49 #include <ti/sysbios/hal/Cache.h>
50 #include <ti/sysbios/knl/Clock.h>
51 #include <ti/sysbios/knl/Task.h>
52 #include <ti/ipc/Ipc.h>
53 #include <ti/ipc/MessageQ.h>
54 #include <ti/ipc/MultiProc.h>
56 #include <sio.h>
57 #include <pafsio_ialg.h>
59 #include "common.h"
60 #include "paf_heapMgr.h"
61 #include "aspMsg_common.h"
62 #include "aspMsg_master.h"
63 #include "aspDecOpCircBuf_master.h"
64 #include "audioStreamProc_common.h"
65 #include "audioStreamProc_master.h"
66 #include "audioStreamInpProc.h"
68 // FL: porting
69 #include "fwkSim.h"
70 //#include "fwkPort.h"
71 // FL: debug
72 #include "dbgCapAf.h"
74 #include "statusOp_common.h"
77 // -----------------------------------------------------------------------------
78 // Debugging Trace Control, local to this file.
79 // 
80 #include "logp.h"
82 #define TRACE_ARC(a)
84 // allows you to set a different trace module in pa.cfg
85 #define TR_MOD  trace
87 // Allow a developer to selectively enable tracing.
88 #define CURRENT_TRACE_MASK      0x21
90 #define TRACE_MASK_TERSE        0x01   // only flag errors and show init
91 #define TRACE_MASK_GENERAL      0x02   // half dozen lines per frame
92 #define TRACE_MASK_VERBOSE      0x04   // trace full operation
93 #define TRACE_MASK_DATA         0x08   // Show data
94 #define TRACE_MASK_TIME         0x10   // Timing related traces
95 #define TRACE_MASK_MSG          0x20   // Message related traces
97 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
98     #undef  TRACE_TERSE0
99     #undef  TRACE_TERSE1
100     #undef  TRACE_TERSE2
101     #undef  TRACE_TERSE3
102     #undef  TRACE_TERSE4
103     #define TRACE_TERSE0(a)
104     #define TRACE_TERSE1(a,b)
105     #define TRACE_TERSE2(a,b,c)
106     #define TRACE_TERSE3(a,b,c,d)
107     #define TRACE_TERSE4(a,b,c,d,e)
108 #endif
110 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
111     #undef  TRACE_GEN0
112     #undef  TRACE_GEN1
113     #undef  TRACE_GEN2
114     #undef  TRACE_GEN3
115     #undef  TRACE_GEN4
116     #define TRACE_GEN0(a)
117     #define TRACE_GEN1(a,b)
118     #define TRACE_GEN2(a,b,c)
119     #define TRACE_GEN3(a,b,c,d)
120     #define TRACE_GEN4(a,b,c,d,e)
121 #endif
123 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
124     // consolidate list of processing strings, indexed by PAF_SOURCE
125     static char *procName[] =
126     {
127         "", //PAF_SOURCE_UNKNOWN
128         "", //PAF_SOURCE_NONE
129         "AS%d: Pass processing ...",   //PAF_SOURCE_PASS
130         "AS%d: SNG processing ...",    //PAF_SOURCE_SNG
131         "AS%d: Auto processing ...",   //PAF_SOURCE_AUTO
132         "AS%d: Auto processing ...",   //PAF_SOURCE_BITSTREAM
133         "AS%d: DTS processing ...",    //PAF_SOURCE_DTSALL
134         "AS%d: PCM processing ...",    //PAF_SOURCE_PCMAUTO
135         "AS%d: PCM processing ...",    //PAF_SOURCE_PCM
136         "AS%d: PCN processing ...",    //PAF_SOURCE_PC8
137         "AS%d: AC3 processing ...",    //PAF_SOURCE_AC3
138         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS
139         "AS%d: AAC processing ...",    //PAF_SOURCE_AAC
140         "AS%d: MPG processing ...",    //PAF_SOURCE_MPEG
141         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS12
142         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS13
143         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS14
144         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS16
145         "AS%d: WMP processing ...",    //PAF_SOURCE_WMA9PRO
146         "AS%d: MP3 processing ...",    //PAF_SOURCE_MP3
147         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD1
148         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD2
149         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD3
150         "AS%d: DDP processing ...",    //PAF_SOURCE_DDP
151         "AS%d: DTSHD processing ...",  //PAF_SOURCE_DTSHD
152         "AS%d: THD processing ...",    //PAF_SOURCE_THD
153         "AS%d: DXP processing ...",    //PAF_SOURCE_DXP
154         "AS%d: WMA processing ...",    //PAF_SOURCE_WMA
155     };
157 #else
158     #undef  TRACE_VERBOSE0
159     #undef  TRACE_VERBOSE1
160     #undef  TRACE_VERBOSE2
161     #undef  TRACE_VERBOSE3
162     #undef  TRACE_VERBOSE4
163     #define TRACE_VERBOSE0(a)
164     #define TRACE_VERBOSE1(a,b)
165     #define TRACE_VERBOSE2(a,b,c)
166     #define TRACE_VERBOSE3(a,b,c,d)
167     #define TRACE_VERBOSE4(a,b,c,d,e)
168 #endif
170 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
171     #define TRACE_DATA(a) LOG_printf a
172 #else
173     #define TRACE_DATA(a)
174 #endif
176 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
177     #define TRACE_TIME(a) LOG_printf a
178     #define TIME_MOD  trace // this could be different
179     static Int dtime()
180     {
181          static Int old_time = 0;
182          Int time = TSK_time();
183          Int delta_time = time - old_time;
184          old_time = time;
185          return( delta_time);
186     }
188     static char *stateName[11] =
189     {
190          "INIT",
191          "INFO1",
192          "AGAIN",
193          "INFO2",
194          "CONT",
195          "TIME",
196          "DECODE",
197          "STREAM",
198          "ENCODE",
199          "FINAL",
200          "QUIT"
201     };
203 #else
204     #define TRACE_TIME(a)
205 #endif
207 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
208     #undef  TRACE_MSG0
209     #undef  TRACE_MSG1
210     #undef  TRACE_MSG2
211     #undef  TRACE_MSG3
212     #undef  TRACE_MSG4
213     #define TRACE_MSG0(a)
214     #define TRACE_MSG1(a,b)
215     #define TRACE_MSG2(a,b,c)
216     #define TRACE_MSG3(a,b,c,d)
217     #define TRACE_MSG4(a,b,c,d,e)
218 #endif
219     
221 // .............................................................................
223 #include <pafsio.h>
224 #include "paferr.h"
226 #include <acp_mds.h>
228 #include <pcm.h>
230 #include <pce.h>
232 #include <doberr.h>
234 #include <diberr.h>
236 #include <stdasp.h>
238 #include "as0.h"
239 #include "asperr.h"
241 #include "audioStreamProc_params.h"
242 #include "audioStreamProc_patchs.h"
243 #include "audioStreamProc_config.h"
244 #include "audioStreamInpProc.h"
246 //
247 // Audio Stream Definitions
248 //
250 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
251 #define MINFRAMELENGTH 24
252 #define PA_MODULO       8   // also defined independently in ARC2 code, and may be hard coded other places.
255 //
256 // Decoder Definitions
257 //
258 //#define decLinkInit pQ->i_decLinkInit
260 //
261 // Audio Stream Processing Definitions
262 //
263 //#define aspLinkInit pQ->i_aspLinkInit
265 //
266 // Encoder Definitions
267 //
268 #define encLinkInit pQ->i_encLinkInit
270 //
271 // Input, Output Definitions
272 //
273 #define inpLinkInit pP->i_inpLinkInit
274 //#define outLinkInit pP->i_outLinkInit
276 /* ---------------------------------------------------------------- */
277 /*              Parameter macro definitions end here.               */
278 /* ---------------------------------------------------------------- */
280 //
281 // Standardized Definitions
282 //
284 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
285 //#define ENC_Handle PCE_Handle /* works for all: PCE */
287 #define __TASK_NAME__  "TaskAsip"
289 LINNO_DEFN(TaskAsip); /* Line number macros */
290 ERRNO_DEFN(TaskAsip); /* Error number macros */
292 // ASIT configuration
293 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
294 PAF_ASIT_Config gPAF_ASIT_config = {
295     NULL,               // acp
296     &gPAF_ASPM_config,  // pAspmCfg, shared ASIT/ASOT configuration
297     &gPAF_AST_config    // pAstCfg, shared ASIT/ASOT/ASDT configuration
298 };
300 // Global debug counters */
301 UInt32 gTaskAsipCnt             =0;
302 UInt32 gAsipInitCnt             =0;
303 UInt32 gAsipInfo1Cnt            =0;
304 UInt32 gAsipInfo2Cnt            =0;
305 UInt32 gAsipDecodeCnt           =0;
306 UInt32 gAsipDecodeErrCnt        =0;
307 UInt32 gAsipFinalCnt            =0;
308 UInt32 gAsipQuitCnt             =0;
309 UInt32 gIbReset_cnt             =0;
310 UInt32 gcapIb_cnt               =0;
311 UInt32 gAsipInfo2_PrimaryErrCnt =0;
312 UInt32 gAsipInfo2_ErrCnt        =0;
313 // debug
314 UInt32 gCbWrtAfErrCnt           =0; // // decoder output circular buffer write error count (returned from ARM to DSP)
315                                    
317 #include "dbgDib.h" // debug
319 extern struct {
320     Int size;
321     IALG_Status *pStatus[512];
322 } IACP_STD_BETA_TABLE;
324 // FL: debug
325 #include "evmc66x_gpio_dbg.h"
327 /*
328  *  ======== taskAsipFxn ========
329  *  Audio Stream Input Processing task function
330  */
331 Void taskAsipFxn(
332 //    Int betaPrimeValue, // FL: revisit
333     const PAF_ASIT_Params *pP,
334     const PAF_ASIT_Patchs *pQ
337     PAF_ASIT_Config *pC;            /* Local configuration pointer */
338     PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
339     Int as;                         /* Audio Stream Number (1, 2, etc.) */
340     Int z;                          /* input/encode/stream/decode/output counter */
341     Int i;                          /* phase */
342     Int errno;                      /* error number */
343     Int zMD, zMI, zMS, zX;
344     Int loopCount = 0;  // used to stop trace to see startup behavior.        
345     UInt32 curTime;
346     Int size;
347     // Messaging
348     ASP_Msg *pAspMsg;              
349     Int status;
350 #ifdef NON_CACHE_STATUS
351     Int8 tempVar8;
352 #endif
353     Task_Handle taskHandle;
355     Log_info0("Enter taskAsipFxn()");
356     
357 #ifdef SIMULATE_SIO
358     /* Start simulation */
359     simStart();
360 #endif // SIMULATE_SIO
362     //
363     // Audio Framework Parameters & Patch (*pP, *pQ)
364     //
365     if (!pP) 
366     {
367         TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
368         LINNO_RPRT(TaskAsip, -1);
369         return;
370     }
372     if (!pQ)
373     {
374         TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
375         LINNO_RPRT(TaskAsip, -1);
376         return;
377     }    
378     
379     //
380     // Audio Framework Configuration (*pC):
381     //
382     pC = &gPAF_ASIT_config;
383     pAstCfg = pC->pAstCfg;
385     /* Set Audio Stream Number (1, 2, etc.) */
386     as = gBetaPrimeValue + 1;
387     pAstCfg->as = as;    
388     TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
390     taskHandle = Task_self();
391     
392     //
393     // Initialize message log trace and line number reporting
394     //
395     for (z=STREAM1; z < STREAMN; z++)
396     {
397         TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
398     }
399     LINNO_RPRT(TaskAsip, -1);
400     
401     //
402     // Determine decoder and stream indices associated with the master input
403     //
404     zMI = pP->zone.master;
405     pAstCfg->masterDec = zMI;
406     pAstCfg->masterStr = zMI;
407     for (zX = DECODE1; zX < DECODEN; zX++)
408     {
409         if (pP->inputsFromDecodes[zX] == zMI)
410         {
411             pAstCfg->masterDec = zX;
412             pAstCfg->masterStr = pP->streamsFromDecodes[zX];
413             break;
414         }
415     }
416     zMD = pAstCfg->masterDec;
417     zMS = pAstCfg->masterStr;
419     // Initialize as per parametrized phases:
420     //
421     //   In standard form these are:
422     //      - Malloc: Memory Allocation
423     //      - Config: Configuration Initialization
424     //      - AcpAlg: ACP Algorithm Initialization and Local Attachment
425     //      - Common: Common Memory Initialization
426     //      - AlgKey: Dec/Enc chain to Array Initialization
427     //      - Device: I/O Device Initialization
428     //      - DecOpCircBuf: Decoder Output Circular Buffer
429     //      - Unused: (available)
430     //
431     LINNO_RPRT(TaskAsip, -2);
432     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
433     {
434         Int linno;
435         if (pP->fxns->initPhase[i])
436         {
437             if (linno = pP->fxns->initPhase[i](pP, pQ, pC)) 
438             {
439                 LINNO_RPRT(TaskAsip, linno);
440                 return;
441             }
442         }
443         else 
444         {
445             TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
446         }
447         TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
448         LINNO_RPRT(TaskAsip, -i-3);
449     }
451     //
452     // End of Initialization -- display memory usage report.
453     //
454     if (pP->fxns->memStatusPrint)
455     {
456         pP->fxns->memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
457     }
458     
459     // (***) FL: revisit
460     // write back AST shared configuration
461     Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
462     // FL: no need to share this pointer, can be local
463     //Cache_wb(&pC, sizeof(PAF_AST_Config *), Cache_Type_ALLD, 0);
464     Cache_wait();
466     // (***) FL: revisit
467     // write back Dec configuration
468     Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
469     Cache_wait();
471     // (***) FL: revisit
472     // write back entire beta table
473     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
474     Cache_wait();
475     
476     // FL: send start initialization message to slave
477     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
478     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
479     pAspMsg->cmd = ASP_SLAVE_START;                                                     /* fill in message payload */
480     pAspMsg->procId = hAspMsgMaster->masterProcId;
481     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
482     pAspMsg->expectResp = TRUE;
483     TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
484     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
485     if (status != MessageQ_S_SUCCESS)
486     {
487         SW_BREAKPOINT;
488     }
489     // wait for initialization complete message from slave
490     do {
491         //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
492         status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
493     } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
494     if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
495         (pAspMsg->cmd != ASP_MASTER_START_DONE) || 
496         (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
497     {
498         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
499         SW_BREAKPOINT;
500     }
501     hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
502     TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
503     status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
504     if (status != MessageQ_S_SUCCESS)
505     {
506         SW_BREAKPOINT;
507     }
509     // (***) FL: revisit
510     // invalidate Status structure addresses for Beta Units initialized on Slave
511     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
512     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
513     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
514     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
515     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
516     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
517     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
518     Cache_wait();
519     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
520     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
521     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
522     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
523     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
524     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
525     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
526     
527     // (***) FL: revisit
528     // invalidate Status structures for Beta Units initialized on Slave
529     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
530     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
531     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
532     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
533     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
534     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
535     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
536     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
537     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
538     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
539     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
540     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
541     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
542     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
543     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
544     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
545     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
546     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
547     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
548     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
549     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
550     Cache_wait();
551     
552 #ifdef NON_CACHE_STATUS
553     // Get the shared status structure GateMP handles. Initialized at slave.
554     if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
555     {
556         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
557     }
558     if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
559     {
560         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
561     }
562     if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
563     {
564         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
565     }
566     if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
567     {
568         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
569     }
570 #endif
572     // (***) FL: revisit
573     // invalidate Dec configuration
574     Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
575     Cache_wait();
576     
577     //
578     // Main processing loop
579     //   
580     for (z=STREAM1; z < STREAMN; z++)
581     {
582         TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
583     }
585     TRACE_TERSE0("TaskAsip: Entering Main Loop.");
586     
587     errno = 0;
588     for (;;)
589     {
590         Int sourceSelect;
591         XDAS_Int8 sourceProgram;
593         loopCount++;
595 #if 0   // enable and tune to see startup behavior.
596         // this is an alternative to fixed/circular setting in pa.cfg.
597         // If you are searching for a memory allocation failure, disable on first round.
598         // All allocation has already happened.
599         // This is the outer loop.  This loop count goes up when the stream resets.
600         // If the stream is running without problems, this does not increment.
601         // If the stream is repeatedly resetting, this loop count will go up rapidly.
602         if (loopCount > 10)  // see traces for a few of the passes through the main loop.
603         {
604              TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
605              LOG_disable(&TR_MOD);  // stop tracing
606         }
607 #endif
609         TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
610         TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
611         
612         // since not decoding indicate such
613         pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_NONE);
615         // any error forces idling of input
616         if (errno) 
617         {
618             for (z=INPUT1; z < INPUTN; z++)
619             {
620                 if (pAstCfg->xInp[z].hRxSio)
621                 {
622                     SIO_idle(pAstCfg->xInp[z].hRxSio);
623                 }
624             }
625         
626             TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
627             ERRNO_RPRT(TaskAsip, errno);
628         }
629         
630         // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
631         // up to allow lower priority tasks to run. This may seem odd to be at the top
632         // of the state machine but provides for a cleaner flow even though the very
633         // first time we enter we do a sleep which is non-intuitive.
634         TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
635         TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
636         Task_sleep(1);
638         TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
639         if (errno = pP->fxns->selectDevices(pP, pQ, pC))
640         {
641             TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
642             continue;
643         }
645         // if no master input selected then we don't know what may be at the input
646         // so set to unknown and skip any remaining processing
647         if (!pAstCfg->xInp[zMI].hRxSio)
648         {
649 #ifdef NON_CACHE_STATUS
650             tempVar8 = PAF_SOURCE_UNKNOWN;
651             statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
652                            &tempVar8,
653                            sizeof(tempVar8),
654                            GATEMP_INDEX_DEC);
655 #else
656             pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_UNKNOWN;
657 #endif
658             TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
659             continue;
660         }
661         
662         // if here then we have a valid input so query its status
663         if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig))
664         {
665             TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
666             continue;
667         }
668         
669 #ifdef NON_CACHE_STATUS
670         statusOp_read(&tempVar8,
671                       &(pAstCfg->xDec[zMD].decodeStatus.mode),
672                       sizeof(tempVar8),
673                       GATEMP_INDEX_DEC);
674         // If master decoder is not enabled, or the input is unlocked, then do nothing
675         if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
676         {
677             TRACE_VERBOSE0("TaskAsip: Not locked, continue");
678             continue;
679         }
680 #else
681         // If master decoder is not enabled, or the input is unlocked, then do nothing
682         if (!pAstCfg->xDec[zMD].decodeStatus.mode || !pAstCfg->xInp[zMI].inpBufStatus.lock)
683         {
684             TRACE_VERBOSE0("TaskAsip: Not locked, continue");
685             continue;
686         }
687 #endif
688         
689 #ifdef NON_CACHE_STATUS
690         statusOp_read(&tempVar8,
691                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
692                       sizeof(tempVar8),
693                       GATEMP_INDEX_DEC);
694         // If no source selected then do nothing
695         if (tempVar8 == PAF_SOURCE_NONE)
696         {
697             tempVar8 = PAF_SOURCE_NONE;
698             statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
699                            &tempVar8,
700                            sizeof(tempVar8),
701                            GATEMP_INDEX_DEC);
702             TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
703             continue;
704         }
705 #else
706         // If no source selected then do nothing
707         if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE) 
708         {
709             pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
710             TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
711             continue;
712         }
713 #endif
715 #ifdef NON_CACHE_STATUS
716         statusOp_read(&tempVar8,
717                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
718                       sizeof(tempVar8),
719                       GATEMP_INDEX_DEC);
720         // If we want pass processing then proceed directly
721         if (tempVar8 == PAF_SOURCE_PASS)
722         {
723             TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
725             tempVar8 = PAF_SOURCE_PASS;
726             statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
727                            &tempVar8,
728                            sizeof(tempVar8),
729                            GATEMP_INDEX_DEC);
730 #else
731         // If we want pass processing then proceed directly
732         if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) 
733         {
734             TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
735             pAstCfg->xDec[zMD].decodeStatus.sourceProgram = PAF_SOURCE_PASS;
736 #endif
737             pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_PASS);
738             if (pP->fxns->passProcessing)
739             {
740                 errno = pP->fxns->passProcessing(pP, pQ, pC, NULL);                
741             }
742             else 
743             {
744                 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
745                 errno = ASPERR_PASS;
746             }
747             TRACE_VERBOSE0("TaskAsip: continue");
748             continue;
749         }
751 #ifdef NON_CACHE_STATUS
752         statusOp_read(&tempVar8,
753                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
754                       sizeof(tempVar8),
755                       GATEMP_INDEX_DEC);
756         // .....................................................................
757         // At this point we have an enabled input and want to decode something.
758         // If no decoder selected then do nothing. Need to reset the sourceProgram, since
759         // when no decoder is selected there are no calls to IB
760         //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
761         if (errno = pP->fxns->autoProcessing(pP, pQ, pC, tempVar8, NULL)) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
762         {
763             TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
764             continue;
765         }
766 #else
767         // .....................................................................
768         // At this point we have an enabled input and want to decode something.
769         // If no decoder selected then do nothing. Need to reset the sourceProgram, since
770         // when no decoder is selected there are no calls to IB
771         //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
772         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
773         {
774             TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
775             continue;
776         }
777 #endif
778         
779         // query for input type
780         if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram))
781         {
782             TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
783             errno = ASPERR_AUTO_PROGRAM;
784             continue;
785         }
786 #ifdef NON_CACHE_STATUS
787         statusOp_write(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
788                       &(sourceProgram),
789                       sizeof(sourceProgram),
790                       GATEMP_INDEX_DEC);
791 #else
792         pAstCfg->xDec[zMD].decodeStatus.sourceProgram = sourceProgram;
793 #endif
795         // if input is unclassifiable then do nothing
796         if (sourceProgram == PAF_SOURCE_UNKNOWN)
797         {
798             TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
799             continue;
800         }
802         // now that we have some input classification, and possibly an outstanding
803         // input frame, we determine whether or not to call decodeProcessing and with
804         // what decAlg.
805         sourceSelect = PAF_SOURCE_NONE;
806 #ifdef NON_CACHE_STATUS
807         statusOp_read(&tempVar8,
808                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
809                       sizeof(tempVar8),
810                       GATEMP_INDEX_DEC);
811         switch (tempVar8)
812         {
813 #else
814         switch (pAstCfg->xDec[zMD].decodeStatus.sourceSelect) 
815         {
816 #endif
817             // If autodetecting, decoding everything, and input is something
818             // (i.e. bitstream or PCM) then decode.
819             case PAF_SOURCE_AUTO:
820                 if (sourceProgram >= PAF_SOURCE_PCM)
821                 {
822                     sourceSelect = sourceProgram;                    
823                 }
824                 break;
826             // If autodetecting, decoding only PCM, and input is PCM then decode.
827             case PAF_SOURCE_PCMAUTO:
828                 if (sourceProgram == PAF_SOURCE_PCM)
829                 {
830                     sourceSelect = sourceProgram;                    
831                 }
832                 break;
834             // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
835             case PAF_SOURCE_BITSTREAM:
836                 if (sourceProgram >= PAF_SOURCE_AC3)
837                 {
838                     sourceSelect = sourceProgram;                    
839                 }
840                 break;
842             // If autodetecting, decoding only DTS, and input is DTS then decode.
843             case PAF_SOURCE_DTSALL:
844                 switch (sourceProgram) 
845                 {
846                     case PAF_SOURCE_DTS11:
847                     case PAF_SOURCE_DTS12:
848                     case PAF_SOURCE_DTS13:
849                     case PAF_SOURCE_DTS14:
850                     case PAF_SOURCE_DTS16:
851                     case PAF_SOURCE_DTSHD:
852                         sourceSelect = sourceProgram;
853                         break;
854                 }
855                 break;
857             // All others, e.g., force modes, fall through to here.
858             // If user made specific selection then program must match select.
859             // (NB: this compare relies on ordering of PAF_SOURCE)
860             default:
861 #ifdef NON_CACHE_STATUS
862                 sourceSelect = 0; // due to size difference
863                 statusOp_read(&sourceSelect,
864                               &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
865                               sizeof(Int8),
866                               GATEMP_INDEX_DEC);
867 #else
868                 sourceSelect = pAstCfg->xDec[zMD].decodeStatus.sourceSelect;
869 #endif
870                 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
871                 {
872                     if (sourceProgram != sourceSelect)
873                     {
874                         sourceSelect = PAF_SOURCE_NONE;                        
875                     }
876                 }
877                 break;
878         }
880         // if we didn't find any matches then skip
881         if (sourceSelect == PAF_SOURCE_NONE)
882         {
883             TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
884             continue;
885         }
887         // FL: debug, reset IB capture buffer
888         capIbReset();
889         gIbReset_cnt++;
890         Log_info0("capIbReset()");
892         // FL: send source select message to slave
893         pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
894         MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
895         pAspMsg->cmd = ASP_SLAVE_DEC_SOURCE_SELECT;                                         /* fill in message payload */
896         pAspMsg->procId = hAspMsgMaster->masterProcId;
897         pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
898         pAspMsg->expectResp = TRUE;
899         *(Int32 *)&pAspMsg->buf[0] = sourceSelect;
900         TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
901         TRACE_MSG1("sourceSelect=%d", pAspMsg->buf[0]);
902         status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
903         if (status != MessageQ_S_SUCCESS)
904         {
905             SW_BREAKPOINT;
906         }
907         // wait for source select complete message from slave
908         //do {
909         //    status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
910         //} while (status != MessageQ_S_SUCCESS);
911         status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
912         if (status != MessageQ_S_SUCCESS)
913         {
914             TRACE_TERSE0("MessageQ_get() failure.");
915             SW_BREAKPOINT; // temporary
916         }
917         if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
918             (pAspMsg->cmd != ASP_MASTER_DEC_SOURCE_SELECT_DONE) ||
919             (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
920         {
921             TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
922             SW_BREAKPOINT;
923         }
924         hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
925         TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
926         status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
927         if (status != MessageQ_S_SUCCESS)
928         {
929             SW_BREAKPOINT;
930         }
931         
932         // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
933         // iff we are in this top level state machine and specifically not in decodeProcessing
934         pP->fxns->sourceDecode(pP, pQ, pC, PAF_SOURCE_UNKNOWN);
935         
936         TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
938         // Reduce priority level since autodetection complete
939         Task_setPri(taskHandle, Task_getPri(taskHandle)-1);
940         
941         TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
942         errno = pP->fxns->decodeProcessing(pP, pQ, pC, sourceSelect);
943         if (errno) 
944         {
945             TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
946         }
947         else
948         {
949             TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
950         }        
952         // Increase priority level since decoding complete
953         Task_setPri(taskHandle, Task_getPri(taskHandle)+1);
955         // FL: send dec exit message to slave
956         pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
957         MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
958         pAspMsg->cmd = ASP_SLAVE_DEC_EXIT;                                                  /* fill in message payload */
959         pAspMsg->procId = hAspMsgMaster->masterProcId;
960         pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
961         pAspMsg->expectResp = TRUE;
962         TRACE_MSG2("Tx ASP message: procId=%d, cmd=%d.", pAspMsg->procId, pAspMsg->cmd);
963         status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
964         if (status != MessageQ_S_SUCCESS)
965         {
966             SW_BREAKPOINT;
967         }
968         // wait for dec exit complete message from slave
969         //do {
970         //    status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
971         //} while ((status < 0) || (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE));
972         status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
973         if (status != MessageQ_S_SUCCESS)
974         {
975             TRACE_TERSE0("MessageQ_get() failure.");
976             SW_BREAKPOINT; // temporary
977         }
978         if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) || 
979             (pAspMsg->cmd != ASP_MASTER_DEC_EXIT_DONE) ||
980             (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
981         {
982             TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
983             SW_BREAKPOINT;
984         }
985         hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
986         TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
987         // free the message
988         status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
989         if (status != MessageQ_S_SUCCESS)
990         {
991             SW_BREAKPOINT;
992         }
993     } // End of main processing loop for (;;)
994     
995     Log_info0("Exit taskAsipFxn()");
998 // -----------------------------------------------------------------------------
999 // ASIT Initialization Function - Memory Allocation
1000 //
1001 //   Name:      PAF_ASIT_initPhaseMalloc
1002 //   Purpose:   Audio Stream Input Task Function for initialization of data pointers
1003 //              by allocation of memory.
1004 //   From:      audioStream1Task or equivalent
1005 //   Uses:      See code.
1006 //   States:    x
1007 //   Return:    0 on success.
1008 //              Source code line number on MEM_calloc failure.
1009 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1010 //              * State information as per parent.
1011 //              * Memory allocation errors.
1012 //
1013 Int
1014 PAF_ASIT_initPhaseMalloc(
1015     const PAF_ASIT_Params *pP, 
1016     const PAF_ASIT_Patchs *pQ, 
1017     PAF_ASIT_Config *pC
1020     PAF_AST_Config *pAstCfg;
1021     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1022     Int zMS;
1023     Error_Block    eb;
1025     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1026     as = pAstCfg->as;
1027     zMS = pAstCfg->masterStr;
1028     
1029     TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
1031     // Initialize error block
1032     Error_init(&eb); 
1034     /* Input memory */
1035     if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
1036         INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
1037     {
1038         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1039         SW_BREAKPOINT;
1040         return __LINE__;
1041     }
1042     TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xInp) %d bytes from space %d at 0x%x.",
1043         INPUTN * sizeof (*pAstCfg->xInp),
1044         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
1046 #ifdef NON_CACHE_STATUS
1047     /* Decode memory */
1048     if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM,
1049         DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1050     {
1051         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1052         SW_BREAKPOINT;
1053         return __LINE__;
1054     }
1055 #else
1056     /* Decode memory */
1057     if (!(pAstCfg->xDec = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
1058         DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
1059     {
1060         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
1061         SW_BREAKPOINT;
1062         return __LINE__;
1063     }
1064 #endif
1065     TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pC->xDec) %d bytes from space %d at 0x%x.",
1066         DECODEN * sizeof (*pAstCfg->xDec),
1067         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
1068                 
1069     TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
1070     return 0;
1071 } //PAF_ASIT_initPhaseMalloc
1073 // -----------------------------------------------------------------------------
1074 // ASIT Initialization Function - Memory Initialization from Configuration
1075 //
1076 //   Name:      PAF_ASIT_initPhaseConfig
1077 //   Purpose:   Audio Stream Task Function for initialization of data values
1078 //              from parameters.
1079 //   From:      audioStream1Task or equivalent
1080 //   Uses:      See code.
1081 //   States:    x
1082 //   Return:    0 on success.
1083 //              Other as per initFrame0 and initFrame1.
1084 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1085 //              * State information as per parent.
1086 //
1087 Int
1088 PAF_ASIT_initPhaseConfig(
1089     const PAF_ASIT_Params *pP, 
1090     const PAF_ASIT_Patchs *pQ, 
1091     PAF_ASIT_Config *pC
1094     PAF_AST_Config *pAstCfg;
1095     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1096     Int z;                     /* input/encode/stream/decode/output counter */
1097     Int zMS;
1099     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1100     as = pAstCfg->as;
1101     zMS = pAstCfg->masterStr;
1102     
1103     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
1105     //
1106     // Unspecified elements have been initialized to zero during alloc
1107     //
1108     
1109     for (z=INPUT1; z < INPUTN; z++) 
1110     {
1111         pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
1112         pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
1113     }
1115     for (z=DECODE1; z < DECODEN; z++) 
1116     {
1117         Int zI = pP->inputsFromDecodes[z];
1118         pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
1119         pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
1120         //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
1121     }
1123     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1124     return 0;
1125 } //PAF_ASIT_initPhaseConfig
1127 // -----------------------------------------------------------------------------
1128 // ASIT Initialization Function - ACP Algorithm Instantiation
1129 //
1130 //   Name:      PAF_ASIT_initPhaseAcpAlg
1131 //   Purpose:   Audio Stream Input Task Function for initialization of ACP by
1132 //              instantiation of the algorithm.
1133 //   From:      audioStream1Task or equivalent
1134 //   Uses:      See code.
1135 //   States:    x
1136 //   Return:    0 on success.
1137 //              Source code line number on ACP Algorithm creation failure.
1138 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1139 //              * State information as per parent.
1140 //              * Memory allocation errors.
1141 //
1142 Int
1143 PAF_ASIT_initPhaseAcpAlg(
1144     const PAF_ASIT_Params *pP, 
1145     const PAF_ASIT_Patchs *pQ, 
1146     PAF_ASIT_Config *pC
1149     PAF_AST_Config *pAstCfg;
1150     Int as;                 /* Audio Stream Number (1, 2, etc.) */
1151     Int z;                  /* input/encode/stream/decode/output counter */
1152     Int betaPrimeOffset;
1153     ACP_Handle acp;
1154     Int zMS;
1155     Int zS, zX;
1157     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1158     as = pAstCfg->as;
1159     zMS = pAstCfg->masterStr;
1160     
1161     TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1163     ACP_MDS_init();
1165     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1166     {
1167         TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1168         return __LINE__;
1169     }
1170     pC->acp = acp;
1172     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1173         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1175     for (z=INPUT1; z < INPUTN; z++) 
1176     {
1177         zS = z;
1178         for (zX = DECODE1; zX < DECODEN; zX++) 
1179         {
1180             if (pP->inputsFromDecodes[zX] == z) 
1181             {
1182                 zS = pP->streamsFromDecodes[zX];
1183                 break;
1184             }
1185         }
1186         acp->fxns->attach(acp, ACP_SERIES_STD,
1187             STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1188             (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1189         /* Ignore errors, not reported. */
1190     }
1192     TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1194     return 0;
1195 } //PAF_ASIT_initPhaseAcpAlg
1197 // -----------------------------------------------------------------------------
1198 // ASIT Initialization Function - Common Memory
1199 //
1200 //   Name:      PAF_ASIT_initPhaseCommon
1201 //   Purpose:   Audio Stream Input Task Function for allocation of common memory.
1202 //   From:      audioStream1Task or equivalent
1203 //   Uses:      See code.
1204 //   States:    x
1205 //   Return:    0 on success.
1206 //              Source code line number on PAF_ALG_alloc failure.
1207 //              Source code line number on PAF_ALG_mallocMemory failure.
1208 //              Source code line number on Decode Chain initialization failure.
1209 //              Source code line number on ASP Chain initialization failure.
1210 //              Source code line number on Encode Chain initialization failure.
1211 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1212 //              * State information as per parent.
1213 //              * Memory allocation errors.
1214 //
1215 Int
1216 PAF_ASIT_initPhaseCommon(
1217     const PAF_ASIT_Params *pP, 
1218     const PAF_ASIT_Patchs *pQ, 
1219     PAF_ASIT_Config *pC
1222     PAF_AST_Config *pAstCfg;
1223     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1224     Int z;                      /* stream counter */
1225     ACP_Handle acp;
1226     PAF_IALG_Config pafAlgConfig;
1227     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1228    
1229     acp = pC->acp;
1230     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1231     as = pAstCfg->as;
1232     
1233     TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1235     //
1236     // Determine memory needs and instantiate algorithms across audio streams
1237     //
1238     TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1239     PAF_ALG_setup(&pafAlgConfig, 
1240         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1241         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1242         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1243         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1244         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1245         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1246         HEAP_CLEAR);
1248     if (pP->fxns->headerPrint)
1249     {
1250         pP->fxns->headerPrint();        
1251     }
1253     for (z = STREAM1; z < STREAMN; z++) 
1254     {
1255         TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1257         //
1258         // Determine common memory for:
1259         //  (1) Logical Input drivers
1260         //
1261         // Decode Algorithms common memory determined in ASP Slave.
1262         //
1263         PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1265         //
1266         // Determine common memory needs of Logical Input driver
1267         //
1269         // really need to loop over all inputs for this stream using the tables
1270         // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1271         // patch, and not needed for FS11, since there is only one input.
1272         if (INPUT1 <= z && z < INPUTN) 
1273         {
1274             TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1275             if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1276             {
1277                 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1278                 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1279                 SW_BREAKPOINT;
1280                 return __LINE__;
1281             }
1282             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1283             if (pP->fxns->allocPrint)
1284             {
1285                 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1286             }
1287         }
1288     }
1289     {
1290         // Changes made to share scratch between zones
1291         // Assume maximum 3 zones and scratch common memory is at offset 0;
1292         int max=0;
1293         for (z=STREAM1; z<STREAMN; z++)
1294         {
1295             if (max < common[z][0].size)
1296             {
1297                 max = common[z][0].size;
1298             }
1299         }
1300         common[STREAM1][0].size=max;
1301         for (z=STREAM1+1; z<STREAMN; z++)
1302         {
1303             common[z][0].size = 0;            
1304         }
1305     }
1306         
1307     //
1308     // Allocate common memory for:
1309     //  (1) Logical Input drivers
1310     //
1311     for (z = STREAM1; z < STREAMN; z++) 
1312     {
1313         TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1314         if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig)) 
1315         {
1316             TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1317             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1318             SW_BREAKPOINT;
1319             return __LINE__;
1320         }
1321         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1322         // share zone0 scratch with all zones 
1323         common[z][0].base = common[0][0].base;
1324         if (pP->fxns->commonPrint)
1325         {
1326             pP->fxns->commonPrint(common[z], &pafAlgConfig);
1327         }
1329         //
1330         // Allocate non-common memories for Logical IO drivers
1331         //    Since these structures are used at run-time we allocate from external memory
1332         if (INPUT1 <= z && z < INPUTN) 
1333         {
1334             PAF_ASP_Chain *chain;
1335             TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1336                            as+z, z);
1337             chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1338                         HEAP_EXTERNAL, as+z, acp, &trace,
1339                         inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1340             if (!chain) 
1341             {
1342                 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1343                 return __LINE__;
1344             }
1345         }
1346     }
1347     TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1349     return 0;
1350 } //PAF_ASIT_initPhaseCommon
1352 // (***) FL: candidate for removal
1353 // -----------------------------------------------------------------------------
1354 // ASIT Initialization Function - Algorithm Keys
1355 //
1356 //   Name:      PAF_ASIT_initPhaseAlgKey
1357 //   Purpose:   Audio Stream Input Task Function for initialization of data values
1358 //              from parameters for Algorithm Keys.
1359 //   From:      audioStream1Task or equivalent
1360 //   Uses:      See code.
1361 //   States:    x
1362 //   Return:    0.
1363 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1364 //              * State information as per parent.
1365 //
1366 // .............................................................................
1367 Int
1368 PAF_ASIT_initPhaseAlgKey(
1369     const PAF_ASIT_Params *pP, 
1370     const PAF_ASIT_Patchs *pQ, 
1371     PAF_ASIT_Config *pC
1374     PAF_AST_Config *pAstCfg;
1375     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1377     
1378     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1379     as = pAstCfg->as;
1380     (void)as;  // clear compiler warning in case not used with tracing disabled
1382     TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1384 #if 0 // FL: slave    
1385     for (z=DECODE1; z < DECODEN; z++) 
1386     {
1387         for (s=0; s < pP->pDecAlgKey->length; s++) 
1388         {
1389             if ((pP->pDecAlgKey->code[s].full != 0) &&
1390                 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s]))) 
1391             {
1392                 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1393                 /* Cast in interface, for now --Kurt */
1394             }
1395             else
1396             {
1397                 pC->xDec[z].decAlg[s] = NULL;
1398             }
1399         }
1400     }
1401 #endif
1403     return 0;
1404 } //PAF_ASIT_initPhaseAlgKey
1406 // -----------------------------------------------------------------------------
1407 // ASIT Initialization Function - I/O Devices
1408 //
1409 //   Name:      PAF_ASIT_initPhaseDevice
1410 //   Purpose:   Audio Stream Input Task Function for initialization of I/O Devices.
1411 //   From:      audioStream1Task or equivalent
1412 //   Uses:      See code.
1413 //   States:    x
1414 //   Return:    0 on success.
1415 //              Source code line number on device allocation failure.
1416 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1417 //              * State information as per parent.
1418 //              * Memory allocation errors.
1419 //
1420 Int
1421 PAF_ASIT_initPhaseDevice(
1422     const PAF_ASIT_Params *pP, 
1423     const PAF_ASIT_Patchs *pQ, 
1424     PAF_ASIT_Config *pC
1427     PAF_AST_Config *pAstCfg;
1428     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1429     Int z;                              /* input/output counter */
1430     PAF_SIO_IALG_Obj    *pObj;
1431     PAF_SIO_IALG_Config *pAlgConfig;
1432     PAF_IALG_Config pafAlgConfig;
1435     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1436     as = pAstCfg->as;
1437     (void)as; // clear compiler warning in case not used with tracing disabled
1439     TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1441     if (pP->fxns->bufMemPrint)
1442     {
1443         PAF_ALG_setup (&pafAlgConfig, 
1444             HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1445             HEAP_ID_INTERNAL1,              HEAP_INTERNAL1,
1446             HEAP_ID_EXTERNAL,               HEAP_EXTERNAL,
1447             HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM,
1448             HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM,
1449             HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1450             HEAP_CLEAR);
1451         TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1452     }
1454     for (z=INPUT1; z < INPUTN; z++) 
1455     {
1456         PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1458         pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1459         pAlgConfig = &pObj->config;
1461         pAstCfg->xInp[z].hRxSio = NULL;
1463         pConfig->base.pVoid       = pAlgConfig->pMemRec[0].base;
1464         pConfig->pntr.pVoid       = pAlgConfig->pMemRec[0].base;
1465         pConfig->head.pVoid       = pAlgConfig->pMemRec[0].base;
1466         pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1467         pConfig->allocation       = pAlgConfig->pMemRec[0].size;
1468         pConfig->sizeofElement    = 2;
1469         pConfig->precision        = 16;
1471         if (pP->fxns->bufMemPrint)
1472         {
1473             pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1474         }
1475     }
1477     TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1479     return 0;
1480 } //PAF_ASIT_initPhaseDevice
1482 // -----------------------------------------------------------------------------
1483 // ASIT Initialization Function - Decoder Output Circular Buffer
1484 //
1485 //   Name:      PAF_ASIT_initPhaseDecOpCircBuf
1486 //   Purpose:   Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1487 //   From:      audioStream1Task or equivalent
1488 //   Uses:      See code.
1489 //   States:    x
1490 //   Return:    0 on success.
1491 //              Source code line number on device allocation failure.
1492 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1493 //              * State information as per parent.
1494 //              * Memory allocation errors.
1495 //
1496 Int
1497 PAF_ASIT_initPhaseDecOpCircBuf(
1498     const PAF_ASIT_Params *pP, 
1499     const PAF_ASIT_Patchs *pQ, 
1500     PAF_ASIT_Config *pC
1503     PAF_AST_Config *pAstCfg;
1504     PAF_AST_DecOpCircBuf *pCb;          /* Decoder output circular buffer */
1505     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1506     Int zMS;
1507     Int z;                              /* decode counter */
1508     Int errno;                          /* error number */
1509     Error_Block    eb;
1510     Int i;
1512     // FL: (***)revisit
1513     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1514     as = pAstCfg->as;
1515     zMS = pAstCfg->masterStr;
1517     /* Decode output circular buffer memory */
1518     if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
1519         DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1520     {
1521         TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1522         SW_BREAKPOINT;
1523         return __LINE__;
1524     }
1526     TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pC->xDecOpCb) %d bytes from space %d at 0x%x.",
1527         DECODEN * sizeof (*pAstCfg->xDecOpCb),
1528         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1529         
1530     for (z=DECODE1; z < DECODEN; z++)
1531     {
1532         pCb = &pAstCfg->xDecOpCb[z];
1533         
1534         // allocate audio frame circular buffer
1535         if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1536         {
1537             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1538             SW_BREAKPOINT;
1539         }
1540         // allocate audio frame PCM sample pointer array
1541         for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1542         {
1543             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)))
1544             {
1545                 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1546                 SW_BREAKPOINT;
1547             }
1548             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)))
1549             {
1550                 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1551                 SW_BREAKPOINT;
1552             }                
1553         }
1554         // allocate PCM sample buffer
1555         if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1556         {
1557             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1558             SW_BREAKPOINT;
1559         }
1560         pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1561         // allocate Metadata buffers //QIN
1562         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)))
1563         {
1564             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1565             SW_BREAKPOINT;
1566         }
1567         pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1568         // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length        
1569         // Initialize decoder output circular buffer for PCM
1570         errno = cbInit(pCb);
1571         if (errno)
1572         {
1573             SW_BREAKPOINT; // FL: debug
1574             return errno;
1575         }
1576     }
1578     return 0;
1579 } //PAF_ASIT_initPhaseDecOpCircBuf
1582 #if 0
1583 // -----------------------------------------------------------------------------
1584 // AST Processing Function - Pass-Through Processing
1585 //
1586 //   Name:      PAF_AST_passProcessing
1587 //   Purpose:   Audio Stream Task Function for processing audio data as a
1588 //              pass-through from the input driver to the output driver
1589 //              for development and testing.
1590 //   From:      audioStream1Task or equivalent
1591 //   Uses:      See code.
1592 //   States:    x
1593 //   Return:    Error number in standard form (0 on success).
1594 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1595 //              * State information on initialization.
1596 //              * State information on processing.
1597 //
1599 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1600 /* Pass Processing is often omitted from builds to save memory, */
1601 /* and CODE_SECTION/clink constructs facilitate this omission.  */
1603 Int
1604 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1606     Int z;                              /* input/output counter */
1607     Int errno = 0;                      /* error number */
1608     Int getVal;
1609     Int rxNumChan, txNumChan;
1610     Int first;
1611     Int zMD = pC->masterDec;
1612     Int zMI = pP->zone.master;
1615 #ifndef __TI_EABI__
1616     asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1617 #endif    
1619     TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1621     //
1622     // Determine that receive/transmit channels are compatible
1623     //
1625     // Can handle handle only master input
1626     for (z=INPUT1; z < INPUTN; z++) {
1627         if (z != zMI && pC->xInp[z].hRxSio)
1628             return (ASPERR_PASS + 0x01);
1629     }
1631     /* Number of receive/transmit channels */
1633     if (! pC->xInp[zMI].hRxSio)
1634         return (ASPERR_PASS + 0x11);
1635     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1636         return (ASPERR_PASS + 0x12);
1637     if (rxNumChan > NUM_TX_CHAN(zMI))
1638         return (ASPERR_PASS + 0x13);
1640     for (z=OUTPUT1; z < OUTPUTN; z++) {
1641         if (! pC->xOut[zMI].hTxSio)
1642             return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1643         if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1644             return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1645         if (txNumChan > NUM_TX_CHAN(zMI))
1646             return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1647     }
1649     //
1650     // Set up receive/transmit
1651     //
1653     SIO_idle (pC->xInp[zMI].hRxSio);
1654     for (z=OUTPUT1; z < OUTPUTN; z++) {
1655         if(SIO_idle (pC->xOut[z].hTxSio))
1656             return ASPERR_IDLE;
1657     }
1659     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1660         return (ASPERR_PASS + 0x14);
1662     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1663         return (ASPERR_PASS + 0x15);
1665     for (z=OUTPUT1; z < OUTPUTN; z++)
1666         pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1668     if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1669         return ASPERR_PASS + 0x16;
1671     if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1672         return ASPERR_PASS + 0x17;
1674     //
1675     // Receive and transmit the data in single-frame buffers
1676     //
1678     first = 1;
1679     while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1680         PAF_OutBufConfig *pOutBuf;
1681         PAF_InpBufConfig *pInpBuf;
1683         if (first) {
1684             first = 0;
1686             TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1688             for (z=OUTPUT1; z < OUTPUTN; z++) {
1689                 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1690                 if (getVal > 0) {
1691                     errno = ASPERR_ISSUE;
1692                     break;
1693                 }
1694                 else if (getVal < 0) {
1695                     errno = -getVal;
1696                     break;
1697                 }
1699                 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1700                     return (getVal & 0xff) | ASPERR_MUTE;
1701             }
1702             if (errno)
1703                 break;
1705         }
1707         getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1708         if (getVal > 0) {
1709             errno = ASPERR_ISSUE;
1710             break;
1711         }
1713         TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1715         getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1716         if (getVal < 0) {
1717             errno = -getVal;
1718             break;
1719         }
1721         for (z=OUTPUT1; z < OUTPUTN; z++) {
1722             getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1723             if (getVal < 0) {
1724                 errno = -getVal;
1725                 break;
1726             }
1727         }
1728         if( errno )
1729             break;
1731         TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1733         if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1734             break;
1736         for (z=OUTPUT1; z < OUTPUTN; z++) {
1737             getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1738             if (getVal > 0) {
1739                 errno = ASPERR_ISSUE;
1740                 break;
1741             }
1742             else if (getVal < 0) {
1743                 errno = -getVal;
1744                 break;
1745             }
1746         }
1747         if( errno )
1748             break;
1749     }
1751     //
1752     // Close down receive/transmit
1753     //
1755     TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1757     for (z=OUTPUT1; z < OUTPUTN; z++) {
1758         if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1759             if (! errno)
1760                 errno = (getVal & 0xff) | ASPERR_MUTE;
1761             /* convert to sensical errno */
1762         }
1763     }
1765     SIO_idle (pC->xInp[zMI].hRxSio);
1766     for (z=OUTPUT1; z < OUTPUTN; z++)
1767         SIO_idle (pC->xOut[z].hTxSio);
1769     return errno;
1771 } //PAF_AST_passProcessing
1772 #endif // #if 0
1774 #if 0
1775 // -----------------------------------------------------------------------------
1776 // AST Processing Function Helper - Pass-Through Processing Patch Point
1777 //
1778 //   Name:      PAF_AST_passProcessingCopy
1779 //   Purpose:   Pass-Through Processing Function for copying audio data
1780 //              from the input buffer to the output buffer.
1781 //   From:      AST Parameter Function -> passProcessing
1782 //   Uses:      See code.
1783 //   States:    x
1784 //   Return:    Error number in standard form (0 on success).
1785 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1786 //              x
1787 //
1789 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1790 /* Pass Processing is often omitted from builds to save memory, */
1791 /* and CODE_SECTION/clink constructs facilitate this omission.  */
1793 Int
1794 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1796     Int z;                              /* output counter */
1797     Int errno;                          /* error number */
1798     Int i;
1799     Int rxNumChan, txNumChan;
1800     Int zMI = pP->zone.master;
1803     asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1805     // Copy data from input channels to output channels one of two ways:
1807     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1808         return (ASPERR_PASS + 0x12);
1810     for (z=OUTPUT1; z < OUTPUTN; z++) {
1811         if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1812             return (ASPERR_PASS + 0x22);
1814         if( txNumChan <= rxNumChan ) {
1816             // Copy one to one, ignoring later rx channels as needed.
1818             for( i=0; i < txNumChan; i++ ) {
1819                 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1820                 if( errno )
1821                     return errno;
1822             }
1823         }
1824         else {
1826             // Copy one to many, repeating earlier rx channels as needed.
1828             Int from, to;
1830             from = 0;
1831             to   = 0;
1832             while( to < txNumChan ) {
1833                 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1834                 if( errno )
1835                     return errno;
1837                 from++;
1838                 to++;
1839                 if( from == rxNumChan )
1840                     from = 0;
1841             }
1842         }
1843     }
1845     return 0;
1846 } //PAF_AST_passProcessingCopy
1847 #endif // #if 0
1849 // -----------------------------------------------------------------------------
1850 // ASIT Processing Function - Auto Processing
1851 //
1852 //   Name:      PAF_ASIT_autoProcessing
1853 //   Purpose:   Audio Stream Input Task Function for processing audio data to
1854 //              determine the input type without output.
1855 //   From:      audioStream1Task or equivalent
1856 //   Uses:      See code.
1857 //   States:    x
1858 //   Return:    Error number in standard or SIO form (0 on success).
1859 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1860 //              * State information on initialization.
1861 //
1863 #define DECSIOMAP(X)                                                \
1864     pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1866 Int
1867 PAF_ASIT_autoProcessing(
1868     const PAF_ASIT_Params *pP, 
1869     const PAF_ASIT_Patchs *pQ, 
1870     PAF_ASIT_Config *pC, 
1871     Int inputTypeSelect, 
1872     ALG_Handle pcmAlgMaster
1875     PAF_AST_Config *pAstCfg;
1876     Int as;                 /* Audio Stream Number (1, 2, etc.) */
1877     Int errno = 0;          /* error number */
1878     Int nbytes;
1879     Int frameLength;
1880     Int zMD;
1881     Int zMI;
1882     Int zMS;
1883     
1884     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1885     as = pAstCfg->as;
1886     zMD = pAstCfg->masterDec;
1887     zMS = pAstCfg->masterStr;    
1888     zMI = pP->zone.master;    
1889     
1890     TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1892     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1893                          PAF_SIO_CONTROL_SET_SOURCESELECT,
1894                          DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1895     {
1896         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1897         return errno;
1898     }
1899     //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1900     //                                            pC->xDec[zMD].decodeStatus.bufferRatio);
1901     frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1903     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1904                          PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1905     {
1906         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1907             errno, ASPERR_AUTO_LENGTH);
1908         return ASPERR_AUTO_LENGTH;
1909     }
1911     if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1912                           &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1913                           PAF_SIO_REQUEST_SYNC))
1914     {
1915         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1916             errno, ASPERR_ISSUE);
1917         return ASPERR_ISSUE;
1918     }
1920     TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1922     // all of the sync scan work is done in this call. If the error returned
1923     // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1924     // error so we mask it off.
1925     nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1926     if (nbytes == -DIBERR_SYNC)
1927     {
1928 #if 0 // (***) FL: shows timing of autosync restart
1929         // (***) debug // B5
1930         {
1931             static Uint8 toggleState = 0;
1932             if (toggleState == 0)
1933                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
1934             else
1935                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
1936             toggleState = ~(toggleState);
1937         }
1938 #endif        
1939         
1940         TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1941         return nbytes;
1942     }
1943     if (nbytes != sizeof(PAF_InpBufConfig))
1944     {
1945         TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1946             nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1947         return ASPERR_RECLAIM;
1948     }
1949     if (errno)
1950     {
1951         TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1952     }
1953     return errno;
1954 } //PAF_ASIT_autoProcessing
1956 UInt32 gProbe1Err=0;
1957 UInt32 gProbe2Err=0;
1958 UInt32 gMajorAuMissed=0;
1960 // -----------------------------------------------------------------------------
1961 // ASIT Processing Function - Decode Processing
1962 //
1963 //   Name:      PAF_ASIT_decodeProcessing
1964 //   Purpose:   Audio Stream Input Task Function for processing audio data.
1965 //   From:      audioStream1Task or equivalent
1966 //   Uses:      See code.
1967 //   States:    x
1968 //   Return:    Error number in standard form (0 on success).
1969 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1970 //              * State information on initialization (via children).
1971 //              * State information on processing (via children).
1972 //              * Decode warnings.
1973 //
1974 // When "writeDECModeContinuous" is used for zMI input/decode:
1975 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1976 // (a) if "writeDECCommandRestart" is used
1977 //    (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1978 // (b) if "writeDECSourceSelectNone" is used
1979 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1980 // (c) if an error occurs in
1981 //     INIT
1982 //     CONT ("subsequent block state", which "Establish[es] secondary timing")
1983 //         -> PAF_AST_decodeCont(): "Await slave inputs"
1984 //     STREAM (errno |= PAF_COMPONENT_ASP)
1985 //     ENCODE (errno |= PAF_COMPONENT_ENCODE)
1986 // [ the latter errors lead to "switch_break:"
1987 //         -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1988 //
1989 // [ Notably, in FINAL ("frame-finalization state")
1990 //         -> PAF_AST_decodeFinalTest() is *not* called,
1991 //   and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1992 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1993 //
1994 // States in which error can't occur:
1995 //     AGAIN ("subsequent initial state")
1996 //
1997 // States in which (some) errors must be handled:
1998 //     INFO1 ("first frame state")
1999 //         -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
2000 //            -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
2001 //               ?*? but what about ASPERR_RESYNC from same call ?*?
2002 //            -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
2003 //            -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
2004 //         -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
2005 //            - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
2006 //            - enc->fxns->info()
2007 //            - pP->fxns->setCheckRateX()
2008 //            - pP->fxns->startOutput()
2009 //            - "Start slave inputs if necessary"
2010 //     INFO2 ("subsequent frame state")
2011 //         -> PAF_AST_decodeInfo(): (see above)
2012 //         -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
2013 //            - pP->fxns->setCheckRateX()
2014 //     TIME ("timing state")
2015 //         -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
2016 //         -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
2017 //         -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
2018 //            (*OK* don't try to recover from this*)
2019 //         -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
2020 //         -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
2021 //            possibly in PAF_AST_decodeProcessing() itself **
2022 //     DECODE ("decode state")
2023 //         -> PAF_AST_decodeDecode(): pass on error from
2024 //            - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
2025 //            - dec->fxns->reset()
2026 //            - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
2027 //         -> *DONE* must catch error from (zMI) dec->fxns->decode()
2028 //         -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
2029 Int
2030 PAF_ASIT_decodeProcessing(
2031     const PAF_ASIT_Params *pP, 
2032     const PAF_ASIT_Patchs *pQ, 
2033     PAF_ASIT_Config *pC, 
2034     Int sourceSelect
2037     PAF_AST_Config *pAstCfg;
2038     //Int as = pC->as;                    /* Audio Stream Number (1, 2, etc.) */
2039     Int z;                              /* decode counter */
2040     Int errno;                          /* error number */
2041     Int getVal;
2042     enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
2043     ALG_Handle alg[DECODEN_MAX];
2044     Int zMD;
2045     Int zMS;
2046     Int size;
2047     //PAF_InpBufConfig *pIpBufConfig;
2048     Int frame; // decoder input frame count
2049     Int block; // (***) FL: formerly  -- decoder output block count / input frame
2050 #ifdef NON_CACHE_STATUS
2051     Int8 tempVar8, temp2Var8;
2052 #endif
2053     
2054     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2055     zMD = pAstCfg->masterDec;
2056     zMS = pAstCfg->masterStr;
2057         
2058     for (z=DECODE1; z < DECODEN; z++)
2059     {
2060         alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];        
2061     }
2062     alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
2064     //
2065     // Receive and process the data in single-frame buffers
2066     //
2068     state = INIT;
2069     errno = 0; /* error number */
2071 #ifdef NON_CACHE_STATUS
2072     statusOp_read(&tempVar8,
2073                   &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2074                   sizeof(tempVar8),
2075                   GATEMP_INDEX_DEC);
2076     TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
2078     for (;;) 
2079     {
2080         statusOp_read(&tempVar8,
2081                       &(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
2082                     sizeof(tempVar8),
2083                     GATEMP_INDEX_DEC);
2084         if (tempVar8 == PAF_SOURCE_NONE)
2085         {
2086 #else
2087     TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", pAstCfg->xDec[zMD].decodeStatus.sourceSelect);
2089     for (;;)
2090     {
2091         if (pAstCfg->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_NONE)
2092         {
2093 #endif
2094             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
2095             state = QUIT;
2096         }
2098         // Process commands (decode)
2099         if (getVal = pP->fxns->decodeCommand(pP, pQ, pC)) 
2100         {
2101             if (state != INIT)   // no need to restart/abort if not yet started
2102             {
2103                 if (getVal == ASPERR_QUIT)
2104                 {
2105                     state = QUIT;
2106                     TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
2107                 }
2108                 else if (getVal == ASPERR_ABORT)
2109                 {
2110                     TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
2111                     return getVal;
2112                 }
2113                 else
2114                 {
2115                     /* ignore */;
2116                 }
2117             }
2118             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
2119         }
2121         TRACE_TIME((&TIME_MOD,         "... + %d = %d ->", dtime(), TSK_time()));
2122         TRACE_TIME((&TIME_MOD,         "                 state = %s", stateName[state]));
2124         // Process state (decode)
2125         switch (state) 
2126         {
2127             case INIT: // initial state
2128                 gAsipInitCnt++;
2129                 Log_info0("TaskAsip: state=INIT");
2131 #if 0 // Not necessary since decoder status is in uncached memory
2132                 // status for shared beta units can change (e.g. at-boot or alpha)
2133                 
2134                 // write back Status structures for shared Beta Units
2135                 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2136                 //Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2137                 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2138                 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2139                 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2140                 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2141                 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
2142                 Cache_wb((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
2143                 Cache_wait();
2144 #endif
2145 #if 0 // Not necessary since decoder status is in uncached memory
2146                 ////size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2147                 ////Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2148                 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2149                 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2150                 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2151                 //Cache_wbInv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2152                 //Cache_wait();                
2153 #endif                
2154                 
2155                 if (errno = pP->fxns->decodeInit(pP, pQ, pC, sourceSelect))
2156                 {
2157                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x.  break after decodeInit", errno);
2158                     break;
2159                 }
2160                 
2161                 //
2162                 // Not necessary since decoder status is in uncached memory
2163                 //
2164                
2165 #if 0 // Not necessary since decoder status is in uncached memory
2166                 // invalidate Status structures for shared Beta Units
2167                 //size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
2168                 //Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
2169                 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
2170                 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
2171                 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
2172                 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
2173                 size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
2174                 Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
2175                 Cache_wait();
2176 #endif
2177                 
2178                 frame = 0;
2179                 block = 0;
2181                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2182                 state = INFO1;
2183                 continue;
2185             case INFO1: // first frame state
2186                 gAsipInfo1Cnt++;
2187                 Log_info0("TaskAsip: state=INFO1");
2188                 
2189 #if 0
2190                 //// (***) FL: revisit
2191                 //// write back Inp configuration
2192                 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2193                 //// write back input data
2194                 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2195                 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2196                 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2197                 //// write back Dec configuration
2198                 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2199                 //Cache_wait();            
2200 #endif                
2202                 // Establish primary timing
2203                 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2204                 {
2205                     gProbe1Err++;
2206                     TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2207                     break;
2208                 }
2209                 
2210 #if 0
2211                 //// (***) FL: revisit
2212                 //// invalidate Dec configuration
2213                 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2214                 //Cache_wait();                            
2215 #endif                
2218 #ifdef NON_CACHE_STATUS
2219                 statusOp_read(&tempVar8,
2220                               &(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2221                               sizeof(tempVar8),
2222                               GATEMP_INDEX_DEC);
2223                 statusOp_read(&temp2Var8,
2224                               &(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
2225                               sizeof(tempVar8),
2226                               GATEMP_INDEX_DEC);
2227                 // Don't start decode until major access unit is found.
2228                 if (((tempVar8 == PAF_SOURCE_THD)    ||
2229                      (tempVar8 == PAF_SOURCE_DXP)    ||
2230                      (tempVar8 == PAF_SOURCE_DTSHD)) &&
2231                      (temp2Var8 == PAF_SAMPLERATE_UNKNOWN)) 
2232 #else
2233                 // Don't start decode until major access unit is found.
2234                 if (((pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_THD)    ||
2235                      (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DXP)    ||
2236                      (pAstCfg->xDec[zMD].decodeStatus.sourceDecode == PAF_SOURCE_DTSHD)) &&
2237                      (pAstCfg->xDec[zMD].decodeStatus.sampleRate == PAF_SAMPLERATE_UNKNOWN))
2238 #endif
2239                 {
2240                     Int z;
2241                     for (z=DECODE1; z < DECODEN; z++) 
2242                     {
2243                         Int zI = pP->inputsFromDecodes[z];
2244 #ifdef NON_CACHE_STATUS
2245                         statusOp_read(&tempVar8,
2246                                       &(pAstCfg->xDec[z].decodeStatus.mode),
2247                                       sizeof(tempVar8),
2248                                       GATEMP_INDEX_DEC);
2249                         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2250                         {
2251 #else
2252                         if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2253                         {
2254 #endif
2255                             TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2256                             if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2257                                 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2258                             {
2259                                 gProbe2Err++;
2260                                 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2261                                 return (ASPERR_ISSUE);
2262                             }
2263                         }
2264                     }
2265                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2266                     gMajorAuMissed++; // debug
2267                     frame++;
2268                     state = INFO1;
2269                     continue;
2270                 }
2271                 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2273                 // Establish secondary timing
2274                 if (errno = pP->fxns->decodeInfo1(pP, pQ, pC, frame, block))
2275                 {
2276                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x.  break after decodeInfo1", errno);
2277                     break;
2278                 }
2280                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2281                 state = DECODE;
2282                 continue;
2284             case INFO2: // subsequent frame state
2285                 gAsipInfo2Cnt++;
2286                 Log_info0("TaskAsip: state=INFO2");
2288 #if 0            
2289                 //// (***) FL: revisit
2290                 //// write back Inp configuration
2291                 //Cache_wb(&gPAF_AST_config.xInp[0], INPUTN*sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2292                 //// write back input data
2293                 //pIpBufConfig = &gPAF_AST_config.xInp[0].inpBufConfig;
2294                 //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2295                 //Cache_wb(pIpBufConfig->pntr.pLgInt, size, Cache_Type_ALLD, 0);
2296                 //// write back Dec configuration
2297                 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2298                 //Cache_wait();
2299 #endif                
2301                 // Establish primary timing
2302                 if (errno = pP->fxns->decodeInfo(pP, pQ, pC, frame, block))
2303                 {
2304                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2305                     gAsipInfo2_PrimaryErrCnt++;
2306                     break;
2307                 }
2309 #if 0            
2310                 //// (***) FL: revisit
2311                 //// invalidate Dec configuration
2312                 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2313                 //Cache_wait();                                            
2314 #endif                
2315                 
2316                 if (errno = pP->fxns->decodeInfo2(pP, pQ, pC, frame, block))
2317                 {
2318                     TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2319                     gAsipInfo2_ErrCnt++;
2320                     break;
2321                 }
2323                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2324                 state = DECODE;
2325                 continue;
2327             case DECODE: // decode state
2328                 gAsipDecodeCnt++;
2329                 Log_info0("TaskAsip: state=DECODE");
2331 #if 0
2332                 //// (***) FL: revisit
2333                 //// write back Dec configuration
2334                 //Cache_wb(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2335                 //Cache_wait();                        
2336 #endif
2337             
2338                 if (errno = pP->fxns->decodeDecode(pP, pQ, pC, sourceSelect, frame, block))
2339                 {
2340                         gAsipDecodeErrCnt++;
2341                         TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
2342                     break;
2343                 }
2344       
2345 #if 0      
2346                 //// (***) FL: revisit
2347                 //// invalidate Dec configuration
2348                 //Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2349                 //Cache_wait();                                            
2350 #endif                
2351                 
2352                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2353                 state = FINAL;
2354                 continue;
2356             case FINAL: // frame-finalization state
2357                 gAsipFinalCnt++;
2358                 Log_info0("TaskAsip: state=FINAL");
2360                 // Check for final frame, and if indicated:
2361                 // - Exit state machine to "complete" processing.
2362                 if (pP->fxns->decodeFinalTest(pP, pQ, pC, frame, block)) 
2363                 {
2364                     break;
2365                 }
2367                 frame++;
2368                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2369                 state = INFO2;
2370                 continue;
2372             case QUIT: // exit state
2373                 gAsipQuitCnt++;
2374                 Log_info0("TaskAsip: state=QUIT");
2376                 // Quit:
2377                 // - Set error number registers.
2378                 // - Exit state machine to "decode complete" processing.
2379                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2380                 errno = ASPERR_QUIT;
2381                 break;
2383             default: // unknown state
2385                 // Unknown:
2386                 // - Set error number registers.
2387                 // - Exit state machine to "decode complete" processing.
2389                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2390                 errno = ASPERR_UNKNOWNSTATE;
2391                 break;
2393         }  // End of switch (state).
2395         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2396         if (pP->fxns->decodeComplete(pP, pQ, pC, alg, frame, block))
2397         {
2398             /* ignored? */;
2399         }
2401         TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2403         return errno;
2404     }  // End of for (;;) to Receive, process, and transmit the data.
2405 } //PAF_ASIT_decodeProcessing
2407 // -----------------------------------------------------------------------------
2408 // ASIT Decoding Function - Decode Command Processing
2409 //
2410 //   Name:      PAF_ASIT_decodeCommand
2411 //   Purpose:   Decoding Function for processing Decode Commands.
2412 //   From:      AST Parameter Function -> decodeProcessing
2413 //   Uses:      See code.
2414 //   States:    x
2415 //   Return:    Error number in standard form (0 on success).
2416 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2417 //              * Command execution.
2418 //
2420 Int
2421 PAF_ASIT_decodeCommand(
2422     const PAF_ASIT_Params *pP, 
2423     const PAF_ASIT_Patchs *pQ, 
2424     PAF_ASIT_Config *pC
2427     PAF_AST_Config *pAstCfg;
2428     Int as;                 /* Audio Stream Number (1, 2, etc.) */
2429     Int z;                  /* decode counter */
2430     Int zS;
2431 #ifdef NON_CACHE_STATUS
2432     Int8 tempVar8;
2433 #endif
2435     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2436     as = pAstCfg->as;
2438     for (z=DECODE1; z < DECODEN; z++) 
2439     {
2440         zS = pP->streamsFromDecodes[z];
2441 #ifdef NON_CACHE_STATUS
2442         statusOp_read(&tempVar8,
2443                       &(pAstCfg->xDec[z].decodeStatus.command2),
2444                       sizeof(tempVar8),
2445                       GATEMP_INDEX_DEC);
2446         if (!(tempVar8 & 0x80))
2447         {
2448             switch (tempVar8)
2449             {
2450                 case 0: // command none - process
2451                     tempVar8 |= 0x80;
2452                     statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2453                                    &tempVar8,
2454                                    sizeof(tempVar8),
2455                                    GATEMP_INDEX_DEC);
2456                     break;
2457                 case 1: // command abort - leave now
2458                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2459                     tempVar8 |= 0x80;
2460                     statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2461                                    &tempVar8,
2462                                    sizeof(tempVar8),
2463                                    GATEMP_INDEX_DEC);
2464                     return (ASPERR_ABORT);
2465                 case 2: // command restart - leave later
2466                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2467                     tempVar8 |= 0x80;
2468                     statusOp_write(&(pAstCfg->xDec[z].decodeStatus.command2),
2469                                    &tempVar8,
2470                                    sizeof(tempVar8),
2471                                    GATEMP_INDEX_DEC);
2472                     return (ASPERR_QUIT);
2473                 default: // command unknown - ignore
2474                     break;
2475             }
2476         }
2477 #else
2478         if (!(pAstCfg->xDec[z].decodeStatus.command2 & 0x80))
2479         {
2480             switch (pAstCfg->xDec[z].decodeStatus.command2)
2481             {
2482                 case 0: // command none - process
2483                     pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2484                     break;
2485                 case 1: // command abort - leave now
2486                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2487                     pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2488                     return (ASPERR_ABORT);
2489                 case 2: // command restart - leave later
2490                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2491                     pAstCfg->xDec[z].decodeStatus.command2 |= 0x80;
2492                     return (ASPERR_QUIT);
2493                 default: // command unknown - ignore
2494                     break;
2495             }
2496         }
2497 #endif
2498     }
2500     return 0;
2501 } //PAF_ASIT_decodeCommand
2503 // -----------------------------------------------------------------------------
2504 // ASIT Decoding Function - Reinitialization of Decode
2505 //
2506 //   Name:      PAF_ASIT_decodeInit
2507 //   Purpose:   Decoding Function for reinitializing the decoding process.
2508 //   From:      AST Parameter Function -> decodeProcessing
2509 //   Uses:      See code.
2510 //   States:    x
2511 //   Return:    Error number in standard or SIO form (0 on success).
2512 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2513 //              * State information as per parent.
2514 //
2515 Int
2516 PAF_ASIT_decodeInit(
2517     const PAF_ASIT_Params *pP, 
2518     const PAF_ASIT_Patchs *pQ, 
2519     PAF_ASIT_Config *pC, 
2520     Int sourceSelect
2523     PAF_AST_Config *pAstCfg;
2524     PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
2525     Int as;                             /* Audio Stream Number (1, 2, etc.) */
2526     Int z;                              /* decode/encode counter */
2527     Int errno;                          /* error number */
2528     Int zI, zS;
2529     Int zMD;
2530     Int zMI;
2531     ASP_Msg* pAspMsg;                   /* Messaging */
2532     Int argIdx;
2533     Int decErrno;
2534     Int status;
2535 #ifdef NON_CACHE_STATUS
2536     Int8 tempVar8;
2537 #endif
2538     
2539     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2540     as = pAstCfg->as;
2541     zMD = pAstCfg->masterDec;
2542     zMI = pP->zone.master;
2543     (void)as;  // clear compiler warning in case not used with tracing disabled
2544     
2545     pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2547 #ifdef NON_CACHE_STATUS
2548     // reset frameCount
2549     for (z=DECODE1; z < DECODEN; z++)
2550     {
2551         statusOp_read(&tempVar8,
2552                       &(pAstCfg->xDec[z].decodeStatus.mode),
2553                       sizeof(tempVar8),
2554                       GATEMP_INDEX_DEC);
2555         if (tempVar8)
2556         {
2557             tempVar8 = 0;
2558             statusOp_write(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2559                           &tempVar8,
2560                           sizeof(tempVar8),
2561                           GATEMP_INDEX_DEC);
2562         }
2563     }
2565     for (z=DECODE1; z < DECODEN; z++) 
2566     {
2567         zI = pP->inputsFromDecodes[z];
2568         zS = pP->streamsFromDecodes[z];
2569         (void)zS; // clear compiler warning in case not used with tracing disabled
2570         statusOp_read(&tempVar8,
2571                       &(pAstCfg->xDec[z].decodeStatus.mode),
2572                       sizeof(tempVar8),
2573                       GATEMP_INDEX_DEC);
2574         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2575         {
2576 #else
2577     // reset frameCount
2578     for (z=DECODE1; z < DECODEN; z++)
2579     {
2580         if (pAstCfg->xDec[z].decodeStatus.mode)
2581         {
2582             pAstCfg->xDec[z].decodeStatus.frameCount = 0;
2583         }
2584     }
2586     for (z=DECODE1; z < DECODEN; z++)
2587     {
2588         zI = pP->inputsFromDecodes[z];
2589         zS = pP->streamsFromDecodes[z];
2590         (void)zS; // clear compiler warning in case not used with tracing disabled
2591         if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2592         {
2593 #endif
2594             Uns gear;
2595             Int frameLength;
2596             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2598             // write back Dec configuration
2599             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2600             Cache_wait();
2602             // FL: send dec activate message to slave
2603             pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);  /* allocate message */
2604             if (pAspMsg == NULL)
2605             {
2606                 TRACE_TERSE0("MessageQ_alloc() failure.");
2607                 SW_BREAKPOINT; // temporary
2608                 return -1; // temporary
2609             }
2610             MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
2611             pAspMsg->cmd = ASP_SLAVE_DEC_ACTIVATE;                                              /* fill in message payload */
2612             pAspMsg->procId = hAspMsgMaster->masterProcId;
2613             pAspMsg->expectResp = TRUE;
2614             pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2615             argIdx = 0; // set decIdx (zone index)
2616             *(Int32 *)&pAspMsg->buf[argIdx] = z;
2617             TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2618             TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2619             status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);                       /* send message */
2620             if (status != MessageQ_S_SUCCESS)
2621             {
2622                 SW_BREAKPOINT;
2623             }
2624             // wait for dec activate complete message from slave
2625             status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2626             if (status != MessageQ_S_SUCCESS)
2627             {
2628                 TRACE_TERSE0("MessageQ_get() failure.");
2629                 SW_BREAKPOINT; // temporary
2630                 return -1; // temporary
2631             }
2632             if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) || 
2633                 (pAspMsg->cmd != ASP_MASTER_DEC_ACTIVATE_DONE) ||
2634                 (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2635             {
2636                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2637                 SW_BREAKPOINT; // temporary
2638                 return -1; // temporary
2639             }      
2640             hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2641             TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2642             // free the message
2643             status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2644             if (status != MessageQ_S_SUCCESS)
2645             {
2646                 SW_BREAKPOINT;
2647             }
2648             
2649 #if 0 // FL: decoder activate call, slave
2650             if (decAlg[z]->fxns->algActivate)
2651                 decAlg[z]->fxns->algActivate (decAlg[z]);
2652 #endif
2654             // FL: send dec reset message to slave
2655             pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);  /* allocate message */
2656             if (pAspMsg == NULL)
2657             {
2658                 TRACE_TERSE0("MessageQ_alloc() failure.");
2659                 SW_BREAKPOINT; // temporary
2660                 return -1; // temporary
2661             }
2662             MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
2663             pAspMsg->cmd = ASP_SLAVE_DEC_RESET;                                                 /* fill in message payload */
2664             pAspMsg->procId = hAspMsgMaster->masterProcId;
2665             pAspMsg->expectResp = TRUE;
2666             pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
2667             argIdx = 0; // set decIdx
2668             *(Int32 *)&pAspMsg->buf[argIdx] = z;
2669             TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2670             TRACE_MSG1("decIdx=%d", pAspMsg->buf[0]);
2671             // wait for dec reset complete message from slave
2672             status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
2673             if (status != MessageQ_S_SUCCESS)
2674             {
2675                 SW_BREAKPOINT;
2676             }
2677             status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
2678             if (status != MessageQ_S_SUCCESS)
2679             {
2680                 TRACE_TERSE0("MessageQ_get() failure.");
2681                 SW_BREAKPOINT; // temporary
2682                 return -1; // temporary
2683             }
2684             if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&
2685                 (pAspMsg->cmd == ASP_MASTER_DEC_RESET_DONE) && 
2686                 (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
2687             {
2688                 hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
2689                 TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2690                 TRACE_MSG1("decErrno=%d", pAspMsg->buf[0]);
2692                 argIdx = 0; // get decErrno
2693                 decErrno = *(Int32 *)&pAspMsg->buf[argIdx];
2694                 if (decErrno != 0)
2695                 {
2696                     return decErrno;
2697                 }
2698             }
2699             else
2700             {
2701                 TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
2702                 SW_BREAKPOINT; // temporary
2703                 return -1; // temporary
2704             }
2705             // free the message
2706             status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
2707             if (status != MessageQ_S_SUCCESS)
2708             {
2709                 SW_BREAKPOINT;
2710             }
2712             // (***) FL: revisit
2713             // invalidate Dec configuration
2714             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2715             Cache_wait();
2716             
2717 #if 0 // FL: decoder reset call, slave
2718             if (dec->fxns->reset
2719                 && (errno = dec->fxns->reset (dec, NULL,
2720                                               &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2721                 return errno;
2722 #endif
2723             
2724 #ifdef NON_CACHE_STATUS
2725             gear = 0;  // due to size difference
2726             statusOp_read(&gear,
2727                           &(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2728                           sizeof(Int8),
2729                           GATEMP_INDEX_DEC);
2730             tempVar8 = gear < GEARS ? gear : 0;
2731             statusOp_write(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2732                            &tempVar8,
2733                            sizeof(tempVar8),
2734                            GATEMP_INDEX_DEC);
2735 #else
2736             gear = pAstCfg->xDec[z].decodeStatus.aspGearControl;
2737             pAstCfg->xDec[z].decodeStatus.aspGearStatus = gear < GEARS ? gear : 0;
2738 #endif
2739             
2740 #if 0 // FL: change handle to decIdx (zone index)
2741             frameLength = pP->fxns->computeFrameLength(decAlg[z], 
2742                 FRAMELENGTH,
2743                 pC->xDec[z].decodeStatus.bufferRatio);
2744 #endif
2745 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2746             frameLength = pP->fxns->computeFrameLength(z, 
2747                 FRAMELENGTH, 
2748                 pC->xDec[z].decodeStatus.bufferRatio);
2749 #else
2750             if (sourceSelect == PAF_SOURCE_PCM)
2751             {
2752                 frameLength = 256;
2753             }
2754             else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2755             {
2756                 frameLength = 1536;
2757             }
2758             else if (sourceSelect == PAF_SOURCE_THD)
2759             {
2760                 frameLength = 1536; //QIN FIX ME
2761             }
2762             else
2763             {
2764                 frameLength = 256;
2765             }
2766 #endif    
2767             
2768             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2769             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2770             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2771             
2772             // (***) FL: revisit. Count samples for DDP.
2773             // Add framework frame length and running sample count to decoder control.
2774             //pC->xDec[z].decodeControl.pafFrameLength = FRAMELENGTH;
2775             //pC->xDec[z].decodeControl.rdSampleCount = 0;
2777             // Initialize decoder output circular buffer for selected source
2778             errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2779             if (errno)
2780             {
2781                 SW_BREAKPOINT; // FL: debug
2782                 return errno;
2783             }
2784             // FL: debug
2785             cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2786             
2787             if (z != zMD) 
2788             {
2789                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2790                 {
2791                     return errno;
2792                 }
2793             }
2795 #ifdef NON_CACHE_STATUS
2796             statusOp_read(&tempVar8,
2797                           &(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2798                           sizeof(Int8),
2799                           GATEMP_INDEX_DEC);
2800             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2801                 DECSIOMAP(tempVar8)))
2802             {
2803                 return errno;
2804             }
2805 #else
2806             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2807                 DECSIOMAP(pAstCfg->xDec[z].decodeStatus.sourceSelect)))
2808             {
2809                 return errno;
2810             }
2811 #endif
2812             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, 
2813                 frameLength))
2814             {
2815                 return errno;
2816             }
2817             if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus, 
2818                 &pAstCfg->xInp[zI].inpBufConfig))
2819             {
2820                 return errno;
2821             }
2822         }
2823     }
2825     if (pAstCfg->xInp[zMI].hRxSio) 
2826     {
2827         errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2828             sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2829         if (errno)
2830         {
2831             return errno;
2832         }
2833     }
2835     return 0;
2836 } //PAF_AST_decodeInit
2838 // -----------------------------------------------------------------------------
2839 // ASIT Decoding Function - Info Processing, Common
2840 //
2841 //   Name:      PAF_ASIT_decodeInfo
2842 //   Purpose:   Decoding Function for processing information in a manner that
2843 //              is common for both initial and subsequent frames of input data.
2844 //   From:      AST Parameter Function -> decodeProcessing
2845 //   Uses:      See code.
2846 //   States:    x
2847 //   Return:    Error number in standard form (0 on success).
2848 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2849 //              * State information as per parent.
2850 //
2851 Int
2852 PAF_ASIT_decodeInfo(
2853     const PAF_ASIT_Params *pP, 
2854     const PAF_ASIT_Patchs *pQ, 
2855     PAF_ASIT_Config *pC, 
2856     Int frame, 
2857     Int block
2860     PAF_AST_Config *pAstCfg;
2861     Int as;                    /* Audio Stream Number (1, 2, etc.) */
2862     Int z;                     /* input/decode/stream counter */
2863     Int errno;                 /* error number */
2864     Int sioErr;                /* error number, SIO */
2865     Int zD, zI, zS, zX;
2866     Int zMD;
2867     Int zMI;
2868     Int zMS;
2869     UInt32 curTime;
2870     ASP_Msg *pAspMsg;          /* Messaging */
2871     Int argIdx;
2872     Int status;
2873 #ifdef NON_CACHE_STATUS
2874     Int8 tempVar8;
2875     Int tempVar;
2876 #endif
2877     // FL: revisit
2878     //Int size;
2879     //PAF_InpBufConfig *pIpBufConfig;
2881     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
2882     as = pAstCfg->as;
2883     zMD = pAstCfg->masterDec;
2884     zMS = pAstCfg->masterStr;
2885     zMI = pP->zone.master;
2886     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
2887     
2888     // Set decode control: sample rate, emphasis
2889     for (z=INPUT1; z < INPUTN; z++)
2890     {
2891         zD = z;
2892         for (zX = DECODE1; zX < DECODEN; zX++) 
2893         {
2894             if (pP->inputsFromDecodes[zX] == z) 
2895             {
2896                 zD = zX;
2897           &nbs