]> 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-577:Move local var declarations outside if()
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / audioStreamOutIo.c
index 2764cfa66a380d82006d09a55aa25d8173690ca1..8b2b37f85bf7f45c8ca8892e4fd6d3f201cf948d 100644 (file)
@@ -64,31 +64,75 @@ 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(void *pConfig, PAF_AST_IoOut *pOut)
+Int asopSelectDevices(
+    const PAF_SIO_Params *pOutCfg, 
+    PAF_AST_IoOut *pOut
+)
 {
-    if((pOut->hIoBuff == NULL) || (pOut->hIoPhy == NULL) || (!d10Initialized)) {
-        return -1;
-    }
+    mcaspLLDconfig *pReqLldCfg;
+    Ptr mcaspChanHandle;
+    Aud_STATUS status;
 
-    if(pOut->hMcaspChan == NULL) {
-        Audk2g_STATUS status;
-        mcaspLLDconfig * lldCfg;
-        Ptr mcaspChanHandle;
+    if ((pOut->hIoBuff == NULL) || (pOut->hIoPhy == NULL) || (!d10Initialized)) 
+    {
+        return ASOP_IO_ERR_IO_UNINIT;
+    }
 
-        lldCfg = (mcaspLLDconfig *)pConfig;
-        status = mcasplldChanCreate(lldCfg, &mcaspChanHandle);
-        if(status != Audk2g_EOK) {
-            return -1;
+    // Deactivate currently active Output device
+    if (pOut->hMcaspChan != NULL)
+    {
+        // Delete McASP LLD channel
+        status = mcaspDeleteChan(pOut->hMcaspChan);
+        if (status != Aud_EOK)
+        {
+            Log_info0("asopSelectDevices(): McASP channel deletion failed!\n");
+            return ASOP_IO_ERR_MCASP_CFG;
         }
+        
+        pOut->hMcaspChan = NULL;            // reset active McASP LLD handle
+        pOut->pLldCfg->hMcaspChan = NULL;   // reset McASP LLD handle for active McASP LLD configuration
+        pOut->pLldCfg = NULL;               // reset pointer to active McASP LLD configuration
+    }
 
-        pOut->hMcaspChan = mcaspChanHandle;
-        pOut->stride = lldCfg->mcaspChanParams->noOfSerRequested * lldCfg->mcaspChanParams->noOfChannels;
+    // Activate requested device
+    if (pOutCfg != NULL)
+    {
+        //
+        // Device other than OutNone selected
+        //
+        
+        pReqLldCfg = (mcaspLLDconfig *)pOutCfg->sio.pConfig;
+        if (pReqLldCfg->hMcaspChan == NULL) 
+        {
+            // Create McASP LLD channel
+            mcaspChanHandle = NULL;
+            status = mcasplldChanCreate(pReqLldCfg, &mcaspChanHandle);
+            if (status != Aud_EOK) {
+                Log_info0("asopSelectDevices(): McASP channel creation failed!\n");
+                return ASOP_IO_ERR_MCASP_CFG;
+            }
+
+            pReqLldCfg->hMcaspChan = mcaspChanHandle;   // set McASP LLD handle for requested McASP LLD configuration
+            pOut->pLldCfg = pReqLldCfg;                 // set pointer to active McASP LLD configuration
+            pOut->hMcaspChan = pReqLldCfg->hMcaspChan;  // set active McASP LLD handle
+            
+            // configure stride according to selected McASP LLD configuration
+            pOut->stride = pReqLldCfg->mcaspChanParams->noOfSerRequested * 
+                pReqLldCfg->mcaspChanParams->noOfChannels;
+        }
+    }
+    else
+    {
+        //
+        // OutNone device selected
+        //
+        
+        pOut->hMcaspChan = NULL;    // reset active McASP LLD handle
+        pOut->pLldCfg = NULL;       // reset pointer to active McASP LLD configuration
     }
 
-    return 0;
+    return ASOP_IO_SOK;
 }
 
 // Check if Output device SIO selection changed
@@ -106,12 +150,12 @@ Int checkOutDevSioSelUpdate(
     if ((z < OUTPUT1) || (z >= OUTPUTN))
     {
         *pOutDevSelUpdate = FALSE;
-        return -1;
+        return ASOP_IO_ERR_INV_PARAMS;
     }
     
     *pOutDevSelUpdate = (Bool)(pAstCfg->xOut[z].outBufStatus.sioSelect >= 0);
 
-    return 0;
+    return ASOP_IO_SOK;
 }
 
 // Check if any Output device SIO selection changed
@@ -139,7 +183,7 @@ Int checkAnyOutDevSioSelUpdate(
     
     *pOutDevSelUpdate = outDevSelUpdate;
 
-    return 0;
+    return ASOP_IO_SOK;
 }
 
 // -----------------------------------------------------------------------------
@@ -243,10 +287,12 @@ Int asopSetCheckRateX(
                 return ((getVal & 0xff) | ASPERR_RATE_CHECK);
             }
 #endif // FL, New IO
+            // FL: ugly little experiment
+            //*(volatile UInt32 *)0x23400B0 |= 7;
         }
     }
 
-    return 0;
+    return ASOP_IO_SOK;
 } //asopSetCheckRateX
 
 // -----------------------------------------------------------------------------
@@ -386,7 +432,7 @@ Int asopStartOutput(
         }
     }
 
-    return 0;
+    return ASOP_IO_SOK;
 } /* asopStartOutput */
 
 // -----------------------------------------------------------------------------
@@ -412,7 +458,7 @@ Int asopStopOutput(
     PAF_AST_IoOut  *pOut;
     Int as;                     /* Audio Stream Number (1, 2, etc.) */
     Int z;                      /* output counter */
-    Int errno = 0, getVal;
+    Int errno, getVal;
     Int zS, zX;
     PAF_SIO_IALG_Obj    *pObj;
     PAF_SIO_IALG_Config *pAlgConfig;
@@ -422,6 +468,7 @@ Int asopStopOutput(
     as = pAstCfg->as;
     (void)as;  // clear compiler warning in case not used with tracing disabled
 
+    errno = ASOP_IO_SOK;
     for (z=OUTPUT1; z < OUTPUTN; z++) 
     {
         if (pOut[z].hIoPhy) 
@@ -524,35 +571,38 @@ Int asopIoCompsInit(
     PAF_AST_IoOut *pOutIo
 )
 {
-    // Initialize I/O BUFF and I/O PHY components for output task
     ioBuffParams_t ioBuffParams;
     ioPhyParams_t  ioPhyParams;
 
-    ioBuffParams.base         = pOutBuf->outBufConfig.base.pVoid;
-    ioBuffParams.size         = pOutBuf->outBufConfig.allocation/STRIDE_WORST_CASE*STRIDE_WORST_CASE;
-    ioBuffParams.sync         = IOBUff_READ_SYNC;
-    ioBuffParams.nominalDelay = NUM_CYCLE_PER_FRAME_DEF * pOutIo->stride * WORD_SIZE_PCM * (NUM_PRIME_XFERS+1);
-    if(ioBuffInit(pOutIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) 
+    if (pOutIo->hMcaspChan != NULL)
     {
-        return -1;   // to remove magic number
-    }
+        // Initialize I/O BUFF and I/O PHY components for output task
+        ioBuffParams.base         = pOutBuf->outBufConfig.base.pVoid;
+        ioBuffParams.size         = pOutBuf->outBufConfig.allocation/STRIDE_WORST_CASE*STRIDE_WORST_CASE;
+        ioBuffParams.sync         = IOBUff_READ_SYNC;
+        ioBuffParams.nominalDelay = NUM_CYCLE_PER_OUTPUT_FRAME_DEF * pOutIo->stride * WORD_SIZE_PCM * (NUM_PRIME_XFERS+1);
+        if(ioBuffInit(pOutIo->hIoBuff, &ioBuffParams) != IOBUFF_NOERR) 
+        {
+            return ASOP_IO_ERR_IOBUFF_INIT;   // to remove magic number
+        }
 
-    ioPhyParams.ioBuffHandle    = pOutIo->hIoBuff;
-    ioPhyParams.xferFrameSize   = NUM_CYCLE_PER_FRAME_DEF * pOutIo->stride * WORD_SIZE_PCM;
-    ioPhyParams.mcaspChanHandle = pOutIo->hMcaspChan;
-    ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_READ;
-    if(ioPhyInit(pOutIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) 
-    {
-        return -1;   // to remove magic number
-    }
+        ioPhyParams.ioBuffHandle    = pOutIo->hIoBuff;
+        ioPhyParams.xferFrameSize   = NUM_CYCLE_PER_FRAME_DEF * pOutIo->stride * WORD_SIZE_PCM;
+        ioPhyParams.mcaspChanHandle = pOutIo->hMcaspChan;
+        ioPhyParams.ioBuffOp        = IOPHY_IOBUFFOP_READ;
+        if(ioPhyInit(pOutIo->hIoPhy, &ioPhyParams) != IOPHY_NOERR) 
+        {
+            return ASOP_IO_ERR_IOPHY_INIT;   // to remove magic number
+        }
 
-    pOutIo->phyXferSize = ioPhyParams.xferFrameSize;
+        pOutIo->phyXferSize = ioPhyParams.xferFrameSize;
+        
+        pOutIo->ioBuffBuf2AllocCnt = 0; // initialize buffer2 alloc count (indicates Output buffer wrap)
+        pOutIo->errIoBuffOvrCnt = 0; // initialize IO buff overflow count
+        pOutIo->errIoBuffUndCnt = 0; // initialize IO buff underflow count
+    }
     
-    pOutIo->ioBuffBuf2AllocCnt = 0; // initialize buffer2 alloc count (indicates Output buffer wrap)
-    pOutIo->errIoBuffOvrCnt = 0; // initialize IO buff overflow count
-    pOutIo->errIoBuffUndCnt = 0; // initialize IO buff underflow count
-
-    return 0;
+    return ASOP_IO_SOK;
 } /* asopIoCompsInit */
 
 /*======================================================================================
@@ -606,7 +656,7 @@ Int asopInitOutBufConfig(
     
     pOutBuf->pOutBuf = &(pOutBuf->outBufConfig);
     
-    return 0;
+    return ASOP_IO_SOK;
 }
 
 Int asopGetOutBufPtrs(
@@ -626,7 +676,7 @@ Int asopGetOutBufPtrs(
         //System_printf ("asopGetOutBufPtrs: output buff overflow\n"); // debug
 
         // skip processing since output buffer overflows
-        return -1;
+        return ASOP_IO_ERR_OUTBUF_OVERFLOW;
     }
     else if (status == IOBUFF_ERR_UNDERFLOW)
     {
@@ -642,7 +692,7 @@ Int asopGetOutBufPtrs(
     pOutIo->buff2 = buff2;
     pOutIo->size2 = size2;
 
-    return 0;
+    return ASOP_IO_SOK;
 }
 
 #if 0
@@ -680,7 +730,7 @@ Int asopUpdateOutBufConfig(
         //System_printf ("asopUpdateOutBufConfig: output buff overflow\n"); // debug
 
         // skip processing since output buffer overflows        
-        return -1;
+        return ASOP_IO_ERR_OUTBUF_OVERFLOW;
     }
     else if (status == IOBUFF_ERR_UNDERFLOW) 
     {
@@ -705,7 +755,7 @@ Int asopUpdateOutBufConfig(
     pOutIo->buff2 = buff2;
     pOutIo->size2 = size2;
     
-    return 0;
+    return ASOP_IO_SOK;
 }
 #endif
 
@@ -734,7 +784,7 @@ Int asopMarkOutBuffsWriteComplete(
         ioBuffWriteComplete(hIoBuff, buff2, size2);
     }
     
-    return 0;
+    return ASOP_IO_SOK;
 }
 
 /*======================================================================================