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