]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamInpProc.c
Modified messaging code after code review.
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpProc.c
2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /*
37  *  ======== audioStreamInpProc.c ========
38  */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Diags.h>
43 #include <xdc/runtime/Error.h>
44 #include <xdc/runtime/Log.h>
45 #include <xdc/runtime/Memory.h>
46 #include <xdc/runtime/System.h>
47 #include <ti/sysbios/BIOS.h>
48 #include <ti/sysbios/hal/Hwi.h>
49 #include <ti/sysbios/hal/Cache.h>
50 #include <ti/sysbios/knl/Clock.h>
51 #include <ti/sysbios/knl/Task.h>
52 #include <ti/ipc/Ipc.h>
53 #include <ti/ipc/MessageQ.h>
54 #include <ti/ipc/MultiProc.h>
56 #include <sio.h>
57 #include <pafsio_ialg.h>
59 #include "common.h"
60 #include "paf_heapMgr.h"
61 #include "aspMsg_common.h"
62 #include "aspMsg_master.h"
63 #include "aspDecOpCircBuf_master.h"
64 #include "audioStreamProc_common.h"
65 #include "audioStreamProc_master.h"
66 #include "audioStreamInpProc.h"
67 #include "statusOp_common.h"
69 #include "pfp/pfp.h"
70 #include "pfp_app.h"        /* contains all PFP ID's */
71 Int32 gNumPfpAsit1=0; // debug
72 Int32 gNumPfpAsit2=0;
76 // FL: debug
77 #include "dbgCapAf.h"
80 // -----------------------------------------------------------------------------
81 // Debugging Trace Control, local to this file.
82 // 
83 #include "logp.h"
85 #define TRACE_ARC(a)
87 // allows you to set a different trace module in pa.cfg
88 #define TR_MOD  trace
90 // Allow a developer to selectively enable tracing.
91 #define CURRENT_TRACE_MASK      0x21
93 #define TRACE_MASK_TERSE        0x01   // only flag errors and show init
94 #define TRACE_MASK_GENERAL      0x02   // half dozen lines per frame
95 #define TRACE_MASK_VERBOSE      0x04   // trace full operation
96 #define TRACE_MASK_DATA         0x08   // Show data
97 #define TRACE_MASK_TIME         0x10   // Timing related traces
98 #define TRACE_MASK_MSG          0x20   // Message related traces
100 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
101     #undef  TRACE_TERSE0
102     #undef  TRACE_TERSE1
103     #undef  TRACE_TERSE2
104     #undef  TRACE_TERSE3
105     #undef  TRACE_TERSE4
106     #define TRACE_TERSE0(a)
107     #define TRACE_TERSE1(a,b)
108     #define TRACE_TERSE2(a,b,c)
109     #define TRACE_TERSE3(a,b,c,d)
110     #define TRACE_TERSE4(a,b,c,d,e)
111 #endif
113 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
114     #undef  TRACE_GEN0
115     #undef  TRACE_GEN1
116     #undef  TRACE_GEN2
117     #undef  TRACE_GEN3
118     #undef  TRACE_GEN4
119     #define TRACE_GEN0(a)
120     #define TRACE_GEN1(a,b)
121     #define TRACE_GEN2(a,b,c)
122     #define TRACE_GEN3(a,b,c,d)
123     #define TRACE_GEN4(a,b,c,d,e)
124 #endif
126 #if (CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
127     // consolidate list of processing strings, indexed by PAF_SOURCE
128     static char *procName[] =
129     {
130         "", //PAF_SOURCE_UNKNOWN
131         "", //PAF_SOURCE_NONE
132         "AS%d: Pass processing ...",   //PAF_SOURCE_PASS
133         "AS%d: SNG processing ...",    //PAF_SOURCE_SNG
134         "AS%d: Auto processing ...",   //PAF_SOURCE_AUTO
135         "AS%d: Auto processing ...",   //PAF_SOURCE_BITSTREAM
136         "AS%d: DTS processing ...",    //PAF_SOURCE_DTSALL
137         "AS%d: PCM processing ...",    //PAF_SOURCE_PCMAUTO
138         "AS%d: PCM processing ...",    //PAF_SOURCE_PCM
139         "AS%d: PCN processing ...",    //PAF_SOURCE_PC8
140         "AS%d: AC3 processing ...",    //PAF_SOURCE_AC3
141         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS
142         "AS%d: AAC processing ...",    //PAF_SOURCE_AAC
143         "AS%d: MPG processing ...",    //PAF_SOURCE_MPEG
144         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS12
145         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS13
146         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS14
147         "AS%d: DTS processing ...",    //PAF_SOURCE_DTS16
148         "AS%d: WMP processing ...",    //PAF_SOURCE_WMA9PRO
149         "AS%d: MP3 processing ...",    //PAF_SOURCE_MP3
150         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD1
151         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD2
152         "AS%d: DSD processing ...",    //PAF_SOURCE_DSD3
153         "AS%d: DDP processing ...",    //PAF_SOURCE_DDP
154         "AS%d: DTSHD processing ...",  //PAF_SOURCE_DTSHD
155         "AS%d: THD processing ...",    //PAF_SOURCE_THD
156         "AS%d: DXP processing ...",    //PAF_SOURCE_DXP
157         "AS%d: WMA processing ...",    //PAF_SOURCE_WMA
158     };
160 #else
161     #undef  TRACE_VERBOSE0
162     #undef  TRACE_VERBOSE1
163     #undef  TRACE_VERBOSE2
164     #undef  TRACE_VERBOSE3
165     #undef  TRACE_VERBOSE4
166     #define TRACE_VERBOSE0(a)
167     #define TRACE_VERBOSE1(a,b)
168     #define TRACE_VERBOSE2(a,b,c)
169     #define TRACE_VERBOSE3(a,b,c,d)
170     #define TRACE_VERBOSE4(a,b,c,d,e)
171 #endif
173 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
174     #define TRACE_DATA(a) LOG_printf a
175 #else
176     #define TRACE_DATA(a)
177 #endif
179 #if (CURRENT_TRACE_MASK & TRACE_MASK_TIME)
180     #define TRACE_TIME(a) LOG_printf a
181     #define TIME_MOD  trace // this could be different
182     static Int dtime()
183     {
184          static Int old_time = 0;
185          Int time = TSK_time();
186          Int delta_time = time - old_time;
187          old_time = time;
188          return( delta_time);
189     }
191     static char *stateName[11] =
192     {
193          "INIT",
194          "INFO1",
195          "AGAIN",
196          "INFO2",
197          "CONT",
198          "TIME",
199          "DECODE",
200          "STREAM",
201          "ENCODE",
202          "FINAL",
203          "QUIT"
204     };
206 #else
207     #define TRACE_TIME(a)
208 #endif
210 #if !(CURRENT_TRACE_MASK & TRACE_MASK_MSG)
211     #undef  TRACE_MSG0
212     #undef  TRACE_MSG1
213     #undef  TRACE_MSG2
214     #undef  TRACE_MSG3
215     #undef  TRACE_MSG4
216     #define TRACE_MSG0(a)
217     #define TRACE_MSG1(a,b)
218     #define TRACE_MSG2(a,b,c)
219     #define TRACE_MSG3(a,b,c,d)
220     #define TRACE_MSG4(a,b,c,d,e)
221 #endif
222     
224 // .............................................................................
226 #include <pafsio.h>
227 #include "paferr.h"
229 #include <acp_mds.h>
231 #include <pcm.h>
233 #include <pce.h>
235 #include <doberr.h>
237 #include <diberr.h>
239 #include <stdasp.h>
241 #include "as0.h"
242 #include "asperr.h"
244 #include "audioStreamProc_params.h"
245 #include "audioStreamProc_patchs.h"
246 #include "audioStreamProc_config.h"
247 #include "audioStreamInpProc.h"
250 #include "dbgBenchmark.h" // PCM high-sampling rate + SRC + CAR benchmarking
251 #ifdef _ENABLE_BENCHMARK_PCMHSR_SRC_CAR_
252 //
253 // Performing PCM high-sampling rate + SRC + CAR benchmarking
254 //
256 #define PROFILER
257 #endif
259 #ifdef PROFILER
260 extern UInt32 start_profiling;
261 #endif
263 extern UInt32 gAspProfileEnable;
265 //
266 // Audio Stream Definitions
267 //
269 // minimum audio frame "length" in samples (must be multiple of PA_MODULO)
270 #define MINFRAMELENGTH 24
271 #define PA_MODULO       8   // also defined independently in ARC2 code, and may be hard coded other places.
274 //
275 // Decoder Definitions
276 //
277 //#define decLinkInit pQ->i_decLinkInit
279 //
280 // Audio Stream Processing Definitions
281 //
282 //#define aspLinkInit pQ->i_aspLinkInit
284 //
285 // Encoder Definitions
286 //
287 #define encLinkInit pQ->i_encLinkInit
289 //
290 // Input, Output Definitions
291 //
292 #define inpLinkInit pP->i_inpLinkInit
293 //#define outLinkInit pP->i_outLinkInit
295 /* ---------------------------------------------------------------- */
296 /*              Parameter macro definitions end here.               */
297 /* ---------------------------------------------------------------- */
299 //
300 // Standardized Definitions
301 //
303 //#define DEC_Handle PCM_Handle /* works for all: SNG, PCM, AC3, DTS, AAC */
304 //#define ENC_Handle PCE_Handle /* works for all: PCE */
306 #define __TASK_NAME__  "TaskAsip"
308 LINNO_DEFN(TaskAsip); /* Line number macros */
309 ERRNO_DEFN(TaskAsip); /* Error number macros */
311 // ASIT configuration
312 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
313 PAF_ASIT_Config gPAF_ASIT_config = {
314     NULL,               // taskHandle
315     NULL,               // acp
316     &gPAF_ASPM_config,  // pAspmCfg, shared ASIT/ASOT configuration
317     &gPAF_AST_config    // pAstCfg, shared ASIT/ASOT/ASDT configuration
318 };
320 // Global debug counters */
321 UInt32 gTaskAsipCnt             =0;
322 UInt32 gAsipInitCnt             =0;
323 UInt32 gAsipInfo1Cnt            =0;
324 UInt32 gAsipInfo2Cnt            =0;
325 UInt32 gAsipDecodeCnt           =0;
326 UInt32 gAsipDecodeErrCnt        =0;
327 UInt32 gAsipFinalCnt            =0;
328 UInt32 gAsipQuitCnt             =0;
329 UInt32 gAsipInfo1_PrimaryErrCnt =0;
330 UInt32 gAsipInfo1_ErrCnt        =0;
331 UInt32 gAsipInfo2_PrimaryErrCnt =0;
332 UInt32 gAsipInfo2_ErrCnt        =0;
333 UInt32 gCapIbReset_cnt          =0;
334 UInt32 gCapIb_cnt               =0;
335 // debug
336 UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count (returned from ARM to DSP)
337                                    
339 #include "dbgDib.h" // debug
341 extern struct {
342     Int size;
343     IALG_Status *pStatus[512];
344 } IACP_STD_BETA_TABLE;
346 // FL: debug
347 #include "evmc66x_gpio_dbg.h"
349 /*
350  *  ======== taskAsipFxn ========
351  *  Audio Stream Input Processing task function
352  */
353 Void taskAsipFxn(
354 //    Int betaPrimeValue, // FL: revisit
355     const PAF_ASIT_Params *pP,
356     const PAF_ASIT_Patchs *pQ
359     PAF_ASIT_Config *pAsitCfg;      /* ASIT configuration pointer */
360     PAF_AST_Config *pAstCfg;        /* AST Common (shared) configuration pointer */
361     Int as;                         /* Audio Stream Number (1, 2, etc.) */
362     Int z;                          /* input/encode/stream/decode/output counter */
363     Int i;                          /* phase */
364     Int errno;                      /* error number */
365     Int zMD, zMI, zMS, zX;
366     Int loopCount = 0;  // used to stop trace to see startup behavior.        
367     UInt32 curTime;
368     Int size;
369     // Messaging
370     ASP_Msg *pAspMsg;              
371     Int status;
372     Int8 tempVar8;
373     char asipMsgBuf[ASP_MSG_BUF_LEN];
375     Log_info0("Enter taskAsipFxn()");
377     //
378     // Audio Stream Input Task Parameters & Patch (*pP, *pQ)
379     //
380     if (!pP) 
381     {
382         TRACE_TERSE0("TaskAsip: No Parameters defined. Exiting.");
383         LINNO_RPRT(TaskAsip, -1);
384         return;
385     }
387     if (!pQ)
388     {
389         TRACE_TERSE0("TaskAsip: No Patchs defined. Exiting.");
390         LINNO_RPRT(TaskAsip, -1);
391         return;
392     }    
393     
394     //
395     // Audio Stream Input Task Configuration (*pAsitCfg):
396     //
397     pAsitCfg = &gPAF_ASIT_config;       // initialize pointer to task configuration
398     pAsitCfg->taskHandle = Task_self(); // set task handle
399     pAstCfg = pAsitCfg->pAstCfg;        // get pointer to AST common (shared) configuration
401     /* Set Audio Stream Number (1, 2, etc.) */
402     as = gBetaPrimeValue + 1;
403     pAstCfg->as = as;    
404     TRACE_TERSE1("TaskAsip: Started with AS%d.", as);
406     //
407     // Initialize message log trace and line number reporting
408     //
409     for (z=STREAM1; z < STREAMN; z++)
410     {
411         TRACE_TERSE1("TaskAsip: AS%d: initiated", as+z);
412     }
413     LINNO_RPRT(TaskAsip, -1);
414     
415     //
416     // Determine decoder and stream indices associated with the master input
417     //
418     zMI = pP->zone.master;
419     pAstCfg->masterDec = zMI;
420     pAstCfg->masterStr = zMI;
421     for (zX = DECODE1; zX < DECODEN; zX++)
422     {
423         if (pP->inputsFromDecodes[zX] == zMI)
424         {
425             pAstCfg->masterDec = zX;
426             pAstCfg->masterStr = pP->streamsFromDecodes[zX];
427             break;
428         }
429     }
430     zMD = pAstCfg->masterDec;
431     zMS = pAstCfg->masterStr;
433     // Initialize as per parametrized phases:
434     //
435     //   In standard form these are:
436     //      - Malloc: Memory Allocation
437     //      - Config: Configuration Initialization
438     //      - AcpAlg: ACP Algorithm Initialization and Local Attachment
439     //      - Common: Common Memory Initialization
440     //      - AlgKey: Dec/Enc chain to Array Initialization
441     //      - Device: I/O Device Initialization
442     //      - DecOpCircBuf: Decoder Output Circular Buffer
443     //      - Unused: (available)
444     //
445     LINNO_RPRT(TaskAsip, -2);
446     for (i=0; i < lengthof(pP->fxns->initPhase); i++)
447     {
448         Int linno;
449         if (pP->fxns->initPhase[i])
450         {
451             linno = pP->fxns->initPhase[i](pP, pQ, pAsitCfg);
452             if (linno) 
453             {
454                 LINNO_RPRT(TaskAsip, linno);
455                 return;
456             }
457         }
458         else 
459         {
460             TRACE_TERSE1("TaskAsip: AS%d: initialization phase - null", as+zMS);
461         }
462         TRACE_TERSE2("TaskAsip: AS%d: initialization phase - %d completed", as+zMS, i);
463         LINNO_RPRT(TaskAsip, -i-3);
464     }
466     //
467     // End of Initialization -- display memory usage report.
468     //
469     if (pP->fxns->memStatusPrint)
470     {
471         pP->fxns->memStatusPrint("ASIT MEMSTAT REPORT",
472             HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, 
473             HEAP_INTERNAL1_SHM, HEAP_EXTERNAL_SHM, HEAP_EXTERNAL_NONCACHED_SHM);
474     }
475     
476     // (***) FL: revisit
477     // write back AST shared configuration
478     Cache_wb(pAstCfg, sizeof(PAF_AST_Config), Cache_Type_ALLD, 0);
479     Cache_wait();
481     // (***) FL: revisit
482     // write back Dec configuration
483     Cache_wb(&pAstCfg->xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
484     Cache_wait();
486     // (***) FL: revisit
487     // write back entire beta table
488     Cache_wb((Ptr)(&IACP_STD_BETA_TABLE.pStatus[0]), 512*sizeof(IALG_Status *), Cache_Type_ALLD, 0);
489     Cache_wait();
490     
491     // FL: send start initialization message to slave
492     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
493     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
494     pAspMsg->cmd = ASP_SLAVE_START;                                                     /* fill in message payload */
495     pAspMsg->procId = hAspMsgMaster->masterProcId;
496     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
497     pAspMsg->expectResp = TRUE;
498     TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
499     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
500     if (status != MessageQ_S_SUCCESS)
501     {
502         SW_BREAKPOINT;
503     }
504     // wait for initialization complete message from slave
505     do {
506         //status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
507         status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0); // FL: no other thread is allowed to run until Slave finished startup
508     } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
509     if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
510         (pAspMsg->cmd != ASP_MASTER_START_DONE) || 
511         (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
512     {
513         TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
514         SW_BREAKPOINT;
515     }
516     hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
517     TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
518     status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
519     if (status != MessageQ_S_SUCCESS)
520     {
521         SW_BREAKPOINT;
522     }
524     // (***) FL: revisit
525     // invalidate Status structure addresses for Beta Units initialized on Slave
526     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
527     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
528     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
529     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
530     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
531     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
532     Cache_inv((Ptr)(&IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(IALG_Status *), Cache_Type_ALLD, 0);
533     Cache_wait();
534     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]) Log_info0("ERROR: beta unit for Dec==NULL");
535     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]) Log_info0("ERROR: beta unit for Dec==NULL");
536     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]) Log_info0("ERROR: beta unit for Dec==NULL");
537     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]) Log_info0("ERROR: beta unit for Dec==NULL");
538     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]) Log_info0("ERROR: beta unit for Dec==NULL");
539     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]) Log_info0("ERROR: beta unit for Dec==NULL");
540     if (!IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]) Log_info0("ERROR: beta unit for Dec==NULL");
541     
542     // (***) FL: revisit
543     // invalidate Status structures for Beta Units initialized on Slave
544     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), sizeof(Int), Cache_Type_ALLD, 0);
545     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]->size;
546     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DECODE]), size, Cache_Type_ALLD, 0);
547     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), sizeof(Int), Cache_Type_ALLD, 0);
548     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]->size;
549     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM]), size, Cache_Type_ALLD, 0);
550     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), sizeof(Int), Cache_Type_ALLD, 0);
551     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]->size;
552     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_PCM2]), size, Cache_Type_ALLD, 0);
553     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), sizeof(Int), Cache_Type_ALLD, 0);
554     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]->size;
555     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP]), size, Cache_Type_ALLD, 0);
556     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), sizeof(Int), Cache_Type_ALLD, 0);
557     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]->size;
558     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_DDP2]), size, Cache_Type_ALLD, 0);
559     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), sizeof(Int), Cache_Type_ALLD, 0);
560     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]->size;
561     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD]), size, Cache_Type_ALLD, 0);
562     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), sizeof(Int), Cache_Type_ALLD, 0);
563     size = IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]->size;
564     Cache_inv((Ptr)(IACP_STD_BETA_TABLE.pStatus[STD_BETA_THD2]), size, Cache_Type_ALLD, 0);
565     Cache_wait();
566     
567 #ifdef NON_CACHE_STATUS
568     // Get the shared status structure GateMP handles. Initialized at slave.
569     if (statusOp_Init(GATEMP_INDEX_DEC) == STATUSOP_INIT_FAIL)
570     {
571         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DEC);
572     }
573     if (statusOp_Init(GATEMP_INDEX_DDP) == STATUSOP_INIT_FAIL)
574     {
575         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_DDP);
576     }
577     if (statusOp_Init(GATEMP_INDEX_PCM) == STATUSOP_INIT_FAIL)
578     {
579         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_PCM);
580     }
581     if (statusOp_Init(GATEMP_INDEX_THD) == STATUSOP_INIT_FAIL)
582     {
583         Log_info1("TaskAfp: Gate Index %d:Open status GateMP Fail.", GATEMP_INDEX_THD);
584     }
585 #endif
587     // (***) FL: revisit
588     // invalidate Dec configuration
589     Cache_inv(&gPAF_AST_config.xDec[0], DECODEN*sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
590     Cache_wait();
591     
592     //
593     // Main processing loop
594     //   
595     for (z=STREAM1; z < STREAMN; z++)
596     {
597         TRACE_VERBOSE1("TaskAsip: AS%d: running", as+z);
598     }
600     TRACE_TERSE0("TaskAsip: Entering Main Loop.");
601     
602     errno = 0;
603     for (;;)
604     {
605         Int sourceSelect;
606         XDAS_Int8 sourceProgram;
608         loopCount++;
610 #if 0   // enable and tune to see startup behavior.
611         // this is an alternative to fixed/circular setting in pa.cfg.
612         // If you are searching for a memory allocation failure, disable on first round.
613         // All allocation has already happened.
614         // This is the outer loop.  This loop count goes up when the stream resets.
615         // If the stream is running without problems, this does not increment.
616         // If the stream is repeatedly resetting, this loop count will go up rapidly.
617         if (loopCount > 10)  // see traces for a few of the passes through the main loop.
618         {
619              TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
620              LOG_disable(&TR_MOD);  // stop tracing
621         }
622 #endif
624         TRACE_GEN2("TaskAsip (begin Main loop %d) (errno 0x%x)", loopCount, errno);
625         TRACE_TIME((&TIME_MOD, "as1_f2... + %d = %d (begin Main loop)", dtime(), TSK_time()));
626         
627         // since not decoding indicate such
628         pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_NONE);
630         // any error forces idling of input
631         if (errno) 
632         {
633             for (z=INPUT1; z < INPUTN; z++)
634             {
635                 if (pAstCfg->xInp[z].hRxSio)
636                 {
637                     SIO_idle(pAstCfg->xInp[z].hRxSio);
638                 }
639             }
640         
641             TRACE_TERSE1("TaskAsip: Trace stopped at loop %d.", loopCount);
642             ERRNO_RPRT(TaskAsip, errno);
643         }
644         
645         // Execute a TSK_sleep to ensure that any non-blocking code paths are broken
646         // up to allow lower priority tasks to run. This may seem odd to be at the top
647         // of the state machine but provides for a cleaner flow even though the very
648         // first time we enter we do a sleep which is non-intuitive.
649         TRACE_VERBOSE1("TaskAsip: AS%d: ... sleeping ...", as+zMS);
650         TRACE_TIME((&TIME_MOD, "as1-f2... + %d = %d (begin SLEEP)", dtime(), TSK_time()));
651         Task_sleep(1);
653         TRACE_GEN1("TaskAsip: AS%d: Input device selection ...", as+zMS);
654         errno = pP->fxns->selectDevices(pP, pQ, pAsitCfg);
655         if (errno)
656         {
657             TRACE_TERSE2("TaskAsip: selectDevices returned errno = 0x%04x at line %d. AS%d", errno, as+zMS);
658             continue;
659         }
661         // if no master input selected then we don't know what may be at the input
662         // so set to unknown and skip any remaining processing
663         if (!pAstCfg->xInp[zMI].hRxSio)
664         {
665             sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), 
666                                (Int8)PAF_SOURCE_UNKNOWN, GATEMP_INDEX_DEC);
668             TRACE_VERBOSE1("TaskAsip: AS%d: No input selected...", as+zMS);
669             continue;
670         }
671         
672         // if here then we have a valid input so query its status
673         errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufStatus, &pAstCfg->xInp[zMI].inpBufConfig);
674         if (errno)
675         {
676             TRACE_VERBOSE1("TaskAsip: continue as updateInputStatus returns 0x%x", errno);
677             continue;
678         }
680         // If master decoder is not enabled, or the input is unlocked, then do nothing
681         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode), 
682                                      GATEMP_INDEX_DEC);
683         if (!tempVar8 || !pAstCfg->xInp[zMI].inpBufStatus.lock)
684         {
685             TRACE_VERBOSE0("TaskAsip: Not locked, continue");
686             continue;
687         }
688         
689         // If no source selected then do nothing
690         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
691                                      GATEMP_INDEX_DEC);
692         if (tempVar8 == PAF_SOURCE_NONE)
693         {
694             sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), 
695                                (Int8)PAF_SOURCE_NONE, GATEMP_INDEX_DEC);
696             TRACE_VERBOSE1("TaskAsip: AS%d: no source selected, continue", as+zMS);
697             continue;
698         }
700         // If we want pass processing then proceed directly
701         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
702                                      GATEMP_INDEX_DEC);
703         if (tempVar8 == PAF_SOURCE_PASS)
704         {
705             TRACE_VERBOSE1("TaskAsip: AS%d: Pass processing ...", as+zMS);
706             sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), 
707                                (Int8)PAF_SOURCE_PASS, GATEMP_INDEX_DEC);
709             pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_PASS);
710             if (pP->fxns->passProcessing)
711             {
712                 errno = pP->fxns->passProcessing(pP, pQ, pAsitCfg, NULL);                
713             }
714             else 
715             {
716                 TRACE_TERSE2("TaskAsip: AS%d: Pass Processing not supported, errno 0x%x", as+zMS, ASPERR_PASS);
717                 errno = ASPERR_PASS;
718             }
719             TRACE_VERBOSE0("TaskAsip: continue");
720             continue;
721         }
723         // .....................................................................
724         // At this point we have an enabled input and want to decode something.
725         // If no decoder selected then do nothing. Need to reset the sourceProgram, since
726         // when no decoder is selected there are no calls to IB
727         //if (errno = pP->fxns->autoProcessing(pP, pQ, pC, pC->xDec[zMD].decodeStatus.sourceSelect, pC->xDec[zMD].decAlg[PAF_SOURCE_PCM]))
728         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
729                                      GATEMP_INDEX_DEC);
730         pfpBegin(PFP_ID_ASIT_1, pAsitCfg->taskHandle);  // PFP begin
731         gNumPfpAsit1++;
732         errno = pP->fxns->autoProcessing(pP, pQ, pAsitCfg, tempVar8, NULL);
733         pfpEnd(PFP_ID_ASIT_1, PFP_FINISH_MEAS);         // PFP end
734         gNumPfpAsit1--;
736         if (errno) // (***) FL: re-visit this, hard-coded to use PCM framelength inside function
737         {
738             TRACE_VERBOSE1("TaskAsip: autoProcessing returns 0x%x, continue", errno);
739             continue;
740         }
741         
742         // query for input type
743         errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM, (Arg )&sourceProgram);
744         if (errno)
745         {
746             TRACE_TERSE2("TaskAsip: SIO_ctrl returns 0x%x, then 0x%x, continue", errno, ASPERR_AUTO_PROGRAM);
747             errno = ASPERR_AUTO_PROGRAM;
748             continue;
749         }
751         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram), 
752                            sourceProgram, GATEMP_INDEX_DEC);
754         // if input is unclassifiable then do nothing
755         if (sourceProgram == PAF_SOURCE_UNKNOWN)
756         {
757             TRACE_VERBOSE0("TaskAsip: Source program unknown. continue");
758             continue;
759         }
761         // now that we have some input classification, and possibly an outstanding
762         // input frame, we determine whether or not to call decodeProcessing and with
763         // what decAlg.
764         sourceSelect = PAF_SOURCE_NONE;
765         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
766                                      GATEMP_INDEX_DEC);
767         switch (tempVar8)
768         {
769             // If autodetecting, decoding everything, and input is something
770             // (i.e. bitstream or PCM) then decode.
771             case PAF_SOURCE_AUTO:
772                 if (sourceProgram >= PAF_SOURCE_PCM)
773                 {
774                     sourceSelect = sourceProgram;                    
775                 }
776                 break;
778             // If autodetecting, decoding only PCM, and input is PCM then decode.
779             case PAF_SOURCE_PCMAUTO:
780                 if (sourceProgram == PAF_SOURCE_PCM)
781                 {
782                     sourceSelect = sourceProgram;                    
783                 }
784                 break;
786             // If autodetecting, decoding only bitstreams, and input is a bitstream then decode.
787             case PAF_SOURCE_BITSTREAM:
788                 if (sourceProgram >= PAF_SOURCE_AC3)
789                 {
790                     sourceSelect = sourceProgram;                    
791                 }
792                 break;
794             // If autodetecting, decoding only DTS, and input is DTS then decode.
795             case PAF_SOURCE_DTSALL:
796                 switch (sourceProgram) 
797                 {
798                     case PAF_SOURCE_DTS11:
799                     case PAF_SOURCE_DTS12:
800                     case PAF_SOURCE_DTS13:
801                     case PAF_SOURCE_DTS14:
802                     case PAF_SOURCE_DTS16:
803                     case PAF_SOURCE_DTSHD:
804                         sourceSelect = sourceProgram;
805                         break;
806                 }
807                 break;
809             // All others, e.g., force modes, fall through to here.
810             // If user made specific selection then program must match select.
811             // (NB: this compare relies on ordering of PAF_SOURCE)
812             default:
813                 sourceSelect = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
814                                                               GATEMP_INDEX_DEC);
815                 if ((sourceSelect >= PAF_SOURCE_PCM) && (sourceSelect <= PAF_SOURCE_N))
816                 {
817                     if (sourceProgram != sourceSelect)
818                     {
819                         sourceSelect = PAF_SOURCE_NONE;                        
820                     }
821                 }
822                 break;
823         }
825         // if we didn't find any matches then skip
826         if (sourceSelect == PAF_SOURCE_NONE)
827         {
828             TRACE_VERBOSE0("TaskAsip: no matching source type, continue");
829             continue;
830         }
832         // FL: debug, reset IB capture buffer
833         capIbReset();
834         gCapIbReset_cnt++;
835         Log_info0("capIbReset()");
837         // FL: send source select message to slave
838         *(Int32 *)&asipMsgBuf[0] = sourceSelect;
839         if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE,
840                       asipMsgBuf, NULL) != ASP_MSG_NO_ERR)
841         {
842             TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
843             SW_BREAKPOINT;
844         }
845         
846         // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
847         // iff we are in this top level state machine and specifically not in decodeProcessing
848         pP->fxns->sourceDecode(pP, pQ, pAsitCfg, PAF_SOURCE_UNKNOWN);
849         
850         TRACE_VERBOSE1(procName[sourceProgram], as+zMS);
852         // Reduce priority level since autodetection complete
853         Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)-1);
854         
855         gAspProfileEnable=1; // enable ASP profiling
856         
857         TRACE_VERBOSE0("TaskAsip: calling decodeProcessing.");
858         errno = pP->fxns->decodeProcessing(pP, pQ, pAsitCfg, sourceSelect);
859         if (errno) 
860         {
861             TRACE_TERSE1("TaskAsip: decodeProcessing returns 0x%x, continue", errno);
862         }
863         else
864         {
865             TRACE_VERBOSE0("TaskAsip: decodeProcessing complete with no error.");
866         }        
868         gAspProfileEnable=0; // disable ASP profiling
869         
870         // Increase priority level since decoding complete
871         Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)+1);
873         // FL: send dec exit message to slave
874         if( AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL)
875             != ASP_MSG_NO_ERR)
876         {
877             TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
878             SW_BREAKPOINT;                
879         }
881     } // End of main processing loop for (;;)
882     
883     Log_info0("Exit taskAsipFxn()");
886 // -----------------------------------------------------------------------------
887 // ASIT Initialization Function - Memory Allocation
888 //
889 //   Name:      PAF_ASIT_initPhaseMalloc
890 //   Purpose:   Audio Stream Input Task Function for initialization of data pointers
891 //              by allocation of memory.
892 //   From:      audioStream1Task or equivalent
893 //   Uses:      See code.
894 //   States:    x
895 //   Return:    0 on success.
896 //              Source code line number on MEM_calloc failure.
897 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
898 //              * State information as per parent.
899 //              * Memory allocation errors.
900 //
901 Int
902 PAF_ASIT_initPhaseMalloc(
903     const PAF_ASIT_Params *pP, 
904     const PAF_ASIT_Patchs *pQ, 
905     PAF_ASIT_Config *pAsitCfg
908     PAF_AST_Config *pAstCfg;
909     Int as;                    /* Audio Stream Number (1, 2, etc.) */
910     Int zMS;
911     Error_Block    eb;
912         IHeap_Handle   decHeapHandle;
914     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
915     as = pAstCfg->as;
916     zMS = pAstCfg->masterStr;
917     
918     TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation", as+zMS);
920     // Initialize error block
921     Error_init(&eb); 
923     /* Input memory */
924     if (!(pAstCfg->xInp = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
925         INPUTN * sizeof (*pAstCfg->xInp), 4, &eb)))
926     {
927         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
928         SW_BREAKPOINT;
929         return __LINE__;
930     }
931     TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pAstCfg->xInp) %d bytes from space %d at 0x%x.",
932         INPUTN * sizeof (*pAstCfg->xInp),
933         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xInp);
935     /* Decode memory */
936 #ifdef NON_CACHE_STATUS
937     decHeapHandle = (IHeap_Handle)HEAP_EXTERNAL_NONCACHED_SHM;
938 #else 
939     decHeapHandle = (IHeap_Handle)HEAP_INTERNAL1_SHM;
940 #endif
941     if (!(pAstCfg->xDec = Memory_calloc(decHeapHandle,
942         DECODEN * sizeof (*pAstCfg->xDec), 4, &eb)))
943     {
944         TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: Memory_calloc failed", as+zMS);
945         SW_BREAKPOINT;
946         return __LINE__;
947     }
949     TRACE_TERSE3("PAF_ASIT_initPhaseMalloc. (pAstCfg->xDec) %d bytes from space %d at 0x%x.",
950         DECODEN * sizeof (*pAstCfg->xDec),
951         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDec);
952                 
953     TRACE_TERSE1("PAF_ASIT_initPhaseMalloc: AS%d: initialization phase - memory allocation complete.", as+zMS);
954     return 0;
955 } //PAF_ASIT_initPhaseMalloc
957 // -----------------------------------------------------------------------------
958 // ASIT Initialization Function - Memory Initialization from Configuration
959 //
960 //   Name:      PAF_ASIT_initPhaseConfig
961 //   Purpose:   Audio Stream Task Function for initialization of data values
962 //              from parameters.
963 //   From:      audioStream1Task or equivalent
964 //   Uses:      See code.
965 //   States:    x
966 //   Return:    0 on success.
967 //              Other as per initFrame0 and initFrame1.
968 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
969 //              * State information as per parent.
970 //
971 Int
972 PAF_ASIT_initPhaseConfig(
973     const PAF_ASIT_Params *pP, 
974     const PAF_ASIT_Patchs *pQ, 
975     PAF_ASIT_Config *pAsitCfg
978     PAF_AST_Config *pAstCfg;
979     Int as;                    /* Audio Stream Number (1, 2, etc.) */
980     Int z;                     /* input/encode/stream/decode/output counter */
981     Int zMS;
983     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
984     as = pAstCfg->as;
985     zMS = pAstCfg->masterStr;
986     
987     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration", as+zMS);
989     //
990     // Unspecified elements have been initialized to zero during alloc
991     //
992     
993     for (z=INPUT1; z < INPUTN; z++) 
994     {
995         pAstCfg->xInp[z].inpBufStatus = *pP->pInpBufStatus;
996         pAstCfg->xInp[z].inpBufConfig.pBufStatus = &pAstCfg->xInp[z].inpBufStatus;
997     }
999     for (z=DECODE1; z < DECODEN; z++) 
1000     {
1001         Int zI = pP->inputsFromDecodes[z];
1002         pAstCfg->xDec[z].decodeControl.size = sizeof(pAstCfg->xDec[z].decodeControl);
1003         pAstCfg->xDec[z].decodeControl.pInpBufConfig = (const PAF_InpBufConfig *)&pAstCfg->xInp[zI].inpBufConfig;
1004         //pC->xDec[z].decodeStatus = *pP->z_pDecodeStatus[z]; // FL: slave
1005     }
1007     TRACE_TERSE1("PAF_ASIT_initPhaseConfig: AS%d: initialization phase - configuration complete.", as+zMS);
1008     return 0;
1009 } //PAF_ASIT_initPhaseConfig
1011 // -----------------------------------------------------------------------------
1012 // ASIT Initialization Function - ACP Algorithm Instantiation
1013 //
1014 //   Name:      PAF_ASIT_initPhaseAcpAlg
1015 //   Purpose:   Audio Stream Input Task Function for initialization of ACP by
1016 //              instantiation of the algorithm.
1017 //   From:      audioStream1Task or equivalent
1018 //   Uses:      See code.
1019 //   States:    x
1020 //   Return:    0 on success.
1021 //              Source code line number on ACP Algorithm creation failure.
1022 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1023 //              * State information as per parent.
1024 //              * Memory allocation errors.
1025 //
1026 Int
1027 PAF_ASIT_initPhaseAcpAlg(
1028     const PAF_ASIT_Params *pP, 
1029     const PAF_ASIT_Patchs *pQ, 
1030     PAF_ASIT_Config *pAsitCfg
1033     PAF_AST_Config *pAstCfg;
1034     Int as;                 /* Audio Stream Number (1, 2, etc.) */
1035     Int z;                  /* input/encode/stream/decode/output counter */
1036     Int betaPrimeOffset;
1037     ACP_Handle acp;
1038     Int zMS;
1039     Int zS, zX;
1041     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1042     as = pAstCfg->as;
1043     zMS = pAstCfg->masterStr;
1044     
1045     TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm", as+zMS);
1047     ACP_MDS_init();
1049     if (!(acp = (ACP_Handle)ACP_MDS_create(NULL))) 
1050     {
1051         TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: ACP algorithm instance creation failed", as+zMS);
1052         return __LINE__;
1053     }
1054     pAsitCfg->acp = acp;
1056     ((ALG_Handle)acp)->fxns->algControl((ALG_Handle) acp,
1057         ACP_GETBETAPRIMEOFFSET, (IALG_Status *)&betaPrimeOffset);
1059     for (z=INPUT1; z < INPUTN; z++) 
1060     {
1061         zS = z;
1062         for (zX = DECODE1; zX < DECODEN; zX++) 
1063         {
1064             if (pP->inputsFromDecodes[zX] == z) 
1065             {
1066                 zS = pP->streamsFromDecodes[zX];
1067                 break;
1068             }
1069         }
1070         acp->fxns->attach(acp, ACP_SERIES_STD,
1071             STD_BETA_IB + betaPrimeOffset * (as-1+zS),
1072             (IALG_Status *)&pAstCfg->xInp[z].inpBufStatus);
1073         /* Ignore errors, not reported. */
1074     }
1076     TRACE_TERSE1("PAF_ASIT_initPhaseAcpAlg: AS%d: initialization phase - ACP Algorithm complete.", as+zMS);
1078     return 0;
1079 } //PAF_ASIT_initPhaseAcpAlg
1081 // -----------------------------------------------------------------------------
1082 // ASIT Initialization Function - Common Memory
1083 //
1084 //   Name:      PAF_ASIT_initPhaseCommon
1085 //   Purpose:   Audio Stream Input Task Function for allocation of common memory.
1086 //   From:      audioStream1Task or equivalent
1087 //   Uses:      See code.
1088 //   States:    x
1089 //   Return:    0 on success.
1090 //              Source code line number on PAF_ALG_alloc failure.
1091 //              Source code line number on PAF_ALG_mallocMemory failure.
1092 //              Source code line number on Decode Chain initialization failure.
1093 //              Source code line number on ASP Chain initialization failure.
1094 //              Source code line number on Encode Chain initialization failure.
1095 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1096 //              * State information as per parent.
1097 //              * Memory allocation errors.
1098 //
1099 Int
1100 PAF_ASIT_initPhaseCommon(
1101     const PAF_ASIT_Params *pP, 
1102     const PAF_ASIT_Patchs *pQ, 
1103     PAF_ASIT_Config *pAsitCfg
1106     PAF_AST_Config *pAstCfg;
1107     Int as;                     /* Audio Stream Number (1, 2, etc.) */
1108     Int z;                      /* stream counter */
1109     ACP_Handle acp;
1110     PAF_IALG_Config pafAlgConfig;
1111     IALG_MemRec common[3][PAF_IALG_COMMON_MEMN+1];
1112    
1113     acp = pAsitCfg->acp;
1114     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1115     as = pAstCfg->as;
1116     
1117     TRACE_TERSE0("PAF_ASIT_initPhaseCommon: initialization phase - Common Memory");
1119     //
1120     // Determine memory needs and instantiate algorithms across audio streams
1121     //
1122     TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_setup.");
1123     PAF_ALG_setup(&pafAlgConfig, 
1124         HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1125         HEAP_ID_INTERNAL1,              HEAP_INTERNAL1, 
1126         HEAP_ID_EXTERNAL,               HEAP_EXTERNAL, 
1127         HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM, 
1128         HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM, 
1129         HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1130         HEAP_CLEAR);
1132     if (pP->fxns->headerPrint)
1133     {
1134         pP->fxns->headerPrint();        
1135     }
1137     for (z = STREAM1; z < STREAMN; z++) 
1138     {
1139         TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: initialization phase - Common Memory", as+z);
1141         //
1142         // Determine common memory for:
1143         //  (1) Logical Input drivers
1144         //
1145         // Decode Algorithms common memory determined in ASP Slave.
1146         //
1147         PAF_ALG_init(common[z], lengthof(common[z]), COMMONSPACE);
1149         //
1150         // Determine common memory needs of Logical Input driver
1151         //
1153         // really need to loop over all inputs for this stream using the tables
1154         // inputsFromDecodes and streamsFromDecodes. But these don't exist for this
1155         // patch, and not needed for FS11, since there is only one input.
1156         if (INPUT1 <= z && z < INPUTN) 
1157         {
1158             TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: alloc inpLinkInit common[%d]", as+z, z);
1159             if (PAF_ALG_ALLOC(inpLinkInit[z-INPUT1], common[z]))
1160             {
1161                 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_alloc failed", as+z);
1162                 TRACE_TERSE2("failed to alloc %d bytes from space %d", common[z]->size, (IArg)common[z]->space);
1163                 SW_BREAKPOINT;
1164                 return __LINE__;
1165             }
1166             TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1167             if (pP->fxns->allocPrint)
1168             {
1169                 pP->fxns->allocPrint((const PAF_ALG_AllocInit *)(inpLinkInit[z-INPUT1]), sizeof (*(inpLinkInit[z-INPUT1])), &pafAlgConfig);
1170             }
1171         }
1172     }
1173     {
1174         // Changes made to share scratch between zones
1175         // Assume maximum 3 zones and scratch common memory is at offset 0;
1176         int max=0;
1177         for (z=STREAM1; z<STREAMN; z++)
1178         {
1179             if (max < common[z][0].size)
1180             {
1181                 max = common[z][0].size;
1182             }
1183         }
1184         common[STREAM1][0].size=max;
1185         for (z=STREAM1+1; z<STREAMN; z++)
1186         {
1187             common[z][0].size = 0;            
1188         }
1189     }
1190         
1191     //
1192     // Allocate common memory for:
1193     //  (1) Logical Input drivers
1194     //
1195     for (z = STREAM1; z < STREAMN; z++) 
1196     {
1197         TRACE_TERSE0("PAF_ASIT_initPhaseCommon: calling PAF_ALG_mallocMemory for common space.");
1198         if (PAF_ALG_mallocMemory(common[z], &pafAlgConfig)) 
1199         {
1200             TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: PAF_ALG_mallocMemory failed", as+z);
1201             TRACE_TERSE3("AS%d: z: %d.  Size 0x%x", as+z, z, common[z][0].size);
1202             SW_BREAKPOINT;
1203             return __LINE__;
1204         }
1205         TRACE_TERSE3("alloced %d bytes from space %d at 0x%x", common[z]->size, common[z]->space, (IArg)common[z]->base);
1206         // share zone0 scratch with all zones 
1207         common[z][0].base = common[0][0].base;
1208         if (pP->fxns->commonPrint)
1209         {
1210             pP->fxns->commonPrint(common[z], &pafAlgConfig);
1211         }
1213         //
1214         // Allocate non-common memories for Logical IO drivers
1215         //    Since these structures are used at run-time we allocate from external memory
1216         if (INPUT1 <= z && z < INPUTN) 
1217         {
1218             PAF_ASP_Chain *chain;
1219             TRACE_TERSE2("PAF_ASIT_initPhaseCommon: AS%d: non-common input chain init for %d",
1220                            as+z, z);
1221             chain = PAF_ASP_chainInit(&pAstCfg->xInp[z].inpChainData, pP->pChainFxns,
1222                         HEAP_EXTERNAL, as+z, acp, &trace,
1223                         inpLinkInit[z-INPUT1], NULL, common[z], &pafAlgConfig);
1224             if (!chain) 
1225             {
1226                 TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Input chain initialization failed", as+z);
1227                 return __LINE__;
1228             }
1229         }
1230     }
1231     TRACE_TERSE1("PAF_ASIT_initPhaseCommon: AS%d: Returning complete.", as+z);
1233     return 0;
1234 } //PAF_ASIT_initPhaseCommon
1236 // (***) FL: candidate for removal
1237 // -----------------------------------------------------------------------------
1238 // ASIT Initialization Function - Algorithm Keys
1239 //
1240 //   Name:      PAF_ASIT_initPhaseAlgKey
1241 //   Purpose:   Audio Stream Input Task Function for initialization of data values
1242 //              from parameters for Algorithm Keys.
1243 //   From:      audioStream1Task or equivalent
1244 //   Uses:      See code.
1245 //   States:    x
1246 //   Return:    0.
1247 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1248 //              * State information as per parent.
1249 //
1250 // .............................................................................
1251 Int
1252 PAF_ASIT_initPhaseAlgKey(
1253     const PAF_ASIT_Params *pP, 
1254     const PAF_ASIT_Patchs *pQ, 
1255     PAF_ASIT_Config *pAsitCfg
1258     PAF_AST_Config *pAstCfg;
1259     Int as;                    /* Audio Stream Number (1, 2, etc.) */
1261     
1262     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1263     as = pAstCfg->as;
1264     (void)as;  // clear compiler warning in case not used with tracing disabled
1266     TRACE_VERBOSE1("PAF_ASIT_initPhaseAlgKey: AS%d: initialization phase - Algorithm Keys", as);
1268 #if 0 // FL: slave    
1269     for (z=DECODE1; z < DECODEN; z++) 
1270     {
1271         for (s=0; s < pP->pDecAlgKey->length; s++) 
1272         {
1273             if ((pP->pDecAlgKey->code[s].full != 0) &&
1274                 (that = PAF_ASP_chainFind (&pC->xDec[z].decChainData, pP->pDecAlgKey->code[s]))) 
1275             {
1276                 pC->xDec[z].decAlg[s] = (ALG_Handle )that->alg;
1277                 /* Cast in interface, for now --Kurt */
1278             }
1279             else
1280             {
1281                 pC->xDec[z].decAlg[s] = NULL;
1282             }
1283         }
1284     }
1285 #endif
1287     return 0;
1288 } //PAF_ASIT_initPhaseAlgKey
1290 // -----------------------------------------------------------------------------
1291 // ASIT Initialization Function - I/O Devices
1292 //
1293 //   Name:      PAF_ASIT_initPhaseDevice
1294 //   Purpose:   Audio Stream Input Task Function for initialization of I/O Devices.
1295 //   From:      audioStream1Task or equivalent
1296 //   Uses:      See code.
1297 //   States:    x
1298 //   Return:    0 on success.
1299 //              Source code line number on device allocation failure.
1300 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1301 //              * State information as per parent.
1302 //              * Memory allocation errors.
1303 //
1304 Int
1305 PAF_ASIT_initPhaseDevice(
1306     const PAF_ASIT_Params *pP, 
1307     const PAF_ASIT_Patchs *pQ, 
1308     PAF_ASIT_Config *pAsitCfg
1311     PAF_AST_Config *pAstCfg;
1312     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1313     Int z;                              /* input/output counter */
1314     PAF_SIO_IALG_Obj    *pObj;
1315     PAF_SIO_IALG_Config *pAlgConfig;
1316     PAF_IALG_Config pafAlgConfig;
1319     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1320     as = pAstCfg->as;
1321     (void)as; // clear compiler warning in case not used with tracing disabled
1323     TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices", as);
1325     if (pP->fxns->bufMemPrint)
1326     {
1327         PAF_ALG_setup (&pafAlgConfig, 
1328             HEAP_ID_INTERNAL,               HEAP_INTERNAL, 
1329             HEAP_ID_INTERNAL1,              HEAP_INTERNAL1,
1330             HEAP_ID_EXTERNAL,               HEAP_EXTERNAL,
1331             HEAP_ID_INTERNAL1_SHM,          HEAP_INTERNAL1_SHM,
1332             HEAP_ID_EXTERNAL_SHM,           HEAP_EXTERNAL_SHM,
1333             HEAP_ID_EXTERNAL_NONCACHED_SHM, HEAP_EXTERNAL_NONCACHED_SHM,
1334             HEAP_CLEAR);
1335         TRACE_TERSE2("PAF_ASIT_initPhaseDevice: AS%d: calling PAF_ALG_setup with clear at %d.", as, HEAP_CLEAR);
1336     }
1338     for (z=INPUT1; z < INPUTN; z++) 
1339     {
1340         PAF_InpBufConfig *pConfig = &pAstCfg->xInp[z].inpBufConfig;
1342         pObj = (PAF_SIO_IALG_Obj *)pAstCfg->xInp[z].inpChainData.head->alg;
1343         pAlgConfig = &pObj->config;
1345         pAstCfg->xInp[z].hRxSio = NULL;
1347         pConfig->base.pVoid       = pAlgConfig->pMemRec[0].base;
1348         pConfig->pntr.pVoid       = pAlgConfig->pMemRec[0].base;
1349         pConfig->head.pVoid       = pAlgConfig->pMemRec[0].base;
1350         pConfig->futureHead.pVoid = pAlgConfig->pMemRec[0].base;
1351         pConfig->allocation       = pAlgConfig->pMemRec[0].size;
1352         pConfig->sizeofElement    = 2;
1353         pConfig->precision        = 16;
1355         if (pP->fxns->bufMemPrint)
1356         {
1357             pP->fxns->bufMemPrint(z, pAlgConfig->pMemRec[0].size, PAF_ALG_memSpaceToHeapId(&pafAlgConfig,pAlgConfig->pMemRec[0].space), 0);
1358         }
1359     }
1361     TRACE_TERSE1("PAF_ASIT_initPhaseDevice: AS%d: initialization phase - I/O Devices complete.", as);
1363     return 0;
1364 } //PAF_ASIT_initPhaseDevice
1366 // -----------------------------------------------------------------------------
1367 // ASIT Initialization Function - Decoder Output Circular Buffer
1368 //
1369 //   Name:      PAF_ASIT_initPhaseDecOpCircBuf
1370 //   Purpose:   Audio Stream Input Task Function for initialization of Decoder Output Circular Buffer.
1371 //   From:      audioStream1Task or equivalent
1372 //   Uses:      See code.
1373 //   States:    x
1374 //   Return:    0 on success.
1375 //              Source code line number on device allocation failure.
1376 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1377 //              * State information as per parent.
1378 //              * Memory allocation errors.
1379 //
1380 Int
1381 PAF_ASIT_initPhaseDecOpCircBuf(
1382     const PAF_ASIT_Params *pP, 
1383     const PAF_ASIT_Patchs *pQ, 
1384     PAF_ASIT_Config *pAsitCfg
1387     PAF_AST_Config *pAstCfg;
1388     PAF_AST_DecOpCircBuf *pCb;          /* Decoder output circular buffer */
1389     Int as;                             /* Audio Stream Number (1, 2, etc.) */
1390     Int zMS;
1391     Int z;                              /* decode counter */
1392     Int errno;                          /* error number */
1393     Error_Block    eb;
1394     Int i;
1396     // FL: (***)revisit
1397     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1398     as = pAstCfg->as;
1399     zMS = pAstCfg->masterStr;
1401     /* Decode output circular buffer memory */
1402     if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
1403         DECODEN * sizeof (*pAstCfg->xDecOpCb), 4, &eb)))
1404     {
1405         TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1406         SW_BREAKPOINT;
1407         return __LINE__;
1408     }
1410     TRACE_TERSE3("PAF_ASIT_initPhaseDecOpCircBuf. (pAsitCfg->xDecOpCb) %d bytes from space %d at 0x%x.",
1411         DECODEN * sizeof (*pAstCfg->xDecOpCb),
1412         HEAP_ID_INTERNAL1_SHM, (IArg)pAstCfg->xDecOpCb);
1413         
1414     for (z=DECODE1; z < DECODEN; z++)
1415     {
1416         pCb = &pAstCfg->xDecOpCb[z];
1417         
1418         // allocate audio frame circular buffer
1419         if (!(pCb->afCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, ASP_DECOP_CB_MAX_NUM_AF * sizeof(PAF_AudioFrame), 4, &eb)))
1420         {
1421             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1422             SW_BREAKPOINT;
1423         }
1424         // allocate audio frame PCM sample pointer array
1425         for (i = 0; i<ASP_DECOP_CB_MAX_NUM_AF; i++)
1426         {
1427             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)))
1428             {
1429                 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1430                 SW_BREAKPOINT;
1431             }
1432             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)))
1433             {
1434                 TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1435                 SW_BREAKPOINT;
1436             }                
1437         }
1438         // allocate PCM sample buffer
1439         if (!(pCb->pcmBuf = Memory_calloc((IHeap_Handle)HEAP_EXTERNAL_SHM, ASP_DECOP_CB_PCM_BUF_SZ * sizeof(PAF_AudioData), 4, &eb)))
1440         {
1441             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1442             SW_BREAKPOINT;
1443         }
1444         pCb->pcmBufEnd = pCb->pcmBuf + ASP_DECOP_CB_PCM_BUF_SZ;
1445         // allocate Metadata buffers //QIN
1446         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)))
1447         {
1448             TRACE_TERSE1("PAF_ASIT_initPhaseDecOpCircBuf: AS%d: Memory_calloc failed", as+zMS);
1449             SW_BREAKPOINT;
1450         }
1451         pCb->metaBufEnd = pCb->metaBuf + (ASP_DECOP_CB_MAX_NUM_AF * PAF_MAX_PRIVATE_MD_SZ * PAF_MAX_NUM_PRIVATE_MD);
1452         // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length        
1453         // Initialize decoder output circular buffer for PCM
1454         errno = cbInit(pCb);
1455         if (errno)
1456         {
1457             SW_BREAKPOINT; // FL: debug
1458             return errno;
1459         }
1460     }
1462     return 0;
1463 } //PAF_ASIT_initPhaseDecOpCircBuf
1466 #if 0
1467 // -----------------------------------------------------------------------------
1468 // AST Processing Function - Pass-Through Processing
1469 //
1470 //   Name:      PAF_AST_passProcessing
1471 //   Purpose:   Audio Stream Task Function for processing audio data as a
1472 //              pass-through from the input driver to the output driver
1473 //              for development and testing.
1474 //   From:      audioStream1Task or equivalent
1475 //   Uses:      See code.
1476 //   States:    x
1477 //   Return:    Error number in standard form (0 on success).
1478 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1479 //              * State information on initialization.
1480 //              * State information on processing.
1481 //
1483 #pragma CODE_SECTION(PAF_AST_passProcessing,".text:_PAF_AST_passProcessing")
1484 /* Pass Processing is often omitted from builds to save memory, */
1485 /* and CODE_SECTION/clink constructs facilitate this omission.  */
1487 Int
1488 PAF_AST_passProcessing(const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, Int hack)
1490     Int z;                              /* input/output counter */
1491     Int errno = 0;                      /* error number */
1492     Int getVal;
1493     Int rxNumChan, txNumChan;
1494     Int first;
1495     Int zMD = pC->masterDec;
1496     Int zMI = pP->zone.master;
1499 #ifndef __TI_EABI__
1500     asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1501 #endif    
1503     TRACE_VERBOSE0("PAF_AST_passProcessing: initializing");
1505     //
1506     // Determine that receive/transmit channels are compatible
1507     //
1509     // Can handle handle only master input
1510     for (z=INPUT1; z < INPUTN; z++) {
1511         if (z != zMI && pC->xInp[z].hRxSio)
1512             return (ASPERR_PASS + 0x01);
1513     }
1515     /* Number of receive/transmit channels */
1517     if (! pC->xInp[zMI].hRxSio)
1518         return (ASPERR_PASS + 0x11);
1519     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1520         return (ASPERR_PASS + 0x12);
1521     if (rxNumChan > NUM_TX_CHAN(zMI))
1522         return (ASPERR_PASS + 0x13);
1524     for (z=OUTPUT1; z < OUTPUTN; z++) {
1525         if (! pC->xOut[zMI].hTxSio)
1526             return (ASPERR_PASS + 0x10*(z+2) + 0x01);
1527         if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1528             return (ASPERR_PASS + 0x10*(z+2) + 0x02);
1529         if (txNumChan > NUM_TX_CHAN(zMI))
1530             return (ASPERR_PASS + 0x10*(z+2) + 0x03);
1531     }
1533     //
1534     // Set up receive/transmit
1535     //
1537     SIO_idle (pC->xInp[zMI].hRxSio);
1538     for (z=OUTPUT1; z < OUTPUTN; z++) {
1539         if(SIO_idle (pC->xOut[z].hTxSio))
1540             return ASPERR_IDLE;
1541     }
1543     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT, PAF_SOURCE_PCM))
1544         return (ASPERR_PASS + 0x14);
1546     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, FRAMELENGTH))
1547         return (ASPERR_PASS + 0x15);
1549     for (z=OUTPUT1; z < OUTPUTN; z++)
1550         pC->xOut[z].outBufConfig.lengthofFrame = FRAMELENGTH;
1552     if (SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_SYNC))
1553         return ASPERR_PASS + 0x16;
1555     if (SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr)&pC->xInp[zMI].pInpBuf, NULL) != sizeof (PAF_InpBufConfig))
1556         return ASPERR_PASS + 0x17;
1558     //
1559     // Receive and transmit the data in single-frame buffers
1560     //
1562     first = 1;
1563     while (pC->xDec[zMD].decodeStatus.sourceSelect == PAF_SOURCE_PASS) {
1564         PAF_OutBufConfig *pOutBuf;
1565         PAF_InpBufConfig *pInpBuf;
1567         if (first) {
1568             first = 0;
1570             TRACE_VERBOSE0("PAF_AST_passProcessing: starting output");
1572             for (z=OUTPUT1; z < OUTPUTN; z++) {
1573                 getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1574                 if (getVal > 0) {
1575                     errno = ASPERR_ISSUE;
1576                     break;
1577                 }
1578                 else if (getVal < 0) {
1579                     errno = -getVal;
1580                     break;
1581                 }
1583                 if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_UNMUTE, 0))
1584                     return (getVal & 0xff) | ASPERR_MUTE;
1585             }
1586             if (errno)
1587                 break;
1589         }
1591         getVal = SIO_issue (pC->xInp[zMI].hRxSio, &pC->xInp[zMI].inpBufConfig, sizeof (pC->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
1592         if (getVal > 0) {
1593             errno = ASPERR_ISSUE;
1594             break;
1595         }
1597         TRACE_VERBOSE1("PAF_AST_passProcessing: awaiting frame -- input size %d", rxNumChan * FRAMELENGTH);
1599         getVal = SIO_reclaim (pC->xInp[zMI].hRxSio, (Ptr) &pInpBuf, NULL);
1600         if (getVal < 0) {
1601             errno = -getVal;
1602             break;
1603         }
1605         for (z=OUTPUT1; z < OUTPUTN; z++) {
1606             getVal = SIO_reclaim (pC->xOut[z].hTxSio, (Ptr) &pOutBuf, NULL);
1607             if (getVal < 0) {
1608                 errno = -getVal;
1609                 break;
1610             }
1611         }
1612         if( errno )
1613             break;
1615         TRACE_VERBOSE0("PAF_AST_passProcessing: copying frame");
1617         if (errno = pP->fxns->passProcessingCopy (pP, pQ, pC))
1618             break;
1620         for (z=OUTPUT1; z < OUTPUTN; z++) {
1621             getVal = SIO_issue (pC->xOut[z].hTxSio, &pC->xOut[z].outBufConfig, sizeof(pC->xOut[z].outBufConfig), 0);
1622             if (getVal > 0) {
1623                 errno = ASPERR_ISSUE;
1624                 break;
1625             }
1626             else if (getVal < 0) {
1627                 errno = -getVal;
1628                 break;
1629             }
1630         }
1631         if( errno )
1632             break;
1633     }
1635     //
1636     // Close down receive/transmit
1637     //
1639     TRACE_TERSE0("PAF_AST_passProcessing: finalizing"));
1641     for (z=OUTPUT1; z < OUTPUTN; z++) {
1642         if (getVal = SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_MUTE, 0)) {
1643             if (! errno)
1644                 errno = (getVal & 0xff) | ASPERR_MUTE;
1645             /* convert to sensical errno */
1646         }
1647     }
1649     SIO_idle (pC->xInp[zMI].hRxSio);
1650     for (z=OUTPUT1; z < OUTPUTN; z++)
1651         SIO_idle (pC->xOut[z].hTxSio);
1653     return errno;
1655 } //PAF_AST_passProcessing
1656 #endif // #if 0
1658 #if 0
1659 // -----------------------------------------------------------------------------
1660 // AST Processing Function Helper - Pass-Through Processing Patch Point
1661 //
1662 //   Name:      PAF_AST_passProcessingCopy
1663 //   Purpose:   Pass-Through Processing Function for copying audio data
1664 //              from the input buffer to the output buffer.
1665 //   From:      AST Parameter Function -> passProcessing
1666 //   Uses:      See code.
1667 //   States:    x
1668 //   Return:    Error number in standard form (0 on success).
1669 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1670 //              x
1671 //
1673 #pragma CODE_SECTION(PAF_AST_passProcessingCopy,".text:_PAF_AST_passProcessingCopy")
1674 /* Pass Processing is often omitted from builds to save memory, */
1675 /* and CODE_SECTION/clink constructs facilitate this omission.  */
1677 Int
1678 PAF_AST_passProcessingCopy (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC)
1680     Int z;                              /* output counter */
1681     Int errno;                          /* error number */
1682     Int i;
1683     Int rxNumChan, txNumChan;
1684     Int zMI = pP->zone.master;
1687     asm (" .clink"); /* See comment above regarding CODE_SECTION/clink. */
1689     // Copy data from input channels to output channels one of two ways:
1691     if (SIO_ctrl (pC->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &rxNumChan))
1692         return (ASPERR_PASS + 0x12);
1694     for (z=OUTPUT1; z < OUTPUTN; z++) {
1695         if (SIO_ctrl (pC->xOut[z].hTxSio, PAF_SIO_CONTROL_GET_NUMCHANNELS, (Arg) &txNumChan))
1696             return (ASPERR_PASS + 0x22);
1698         if( txNumChan <= rxNumChan ) {
1700             // Copy one to one, ignoring later rx channels as needed.
1702             for( i=0; i < txNumChan; i++ ) {
1703                 errno = pP->fxns->copy( i, &pC->xInp[zMI].inpBufConfig, i, &pC->xOut[z].outBufConfig );
1704                 if( errno )
1705                     return errno;
1706             }
1707         }
1708         else {
1710             // Copy one to many, repeating earlier rx channels as needed.
1712             Int from, to;
1714             from = 0;
1715             to   = 0;
1716             while( to < txNumChan ) {
1717                 errno = pP->fxns->copy( from, &pC->xInp[zMI].inpBufConfig, to, &pC->xOut[z].outBufConfig );
1718                 if( errno )
1719                     return errno;
1721                 from++;
1722                 to++;
1723                 if( from == rxNumChan )
1724                     from = 0;
1725             }
1726         }
1727     }
1729     return 0;
1730 } //PAF_AST_passProcessingCopy
1731 #endif // #if 0
1733 // -----------------------------------------------------------------------------
1734 // ASIT Processing Function - Auto Processing
1735 //
1736 //   Name:      PAF_ASIT_autoProcessing
1737 //   Purpose:   Audio Stream Input Task Function for processing audio data to
1738 //              determine the input type without output.
1739 //   From:      audioStream1Task or equivalent
1740 //   Uses:      See code.
1741 //   States:    x
1742 //   Return:    Error number in standard or SIO form (0 on success).
1743 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1744 //              * State information on initialization.
1745 //
1747 #define DECSIOMAP(X)                                                \
1748     pP->pDecSioMap->map[(X) >= pP->pDecSioMap->length ? 0 : (X)]
1750 Int
1751 PAF_ASIT_autoProcessing(
1752     const PAF_ASIT_Params *pP, 
1753     const PAF_ASIT_Patchs *pQ, 
1754     PAF_ASIT_Config *pAsitCfg, 
1755     Int inputTypeSelect, 
1756     ALG_Handle pcmAlgMaster
1759     PAF_AST_Config *pAstCfg;
1760     Int as;                 /* Audio Stream Number (1, 2, etc.) */
1761     Int errno = 0;          /* error number */
1762     Int nbytes;
1763     Int frameLength;
1764     Int zMD;
1765     Int zMI;
1766     Int zMS;
1767     
1768     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1769     as = pAstCfg->as;
1770     zMD = pAstCfg->masterDec;
1771     zMS = pAstCfg->masterStr;    
1772     zMI = pP->zone.master;    
1773     
1774     TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: PAF_AST_autoProcessing", as+zMS);
1776     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1777                          PAF_SIO_CONTROL_SET_SOURCESELECT,
1778                          DECSIOMAP(pAstCfg->xDec[zMD].decodeStatus.sourceSelect)))
1779     {
1780         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: AS%d: source select returns 0x%x", as+zMS, errno);
1781         return errno;
1782     }
1783     //frameLength = pP->fxns->computeFrameLength (pcmAlgMaster, FRAMELENGTH,
1784     //                                            pC->xDec[zMD].decodeStatus.bufferRatio);
1785     frameLength = FRAMELENGTH; // FL: fix PCM frameLength for alpha release.
1787     if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio,
1788                          PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
1789     {
1790         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: SET_PCMFRAMELENGTH returns 0x%x, returning ASPERR_AUTO_LENGTH, 0x%x",
1791             errno, ASPERR_AUTO_LENGTH);
1792         return ASPERR_AUTO_LENGTH;
1793     }
1795     if (errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio,
1796                           &pAstCfg->xInp[zMI].inpBufConfig, sizeof(pAstCfg->xInp[zMI].inpBufConfig),
1797                           PAF_SIO_REQUEST_SYNC))
1798     {
1799         TRACE_VERBOSE2("PAF_ASIT_autoProcessing: REQUEST_SYNC returns 0x%x, returning ASPERR_ISSUE, 0x%x",
1800             errno, ASPERR_ISSUE);
1801         return ASPERR_ISSUE;
1802     }
1804     TRACE_VERBOSE1("PAF_ASIT_autoProcessing: AS%d: awaiting sync", as+zMS);
1806     // all of the sync scan work is done in this call. If the error returned
1807     // is DIBERR_SYNC then that just means we didn't find a sync, not a real I/O
1808     // error so we mask it off.
1809     nbytes = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
1810     if (nbytes == -DIBERR_SYNC)
1811     {
1812 #if 1 // (***) FL: shows timing of autosync restart
1813         // (***) debug // B5
1814         {
1815             static Uint8 toggleState = 0;
1816             if (toggleState == 0)
1817                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
1818             else
1819                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
1820             toggleState = ~(toggleState);
1821         }
1822 #endif                
1823         TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: SIO_reclaim returned 0x%x, ignoring", as+zMS, nbytes);
1824         return nbytes;
1825     }
1826     if (nbytes != sizeof(PAF_InpBufConfig))
1827     {
1828         TRACE_TERSE3("PAF_ASIT_autoProcessing. SIO_reclaim returned %d, not %d, returning ASPERR_RECLAIM (0x%x)",
1829             nbytes, sizeof(PAF_InpBufConfig), ASPERR_RECLAIM);
1830         return ASPERR_RECLAIM;
1831     }
1832     if (errno)
1833     {
1834         TRACE_TERSE2("PAF_ASIT_autoProcessing: AS%d: returning errno 0x%x", as+zMS, errno);
1835     }
1836     return errno;
1837 } //PAF_ASIT_autoProcessing
1839 UInt32 gProbe1Err=0;
1840 UInt32 gProbe2Err=0;
1841 UInt32 gMajorAuMissed=0;
1843 // -----------------------------------------------------------------------------
1844 // ASIT Processing Function - Decode Processing
1845 //
1846 //   Name:      PAF_ASIT_decodeProcessing
1847 //   Purpose:   Audio Stream Input Task Function for processing audio data.
1848 //   From:      audioStream1Task or equivalent
1849 //   Uses:      See code.
1850 //   States:    x
1851 //   Return:    Error number in standard form (0 on success).
1852 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
1853 //              * State information on initialization (via children).
1854 //              * State information on processing (via children).
1855 //              * Decode warnings.
1856 //
1857 // When "writeDECModeContinuous" is used for zMI input/decode:
1858 // PAF_AST_decodeProcessing() loop may be (is designed to be) exited:
1859 // (a) if "writeDECCommandRestart" is used
1860 //    (or "writeDECCommandAbort", but this performs no cleanup whatsoever, and so its use is discouraged)
1861 // (b) if "writeDECSourceSelectNone" is used
1862 // [ the latter events lead to QUIT state, simply for exiting (errme = errno = ASPERR_QUIT)
1863 // (c) if an error occurs in
1864 //     INIT
1865 //     CONT ("subsequent block state", which "Establish[es] secondary timing")
1866 //         -> PAF_AST_decodeCont(): "Await slave inputs"
1867 //     STREAM (errno |= PAF_COMPONENT_ASP)
1868 //     ENCODE (errno |= PAF_COMPONENT_ENCODE)
1869 // [ the latter errors lead to "switch_break:"
1870 //         -> PAF_AST_decodeComplete(), which always returns 0 (no error) ]
1871 //
1872 // [ Notably, in FINAL ("frame-finalization state")
1873 //         -> PAF_AST_decodeFinalTest() is *not* called,
1874 //   and so any other (asynchronous) changes in pC->xDec[zMD].decodeStatus.sourceSelect are ignored. ]
1875 // [ For completeness, note also: "default" state, internal check (errme = errno = ASPERR_UNKNOWNSTATE) ]
1876 //
1877 // States in which error can't occur:
1878 //     AGAIN ("subsequent initial state")
1879 //
1880 // States in which (some) errors must be handled:
1881 //     INFO1 ("first frame state")
1882 //         -> PAF_AST_decodeInfo(): pass on ASPERR_INFO_RATECHANGE, ASPERR_INFO_PROGRAM ("bad" internal error)
1883 //            -> *DONE* must "catch" ASPERR_RECLAIM from SIO_reclaim (pC->xInp[zMI].hRxSio) -- note zMI only **
1884 //               ?*? but what about ASPERR_RESYNC from same call ?*?
1885 //            -> *for now, at least, pass on error from pP->fxns->updateInputStatus ()*
1886 //            -> *DONE* must "catch" error from (zMI) dec->fxns->info() **
1887 //         -> PAF_AST_decodeInfo1(): pass on any errors which occur here:
1888 //            - pP->fxns->streamChainFunction (... PAF_ASP_CHAINFRAMEFXNS_RESET)
1889 //            - enc->fxns->info()
1890 //            - pP->fxns->setCheckRateX()
1891 //            - pP->fxns->startOutput()
1892 //            - "Start slave inputs if necessary"
1893 //     INFO2 ("subsequent frame state")
1894 //         -> PAF_AST_decodeInfo(): (see above)
1895 //         -> PAF_AST_decodeInfo2(): pass on any errors which occur here:
1896 //            - pP->fxns->setCheckRateX()
1897 //     TIME ("timing state")
1898 //         -> PAF_AST_decodeTime(): "Special timing consideations for AC-3"
1899 //         -> performs SIO_issue (... PAF_SIO_REQUEST_FULLFRAME) & SIO_reclaim() *for zMI only*
1900 //         -> now, DIB_issue [PAF_SIO_REQUEST_FULLFRAME] would only return SYS_EINVAL for "bad" internal error
1901 //            (*OK* don't try to recover from this*)
1902 //         -> much more likely would be SIO_reclaim() error (ASPERR_RECLAIM)
1903 //         -> *DONE* must "catch" (just) ASPERR_RECLAIM error -- note zMI only,
1904 //            possibly in PAF_AST_decodeProcessing() itself **
1905 //     DECODE ("decode state")
1906 //         -> PAF_AST_decodeDecode(): pass on error from
1907 //            - PAF_SIO_CONTROL_GET_NUM_REMAINING ("bad" internal error)
1908 //            - dec->fxns->reset()
1909 //            - PAF_SIO_CONTROL_SET_PCMFRAMELENGTH
1910 //         -> *DONE* must catch error from (zMI) dec->fxns->decode()
1911 //         -> *?* must catch ASPERR_ISSUE from (zMI) SIO_issue()
1912 Int
1913 PAF_ASIT_decodeProcessing(
1914     const PAF_ASIT_Params *pP, 
1915     const PAF_ASIT_Patchs *pQ, 
1916     PAF_ASIT_Config *pAsitCfg, 
1917     Int sourceSelect
1920     PAF_AST_Config *pAstCfg;
1921     //Int as = pAsitCfg->as;              /* Audio Stream Number (1, 2, etc.) */
1922     Int z;                              /* decode counter */
1923     Int errno;                          /* error number */
1924     Int getVal;
1925     enum { INIT, INFO1, INFO2, DECODE, FINAL, QUIT } state;
1926     ALG_Handle alg[DECODEN_MAX];
1927     Int zMD;
1928     Int zMS;
1929     Int size;
1930     //PAF_InpBufConfig *pIpBufConfig;
1931     Int frame; // decoder input frame count
1932     Int block; // (***) FL: formerly  -- decoder output block count / input frame
1933     Int8 tempVar8, temp2Var8;
1934     
1935     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
1936     zMD = pAstCfg->masterDec;
1937     zMS = pAstCfg->masterStr;
1938         
1939     for (z=DECODE1; z < DECODEN; z++)
1940     {
1941         alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];        
1942     }
1943     alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
1945     //
1946     // Receive and process the data in single-frame buffers
1947     //
1949     state = INIT;
1950     errno = 0; /* error number */
1952     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
1953                                  GATEMP_INDEX_DEC);
1954     TRACE_TERSE1("PAF_ASIT_decodeProcessing: sourceSelect is %d", tempVar8);
1956     for (;;) 
1957     {
1958         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect), 
1959                                      GATEMP_INDEX_DEC);
1960         if (tempVar8 == PAF_SOURCE_NONE)
1961         {
1962             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1963             state = QUIT;
1964         }
1966         // Process commands (decode)
1967         getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
1968         if (getVal) 
1969         {
1970             if (state != INIT)   // no need to restart/abort if not yet started
1971             {
1972                 if (getVal == ASPERR_QUIT)
1973                 {
1974                     state = QUIT;
1975                     TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1976                 }
1977                 else if (getVal == ASPERR_ABORT)
1978                 {
1979                     TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1980                     
1981                     // PFP end -- outside of PFP for errors, EOS, or Input SIO change
1982                     pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
1983                     gNumPfpAsit2--;
1984                     
1985                     return getVal;
1986                 }
1987                 else
1988                 {
1989                     /* ignore */;
1990                 }
1991             }
1992             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state == INIT");
1993         }
1995         TRACE_TIME((&TIME_MOD,         "... + %d = %d ->", dtime(), TSK_time()));
1996         TRACE_TIME((&TIME_MOD,         "                 state = %s", stateName[state]));
1998         // Process state (decode)
1999         switch (state) 
2000         {
2001             case INIT: // initial state
2002                 gAsipInitCnt++;
2003                 Log_info0("TaskAsip: state=INIT");               
2005                 errno = pP->fxns->decodeInit(pP, pQ, pAsitCfg, sourceSelect);
2006                 if (errno)
2007                 {
2008                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INIT, errno 0x%x.  break after decodeInit", errno);
2009                     break;
2010                 }
2011                                
2012                 frame = 0;
2013                 block = 0;
2015                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INIT->INFO1");
2016                 state = INFO1;
2017                 continue;
2019             case INFO1: // first frame state
2020                 gAsipInfo1Cnt++;
2021                 Log_info0("TaskAsip: state=INFO1");
2022                 
2023                 // Establish primary timing
2024                 errno = pP->fxns->decodeInfo(pP, pQ, pAsitCfg, frame, block);
2025                 if (errno)
2026                 {
2027                     gAsipInfo1_PrimaryErrCnt++;
2028                     TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
2029                     break;
2030                 }
2031                 
2032                 tempVar8  = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
2033                                               GATEMP_INDEX_DEC);
2034                 temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate), 
2035                                               GATEMP_INDEX_DEC);
2036                 // Don't start decode until major access unit is found.
2037                 if (((tempVar8 == PAF_SOURCE_THD)    ||
2038                      (tempVar8 == PAF_SOURCE_DXP)    ||
2039                      (tempVar8 == PAF_SOURCE_DTSHD)) &&
2040                      (temp2Var8 == PAF_SAMPLERATE_UNKNOWN)) 
2041                 {
2042                     Int z;
2043                     for (z=DECODE1; z < DECODEN; z++) 
2044                     {
2045                         Int zI = pP->inputsFromDecodes[z];
2046                         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode), 
2047                                                      GATEMP_INDEX_DEC);
2048                         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2049                         {
2050                             TRACE_VERBOSE0("TaskAsip: PAF_ASIT_decodeProcessing: INFO1, SIO_issue");
2051                             if (SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
2052                                 sizeof(pAstCfg->xInp[zI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME))
2053                             {
2054                                 gProbe2Err++;
2055                                 TRACE_TERSE0("PAF_ASIT_decodeProcessing. %d: INFO1, return (ASPERR_ISSUE)");
2056                                 
2057                                 // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2058                                 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2059                                 gNumPfpAsit2--;
2060                                 
2061                                 return (ASPERR_ISSUE);
2062                             }
2063                         }
2064                     }
2065                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, not major access unit", frame);
2066                     gMajorAuMissed++; // debug
2067                     frame++;
2068                     state = INFO1;
2069                     continue;
2070                 }
2071                 TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1: frame %d, major access unit found", frame);
2073                 // Establish secondary timing
2074                 errno = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, frame, block);
2075                 if (errno)
2076                 {
2077                     TRACE_VERBOSE1("PAF_ASIT_decodeProcessing: INFO1, errno 0x%x.  break after decodeInfo1", errno);
2078                     gAsipInfo1_ErrCnt++;
2079                     break;
2080                 }
2082                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO1->DECODE");
2083                 state = DECODE;
2084                 continue;
2086             case INFO2: // subsequent frame state
2087                 gAsipInfo2Cnt++;
2088                 Log_info0("TaskAsip: state=INFO2");
2090                 // Establish primary timing
2091                 errno = pP->fxns->decodeInfo(pP, pQ, pAsitCfg, frame, block);
2092                 if (errno)
2093                 {
2094                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: INFO2 break on decodeInfo. errno 0x%x", errno);
2095                     gAsipInfo2_PrimaryErrCnt++;
2096                     break;
2097                 }
2098                                 
2099                 // Measure cycles in decode processing loop.
2100                 // Only measures cycles spent in loop.
2101                 pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);         // PFP end
2102                 gNumPfpAsit2--;
2103                 pfpBegin(PFP_ID_ASIT_2, pAsitCfg->taskHandle);  // PFP begin
2104                 gNumPfpAsit2++;
2106                 errno = pP->fxns->decodeInfo2(pP, pQ, pAsitCfg, frame, block);
2107                 if (errno)
2108                 {
2109                     TRACE_TERSE1("PAF_ASIT_decodeProcessing. %d: INFO2 break on decodeInfo2. errno 0x%x", errno);
2110                     gAsipInfo2_ErrCnt++;
2111                     break;
2112                 }
2113                
2114                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: INFO2->DECODE");
2115                 state = DECODE;
2116                 continue;
2118             case DECODE: // decode state
2119                 gAsipDecodeCnt++;
2120                 Log_info0("TaskAsip: state=DECODE");
2122                 errno = pP->fxns->decodeDecode(pP, pQ, pAsitCfg, sourceSelect, frame, block);
2123                 if (errno)
2124                 {
2125                         gAsipDecodeErrCnt++;
2126                         TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
2127                     break;
2128                 }
2129                 
2130                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: DECODE->FINAL");
2131                 state = FINAL;
2132                 continue;
2134             case FINAL: // frame-finalization state
2135                 gAsipFinalCnt++;
2136                 Log_info0("TaskAsip: state=FINAL");
2138                 // Check for final frame, and if indicated:
2139                 // - Exit state machine to "complete" processing.
2140                 if (pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, frame, block)) 
2141                 {
2142                     break;
2143                 }
2145                 frame++;
2146                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: FINAL->AGAIN");
2147                 state = INFO2;
2148                 continue;
2150             case QUIT: // exit state
2151                 gAsipQuitCnt++;
2152                 Log_info0("TaskAsip: state=QUIT");
2154                 // Quit:
2155                 // - Set error number registers.
2156                 // - Exit state machine to "decode complete" processing.
2157                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
2158                 errno = ASPERR_QUIT;
2159                 break;
2161             default: // unknown state
2163                 // Unknown:
2164                 // - Set error number registers.
2165                 // - Exit state machine to "decode complete" processing.
2167                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: unknown, 0x%x", state);
2168                 errno = ASPERR_UNKNOWNSTATE;
2169                 break;
2171         }  // End of switch (state).
2173         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: Calling decode complete");
2174         if (pP->fxns->decodeComplete(pP, pQ, pAsitCfg, alg, frame, block))
2175         {
2176             /* ignored? */;
2177         }
2178         
2179         TRACE_TIME((&TIME_MOD, "as1-f2: ... + %d = ?? (final? %d)", dtime(), state == FINAL));
2181         // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2182         //pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2183         //gNumPfpAsit2--;
2184         
2185         //return errno;
2186         break;
2187     }  // End of for (;;) to Receive, process, and transmit the data.
2188     
2189     // PFP end -- outside of PFP for errors, EOS, or Input SIO change
2190     pfpEnd(PFP_ID_ASIT_2, PFP_FINISH_MEAS);
2191     gNumPfpAsit2--;
2192     
2193     return errno;
2194 } //PAF_ASIT_decodeProcessing
2196 // -----------------------------------------------------------------------------
2197 // ASIT Decoding Function - Decode Command Processing
2198 //
2199 //   Name:      PAF_ASIT_decodeCommand
2200 //   Purpose:   Decoding Function for processing Decode Commands.
2201 //   From:      AST Parameter Function -> decodeProcessing
2202 //   Uses:      See code.
2203 //   States:    x
2204 //   Return:    Error number in standard form (0 on success).
2205 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2206 //              * Command execution.
2207 //
2209 Int
2210 PAF_ASIT_decodeCommand(
2211     const PAF_ASIT_Params *pP, 
2212     const PAF_ASIT_Patchs *pQ, 
2213     PAF_ASIT_Config *pAsitCfg
2216     PAF_AST_Config *pAstCfg;
2217     Int as;                 /* Audio Stream Number (1, 2, etc.) */
2218     Int z;                  /* decode counter */
2219     Int zS;
2220     Int8 tempVar8;
2222     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2223     as = pAstCfg->as;
2225     for (z=DECODE1; z < DECODEN; z++) 
2226     {
2227         zS = pP->streamsFromDecodes[z];
2228         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.command2), 
2229                                      GATEMP_INDEX_DEC);
2230         if (!(tempVar8 & 0x80))
2231         {
2232             switch (tempVar8)
2233             {
2234                 case 0: // command none - process
2235                     tempVar8 |= 0x80;
2236                     sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2237                                        tempVar8, GATEMP_INDEX_DEC);
2238                     break;
2239                 case 1: // command abort - leave now
2240                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command abort (0x%02x)", as+zS, 1);
2241                     tempVar8 |= 0x80;
2242                     sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2243                                        tempVar8, GATEMP_INDEX_DEC);
2244                     return (ASPERR_ABORT);
2245                 case 2: // command restart - leave later
2246                     TRACE_TERSE2("AS%d: PAF_ASIT_decodeCommand: decode command quit (0x%02x)", as+zS, 2);
2247                     tempVar8 |= 0x80;
2248                     sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.command2),
2249                                        tempVar8, GATEMP_INDEX_DEC);
2250                     return (ASPERR_QUIT);
2251                 default: // command unknown - ignore
2252                     break;
2253             }
2254         }
2255     }
2257     return 0;
2258 } //PAF_ASIT_decodeCommand
2260 // -----------------------------------------------------------------------------
2261 // ASIT Decoding Function - Reinitialization of Decode
2262 //
2263 //   Name:      PAF_ASIT_decodeInit
2264 //   Purpose:   Decoding Function for reinitializing the decoding process.
2265 //   From:      AST Parameter Function -> decodeProcessing
2266 //   Uses:      See code.
2267 //   States:    x
2268 //   Return:    Error number in standard or SIO form (0 on success).
2269 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2270 //              * State information as per parent.
2271 //
2272 Int
2273 PAF_ASIT_decodeInit(
2274     const PAF_ASIT_Params *pP, 
2275     const PAF_ASIT_Patchs *pQ, 
2276     PAF_ASIT_Config *pAsitCfg, 
2277     Int sourceSelect
2280     PAF_AST_Config *pAstCfg;
2281     PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
2282     Int as;                             /* Audio Stream Number (1, 2, etc.) */
2283     Int z;                              /* decode/encode counter */
2284     Int errno;                          /* error number */
2285     Int zI, zS;
2286     Int zMD;
2287     Int zMI;
2288     Int argIdx;
2289     Int8 tempVar8;
2290     char decMsgBuf[ASP_MSG_BUF_LEN];
2291     
2292     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2293     as = pAstCfg->as;
2294     zMD = pAstCfg->masterDec;
2295     zMI = pP->zone.master;
2296     (void)as;  // clear compiler warning in case not used with tracing disabled
2297     
2298     pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
2300     // reset frameCount
2301     for (z=DECODE1; z < DECODEN; z++)
2302     {
2303         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2304                                      GATEMP_INDEX_DEC);
2305         if (tempVar8)
2306         {
2307             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2308                               (Int)0, GATEMP_INDEX_DEC);
2309         }
2310     }
2312     for (z=DECODE1; z < DECODEN; z++) 
2313     {
2314         zI = pP->inputsFromDecodes[z];
2315         zS = pP->streamsFromDecodes[z];
2316         (void)zS; // clear compiler warning in case not used with tracing disabled
2317         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode), 
2318                                      GATEMP_INDEX_DEC);
2319         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2320         {
2322             Uns gear;
2323             Int frameLength;
2324             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
2326             // write back Dec configuration
2327             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2328             Cache_wait();
2330             // FL: send dec activate message to slave
2331             argIdx = 0; // set decIdx (zone index)
2332             *(Int32 *)&decMsgBuf[argIdx] = z;
2333             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE, 
2334                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
2335             {
2336                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
2337                 SW_BREAKPOINT; // temporary
2338                 return -1; // temporary
2339             }           
2341 #if 0 // FL: decoder activate call, slave
2342             if (decAlg[z]->fxns->algActivate)
2343                 decAlg[z]->fxns->algActivate (decAlg[z]);
2344 #endif
2345             // FL: send dec reset message to slave
2346             argIdx = 0; // set decIdx
2347             *(Int32 *)&decMsgBuf[argIdx] = z;
2348             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE, 
2349                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2350             {
2351                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
2352                 SW_BREAKPOINT; // temporary
2353                 return -1; // temporary
2354             }
2355             else
2356             {
2357                 argIdx = 0; // get decErrno
2358                 errno = *(Int32 *)&decMsgBuf[argIdx];                
2359             }   
2361             // (***) FL: revisit
2362             // invalidate Dec configuration
2363             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2364             Cache_wait();
2365             
2366 #if 0 // FL: decoder reset call, slave
2367             if (dec->fxns->reset
2368                 && (errno = dec->fxns->reset (dec, NULL,
2369                                               &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
2370                 return errno;
2371 #endif
2372             if (errno != 0)
2373             {
2374                 return errno;
2375             }
2376             
2377             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
2378                                               GATEMP_INDEX_DEC);
2379             tempVar8 = gear < GEARS ? gear : 0;
2380             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
2381                                    tempVar8, GATEMP_INDEX_DEC);
2382             
2383 #if 0 // FL: change handle to decIdx (zone index)
2384             frameLength = pP->fxns->computeFrameLength(decAlg[z], 
2385                 FRAMELENGTH,
2386                 pC->xDec[z].decodeStatus.bufferRatio);
2387 #endif
2388 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2389             frameLength = pP->fxns->computeFrameLength(z, 
2390                 FRAMELENGTH, 
2391                 pC->xDec[z].decodeStatus.bufferRatio);
2392 #else
2393             if (sourceSelect == PAF_SOURCE_PCM)
2394             {
2395                 frameLength = PAF_SYS_FRAMELENGTH;
2396             }
2397             else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
2398             {
2399                 frameLength = 1536;
2400             }
2401             else if (sourceSelect == PAF_SOURCE_THD)
2402             {
2403                 frameLength = 1536; //QIN FIX ME
2404             }
2405             else
2406             {
2407                 frameLength = 256;
2408             }
2409 #endif    
2410             
2411             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
2412             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
2413             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2414             
2415             // Initialize decoder output circular buffer for selected source
2416             errno = cbInitSourceSel(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
2417             if (errno)
2418             {
2419                 SW_BREAKPOINT; // FL: debug
2420                 return errno;
2421             }
2422             // FL: debug
2423             cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInitSourceSel");
2424             
2425             if (z != zMD) 
2426             {
2427                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio))
2428                 {
2429                     return errno;
2430                 }
2431             }
2433             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2434                                              GATEMP_INDEX_DEC);
2435             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_SOURCESELECT,
2436                 DECSIOMAP(tempVar8)))
2437             {
2438                 return errno;
2439             }
2441             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio, PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, 
2442                 frameLength))
2443             {
2444                 return errno;
2445             }
2446             if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufStatus, 
2447                 &pAstCfg->xInp[zI].inpBufConfig))
2448             {
2449                 return errno;
2450             }
2451         }
2452     }
2454     if (pAstCfg->xInp[zMI].hRxSio) 
2455     {
2456         errno = SIO_issue(pAstCfg->xInp[zMI].hRxSio, &pAstCfg->xInp[zMI].inpBufConfig,
2457             sizeof(pAstCfg->xInp[zMI].inpBufConfig), PAF_SIO_REQUEST_NEWFRAME);
2458         if (errno)
2459         {
2460             return errno;
2461         }
2462     }
2464     return 0;
2465 } //PAF_AST_decodeInit
2467 // -----------------------------------------------------------------------------
2468 // ASIT Decoding Function - Info Processing, Common
2469 //
2470 //   Name:      PAF_ASIT_decodeInfo
2471 //   Purpose:   Decoding Function for processing information in a manner that
2472 //              is common for both initial and subsequent frames of input data.
2473 //   From:      AST Parameter Function -> decodeProcessing
2474 //   Uses:      See code.
2475 //   States:    x
2476 //   Return:    Error number in standard form (0 on success).
2477 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2478 //              * State information as per parent.
2479 //
2480 Int
2481 PAF_ASIT_decodeInfo(
2482     const PAF_ASIT_Params *pP, 
2483     const PAF_ASIT_Patchs *pQ, 
2484     PAF_ASIT_Config *pAsitCfg, 
2485     Int frame, 
2486     Int block
2489     PAF_AST_Config *pAstCfg;
2490     Int as;                    /* Audio Stream Number (1, 2, etc.) */
2491     Int z;                     /* input/decode/stream counter */
2492     Int errno;                 /* error number */
2493     Int sioErr;                /* error number, SIO */
2494     Int zD, zI, zS, zX;
2495     Int zMD;
2496     Int zMI;
2497     Int zMS;
2498     UInt32 curTime;
2499     Int argIdx;
2500     Int8 tempVar8;
2501     Int tempVar;
2502     char decMsgBuf[ASP_MSG_BUF_LEN];
2503     // FL: revisit
2504     //Int size;
2505     //PAF_InpBufConfig *pIpBufConfig;
2507     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2508     as = pAstCfg->as;
2509     zMD = pAstCfg->masterDec;
2510     zMS = pAstCfg->masterStr;
2511     zMI = pP->zone.master;
2512     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
2513     
2514     // Set decode control: sample rate, emphasis
2515     for (z=INPUT1; z < INPUTN; z++)
2516     {
2517         zD = z;
2518         for (zX = DECODE1; zX < DECODEN; zX++) 
2519         {
2520             if (pP->inputsFromDecodes[zX] == z) 
2521             {
2522                 zD = zX;
2523                 break;
2524             }
2525         }
2526 #ifdef PROFILER
2527             // modify for different sampling rate
2528             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus == PAF_SAMPLERATE_96000HZ)
2529             {
2530                 start_profiling = 1;
2531             }
2532             else
2533             {
2534                 start_profiling = 0;
2535             }
2536 #endif
2537         if (pAstCfg->xInp[z].hRxSio) 
2538         {
2539             //determine associated decoder
2540             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus != 
2541                 pAstCfg->xDec[zD].decodeControl.sampleRate) 
2542             {
2543                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) 
2544                 {
2545                     pAstCfg->xDec[zD].decodeControl.sampleRate = 
2546                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
2547                 }
2548                 else
2549                 {
2550                     TRACE_TERSE1("AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
2551                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
2552                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus, 
2553                         pAstCfg->xDec[zD].decodeControl.sampleRate);
2554                     // return (ASPERR_INFO_RATECHANGE);
2555                 }
2556             }
2558             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
2559                                              GATEMP_INDEX_DEC);
2560             pAstCfg->xDec[zD].decodeControl.emphasis = 
2561                 tempVar8 != PAF_SOURCE_PCM
2562                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
2563                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
2564         }
2565         else 
2566         {
2567             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
2568             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
2569         }
2570     }
2572     // Wait for info input
2573     TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: awaiting frame %d -- sync+info+data", as+zMS, frame);
2574     if (pAstCfg->xInp[zMI].hRxSio) 
2575     {
2576         TRACE_VERBOSE0("PAF_ASIT_decodeInfo: call SIO_reclaim to get input buffer.");
2577         sioErr = SIO_reclaim(pAstCfg->xInp[zMI].hRxSio, (Ptr)&pAstCfg->xInp[zMI].pInpBuf, NULL);
2578         if (sioErr != sizeof(pAstCfg->xInp[zMI].inpBufConfig))
2579         {
2580             TRACE_TERSE1("SIO_reclaim on input returned error ASPERR_RECLAIM.  sioErr: 0x%x", sioErr);
2581             return ASPERR_RECLAIM;
2582         }
2583         
2584         // FL: debug, capture input buffer
2585         capIb(pAstCfg->xInp[zMI].pInpBuf);
2586         gCapIb_cnt++;
2587         
2588 #if 1 // (***) FL: shows timing of Input Rx SIO reclaim after decoding has started (autodet complete)
2589         // (***) debug // B5
2590         {
2591             static Uint8 toggleState = 0;
2592             if (toggleState == 0)
2593                 GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_99);
2594             else
2595                 GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_99);
2596             toggleState = ~(toggleState);
2597         }
2598 #endif
2600         //
2601         // Simulate Rx SIO_reclaim() pend
2602         //
2603         //Semaphore_pend(semaphoreRxAudio, BIOS_WAIT_FOREVER); 
2604         gTaskAsipCnt++;
2605         curTime = Clock_getTicks();
2606         //System_printf("System time in TaskAsipFxn Rx audio = %lu\n", (ULong)curTime);        
2607         //Log_info1("System time in TaskAsipFxn Rx audio = %u", curTime);
2608         //Log_info1("decodeInfo():Rx SIO reclaim(), system time = %u", curTime);
2609     } //pAstCfg->xInp[zMI].hRxSio
2611     // Decode info
2612     for (z=DECODE1; z < DECODEN; z++) 
2613     {
2614         zI = pP->inputsFromDecodes[z];
2615         zS = pP->streamsFromDecodes[z];
2616         (void)zS; // clear compiler warning in case not used with tracing disabled
2618         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2619                                      GATEMP_INDEX_DEC);
2620         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
2621         {
2622             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, frame);
2624             if (errno = pP->fxns->updateInputStatus(pAstCfg->xInp[zI].hRxSio,
2625                 &pAstCfg->xInp[zI].inpBufStatus, &pAstCfg->xInp[zI].inpBufConfig))
2626             {
2627                 TRACE_TERSE1("return error errno 0x%x.", errno);
2628                 return errno;
2629             }
2631 #if 1
2632             // (***) FL: revisit
2633             // write back Inp configuration
2634             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
2635             // write back input data //  (***) GJ: don't need this for 1xI2S HDMI/SPDIF. Maybe need this for 4xI2S HDMI.
2636             //pIpBufConfig = &gPAF_AST_config.xInp[zI].inpBufConfig;
2637             //size = pIpBufConfig->frameLength * pIpBufConfig->sizeofElement;
2638             //Cache_wb((Ptr)pIpBufConfig->pntr.pSmInt, size, Cache_Type_ALLD, 0);
2639             // write back Dec configuration
2640             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2641             Cache_wait();
2642 #endif
2643             
2644             // FL: send info message to slave
2645             argIdx = 0; // set decIdx
2646             *(Int32 *)&decMsgBuf[argIdx] = z;
2647             if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE, 
2648                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2649             {
2650                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
2651                 SW_BREAKPOINT; // temporary
2652                 return -1;     // temporary
2653             }
2654             else
2655             {
2656                 argIdx = 0; // get decErrno
2657                 errno = *(Int32 *)&decMsgBuf[argIdx];                
2658             }             
2660 #if 1
2661             // (***) FL: revisit
2662             // invalidate Dec configuration
2663             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2664             Cache_wait();                            
2665 #endif            
2666             
2667 #if 0 // FL: decoder info call, slave
2668             if (dec->fxns->info
2669                 && (errno = dec->fxns->info (dec, NULL,
2670                                              &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus))) 
2671 #endif
2672             if (errno)
2673             {
2674                 TRACE_TERSE1("return error errno 0x%x.", errno);
2675                 return errno;
2676             }
2678             // increment decoded frame count
2679             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2680                                        GATEMP_INDEX_DEC);
2681             tempVar += 1;
2682             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
2683                               tempVar, GATEMP_INDEX_DEC);
2684         }
2685     } // z=DECODE1 to DECODEN
2687     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
2688     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
2689                                  GATEMP_INDEX_DEC);
2690     if (tempVar8)
2691     {
2692         XDAS_Int8 sourceProgram;
2693         if (errno = SIO_ctrl(pAstCfg->xInp[zMI].hRxSio, PAF_SIO_CONTROL_GET_SOURCEPROGRAM,
2694             (Arg)&sourceProgram))
2695         {
2696             TRACE_TERSE1("return error ASPERR_AUTO_PROGRAM. errno 0x%x.", errno);
2697             return ASPERR_AUTO_PROGRAM;
2698         }
2700         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
2701                            sourceProgram, GATEMP_INDEX_DEC);
2702     }
2704     // since now decoding update decode status for all enabled decoders
2705     for (z=DECODE1; z < DECODEN; z++)
2706     {
2707         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2708                                      GATEMP_INDEX_DEC);
2709         if (tempVar8)
2710         {
2711             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
2712                                          GATEMP_INDEX_DEC);
2713             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
2714                                tempVar8, GATEMP_INDEX_DEC);
2716             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
2717                                          GATEMP_INDEX_DEC);
2718             if (tempVar8 == PAF_SOURCE_SNG)
2719             {
2720                 tempVar8 = PAF_SOURCE_SNG;
2721                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
2722                                    tempVar8, GATEMP_INDEX_DEC);
2723             }
2724         }
2725     }
2727 #if 0 // FL: ASDT (slave)
2728     // TODO: move this to start of this function so that it doesn't affect IO timing
2729     // Initialize audio frame(s)
2730     //    Re-initialize audio frame if there is an associated decode and
2731     //    that decode doesn't have a valid input or is turned off
2732     for (z=STREAM1; z < STREAMN; z++) 
2733     {
2734         Int reset = 0;
2735         for (zX = DECODE1; zX < DECODEN; zX++) 
2736         {
2737             if (pP->streamsFromDecodes[zX] == z) 
2738             {
2739                 zI = pP->inputsFromDecodes[zX];
2740                 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
2741                 {
2742                     reset = 1;
2743                 }
2744             }
2745         }
2746         if (reset) 
2747         {
2748             TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info", as+z, frame);
2749             pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
2750         }
2751         else
2752         {
2753             TRACE_VERBOSE2("PAF_ASIT_decodeInfo: AS%d: initializing block %d -- info <ignored>", as+z, frame);
2754         }
2755     }
2756 #endif    
2758     return 0;
2759 } //PAF_ASIT_decodeInfo
2761 // -----------------------------------------------------------------------------
2762 // ASIT Decoding Function - Info Processing, Initial
2763 //
2764 //   Name:      PAF_ASIT_decodeInfo1
2765 //   Purpose:   Decoding Function for processing information in a manner that
2766 //              is unique to initial frames of input data.
2767 //   From:      AST Parameter Function -> decodeProcessing
2768 //   Uses:      See code.
2769 //   States:    x
2770 //   Return:    Error number in standard or SIO form (0 on success).
2771 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2772 //              * State information as per parent.
2773 //
2774 Int
2775 PAF_ASIT_decodeInfo1(
2776     const PAF_ASIT_Params *pP, 
2777     const PAF_ASIT_Patchs *pQ, 
2778     PAF_ASIT_Config *pAsitCfg, 
2779     Int frame, 
2780     Int block
2783     return 0;
2784 } //PAF_ASIT_decodeInfo1
2786 // -----------------------------------------------------------------------------
2787 // AST Decoding Function - Info Processing, Subsequent
2788 //
2789 //   Name:      PAF_AST_decodeInfo2
2790 //   Purpose:   Decoding Function for processing information in a manner that
2791 //              is unique to frames of input data other than the initial one.
2792 //   From:      AST Parameter Function -> decodeProcessing
2793 //   Uses:      See code.
2794 //   States:    x
2795 //   Return:    Error number in standard form (0 on success).
2796 //   Trace:     None.
2797 //
2798 Int
2799 PAF_ASIT_decodeInfo2(
2800     const PAF_ASIT_Params *pP, 
2801     const PAF_ASIT_Patchs *pQ, 
2802     PAF_ASIT_Config *pAsitCfg, 
2803     Int frame, 
2804     Int block
2807     return 0;
2808 } //PAF_ASIT_decodeInfo2
2810 #if 0
2811 // -----------------------------------------------------------------------------
2812 // AST Decoding Function - Continuation Processing
2813 //
2814 //   Name:      PAF_AST_decodeCont
2815 //   Purpose:   Decoding Function for processing that occurs subsequent to
2816 //              information processing but antecedent to timing processing
2817 //              for frames of input data other than the initial one.
2818 //   From:      AST Parameter Function -> decodeProcessing
2819 //   Uses:      See code.
2820 //   States:    x
2821 //   Return:    Error number in standard form (0 on success).
2822 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2823 //              * State information as per parent.
2824 //
2826 Int
2827 PAF_AST_decodeCont(
2828     const PAF_ASIT_Params *pP, 
2829     const PAF_ASIT_Patchs *pQ, 
2830     PAF_ASIT_Config *pAsitCfg, 
2831     ALG_Handle decAlg[], 
2832     Int frame, 
2833     Int block
2836     PAF_AST_Config *pAstCfg;
2837     Int as;                     /* Audio Stream Number (1, 2, etc.) */
2838     Int z;                      /* decode counter */
2839     Int zI, zS;
2840     Int zMD;
2841     Int8 tempVar8;
2843     
2844     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2845     as = pAstCfg->as;
2846     zMD = pAstCfg->masterDec;
2847     (void)as;  // clear compiler warning in case not used with tracing disabled
2848     
2849     // Await slave inputs
2850     for (z=DECODE1; z < DECODEN; z++)
2851     {
2852         zI = pP->inputsFromDecodes[z];
2853         zS = pP->streamsFromDecodes[z];
2854         (void)zS;
2855         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
2856                                      GATEMP_INDEX_DEC);
2857         if (z == zMD
2858             || ! pAstCfg->xInp[zI].hRxSio
2859             || ! tempVar8)
2860             continue;
2861         TRACE_VERBOSE2("PAF_AST_decodeCont: AS%d: awaiting frame %d -- data", as+zS, frame);
2862         if (SIO_reclaim(pAstCfg->xInp[zI].hRxSio, (Ptr)&pAstCfg->xInp[zI].pInpBuf, NULL)
2863             != sizeof (pAstCfg->xInp[zI].inpBufConfig))
2864             return (ASPERR_RECLAIM);
2865     }
2867     return 0;
2868 } //PAF_AST_decodeCont
2869 #endif
2871 // -----------------------------------------------------------------------------
2872 // ASIT Decoding Function - Decode Processing
2873 //
2874 //   Name:      PAF_ASIT_decodeDecode
2875 //   Purpose:   Decoding Function for processing of input data by the
2876 //              Decode Algorithm.
2877 //   From:      AST Parameter Function -> decodeProcessing
2878 //   Uses:      See code.
2879 //   States:    x
2880 //   Return:    Error number in standard form (0 on success).
2881 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
2882 //              * State information as per parent.
2883 //
2884 Int
2885 PAF_ASIT_decodeDecode(
2886     const PAF_ASIT_Params *pP, 
2887     const PAF_ASIT_Patchs *pQ, 
2888     PAF_ASIT_Config *pAsitCfg, 
2889     Int sourceSelect, 
2890     Int frame, 
2891     Int block
2894     PAF_AST_Config *pAstCfg;
2895     Int as;                     /* Audio Stream Number (1, 2, etc.) */
2896     Int z;                      /* decode/stream counter */
2897     Int errno;                  /* error number */
2898     //Int ch;
2899     Int argIdx;
2900     Int cbErrno;
2901     Int frameLength;    
2902     char decMsgBuf[ASP_MSG_BUF_LEN];
2904     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
2905     as = pAstCfg->as;
2906     (void)as; // clear compiler warning in case not used with tracing disabled
2908 #if 0 // FL: slave
2909     // Clear samsiz for all channels - MID 208.
2910     for (z=STREAM1; z < STREAMN; z++) 
2911     {
2912         for (ch=0; ch < PAF_MAXNUMCHAN_AF; ch++) 
2913         {
2914             pC->xStr[z].pAudioFrame->data.samsiz[ch] = 0;
2915         }
2916     }
2917 #endif    
2919     // Decode data
2920     for (z=DECODE1; z < DECODEN; z++) 
2921     {
2922         Int zI = pP->inputsFromDecodes[z];
2923         Int zS = pP->streamsFromDecodes[z];
2924         (void)zS; // clear compiler warning in case not used with tracing disabled
2925         if (pAstCfg->xInp[zI].hRxSio && pAstCfg->xDec[z].decodeStatus.mode)
2926         {
2927             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, block);
2929             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
2930                     as+zS,
2931                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
2932                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
2934             // FL: debug, capture input buffer
2935             //capIbPcm(pAstCfg->xInp[z].pInpBuf);
2936             
2937             // (***) FL: revisit
2938             // write back Dec configuration
2939             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2940             Cache_wait();                        
2942             // FL: send decode message to slave
2943             argIdx = 0; // set decIdx
2944             *(Int32 *)&decMsgBuf[argIdx] = z;
2945             if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE, 
2946                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
2947             {
2948                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
2949                 SW_BREAKPOINT; // temporary
2950                 return -1;     // temporary
2951             }
2952             else 
2953             {
2954                 argIdx = 0; // get decErrno
2955                 errno = *(Int32 *)&decMsgBuf[argIdx];
2956                 argIdx += sizeof(Int32); // get cbErrno
2957                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
2958                 if (cbErrno != 0)
2959                 {
2960                     gCbWrtAfErrCnt++;
2961                     TRACE_TERSE1("CB write error=%d", cbErrno);
2962                     //SW_BREAKPOINT; // temporary
2963                 }
2964             }           
2966             // (***) FL: revisit
2967             // invalidate Dec configuration
2968             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
2969             Cache_wait();
2971 #if 0 // FL: decoder decode call, slave
2972             if (dec->fxns->decode
2973                 && (errno = dec->fxns->decode (dec, NULL,
2974                                                &pC->xDec[z].decodeInStruct, &pC->xDec[z].decodeOutStruct))) 
2975 #endif
2976             if (errno)
2977             {
2978                 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: fxns->decode returns 0x%x", errno);
2979                 return errno;
2980             }
2982 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
2983             as_traceChannels(pC, z);
2984 #endif
2986 #if 0 // FL: change handle to decIdx (zone index)  
2987             frameLength = pP->fxns->computeFrameLength(decAlg[z],
2988                 FRAMELENGTH, 
2989                 pC->xDec[z].decodeStatus.bufferRatio);
2990 #endif
2991 #if 0 // (***) FL: revisit. Bypass computeFrameLength().
2992             frameLength = pP->fxns->computeFrameLength(z, 
2993                 FRAMELENGTH, 
2994                 pC->xDec[z].decodeStatus.bufferRatio);
2995 #else
2996             if (sourceSelect == PAF_SOURCE_PCM)
2997             {
2998                 frameLength = PAF_SYS_FRAMELENGTH;
2999             }
3000             else if ((sourceSelect == PAF_SOURCE_DDP) || (sourceSelect == PAF_SOURCE_AC3))
3001             {
3002                 frameLength = 1536;
3003             }
3004             else if (sourceSelect == PAF_SOURCE_THD)
3005             {
3006                 frameLength = 1536; //QIN FIX ME
3007             }
3008             else
3009             {
3010                 frameLength = 256;
3011             }
3012 #endif
3015 //#ifdef PROFILER
3016 //            // modify for different decoders
3017 //            if (sourceSelect == PAF_SOURCE_THD)
3018 //            {
3019 //              start_profiling = 1;
3020 //            }
3021 //            else
3022 //            {
3023 //                start_profiling = 0;
3024 //            }
3025 //#endif
3028 // ............................................................................
3030             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
3031             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
3032             if (errno = SIO_ctrl(pAstCfg->xInp[zI].hRxSio,
3033                 PAF_SIO_CONTROL_SET_PCMFRAMELENGTH, frameLength))
3034             {
3035                 TRACE_VERBOSE1("PAF_ASIT_decodeDecode: SIO SET_PCMFRAMELENGTH returns 0x%x", errno);
3036                 return errno;
3037             }
3038                 
3039             TRACE_VERBOSE1("PAF_ASIT_decodeDecode: calling SIO_issue[%d]", zI);
3040             if (errno = SIO_issue(pAstCfg->xInp[zI].hRxSio, &pAstCfg->xInp[zI].inpBufConfig,
3041                 sizeof(pAstCfg->xInp[zI].inpBufConfig),
3042                 PAF_SIO_REQUEST_NEWFRAME))
3043             {
3044                 TRACE_VERBOSE2("PAF_ASIT_decodeDecode: SIO_issue returns 0x%x, we return ASPERR_ISSUE (0x%x)", errno, ASPERR_ISSUE);
3045                 return (ASPERR_ISSUE);
3046             }
3047         } // hRxSio && decodeStatus.mode
3048         else
3049         {
3050             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, block);
3051         }
3052     } // z=DECODE1 to DECODEN
3054 #if 0 // FL: ASDT (slave)
3055     // Set up audio frames not decoded into
3056     //    Re-initialize audio frame if there is an assocatiated decode and
3057     //    that decode doesn't have a valid input or is turned off
3058     for (z=STREAM1; z < STREAMN; z++) 
3059     {
3060         Int zX;
3061         Int reset = 0;
3062         for (zX = DECODE1; zX < DECODEN; zX++) 
3063         {
3064             if (pP->streamsFromDecodes[zX] == z) 
3065             {
3066                 Int zI = pP->inputsFromDecodes[zX];
3067                 if (!pC->xDec[zX].decodeStatus.mode || !pC->xInp[zI].hRxSio)
3068                     reset = 1;
3069             }
3070         }
3071         if (reset) 
3072         {
3073             TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode", as+z, frame);
3074             pP->fxns->initFrame1 (pP, pQ, pC, z, 0);
3075         }
3076         else
3077             TRACE_VERBOSE2("PAF_ASIT_decodeDecode: AS%d: initializing block %d -- decode <ignored>", as+z, frame);
3078     }
3079 #endif
3080     
3081     return 0;
3082 } //PAF_ASIT_decodeDecode
3084 // -----------------------------------------------------------------------------
3085 // ASIT Decoding Function - Frame-Final Processing
3086 //
3087 //   Name:      PAF_ASIT_decodeFinalTest
3088 //   Purpose:   Decoding Function for determining whether processing of the
3089 //              current frame is complete.
3090 //   From:      AST Parameter Function -> decodeProcessing
3091 //   Uses:      See code.
3092 //   States:    x
3093 //   Return:    0 if incomplete, and 1 if complete.
3094 //   Trace:     None.
3095 //
3097 Int
3098 PAF_ASIT_decodeFinalTest(
3099     const PAF_ASIT_Params *pP, 
3100     const PAF_ASIT_Patchs *pQ, 
3101     PAF_ASIT_Config *pAsitCfg, 
3102     Int frame, 
3103     Int block
3106     PAF_AST_Config *pAstCfg;
3107     Int zMD;
3108     Int sourceSelect;
3109     Int sourceProgram;
3110     Int8 tempVar8, temp2Var8;
3112     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3113     zMD = pAstCfg->masterDec;
3115     sourceSelect  = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3116                                            GATEMP_INDEX_DEC);
3117     sourceProgram = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
3118                                            GATEMP_INDEX_DEC);
3120     if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
3121     {
3122         return 1;
3123     }
3125     // The following allows for Force modes to switch without command deferral. This might
3126     // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
3127     if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM)) 
3128     {
3129         if (sourceSelect == PAF_SOURCE_DTSALL)
3130         {
3131             if (sourceProgram != PAF_SOURCE_DTS11 &&
3132                 sourceProgram != PAF_SOURCE_DTS12 &&
3133                 sourceProgram != PAF_SOURCE_DTS13 &&
3134                 sourceProgram != PAF_SOURCE_DTS14 &&
3135                 sourceProgram != PAF_SOURCE_DTS16 &&
3136                 sourceProgram != PAF_SOURCE_DTSHD)
3137             {
3138                 return 1;
3139             }
3140         }
3141         else if (sourceSelect == PAF_SOURCE_PCMAUTO) 
3142         {
3143             if (sourceProgram != PAF_SOURCE_PCM)
3144             {
3145                 return 1;
3146             }
3147         }
3148         else 
3149         {
3150             tempVar8  = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
3151                                           GATEMP_INDEX_DEC);
3152             temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
3153                                           GATEMP_INDEX_DEC);
3154             if (temp2Var8 != tempVar8)
3155             {
3156                 return 1;
3157             }
3158         }
3159     }
3161     return 0;
3162 } //PAF_ASIT_decodeFinalTest
3164 // -----------------------------------------------------------------------------
3165 // ASIT Decoding Function - Stream-Final Processing
3166 //
3167 //   Name:      PAF_ASIT_decodeComplete
3168 //   Purpose:   Decoding Function for terminating the decoding process.
3169 //   From:      AST Parameter Function -> decodeProcessing
3170 //   Uses:      See code.
3171 //   States:    x
3172 //   Return:    0.
3173 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
3174 //              * State information as per parent.
3175 //
3176 Int
3177 PAF_ASIT_decodeComplete(
3178     const PAF_ASIT_Params *pP, 
3179     const PAF_ASIT_Patchs *pQ, 
3180     PAF_ASIT_Config *pAsitCfg, 
3181     ALG_Handle decAlg[], 
3182     Int frame, 
3183     Int block
3186     PAF_AST_Config *pAstCfg;
3187     Int as;                     /* Audio Stream Number (1, 2, etc.) */
3188     Int z;                      /* decode/encode counter */
3189     Int argIdx;
3190     Int errno;                  /* error number */
3191     Int8 tempVar8;
3192     char decMsgBuf[ASP_MSG_BUF_LEN];
3193     
3194     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3195     as = pAstCfg->as;
3196     (void)as;  // clear compiler warning in case not used with tracing disabled
3198 #ifdef PAF_ASP_FINAL
3199     /* This material is currently not utilized */
3200 #endif /* PAF_ASP_FINAL */
3201     for (z=DECODE1; z < DECODEN; z++) 
3202     {
3203 #ifdef PAF_ASP_FINAL
3204         DEC_Handle dec = (DEC_Handle )decAlg[z];
3205 #endif /* PAF_ASP_FINAL */
3206         Int zI = pP->inputsFromDecodes[z];
3207         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
3208                                      GATEMP_INDEX_DEC);
3209         if (pAstCfg->xInp[zI].hRxSio && tempVar8)
3210         {
3211             TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: finalizing decode", as+z);
3212 #ifdef PAF_ASP_FINAL
3213             if (dec->fxns->final)
3214                 dec->fxns->final(dec, NULL, &pAstCfg->xDec[z].decodeControl,
3215                                  &pAstCfg->xDec[z].decodeStatus);
3216 #endif /* PAF_ASP_FINAL */
3218             // FL: send dec deactivate message to slave
3219             argIdx = 0; // set decIdx
3220             *(Int32 *)&decMsgBuf[argIdx] = z;
3221             if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
3222                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
3223             {
3224                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
3225                 SW_BREAKPOINT;
3226                 return -1;
3227             }
3229 #if 0 // FL: decoder deactivate call, slave
3230             if (decAlg[z]->fxns->algDeactivate)
3231                 decAlg[z]->fxns->algDeactivate (decAlg[z]);
3232 #endif    
3233         }
3234         else 
3235         {
3236             TRACE_VERBOSE1("PAF_ASIT_decodeComplete: AS%d: processing decode <ignored>", as+z);
3237         }
3238     }
3239     return 0;
3240 } //PAF_ASIT_decodeComplete
3242 // -----------------------------------------------------------------------------
3243 // ASIT Selection Function - Input Device Selection
3244 //
3245 //   Name:      PAF_ASIT_selectDevices
3246 //   Purpose:   Audio Stream Input Task Function for selecting the devices used
3247 //              for input.
3248 //   From:      audioStream1Task or equivalent
3249 //   Uses:      See code.
3250 //   States:    x
3251 //   Return:    Error number in standard form (0 on success).
3252 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
3253 //              * State information as per parent.
3254 //
3255 Int
3256 PAF_ASIT_selectDevices(
3257     const PAF_ASIT_Params *pP, 
3258     const PAF_ASIT_Patchs *pQ, 
3259     PAF_ASIT_Config *pAsitCfg
3262     PAF_AST_Config *pAstCfg;
3263     Int as;                     /* Audio Stream Number (1, 2, etc.) */
3264     Int z;                      /* input/output counter */
3265     Int errno = 0;              /* error number */
3266     Int errme;                  /* error number, local */
3267     Int device;
3268     Int zMD;
3270     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3271     as = pAstCfg->as;
3272     zMD = pAstCfg->masterDec;
3273     (void)as;  // clear compiler warning in case not used with tracing disabled
3274     
3275     // Select input devices
3276     for (z=INPUT1; z < INPUTN; z++) 
3277     {
3278         if ((device = pAstCfg->xInp[z].inpBufStatus.sioSelect) >= 0) 
3279         {
3280             TRACE_VERBOSE2("PAF_ASIT_selectDevices: AS%d: input device %d selecting ...", as+z, device);
3282             // check for valid index into device array
3283             if (device >= pQ->devinp->n)
3284             {
3285                 device = 0; /* treat as device None */
3286             }
3288             errme = pP->fxns->deviceSelect(&pAstCfg->xInp[z].hRxSio, SIO_INPUT,
3289                 HEAP_ID_INPBUF, (Ptr)pQ->devinp->x[device]);
3291             if (errme)
3292             {
3293                 TRACE_VERBOSE2("PAF_ASIT_selectDevices: errme 0x%x, errno 0x%x", errme, errno);
3294                 if (!errno)
3295                 {
3296                     errno = ASPERR_DEVINP + errme;
3297                 }
3298                 pAstCfg->xInp[z].inpBufStatus.sioSelect = 0x80;
3299             }
3300             else 
3301             {
3302                 pAstCfg->xInp[z].inpBufStatus.sioSelect = device | 0x80;
3303                 // register decodeStatus pointer with input devices
3304                 // This allows, e.g., autoProcessing to exit when sourceSelect = none
3305                 // Use zMIs decodeStatus for all inputs
3306                 if (pAstCfg->xInp[z].hRxSio) 
3307                 {
3308                     // register PAF_SIO_IALG object address
3309                     SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_IALGADDR, 
3310                         (Arg)pAstCfg->xInp[z].inpChainData.head->alg);
3311                     SIO_ctrl(pAstCfg->xInp[z].hRxSio, PAF_SIO_CONTROL_SET_DECSTATUSADDR, 
3312                         (Arg)&pAstCfg->xDec[zMD].decodeStatus);
3313                 }
3314             }
3315         }
3316     }
3318     return errno;
3319 } //PAF_ASIT_selectDevices
3321 // -----------------------------------------------------------------------------
3322 // ASIT Selection Function - Source Selection
3323 //
3324 //   Name:      PAF_ASIT_sourceDecode
3325 //   Purpose:   Audio Input Stream Task Function for selecting the sources used
3326 //              for decoding of input to output.
3327 //   From:      audioStream1Task or equivalent
3328 //   Uses:      See code.
3329 //   States:    x
3330 //   Return:    0.
3331 //   Trace:     None.
3332 //
3333 Int
3334 PAF_ASIT_sourceDecode(
3335     const PAF_ASIT_Params *pP, 
3336     const PAF_ASIT_Patchs *pQ, 
3337     PAF_ASIT_Config *pAsitCfg, 
3338     Int x
3341     PAF_AST_Config *pAstCfg;
3342     Int z;                              /* decode counter */
3343     Int8 tempVar8;
3345     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
3347     for (z=DECODE1; z < DECODEN; z++)
3348     {
3349         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
3350                                      GATEMP_INDEX_DEC);
3351         if (tempVar8)
3352         {
3353             tempVar8 = x;
3354             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
3355                                tempVar8, GATEMP_INDEX_DEC);
3356         }
3357     }
3358     
3359     return 0;
3360 } //PAF_ASIT_sourceDecode
3362 // -----------------------------------------------------------------------------
3364 #if 0 // (***) FL: no longer used w/ removal of CONTINUOUS mode
3365 Int
3366 PAF_AST_decodeHandleErrorInput (const PAF_AST_Params *pP, const PAF_AST_Patchs *pQ, PAF_AST_Config *pC, ALG_Handle decAlg[], Int z, Int error)
3368     Int errno = 0;
3369     Int zMD = pC->masterDec;
3370     Int zI = pP->inputsFromDecodes[z];
3372     // only handle real errors, on primary input, for writeDECModeContinuous
3373     if ( !( error &&
3374             z == zMD ))
3375         return error;
3377     TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: (primary) input error caught = %d", pC->as+z, error));
3378     TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: old sourceProgram = %d", pC->as+z, pC->xDec[z].decodeStatus.sourceProgram));
3380     if (pC->xInp[zI].hRxSio) {
3381         DEC_Handle dec;
3383         if (errno = SIO_idle (pC->xInp[zI].hRxSio))
3384             return errno;
3386         // indicates (primary) input not running
3387         pC->xDec[z].decodeStatus.sourceDecode = PAF_SOURCE_NONE;
3389         pC->xInp[zI].inpBufConfig.deliverZeros = 1;
3391         // will be changed after next reclaim, to PAF_SOURCE_UNKNOWN or other
3392         pC->xDec[z].decodeStatus.sourceProgram = PAF_SOURCE_NONE;
3394         if (decAlg[z]->fxns->algDeactivate)
3395             decAlg[z]->fxns->algDeactivate (decAlg[z]);
3397         decAlg[z] = pC->xDec[z].decAlg[PAF_SOURCE_PCM];
3398         dec = (DEC_Handle )decAlg[z];
3400         TRACE_TIME((&TIME_MOD, "AS%d: PAF_AST_decodeHandleErrorInput: resetting to PCM decoder",
3401                     pC->as+z));
3403         if (decAlg[z]->fxns->algActivate)
3404             decAlg[z]->fxns->algActivate (decAlg[z]);
3406         if (dec->fxns->reset
3407             && (errno = dec->fxns->reset (dec, NULL,
3408                                           &pC->xDec[z].decodeControl, &pC->xDec[z].decodeStatus)))
3409             return errno;
3410     }
3412     return errno;
3413 } //PAF_AST_decodeHandleErrorInput
3414 #endif
3416 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
3418 //------------------------------------------------------------------------------
3419 static int sSkipCount = 0;
3420 int gReportBuffers = 0;
3421 void as_traceChannels(PAF_AST_Config *pC, int z)
3423     PAF_AudioFrame *pAudioFrame = pC->xDec[z].decodeInStruct.pAudioFrame;
3424     int i;
3425          
3426 // #ifdef THIS_IS_DSPA
3427     sSkipCount++;
3428     if (sSkipCount<1)
3429         return;
3430     sSkipCount = 0;
3431 // #endif
3433 #ifdef THIS_IS_DSPB
3434     if (!gReportBuffers)
3435         return;
3436     gReportBuffers = 0;
3437 #endif
3439     dp(NULL, "\n");
3440     for (i=0; i<PAF_MAXNUMCHAN; i++)
3441     {
3442         if (pAudioFrame->data.sample[i] != 0)
3443         {
3444             float *wp = (float*)pAudioFrame->data.sample[i];
3445                dp(NULL, "i: %d.  p: 0x%x.  %f, %f, %f, %f\n",
3446                        i, pAudioFrame->data.sample[i], wp[0], wp[1], wp[2], wp[3]);
3447         }
3448     }
3450 #endif