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