]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/audioStreamOutProc.c
Update comments
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutProc.c
2 /*
3 Copyright (c) 2018, 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  *  ======== audioStreamOutProc.c ========
38  */
40 #include <xdc/runtime/Log.h>
41 #include <ti/sysbios/BIOS.h>
43 #include "aspOutInitSync_master.h"
44 #include "audioStreamProc_common.h"
45 #include "audioStreamOutProc.h"
46 #include "audioStreamOutInit.h"
47 #include "audioStreamOutDec.h"
48 #include "audioStreamOutIo.h"
50 //#include "pfp/pfp.h"
51 //#include "pfp_app.h"        /* contains all PFP ID's */
52 //Int32 gNumPfpAsot1=0; // debug
54 // debug
55 #include "evmc66x_gpio_dbg.h"
57 //#include "ioConfig.h"
59 // -----------------------------------------------------------------------------
60 // Debugging Trace Control, local to this file.
61 // 
62 #include "logp.h"
64 // Allow a developer to selectively enable tracing.
65 #define CURRENT_TRACE_MASK      0x07
67 #define TRACE_MASK_TERSE        0x01   // only flag errors and show init
68 #define TRACE_MASK_GENERAL      0x02   // half dozen lines per frame
69 #define TRACE_MASK_VERBOSE      0x04   // trace full operation
71 #if !(CURRENT_TRACE_MASK & TRACE_MASK_TERSE)
72     #undef  TRACE_TERSE0
73     #undef  TRACE_TERSE1
74     #undef  TRACE_TERSE2
75     #undef  TRACE_TERSE3
76     #undef  TRACE_TERSE4
77     #define TRACE_TERSE0(a)
78     #define TRACE_TERSE1(a,b)
79     #define TRACE_TERSE2(a,b,c)
80     #define TRACE_TERSE3(a,b,c,d)
81     #define TRACE_TERSE4(a,b,c,d,e)
82 #endif
83     
84 #if !(CURRENT_TRACE_MASK & TRACE_MASK_GENERAL)
85     #undef  TRACE_GEN0
86     #undef  TRACE_GEN1
87     #undef  TRACE_GEN2
88     #undef  TRACE_GEN3
89     #undef  TRACE_GEN4
90     #define TRACE_GEN0(a)
91     #define TRACE_GEN1(a,b)
92     #define TRACE_GEN2(a,b,c)
93     #define TRACE_GEN3(a,b,c,d)
94     #define TRACE_GEN4(a,b,c,d,e)
95 #endif
97 #if !(CURRENT_TRACE_MASK & TRACE_MASK_VERBOSE)
98     #undef  TRACE_VERBOSE0
99     #undef  TRACE_VERBOSE1
100     #undef  TRACE_VERBOSE2
101     #undef  TRACE_VERBOSE3
102     #undef  TRACE_VERBOSE4
103     #define TRACE_VERBOSE0(a)
104     #define TRACE_VERBOSE1(a,b)
105     #define TRACE_VERBOSE2(a,b,c)
106     #define TRACE_VERBOSE3(a,b,c,d)
107     #define TRACE_VERBOSE4(a,b,c,d,e)
108 #endif
110 // -----------------------------------------------------------------------------
111 //
112 // Audio Stream Output Task definitions
113 //
115 #define __TASK_NAME__  "TaskAsop"
117 // status codes
118 // ASOT FSM
119 #define ASOP_SOK_INITSYNC_NOTREADY              (   1 ) // ok, init-sync not ready
120 #define ASOP_SOK                                (   0 ) // ok
121 #define ASOP_ERR_FORWARD_ERR                    (  -1 ) // error, forward (ASIT) error
122 #define ASOP_ERR_RESETOUTPROC_NOOUTDEVSEL       (  -2 ) // error, reset dec out proc, no output device selected
123 #define ASOP_ERR_PROCDECOUT_OUTDEVSELUPD        (  -3 ) // error, proc dec out, output device select updated
124 #define ASOP_ERR_PROCDECOUT_IOPHYXFERCOMPLETE   (  -4 ) // error, proc dec out, io phy transfer complete
125 #define ASOP_ERR_PROCDECOUT_CHKOUTDEVSELUPD     (  -5 ) // error, proc dec out, check output device select update
127 // -----------------------------------------------------------------------------
129 // ASOT FSM states 
130 enum 
131
132     ASOT_STATE_SEL_OUT_DEV, 
133     ASOT_STATE_RESET_OUT_PROC, 
134     ASOT_STATE_INITSYNC_DEC_INFO1, 
135     ASOT_STATE_INITSYNC_DEC_DECODE1, 
136     ASOT_STATE_PROC_DEC_OUT,
137     ASOT_STATE_RESEL_OUT_DEV,
138     ASOT_STATE_INITSYNC_RESYNC
139 };
141 // Check if Output device selected
142 static Int checkOutDevSel(
143     PAF_AST_IoOut *pOut,
144     Bool *pOutDevSel);
145     
146 // Check if any Output device selected
147 static Int checkAnyOutDevSel(
148     const PAF_ASOT_Params *pP,
149     PAF_AST_IoOut *pOut,
150     Bool *pOutDevSel);
152 // ASOT SM function
153 //   Purpose:   Audio Stream Output Task Function for selecting the devices used
154 //              for output.
155 static Int PAF_ASOT_selectDevices(
156     const PAF_ASOT_Params *pP, 
157     const PAF_ASOT_Patchs *pQ, 
158     PAF_ASOT_Config *pAsotCfg,
159     Bool *pOutDevSel
160 );
162 // Reset audio frame pointers to original values
163 static Void resetAfPointers(
164     const PAF_ASOT_Params *pP, 
165     PAF_AST_Stream *xStr
166 );
168 // Reset audio frame meta data elements
169 static Void resetAfMetadata(
170     const PAF_ASOT_Params *pP, 
171     PAF_AST_Stream *xStr
172 );
174 // Reset audio frames
175 static Void resetAfs(
176     const PAF_ASOT_Params *pP, 
177     PAF_AST_Stream *xStr
178 );
180 // used by new OutProc.c, will be changed back to static once refactoring is done
181 //   Purpose:   Init-Sync Dec Reset state function.
182 //              Performs Dec Reset Init-Sync.
183 static Int PAF_ASOT_initSyncDecReset(
184     const PAF_ASOT_Params *pP, 
185     const PAF_ASOT_Patchs *pQ, 
186     PAF_ASOT_Config *pAsotCfg,
187     PAF_AudioFrame *pDecResetAf,
188     Int frame
189 );
191 // ASOT SM function
192 // Reset Decoder Output processing
193 static Int PAF_ASOT_resetDecOutProc(
194     const PAF_ASOT_Params *pP, 
195     const PAF_ASOT_Patchs *pQ, 
196     PAF_ASOT_Config *pAsotCfg,
197     PAF_AudioFrame *pDecResetAf,
198     Bool outDevSel,
199     Int frame
200 );
202 // ASOT SM function
203 //   Purpose:   Init-Sync Dec Info1 state function.
204 //              Performs Dec Info1 Init-Sync.
205 static Int PAF_ASOT_initSyncDecInfo1(
206     const PAF_ASOT_Params *pP, 
207     const PAF_ASOT_Patchs *pQ, 
208     PAF_ASOT_Config *pAsotCfg,
209     PAF_AudioFrame *pDecInfo1Af, 
210     Int frame
211 );
213 // ASOT SM function
214 //   Purpose:   Init-Sync Dec Decode1 state function.
215 //              Performs Dec Decode1 Init-Sync.
216 static Int PAF_ASOT_initSyncDecDecode1(
217     const PAF_ASOT_Params *pP, 
218     const PAF_ASOT_Patchs *pQ, 
219     PAF_ASOT_Config *pAsotCfg, 
220     Int frame
221 );
223 // ASOT SM function
224 // Process Decoder output audio data
225 static Int PAF_ASOT_procDecOut(
226     const PAF_ASOT_Params *pP, 
227     const PAF_ASOT_Patchs *pQ, 
228     PAF_ASOT_Config *pAsotCfg, 
229     Bool *pFirstTime, 
230     Int frame
231 );
233 // ASOT SM function
234 //   Purpose:   Init-Sync Re-Sync state function.
235 //              Performs Init-Sync using stored Dec Reset/Info1 AFs.
236 static Int PAF_ASOT_initSyncResync(
237     const PAF_ASOT_Params *pP, 
238     const PAF_ASOT_Patchs *pQ, 
239     PAF_ASOT_Config *pAsotCfg,
240     PAF_AudioFrame *pDecResetAf,
241     PAF_AudioFrame *pDecInfo1Af, 
242     Int frame
243 );
245 // ASOT SM function
246 //   Purpose:   Re-select devices used for Output.
247 //              Performs Init-Sync using stored Dec Reset/Info1 AFs.
248 static Int PAF_ASOT_reselectDevices(
249     const PAF_ASOT_Params *pP, 
250     const PAF_ASOT_Patchs *pQ, 
251     PAF_ASOT_Config *pAsotCfg,
252     PAF_AudioFrame *pDecResetAf,
253     PAF_AudioFrame *pDecInfo1Af,
254     Int frame, 
255     Bool *pOutDevSel
256 );
257    
259 // FL: debug, allow modification of Output frame length via JTAG.
260 Int16 gOutFrameLen=PAF_ASOT_FRAMELENGTH; // output frame length (PCM samples)
262 // ASOT configuration
263 #pragma DATA_SECTION(gPAF_ASOT_config, ".globalSectionPafAsotConfig")
264 PAF_ASOT_Config gPAF_ASOT_config = {
265     NULL,               // taskHandle
266     0,                  // asotState
267     NULL,               // acp
268     0,0,0,              // cbDrainedFlag (size DECODE_MAXN)
269     &gPAF_ASPM_config,  // pAspmCfg
270     &gPAF_AST_config    // pAstCfg
271 };
273 // ASOT event handle - to put in structure
274 Event_Handle gAsotEvtHandle;
276 extern Int d10Initialized;
278 // For writeDECCommandRestart
279 extern volatile UInt32 gCommandOutputTask_SYNC;
280 extern volatile UInt32 gCommandOutputTask_ACK;
282 LINNO_DEFN(TaskAsop); // Line number macros
283 ERRNO_DEFN(TaskAsop); // Error number macros
285 #define ASOP_DEBUG
286 #ifdef ASOP_DEBUG
287 Int asopLoopCount;
288 #endif
290 // Debug event-in-state counters
291 UInt32 gSelOutDevState_EvtWakeTimer_cnt                 = 0; // Select Output state, Wake Timer event count
292 UInt32 gSelOutDevState_EvtTxMcaspEdma_invCnt            = 0; // Select Output state, invalid Tx McASP EDMA event count
293 UInt32 gSelOutDevState_Evt_invCnt                       = 0; // Select Output state, invalid other event count
294 UInt32 gResetOutProcState_EvtWakeTimer_cnt              = 0; // Select Output state, Wake Timer event count
295 UInt32 gResetOutProcState_EvtTxMcaspEdma_invCnt         = 0; // Reset Output Processing state, invalid Tx McASP EDMA event count
296 UInt32 gResetOutProcState_Evt_invCnt                    = 0; // Reset Output Processing state, invalid other event count
297 UInt32 gInitSyncDecInfo1State_EvtWakeTimer_cnt          = 0; // Init-Sync Dec Info1 state, Wake Timer event count
298 UInt32 gInitSyncDecInfo1State_EvtTxMcaspEdma_invCnt     = 0; // Init-Sync Dec Info1 state, invalid Tx McASP EDMA event count
299 UInt32 gInitSyncDecInfo1State_Evt_invCnt                = 0; // Init-Sync Dec Info1 state, invalid other event count
300 UInt32 gInitSyncDecDecode1State_EvtWakeTimer_cnt        = 0; // Init-Sync Dec Decode1 state, Wake Timer event count
301 UInt32 gInitSyncDecDecode1State_EvtTxMcaspEdma_invCnt   = 0; // Init-Sync Dec Decode1 state, invalid Tx McASP EDMA event count
302 UInt32 gInitSyncDecDecode1State_Evt_invCnt              = 0; // Init-Sync Dec Decode1 state, invalid other event count
303 UInt32 gProcDecOutState_EvtWakeTimer_cnt                = 0; // Process Output state, Wake Timer event count 
304 UInt32 gProcDecOutState_EvtTxMcaspEdma_cnt              = 0; // Process Output state, Tx McASP EDMA event count
305 UInt32 gProcDecOutState_Evt_invCnt                      = 0; // Process Output state, invalid other event count
306 UInt32 gReselOutDevState_EvtWakeTimer_cnt               = 0; // Process Output state, Wake Timer event count 
307 UInt32 gReselOutDevState_EvtTxMcaspEdma_invCnt          = 0; // Re-select Output state, invalid other event count
308 UInt32 gReselOutDevState_Evt_invCnt                     = 0; // Re-select Output state, invalid other event count
309 // Debug state counters
310 UInt32 gAsotInitSyncResyncState_Cnt                     = 0; // Init-Sync Re-sync (Local error) state execution count
311 UInt32 gAsotInvState_Cnt                                = 0; // invalid state count
314 /*
315  *  ======== taskAsopFxn ========
316  *  Audio Stream Output Processing task function
317  */
318 Void taskAsopFxn(
319     const PAF_ASOT_Params *pP,
320     const PAF_ASOT_Patchs *pQ
323     PAF_ASOT_Config *pAsotCfg;      // ASOT configuration pointer
324     PAF_AST_Config *pAstCfg;        // Common (shared) configuration pointer
325     Int as;                         // Audio Stream Number (1, 2, etc.)
326     Int z;                          // input/encode/stream/decode/output counter
327     Bool outDevSel;                 // whether output device selected
328     PAF_AudioFrame decResetAf;
329     PAF_AudioFrame decInfo1Af;
330     UInt events;                    // latched event flags
331     Bool procEvents;                // process events flags
332     Bool procOutFirstTime;          // first time process output flag
333     Int asopFrameCount;             // frame counter
334     Int status;                     // status code
335 #ifndef ASOP_DEBUG
336     Int asopLoopCount;              // debug, ASOT loop counter
337 #endif
339     Log_info0("Enter taskAsopFxn()");
341     taskAsopFxnInit(pP, pQ);    // initialization of output task
342     
343     //
344     // Audio Stream Output Task Configuration (*pAsotCfg):
345     //
346     pAsotCfg = &gPAF_ASOT_config;       // initialize pointer to task configuration
347     pAstCfg = pAsotCfg->pAstCfg;        // get pointer to AST common (shared) configuration
348     as = pAstCfg->as;                   // obtain Audio Stream Number (1, 2, etc.)
350     //
351     // Main processing loop
352     //
353     for (z=STREAM1; z < STREAMN; z++)
354     {
355         TRACE_VERBOSE1("TaskAsop: AS%d: running", as+z);
356     }
358     pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;   // init state
359     procEvents = TRUE;                          // init proc events flag
360     procOutFirstTime = TRUE;                    // init first time process output flag
361     asopFrameCount = 0;                         // init frame counter TBD
362     asopLoopCount = 0;                          // loop counter
363     for (;;)
364     {
365         // Pend for next event
366         //  Evt_Id_AsotWakeTimer    : Wakeup timer (poll for Output device selection)
367         //  Evt_Id_AsotTxMcaspEdma  : Tx McASP EDMA completion
368         if (procEvents == TRUE)
369         {
370             events = Event_pend(gAsotEvtHandle, Event_Id_NONE, (Evt_Id_AsotWakeTimer + Evt_Id_AsotTxMcaspEdma), BIOS_WAIT_FOREVER);
371         }
373         asopLoopCount++;
374         TRACE_GEN1("TaskAsop (begin Main loop %d)", asopLoopCount);
376         switch (pAsotCfg->state)
377         {
378             //
379             //  Select Output Device state
380             //
381             case ASOT_STATE_SEL_OUT_DEV:
382                 if (events & Evt_Id_AsotWakeTimer)
383                 {
384                     gSelOutDevState_EvtWakeTimer_cnt++;
385                     events &= ~Evt_Id_AsotWakeTimer; // clear event
386                     
387                     // Select Output devices
388                     //  outDevSel==TRUE if Output device selection successful
389                     status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
390                     if (status < 0)
391                     {
392                         // FL, New IO: 
393                         //Tx status==error message to ASIT;   // ASOT initiated message to ASIT, "backward" error
394                         
395                         // No explicit handling of Select Output Device error, so stay in state and try again
396                         pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
397                         break;
398                     }
399                     else if (outDevSel == TRUE)
400                     {
401                         // Select successful
402                         pAsotCfg->state = ASOT_STATE_RESET_OUT_PROC;
403                     }
404                     else
405                     {
406                         // No output device selected (outDevSel == FALSE).
407                         // Remain in current state.
408                         ;
409                     }
410                 }
411                 
412                 // Check for unexpected Tx McASP EDMA event
413                 if (events & Evt_Id_AsotTxMcaspEdma)
414                 {
415                     gSelOutDevState_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
416                     TRACE_TERSE2("TaskAsop: invalid Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
417                     events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
418                 }
420                 // Check for any other unexpected events
421                 if (events != 0)
422                 {
423                     gSelOutDevState_Evt_invCnt++; // log invalid event count in state
424                     TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
425                     events &= ~events; // clear events
426                 }
427                 
428                 break;
429                 
430             // FL, New IO: currently using timer event
431             //
432             //  Reset Output Processing state
433             //
434             case ASOT_STATE_RESET_OUT_PROC:
435                 if (events & Evt_Id_AsotWakeTimer)
436                 {
437                     gResetOutProcState_EvtWakeTimer_cnt++;
438                     events &= ~Evt_Id_AsotWakeTimer; // clear event
439                     
440                     //
441                     // Allow Output device re-selection prior to Output processing.
442                     //  Output device selection has already been performed in state==ASOT_STATE_SEL_OUT_DEV.
443                     //  Output device can be re-selected via alpha commands before streaming is initiated.
444                     //  Here check whether this has occurred.
445                     //
446                     
447                     // Select Output devices
448                     //  outDevSel==TRUE if Output device selection successful
449                     status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
450                     if (status < 0)
451                     {
452                         // FL, New IO: 
453                         //Tx status==error message to ASIT;   // ASOT initiated message to ASIT, "backward" error
454                         
455                         // Starting over with Output device selection in case of error                        
456                         pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
457                         break;
458                     }
459                     
460                     // Reset Output processing
461                     status = PAF_ASOT_resetDecOutProc(pP, pQ, pAsotCfg, &decResetAf, outDevSel, asopFrameCount);
462                     if (status < 0)
463                     {
464                         // FL, New IO: 
465                         //Tx status==error message to ASDT; // feedback message ASOT -> ASDT
466                         
467                         pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;   // starting over with Output device selection in case of error
468                         break;
469                     }
470                     else if (status == ASOP_SOK_INITSYNC_NOTREADY)
471                     {
472                         // FL, New IO: this is only necessary for Wake Timer, POLLING Init-Sync
473                         // FL, New IO: can be removed once Rx ASDT messages are implemented for Init-Sync
474                         
475                         // Dec Reset Init-Sync not ready.
476                         // Remain in current state.
477                         ;
478                     }
479                     else
480                     {
481                         // FL, New IO: 
482                         //Tx status==ok message to ASDT; // feedback message ASOT -> ASDT
483                         
484                         pAsotCfg->state = ASOT_STATE_INITSYNC_DEC_INFO1;
485                     }
486                 }
487                 
488                 // Check for unexpected Tx McASP EDMA event
489                 if (events & Evt_Id_AsotTxMcaspEdma)
490                 {
491                     gResetOutProcState_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
492                     TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
493                     events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
494                 }
496                 // Check for any other unexpected events
497                 if (events != 0)
498                 {
499                     gResetOutProcState_Evt_invCnt++; // log invalid event count in state
500                     TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
501                     events &= ~events; // clear events
502                 }
503                 
504                 break;
505                 
506             // FL, New IO: currently using timer event
507             //
508             //  Init-Sync Info1 state
509             //
510             case ASOT_STATE_INITSYNC_DEC_INFO1:
511                 if (events & Evt_Id_AsotWakeTimer)
512                 {
513                     gInitSyncDecInfo1State_EvtWakeTimer_cnt++;
514                     events &= ~Evt_Id_AsotWakeTimer; // clear event
515                     
516                     status = PAF_ASOT_initSyncDecInfo1(pP, pQ, pAsotCfg, &decInfo1Af, asopFrameCount);
517                     if (status < 0)
518                     {
519                         // FL, New IO: 
520                         //Tx status==error message to ASDT;   // feedback message ASOT -> ASDT
521                         
522                         pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;          // starting over with Output device selection in case of error
523                         break;
524                     }
525                     else if (status == ASOP_SOK_INITSYNC_NOTREADY)
526                     {
527                         // FL, New IO: this is only necessary for Wake Timer, POLLING Init-Sync
528                         // FL, New IO: can be removed once Rx ASDT messages are implemented for Init-Sync
529                         
530                         // Dec Reset Init-Sync not ready.
531                         // Remain in current state.
532                         ;
533                     }
534                     else
535                     {
536                         // FL, New IO: 
537                         //Tx status==ok message to ASDT;      // feedback message ASOT -> ASDT
538                         
539                         pAsotCfg->state = ASOT_STATE_INITSYNC_DEC_DECODE1;
540                     }
541                 }
543                 // Check for unexpected Tx McASP EDMA event
544                 if (events & Evt_Id_AsotTxMcaspEdma)
545                 {
546                     gInitSyncDecInfo1State_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
547                     TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
548                     events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
549                 }
551                 // Check for any other unexpected events
552                 if (events != 0)
553                 {
554                     gInitSyncDecInfo1State_Evt_invCnt++; // log invalid event count in state
555                     TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
556                     events &= ~events; // clear events
557                 }
558                 
559                 break;
560             
561             // FL, New IO: currently using timer event
562             //
563             //  Init-Sync Decode1 state
564             //
565             case ASOT_STATE_INITSYNC_DEC_DECODE1:
566                 if (events & Evt_Id_AsotWakeTimer)
567                 {
568                     gInitSyncDecDecode1State_EvtWakeTimer_cnt++;
569                     events &= ~Evt_Id_AsotWakeTimer; // clear event
570                     
571                     status = PAF_ASOT_initSyncDecDecode1(pP, pQ, pAsotCfg, asopFrameCount);
572                     if (status < 0)
573                     {
574                         // FL, New IO: 
575                         //Tx status==error message to ASDT;   // feedback message ASOT -> ASDT
576                         
577                         pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;          // starting over with Output device selection in case of error
578                         break;
579                     }
580                     else if (status == ASOP_SOK_INITSYNC_NOTREADY)
581                     {
582                         // FL, New IO: this is only necessary for Wake Timer, POLLING Init-Sync
583                         // FL, New IO: can be removed once Rx ASDT messages are implemented for Init-Sync
584                         
585                         // Dec Reset Init-Sync not ready.
586                         // Remain in current state.
587                         ;
588                     }
589                     else
590                     {
591                         // FL, New IO: 
592                         //Tx status==ok message to ASDT;      // feedback message ASOT -> ASDT
593                         
594                         pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
595                         procOutFirstTime = TRUE;
596                     }
597                 }
598             
599                 // Check for unexpected Tx McASP EDMA event
600                 if (events & Evt_Id_AsotTxMcaspEdma)
601                 {
602                     gInitSyncDecDecode1State_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
603                     TRACE_TERSE2("TaskAsop: Tx McASP EDMA event, state=%u, events=%u", pAsotCfg->state, events);
604                     events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
605                 }
607                 // Check for any other unexpected events
608                 if (events != 0)
609                 {
610                     gInitSyncDecDecode1State_Evt_invCnt++; // log invalid event count in state
611                     TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
612                     events &= ~events; // clear events
613                 }
614                 
615                 break;
616                 
617             //
618             //  Process Decoder Output state
619             //
620             case ASOT_STATE_PROC_DEC_OUT:
621                 if (events & Evt_Id_AsotTxMcaspEdma)
622                 {
623                     gProcDecOutState_EvtTxMcaspEdma_cnt++;
624                     events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
625                     
626 #if 1 // (***) FL: shows timing of Output (Tx McASP EDMA)
627                     // (***) debug // B8
628                     {
629                         static Uint8 toggleState = 0;
630                         if (toggleState == 0)
631                             GPIOSetOutput(GPIO_PORT_0, GPIO_PIN_106);
632                         else
633                             GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_106);
634                         toggleState = ~(toggleState);
635                     }
636 #endif                                 
637                     
638                     // Process Output
639                     status = PAF_ASOT_procDecOut(pP, pQ, pAsotCfg, &procOutFirstTime, asopFrameCount);
640                     if (status < 0)
641                     {
642                         if (status == ASOP_DOP_ERR_FINALTEST_CBDRAINED)
643                         {
644                             // normal completion, CB drained @ EOS
645                             pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;
646                             break;
647                             
648                         }
649                         else if (status == ASOP_ERR_PROCDECOUT_OUTDEVSELUPD)
650                         {
651                             // Output re-select
652                             pAsotCfg->state = ASOT_STATE_RESEL_OUT_DEV;
653                             break;
654                         }
655                         // FL, New IO: "backward" error handling.
656                         // Currently all errors handled locally.
657                         else
658                         {
659                             // Handle ASOT "local" errors
660                             pAsotCfg->state = ASOT_STATE_INITSYNC_RESYNC;
661                             procEvents = FALSE;
662                             break;
663                         }
664                     }
665                 }
666             
667                 // Check for Wakeup Timer event.
668                 //  Wakeup Timer events are allowed to occur, but no processing is 
669                 //  performed in response to such an event.
670                 if (events & Evt_Id_AsotWakeTimer)
671                 {
672                     events &= ~Evt_Id_AsotWakeTimer; // clear event
673                     gProcDecOutState_EvtWakeTimer_cnt++; // log event count in state
674                 }
675             
676                 // Check for any other unexpected events
677                 if (events != 0)
678                 {
679                     gProcDecOutState_Evt_invCnt++; // log invalid event count in state
680                     TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
681                     events &= ~events; // clear events
682                 }
683             
684                 break;
685                 
686             //
687             //  Re-Select Output Device state
688             //
689             case ASOT_STATE_RESEL_OUT_DEV:
690                 if (events & Evt_Id_AsotWakeTimer)
691                 {
692                     gReselOutDevState_EvtWakeTimer_cnt++;
693                     events &= ~Evt_Id_AsotWakeTimer; // clear event
694                     
695                     status = PAF_ASOT_reselectDevices(pP, pQ, pAsotCfg, &decResetAf, &decInfo1Af, asopFrameCount, &outDevSel);
696                     if (status < 0)
697                     {
698                         // FL, New IO: 
699                         //Tx status==error message to ASIT;       // ASOT initiated message to ASIT, "backward" error
700                         
701                         pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;   // starting over with Output device selection in case of error
702                         break;
703                     }
704                     else if (outDevSel == TRUE)
705                     {
706                         // Re-select successful
707                         pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
708                         procOutFirstTime = TRUE;
709                     }
710                     else
711                     {
712                         // No output device selected (outDevSel == FALSE).
713                         // Remain in current state.
714                         ;                
715                     }
716                 }
717             
718                 // Check for unexpected Tx McASP EDMA event
719                 if (events & Evt_Id_AsotTxMcaspEdma)
720                 {
721                     events &= ~Evt_Id_AsotTxMcaspEdma; // clear event
722                     gReselOutDevState_EvtTxMcaspEdma_invCnt++; // log invalid event count in state
723                 }
725                 // Check for any other unexpected events
726                 if (events != 0)
727                 {
728                     gReselOutDevState_Evt_invCnt++; // log invalid event count in state
729                     TRACE_TERSE2("TaskAsop: invalid events, state=%u, events=%u", pAsotCfg->state, events);
730                     events &= ~events; // clear events
731                 }
732             
733                 break;
734                 
735             //
736             //   Init-Sync Re-sync (Process Output Local Error) state
737             //
738             case ASOT_STATE_INITSYNC_RESYNC: // not event driven state
739                 gAsotInitSyncResyncState_Cnt++;
740                 
741                 status = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, &decResetAf, &decInfo1Af, asopFrameCount);
742                 if (status < 0)
743                 {
744                     // FL, New IO: 
745                     //Tx status==error message to ASIT;   // ASIT initiated message to ASOT, "backward" error
746                     
747                     pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;     // starting over with Output device selection in case of error
748                     procEvents = TRUE;
749                     break;
750                 }
751                 else
752                 {
753                     pAsotCfg->state = ASOT_STATE_PROC_DEC_OUT;
754                     procEvents = TRUE;
755                     procOutFirstTime = TRUE;
756                 }
757             
758                 break;
759                 
760             default: 
761                 gAsotInvState_Cnt++;
762                 TRACE_TERSE1("TaskAsop: invalid state, state=%u", pAsotCfg->state);
763             
764                 break;
765         }
767         // FL, New IO: handle ASIT messages separately in each state
768         // FL, New IO: proper SM clean up can be skipped if forward error / DEC restart is handled in this way
769         
770         //
771         // Check forward (ASIT) error, TBD
772         //
773         
774         // Check writeDECCommandRestart, TBD
775         if (gCommandOutputTask_SYNC) 
776         {
777             TRACE_TERSE0("TaskAsop: ack writeDECCommandRestart ... Wait for command de-assert");
778             gCommandOutputTask_ACK = 1;
779             while (gCommandOutputTask_SYNC) 
780             {
781                 Event_pend(gAsotEvtHandle, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
782             }
783             TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Re-start the process");
784             pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;   // init state -- start over
785             status = ASOP_ERR_FORWARD_ERR;              // set status -- force flushing of output device
786         }
788         // any error forces idling of output
789         if (status < 0)
790         {
791             for (z=OUTPUT1; z < OUTPUTN; z++)
792             {
793                 //if (pAstCfg->xOut[z].hTxSio)
794                 if (pAsotCfg->pIoOut[z].hIoPhy)
795                 {
796                     //SIO_idle(pAstCfg->xOut[z].hTxSio);  JX TO DO: implement proper error handling
797                 }
798             }
800             TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", asopLoopCount);
801             //ERRNO_RPRT(TaskAsop, errno);
802         }
803     } // End of main processing loop for (;;)
804 } /* taskAsopFxn */
806 // ASOT wake timer (clock) function
807 Void clkAsotFxn(Void)
809     Event_post(gAsotEvtHandle, Evt_Id_AsotWakeTimer);
812 void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
814     /* post semaphore */
815     if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
816         //Semaphore_post(asopSemTx);
817         Event_post(gAsotEvtHandle, Evt_Id_AsotTxMcaspEdma);
818     } else {
819         ;    // intermediate packet due to buffer wrapping around
820     }
823 // Reset audio frame pointers to original values
824 static Void resetAfPointers(
825     const PAF_ASOT_Params *pP, 
826     PAF_AST_Stream *xStr
829     Int z;
830     Int ch;
832     // Reset audio frame pointers to original values
833     for (z = STREAM1; z < STREAMN; z++) 
834     {
835         for (ch = PAF_LEFT; ch < PAF_MAXNUMCHAN_AF; ch++) 
836         {
837             if (xStr[z].audioFrameChannelPointers[ch])
838             {
839                 xStr[z].audioFrameChannelPointers[ch] = 
840                     xStr[z].origAudioFrameChannelPointers[ch];
841             }
842         }
843     }
846 // Check if Output device selected
847 static Int checkOutDevSel(
848     PAF_AST_IoOut *pOut,
849     Bool *pOutDevSel
852     *pOutDevSel = (Bool)(pOut->hMcaspChan != NULL);
853     
854     return ASOP_SOK;
857 // Check if any Output device selected
858 static Int checkAnyOutDevSel(
859     const PAF_ASOT_Params *pP,
860     PAF_AST_IoOut *pOut, 
861     Bool *pOutDevSel
864     Bool outDevSel;
865     Int z;
867     outDevSel = FALSE;
868     for (z=OUTPUT1; z < OUTPUTN; z++)
869     {
870         if (pOut[z].hMcaspChan)
871         {
872             outDevSel = TRUE;
873             break;
874         }
875     }
877     *pOutDevSel = outDevSel;
879     return ASOP_SOK;
882 // ASOT SM function
883 // -----------------------------------------------------------------------------
884 // ASOT Selection Function - Output Device Selection
885 //
886 //   Name:      PAF_ASOT_selectDevices
887 //   Purpose:   Audio Stream Output Task Function for selecting the devices used
888 //              for output.
889 //
890 static Int PAF_ASOT_selectDevices(
891     const PAF_ASOT_Params *pP, 
892     const PAF_ASOT_Patchs *pQ, 
893     PAF_ASOT_Config *pAsotCfg,
894     Bool *pOutDevSel
897     PAF_AST_Config *pAstCfg;        // Common (shared) configuration pointer
898     Int z;
899     Int zS, zO;
900     Int device;
901     Int status;
902     Bool ioPhyInit;
903     
904     pAstCfg = pAsotCfg->pAstCfg;        // get pointer to AST common (shared) configuration
906     // Find first Output associated with Master Stream
907     zO = OUTPUT1;
908     for (z=ENCODE1; z < ENCODEN; z++)
909     {
910         zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
911         if (zS == pAstCfg->masterStr)
912         {
913             // This Encoder is associated with Master Stream.
914             // Note other Encoder can also be associated with Master Stream.
915             zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
916         }
917     }
918     
919     ioPhyInit = asopIoPhyCheckInit(); // check if IO Phy is initialized
920     device = pAstCfg->xOut[zO].outBufStatus.sioSelect; // obtain SIO select for Output
921     if ((ioPhyInit == TRUE) && (device >= 0))
922     {
923         // check for valid index into device array
924         if (device >= pQ->devout->n)
925         {
926             device = 0; // treat as device None
927         }
928         
929         if (device > 0)
930         {
931             // Select Output Devices
932             //  FL, New IO: Placeholder function, this will be reorganized moving forward.
933             //  FL, New IO: API for single Output.
934             //  FL, New IO: Doesn't (re-)configure Output driver.
935             status = asopSelectDevices(&pAsotCfg->pIoOut[zO]);
936             if (status < 0)
937             {
938                 pAstCfg->xOut[zO].outBufStatus.sioSelect = 0x80;
939                 *pOutDevSel = FALSE;
940                 return status;
941             }
942             
943             // Reset IO Buff & IO Phy
944             //  FL, New IO: API for single Output
945             status = asopIoCompsInit(&pAstCfg->xOut[zO], &pAsotCfg->pIoOut[zO]);
946             if (status < 0)
947             {
948                 pAstCfg->xOut[zO].outBufStatus.sioSelect = 0x80;
949                 *pOutDevSel = FALSE;
950                 return status;
951             }
952         }
954         pAstCfg->xOut[zO].outBufStatus.sioSelect = device | 0x80;
955     }
956     
957     // Check if Output device selected
958     //  FL, New IO: API for single Output
959     status = checkOutDevSel(&pAsotCfg->pIoOut[zO], pOutDevSel);
960     if (status < 0)
961     {
962         *pOutDevSel = FALSE;
963         return status;
964     }
965     
966     return ASOP_SOK;
969 // ASOT SM function
970 //  Wake Timer + *POLLING* version.
971 //  No explicit Rx ASDT message event from ASDT.
972 //  ASOT wakes on Wake Timer event and polls for flag set.
973 // Reset Decoder Output processing
974 static Int PAF_ASOT_resetDecOutProc(
975     const PAF_ASOT_Params *pP, 
976     const PAF_ASOT_Patchs *pQ, 
977     PAF_ASOT_Config *pAsotCfg,
978     PAF_AudioFrame *pDecResetAf,
979     Bool outDevSel,
980     Int frame
983     Int status;
984     
985     if (outDevSel == FALSE)
986     {
987         // 
988         // Rx Dec Out-IS message before Output selected.
989         // Decoder is producing output, but no Output selected.
990         //
991         return ASOP_ERR_RESETOUTPROC_NOOUTDEVSEL;
992     }
993     
994     // Perform Dec Reset Init-Sync
995     status = PAF_ASOT_initSyncDecReset(pP, pQ, pAsotCfg, pDecResetAf, frame);
996     
997     return status;
1001 // Reset audio frame meta data elements
1002 static Void resetAfMetadata(
1003     const PAF_ASOT_Params *pP, 
1004     PAF_AST_Stream *xStr
1007     Int z;
1008     Int i;
1010     for (z = STREAM1; z < STREAMN; z++) 
1011     {
1012         xStr[z].pAudioFrame->pafBsMetadataUpdate = XDAS_FALSE;
1013         xStr[z].pAudioFrame->numPrivateMetadata = 0;
1014         xStr[z].pAudioFrame->bsMetadata_offset = 0;
1015         xStr[z].pAudioFrame->bsMetadata_type = PAF_bsMetadata_channelData;
1017         for (i = 0; i < pP->pMetadataBufStatus->NumBuf; i++)
1018         {
1019             xStr[z].pAudioFrame->pafPrivateMetadata[i].offset = 0;
1020             xStr[z].pAudioFrame->pafPrivateMetadata[i].size = 0;
1021         }
1022     }
1025 // Reset audio frames
1026 static Void resetAfs(
1027     const PAF_ASOT_Params *pP, 
1028     PAF_AST_Stream *xStr
1031     // Reset audio frame pointers to original values
1032     // (may be needed if error occurred).
1033     resetAfPointers(pP, xStr);
1034     // Reset audio frame meta data elements
1035     resetAfMetadata(pP, xStr);
1038 //   Purpose:   Performs Dec Reset Init-Sync.
1039 //static Int PAF_ASOT_initSyncDecReset(
1040 // used by new OutProc.c, will be changed back to static once refactoring is done
1041 static Int PAF_ASOT_initSyncDecReset(
1042     const PAF_ASOT_Params *pP, 
1043     const PAF_ASOT_Patchs *pQ, 
1044     PAF_ASOT_Config *pAsotCfg,
1045     PAF_AudioFrame *pDecResetAf,
1046     Int frame
1049     PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
1050     Int zMD, zMS;                       // Dec and Stream Master indices
1051     PAF_AudioFrame *pStrAf;             // stream audio frame
1052     PAF_AST_OutInitSyncCtl *pOutIsCtl;  // Output Init-Sync control
1053     Int8 decFlag;                       // dec stage flag
1054     Int status;                         // status code
1055    
1056     pAstCfg = pAsotCfg->pAstCfg;
1057     zMD = pAstCfg->masterDec;
1058     pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
1059     
1060     // check for Dec Reset
1061     // store dec reset AF
1062     status = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
1063         ASP_OUTIS_DEC_STAGE_RESET_IDX, &decFlag, pDecResetAf);
1064     if (status < 0)
1065     {
1066         return status;
1067     }
1068     
1069     if (decFlag == 0)
1070     {
1071         return ASOP_SOK_INITSYNC_NOTREADY;
1072     }
1073     else
1074     {
1075         zMS = pAstCfg->masterStr;
1076         pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1077         
1078         // Reset audio frames
1079         // FL, New IO: API for multiple streams.
1080         resetAfs(pP, pAstCfg->xStr);
1081     
1082         // Update Stream Audio Frame.
1083         // Copy Dec Reset AF to Stream AF.
1084         // FL, New IO: Only Master zone (single) stream handled.
1085         outIsCpyAf(pDecResetAf, pStrAf);
1086         
1087         // Enc activate
1088         // Enc reset
1089         status = asopDecOutProcReset(pP, pQ, pAsotCfg, frame);
1090         if (status < 0)
1091         {
1092             return status;
1093         }
1094         
1095         return ASOP_SOK;
1096     }
1099 // ASOT SM function
1100 //   Purpose:   Init-Sync Dec Info1 state function.
1101 //      Wake Timer + *POLLING* version.
1102 //      No explicit Rx ASDT message event from ASDT.
1103 //      ASOT wakes on Wake Timer event and polls for flag set.
1104 static Int PAF_ASOT_initSyncDecInfo1(
1105     const PAF_ASOT_Params *pP, 
1106     const PAF_ASOT_Patchs *pQ, 
1107     PAF_ASOT_Config *pAsotCfg,
1108     PAF_AudioFrame *pDecInfo1Af,
1109     Int frame
1112     PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
1113     Int zMD, zMS;                       // Dec and Stream Master indices
1114     PAF_AudioFrame *pStrAf;             // stream audio frame
1115     PAF_AST_OutInitSyncCtl *pOutIsCtl;  // Output Init-Sync control
1116     Int8 decFlag;                       // dec stage flag
1117     Int status;                         // status code
1118     
1119     pAstCfg = pAsotCfg->pAstCfg;
1120     zMD = pAstCfg->masterDec;
1121     pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
1122     
1123     // Check for Dec Reset, 
1124     // Store dec reset AF
1125     status = outIsReadDecStageFlagAndAf(pOutIsCtl, zMD,
1126         ASP_OUTIS_DEC_STAGE_INFO1_IDX, &decFlag, pDecInfo1Af);
1127     if (status < 0)
1128     {
1129         return status;
1130     }
1131     
1132     if (decFlag == 0)
1133     {
1134         return ASOP_SOK_INITSYNC_NOTREADY;
1135     }
1136     else
1137     {
1138         zMS = pAstCfg->masterStr;
1139         pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1140         
1141         // Set ASOT output frame length.
1142             // THD sets this to 256 (hard-coded in Dec Info)
1143             // DDP sets this to 0 (audio frame pass through, 0 from ASDT AF frame length)
1144             // PCM sets this to 256 (decodeControl.frameLength)
1145         pDecInfo1Af->sampleCount = gOutFrameLen;    // !!!! GJ: Revisit !!!!
1146         
1147         // Update Stream Audio Frame.
1148         // Copy Dec Reset AF to Stream AF.
1149         outIsCpyAf(pDecInfo1Af, pStrAf);
1151         // outputInfo1():
1152         //      - ASP chain reset,
1153         //      - Enc Info,
1154         //      - Start Output
1155         status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
1156         if (status < 0)
1157         {
1158             return status;
1159         }
1160         
1161         return ASOP_SOK;
1162     }
1165 // ASOT SM function
1166 //   Purpose:   Init-Sync Dec Decode1 state function.
1167 //      Wake Timer + *POLLING* version.
1168 //      No explicit Rx ASDT message event from ASDT.
1169 //      ASOT wakes on Wake Timer event and polls for flag set.
1170 //static Int PAF_ASOT_initSyncDecDecode1(
1171 static Int PAF_ASOT_initSyncDecDecode1(
1172     const PAF_ASOT_Params *pP, 
1173     const PAF_ASOT_Patchs *pQ, 
1174     PAF_ASOT_Config *pAsotCfg,
1175     Int frame
1178     PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
1179     Int zMD;                            // Dec Master index
1180     PAF_AST_OutInitSyncCtl *pOutIsCtl;  // Output Init-Sync control
1181     Int8 decFlag;                       // dec stage flag
1182     Int z;
1183     Int zS, zO;
1184     Int status;                         // status code
1186     pAstCfg = pAsotCfg->pAstCfg;
1187     zMD = pAstCfg->masterDec;
1188     pOutIsCtl = &pAsotCfg->pAspmCfg->outIsCtl;
1189     
1190     // Check for Dec Reset, 
1191     // Store dec reset AF
1192     status = outIsReadDecStageFlag(pOutIsCtl, zMD,
1193         ASP_OUTIS_DEC_STAGE_DECODE1_IDX, &decFlag);
1194     if (status < 0)
1195     {
1196         return status;
1197     }
1198     
1199     if (decFlag == 0)
1200     {
1201         return ASOP_SOK_INITSYNC_NOTREADY;
1202     }
1203     else
1204     {
1205         // Find first Output associated with Master Stream
1206         zO = OUTPUT1;
1207         for (z=ENCODE1; z < ENCODEN; z++)
1208         {
1209             zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
1210             if (zS == pAstCfg->masterStr)
1211             {
1212                 // This Encoder is associated with Master Stream.
1213                 // Note other Encoder can also be associated with Master Stream.
1214                 zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
1215             }
1216         }
1218         // FL, New IO: assumption here is Tx McASP clock dividers &
1219         //  Output frame size are set correctly before IO prime, 
1220         //  i.e. IO prime is not using defaults
1221         
1222         // FL, New IO: API for single Output
1224         // I/O physical layer prime operation required by McASP LLD
1225         asopIoPhyPrime(&pAsotCfg->pIoOut[zO]);        
1226         
1227         return ASOP_SOK;
1228     }
1231 // ASOT SM function
1232 // Process Decoder output audio data
1233 static Int PAF_ASOT_procDecOut(
1234     const PAF_ASOT_Params *pP, 
1235     const PAF_ASOT_Patchs *pQ, 
1236     PAF_ASOT_Config *pAsotCfg, 
1237     Bool *pFirstTime, 
1238     Int frame
1241     PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
1242     Bool outDevSioSelUpdate;    // indicates whether Output SIO selection has changed
1243     Int zO, zS;
1244     Int z;                      // decode/encode counter
1245     Int errno;                  // error number
1246     Int status;                 // status code
1247     
1248     status = ASOP_SOK;
1249     pAstCfg = pAsotCfg->pAstCfg;
1250     
1251     if (*pFirstTime == TRUE)
1252     {
1253         // Initialize Decoder output processing
1254         errno = asopDecOutProcInit(pP, pQ, pAsotCfg, frame);
1255         if (errno < 0)
1256         {
1257             status = errno;
1258         }
1259         else
1260         {
1261             *pFirstTime = FALSE;
1262         }
1263     }
1264     
1265     if (status == ASOP_SOK)
1266     {
1267         // Find first Output associated with Master Stream
1268         zO = OUTPUT1;
1269         for (z=ENCODE1; z < ENCODEN; z++)
1270         {
1271             zS = pP->streamsFromEncodes[z]; // get Stream associated with Encoder
1272             if (zS == pAstCfg->masterStr)
1273             {
1274                 // This Encoder is associated with Master Stream.
1275                 // Note other Encoder can also be associated with Master Stream.
1276                 zO = pP->outputsFromEncodes[z]; // get Output associated with Encoder
1277             }
1278         }    
1279         
1280         // Mark Output transfer complete
1281         errno = ioPhyXferComplete(pAsotCfg->pIoOut[zO].hIoPhy, FALSE);
1282         if (errno)
1283         {
1284             status = ASOP_ERR_PROCDECOUT_IOPHYXFERCOMPLETE;
1285         }
1286     }
1287     
1288     if (status == ASOP_SOK)
1289     {
1290         // Check if Output device SIO selection changed
1291         errno = checkOutDevSioSelUpdate(pP, pAsotCfg, zO, &outDevSioSelUpdate);
1292         if (errno)
1293         {
1294             status = ASOP_ERR_PROCDECOUT_CHKOUTDEVSELUPD;
1295         }
1296         else if (outDevSioSelUpdate == TRUE)
1297         {
1298             status = ASOP_ERR_PROCDECOUT_OUTDEVSELUPD;
1299         }
1300     }
1302     if (status == ASOP_SOK)
1303     {
1304         // Process encoder command
1305         errno = asopDecOutProcEncodeCommand(pP, pQ, pAsotCfg);
1306         if (errno < 0)
1307         {
1308             status = errno;
1309         }
1310     }
1312     if (status == ASOP_SOK)
1313     {
1314         // Read CB, execute ASP chain
1315         errno = asopDecOutProcStream(pP, pQ, pAsotCfg, frame);
1316         if (errno < 0)
1317         {
1318             status = errno;
1319         }
1320     }
1322     if (status == ASOP_SOK)
1323     {
1324         // Update Output buffer configuration
1325         asopUpdateOutBufConfig(&pAstCfg->xOut[zO], &pAsotCfg->pIoOut[zO]);
1326         
1327         // Execute encode
1328         errno = asopDecOutProcEncode(pP, pQ, pAsotCfg, frame);
1329         if (errno < 0)
1330         {
1331             status = errno;
1332         }
1334         // Mark Output buffers write complete
1335         asopMarkOutBuffsWriteComplete(&pAstCfg->xOut[zO], &pAsotCfg->pIoOut[zO]);
1336     }
1338     if (status == ASOP_SOK)
1339     {
1340         // Execute Info2
1341         errno = asopDecOutProcInfo2(pP, pQ, pAsotCfg, frame);
1342         if (errno < 0)
1343         {
1344             status = errno;
1345         }
1346     }
1348     if (status == ASOP_SOK)
1349     {
1350         errno = asopDecOutProcFinalTest(pP, pQ, pAsotCfg, frame);
1351         if (errno < 0)
1352         {
1353             status = errno;
1354         }
1355     }
1357     if (status != ASOP_SOK)    
1358     {
1359         // Complete Output Processing
1360         errno = asopDecOutProcComplete(pP, pQ, pAsotCfg, frame);
1361         if (errno < 0)
1362         {
1363             status = errno;
1364         }
1365     }
1366     
1367     return status;
1370 // ASOT SM function
1371 //   Purpose:   Init-Sync Re-Sync state function.
1372 //              Performs Init-Sync using stored Dec Reset/Info1 AFs.
1373 static Int PAF_ASOT_initSyncResync(
1374     const PAF_ASOT_Params *pP, 
1375     const PAF_ASOT_Patchs *pQ, 
1376     PAF_ASOT_Config *pAsotCfg,
1377     PAF_AudioFrame *pDecResetAf,
1378     PAF_AudioFrame *pDecInfo1Af,
1379     Int frame
1382     PAF_AST_Config *pAstCfg;    // ASIT/ASOT/ASDT shared configuration
1383     Int zMS;                    // Stream Master index
1384     PAF_AudioFrame *pStrAf;     // stream audio frame
1385     Int status;                 // status code
1387     pAstCfg = pAsotCfg->pAstCfg;
1388     zMS = pAstCfg->masterStr;
1389     pStrAf = pAstCfg->xStr[zMS].pAudioFrame;
1390         
1391     // Reset audio frames
1392     resetAfs(pP, pAstCfg->xStr);
1393     
1394     //
1395     // Dec Reset re-sync using stored Dec Reset AF
1396     //
1397     
1398     // Update Stream Audio Frame.
1399     // Copy Dec Reset AF to Stream AF.
1400     outIsCpyAf(pDecResetAf, pStrAf);
1401     
1402     // Enc activate,
1403     // Enc reset
1404     status = asopDecOutProcReset(pP, pQ, pAsotCfg, frame);
1405     if (status < 0)
1406     {
1407         return status;
1408     }
1409     
1410     //
1411     // Dec Info1 re-sync using stored Dec Info1 AF
1412     //
1413     
1414     // Update Stream Audio Frame.
1415     // Copy Dec Info1 AF to Stream AF.
1416     outIsCpyAf(pDecInfo1Af, pStrAf);
1417     
1418     // outputInfo1():
1419     //      - ASP chain reset,
1420     //      - Enc Info,
1421     //      - Start Output
1422     status = asopDecOutProcInfo1(pP, pQ, pAsotCfg, frame);
1423     if (status < 0)
1424     {
1425         return status;
1426     }
1427     
1428     return ASOP_SOK;    
1431 // ASOT SM function
1432 //   Purpose:   Re-select devices used for Output.
1433 //              Performs Init-Sync using stored Dec Reset/Info1 AFs.
1434 static Int PAF_ASOT_reselectDevices(
1435     const PAF_ASOT_Params *pP, 
1436     const PAF_ASOT_Patchs *pQ, 
1437     PAF_ASOT_Config *pAsotCfg,
1438     PAF_AudioFrame *pDecResetAf,
1439     PAF_AudioFrame *pDecInfo1Af,
1440     Int frame, 
1441     Bool *pOutDevSel
1444     Bool outDevSel;
1445     Int status;
1446     
1447     // Re-select Output devices
1448     status = PAF_ASOT_selectDevices(pP, pQ, pAsotCfg, &outDevSel);
1449     if (status < 0)
1450     {
1451         *pOutDevSel = outDevSel;
1452         return status;
1453     }
1454     else if (outDevSel == FALSE)
1455     {
1456         *pOutDevSel = outDevSel;
1457         return status;
1458     }
1459     else
1460     {
1461         // Init-Sync Resync
1462         status = PAF_ASOT_initSyncResync(pP, pQ, pAsotCfg, pDecResetAf, pDecInfo1Af, frame);
1463         if (status < 0)
1464         {
1465             outDevSel = FALSE;
1466             *pOutDevSel = outDevSel;
1467             return status;
1468         }
1469     }
1470     
1471     *pOutDevSel = outDevSel;
1472     return status;