fe2bb19b3474b7500be2444e5a237218b392a7c9
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamInpDec.c
1 /*
2 Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/
3 All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * Neither the name of Texas Instruments Incorporated nor the names of
18 * its contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
35 /*
36  *  ======== audioStreamInpDec.c ========
37  */
38 #include <ti/sysbios/hal/Cache.h>
39 #include <xdc/runtime/Log.h>
41 #include "procsdk_audio_typ.h"
42 #include "audioStreamInpProc.h"
43 #include "audioStreamProc_common.h"
44 #include "aspMsg_common.h"
45 #include "aspMsg_master.h"
46 #include "asperr.h"
47 #include "common.h"
48 #include "as1-f2.h"
50 #include "ioConfig.h"    //TODO: remove this header
51 #include "ioBuff.h"
52 #include "ioPhy.h"
53 #include "ioData.h"
56 extern void asitPostInfoEvent();    // TODO: remove
57 extern void asitPostDecEvent();     // TODO: remove
59 enum {
60     DEC_STATE_INFO_SND,
61     DEC_STATE_INFO_ACK_DECODE_SND,
62     DEC_STATE_DECODE_ACK,
63     DEC_STATE_QUIT
64 };
66 static Int decodeInit(const PAF_ASIT_Params *pP, PAF_ASIT_Config *pAsitCfg,
67                       Int sourceSelect);
69 static Int decDecodeComplete(const PAF_ASIT_Params *pP,
70                              PAF_ASIT_Config *pAsitCfg);
72 static Int decErrorCheck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
73                          PAF_ASIT_Config *pAsitCfg, Int sourceSelect);
74 static Int decInfoSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
75                          PAF_ASIT_Config *pAsitCfg);
76 static Int decInfoAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
77                          PAF_ASIT_Config *pAsitCfg);
78 static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
79                            PAF_ASIT_Config *pAsitCfg);
80 static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
81                            PAF_ASIT_Config *pAsitCfg);
82 static Int decDecodeFinalTest(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
83                               PAF_ASIT_Config *pAsitCfg);
84 Int decCheckMajorAu(PAF_AST_Config *pAstCfg);
86 #if 0
87 Int AspMsgSnd(UInt32 sndCmd, char *sndMsgBuf);
88 Int AspMsgAck(UInt32 ackCmd, char *ackMsgBuf);
89 #endif
91 extern UInt32 gCbWrtAfErrCnt;
94 Int decDecodeInit(
95         const PAF_ASIT_Params *pP,
96         PAF_ASIT_Config *pAsitCfg,
97         Int sourceSelect)
98 {
99     Int errno;
101     errno = decodeInit(pP, pAsitCfg, sourceSelect);
103     if(errno) {
104         decDecodeComplete(pP, pAsitCfg);
106         return ASIP_ERR_DECODE_INIT;
107     }
109     pAsitCfg->inpDec.majorAuFound = FALSE;
110     
111     return ASIP_NO_ERR;
115 // -----------------------------------------------------------------------------
116 // -----------------------------------------------------------------------------
117 Int decDecodeFsm(
118         const PAF_ASIT_Params *pP,
119         const PAF_ASIT_Patchs *pQ,
120         PAF_ASIT_Config *pAsitCfg,
121         Int sourceSelect,
122         UInt decMsg)
124     asipDecProc_t  *pDec;
125     Int decErr, decDone;
127     pDec = &pAsitCfg->inpDec;
129     TRACE_VERBOSE1("Entering decDecodeFsm with decMsg %d.", decMsg);
131     decErr = decErrorCheck(pP, pQ, pAsitCfg, sourceSelect);
132     if(decErr == DEC_ERR_ASPERR_ABORT) {
133         return decErr;
134     }
135     else if(decErr != DEC_NO_ERR) {
136         pDec->state = DEC_STATE_QUIT;
137     }
138     else {
139         ; // No error
140     }
142     // It is possible to go through the FSM multiple times:
143     //    - Multiple messages may be received, INPDATA and DECACK. In this case,
144     //      the FSM will process DECACK in state DEC_STATE_DECODE_ACK and then 
145     //      INPDATA in state DEC_STATE_INFO_SND.
146     //    - DECACK is received after INPDATA. In this case, after DECACK is 
147     //      processed, we will spoof decMsg with INPDATA so that FSM will run 
148     //      again and process INPDATA in DEC_STATE_INFO_SND.
149     do {
150         switch(pDec->state)
151         {
152         case DEC_STATE_INFO_SND:
153             if(decMsg != DEC_MSGMSK_INPDATA) {
154                 // Only DEC_MSGMSK_INPDATA is expected in this state
155                 decErr = DEC_ERR_WRONG_MSG;
156             }
157             else {
158                 decMsg &= ~DEC_MSGMSK_INPDATA;   // clear bit mask
160                 // Prepare and send INFO to decoder
161                 decErr = decInfoSnd(pP, pQ, pAsitCfg);
162                 if(decErr == DEC_NO_ERR) {
163                     pDec->state = DEC_STATE_INFO_ACK_DECODE_SND;
164                     TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_SND done.");
165                 }
166             }
167         break;
169         case DEC_STATE_INFO_ACK_DECODE_SND:
170             //if(decMsg != DEC_MSGMSK_INFOACK) {
171                 // only DEC_MSGMSK_INFOACK is expected in this state
172             //if((decMsg&DEC_MSGMSK_INFOACK) != DEC_MSGMSK_INFOACK) {
173             //    // During debugging, it is possible that INPDATA and INFOACK
174             //    // come at the same time (e.g. due to breaking point).
175             //    decErr = DEC_ERR_WRONG_MSG;
176             //}
177             //else {
178                 
179             if (decMsg & DEC_MSGMSK_RXACK) {
180                 decMsg &= ~DEC_MSGMSK_RXACK;  // clear the bit mask
182                 // Process the INFO acknowledgment from decoder
183                 decErr = decInfoAck(pP, pQ, pAsitCfg);
184                 if(decErr == DEC_NO_ERR) {
185                     // Don't start decode until major access unit is found.
186                     if(!pDec->majorAuFound) {
187                         // Do we want to still check major AU after it is found?
188                         // In old code, it was not checked again after it was found. 
189                         pDec->majorAuFound = decCheckMajorAu(pAsitCfg->pAstCfg);    
190                     }
191                     
192                     if(pDec->majorAuFound) {
193                         // Major access unit is found. Send message to decoder to decode now.
194                         decErr = decDecodeSnd(pP, pQ, pAsitCfg);
195                         if(decErr == DEC_NO_ERR) {
196                             pDec->state = DEC_STATE_DECODE_ACK;
198                             // Initialize decodeAckDelayed to FALSE - normally
199                             // DECODE ACK comes after INPDATA. 
200                             pDec->decodeAckDelayed = FALSE;
202                             TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_ACK_DECODE_SND done and going to DEC_STATE_DECODE_ACK.");
203                         }
204                     }
205                     else {
206                         // No major access unit - go back to INFO.
207                         pDec->frame++;
208                         pDec->state = DEC_STATE_INFO_SND;
209                         TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_INFO_ACK_DECODE_SND done and going to DEC_STATE_INFO_SND.");
210                     }
211                 }
212             }
213             
214             if (decMsg != 0) {
215                 decErr = DEC_ERR_WRONG_MSG;
216             }            
217         break;
219         case DEC_STATE_DECODE_ACK:
220             // Two different messages may be received: DECACK (decode acknowledgment)
221             // or INPDATA (input data ready).
222             //if(decMsg & DEC_MSGMSK_DECACK) {
223             //    decMsg &= ~DEC_MSGMSK_DECACK;
224             
225             if (decMsg & DEC_MSGMSK_RXACK)
226             {
227                 decMsg &= ~DEC_MSGMSK_RXACK;  // clear the bit mask
228                 
229                 // Process DECODE ACK from decoder
230                 decErr = decDecodeAck(pP, pQ, pAsitCfg);
231                 if(decErr == DEC_NO_ERR) {
232                     // Decode finishes. Conduct final test.
233                     decErr = decDecodeFinalTest(pP, pQ, pAsitCfg);
234                     if(decErr == DEC_NO_ERR) {
235                         pDec->frame++;
236                         pDec->state = DEC_STATE_INFO_SND;
237                         TRACE_VERBOSE0("decDecodeFsm: DEC_STATE_DECODE_ACK done and going to DEC_STATE_INFO_SND.");
239                         // Check if DECACK comes late (after INPDATA)
240                         if(pDec->decodeAckDelayed) {
241                             pDec->decodeAckDelayed = FALSE;
243                             // Need to prepare and send INFO to decoder immediately.
244                             // Becuase INPUT_DATA message is already received, 
245                             // we're just spoofing the message with INPDATA to 
246                             // run the FSM one more time. 
247                             decMsg |= DEC_MSGMSK_INPDATA;
249                             TRACE_VERBOSE0("decDecodeFsm: Info was delayed.");
250                         }
251                     }
252                 }
253             }
254             
255             if (decMsg & DEC_MSGMSK_INPDATA) {
256                 // If we're here, it means decode acknowledgment from decoder
257                 // is delayed, i.e., a new frame of input data is ready before
258                 // current frame decoding is finished.
259                 decMsg &= ~DEC_MSGMSK_INPDATA;
261                 // Do nothing but set a flag to postpone action.
262                 pDec->decodeAckDelayed = TRUE;
264                 TRACE_VERBOSE0("decDecodeFsm: receiving INPDATA in DEC_STATE_DECODE_ACK");
265             }
266             
267             if (decMsg != 0) {
268                 decErr = DEC_ERR_WRONG_MSG;
269             }
270         break;
272         case DEC_STATE_QUIT:
273             //gAsipQuitCnt++;
274             TRACE_VERBOSE0("decDecodeFsm: state: DEC_STATE_QUIT");
275         break;
277         default:
278         break;
279         } /* switch */
281         // Loop through the FSM one more time if:
282         //    - there are more real or spoofed messages to process, 
283         //    - and there is no error.
284         if((decMsg==0) || (decErr!=DEC_NO_ERR)) {
285             decDone = TRUE;
286         }
287         else {
288             decDone = FALSE;
289         }
290     } while(!decDone);
292     // Error handling - complete decoding
293     if(decErr != DEC_NO_ERR) {
294         TRACE_VERBOSE1("decDecodeFsm: decErr %d, calling decDecodeComplete.", decErr);
295         decDecodeComplete(pP, pAsitCfg);
296         TRACE_VERBOSE0("decDecodeFsm: decDecodeComplete done.");
297     }
299     return decErr;
300 } /* decDecodeFsm */
303 Int decErrorCheck(const PAF_ASIT_Params *pP,
304                   const PAF_ASIT_Patchs *pQ,
305                   PAF_ASIT_Config *pAsitCfg,
306                   Int sourceSelect
309     Int retVal, getVal, zMD;
310     Int8 sourceConfig;
312     retVal = DEC_NO_ERR;
314     // Check if source has configured to NONE
315     zMD = pAsitCfg->pAstCfg->masterDec;
316     sourceConfig = sharedMemReadInt8(&(pAsitCfg->pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
317                                      GATEMP_INDEX_DEC);
318     if (sourceConfig == PAF_SOURCE_NONE || sourceSelect == PAF_SOURCE_NONE) {
319         TRACE_VERBOSE0("decDecodeFsm: sourceSelect == PAF_SOURCE_NONE");
320         retVal = DEC_ERR_SOURCE_NONE;
321     }
323     // Process commands (decode)
324     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
325     if (getVal == ASPERR_QUIT) {
326         TRACE_VERBOSE0("decDecodeFsm. %d: state = QUIT");
327         retVal = DEC_ERR_ASPERR_QUIT;
328     }
329     else if (getVal == ASPERR_ABORT) {
330         TRACE_VERBOSE0("decDecodeFsm. %d: return getVal");
332         // Return here if ASPERR_ABORT
333         retVal = DEC_ERR_ASPERR_ABORT;
334     }
335     else {
336         ;  // No error
337     }
339     return retVal;
340 }  /* decErrorCheck */
343 Int decCheckMajorAu(PAF_AST_Config *pAstCfg)
345     Int8 sourceDecode, sampleRate;
346     Int zMD;
348     zMD = pAstCfg->masterDec;
350     sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
351                                      GATEMP_INDEX_DEC);
352     sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
353                                      GATEMP_INDEX_DEC);
354     if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
355            (sourceDecode == PAF_SOURCE_DXP)     ||
356            (sourceDecode == PAF_SOURCE_DTSHD)
357          )
358        &&( sampleRate == PAF_SAMPLERATE_UNKNOWN)
359        ) {
360         return FALSE;
361     }
362     else {
363         return TRUE;
364     }
365 } /* decCheckMajorAu*/
368 // -----------------------------------------------------------------------------
369 // ASIT Decoding Function - Reinitialization of Decode
370 //
371 //   Name:      decDecodeInit
372 //   Purpose:   Decoding Function for reinitializing the decoding process.
373 //   From:      AST Parameter Function -> decodeProcessing
374 //   Uses:      See code.
375 //   States:    x
376 //   Return:    Error number in standard or SIO form (0 on success).
377 //   Trace:     Message Log "trace" in Debug Project Configuration reports:
378 //              * State information as per parent.
379 //
380 // -----------------------------------------------------------------------------
381 static Int decodeInit(
382         const PAF_ASIT_Params *pP,
383         PAF_ASIT_Config *pAsitCfg,
384         Int sourceSelect)
386     PAF_AST_Config *pAstCfg;
387     PAF_AST_IoInp  *pInp;
388     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
389     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
390     Int as;                             /* Audio Stream Number (1, 2, etc.) */
391     Int z;                              /* decode/encode counter */
392     Int errno;                          /* error number */
393     Int zI, zS;
394     Int argIdx;
395     Int8 tempVar8;
396     char decMsgBuf[ASP_MSG_BUF_LEN];
397     Int status;
399     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
400     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
401     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
403     as = pAstCfg->as;
404     (void)as;  // clear compiler warning in case not used with tracing disabled
406     //pCbCtl = &pAsitCfg->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
408     // reset frameCount
409     for (z=DECODE1; z < DECODEN; z++)
410     {
411         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
412                                      GATEMP_INDEX_DEC);
413         if (tempVar8)
414         {
415             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
416                               (Int)0, GATEMP_INDEX_DEC);
417         }
418     }
420     // loop through all supported inputs
421     for (z=DECODE1; z < DECODEN; z++)
422     {
423         zI = pP->inputsFromDecodes[z];
424         zS = pP->streamsFromDecodes[z];
425         (void)zS; // clear compiler warning in case not used with tracing disabled
426         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
427                                      GATEMP_INDEX_DEC);
428         if (pInp[zI].hIoPhy && tempVar8)
429         {
430             Uns gear;
431             TRACE_VERBOSE1("AS%d: PAF_ASIT_decodeInit: initializing decode", as+zS);
433             // write back Dec configuration
434             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
435             Cache_wait();
437             // send dec activate message to slave
438             argIdx = 0; // set decIdx (zone index)
439             *(Int32 *)&decMsgBuf[argIdx] = z;
440             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_ACTIVATE, decMsgBuf);
441             if (status != ASP_MSG_NO_ERR)
442             {
443                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
444                 SW_BREAKPOINT; // temporary
445                 return ASIP_ERR_DECODE_MSG; // temporary
446             }
447             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_ACTIVATE_DONE, NULL, TRUE);
448             if (status != ASP_MSG_NO_ERR)
449             {
450                 TRACE_TERSE0("decodeInit: error in receiving DEC_ACTIVATE_DONE ack message ");
451                 SW_BREAKPOINT; // temporary
452                 return ASIP_ERR_DECODE_MSG; // temporary
453             }
455             // send dec reset message to slave
456             argIdx = 0; // set decIdx
457             *(Int32 *)&decMsgBuf[argIdx] = z;
458             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_RESET, decMsgBuf);
459             if (status != ASP_MSG_NO_ERR)
460             {
461                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
462                 SW_BREAKPOINT; // temporary
463                 return ASIP_ERR_DECODE_MSG; // temporary
464             }
465             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_RESET_DONE, decMsgBuf, TRUE);
466             if (status != ASP_MSG_NO_ERR)
467             {
468                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
469                 SW_BREAKPOINT; // temporary
470                 return ASIP_ERR_DECODE_MSG; // temporary
471             }
472             else
473             {
474                 argIdx = 0; // get decErrno
475                 errno = *(Int32 *)&decMsgBuf[argIdx];
476             }
478             // invalidate Dec configuration
479             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
480             Cache_wait();
482             if (errno != 0) {
483                 return ASIP_ERR_DECODE_MSG;
484             }
486             gear = (Uns)sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearControl),
487                                           GATEMP_INDEX_DEC);
488             tempVar8 = gear < GEARS ? gear : 0;
489             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.aspGearStatus),
490                                tempVar8, GATEMP_INDEX_DEC);
492             // Compute decoder frame length based on source selection
493             // JXU: what does this function do? why does it only return PCM frame length?
494             /*frameLength = getFrameLengthSourceSel(pP, sourceSelect);
496             pAstCfg->xDec[z].decodeControl.frameLength = frameLength;
497             pAstCfg->xDec[z].decodeInStruct.sampleCount = frameLength;
498             pAstCfg->xDec[z].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;*/
500 /*
501             if (z != zMD) {    // JXTODO: implement similar thing with new I/O
502                 if (errno = SIO_idle(pAstCfg->xInp[zI].hRxSio)) {
503                     return errno;
504                 }
505             }
506 */
507 /*//JXTODO: find out if frameLength needs to be passed to I/O DATA or I/O PHY.
508             ioDataCtl.code = IODATA_CTL_SET_PCM_FRAME_LENGTH;
509             ioDataCtl.param.frameLengthPcm = frameLength;
510             ioDataControl(pInp[zI].hIoData, &ioDataCtl);
511 */
512             //JXTODO: do we need to update input status here again?
513             if (errno = asitUpdateInputStatus(pInp[zI].pRxParams,
514                                               &pAstCfg->xInp[zI].inpBufStatus,
515                                               &pAstCfg->xInp[zI].inpBufConfig)) {
516                 return ASIP_ERR_INPUT_CFG;
517             }
518         } /* end of if(hIoPhy && decodeStatus.mode) */
519     } /* end of for (z=DECODE1; z < DECODEN; z++) */
521     pAsitCfg->inpDec.frame = 0;
522     pAsitCfg->inpDec.block = 0;
523     pAsitCfg->inpDec.state = DEC_STATE_INFO_SND;
525     return ASIP_NO_ERR;
526 }  /* decDecodeInit */
530 Int decDecodeComplete( const PAF_ASIT_Params *pP,
531                        PAF_ASIT_Config *pAsitCfg)
533     PAF_AST_Config *pAstCfg;
534     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
535     Int as;                     /* Audio Stream Number (1, 2, etc.) */
536     Int z;                      /* decode/encode counter */
537     Int argIdx;
538     Int8 tempVar8;
539     char decMsgBuf[ASP_MSG_BUF_LEN];
540     Int status;
542     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
543     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
544     as = pAstCfg->as;
545     (void)as;  // clear compiler warning in case not used with tracing disabled
547     for (z=DECODE1; z < DECODEN; z++)
548     {
549         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
550                                      GATEMP_INDEX_DEC);
551         if (pAsitCfg->pIoInp[z].hIoPhy && tempVar8)
552         {
553             TRACE_VERBOSE1("decDecodeComplete: AS%d: finalizing decode", as+z);
555             // send dec deactivate message to slave
556             argIdx = 0; // set decIdx
557             *(Int32 *)&decMsgBuf[argIdx] = z;
558             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_DEACTIVATE, decMsgBuf);
559             if (status != ASP_MSG_NO_ERR)
560             {
561                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
562                 SW_BREAKPOINT;
563                 return DEC_ERR_COMPLETE_MSG;
564             }
565             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_DEACTIVATE_DONE, NULL, TRUE);
566             if (status != ASP_MSG_NO_ERR)
567             {
568                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
569                 SW_BREAKPOINT;
570                 return DEC_ERR_COMPLETE_MSG;
571             }
572         }
573         else
574         {
575             TRACE_VERBOSE1("decDecodeComplete: AS%d: processing decode <ignored>", as+z);
576         }
577     }
579     return DEC_NO_ERR;
580 }  /* decDecodeComplete */
583 // -----------------------------------------------------------------------------
584 // Decoding Function - Frame-Final Processing
585 //
586 //   Name:      decDecodeFinalTest
587 //   Purpose:   Decoding Function for determining whether processing of the
588 //              current frame is complete.
589 //   From:      AST Parameter Function -> decodeProcessing
590 //   Uses:      See code.
591 //   States:    x
592 //   Return:    0 if incomplete, and 1 if complete.
593 //   Trace:     None.
594 //
596 Int
597 decDecodeFinalTest(
598     const PAF_ASIT_Params *pP,
599     const PAF_ASIT_Patchs *pQ,
600     PAF_ASIT_Config *pAsitCfg
603     PAF_AST_Config *pAstCfg;
604     Int zMD;
605     Int sourceSelect;
606     Int sourceProgram;
607     Int8 tempVar8, temp2Var8;
609     pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
610     zMD = pAstCfg->masterDec;
612     sourceSelect  = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
613                                            GATEMP_INDEX_DEC);
614     sourceProgram = (Int)sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
615                                            GATEMP_INDEX_DEC);
617     if ((sourceSelect == PAF_SOURCE_NONE) || (sourceSelect == PAF_SOURCE_PASS))
618     {
619         return DEC_ERR_DECODE_FINAL;
620     }
622     // The following allows for Force modes to switch without command deferral. This might
623     // be better suited for inclusion in DIB_requestFrame, but for now will reside here.
624     if ((sourceSelect == PAF_SOURCE_SNG) || (sourceSelect > PAF_SOURCE_BITSTREAM))
625     {
626         if (sourceSelect == PAF_SOURCE_DTSALL)
627         {
628             if (sourceProgram != PAF_SOURCE_DTS11 &&
629                 sourceProgram != PAF_SOURCE_DTS12 &&
630                 sourceProgram != PAF_SOURCE_DTS13 &&
631                 sourceProgram != PAF_SOURCE_DTS14 &&
632                 sourceProgram != PAF_SOURCE_DTS16 &&
633                 sourceProgram != PAF_SOURCE_DTSHD)
634             {
635                 return DEC_ERR_DECODE_FINAL;
636             }
637         }
638         else if (sourceSelect == PAF_SOURCE_PCMAUTO)
639         {
640             if (sourceProgram != PAF_SOURCE_PCM)
641             {
642                 return DEC_ERR_DECODE_FINAL;
643             }
644         }
645         else
646         {
647             tempVar8  = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
648                                           GATEMP_INDEX_DEC);
649             temp2Var8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
650                                           GATEMP_INDEX_DEC);
651             if (temp2Var8 != tempVar8)
652             {
653                 return DEC_ERR_DECODE_FINAL;
654             }
655         }
656     }
658     return DEC_NO_ERR;
659 } //decDecodeFinalTest
661 Int decInfoSnd(
662         const PAF_ASIT_Params *pP,
663         const PAF_ASIT_Patchs *pQ,
664         PAF_ASIT_Config *pAsitCfg
667     PAF_AST_Config *pAstCfg;
668     PAF_AST_IoInp  *pInp;
669     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
670     Int as;                    /* Audio Stream Number (1, 2, etc.) */
671     Int z;                     /* input/decode/stream counter */
672     Int errno;                 /* error number */
673     Int zD, zI, zS, zX;
674     Int argIdx;
675     Int8 tempVar8;
676     char decMsgBuf[ASP_MSG_BUF_LEN];
677     Int status;
679     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
680     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
681     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
682     as = pAstCfg->as;
684     // Set decode control: sample rate, emphasis
685     for (z=INPUT1; z < INPUTN; z++)
686     {
687         zD = z;
688         for (zX = DECODE1; zX < DECODEN; zX++)
689         {
690             if (pP->inputsFromDecodes[zX] == z) {
691                 zD = zX;
692                 break;
693             }
694         }
696         if (pInp[z].hIoPhy) {
697             //determine associated decoder
698             if (pAstCfg->xInp[z].inpBufStatus.sampleRateStatus !=
699                 pAstCfg->xDec[zD].decodeControl.sampleRate) {
700                 if (pAstCfg->xDec[zD].decodeControl.sampleRate == PAF_SAMPLERATE_UNKNOWN) {
701                     pAstCfg->xDec[zD].decodeControl.sampleRate =
702                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus;
703                 }
704                 else {
705                     //TRACE_TERSE1("decDecodeInfo: AS%d: return error ASPERR_INFO_RATECHANGE", as+pAstCfg->masterStr);
706                     TRACE_TERSE2("inpBufStatus.sampleRateStatus: 0x%x, decodeControl.sampleRate: 0x%x",
707                         pAstCfg->xInp[z].inpBufStatus.sampleRateStatus,
708                         pAstCfg->xDec[zD].decodeControl.sampleRate);
709                     // return (ASPERR_INFO_RATECHANGE);
710                 }
711             }
713             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zD].decodeStatus.sourceDecode),
714                                          GATEMP_INDEX_DEC);
715             pAstCfg->xDec[zD].decodeControl.emphasis =
716                 tempVar8 != PAF_SOURCE_PCM
717                 ? PAF_IEC_PREEMPHASIS_NO // fix for Mantis ID #119
718                 : pAstCfg->xInp[z].inpBufStatus.emphasisStatus;
719         }
720         else {
721             pAstCfg->xDec[zD].decodeControl.sampleRate = PAF_SAMPLERATE_UNKNOWN;
722             pAstCfg->xDec[zD].decodeControl.emphasis = PAF_IEC_PREEMPHASIS_UNKNOWN;
723         }
724     } /* end of for (z=INPUT1; z < INPUTN; z++) */
726     // Decode info
727     for (z=DECODE1; z < DECODEN; z++)
728     {
729         zI = pP->inputsFromDecodes[z];
730         zS = pP->streamsFromDecodes[z];
731         (void)zS; // clear compiler warning in case not used with tracing disabled
733         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
734                                      GATEMP_INDEX_DEC);
735         if (pInp[zI].hIoPhy  && tempVar8)
736         {
737             TRACE_GEN2("PAF_ASIT_decodeInfo: AS%d: processing frame %d -- info", as+zS, pAsitCfg->inpDec.frame);
739             if (errno = asitUpdateInputStatus(pInp[zI].pRxParams,
740                                               &pAstCfg->xInp[zI].inpBufStatus,
741                                               &pAstCfg->xInp[zI].inpBufConfig)) {
742                 TRACE_TERSE1("asitUpdateInputStatus return error errno 0x%x.", errno);
743                 return DEC_ERR_INFO_SNDMSG;
744             }
746 #if 0 // debug
747             // capture input buffer
748             capIb(pAstCfg->xInp[zI].pInpBuf);
749             gCapIb_cnt++;
750 #endif
752             // write back Inp configuration
753             Cache_wb(&pAstCfg->xInp[zI], sizeof(PAF_AST_InpBuf), Cache_Type_ALLD, 0);
754             // write back Dec configuration
755             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
756             Cache_wait();
758             // send info message to slave
759             argIdx = 0; // set decIdx
760             *(Int32 *)&decMsgBuf[argIdx] = z;
761             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_INFO, decMsgBuf);
762             if (status != ASP_MSG_NO_ERR)
763             {
764                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
765                 SW_BREAKPOINT; // temporary
766                 return -1;     // temporary
767             }
768 /*            else
769             {
770                 argIdx = 0; // get decErrno
771                 errno = *(Int32 *)&decMsgBuf[argIdx];
772             }
774             if (errno) {
775                 TRACE_TERSE1("decInfoSndMSg return error errno 0x%x.", errno);
776                 return DEC_ERR_INFO_SNDMSG;
777             }
778 */
779         }
780     } // z=DECODE1 to DECODEN
782 //////////////////////////////////////////////////////////////////////////////
783     //asitPostInfoEvent(); // simulation
784 //////////////////////////////////////////////////////////////////////////////
786     return ASIP_NO_ERR;
787 }  /* decInfoSnd() */
790 Int decInfoAck(
791         const PAF_ASIT_Params *pP,
792         const PAF_ASIT_Patchs *pQ,
793         PAF_ASIT_Config *pAsitCfg
796     PAF_AST_Config *pAstCfg;
797     PAF_AST_IoInp  *pInp;
798     AspMsgMaster_Handle hAspMsgMaster;
799     Int as;                    /* Audio Stream Number (1, 2, etc.) */
800     Int z;                     /* input/decode/stream counter */
801     Int errno;                 /* error number */
802     Int zI, zS;
803     Int zMD;
804     Int zMS;
805     Int argIdx;
806     Int8 tempVar8;
807     Int tempVar;
808     char decMsgBuf[ASP_MSG_BUF_LEN];
809     Int status;
811     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
812     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
813     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
814     as = pAstCfg->as;
815     zMD = pAstCfg->masterDec;
816     zMS = pAstCfg->masterStr;
817     (void)zMS;  (void)as;  // clear compiler warning in case not used with tracing disabled
819     // Decode info
820     for (z=DECODE1; z < DECODEN; z++)
821     {
822         zI = pP->inputsFromDecodes[z];
823         zS = pP->streamsFromDecodes[z];
824         (void)zS; // clear compiler warning in case not used with tracing disabled
826         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
827                                      GATEMP_INDEX_DEC);
828         if (pInp[zI].hIoPhy  && tempVar8)
829         {
830             // acknowledge info message from slave
831             errno  = 0;
832             //argIdx = 0; // set decIdx
833             //*(Int32 *)&decMsgBuf[argIdx] = z;
834             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_INFO_DONE, decMsgBuf, FALSE);
835             if (status != ASP_MSG_NO_ERR)
836             {
837                 TRACE_TERSE0("decodeInfo: error in receiving DEC_INFO_DONE ack message ");
838                 SW_BREAKPOINT; // temporary
839                 errno = -1;    // temporary error return value
840                 return errno;     // temporary
841             }
842             else
843             {
844                 argIdx = 0; // get decErrno
845                 errno = *(Int32 *)&decMsgBuf[argIdx];
846             }
848             // invalidate Dec configuration
849             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
850             Cache_wait();
852             if (errno) {
853                 TRACE_TERSE1("decInfoAck return error errno 0x%x.", errno);
854                 return DEC_ERR_INFO_ACKMSG;
855             }
857             // increment decoded frame count
858             tempVar = sharedMemReadInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
859                                        GATEMP_INDEX_DEC);
860             tempVar += 1;
861             sharedMemWriteInt(&(pAstCfg->xDec[z].decodeStatus.frameCount),
862                               tempVar, GATEMP_INDEX_DEC);
863         }
864     } // z=DECODE1 to DECODEN
866     // query IB for latest sourceProgram (needed if we started decoding due to a force mode)
867     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.mode),
868                                  GATEMP_INDEX_DEC);
869     if (tempVar8)
870     {
871         sharedMemWriteInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceProgram),
872                            pInp[zMD].sourceProgram, GATEMP_INDEX_DEC);
873     }
875     // since now decoding update decode status for all enabled decoders
876     for (z=DECODE1; z < DECODEN; z++)
877     {
878         tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.mode),
879                                      GATEMP_INDEX_DEC);
880         if (tempVar8)
881         {
882             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceProgram),
883                                          GATEMP_INDEX_DEC);
884             sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
885                                tempVar8, GATEMP_INDEX_DEC);
887             tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[z].decodeStatus.sourceSelect),
888                                          GATEMP_INDEX_DEC);
889             if (tempVar8 == PAF_SOURCE_SNG)
890             {
891                 tempVar8 = PAF_SOURCE_SNG;
892                 sharedMemWriteInt8(&(pAstCfg->xDec[z].decodeStatus.sourceDecode),
893                                    tempVar8, GATEMP_INDEX_DEC);
894             }
895         }
896     }
898     return ASIP_NO_ERR;
902 static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
903                            PAF_ASIT_Config *pAsitCfg)
905     PAF_AST_Config *pAstCfg;
906     PAF_AST_IoInp  *pInp;
907     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
908     Int as;                     /* Audio Stream Number (1, 2, etc.) */
909     Int z;                      /* decode/stream counter */
910     Int argIdx;
911     Int cbErrno, errno;
912     char decMsgBuf[ASP_MSG_BUF_LEN];
913     Int status;
915     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
916     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
917     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
918     as = pAstCfg->as;
919     (void)as; // clear compiler warning in case not used with tracing disabled
921     // Decode data
922     for (z=DECODE1; z < DECODEN; z++)
923     {
924         Int zI = pP->inputsFromDecodes[z];
925         Int zS = pP->streamsFromDecodes[z];
926         (void)zS; // clear compiler warning in case not used with tracing disabled
927         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
928         {
929             TRACE_GEN2("PAF_ASIT_decodeDecode: AS%d: decodeDecode: processing block %d -- decode", as+zS, pAsitCfg->inpDec.block);
931             TRACE_VERBOSE3("PAF_ASIT_decodeDecode: AS%d: decodeDecode: decoding from 0x%x (base) 0x%x (ptr)",
932                     as+zS,
933                     (IArg)pAstCfg->xInp[z].pInpBuf->base.pVoid,
934                     (IArg)pAstCfg->xInp[z].pInpBuf->head.pVoid);
936 #if 0 // debug
937             // capture input buffer
938             capIbPcm(pAstCfg->xInp[z].pInpBuf);
939 #endif
940             
941             // write back Dec configuration
942             Cache_wb(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
943             Cache_wait();
945             // send decode message to slave
946             errno  = 0;
947             argIdx = 0; // set decIdx
948             *(Int32 *)&decMsgBuf[argIdx] = z;
949             status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_DECODE, decMsgBuf);
950             if (status != ASP_MSG_NO_ERR)
951             {
952                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
953                 SW_BREAKPOINT; // temporary
954                 return -1;     // temporary
955             }
956 /*            else
957             {
958                 argIdx = 0; // get decErrno
959                 errno = *(Int32 *)&decMsgBuf[argIdx];
960                 argIdx += sizeof(Int32); // get cbErrno
961                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
962                 if (cbErrno != 0)
963                 {
964                     gCbWrtAfErrCnt++;
965                     TRACE_TERSE1("CB write error=%d", cbErrno);
966                     //SW_BREAKPOINT; // temporary
967                 }
969                 if(errno) {
970                     TRACE_TERSE1("decDecodeSnd return error errno 0x%x.", errno);
971                     return DEC_ERR_DECODE_SNDMSG;
972                 }
973             }*/
975         } // hIoPhy && decodeStatus.mode
976         else {
977             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
978         }
979     } // z=DECODE1 to DECODEN
981 //////////////////////////////////////////////////////////////////////////////
982     //asitPostDecEvent(); // simulation
983 //////////////////////////////////////////////////////////////////////////////
985     return ASIP_NO_ERR;
986 } /* decDecodeSnd() */
989 static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
990                            PAF_ASIT_Config *pAsitCfg)
992     PAF_AST_Config *pAstCfg;
993     PAF_AST_IoInp  *pInp;
994     AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
995     Int as;                     /* Audio Stream Number (1, 2, etc.) */
996     Int z;                      /* decode/stream counter */
997     Int errno;                  /* error number */
998     Int argIdx;
999     Int cbErrno;
1000     char decMsgBuf[ASP_MSG_BUF_LEN];
1001     Int status;
1003     pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
1004     pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
1005     hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
1006     as = pAstCfg->as;
1007     (void)as; // clear compiler warning in case not used with tracing disabled
1009     // Decode data
1010     for (z=DECODE1; z < DECODEN; z++)
1011     {
1012         Int zI = pP->inputsFromDecodes[z];
1013         Int zS = pP->streamsFromDecodes[z];
1014         (void)zS; // clear compiler warning in case not used with tracing disabled
1015         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
1016         {
1017             // receive decode ack message from slave
1018             errno  = 0;
1019             //argIdx = 0; // set decIdx
1020             //*(Int32 *)&decMsgBuf[argIdx] = z;
1021             status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_DECODE_DONE, decMsgBuf, FALSE);
1022             if (status != ASP_MSG_NO_ERR)
1023             {
1024                 TRACE_TERSE0("decodeDecode: error in receiving DEC_DECODE_DONE ack message ");
1025                 SW_BREAKPOINT; // temporary
1026                 errno = -1; // temporary error return value
1027                 return errno;
1028             }
1029             else
1030             {
1031                 argIdx = 0; // get decErrno
1032                 errno = *(Int32 *)&decMsgBuf[argIdx];
1033                 argIdx += sizeof(Int32); // get cbErrno
1034                 cbErrno = *(Int32 *)&decMsgBuf[argIdx];
1035                 if (cbErrno != 0)
1036                 {
1037                     gCbWrtAfErrCnt++;
1038                     TRACE_TERSE1("CB write error=%d", cbErrno);
1039                     //SW_BREAKPOINT; // temporary
1040                 }
1041             }
1043             // invalidate Dec configuration
1044             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
1045             Cache_wait();
1047             if(errno) {
1048                 TRACE_TERSE1("decDecodeAck return error errno 0x%x.", errno);
1049                 return DEC_ERR_DECODE_ACKMSG;
1050             }
1052 #if (CURRENT_TRACE_MASK & TRACE_MASK_DATA)
1053             as_traceChannels(pAsitCfg, z);
1054 #endif
1055         } // hIoPhy && decodeStatus.mode
1056         else {
1057             TRACE_VERBOSE2("AS%d: PAF_ASIT_decodeDecode: processing block %d -- decode <ignored>", as+zS, pAsitCfg->inpDec.block);
1058         }
1059     } // z=DECODE1 to DECODEN
1061     return ASIP_NO_ERR;
1062 } /* decDecodeAck */
1065 #if 0
1066 /************************************************************************************
1067  * ASP message sending function. Refer to aspMsg_master.h for detailed description.
1068 ************************************************************************************/
1069 Int AspMsgSnd(UInt32 sndCmd, char *sndMsgBuf)
1071     ASP_Msg* pAspMsg;                   /* Messaging */
1072     Int status;
1074     // allocate message
1075     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
1076     if (pAspMsg == NULL) {
1077         TRACE_TERSE0("MessageQ_alloc() failure.");
1078         return (ASP_MSG_ERR_QUEUE_ALLOC);
1079     }
1081     // set the return address in the message header and fill in message payload
1082     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);
1083     pAspMsg->cmd = sndCmd;
1084     pAspMsg->procId = hAspMsgMaster->masterProcId;
1085     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
1086     pAspMsg->expectResp = TRUE;
1088     // copy the message provided by caller
1089     if(sndMsgBuf != NULL) {
1090         memcpy(pAspMsg->buf, sndMsgBuf, ASP_MSG_BUF_LEN*sizeof(char));
1091     }
1093     // send the message
1094     TRACE_TERSE3("ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1095     status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);
1096     if (status != MessageQ_S_SUCCESS) {
1097         TRACE_TERSE0("MessageQ_put() failure.");
1098         MessageQ_free((MessageQ_Msg)pAspMsg);
1099         return (ASP_MSG_ERR_QUEUE_PUT);
1100     }
1102     status = MessageQ_free((MessageQ_Msg)pAspMsg);
1103     if (status != MessageQ_S_SUCCESS) {
1104         TRACE_TERSE0("MessageQ_free() failure.");
1105         return (ASP_MSG_ERR_QUEUE_FREE);
1106     }
1108     // No error in messaging operation, even though there
1109     // may be error in returned (acknowledgement) message.
1110     return (ASP_MSG_NO_ERR);
1111 } /* AspMsgSnd */
1113 /************************************************************************************
1114  * ASP message sending function. Refer to aspMsg_master.h for detailed description.
1115 ************************************************************************************/
1116 Int AspMsgAck(UInt32 ackCmd, char *ackMsgBuf)
1118     ASP_Msg* pAspMsg;                   /* Messaging */
1119     Int status;
1121     // allocate message
1122     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
1123     if (pAspMsg == NULL) {
1124         TRACE_TERSE0("MessageQ_alloc() failure.");
1125         return (ASP_MSG_ERR_QUEUE_ALLOC);
1126     }
1128     // wait for complete message from slave
1129     status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
1130     if (status != MessageQ_S_SUCCESS) {
1131         TRACE_TERSE0("MessageQ_get() failure.");
1132         MessageQ_free((MessageQ_Msg)pAspMsg);
1133         return (ASP_MSG_ERR_QUEUE_GET);
1134     }
1136     // check if returned message is valid
1137     if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
1138         (pAspMsg->cmd != ackCmd) ||
1139         (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31)))) {
1140         TRACE_TERSE3("ERROR: ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1141         MessageQ_free((MessageQ_Msg)pAspMsg);
1142         return(ASP_MSG_ERR_ACKNOWLEDGE);
1143     }
1145     hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
1146     TRACE_TERSE3("ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
1148     // get the returned message
1149     if(ackMsgBuf != NULL) {
1150         memcpy(ackMsgBuf, pAspMsg->buf, ASP_MSG_BUF_LEN*sizeof(char));
1151     }
1153     // free the message
1154     status = MessageQ_free((MessageQ_Msg)pAspMsg);
1155     if (status != MessageQ_S_SUCCESS) {
1156         TRACE_TERSE0("MessageQ_free() failure.");
1157         return (ASP_MSG_ERR_QUEUE_FREE);
1158     }
1160     // No error in messaging operation, even though there
1161     // may be error in returned (acknowledgement) message.
1162     return (ASP_MSG_NO_ERR);
1163 } /* AspMsgAck */
1164 #endif
1167 #if 0
1168 Int asipDecodeProcessing(
1169         const PAF_ASIT_Params *pP,
1170         const PAF_ASIT_Patchs *pQ,
1171         PAF_ASIT_Config *pC,
1172         Int sourceSelect)
1174     PAF_AST_Config *pAstCfg;
1175     Int errno, retVal;                          /* error number */
1176     Int zMD;
1178     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
1179     zMD = pAstCfg->masterDec;
1180     retVal = ASIP_NO_ERR;
1182     //pAstCfg->xInp[0].inpBufStatus.sampleRateStatus = PAF_SAMPLERATE_192000HZ;  //JXTODO: make this correct
1183     errno = decDecodeInfo(pP, pQ, pC);
1184     if (errno != ASIP_NO_ERR) {
1185         //gAsipInfo1_PrimaryErrCnt++;
1186         TRACE_TERSE1("INFO1: errno 0x%x after decodeInfo, primary timing", errno);
1187         retVal =  ASIP_ERR_DECODE_INFO;
1188     }
1189     else {
1190         // Don't start decode until major access unit is found.
1191         Int8 sourceDecode, sampleRate;
1192         sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
1193                                          GATEMP_INDEX_DEC);
1194         sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
1195                                          GATEMP_INDEX_DEC);
1196         if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
1197                (sourceDecode == PAF_SOURCE_DXP)     ||
1198                (sourceDecode == PAF_SOURCE_DTSHD) ) &&
1199              ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
1200             /* do nothing and return - waiting for major access unit */
1201             pC->inpDec.frame++;
1202             retVal =  ASIP_NO_ERR;
1203         }
1204         else {
1205             errno = decDecodeData(pP, pQ, pC, sourceSelect);
1206             if (errno != ASIP_NO_ERR) {
1207                 //gAsipDecodeErrCnt++;
1208                 TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", errno);
1209                 retVal = ASIP_ERR_DECODE_DATA;
1210             }
1211             else {
1212                 errno = pP->fxns->decodeFinalTest(pP, pQ, pC, pC->inpDec.frame, pC->inpDec.block);
1213                 if (errno) {
1214                     retVal = ASIP_ERR_DECODE_FINAL;
1215                 }
1216                 else {
1217                     retVal = ASIP_NO_ERR;
1218                 }
1219             }
1220         }
1221     }
1223     return retVal;
1224 }  /* asipDecodeProcessing */
1225 #endif
1228 #if 0
1229 // -----------------------------------------------------------------------------
1230 // ASIT Processing Function - Decode Processing
1231 //
1232 //   Name:      asipDecodeProcessing
1233 //   Purpose:
1234 //   Return:    Error number in standard form (0 on success).
1235 // -----------------------------------------------------------------------------
1236 Int asipDecodeProcessing(
1237         const PAF_ASIT_Params *pP,
1238         const PAF_ASIT_Patchs *pQ,
1239         PAF_ASIT_Config *pAsitCfg,
1240         Int sourceSelect)
1242     PAF_AST_Config *pAstCfg;
1243     asipDecProc_t  *pDec;
1244     Int decError, retVal, getVal;                          /* error number */
1245     Int zMD, decDone;
1246     Int8 tempVar8;
1248     pAstCfg = pAsitCfg->pAstCfg;     // get pointer to common (shared) configuration
1249     zMD = pAstCfg->masterDec;
1250     pDec = &pAsitCfg->inpDec;
1252     retVal = ASIP_NO_ERR;
1254     // Initialization for decode processing
1255     if(!pDec->initDone) {
1256         // Initialize decoder and send message to decoder
1257         retVal = decDecodeInit(pP, pAsitCfg, pAsitCfg->pIoInp[zMD].sourceSelect);
1258         if(retVal != ASIP_NO_ERR) {
1259             decDecodeComplete(pP, pAsitCfg);
1261             return retVal;
1262         }
1264         pDec->initDone = TRUE;
1265     }
1267     // Check if source has configured to NONE
1268     tempVar8 = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceSelect),
1269                                  GATEMP_INDEX_DEC);
1270     if (tempVar8 == PAF_SOURCE_NONE || sourceSelect == PAF_SOURCE_NONE) {
1271         TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: sourceSelect == PAF_SOURCE_NONE");
1272         pAsitCfg->inpDec.state = QUIT;   // skip processing, quit decoding
1273         retVal = ASIP_ERR_DECODE_QUIT;
1274     }
1276     // Process commands (decode)
1277     getVal = pP->fxns->decodeCommand(pP, pQ, pAsitCfg);
1278     if (getVal) {
1279         retVal = ASIP_ERR_DECODE_COMMAND;
1280         if (getVal == ASPERR_QUIT) {
1281             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: state = QUIT");
1283             // Don't return if ASPERR_QUIT, but skip decode processing and quit
1284             pAsitCfg->inpDec.state = QUIT;
1285         }
1286         else if (getVal == ASPERR_ABORT) {
1287             TRACE_VERBOSE0("PAF_ASIT_decodeProcessing. %d: return getVal");
1289             // Return here if ASPERR_ABORT
1290             return retVal;
1291         }
1292         else {
1293             /* ignore */;
1294         }
1295     }
1297     do {
1298         decDone = TRUE;
1300         switch(pAsitCfg->inpDec.state)
1301         {
1302             case INFO1:
1303                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
1304                 if (decError) {
1305                     //gAsipInfo1_PrimaryErrCnt++;
1306                     TRACE_TERSE1("INFO1: decError 0x%x after decodeInfo, primary timing", decError);
1307                     retVal = ASIP_ERR_DECODE_INFO1;
1308                 }
1309                 else {
1310                     // Don't start decode until major access unit is found.
1311                     Int8 sourceDecode, sampleRate;
1313                     sourceDecode = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sourceDecode),
1314                                                      GATEMP_INDEX_DEC);
1315                     sampleRate   = sharedMemReadInt8(&(pAstCfg->xDec[zMD].decodeStatus.sampleRate),
1316                                                      GATEMP_INDEX_DEC);
1317                     if ( ( (sourceDecode == PAF_SOURCE_THD)     ||
1318                            (sourceDecode == PAF_SOURCE_DXP)     ||
1319                            (sourceDecode == PAF_SOURCE_DTSHD) ) &&
1320                          ( sampleRate == PAF_SAMPLERATE_UNKNOWN) ) {
1321                         //gMajorAuMissed++; // debug
1322                         pAsitCfg->inpDec.frame++;
1323                         //pAsitCfg->inpDec.state = INFO1;    // stay in this state
1324                     }
1325                     else {
1326                         decError = pP->fxns->decodeInfo1(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
1327                         if(decError) {
1328                             retVal = ASIP_ERR_DECODE_INFO1;
1329                         }
1330                         else {
1331                             pAsitCfg->inpDec.state = DECODE;
1332                             decDone = FALSE;    // go to DECODE state before return
1333                         }
1334                     }
1335                 }
1336                 break;
1338             case INFO2:
1339                 decError = decDecodeInfo(pP, pQ, pAsitCfg);
1340                 if (decError) {
1341                     //gAsipInfo1_PrimaryErrCnt++;
1342                     TRACE_TERSE1("INFO2: decError 0x%x after decodeInfo, primary timing", decError);
1343                     retVal = ASIP_ERR_DECODE_INFO2;
1344                 }
1345                 else {
1346                     pAsitCfg->inpDec.state = DECODE;
1347                     decDone = FALSE;     // go to DECODE state before return
1348                 }
1349                 break;
1351             case DECODE:
1352                 decError = decDecodeData(pP, pQ, pAsitCfg, sourceSelect);
1353                 if (decError) {
1354                     //gAsipDecodeErrCnt++;
1355                     TRACE_TERSE1("PAF_ASIT_decodeProcessing: state: DECODE.  decodeDecode err 0x%04x", decError);
1356                     retVal = ASIP_ERR_DECODE_DATA;
1357                 }
1358                 else {
1359                     decError = pP->fxns->decodeFinalTest(pP, pQ, pAsitCfg, pAsitCfg->inpDec.frame, pAsitCfg->inpDec.block);
1360                     if (decError) {
1361                         retVal = ASIP_ERR_DECODE_FINAL;
1362                     }
1363                     else {
1364                         pAsitCfg->inpDec.frame++;
1365                         pAsitCfg->inpDec.state = INFO2;
1366                     }
1367                 }
1368                 break;
1370             case QUIT:
1371                 //gAsipQuitCnt++;
1372                 Log_info0("TaskAsip: state=QUIT");
1374                 // Quit:
1375                 // - Set error number registers.
1376                 // - Exit state machine to "decode complete" processing.
1377                 TRACE_VERBOSE0("PAF_ASIT_decodeProcessing: state: QUIT");
1378                 break;
1380             default:
1381                 break;
1383         }  /* switch */
1385     } while (!decDone);
1387     if(retVal != ASIP_NO_ERR) {
1388         decDecodeComplete(pP, pAsitCfg);
1389     }
1391     return retVal;
1392 }  /* asipDecodeProcessing */
1394 #endif
1397 /* Nothing past this line */