]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/test_dsp/framework/audioStreamOutIo.c
PASDK-516:Add updates for PCE
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutIo.c
index e0ad21d00140d1b872e0659f2aefdae6a6fc11ca..7c715ba59613a2a55338fb81459825d0e80cc0f3 100644 (file)
@@ -64,6 +64,71 @@ extern Ptr hMcaspTxChan;
 extern Int d10Initialized;
 
 
+// FL, New IO: this function is currently a stub
+// FL, New IO: need to McASP/EDMA configuration using SAP configuration from Output shortcut
+// Select Output devices
+Int asopSelectDevices(PAF_AST_IoOut *pOut)
+{
+    if((pOut->hIoBuff == NULL) || (pOut->hIoPhy == NULL) || (!d10Initialized)) {
+        return -1;
+    }
+
+    pOut->hMcaspChan = hMcaspTxChan;
+
+    return 0;
+}
+
+// Check if Output device SIO selection changed
+Int checkOutDevSioSelUpdate(
+    const PAF_ASOT_Params *pP, 
+    PAF_ASOT_Config *pAsotCfg,
+    Int z, 
+    Bool *pOutDevSelUpdate
+)
+{
+    PAF_AST_Config *pAstCfg;
+    
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+
+    if ((z < OUTPUT1) || (z >= OUTPUTN))
+    {
+        *pOutDevSelUpdate = FALSE;
+        return -1;
+    }
+    
+    *pOutDevSelUpdate = (Bool)(pAstCfg->xOut[z].outBufStatus.sioSelect >= 0);
+
+    return 0;
+}
+
+// Check if any Output device SIO selection changed
+Int checkAnyOutDevSioSelUpdate(
+    const PAF_ASOT_Params *pP, 
+    PAF_ASOT_Config *pAsotCfg,
+    Bool *pOutDevSelUpdate
+)
+{
+    PAF_AST_Config *pAstCfg;
+    Int outDevSelUpdate;
+    Int z;
+    
+    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+
+    outDevSelUpdate = FALSE;
+    for (z=OUTPUT1; z < OUTPUTN; z++) 
+    {
+        if (pAstCfg->xOut[z].outBufStatus.sioSelect >= 0)
+        {
+            outDevSelUpdate = TRUE;
+            break;
+        }
+    }
+    
+    *pOutDevSelUpdate = outDevSelUpdate;
+
+    return 0;
+}
+
 // -----------------------------------------------------------------------------
 // ASOT Decoding Function Helper - SIO Driver Change
 //
@@ -249,17 +314,17 @@ Int asopStartOutput(
             pAstCfg->xOut[z].outBufConfig.lengthofFrame =
                 pAstCfg->xEnc[zE].encodeInStruct.pAudioFrame->sampleCount;
 
-#if 1 // FL New IO: add similar thing to be figured out
+#if 1 // FL, New IO: add similar thing to be figured out
+            // Update framework Phy transfer size
+            pOut[z].phyXferSize = pAstCfg->xOut[z].outBufConfig.lengthofFrame * OUTPUT_STRIDE * WORD_SIZE_PCM;
+            // Update IO Phy transfer size            
             ioPhyCtl.code = IOPHY_CTL_FRAME_SIZE;
-            ioPhyCtl.params.xferFrameSize = pAstCfg->xOut[z].outBufConfig.lengthofFrame
-                                               * OUTPUT_STRIDE * WORD_SIZE_PCM;
+            ioPhyCtl.params.xferFrameSize = pOut[z].phyXferSize;
             ioPhyControl(pOut[z].hIoPhy, &ioPhyCtl);
-            // Update framework transfer size to IO Phy transfer size
-            pOut[z].phyXferSize = ioPhyCtl.params.xferFrameSize;
-            // Update IO Buff delay to match IO Phy transfer size
-            ioBuffAdjustDelay(pOut[z].hIoBuff, ioPhyCtl.params.xferFrameSize * (NUM_PRIME_XFERS+1));
+            // Update IO Buff delay to match Phy transfer size
+            ioBuffAdjustDelay(pOut[z].hIoBuff, pOut[z].phyXferSize * (NUM_PRIME_XFERS+1));
 #endif            
-                
+
             if (pAstCfg->xOut[z].outBufStatus.markerMode == PAF_OB_MARKER_ENABLED)
             {
                 pObj = (PAF_SIO_IALG_Obj *) pAstCfg->xOut[z].outChainData.head->alg;
@@ -438,20 +503,6 @@ Int asopStopOutput(
     return errno;
 } //asopStopOutput
 
-// FL, New IO: this function is currently a stub
-// FL, New IO: need to McASP/EDMA configuration using SAP configuration from Output shortcut
-// Select Output devices
-Int asopSelectDevices(PAF_AST_IoOut *pOut)
-{
-    if((pOut->hIoBuff == NULL) || (pOut->hIoPhy == NULL) || (!d10Initialized)) {
-        return -1;
-    }
-
-    pOut->hMcaspChan = hMcaspTxChan;
-
-    return 0;
-}
-
 /*===========================================================================
  * Initialize I/O components for output processing
 ============================================================================*/
@@ -483,10 +534,23 @@ Int asopIoCompsInit(
     }
 
     pOutIo->phyXferSize = ioPhyParams.xferFrameSize;
+    
+    pOutIo->ioBuffNumOvr = 0; // initialize number of IO buff overflows
+    pOutIo->ioBuffNumUnd = 0; // initialize number of IO buff underflows
 
     return 0;
 } /* asopIoCompsInit */
 
+/*======================================================================================
+ *  This function checks whether the I/O physical layer has been initialized
+ *====================================================================================*/
+Bool asopIoPhyCheckInit(Void)
+{
+    if (!d10Initialized)
+        return FALSE;
+    else 
+        return TRUE;
+}
 
 /*======================================================================================
  *  I/O physical layer prime operation required by McASP LLD
@@ -505,132 +569,141 @@ Void asopIoPhyPrime(
     }
 } /* asipIoPhyPrime */
 
-
-/*======================================================================================
- *  This function checks whether the I/O physical layer has been initialized
- *====================================================================================*/
-Bool asopIoPhyCheckInit(Void)
-{
-    if (!d10Initialized)
-        return FALSE;
-    else 
-        return TRUE;
-}
-
-/*======================================================================================
- *  This function starts an I/O PHY transfer for output
- *====================================================================================*/
-Void asopPhyTransferStart(
-    PAF_AST_IoOut *pOut
+// Initialize Output buffer configuration
+Int asopInitOutBufConfig(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
 )
 {
-    if(mcaspCheckOverUnderRun(pOut->hMcaspChan)) 
-    {
-        mcaspTxReset();
-        mcaspTxCreate();
-        pOut->hMcaspChan = hMcaspTxChan;
-    }
-    else 
-    {
-        if(ioPhyXferSubmit(pOut->hIoPhy) == IOPHY_ERR_BUFF_UNDERFLOW) 
-        {
-            // Output buffer underflows!
-            System_abort("\nOutput buffer underflows!\n");
-        }
-        else {
-            // Output buffer operates normally
-            ;
-        }
-    }
+    PAF_OutBufConfig *pOutBufCfg;
+    ioBuffHandle_t hIoBuff;
+    ioBuffInfo_t outBuffInfo;
+    
+    pOutBufCfg = &pOutBuf->outBufConfig;
+    hIoBuff = pOutIo->hIoBuff;
+    
+    pOutBufCfg->stride = OUTPUT_STRIDE;
+    pOutBufCfg->sizeofElement = WORD_SIZE_PCM;
+    pOutBufCfg->precision = 24;
+    
+    ioBuffGetInfo(hIoBuff, &outBuffInfo);
+       pOutBufCfg->base.pLgInt = outBuffInfo.base;
+       pOutBufCfg->sizeofBuffer = outBuffInfo.size;
+    
+       pOutBuf->pOutBuf = &(pOutBuf->outBufConfig);    
+    
+    return 0;
 }
 
-// Write output buffers with encoded data
-Int asopWriteOpBuffers(
-    PAF_OutBufConfig *pOpBufCfg, 
-    PAF_AST_IoOut *pOut
+// Update Output buffer configuration.
+// This is needed for proper operation of PCM encoder.
+Int asopUpdateOutBufConfig(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
 )
 {
-    PAF_UnionPointer pntr;
+    PAF_OutBufConfig *pOutBufCfg;
+    ioBuffHandle_t hIoBuff;
+    ioBuffInfo_t outBuffInfo;
     void *buff1, *buff2;
-    size_t size1, size2;
-    int status;
+    size_t size1, size2, total_write_size;
+    Int status;
+
+    pOutBufCfg = &pOutBuf->outBufConfig;
+    hIoBuff = pOutIo->hIoBuff;
 
-    pntr = pOpBufCfg->pntr; // get output buffer pointer
+    // FL, New IO: original code can change these values in every DOB issue
+    //  Need to determine if this is required or not.
+    pOutBufCfg->stride = OUTPUT_STRIDE;
+    pOutBufCfg->sizeofElement = WORD_SIZE_PCM;
+    pOutBufCfg->precision = 24;
     
-    status = ioBuffGetWritePtrs(pOut->hIoBuff, pOut->phyXferSize,
+    //JXTODO: to replace hard coded write size
+    // Get write pointers of output memory pool
+       total_write_size = pOutBufCfg->lengthofFrame * pOutBufCfg->stride * pOutBufCfg->sizeofElement;
+    status = ioBuffGetWritePtrs(hIoBuff, total_write_size,
         &buff1, &size1, &buff2, &size2);
     if (status == IOBUFF_ERR_OVERFLOW) 
     {
-        /* skip processing since output buffer overflows */
-        return IOBUFF_ERR_OVERFLOW;   // to use a different error code
-    }
+        pOutIo->ioBuffNumOvr++;
+        //System_printf ("asopUpdateOutBufConfig: output buff overflow\n"); // debug
 
-    // Copy data to output buffer to be transmitted by McASP
-    memcpy(buff1, &pntr.pSmInt[0], size1);
-    Cache_wbInv(buff1, size1, Cache_Type_ALL,TRUE);
-
-    ioBuffWriteComplete(pOut->hIoBuff, buff1, size1);
-
-    if (buff2 != NULL) 
+        // skip processing since output buffer overflows        
+        return -1;
+    }
+    else if (status == IOBUFF_ERR_UNDERFLOW) 
     {
-      memcpy(buff2, &pntr.pSmInt[size1], size2);
-      Cache_wbInv(buff2, size2, Cache_Type_ALL,TRUE);
-
-      ioBuffWriteComplete(pOut->hIoBuff, buff2, size2);
+        pOutIo->ioBuffNumUnd++;
+        //System_printf ("asopUpdateOutBufConfig: output buff underflow\n"); // debug
+        
+        // already underflows and remain in underflow
     }
 
+    // Update Output buffer pointer for Encoder
+       pOutBufCfg->pntr.pLgInt = buff1;
+    
+    // save buffer pointers & sizes for later write complete
+    pOutIo->buff1 = buff1;
+    pOutIo->size1 = size1;
+    pOutIo->buff2 = buff2; // this should always be NULL for Output
+    pOutIo->size2 = size2; // this should always be 0 for Output
+    
     return 0;
 }
 
-// Check if Output device SIO selection changed
-Int checkOutDevSioSelUpdate(
-    const PAF_ASOT_Params *pP, 
-    PAF_ASOT_Config *pAsotCfg,
-    Int z, 
-    Bool *pOutDevSelUpdate
+// Mark Output buffers write complete
+Int asopMarkOutBuffsWriteComplete(
+    PAF_AST_OutBuf *pOutBuf, 
+    PAF_AST_IoOut *pOutIo
 )
 {
-    PAF_AST_Config *pAstCfg;
+    ioBuffHandle_t hIoBuff;
+    void *buff1, *buff2;
+    size_t size1, size2;
     
-    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    // get buffer pointers & sizes from previous IO Buff write allocation
+    buff1 = pOutIo->buff1;
+    size1 = pOutIo->size1;
+    buff2 = pOutIo->buff2; // this should always be NULL for Output
+    size2 = pOutIo->size2; // this should always be 0 for Output
+    
+    hIoBuff = pOutIo->hIoBuff;
+    
+    ioBuffWriteComplete(hIoBuff, buff1, size1);
 
-    if ((z < OUTPUT1) || (z >= OUTPUTN))
+    if (buff2 != NULL) 
     {
-        *pOutDevSelUpdate = FALSE;
-        return -1;
+        ioBuffWriteComplete(hIoBuff, buff2, size2);
     }
     
-    *pOutDevSelUpdate = (Bool)(pAstCfg->xOut[z].outBufStatus.sioSelect >= 0);
-
     return 0;
 }
 
-// Check if any Output device SIO selection changed
-Int checkAnyOutDevSioSelUpdate(
-    const PAF_ASOT_Params *pP, 
-    PAF_ASOT_Config *pAsotCfg,
-    Bool *pOutDevSelUpdate
+/*======================================================================================
+ *  This function starts an I/O PHY transfer for output
+ *====================================================================================*/
+Void asopPhyTransferStart(
+    PAF_AST_IoOut *pOut
 )
 {
-    PAF_AST_Config *pAstCfg;
-    Int outDevSelUpdate;
-    Int z;
-    
-    pAstCfg = pAsotCfg->pAstCfg; // get pointer to AST common (shared) configuration
-
-    outDevSelUpdate = FALSE;
-    for (z=OUTPUT1; z < OUTPUTN; z++) 
+    if(mcaspCheckOverUnderRun(pOut->hMcaspChan)) 
     {
-        if (pAstCfg->xOut[z].outBufStatus.sioSelect >= 0)
+        mcaspTxReset();
+        mcaspTxCreate();
+        pOut->hMcaspChan = hMcaspTxChan;
+    }
+    else 
+    {
+        if(ioPhyXferSubmit(pOut->hIoPhy) == IOPHY_ERR_BUFF_UNDERFLOW) 
         {
-            outDevSelUpdate = TRUE;
-            break;
+            // Output buffer underflows!
+            System_abort("\nOutput buffer underflows!\n");
+        }
+        else {
+            // Output buffer operates normally
+            ;
         }
     }
-    
-    *pOutDevSelUpdate = outDevSelUpdate;
-
-    return 0;
 }
 
 /* nothing past this point */