PASDK-183: Updated IO driver code for driver improvement.
authorChitresh Gupta <chitresh.g@pathpartnertech.com>
Wed, 29 Mar 2017 14:20:29 +0000 (19:50 +0530)
committerChitresh Gupta <chitresh.g@pathpartnertech.com>
Wed, 29 Mar 2017 14:20:29 +0000 (19:50 +0530)
pasdk/test_dsp/mib/mib.c
pasdk/test_dsp/mob/mob.c
pasdk/test_dsp/sap/audio_dc_cfg.c
pasdk/test_dsp/sap/sap.c
pasdk/test_dsp/sap/sap_d10.c
pasdk/test_dsp/sap/sap_mcasp.c
psdk_cust/pdk_k2g_1_0_1_0_eng/packages/ti/platform/evmk2g/platform_lib/src/platform_audio.c

index c36e2e6b91ff947b3d39a456e6bd028422f3c1c7..f3646902b1821d6fac821835e249c446b4fd6ab1 100644 (file)
@@ -353,10 +353,11 @@ Int DIB_issue (DEV2_Handle device)
     if (!pBufConfig || !pBufConfig->pBufStatus)
         return SIO2_EINVAL;
 
-    Queue_put (device->fromdevice, srcFrame);
+    Queue_put (device->fromdevice, (Queue_Elem *)srcFrame);
 
+//GJ: PAF_SIO_REQUEST_AUTO, Not Supported, yet.
     if (srcFrame->arg == PAF_SIO_REQUEST_AUTO) {
-
+#if 0
         // if not yet running, prime input buffer
         if (pDevExt->syncState == SYNC_NONE) {
 
@@ -387,6 +388,7 @@ Int DIB_issue (DEV2_Handle device)
         status = DIB_FTABLE_issueChild (device, &pDevExt->bufConfig, pDevExt->autoRequestSize, 0);
         if (status)
             return status;
+#endif
     }
     else if (srcFrame->arg == PAF_SIO_REQUEST_NEWFRAME) {
 
@@ -408,7 +410,8 @@ Int DIB_issue (DEV2_Handle device)
 // Although interface allows for arbitrary BufConfigs we only support 1 -- so
 // we can assume the one on the fromdevice is the one we want
 
-extern int gIsrCnt; // GJ Debug
+extern int gIsrInputCnt; // GJ Debug
+extern int gIsrOutputCnt; // GJ Debug
 
 Int DIB_reclaim (DEV2_Handle device)
 {
@@ -438,7 +441,8 @@ Int DIB_reclaim (DEV2_Handle device)
     // .........................................................................
 
     if (dstFrame->arg == PAF_SIO_REQUEST_AUTO) {
-
+//GJ: PAF_SIO_REQUEST_AUTO - not supported, yet.
+#if 0
         Log_info0("DIB: At case = PAF_SIO_REQUEST_AUTO"); // GJ Debug
 
         // verify set up by prior DIB_issue()
@@ -499,6 +503,8 @@ Int DIB_reclaim (DEV2_Handle device)
             if (status)
                 return status;
         }
+
+#endif
     } //dstFrame->arg == PAF_SIO_REQUEST_AUTO
 
     // .........................................................................
@@ -640,7 +646,7 @@ Int DIB_reclaim (DEV2_Handle device)
         // since, at least for THD, it is needed by decoders.
         *pBufConfig = pDevExt->bufConfig;
         pBufConfig->lengthofData -= pDevExt->headerSize;
-        Log_info3("DIB_reclaim.%d lengthofData = %d; ISRCNT=%d", __LINE__, pBufConfig->lengthofData, gIsrCnt); // GJ Debug
+        Log_info4("DIB_reclaim.%d lengthofData = %d; InISRCNT=%d; OutISRCNT=%d", __LINE__, pBufConfig->lengthofData, gIsrInputCnt, gIsrInputCnt); // GJ Debug
         //TRACE((&TR_MOD, "DIB_reclaim.%d lengthofData = %d\n", __LINE__, pBufConfig->lengthofData));
 
         // HACK: for DSD the frameLength needs to be the number of samples to generate.
@@ -691,7 +697,7 @@ Int DIB_reclaim (DEV2_Handle device)
 
     // .........................................................................
 
-    Log_info3("DIB_reclaim.%d exit status = %d, ISRCNT = %d", __LINE__, status, gIsrCnt); // GJ Debug
+    Log_info4("DIB_reclaim.%d exit status = %d, InISRCNT = %d OutISRCNT = %d", __LINE__, status, gIsrInputCnt, gIsrOutputCnt); // GJ Debug
     //TRACE((&TR_MOD, "DIB_reclaim.%d exit status = %d\n", __LINE__, status));
 
     return status;
@@ -794,7 +800,7 @@ Int DIB_idle (DEV2_Handle device, Bool flush)
         Queue_enqueue (device->fromdevice, Queue_dequeue (device->todevice));
 
     while (!Queue_empty (device->fromdevice))
-        Queue_enqueue (&((SIO2_Handle) device)->framelist, Queue_dequeue (device->fromdevice));
+        Queue_enqueue (Queue_handle(&((SIO2_Handle) device)->framelist), Queue_dequeue (device->fromdevice));
 
     status = DIB_FTABLE_reset (device, NULL);
     if (status)
@@ -864,7 +870,7 @@ Int DIB_open (DEV2_Handle device, String name)
         frame = DEV2_mkframe (0, 0, 0);
         if (!frame)
             return SYS_EALLOC;
-        Queue_put (&((SIO2_Handle)pChild)->framelist, frame);
+        Queue_put (Queue_handle(&((SIO2_Handle)pChild)->framelist), (Queue_Elem *) frame);
     }
 
     // open underlying device
@@ -970,11 +976,12 @@ Int DIB_getSync (DEV2_Handle device, PAF_InpBufConfig *pBufConfig )
             if (status)
                 return status;
 
+
             // get next block of data to scan
             status = DIB_FTABLE_waitForData (device, pBufConfig, syncBufSize);
             if (status)
                 return status;
-
+            
             // this function updates the tail pointer
             status = DIB_FTABLE_syncScan (device, pBufConfig, &timeout);
             if (status)
@@ -1048,7 +1055,7 @@ Int DIB_getSync (DEV2_Handle device, PAF_InpBufConfig *pBufConfig )
     // syncScan makes this assumption in order to perform an efficient scan.
     {
         int sizeofStride = pBufConfig->sizeofElement*pBufConfig->stride*pDevExt->pcmFrameLength;
-        pBufConfig->sizeofBuffer = pBufConfig->allocation/sizeofStride*sizeofStride;
+        pBufConfig->sizeofBuffer = (pBufConfig->allocation)/sizeofStride*sizeofStride;
     }
 
     if (pDevExt->sourceSelect == PAF_SOURCE_DSD1 || pDevExt->sourceSelect == PAF_SOURCE_DSD2 ||
@@ -1079,6 +1086,7 @@ Int DIB_getSync (DEV2_Handle device, PAF_InpBufConfig *pBufConfig )
 
 // -----------------------------------------------------------------------------
 
+int gWrapCtr=0;
 Int DIB_issueChild (DEV2_Handle device, PAF_InpBufConfig  *pBufConfig, int size, int forTotal)
 {
     DIB_DeviceExtension   *pDevExt = (DIB_DeviceExtension *) device->object;
@@ -1113,7 +1121,7 @@ Int DIB_issueChild (DEV2_Handle device, PAF_InpBufConfig  *pBufConfig, int size,
         size = (size + 7) & ~0x7;
 
     // convert to bytes
-    size = (size * pBufConfig->sizeofElement); //To Do: +2 GJ : Temporary, to get past initial hiccup.  // GJ Debug
+    size *= pBufConfig->sizeofElement;
     //size *= 4;
 
     // if request crosses circular buffer boundary then split into two requests
@@ -1138,19 +1146,26 @@ Int DIB_issueChild (DEV2_Handle device, PAF_InpBufConfig  *pBufConfig, int size,
 
     for (i=0; i < 2; i++) {
         if (sizes[i]) {
-            dstFrame = Queue_get (&((SIO2_Handle) pChild)->framelist);
+            dstFrame = Queue_get (Queue_handle(&((SIO2_Handle) pChild)->framelist));
             if (dstFrame == (DEV2_Frame *)&((SIO2_Handle) pChild)->framelist)
                 return DIBERR_UNSPECIFIED;
             dstFrame->arg = (Arg) pBufConfig;
 
             dstFrame->addr = pBufConfig->futureHead.pVoid;
             dstFrame->size = sizes[i];
-            Queue_put (pChild->todevice, dstFrame);
+            Queue_put (pChild->todevice, (Queue_Elem *)dstFrame);
             status = DEV2_issue (pChild);
             if (status)
                 return DIBERR_UNSPECIFIED;
 
             pBufConfig->futureHead.pVoid = endAddr[i];
+            // GJ Debug
+            if (i==1)
+            {
+               gWrapCtr++;
+               Log_info4("DIB: Inside DIB_issueChild Wrap Around Point #%d, with Future Head: 0x%x, current addr: 0x%x, current size: %d", gWrapCtr, pBufConfig->futureHead.pVoid, dstFrame->addr, dstFrame->size ); // GJ Debug
+
+            }
         }
     }
 
@@ -1181,7 +1196,7 @@ Int DIB_reclaimChild (DEV2_Handle device, PAF_InpBufConfig *pBufConfig)
     srcFrame = Queue_get (pChild->fromdevice);
     //Log_info2("DIB_reclaimChild.%d calling Queue_put(), srcFrame = 0x%x", __LINE__, srcFrame); // GJ Debug
     //TRACE((&TR_MOD, "DIB_reclaimChild.%d calling Queue_put(), srcFrame = 0x%x\n", __LINE__, srcFrame));
-    Queue_put (&((SIO2_Handle) pChild)->framelist, srcFrame);
+    Queue_put (Queue_handle(&((SIO2_Handle) pChild)->framelist), (Queue_Elem *)srcFrame);
 
     // Only for non-fill requests do we update ptrs
     if (srcFrame->addr != NULL) {
@@ -1333,7 +1348,7 @@ Int DIB_reset (DEV2_Handle device, PAF_InpBufConfig *pBufConfig)
 
         // compute and use *effective buffer size*
         sizeofStride = pBufConfig->sizeofElement*pBufConfig->stride;
-        pBufConfig->sizeofBuffer = pBufConfig->allocation/sizeofStride*sizeofStride;
+        pBufConfig->sizeofBuffer = (pBufConfig->allocation)/sizeofStride*sizeofStride; //GJ: Debug - Account for EDMA padding
 
         //hack -- save status context for use in close
         pDevExt->pInpBufStatus = pBufConfig->pBufStatus;
@@ -1417,7 +1432,7 @@ Int DIB_syncScan (DEV2_Handle device, PAF_InpBufConfig *pBufConfig, XDAS_UInt32
     scanState = pDevExt->scanState;
     pSync     = pDevExt->pSync.pMdInt;
 
-    Log_info3("DIB: Entered DIB_syncScan with zeroCount = %d & scanState = %d, pSync = 0x%x", zeroCount, scanState, pSync); // GJ Debug
+    Log_info4("DIB: Entered DIB_syncScan with zeroCount = %d & scanState = %d, stride = %d, pSync = 0x%x", zeroCount, scanState, stride, pSync); // GJ Debug
 
     // scan until out of available data or a sync found
     for (i=0; i < numLeft; i++) {
index aa1eca1e8bd50a440c94aa7c0b79198ce746f6a1..184a23d61dc77239f607f4dca992159baba5739d 100644 (file)
@@ -168,6 +168,14 @@ Int DOB_close (DEV2_Handle device)
     return (SIO2_EBADIO);
 } // DOB_close
 
+// GJ Debug Counters
+Uint32 gMobStart_Idle=0;
+Uint32 gMobIdle_ClocksElse=0;
+Uint32 gMobIdle_ClocksIf=0;
+Uint32 gMobOutRateX_Cnt=0;
+Uint32 gMobStart_Open=0;
+Uint32 gMobStart_Clocks=0;
+Uint32 gMobRateXChanged=0;
 // -----------------------------------------------------------------------------
 
 Int DOB_ctrl (DEV2_Handle  device, Uns code, Arg arg)
@@ -191,6 +199,7 @@ Int DOB_ctrl (DEV2_Handle  device, Uns code, Arg arg)
                     return status;
 
                 status = DOB_FTABLE_startClocks (device);
+                gMobStart_Idle++;
             }
             break;
 
@@ -198,6 +207,7 @@ Int DOB_ctrl (DEV2_Handle  device, Uns code, Arg arg)
             //TODO: check that we are idle?
             pDevExt->rateX = 1.;            
             status = DEV2_ctrl (pChild, code, arg);
+            gMobStart_Open++;
             if (status)
                 return status;
             break;
@@ -207,8 +217,11 @@ Int DOB_ctrl (DEV2_Handle  device, Uns code, Arg arg)
             float rateX = *(float *)arg;
             int errno = SYS_OK;
 
+            gMobOutRateX_Cnt++;
+
             if (pDevExt->rateX != rateX) {
-                status = DEV2_idle (device,0);
+               status = DEV2_idle (device,0);
+               gMobRateXChanged++;
                 if (status)
                     return status;
                 errno = DOBERR_RATECHANGE;
@@ -234,6 +247,7 @@ Int DOB_ctrl (DEV2_Handle  device, Uns code, Arg arg)
             if (arg) {
                 // flush data (and keep clocks)
                 DOB_FTABLE_shutdown (device);
+                gMobIdle_ClocksIf++;
                 status = DEV2_ctrl (pChild, PAF_SIO_CONTROL_IDLE_WITH_CLOCKS, arg);
                 if (!status)
                     pDevExt->state = DOB_STATE_CLOCKING;
@@ -242,6 +256,7 @@ Int DOB_ctrl (DEV2_Handle  device, Uns code, Arg arg)
                 // truncate data (stops clocks)
                 DEV2_idle (device, 0);
                 status = DEV2_ctrl (pChild, code, arg);
+                gMobIdle_ClocksElse++;
             }
             break;
 
@@ -301,7 +316,7 @@ Int DOB_idle (DEV2_Handle device, Bool flush)
     return status;
 } // DOB_idle
 
-static Queue_Handle dobFrameQue;
+static Queue_Struct dobFrameQue;
 
 // -----------------------------------------------------------------------------
 // This function is called before main and hence no devices yet running.
@@ -315,9 +330,10 @@ Void DOB_init (Void)
 
        Error_init(&eb);
 
-    dobFrameQue = Queue_create (NULL, &eb);
-    if (!dobFrameQue) {
-        Log_info1 ("DOB_init failed after Queue_create:", SYS_EALLOC);
+    //dobFrameQue = Queue_create (NULL, &eb);
+       Queue_construct (&dobFrameQue, NULL);
+    if (Queue_handle(&dobFrameQue) == NULL) {
+        Log_info1 ("DOB_init failed after Queue_construct:", SYS_EALLOC);
         return;
     }
 
@@ -344,7 +360,7 @@ Int DOB_issue (DEV2_Handle device)
     if (!pParentFrame->addr)
         return SIO2_EINVAL;
     pBufConfig = (PAF_OutBufConfig *) pParentFrame->addr;
-    Queue_put (device->fromdevice, pParentFrame);
+    Queue_put (device->fromdevice, (Queue_Elem *)pParentFrame);
 
     Log_info0("Still In MOB Issue - 1");
 
@@ -391,7 +407,7 @@ Int DOB_issue (DEV2_Handle device)
         // will be <= this size. Effectively each DEV2_Frame is assigned a unique
         // segment of the buffer. This simplifies bookeeping and limits passing
         // side information between issue and reclaim.
-        pChildFrame = Queue_head (&((SIO2_Handle)pChild)->framelist);
+        pChildFrame = Queue_head (Queue_handle(&((SIO2_Handle)pChild)->framelist));
         for (i=0; i < pDevExt->maxNumBuf; i++) {
             pChildFrame->arg = (Arg) ((int) pBufConfig->pntr.pVoid + i*pBufConfig->sizeofBuffer/pDevExt->maxNumBuf);
             pChildFrame = Queue_next ((Queue_Elem *) pChildFrame);
@@ -416,7 +432,7 @@ Int DOB_issue (DEV2_Handle device)
         return DOB_FTABLE_issueIEC (device, pBufConfig);
 
     for (i=0; i < numXfers; i++) {
-        pChildFrame = Queue_get (&((SIO2_Handle)pChild)->framelist);
+        pChildFrame = Queue_get (Queue_handle(&((SIO2_Handle)pChild)->framelist));
         if (pChildFrame == (DEV2_Frame *)&((SIO2_Handle)pChild)->framelist)
             return SIO2_EBADIO;
 
@@ -428,7 +444,7 @@ Int DOB_issue (DEV2_Handle device)
             pChildFrame->addr = (Ptr) pChildFrame->arg; 
         pChildFrame->size = xferSize;
 
-        Queue_put (pChild->todevice, pChildFrame);
+        Queue_put (pChild->todevice, (Queue_Elem *)pChildFrame);
         status = DEV2_issue(pChild);
         if (status != SYS_OK)
             return status;
@@ -471,7 +487,7 @@ Int DOB_issueIEC (DEV2_Handle device, PAF_OutBufConfig  *pBufConfig)
        numBytes = pBufConfig->head.pSmInt - pBufConfig->pntr.pSmInt;
 
 
-        pChildFrame = Queue_get (&((SIO2_Handle)pChild)->framelist);
+        pChildFrame = Queue_get (Queue_handle(&((SIO2_Handle)pChild)->framelist));
         if (pChildFrame == (DEV2_Frame *)&((SIO2_Handle)pChild)->framelist)
             return SIO2_EBADIO;
 
@@ -512,7 +528,7 @@ Int DOB_issueIEC (DEV2_Handle device, PAF_OutBufConfig  *pBufConfig)
             pChildFrame->addr = NULL; // send zero data
         }
 
-        Queue_put (pChild->todevice, pChildFrame);
+        Queue_put (pChild->todevice, (Queue_Elem *)pChildFrame);
         status = DEV2_issue(pChild);
         if (status != SYS_OK)
             return status;
@@ -521,14 +537,14 @@ Int DOB_issueIEC (DEV2_Handle device, PAF_OutBufConfig  *pBufConfig)
     else {
         // when kick-started send nbufs of zeroes
         for (i=0; i < pChild->nbufs; i++) {
-            pChildFrame = Queue_get (&((SIO2_Handle)pChild)->framelist);
+            pChildFrame = Queue_get (Queue_handle(&((SIO2_Handle)pChild)->framelist));
             if (pChildFrame == (DEV2_Frame *)&((SIO2_Handle)pChild)->framelist)
                 return SIO2_EBADIO;
 
             pChildFrame->size = xferSize;
             pChildFrame->addr = NULL; // send zero data
 
-            Queue_put (pChild->todevice, pChildFrame);
+            Queue_put (pChild->todevice, (Queue_Elem *)pChildFrame);
             status = DEV2_issue(pChild);
             if (status != SYS_OK)
                 return status;
@@ -641,7 +657,7 @@ Int DOB_reclaim (DEV2_Handle device)
         return DOBERR_NOTRUNNING;
 
     // if no available frames then wait for one to free o/w pull one from queue
-    if (Queue_empty (&((SIO2_Handle)pChild)->framelist)) {
+    if (Queue_empty (Queue_handle(&((SIO2_Handle)pChild)->framelist))) {
         status = DEV2_reclaim (pChild);
         if (status != SYS_OK)
             return status;
@@ -649,11 +665,11 @@ Int DOB_reclaim (DEV2_Handle device)
 
         // place frame at end of queue to be used later by issue
         // since queue was empty this will place it on the head of the queue
-        Queue_put (&((SIO2_Handle)pChild)->framelist, pChildFrame);
+        Queue_put (Queue_handle(&((SIO2_Handle)pChild)->framelist), (Queue_Elem *)pChildFrame);
     }
     else
         // since queue is not empty then get head of queue which will be the next one used by issue
-        pChildFrame = Queue_head (&((SIO2_Handle)pChild)->framelist);
+        pChildFrame = Queue_head (Queue_handle(&((SIO2_Handle)pChild)->framelist));
 
     // if in IEC mode then don't update ptrs (this is done by issueIEC),
     // otherwise we assume encoder is PCE and we need these updates
@@ -700,7 +716,7 @@ Int DOB_shutdown (DEV2_Handle device)
         Queue_enqueue (device->fromdevice, Queue_dequeue(device->todevice));
 
     while (!Queue_empty(device->fromdevice))
-        Queue_enqueue(&((SIO2_Handle) device)->framelist, Queue_dequeue(device->fromdevice));
+        Queue_enqueue(Queue_handle(&((SIO2_Handle) device)->framelist), Queue_dequeue(device->fromdevice));
 
     return SYS_OK;
 } // DOB_shutdown
@@ -728,7 +744,7 @@ Int DOB_startClocks (DEV2_Handle device)
     //xferSize = numChan * wordSize * 1;
     xferSize = numChan * wordSize * 4; // GJ: Experiment with longer startup transfers
 
-    pChildFrame = Queue_get (&((SIO2_Handle)pChild)->framelist);
+    pChildFrame = Queue_get (Queue_handle(&((SIO2_Handle)pChild)->framelist));
     if (pChildFrame == (DEV2_Frame *)&((SIO2_Handle)pChild)->framelist)
         return SIO2_EBADIO;
 
@@ -736,7 +752,7 @@ Int DOB_startClocks (DEV2_Handle device)
     pChildFrame->arg = NULL;
     pChildFrame->size = xferSize;
 
-    Queue_put (pChild->todevice, pChildFrame);
+    Queue_put (pChild->todevice, (Queue_Elem *)pChildFrame);
     status = DEV2_issue (pChild);
     if (status != SYS_OK)
         return status;
@@ -752,6 +768,9 @@ Int DOB_startClocks (DEV2_Handle device)
 
     pDevExt->state = DOB_STATE_CLOCKING;
 
+    gMobStart_Clocks++;
+    Log_info0("Leaving DOB_startClocks with DOB_STATE_CLOCKING");
+
     return status;
 } // DOB_startClocks
 
@@ -761,7 +780,7 @@ Int DOB_reallocFrames (DEV2_Handle device)
 {
     DOB_DeviceExtension   *pDevExt   = (DOB_DeviceExtension *)device->object;
     DEV2_Handle             pChild    = (DEV2_Handle)&pDevExt->child;
-    Queue_Handle            pChildQue = &((SIO2_Handle)pChild)->framelist;
+    Queue_Handle            pChildQue = Queue_handle(&((SIO2_Handle)pChild)->framelist);
     DEV2_Frame             *pFrame;
     Int                    i;
 
@@ -769,17 +788,17 @@ Int DOB_reallocFrames (DEV2_Handle device)
     // first pull off any frames from the child frame queue and place in holder
     while (!Queue_empty (pChildQue)) {
        pFrame = (DEV2_Frame *) Queue_get (pChildQue);
-       Queue_put (dobFrameQue, (Queue_Elem *) pFrame);
+       Queue_put (Queue_handle(&dobFrameQue), (Queue_Elem *) pFrame);
     }
 
     // next pull frames from holder and place onto child queue. If there aren't
     // enough in the holder then allocate from memory. We only support
     // ISSUERECLAIM mode so size = 0
     for (i=0; i < pDevExt->maxNumBuf; i++) {
-        if (Queue_empty (dobFrameQue))
+        if (Queue_empty (Queue_handle(&dobFrameQue)))
             pFrame = DEV2_mkframe (0, 0, 0); 
         else
-            pFrame = (DEV2_Frame *) Queue_get (dobFrameQue);
+            pFrame = (DEV2_Frame *) Queue_get (Queue_handle(&dobFrameQue));
 
         if (!pFrame)
             return SYS_EALLOC;            
index fe6cb457f3db694aa1536183a4e4731263ef046a..2e167a96e5b8c317c7d0e33ece66d58bad58f990 100644 (file)
@@ -44,12 +44,20 @@ All rights reserved.
 #include "vproccmds_a.h"
 #include <stdarg.h>
 #include "string.h"
+#include <xdc/runtime/Log.h>
 
 Platform_STATUS audioHDMIConfig(void);
 
 #define HSR4_I2C_ADDR 0x5D
 #define        HSR4_I2C_PORT_NUM I2C_PORT_1
 
+Int16 DA10x_I2C_init();
+Int16 DA10x_I2C_close();
+void DA10x_waitusec( Uint32);
+Int16 DA10x_I2C_reset();
+Int16 DA10x_I2C_write( Uint16, Uint8*, Uint16);
+Int16 DA10x_I2C_read( Uint16, Uint8*, Uint16);
+
 /* ------------------------------------------------------------------------ *
  *  Prototypes                                                              *
  * ------------------------------------------------------------------------ */
@@ -274,7 +282,7 @@ Platform_STATUS audioDirConfig(void)
                }
 
                IFPRINT(platform_write("audioDirConfig : Waiting for DIR to Enter PLL Mode...\n"));
-               platform_delay(1000);
+               platform_delay(10);
                timeout--;
        }
 
@@ -318,6 +326,8 @@ void  hdmi128();
 
 
 int gret_val=0;
+int gI2cWrite_errCnt=0;
+
 int alpha_i2c_write(unsigned short var1, ...)
 {
        unsigned short alpha_type,length,temp_var;
@@ -371,11 +381,37 @@ int alpha_i2c_write(unsigned short var1, ...)
        }
 va_end(argp);
 
+#define DA10x_I2C      1
 
+#ifdef DA10x_I2C
+do
+{
+       ret_val = DA10x_I2C_write(HSR4_I2C_ADDR, cmd, cmd[0]+1);
+
+       if(ret_val !=I2C_RET_OK)
+       {
+               gret_val++;
+               gI2cWrite_errCnt++;
+               DA10x_I2C_reset();
+       }
+}while(ret_val !=I2C_RET_OK);
+
+#else
+do
+{
+//     ret_val = DA10x_I2C_write(HSR4_I2C_ADDR, cmd, cmd[0]+1);
+       ret_val = i2cWrite(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR, cmd, cmd[0]+1, I2C_RELEASE_BUS);
+       if(ret_val !=I2C_RET_OK)
+       {
+               gret_val++;
+               gI2cWrite_errCnt++;
+               i2cConfig(HSR4_I2C_PORT_NUM);
+       }
+}while(ret_val !=I2C_RET_OK);
 ret_val = i2cWrite(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR, cmd, cmd[0]+1, I2C_RELEASE_BUS);
 if(ret_val !=I2C_RET_OK)
                gret_val++;
-
+#endif
 
 return ret_val;
 }
@@ -383,33 +419,36 @@ return ret_val;
 void set_audio_desc(unsigned char var1,unsigned char var2,unsigned char var3,unsigned char var4,unsigned char var5)
 {
        int ret_val=I2C_RET_OK;
-       do{ret_val=alpha_i2c_write(HSDIO_EDID_AUDIO_DESC_FORMAT(var1, var2));}while (ret_val !=I2C_RET_OK);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_EDID_AUDIO_DESC_NUM_CHANNELS(var1, var3));}while (ret_val !=I2C_RET_OK);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_EDID_AUDIO_DESC_SAMPLE_RATES(var1, var4));}while (ret_val !=I2C_RET_OK);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_EDID_AUDIO_DESC_MISC(var1, var5));}while (ret_val !=I2C_RET_OK);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_ALERT(HSDIO_ALERT_INPUT_AUDIO_CHANGE_msk));}while (ret_val !=I2C_RET_OK);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_ALERT(HSDIO_ALERT_INPUT_AUDIO_MUTE_msk));}while (ret_val !=I2C_RET_OK);
-       platform_delay(1000);
+
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_EDID_AUDIO_DESC_FORMAT(var1, var2));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_EDID_AUDIO_DESC_NUM_CHANNELS(var1, var3));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_EDID_AUDIO_DESC_SAMPLE_RATES(var1, var4));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_EDID_AUDIO_DESC_MISC(var1, var5));}while (ret_val !=I2C_RET_OK);
 }
 
+int gI2Ccnt=0;
+
+// Program HDMI CEA / EDID values, as necessary.
 void hrptredid()
 {
        int ret_val=I2C_RET_OK;
 
-       do{
-               platform_delay(1000);
+       /*do{
+               platform_delay(10);
                ret_val=alpha_i2c_write(HSDIO_EDID_SPEAKER_ALLOCATION_BLOCK(0xFF));
         if (ret_val !=I2C_RET_OK)
-            i2cConfig(HSR4_I2C_PORT_NUM);        
+        {
+               gI2Ccnt++;
+#ifdef DA10x_I2C
+               DA10x_I2C_reset();
+#else
+               i2cConfig(HSR4_I2C_PORT_NUM);
+#endif
+        }
             
-       }while (ret_val !=I2C_RET_OK);
-
-       platform_delay(1000);
+       }while (ret_val !=I2C_RET_OK); */
+       do{ret_val=alpha_i2c_write(HSDIO_EDID_SPEAKER_ALLOCATION_BLOCK(0xFF));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);
        do{ret_val=alpha_i2c_write(HSDIO_EDID_SPEAKER_ALLOCATION_BLOCK_2(0x7));}while (ret_val !=I2C_RET_OK);
 
        set_audio_desc(0,1,2,0x7f,7);   // PCM 2 channel, 32kHz, 44.1kHz, 48kHz, 88.2kHz, 96kHz, 176.4 KHz, 192 KHz, 16bit, 20bit, 24bit
@@ -423,14 +462,9 @@ void hrptredid()
        set_audio_desc(7,11,8,0x7F,3);  // DTS-HD, 8 channel, 32kHz, 44.1kHz, 48kHz, 88.2kHz, 96kHz, 176.4kHz, 192kHz,
                                                                        // last byte is 3 for DTS:X, 1 otherwise.
        set_audio_desc(8,11,8,0x7F,1);  // DTS-HD, 8 channel - same as above, but last byte = 1
-
-//     set_audio_desc(5,0,0,0,0);      //AAC LC (5,6,6,0x1f,192);
-//     set_audio_desc(6,0,0,0,0);
-//     set_audio_desc(7,0,0,0,0);
-//     set_audio_desc(8,0,0,0,0);      // DTS-HD (8,11,8,0x7F,1)
        set_audio_desc(9,0,0,0,0);
        set_audio_desc(10,0,0,0,0);
-       set_audio_desc(11,0,0,0,0);
+       set_audio_desc(11,0,0,0,0); //AAC LC (5,6,6,0x1f,192);
        set_audio_desc(12,0,0,0,0);
        set_audio_desc(13,0,0,0,0);
        set_audio_desc(14,0,0,0,0);
@@ -439,59 +473,119 @@ void hrptredid()
        set_audio_desc(17,0,0,0,0);
        set_audio_desc(18,0,0,0,0);
        set_audio_desc(19,0,0,0,0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_EDID_GO);}while (ret_val !=0);
-       //fclose(fp1);
+       platform_delay(10);
+       do{ret_val=alpha_i2c_write(HSDIO_EDID_GO);}while (ret_val !=I2C_RET_OK);
 }
 
+// Configure the HOST port of HSR41 for EXTRACT mode of operation.
+// Note: HDMI Tx/Out Port's state is not cared for, at all.
 void  hdmi128()
 {
-               int ret_val=0;
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_MCLK_TO_HOST(HSDIO_AudioMClk_128X));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_FORMAT_TO_HOST(HSDIO_AudioFmt_I2S));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_IMPLEMENT_AUDIO_TO_HOST_CMDS);}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_PRESENT(HSDIO_AudioPresent_HAS_NO_AUDIO));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_FORMAT(HSDIO_AudioFmt_I2S));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_SAMPLE_SIZE(HSDIO_AudioSampleSize_32));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_FREQ(HSDIO_AudioFreq_48K));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_LAYOUT(HSDIO_AudioLayout_2));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_MCLK(HSDIO_AudioMClk_AUTO));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_AUX_CHANNEL_CNT(1));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_AUX_SPEAKER_MAPPING(0));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_CHSTS_PCM_PREEMPHASIS(HSDIO_CSFormatInfo_PCM_NO_PRE));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_CHSTS_COPYRIGHT(HSDIO_CSCopyright_PROTECTED));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_CHSTS_WORD_LENGTH(HSDIO_CSWordLength_24));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_OUTPUT_GO);}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_AUDIO_ROUTING(HSDIO_AudioRouting_HSDIOIN_HOSTOUT));}while (ret_val !=0);
-       platform_delay(1000);
-       do{ret_val=alpha_i2c_write(HSDIO_SYS_CFG_GO);}while (ret_val !=0);
+       int ret_val=I2C_RET_OK;
+
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_ALERT(HSDIO_ALERT_INPUT_AUDIO_CHANGE_msk));}while (ret_val !=I2C_RET_OK);
+       //platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_ALERT(HSDIO_ALERT_INPUT_AUDIO_MUTE_msk));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_AUDIO_MCLK_TO_HOST(HSDIO_AudioMClk_128X));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_AUDIO_UNMUTE_DELAY_TO_HOST(HSDIO_AudioUnMuteDelay_NO_DELAY));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_AUDIO_FORMAT_TO_HOST(HSDIO_AudioFmt_I2S));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_IMPLEMENT_AUDIO_TO_HOST_CMDS);}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_AUDIO_ROUTING(HSDIO_AudioRouting_HSDIOIN_NOOUT));}while (ret_val !=I2C_RET_OK);
+       platform_delay(10);do{ret_val=alpha_i2c_write(HSDIO_SYS_CFG_GO);}while (ret_val !=I2C_RET_OK);
 }
 
-Platform_STATUS audioHDMIConfig(void)
+//
+// Fetch Video Sync Status from HSR41
+unsigned int read_hdmi_videosyncstatus()
 {
-       Platform_STATUS status = 0;
+       unsigned char data[50];
+       Uint8 length;
+       int ret_val=0;
 
-       hrptredid();
+       ret_val=alpha_i2c_write(HSDIO_INPUT_SYNC_STS);
+#ifdef DA10x_I2C
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&length,1);
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&data[0],length);
+#else
+       if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&length,0,1,1);
+       if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&data[0],0,1,length);
+#endif
+       if(!ret_val) ret_val= data[2]; // 1-byte / indicates error status
 
-       hdmi128();
+       return ret_val;
+}
 
-       return (status);
+//
+// Fetch Audio Present Status from HSR41
+unsigned int read_hdmi_audiostatus()
+{
+       unsigned char data[50];
+       Uint8 length;
+       int ret_val=0;
+
+       ret_val=alpha_i2c_write(HSDIO_AUDIO_INPUT_PRESENT_STS);
+#ifdef DA10x_I2C
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&length,1);
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&data[0],length);
+#else
+       if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&length,0,1,1);
+       if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&data[0],0,1,length);
+#endif
+       if(!ret_val) ret_val= data[2]; // 1-byte / indicates error status
+
+
+       return ret_val;
+}
+
+// Fetch Clock Status from HSR41
+unsigned int read_hdmi_clockstatus()
+{
+       unsigned char data[50];
+       Uint8 length;
+       int ret_val=0;
+
+       ret_val=alpha_i2c_write(HSDIO_GET_AUDIO_MCLK_TO_HOST);
+#ifdef DA10x_I2C
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&length,1);
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&data[0],length);
+#else
+       if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&length,0,1,1);
+       if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&data[0],0,1,length);
+#endif
+       if(!ret_val) ret_val= data[2]; // 1-byte / indicates clock status
+
+       return ret_val;
+}
+
+// Fetch Error Status from HSR41
+unsigned int read_hdmi_errstatus()
+{
+       unsigned char data[50];
+       Uint8 length;
+       int ret_val=0;
+
+       ret_val=alpha_i2c_write(HSDIO_AUDIO_INPUT_ERROR_STS);
+#ifdef DA10x_I2C
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&length,1);
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&data[0],length);
+#else
+       if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&length,0,1,1);
+       if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&data[0],0,1,length);
+#endif
+       if(!ret_val) ret_val= data[2]; // 1-byte / indicates error status
+
+       return ret_val;
+}
+
+void clear_hdmi_hmint()
+{
+       int ret_val=0;
+
+       ret_val=alpha_i2c_write(HSDIO_ALERT_STS); //clear the interrupt on ~HMINT by reading the Alert Status register
+
+       if(ret_val)
+               while(1);               // Control shouldn't be here
+
+       return;
 }
 
 unsigned int read_hdmi_samprate()
@@ -499,20 +593,217 @@ unsigned int read_hdmi_samprate()
        unsigned char data[50];
        Uint8 length;
        int ret_val=7;
-       //int ret_val2=0;
-       int clear_to_read=5;
-
-       clear_to_read=alpha_i2c_write(HSDIO_ALERT_STS); //clear the interrupt on ~HMINT by reading the Alert Status register
 
+       Log_info0("Audio DC CFG: Entered read_hdmi_samprate");
        ret_val=alpha_i2c_write(HSDIO_AUDIO_INPUT_FREQ_STS);
 
+#ifdef DA10x_I2C
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&length,1);
+       if(!ret_val) DA10x_I2C_read(HSR4_I2C_ADDR,&data[0],length);
+#else
        if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&length,0,1,1);
        if(!ret_val) i2cRead(HSR4_I2C_PORT_NUM, HSR4_I2C_ADDR,&data[0],0,1,length);
-       if(!ret_val) ret_val= data[3]; // indicates sample rate
+#endif
+
+       Log_info0("Audio DC CFG: Leaving read_hdmi_samprate");
+
+       if(!ret_val) ret_val= data[2]; // indicates sample rate
        else
        ret_val = 0;
 
        return ret_val;
 }
 
+
+Platform_STATUS audioHDMIConfig(void)
+{
+       Platform_STATUS status = Platform_EOK;
+
+       DA10x_I2C_init();
+
+       hrptredid();
+
+       hdmi128();
+
+       //while((HSDIO_InSync_SYNC_DETECTED != read_hdmi_videosyncstatus()) || (HSDIO_AudioMClk_128X != read_hdmi_clockstatus()));// || (HSDIO_AudioPresent_HAS_AUDIO != read_hdmi_audiostatus()));
+       while((HSDIO_InSync_SYNC_DETECTED != read_hdmi_videosyncstatus()));
+
+       //while((HSDIO_InSync_SYNC_DETECTED != read_hdmi_videosyncstatus()) || (HSDIO_AudioMClk_128X != read_hdmi_clockstatus()));// || (HSDIO_AudioPresent_HAS_AUDIO != read_hdmi_audiostatus()));
+
+       //while((HSDIO_AudioMClk_128X != read_hdmi_clockstatus()) || (HSDIO_AudioErr_NO_ERROR != read_hdmi_errstatus()));
+
+       return (status);
+}
+
+/* ------------------------------------------------------------------------ *
+ *                                                                          *
+ * DA10x_wait( delay )                                                  *
+ *                                                                          *
+ *      Wait in a software loop for 'x' delay                               *
+ *                                                                          *
+ * ------------------------------------------------------------------------ */
+void DA10x_wait( Uint32 delay )
+{
+    volatile Uint32 i;
+    for ( i = 0 ; i < delay ; i++ ){ };
+}
+
+/* ------------------------------------------------------------------------ *
+ *                                                                          *
+ *  DA10x_waitusec( usec )                                               *
+ *                                                                          *
+ *      Wait in a software loop for 'x' microseconds                        *
+ *                                                                          *
+ * ------------------------------------------------------------------------ */
+void DA10x_waitusec( Uint32 usec )
+{
+    DA10x_wait( usec * 3 );
+}
+Int32 i2c_timeout = 0x10000;
+
+/* ------------------------------------------------------------------------ *
+ *                                                                          *
+ *  _I2C_init( )                                                            *
+ *                                                                          *
+ *      Enable and initalize the I2C module                                 *
+ *      The I2C clk is set to run at 400 (384) KHz                          *
+ *                                                                          *
+ * ------------------------------------------------------------------------ */
+Int16 DA10x_I2C_init()
+{
+    I2C_ICMDR   = 0;                // Reset I2C
+    I2C_ICPSC   = 9;               // Prescale to get 10MHz I2C internal
+    I2C_ICCLKL  = 7;               // Config clk LOW for 400kHz
+    I2C_ICCLKH  = 7;               // Config clk HIGH for 400kHz
+    I2C_ICMDR  |= ICMDR_IRS;        // Release I2C from reset
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ *
+ *                                                                          *
+ *  _I2C_close( )                                                           *
+ *                                                                          *
+ * ------------------------------------------------------------------------ */
+Int16 DA10x_I2C_close()
+{
+        I2C_ICMDR = 0;                      // Reset I2C
+        return 0;
+}
+
+/* ------------------------------------------------------------------------ *
+ *                                                                          *
+ *  _I2C_reset( )                                                           *
+ *                                                                          *
+ * ------------------------------------------------------------------------ */
+Int16 DA10x_I2C_reset( )
+{
+    DA10x_I2C_close( );
+    DA10x_I2C_init( );
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ *
+ *                                                                          *
+ *  _I2C_write( i2c_addr, data, len )                                       *
+ *                                                                          *
+ *      I2C write in Master mode                                            *
+ *                                                                          *
+ *      i2c_addr    <- I2C slave address                                    *
+ *      data        <- I2C data ptr                                         *
+ *      len         <- # of bytes to write                                  *
+ *                                                                          *
+ * ------------------------------------------------------------------------ */
+Int16 DA10x_I2C_write( Uint16 i2c_addr, Uint8* data, Uint16 len )
+{
+    Int32 timeout, i;
+    Int32   oldMask;
+
+
+        I2C_ICCNT = len;                    // Set length
+        I2C_ICSAR = i2c_addr;               // Set I2C slave address
+        I2C_ICMDR = ICMDR_STT               // Set for Master Write
+                  | ICMDR_TRX
+                  | ICMDR_MST
+                  | ICMDR_IRS
+                  | ICMDR_FREE;
+
+        DA10x_wait( 10 );                        // Short delay
+
+        for ( i = 0 ; i < len ; i++ )
+        {
+
+            I2C_ICDXR = data[i];            // Write
+
+            timeout = i2c_timeout;
+            do
+            {
+               DA10x_wait( 10);
+                if ( timeout-- < 0  )
+                {
+                    DA10x_I2C_reset( );
+                    return -1;
+                }
+            } while ( ( I2C_ICSTR & ICSTR_ICXRDY ) == 0 );// Wait for Tx Ready
+
+        }
+
+        I2C_ICMDR |= ICMDR_STP;             // Generate STOP
+
+        return 0;
+
+}
+
+/* ------------------------------------------------------------------------ *
+ *                                                                          *
+ *  _I2C_read( i2c_addr, data, len )                                        *
+ *                                                                          *
+ *      I2C read in Master mode                                             *
+ *                                                                          *
+ *      i2c_addr    <- I2C slave address                                    *
+ *      data        <- I2C data ptr                                         *
+ *      len         <- # of bytes to write                                  *
+ *                                                                          *
+ *      Returns:    0: PASS                                                 *
+ *                 -1: FAIL Timeout                                         *
+ *                                                                          *
+ * ------------------------------------------------------------------------ */
+Int16 DA10x_I2C_read( Uint16 i2c_addr, Uint8* data, Uint16 len )
+{
+    Int32 timeout, i;
+
+    I2C_ICCNT = len;                    // Set length
+    I2C_ICSAR = i2c_addr;               // Set I2C slave address
+    I2C_ICMDR = ICMDR_STT               // Set for Master Read
+              | ICMDR_MST
+              | ICMDR_IRS
+              | ICMDR_FREE;
+
+    DA10x_wait( 10 );                        // Short delay
+
+    for ( i = 0 ; i < len ; i++ )
+    {
+        timeout = i2c_timeout;
+
+        /* Wait for Rx Ready */
+        do
+        {
+               DA10x_wait( 10 );
+            if ( timeout-- < 0 )
+            {
+                DA10x_I2C_reset( );
+                return -1;
+            }
+        } while ( ( I2C_ICSTR & ICSTR_ICRRDY ) == 0 );// Wait for Rx Ready
+
+        data[i] = I2C_ICDRR;            // Read
+
+    }
+
+      I2C_ICMDR |= ICMDR_STP;             // Generate STOP
+
+        return 0;
+}
+
+
+
 /* Nothing past this point */
index 0b68afa1a342ca1af495e46f5973ea356be0f93d..aff66f8a17eb23e6de178d11c7061de6f4b3a3e5 100644 (file)
@@ -85,28 +85,34 @@ extern EDMA3_DRV_Handle hEdma0;
 extern EDMA3_DRV_Handle hEdma1;
 
 int gStartError;
-int gIsrCnt;
+int gIsrInputCnt;
+int gIsrOutputCnt;
 int gIsrElseCnt;
-int gIsrErrCnt;
+int gIsrInErrCnt;
+int gIsrOutErrCnt;
 int gIsrRunCnt;
 int gIsrNotRunCnt;
 int gisrOutput;
+int gSAPResetIn;
+int gSAPResetOut;
 
 typedef xdc_Short MdInt;
 
 void swapHdmi(Ptr, int);
 
-#define TEST_MULTICHANNEL
+//#define TEST_MULTICHANNEL
 
 
 #ifdef TEST_MULTICHANNEL
-#define SAP_UNDER_LEN 4
+#define SAP_UNDER_LEN 16
 //#define SAP_UNDER_LEN 1024 // GJ: experiment
 #else
 #define SAP_UNDER_LEN 1024
 #endif
 int sap_UNDER[SAP_UNDER_LEN]; // used for underrun
 int sap_OVER = 0;     // used for overrun
+
+#ifdef DEBUG
 void DJDBG_SAP_EDMA_dumpParams(int tag_place)
 {
        unsigned int *ptrPARAM_BASE = (unsigned int *)0x02704000;
@@ -120,6 +126,7 @@ void DJDBG_SAP_EDMA_dumpParams(int tag_place)
        Log_info5("PARAM0x19b(%d): 0x%x 0x%x 0x%x 0x%x", tag_place, ptrPARAM0x19[4], ptrPARAM0x19[5], ptrPARAM0x19[6], ptrPARAM0x19[7]);
     //Log_info1("TCC0: ERR reg %x", *((unsigned int *)0x02760120)); //DJDBG
 }
+#endif
 // .............................................................................
 // notes:
 //  . add control function to PORT table
@@ -149,7 +156,7 @@ Int  SAP_reclaim(DEV2_Handle);
 Int  SAP_shutdown(DEV2_Handle);
 Int  SAP_start(DEV2_Handle);
 Int  SAP_config(DEV2_Handle device, const SAP_Params *pParams);
-Int  SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, unsigned int addr, unsigned int size);
+Int  SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, XDAS_UInt32 addr, XDAS_UInt32 size);
 Int  SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 parentEdma, XDAS_UInt32 childEdma, DEV2_Frame *pFrame);
 
 // .............................................................................
@@ -473,6 +480,9 @@ Int SAP_ctrl (DEV2_Handle device, Uns code, Arg arg)
     return result;
 } // SAP_ctrl
 
+int gSAPIdleShutdownIn=0;
+int gSAPIdleShutdownOut=0;
+
 // -----------------------------------------------------------------------------
 
 Int SAP_idle (DEV2_Handle device, Bool flush)
@@ -492,6 +502,10 @@ Int SAP_idle (DEV2_Handle device, Bool flush)
 
     // reset serial port -- stop generating sync events
     result = SAP_PORT_FTABLE_reset (device);
+    if(device->mode == DEV2_OUTPUT)
+       gSAPResetOut++;
+    else
+       gSAPResetIn++;
     if (result)
     {
         //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_PORT_FTABLE_reset returned %d.\n", __FUNCTION__, __LINE__, result));
@@ -500,6 +514,11 @@ Int SAP_idle (DEV2_Handle device, Bool flush)
 
     pDevExt->shutDown = 0; // force shutdown to run
     result = SAP_FTABLE_shutdown (device);
+    if(device->mode == DEV2_OUTPUT)
+       gSAPIdleShutdownOut++;
+    else
+       gSAPIdleShutdownIn++;
+
     if (result)
     {
         //TRACE_VERBOSE((&TR_MOD, "%s.%d: SAP_FTABLE_shutdown returned %d.\n", __FUNCTION__, __LINE__, result));
@@ -600,7 +619,7 @@ Int SAP_start (DEV2_Handle device)
 } // SAP_start
 
 int gDmaParamsarray[17][3];
-int gDmaParamsidx=0;
+int gDmaParamsidx=0, gSAPSpecialCase=0;
 // -----------------------------------------------------------------------------
 
 Int SAP_issue (DEV2_Handle device)
@@ -668,8 +687,6 @@ Int SAP_issue (DEV2_Handle device)
     pFrame = Queue_dequeue (device->todevice);
     pParam = (SAP_EDMA_Param *) Queue_dequeue (Queue_handle(&pDevExt->paramQue));
 
-   /* if (pFrame->addr == NULL)
-               SW_BREAKPOINT; */
     if (pParam->hEdmaParam == NULL)
        Log_info0("SAP_issue: hEdma value is NULL");
     // set misc argument to pParam so get enqueue later
@@ -705,10 +722,11 @@ Int SAP_issue (DEV2_Handle device)
 
     // special case enables when not yet started
     if (pDevExt->runState == 0) {
+       gSAPSpecialCase++;
         result = SAP_FTABLE_start (device);
         if (result) {
             //SAP_DMA_FTABLE_unlock (device);
-                 Hwi_enable ();
+                 Hwi_restore (key);
             return result;
         }
     }
@@ -751,16 +769,7 @@ void swapHdmi(Ptr Input, int size)
 
        }
 
-       Log_info3("SAP: Exiting swapHdmi with Frame->Addr: 0x%x, p1->addr: 0x%x, p2->addr: 0x%x ", (MdInt *)Input, p1, p2);
-
-       /**p2++ = 0xF872;
-       *p2++ = 0x4E1F;
-       *p2++ = 0x0016;
-       *p2++ = 0xEFF0;
-       *p2++ = 0x079E;
-       *p2++ = 0x0003;
-       *p2++ = 0x8401;
-       *p2++ = 0x0101; */
+       Log_info3("SAP: Exiting swapHdmi with Frame->Addr: 0x%x, p1->addr: 0x%x, p2->addr: 0x%x ", (xdc_IArg)Input, p1, p2);
 
        return;
 }
@@ -768,7 +777,6 @@ void swapHdmi(Ptr Input, int size)
 Int SAP_reclaim (DEV2_Handle device)
 {
     SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)(device->object);
-    Int result, i, oldMask;
 #ifdef SAP_CACHE_SUPPORT
     DEV2_Frame *pFrame;
 #endif
@@ -819,18 +827,14 @@ Int SAP_reclaim (DEV2_Handle device)
         {
             Cache_inv (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
             Cache_wait();
-               //note: size here is in # of bytes, so incrementing by 4X32b words ( or 8X16b)
-                       //for(i=0; i<(pFrame->size)/(4*4); i+=16)
-                       //{
-                // Hwi_disable commented since it used to affect other interrupts
-                // max HWI disable duration ~1ms observed
-                   //oldMask = Hwi_disable ();
-                               swapHdmi(pFrame->addr, pFrame->size);
-                               //Hwi_restore(oldMask);
-
-                       Cache_wb (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
-                       Cache_wait();
-                       //}
+
+            // max HWI disable duration ~1ms observed
+            //unsigned int key = Hwi_disable ();                    // GJ: Revisit, along with other context protections here.
+            swapHdmi(pFrame->addr, pFrame->size);
+            //Hwi_restore(key);
+
+            Cache_wb (pFrame->addr, pFrame->size, Cache_Type_ALL, 0);
+            Cache_wait();
         }
     }
 
@@ -1075,7 +1079,7 @@ Int SAP_shutdown (DEV2_Handle device)
     SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)(device->object);
     SIO2_Handle stream = (SIO2_Handle) device;
     DEV2_Frame *pFrame;
-    Int result,i;
+    Int i;
     EDMA3_DRV_Handle hEdma;
     //TRACE_GEN((&TR_MOD, "SAP_shutdown.%d (0x%x)", __LINE__, device));
 
@@ -1143,6 +1147,11 @@ Int SAP_shutdown (DEV2_Handle device)
 
 // -----------------------------------------------------------------------------
 int gSapWatchDogThrottle = 0; //DJDBG
+int gSapWatchDogIn =0;
+int gSapWatchDogOut = 0;
+int gSapWatchDogInSemPost = 0;
+int gSapWatchDogOutSemPost = 0;
+
 Void SAP_watchDog (Void)
 {
     DEV2_Handle device;
@@ -1158,12 +1167,13 @@ Void SAP_watchDog (Void)
         return;
     }
 
+    // GJ: Revisit, along with other context protections here.
+    // GJ: Is this architecture ok?
     // protect context
     Task_disable (); // needed since we may call SEM_post
-    // Hwi_disable commented since it used to affect other interrupts
-    // max HWI disable duration ~4ms observed
     //oldMask = Hwi_disable ();
 
+
     //TRACE_VERBOSE((&TR_MOD, "%s.%d: devices loop, numDevices = %d", __FUNCTION__, __LINE__, dapDrv.numDevices));
 
     for (i=0; i < sapDrv.numDevices; i++) {
@@ -1187,6 +1197,11 @@ Void SAP_watchDog (Void)
             // set errorState which will force owner thread
             //   to clean up via SIO_idle()
             pDevExt->errorState = PAF_SIO_ERROR_FATAL;
+            if(device->mode == DEV2_INPUT)
+               gSapWatchDogIn++;
+            else
+                gSapWatchDogOut++;
+
             //TRACE_TERSE((&TR_MOD, "SAP_watchDog.%d, PAF_SIO_ERROR_FATAL: 0x%x", __LINE__, pDevExt->errorState));
            /* if(gSapWatchDogThrottle == 0) //DJDBG
             {
@@ -1196,10 +1211,17 @@ Void SAP_watchDog (Void)
             if(gSapWatchDogThrottle > 10) gSapWatchDogThrottle = 0; */
             // if outstanding pend then post to free owner thead
             if (!Semaphore_pend(pDevExt->sync, 0))
-                Semaphore_post (pDevExt->sync);
+            {
+               if(device->mode == DEV2_INPUT)
+                       gSapWatchDogInSemPost++;
+               else
+                       gSapWatchDogOutSemPost++;
+               Semaphore_post (pDevExt->sync);
+            }
         }
     }
 
+
     // renable interrupts and task manager.
     // If we posted to the semaphore then the TSK_enable call will lead to
     // an immediate task switch to the associated audio thread.
@@ -1225,8 +1247,8 @@ void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context)
 
     device = (DEV2_Handle) context;
     pDevExt = (SAP_DeviceExtension *)(device->object);
-    if (pDevExt->pParams == NULL)
-        return SIO2_EINVAL;
+    //if (pDevExt->pParams == NULL)
+        //return SIO2_EINVAL;
 
     if (pDevExt->pParams->sio.moduleNum == 0)
        hEdma = hEdma0;
@@ -1254,14 +1276,15 @@ void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context)
 
             // decrement count
             pDevExt->numQueued -= 1;
-            gIsrCnt++;
+            //gIsrCnt++;
             if (device->mode == 1)
-               gisrOutput++;
-
+               gIsrOutputCnt++;
+            else
+               gIsrInputCnt++;
             // place frame onto user queue and signal user thread
             Queue_enqueue (device->fromdevice, (Ptr) pFrame);
 
-            Log_info2("Before SEM_post for device: 0x%x gIsrOutput: %d", device->mode, gisrOutput);
+            //Log_info2("Before SEM_post for device: 0x%x gIsrOutput: %d", device->mode, gisrOutput);
             // signal user thread
             Semaphore_post (pDevExt->sync);
 #if 0
@@ -1280,7 +1303,10 @@ void SAP_isrCallback (Uint32 tcc, EDMA3_RM_TccStatus status, Ptr context)
 
         if (!(opt & EDMA3_DRV_OPT_TCINTEN_SET_MASK (1)))
         {
-               gIsrErrCnt++;
+               if (device->mode == 1)
+                       gIsrOutErrCnt++;
+               else
+                       gIsrInErrCnt++;
                pDevExt->errorState = PAF_SIO_ERROR_ERRBUF_XFER;
         }
 
@@ -1325,7 +1351,7 @@ Int SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32
     {
         Log_info0("pFrame has NULL address?");
     }
-    SAP_DMA_FTABLE_setupParam (device, targetEdma, childEdma, pFrame->addr, pFrame->size);
+    SAP_DMA_FTABLE_setupParam (device, targetEdma, childEdma, (XDAS_UInt32) pFrame->addr, pFrame->size);
 
     if (parentEdma != EDMA_HINV)
         EDMA3_DRV_linkChannel (hEdma, parentEdma, targetEdma);
@@ -1339,7 +1365,7 @@ Int SAP_EDMA_setupXfer (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32
 // -----------------------------------------------------------------------------
 // Configure EDMA3 parameter entry
 
-Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, unsigned int addr, unsigned int size)
+Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32 childEdma, XDAS_UInt32 addr, XDAS_UInt32 size)
 {
     SAP_DeviceExtension *pDevExt = (SAP_DeviceExtension *)device->object;
     EDMA3_DRV_Handle           hEdma;
@@ -1353,7 +1379,7 @@ Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32
        else if (pDevExt->pParams->sio.moduleNum == 1 || pDevExt->pParams->sio.moduleNum == 2)
                hEdma = hEdma1;
     MCASP_Handle hPort = sapMcaspDrv.hPort[pDevExt->pParams->sio.moduleNum];
-    volatile Uint32 *base = (volatile Uint32 *)(hPort->baseAddr);
+   // volatile Uint32 *base = (volatile Uint32 *)(hPort->baseAddr);
 
    //Log_info3("%s.%d: Entered SAP_EDMA_setupParam for Target: 0x%x.\n", (xdc_IArg)__FUNCTION__, __LINE__, targetEdma);
 
@@ -1403,7 +1429,7 @@ Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32
             edmaConfig.destAddr = addr;
             edmaConfig.destCIdx  = pDevExt->edmaWordSize * pDevExt->numSers ;
             if(pDevExt->edmaWordSize == 2)
-               edmaConfig.cCnt= (size)/((edmaConfig.aCnt * edmaConfig.bCnt)/2);        // GJ: Account for additional 2-bytes.
+               edmaConfig.cCnt= (size)/((edmaConfig.aCnt * edmaConfig.bCnt)/2);
         }
         else {
                //if(pDevExt->edmaWordSize == 2)
@@ -1420,14 +1446,14 @@ Int SAP_EDMA_setupParam (DEV2_Handle device, XDAS_UInt32 targetEdma, XDAS_UInt32
             edmaConfig.srcBIdx  = pDevExt->edmaWordSize;
             edmaConfig.srcCIdx  = pDevExt->edmaWordSize * pDevExt->numSers ;
             edmaConfig.srcAddr  = addr;
-            Edma3_CacheFlush ((unsigned int) addr, (size+3)/4);
+            //Edma3_CacheFlush ((unsigned int) addr, (size+3)/4);
         }
         else {
             edmaConfig.srcBIdx  = 0;
             edmaConfig.srcAddr  = (unsigned int) &sap_UNDER[0];
 #if 1
             //edmaConfig.cCnt = (SAP_UNDER_LEN * sizeof(int))/(edmaConfig.aCnt * edmaConfig.bCnt); //DJDBG
-            edmaConfig.cCnt = 512; //DJDBG, if underrun have frame of silence
+            edmaConfig.cCnt = SAP_UNDER_LEN; //DJDBG, if underrun have frame of silence
 #endif
         }
     }
index 395c4ae1b57b971a54dccabc85e793b2e43782ae..8e6f0a7da8f05a1256273a9a2018b57bbc65ab32 100644 (file)
@@ -67,7 +67,7 @@ All rights reserved.
 
 #include <sap_d10.h>
 #include <audio_dc_cfg.h>
-
+#include "vproccmds_a.h"
 
 
 // -----------------------------------------------------------------------------
@@ -156,7 +156,7 @@ static const unsigned char clkxDivHDMI[PAF_SAMPLERATE_N] =
     0x2,  //PAF_SAMPLERATE_44100HZ
     0x2,  //PAF_SAMPLERATE_48000HZ
     0x4,  //PAF_SAMPLERATE_88200HZ
-    0x4,  //PAF_SAMPLERATE_96000HZ
+    0x1, // Chitresh since framelength is 256 at both 0x4,  //PAF_SAMPLERATE_96000HZ
     0x2,  //PAF_SAMPLERATE_192000HZ
     0x4,  //PAF_SAMPLERATE_64000HZ
     0x2,  //PAF_SAMPLERATE_128000HZ
@@ -323,7 +323,7 @@ static const MCASP_ConfigXmt txConfigDAC =
         MCASP_ACLKXCTL_CLKXP_FALLING,
         MCASP_ACLKXCTL_ASYNC_ASYNC,
         MCASP_ACLKXCTL_CLKXM_INTERNAL,
-               MCASP_ACLKXCTL_CLKXDIV_OF(1)),
+               MCASP_ACLKXCTL_CLKXDIV_DEFAULT),
     MCASP_AHCLKXCTL_RMK(
         MCASP_AHCLKXCTL_HCLKXM_EXTERNAL,
         MCASP_AHCLKXCTL_HCLKXP_FALLING,
@@ -393,6 +393,7 @@ static const MCASP_ConfigXmt txConfigDIT =
     MCASP_XCLKCHK_DEFAULT
 };
 
+#if 0
 static const MCASP_ConfigXmt txConfigDIT_16bit =
 {
     MCASP_XMASK_OF(0x0000FFFF),
@@ -422,6 +423,7 @@ static const MCASP_ConfigXmt txConfigDIT_16bit =
     MCASP_XINTCTL_DEFAULT,
     MCASP_XCLKCHK_DEFAULT
 };
+#endif
 
 // -----------------------------------------------------------------------------
 // DAP Input Parameter Definitions
@@ -574,7 +576,7 @@ const SAP_D10_Tx_Params SAP_D10_TX_DAC =
     24,                                         // precision (in bits)
     D10_sapControl,                             // control
     0x1600000F,                                 // pinMask
-    0,                                          // mode
+       (D10_MCLK_HDMI << D10_MCLK_SHIFT),          // mode
     0,0,0                                       // unused[3]
 };
 
@@ -616,7 +618,7 @@ const SAP_D10_Tx_Params SAP_D10_TX_DAC_SLAVE =
     24,                                         // precision (in bits)
     D10_sapControl,                             // control
     0x1E00000F,                                                                        // pinMask
-    0,                                          // mode
+    (D10_MCLK_OSC << D10_MCLK_SHIFT),           // mode
     0,0,0                                       // unused[3]
 };
 
@@ -711,7 +713,7 @@ static inline XDAS_Int32 initD10 (DEV2_Handle device)
        status = platformAudioInit();
        if(status != Platform_EOK)
        {
-               System_printf("Audio Init Failed!\n");
+               Log_info0("Audio Init Failed!\n");
                return status;
        }
 
@@ -719,7 +721,7 @@ static inline XDAS_Int32 initD10 (DEV2_Handle device)
        status = audioAdcConfig(ADC_DEVICE_ALL, &adcCfg);
        if(status != Platform_EOK)
        {
-               platform_write("Audio ADC Configuration Failed!\n");
+               Log_info0("Audio ADC Configuration Failed!\n");
                return status;
        }
 
@@ -732,6 +734,16 @@ static inline XDAS_Int32 initD10 (DEV2_Handle device)
                return status;
        }
 
+       // This is needed because DAC configuration needs some default clocking.
+       // We start with S/PDIF, because it's onboard the Audio DC & has its own crystal.
+       // HDMI is an add-on board & Audio OSC would need AUX clocking - both unfit for "default".
+       // ADCs default clock is not available to clock the DAC with.
+       status = platformAudioSelectClkSrc(AUDIO_CLK_SRC_I2S);
+
+       platform_delay(50000); // Without delay between these 2 calls system aborts.
+
+       status = setAudioDacConfig();
+
 #if 1
        /* Setup HSR41 for HDMI input operation */
        //status = platformAudioSelectClkSrc(AUDIO_CLK_SRC_I2S);
@@ -745,14 +757,7 @@ static inline XDAS_Int32 initD10 (DEV2_Handle device)
        }
 #endif
 
-       // This is needed because DAC configuration needs some default clocking.
-       // We start with S/PDIF, because it's onboard the Audio DC & has its own crystal.
-       // HDMI is an add-on board & Audio OSC would need AUX clocking - both unfit for "default".
-       status = platformAudioSelectClkSrc(AUDIO_CLK_SRC_DIR);
-
-       platform_delay(20000); // Without delay between these 2 calls system aborts.
-
-       status = setAudioDacConfig();
+       Log_info1("Leaving initD10 with status = %d", status);
 
     return status;
 
@@ -785,6 +790,8 @@ static XDAS_Int32 clockMuxTx (int sel, int force)
        pClkxDiv = (unsigned char *) clkxDivADC;
        }
 
+    Log_info1("SAP_D10: Inside clockMuxTx with sel = %d", sel);
+
     platform_delay(20000);
 
     return status;
@@ -796,19 +803,22 @@ static XDAS_Int32 clockMuxTx (int sel, int force)
 // This is called once when the device is opened
 // (PAF_SIO_CONTROL_OPEN) and periodically thereafter
 // (PAF_SIO_CONTROL_GET_INPUT_STATUS).
+int gHmint_ctr = 0, gNonAudio = 0, gLockStatus=0, gPrevAudio=0, gPrevLock=0;
+int gSync_ctr, gLock_ctr, gAudioErr_ctr, gNonAudio_ctr = 0;
 
 static int manageInput (DEV2_Handle device, const SAP_D10_Rx_Params *pParams, PAF_SIO_InputStatus *pStatusOut)
 {
     PAF_SIO_InputStatus *pStatusIn = &primaryStatus;
-    volatile Uint32 *mcasp0 = (volatile Uint32 *) _MCASP_BASE_PORT0;
-    volatile Uint32 *mcasp1 = (volatile Uint32 *) _MCASP_BASE_PORT1;
-    volatile Uint32 *mcasp2 = (volatile Uint32 *) _MCASP_BASE_PORT2;
+    //volatile Uint32 *mcasp0 = (volatile Uint32 *) _MCASP_BASE_PORT0;
+    //volatile Uint32 *mcasp1 = (volatile Uint32 *) _MCASP_BASE_PORT1;
+    //volatile Uint32 *mcasp2 = (volatile Uint32 *) _MCASP_BASE_PORT2;
 
-       Platform_STATUS status;
+       //Platform_STATUS status;
 
     static int PrevSampRate = 0;
-       int Rate_spdif=0;
+       int RateHdmi =0;
 
+       /* Mode & MCLK info embedded statically in the Rx IO definition for SPDIF Input */
     if ((((pParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT) == D10_MCLK_DIR) &
         (((pParams->d10rx.mode & D10_MODE_MASK) >> D10_MODE_SHIFT) == D10_MODE_STD))
     {
@@ -820,14 +830,15 @@ static int manageInput (DEV2_Handle device, const SAP_D10_Rx_Params *pParams, PA
                PrevSampRate = pStatusIn->sampleRateMeasured;
 
                // GJ: Is this needed? Probably not.
-        mcasp0[_MCASP_PDOUT_OFFSET] = 0x000 ;
-        mcasp0[_MCASP_PDOUT_OFFSET] = 0x400 ;
+               // GJ: Mute Control during input-change seemingly intended.
+        //mcasp0[_MCASP_PDOUT_OFFSET] = 0x000 ;
+        //mcasp0[_MCASP_PDOUT_OFFSET] = 0x400 ;
 
     }
+    /* Mode & MCLK info embedded statically in the Rx IO definition for ANALOG/ADC Input */
     else if ((((pParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT) == D10_MCLK_OSC) &
              (((pParams->d10rx.mode & D10_MODE_MASK) >> D10_MODE_SHIFT) == D10_MODE_STD)) {
         int adcRate = (pParams->d10rx.mode & D10_RATE_MASK) >> D10_RATE_SHIFT;
-        int regData;
 
         pStatusIn->lock = 1;
         pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_AUDIO;
@@ -836,27 +847,84 @@ static int manageInput (DEV2_Handle device, const SAP_D10_Rx_Params *pParams, PA
         pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
 
     }
+    /* Mode & MCLK info embedded statically in the Rx IO definition for HDMI */
     else if ((((pParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT) == D10_MCLK_HDMI) &
              (((pParams->d10rx.mode & D10_MODE_MASK) >> D10_MODE_SHIFT) == D10_MODE_HDMI))
     {
+        pStatusIn->emphasis = PAF_IEC_PREEMPHASIS_NO;
         pStatusIn->lock = 1;
         pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_AUDIO;
-        pStatusIn->emphasis = PAF_IEC_PREEMPHASIS_NO;
-               
-
-               if(!HDMIGpioGetState()) {
-                       HSR4_readStatus (pStatusIn);
+#if 0
+        RateHdmi = HSDIO_AudioFreq_192K;
+        pStatusIn->sampleRateMeasured = RateTable_hdmi[RateHdmi];
+        pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
+#else
+        if(!HDMIGpioGetState())
+       {
+               Log_info0("SAP_D10: Entering HMINT!\n");
+               clear_hdmi_hmint();
+               gHmint_ctr++;
+
+               Log_info0("SAP_D10: Clearing HMINT!\n");
+               RateHdmi=read_hdmi_samprate();
+                       pStatusIn->sampleRateMeasured = RateTable_hdmi[RateHdmi];
                        pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
                        PrevSampRate = pStatusIn->sampleRateMeasured;
-               }
-               else {
-                       pStatusIn->sampleRateMeasured = PrevSampRate;
-                       pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
-               }
+/*
+               switch(read_hdmi_errstatus())
+                       {
+                               case HSDIO_AudioErr_NO_ERROR:
+                               {
+                                       gPrevLock=pStatusIn->lock;
+                                       gPrevAudio=pStatusIn->nonaudio;
+                                       pStatusIn->lock = 1;
+                                       pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_AUDIO;
+                                       break;
+                               }
+                               case HSDIO_AudioErr_AUDIO_NO_PLL_LOCK:
+                               {
+                                       gLock_ctr++;
+                                       pStatusIn->lock = 0;
+                                       //pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_AUDIO;
+                                       break;
+                               }
+                               case HSDIO_AudioErr_AUDIO_NO_AUDIO:
+                               {
+                                       gAudioErr_ctr++;
+                                       //pStatusIn->lock = 1;
+                                       pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_NONAUDIO;
+                                       break;
+                               }
+                               default:
+                                       while(1);               // Control shouldn't be here.
+                       }
+
+               if(HSDIO_AudioMClk_128X != read_hdmi_clockstatus())
+               {
+                       gLock_ctr++;
+                       pStatusIn->lock = 0;
+               }
+               else if (HSDIO_AudioPresent_HAS_AUDIO != read_hdmi_audiostatus())
+                       {
+                               gNonAudio_ctr++;
+                               pStatusIn->nonaudio = PAF_IEC_AUDIOMODE_NONAUDIO;
+                       }*/
+
+               Log_info0("SAP_D10: Exiting HMINT!\n");
+       }
+       else
+       {
+               pStatusIn->sampleRateMeasured = PrevSampRate;
+               pStatusIn->sampleRateData = pStatusIn->sampleRateMeasured;
+       }
+#endif
+       }
 
-    }
     else
-        return -1;
+        return -1;             // Control shouldn't be here!
+
+    gNonAudio=pStatusIn->nonaudio;
+    gLockStatus=pStatusIn->lock;
 
     // update another status if requested
     if (pStatusOut)
@@ -879,7 +947,7 @@ static int manageOutput (DEV2_Handle device, const SAP_D10_Tx_Params *pParams, f
 
 
     if (!pClkxDiv)
-        return 1;
+        return SIO2_EINVAL;
 
     // set clock divider
     if (rateX < .354)
@@ -893,15 +961,15 @@ static int manageOutput (DEV2_Handle device, const SAP_D10_Tx_Params *pParams, f
     else
         rateX = 4.00;
     // if asynchronous then force clock change (assumes osc master)
-    if (pParams->d10tx.mode & D10_SYNC_MASK) {
+    /*if (pParams->d10tx.mode & D10_SYNC_MASK) {
         int dacRate = (pParams->d10tx.mode & D10_RATE_MASK) >> D10_RATE_SHIFT;
         divider = pClkxDiv[oscRateTable[dacRate]];
     }
-    else
-        divider = pClkxDiv[pStatusIn->sampleRateMeasured];
+    else*/
+    divider = pClkxDiv[pStatusIn->sampleRateMeasured];
     divider /= rateX;
 
-    Log_info2("SAP_D10: Inside manageOutput with divider = %d, rateX = %d", divider, rateX);
+    Log_info3("SAP_D10: Inside manageOutput with divider = %d, rateX = %f & input_rate = %d", divider, rateX, pStatusIn->sampleRateMeasured);
 
     // DIT requires 2x clock
     if ((mcasp[_MCASP_AFSXCTL_OFFSET] & _MCASP_AFSXCTL_XMOD_MASK) ==
@@ -925,7 +993,7 @@ XDAS_Int32 D10_sapControl (DEV2_Handle device, const PAF_SIO_Params *pParams, XD
 {
     const SAP_D10_Rx_Params *pDapD10RxParams = (const SAP_D10_Rx_Params *)pParams;
     const SAP_D10_Tx_Params *pDapD10TxParams = (const SAP_D10_Tx_Params *)pParams;
-    Platform_STATUS status;
+    //Platform_STATUS status;
 
     volatile Uint32 *mcasp = mcaspAddr[pParams->sio.moduleNum];
     XDAS_Int32 result = 0;
@@ -988,10 +1056,10 @@ XDAS_Int32 D10_sapControl (DEV2_Handle device, const PAF_SIO_Params *pParams, XD
 
                     // Since DAC is a slave to the chosen input, operate the clksel switch appropriately
                     // Also, this is a create-time (i.e, CTRL_OPEN) only call & not appropriate under
-                    // the periodic manage_(in/out)put calls
-                    int sel = (pDapD10RxParams->d10rx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT;
+                    // the periodic manage_output calls.
+                    int sel = (pDapD10TxParams->d10tx.mode & D10_MCLK_MASK) >> D10_MCLK_SHIFT;
                     clockMuxTx (sel, -1);
-                    platform_delay(20000); // Without delay between Tx McASP & DAC configs, system aborts.
+                    platform_delay(50000); // GJ REVISIT: Without delay between Tx McASP & DAC configs, system aborts.
                     setAudioDacConfig();
                                        dacHardUnMute ();
 
@@ -1088,15 +1156,6 @@ XDAS_Int32 D10_sapControl (DEV2_Handle device, const PAF_SIO_Params *pParams, XD
 // -----------------------------------------------------------------------------
 
 
-extern unsigned int read_hdmi_samprate();
-int RateHdmi=0;
-void HSR4_readStatus (PAF_SIO_InputStatus *pStatus)
-{
-       //if(!RateHdmi)
-       RateHdmi=read_hdmi_samprate();
-       pStatus->sampleRateMeasured = RateTable_hdmi[RateHdmi];
-}
-
 unsigned int HDMIGpioGetState (void) {
        return(gpioReadInput(GPIO_PORT_0, PLATFORM_AUDIO_HSR_HMINTz_GPIO));
 }
index 4f4093f905c2cf0cc97c5605877278d3315a9842..722aa2e5259215363d18767a808b36ccd3b6818a 100644 (file)
@@ -224,7 +224,6 @@ Void SAP_MCASP_init (Void)
         {
             Uint32 save = *pSers;
             *pSers = 0;
-            //TRACE_TERSE3(("SAP_MCASP_init: pSers: 0x%x.  was 0x%x.  is 0x%x", (IArg) pSers, (IArg) save, (IArg) *pSers));
             pSers++;
         }
         base[_MCASP_PDIR_OFFSET] = 0;  // all input by default
@@ -713,7 +712,7 @@ Int SAP_MCASP_reset (DEV2_Handle device)
 Int SAP_MCASP_waitSet (MCASP_Handle hMcasp, Uint32 wrReg, Uint32 rdReg, Uint32 mask, Uint32 timeout)
 {
     volatile Uint32 *base = (volatile Uint32 *)(hMcasp->baseAddr);
-    Uint32 timeStart, timeNow, elapsed, resMask, i;
+    Uint32 timeStart, timeNow, elapsed, resMask;
 
     //TRACE_TERSE3(("SAP_MCASP_waitSet(0x%x, 0x%x, 0x%x).", hMcasp, wrReg, rdReg));
 
@@ -751,11 +750,8 @@ Int SAP_MCASP_waitSet (MCASP_Handle hMcasp, Uint32 wrReg, Uint32 rdReg, Uint32 m
     }
 #endif
 
-    //timeout = timeout * USEC_PER_MSEC;
     timeStart = Clock_getTicks();
     while (1) {
-               //for(i=0; i < 20000; i++);
-       // return success if register has latched value
                if ((base[rdReg] & mask) == mask)
                        break;
                timeNow = Clock_getTicks();
@@ -774,6 +770,8 @@ Int SAP_MCASP_waitSet (MCASP_Handle hMcasp, Uint32 wrReg, Uint32 rdReg, Uint32 m
     return DEV2_OK;
 } //SAP_MCASP_waitSet
 
+int gMcASPWatchDogInCnt=0;
+int gMcASPWatchDogOutCnt=0;
 // -----------------------------------------------------------------------------
 
 Int SAP_MCASP_watchDog (DEV2_Handle device)
@@ -786,13 +784,19 @@ Int SAP_MCASP_watchDog (DEV2_Handle device)
         stat = MCASP_RGETH (hPort, RSTAT);
         if ((stat & _MCASP_RSTAT_ROVRN_MASK) ||
             (stat & _MCASP_RSTAT_RDMAERR_MASK))
+        {
+               gMcASPWatchDogInCnt++;
             return DEV2_EBADIO;
+        }
     }
     else {
         stat = MCASP_RGETH (hPort, XSTAT);
         if ((stat & _MCASP_XSTAT_XUNDRN_MASK) ||
             (stat & _MCASP_XSTAT_XDMAERR_MASK))
-        return DEV2_EBADIO;
+        {
+               gMcASPWatchDogOutCnt++;
+               return DEV2_EBADIO;
+        }
     }
     
     return DEV2_OK;
index 2fa9737f6b988e237cc76fceb61abb48131cf465..42afabe661b36c21c15cbf964ec805182c794170 100644 (file)
@@ -134,8 +134,8 @@ Platform_STATUS platformAudioInit(void)
        pinMuxSetMode(110, PADCONFIG_MUX_MODE_QUATERNARY);
        gpioSetDirection(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO, GPIO_OUT);
        /* Slect the clock source as DIR */
-       //gpioClearOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
-       gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);  // Default configurations are set for McASP AHCLK driven by SoC
+       gpioClearOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);
+       //gpioSetOutput(GPIO_PORT_0, PLATFORM_AUDIO_CLK_SELz_GPIO);  // Default configurations are set for McASP AHCLK driven by SoC
 
        /* Configure GPIO for PCM1690_RST# - GPIO1 10 & PADCONFIG 185 */
        pinMuxSetMode(185, PADCONFIG_MUX_MODE_QUATERNARY);