]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/aspDecOpCircBuf_master.c
Add 1 16-bit word for EDMA padding for Input Driver
[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / aspDecOpCircBuf_master.c
index 948c1fb9b4716d0092a1f8f27a07b1421a1dff51..f5c0ebcf1b1c795d6e1f76b484fa159a08a4d845 100644 (file)
@@ -35,14 +35,20 @@ All rights reserved.
 
 #include <string.h> // for memset()
 #include <xdc/std.h>
-#include <ti/sysbios/hal/Cache.h>
 #include <xdc/runtime/Log.h>
+#include <ti/sysbios/hal/Cache.h>
+#include <ti/uia/events/UIAEvt.h>
+#include <ti/ipc/GateMP.h>
 
 #include "common.h"
 #include "paftyp.h"
 #include "pafdec.h"
 #include "aspDecOpCircBuf_master.h"
 
+#define DEF_SOURCE_SEL          ( PAF_SOURCE_PCM ) // default source select
+#define DEF_DEC_OP_FRAME_LEN    ( 256 )     // default decoder output frame length
+#define DEF_STR_FRAME_LEN       ( 256 )     // default stream frame length
+
 #define MAX_NUM_AF_PCM      ( 4 )
 #define CB_INIT_RD_LAG_PCM  ( 2 ) // 0...3
 
@@ -55,21 +61,181 @@ static Void cbReadAfMute(
     Int16 strFrameLen           // stream frame length (output transaction size)
 );
 
+
+// Initialize circular buffer control
+Int cbCtlInit(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    PAF_AST_DecOpCircBuf **pXDecOpCb    // address of decoder output circular buffer base pointer
+)
+{
+    GateMP_Params gateParams;
+    GateMP_Handle gateHandle;
+    
+    GateMP_Params_init(&gateParams);
+    gateParams.localProtect = GateMP_LocalProtect_THREAD;
+    gateParams.remoteProtect = GateMP_RemoteProtect_SYSTEM;
+    gateParams.name = ASP_DECODE_CB_GATE_NAME;
+    gateParams.regionId = ASP_DECODE_CB_GATE_REGION_ID;
+    gateHandle = GateMP_create(&gateParams);
+    if (gateHandle != NULL)
+    {
+        pCbCtl->gateHandle = gateHandle;
+    }
+    else
+    {
+        pCbCtl->gateHandle = NULL;
+        return ASP_DECOP_CB_CTL_INIT_INV_GATE;
+    }
+    
+    pCbCtl->pXDecOpCb = pXDecOpCb;
+    
+    return ASP_DECOP_CB_SOK;
+    
+}
+
 // Initialize circular buffer
 Int cbInit(
-    Int8 sourceSelect,          // source select (PCM, DDP, etc.)
-    Int16 decOpFrameLen,        // decoder output frame length (PCM samples)
-    Int16 strFrameLen,          // stream frame length (PCM samples)
-    PAF_AST_DecOpCircBuf *pCb,  // decoder output circular buffer
-    Int8 resetRwFlags           // whether to reset reader, writer, and empty flags
+    PAF_AST_DecOpCircBuf *pCb
 )
 {
+    PAF_AudioFrame *pAfCb;
+    PAF_AudioData *pPcmBuf;
+    UInt8 *pMetaBuf;
+    Int8 n;
+    Int8 i;
+
+    // set source select
+    pCb->sourceSel = DEF_SOURCE_SEL;
+
+    // set input frame length
+    pCb->decOpFrameLen = DEF_DEC_OP_FRAME_LEN;
+    
+    // set output frame length
+    pCb->strFrameLen = DEF_STR_FRAME_LEN;
+    
+    // initialize circular buffer maximum number of audio frames
+    pCb->maxNumAfCb = MAX_NUM_AF_PCM;
+    pCb->afWrtIdx = CB_INIT_RD_LAG_PCM;
+    pCb->afRdIdx = 0;
+    pCb->pcmRdIdx = 0; // 2*256 in behind
+    
+    // initialize audio frames
+    for (n=0; n<pCb->maxNumAfCb; n++)
+    {
+        pAfCb = &pCb->afCb[n];
+        pAfCb->sampleDecode = PAF_SOURCE_PCM;
+        PAF_PROCESS_ZERO(pAfCb->sampleProcess);
+        pAfCb->sampleRate = PAF_SAMPLERATE_48000HZ;
+        pAfCb->sampleCount = DEF_DEC_OP_FRAME_LEN;
+        pAfCb->channelConfigurationRequest.full = 0;
+        pAfCb->channelConfigurationRequest.part.sat = PAF_CC_SAT_SURROUND4;
+        pAfCb->channelConfigurationRequest.part.sub = PAF_CC_SUB_ONE;
+        pAfCb->channelConfigurationStream.full = 0;
+        pAfCb->channelConfigurationStream.part.sat = PAF_CC_SAT_SURROUND4;
+        pAfCb->channelConfigurationStream.part.sub = PAF_CC_SUB_ONE;
+    }
+
+    // initialize circular buffer current number of frames
+    pCb->numAfCb = pCb->afWrtIdx - pCb->afRdIdx;
+    
+    // initialize audio frame PCM buffers
+    pPcmBuf = pCb->pcmBuf;
+    pMetaBuf = pCb->metaBuf; //QIN
+    for (n=0; n<pCb->maxNumAfCb; n++)
+    {
+        pAfCb = &pCb->afCb[n];
+        pAfCb->data.nChannels = ASP_DECOP_CB_MAX_NUM_PCM_CH;
+        pAfCb->data.nSamples = DEF_DEC_OP_FRAME_LEN;
+        for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
+        {
+            pAfCb->data.sample[i] = pPcmBuf;
+            memset(pAfCb->data.sample[i], DEF_DEC_OP_FRAME_LEN, 0);
+            pPcmBuf += DEF_DEC_OP_FRAME_LEN;
+            
+            pAfCb->data.samsiz[i] = 0;
+        }
+        
+        // Initialize metadata buffers //QIN
+        for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)
+        {
+            pAfCb->pafPrivateMetadata[i].offset = 0; 
+            pAfCb->pafPrivateMetadata[i].size   = 0; 
+            pAfCb->pafPrivateMetadata[i].pMdBuf = pMetaBuf;
+            pMetaBuf += PAF_MAX_PRIVATE_MD_SZ;
+        }
+    }
+    
+    // reset read/write flags
+    pCb->writerActiveFlag = 0;
+    pCb->readerActiveFlag = 0;
+    pCb->emptyFlag = 0;
+    
+    // reset error counts
+    pCb->errUndCnt = 0;
+    pCb->errOvrCnt = 0;
+    
+    // (***) FL: revisit
+    // Write back circular buffer configuration
+    Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+    // Write back AF circular buffer
+    Cache_wb(pCb->afCb, pCb->maxNumAfCb*sizeof(PAF_AudioFrame), Cache_Type_ALLD, 0);
+    // Write back PCM data
+    for (n=0; n<pCb->maxNumAfCb; n++)
+    {
+        pAfCb = &pCb->afCb[n];
+        Cache_wb(pAfCb->data.samsiz, ASP_DECOP_CB_MAX_NUM_PCM_CH*sizeof(PAF_AudioSize), Cache_Type_ALLD, 0);
+        Cache_wb(pAfCb->data.sample, ASP_DECOP_CB_MAX_NUM_PCM_CH*sizeof(PAF_AudioData *), Cache_Type_ALLD, 0);
+        for (i=0; i<ASP_DECOP_CB_MAX_NUM_PCM_CH; i++)
+        {
+            Cache_wb(pAfCb->data.sample[i], DEF_DEC_OP_FRAME_LEN*sizeof(PAF_AudioData), Cache_Type_ALLD, 0);
+        }
+        // FL: unnecessary since part of AF
+        //for (i=0; i<PAF_MAX_NUM_PRIVATE_MD; i++)     // Write back metadata //QIN
+        //{
+        //    Cache_wb(&pAfCb->pafPrivateMetadata[i], sizeof(PAF_PrivateMetadata), Cache_Type_ALLD, 0);
+        //}
+    }
+    Cache_wait();
+
+    return ASP_DECOP_CB_SOK;
+}
+
+// Initialize circular buffer based on selected source
+Int cbInitSourceSel(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    Int8 sourceSelect,                  // source select (PCM, DDP, etc.)
+    Int16 decOpFrameLen,                // decoder output frame length (PCM samples)
+    Int16 strFrameLen,                  // stream frame length (PCM samples)
+    Int8 resetRwFlags                   // whether to reset reader, writer, and empty flags
+)
+{
+    IArg key;
+    GateMP_Handle gateHandle;
+    PAF_AST_DecOpCircBuf *pCb;
     PAF_AudioFrame *pAfCb;
     PAF_AudioData *pPcmBuf;
     UInt8 *pMetaBuf; //QIN
     Int8 n;
     Int8 i;
 
+    // Get gate handle
+    gateHandle = pCbCtl->gateHandle;
+    // Enter gate
+    key = GateMP_enter(gateHandle);
+
+    // Get circular buffer base pointer
+    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
+    
+    // Invalidate circular buffer configuration
+    Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
+    Cache_wait();
+
+    Log_info1("cbInitSourceSel:afCb=0x%04x", (IArg)pCb->afCb);
+
+    // set source select
+    pCb->sourceSel = sourceSelect;
+
     // set input frame length
     pCb->decOpFrameLen = decOpFrameLen;
     
@@ -125,6 +291,9 @@ Int cbInit(
     }
     else
     {
+        // Leave the gate
+        GateMP_leave(gateHandle, key);
+
         return ASP_DECOP_CB_INIT_INV_SOURCE_SEL;
     }
 
@@ -165,6 +334,7 @@ Int cbInit(
         pCb->readerActiveFlag = 0;
         pCb->emptyFlag = 0;
     }
+    
     // reset error counts
     pCb->errUndCnt = 0;
     pCb->errOvrCnt = 0;
@@ -192,18 +362,36 @@ Int cbInit(
     }
     Cache_wait();
 
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
+    
     return ASP_DECOP_CB_SOK;
 }
 
 // Start reads from circular buffer
 Int cbReadStart(
-    PAF_AST_DecOpCircBuf *pCb   // decoder output circular buffer
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx                          // decoder output circular buffer index
 )
 {
+    IArg key;
+    GateMP_Handle gateHandle;
+    PAF_AST_DecOpCircBuf *pCb;
+
+    // Get gate handle
+    gateHandle = pCbCtl->gateHandle;
+    // Enter gate
+    key = GateMP_enter(gateHandle);
+
+    // Get circular buffer base pointer
+    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
+    
     // Invalidate circular buffer configuration
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
     
+    Log_info1("cbReadStart:afCb=0x%04x", (IArg)pCb->afCb);
+
     // update flags
     pCb->readerActiveFlag = 1;
     
@@ -212,18 +400,36 @@ Int cbReadStart(
     Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
 
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
+
     return ASP_DECOP_CB_SOK;
 }
 
 // Stop reads from circular buffer
 Int cbReadStop(
-    PAF_AST_DecOpCircBuf *pCb   // decoder output circular buffer
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx                          // decoder output circular buffer index
 )
 {
+    IArg key;
+    GateMP_Handle gateHandle;
+    PAF_AST_DecOpCircBuf *pCb;
+
+    // Get gate handle
+    gateHandle = pCbCtl->gateHandle;
+    // Enter gate
+    key = GateMP_enter(gateHandle);
+
+    // Get circular buffer base pointer
+    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
+
     // Invalidate circular buffer configuration
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
     
+    Log_info1("cbReadStop:afCb=0x%04x", (IArg)pCb->afCb);
+
     // update flags
     pCb->readerActiveFlag = 0;
     
@@ -232,31 +438,52 @@ Int cbReadStop(
     Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
 
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
+
     return ASP_DECOP_CB_SOK;
 }
 
 // Read audio frame from circular buffer
 Int cbReadAf(
-    PAF_AST_DecOpCircBuf *pCb,  // decoder output circular buffer
-    PAF_AudioFrame *pAfRd       // audio frame into which to read
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    PAF_AudioFrame *pAfRd               // audio frame into which to read
 )
 {
+    IArg key;
+    GateMP_Handle gateHandle;
+    PAF_AST_DecOpCircBuf *pCb;
     PAF_AudioFrame *pAfCb;
     PAF_ChannelMask_HD streamMask;
     Int8 i;
     Int16 j;
 
+    // Get gate handle
+    gateHandle = pCbCtl->gateHandle;
+    // Enter gate
+    key = GateMP_enter(gateHandle);
+
+    // Get circular buffer base pointer
+    pCb = &((*pCbCtl->pXDecOpCb)[cbIdx]);
+
     // (***) FL: revisit
     // Invalidate circular buffer configuration.
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
 
+    Log_info1("cbReadAf:afCb=0x%04x", (IArg)pCb->afCb);
+
     if ((pCb->writerActiveFlag == 1) && (pCb->emptyFlag == 1))
     {
         // This shouldn't occur:
         //  writer is active AND draining circular buffer
         Log_info2("cbReadAf: ERROR: writerActiveFlag=%d, emptyFlag=%d", pCb->writerActiveFlag, pCb->emptyFlag);
         SW_BREAKPOINT; // FL: debug
+        
+        // Leave the gate
+        GateMP_leave(gateHandle, key);
+        
         return ASP_DECOP_CB_READ_INVSTATE;
     }
 
@@ -268,9 +495,14 @@ Int cbReadAf(
         //
         cbReadAfMute(pAfRd, pCb->strFrameLen);
         
+        // Leave the gate
+        GateMP_leave(gateHandle, key);
+
         return ASP_DECOP_CB_SOK;
     }
-        
+    
+    // (writerActiveFlag,emptyFlag)=(1,0) and (0,1) are left
+    // Here we are checking (1,0) state here
     if ((pCb->writerActiveFlag == 1))
     {
         // check underflow
@@ -288,6 +520,9 @@ Int cbReadAf(
             Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
             Cache_wait();    
             
+            // Leave the gate
+            GateMP_leave(gateHandle, key);
+            
             return ASP_DECOP_CB_READ_UNDERFLOW;
         }
     }
@@ -418,6 +653,9 @@ Int cbReadAf(
     Cache_wb(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();    
         
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
+
     return ASP_DECOP_CB_SOK;
 }