]> 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 =