PASDK-577:Dynamic Input device selection
authorFrank Livingston <frank-livingston@ti.com>
Wed, 9 May 2018 22:30:22 +0000 (17:30 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Wed, 9 May 2018 22:30:22 +0000 (17:30 -0500)
Update Input device selection routine to allow dynamic selection over
alpha command (Input shortcuts).

pasdk/test_dsp/framework/audioStreamInpProcNewIO.c

index 8975f512ccac16bded7386ee39f95330a397ac9a..6400252941abd461e026217fae7636b14f382610 100644 (file)
@@ -124,7 +124,14 @@ void asitIoPhyPrime(PAF_AST_IoInp *pInpIo);
 void asitPhyTransferComplete(PAF_AST_IoInp * pInpIo);
 void asitPhyTransferStart(PAF_AST_IoInp *pInpIo);
 Int asitRecfgPhyXfer(PAF_AST_IoInp *pInp, size_t xferSize);
-Int asitSelectDevices(const PAF_ASIT_Patchs *pQ, PAF_AST_Config *pAstCfg, PAF_AST_IoInp *pInp);
+
+// Select Input devices
+Int asitSelectDevices(
+    const PAF_ASIT_Patchs *pQ, 
+    PAF_AST_Config *pAstCfg, 
+    PAF_AST_IoInp *pInp
+);
+
 Int asitUpdateInputStatus(const void *pRxParams, PAF_InpBufStatus *pStatus,
                           PAF_InpBufConfig *pInpBuf);
 
@@ -1105,69 +1112,163 @@ extern void McaspDevice_init(void);
 /*======================================================================================
  *  This function initializes HW interface and selects the right device for input
  *====================================================================================*/
-Int asitSelectDevices(const PAF_ASIT_Patchs *pQ, PAF_AST_Config *pAstCfg, PAF_AST_IoInp *pInp)
+Int asitSelectDevices(
+    const PAF_ASIT_Patchs *pQ, 
+    PAF_AST_Config *pAstCfg, 
+    PAF_AST_IoInp *pInp
+)
 {
     Aud_STATUS status;
-    mcaspLLDconfig *lldCfg;
+    const PAF_SIO_Params *pInPrms;
+    mcaspLLDconfig *pLldCfg;
+    mcaspLLDconfig *pReqLldCfg;
     Ptr mcaspChanHandle;
-    Int zMD, interface;
+    Int zMD;
+    Int interface;
+    const PAF_SIO_Params *pD10Params;
 
     zMD = pAstCfg->masterDec;
-
+    
     interface = pAstCfg->xInp[zMD].inpBufStatus.sioSelect; // obtain SIO select for input
+    
+    if (interface >= 0)
+    {
+        // Positive value for interface: new Input SIO update request has been received via alpha command.
+        // Negative value for interface: no new Input SIO update request has been received,
+        //                               previous requests have been processed.
+        
+        // check for valid index into device array
+        if (interface >= pQ->devinp->n)    // DEVINP_N
+        {
+            interface = 0; // treat as device InNone
+        }
+        
+        //
+        // Deactivate currently active interface
+        //
+        if (pInp->hMcaspChan != NULL)   // non-NULL McASP LLD channel handle indicates there's an active interface
+        {
+            // Delete McASP LLD channel
+            status = mcaspDeleteChan(pInp->hMcaspChan);
+            if (status != Aud_EOK)
+            {
+                Log_info0("asitSelectDevices(): McASP channel deletion failed!\n");
+                return ASIP_ERR_MCASP_CFG;
+            }
+            
+            pInp->hMcaspChan = NULL;        // reset active McASP LLD handle
+            if (pInp->pRxParams != NULL)    // sanity check, pInp->pRxParams should be non NULL if pInp->hMcaspChan is non NULL
+            {
+                pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
+                pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig; // get pointer to active McASP LLD configuration
+                pLldCfg->hMcaspChan = NULL; // reset McASP LLD handle for active McASP LLD configuration
+                pInp->pRxParams = NULL;     // reset pointer to active D10 parameters
+            }
+            else 
+            {
+                // This is a programming error
+                SW_BREAKPOINT;  // debug
+            }
+        }
 
-    if (interface <= 0) {
-        pInp->pRxParams = NULL;
-
-        return ASIT_NO_ERR;
-    }
-
-    // Initialize D10
-    if(!d10Initialized) {
-        void * pD10Params = (void *)pQ->devinp->x[interface];
-
-        /* Initialize McASP HW details */
-        McaspDevice_init();
-
-        D10_init(pD10Params);
-
-        d10Initialized = 1;
-    }
+        //
+        // Activate requested interface
+        //
+        pD10Params = (const PAF_SIO_Params *)pQ->devinp->x[interface];  // get D10 parameters for selected interface
+        if (pD10Params != NULL)
+        {
+            //
+            // Requested device is other than InNone
+            //
+            
+            //if (!d10Initialized)
+            //{
+                // FL: probably no harm in calling this for every new i/f request.
+                //     However, it can probably be moved to main() or sys init task.
+                // Initialize McASP HW details
+                McaspDevice_init();
+                
+                // Initialize Rx hardware
+                D10_init((void *)pD10Params);
+                
+            //    d10Initialized=1;
+            //}
+            
+            if (!d10Initialized)
+            {
+                d10Initialized=1; // global flag indicating D10 init completed
+            }
 
-    /* Get the McASP LLD channel for this interface. Create one if not yet created. */
-    lldCfg = (mcaspLLDconfig *)pQ->devinp->x[interface]->sio.pConfig;
-    if(lldCfg->hMcaspChan == NULL) {
-        mcaspChanHandle = NULL;
-        status = mcasplldChanCreate(lldCfg, &mcaspChanHandle);
-        if(status != Aud_EOK) {
-            Log_info0("asitSelectDevices(): McASP channel creation failed!\n");
-            return ASIT_ERR_MCASP_CFG;
+            pReqLldCfg = (mcaspLLDconfig *)pD10Params->sio.pConfig;
+            if (pReqLldCfg->hMcaspChan == NULL)
+            {
+                // Create McASP LLD channel
+                mcaspChanHandle = NULL;
+                status = mcasplldChanCreate(pReqLldCfg, &mcaspChanHandle);
+                if (status != Aud_EOK) 
+                {
+                    Log_info0("asitSelectDevices(): McASP channel creation failed!\n");
+                    return ASIP_ERR_MCASP_CFG;
+                }
+                
+                pReqLldCfg->hMcaspChan = mcaspChanHandle;   // set McASP LLD handle for requested McASP LLD configuration
+                pInp->pRxParams = (const void *)pD10Params; // set pointer to active D10 parameters
+                pInp->hMcaspChan = pReqLldCfg->hMcaspChan;  // set active McASP LLD handle
+                
+                // configure stride according to selected McASP LLD configuration
+                pInp->stride = pReqLldCfg->mcaspChanParams->noOfSerRequested * 
+                    pReqLldCfg->mcaspChanParams->noOfChannels;
+            }
         }
-
-        lldCfg->hMcaspChan = mcaspChanHandle;
-    }
-    else {
-        /* Configure McASP to receive 16/32-bit data according to default configuration */
-        status = mcaspRecfgWordWidth(pInp->hMcaspChan, lldCfg->mcaspChanParams->wordWidth);
-        if(status != Aud_EOK) {
-            return ASIT_ERR_MCASP_CFG;
+        else
+        {
+            //
+            // Requested device is InNone
+            //
+            pInp->hMcaspChan = NULL;    // reset active McASP LLD handle
+            pInp->pRxParams = NULL;     // reset pointer to active D10 parameters
         }
+        
+        // indicate SIO update request processed
+        pAstCfg->xInp[zMD].inpBufStatus.sioSelect = interface | 0x80;
     }
 
-    pInp->pRxParams = pQ->devinp->x[interface];
-    pInp->hMcaspChan = lldCfg->hMcaspChan;
-    pInp->stride     = lldCfg->mcaspChanParams->noOfSerRequested * lldCfg->mcaspChanParams->noOfChannels;
+    if (pInp->hMcaspChan != NULL)       // non NULL indicates there's an active interface
+    {
+        if (pInp->pRxParams != NULL)    // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
+        {
+            pInPrms = (const PAF_SIO_Params *)pInp->pRxParams;
+            pLldCfg = (mcaspLLDconfig *)pInPrms->sio.pConfig;   // get currently active McASP LLD configuration
+            if (pLldCfg != NULL)        // sanity check, this should be non NULL if pInp->hMcaspChan is non NULL
+            {
+                // Configure McASP to receive 16/32-bit data according to default configuration
+                mcaspRecfgWordWidth(pInp->hMcaspChan, pLldCfg->mcaspChanParams->wordWidth);
+                
+                // Set flag to swap HDMI data if it is 4xI2S and word length is 16
+                if ((pLldCfg->mcaspChanParams->wordWidth == Mcasp_WordLength_16) &&
+                    (pLldCfg->mcaspChanParams->noOfSerRequested == 4)) 
+                {
+                    pInp->swapData = TRUE;
+                }
+                else 
+                {
+                    pInp->swapData = FALSE;
+                }
+            }
+            else
+            {
+                // This is a programming error
+                SW_BREAKPOINT;  // debug
+            }
 
-    /* Set flag to swap HDMI data if it is 4xI2S and word length is 16 */
-    if(   (lldCfg->mcaspChanParams->wordWidth == Mcasp_WordLength_16)
-        &&(lldCfg->mcaspChanParams->noOfSerRequested == 4)
-      ) {
-        pInp->swapData = TRUE;
-    }
-    else {
-        pInp->swapData = FALSE;
+        }
+        else
+        {
+            // This is a programming error
+            SW_BREAKPOINT;  // debug
+        }
     }
-
+    
     return ASIT_NO_ERR;
 }  /* asitSelectDevices */