Add GateMP for Decoder Output Circular Buffer
authorFrank Livingston <frank-livingston@ti.com>
Tue, 6 Sep 2016 23:27:11 +0000 (18:27 -0500)
committerFrank Livingston <frank-livingston@ti.com>
Tue, 6 Sep 2016 23:27:11 +0000 (18:27 -0500)
13 files changed:
processor_audio_sdk_1_00_00_00/pasdk/common/aspDecOpCircBuf_common.c
processor_audio_sdk_1_00_00_00/pasdk/common/aspDecOpCircBuf_common.h
processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/aspDecOpCircBuf_slave.c
processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/aspDecOpCircBuf_slave.h
processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/audioStreamDecodeProc.c
processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/audioStreamDecodeProc.h
processor_audio_sdk_1_00_00_00/pasdk/test_arm/framework/systemInit.c
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/aspDecOpCircBuf_master.c
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/aspDecOpCircBuf_master.h
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/audioStreamInpProc.c
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/audioStreamOutProc.c
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/audioStreamProc_master.h
processor_audio_sdk_1_00_00_00/pasdk/test_dsp/framework/systemInit.c

index 41669a9873491bd18fde420c2935ddb4630dc355..edf3b7c16c228d1c569accc0ed4ff89ff5772022 100644 (file)
@@ -34,18 +34,32 @@ All rights reserved.
 */
 
 #include <xdc/std.h>
-#include <ti/sysbios/hal/Cache.h>
 #include <xdc/runtime/Log.h>
+#include <ti/sysbios/hal/Cache.h>
+#include <ti/ipc/GateMP.h>
 
 #include "aspDecOpCircBuf_common.h"
 
 // Output log of circular buffer control variables (debug)
 Int cbLog(
-    PAF_AST_DecOpCircBuf *pCb,
+    PAF_AST_DecOpCircBufCtl *pCbCtl,
+    Int8 cbIdx, 
     Int8 fullLog, 
     char *locInfo
 )
 {
+    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->xDecOpCb[cbIdx];
+    
     // Invalidate circular buffer configuration.
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
@@ -61,6 +75,9 @@ Int cbLog(
         Log_info2("CB: decOpFrameLen=%d, strFrameLen=%d", pCb->decOpFrameLen, pCb->strFrameLen);
         //Log_info1("cbWriteInit=%d", pCb->cbWriteAfInit);
     }
+
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
     
-    return 0;
+    return ASP_DECOP_CB_SOK;
 }
index 7b74a725eec4b56a6c9f79acf046a347303a76f7..46d91f17dda6251ddc229e10ca51842d7dfa56d2 100644 (file)
@@ -40,7 +40,9 @@ All rights reserved.
 #include <ti/ipc/GateMP.h>
 #include "paftyp.h"
 
-#define ASP_DECOP_CB_SOK                    (  0 )      // ok
+#define ASP_DECOP_CB_SOK                    ( 0 )       // ok
+#define ASP_DECOP_CB_CTL_INIT_INV_GATE      ( ASP_DECOP_CB_SOK-1 )  // error: invalid gate handle
+#define ASP_DECOP_CB_ERR_START              ( ASP_DECOP_CB_CTL_INIT_INV_GATE )
 
 #define ASP_DECOP_CB_MAX_NUM_AF             ( 4 )       // decoder output circular buffer maximum number audio frames
 #define ASP_DECOP_CB_MAX_NUM_PCM_CH         ( 16 )      // decoder output circular buffer maximum number audio PCM channels
@@ -48,6 +50,9 @@ All rights reserved.
 #define ASP_DECOP_CB_MAX_PCM_FRAME_LEN      ( 6*256 )   // decoder output circular buffer maximum PCM frame length
 #define ASP_DECOP_CB_PCM_BUF_SZ             ( ASP_DECOP_CB_MAX_NUM_PCM_CH * ASP_DECOP_CB_MAX_NUM_PCM_FRAMES * ASP_DECOP_CB_MAX_PCM_FRAME_LEN )
 
+#define ASP_DECODE_CB_GATE_NAME             ( "AspDecOpCbGate" )
+#define ASP_DECODE_CB_GATE_REGION_ID        ( 0 )
+
 
 // Decoder output circular buffer
 typedef struct PAF_AST_DecOpCircBuf 
@@ -70,15 +75,22 @@ typedef struct PAF_AST_DecOpCircBuf
 } PAF_AST_DecOpCircBuf;
 
 // Decoder output circular buffer control
-typedef struct PAF_AST_DecOpCircBufCtrl
+typedef struct PAF_AST_DecOpCircBufCtl
 {
-    GateMP_Handle *gateHandle;      // circular buffer gate handle
+    GateMP_Handle gateHandle;       // circular buffer gate handle
     PAF_AST_DecOpCircBuf *xDecOpCb; // circular buffer base pointer
-} PAF_AST_DecOpCircBufCtrl;
+} PAF_AST_DecOpCircBufCtl;
+
+// Initialize circular buffer control
+Int cbCtlInit(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    PAF_AST_DecOpCircBuf *xDecOpCb      // decoder output circular buffer base pointer
+);
 
 // Output log of circular buffer control variables (debug)
 Int cbLog(
-    PAF_AST_DecOpCircBuf *pCb,
+    PAF_AST_DecOpCircBufCtl *pCbCtl,
+    Int8 cbIdx, 
     Int8 fullLog, 
     char *locInfo
 );
index 6fb390de61af00d545d4d937e6668ccaf7a1a398..16010b8eb3617b675205cf6fdea3f8eaf44d98cd 100644 (file)
@@ -44,15 +44,48 @@ All rights reserved.
 //#include "pafsp.h"
 #include "aspDecOpCircBuf_slave.h"
 
+// Initialize circular buffer control
+Int cbCtlInit(
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    PAF_AST_DecOpCircBuf *xDecOpCb      // decoder output circular buffer base pointer
+)
+{
+    GateMP_Handle gateHandle;
+    Int status;
+    
+    status = GateMP_open(ASP_DECODE_CB_GATE_NAME, &gateHandle);
+    if (status < 0)
+    {
+        return ASP_DECOP_CB_CTL_INIT_INV_GATE;
+    }
+    
+    pCbCtl->xDecOpCb = xDecOpCb;
+    
+    return ASP_DECOP_CB_SOK;
+    
+}
+
 // Start writes to circular buffer
 Int cbWriteStart(
-    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;
     PAF_AudioFrame *pAfCb;
     Int8 n;
     //Int8 i;
 
+    // Get gate handle
+    gateHandle = pCbCtl->gateHandle;
+    // Enter gate
+    key = GateMP_enter(gateHandle);
+
+    // Get circular buffer base pointer
+    pCb = &pCbCtl->xDecOpCb[cbIdx];
+
     // (***) FL: revisit
     // Invalidate circular buffer configuration.
     // NOTE: Probably only a subset of this information needs to be updated.
@@ -82,14 +115,30 @@ Int cbWriteStart(
     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 writes to circular buffer
 Int cbWriteStop(
-    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->xDecOpCb[cbIdx];
+
     // Invalidate circular buffer configuration
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
@@ -103,20 +152,35 @@ Int cbWriteStop(
     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;
 }
 
 // Write audio frame to circular buffer
 Int cbWriteAf(
-    PAF_AST_DecOpCircBuf *pCb,  // decoder output circular buffer
-    PAF_AudioFrame *pAfWrt      // audio frame from which to write
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    PAF_AudioFrame *pAfWrt              // audio frame from which to write
 )
 {
+    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->xDecOpCb[cbIdx];
+
     // (***) FL: revisit
     // Invalidate circular buffer configuration.
     // NOTE: Probably only a subset of this information nexeds to be updated.
@@ -149,8 +213,13 @@ Int cbWriteAf(
         if (pCb->numAfCb >= pCb->maxNumAfCb)
         {
             pCb->errOvrCnt++;
+
             //SW_BREAKPOINT;
             Log_info1("cbWriteAf: ERROR: overflow, numAfCb=%d", pCb->numAfCb);
+
+            // Leave the gate
+            GateMP_leave(gateHandle, key);
+
             return ASP_DECOP_CB_WRITE_OVERFLOW;
         }
         
@@ -226,15 +295,31 @@ Int cbWriteAf(
         Cache_wait();
     }  
     
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
+
     return ASP_DECOP_CB_SOK;
 }
 
 // Get next audio frame to write in circular buffer
 Int cbGetNextWriteAf(
-    PAF_AST_DecOpCircBuf *pCb, // decoder output circular buffer
-    PAF_AudioFrame **ppAfWrt   // audio frame next to be written
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    PAF_AudioFrame **ppAfWrt            // audio frame next to be written
 )
 {
+    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->xDecOpCb[cbIdx];
+
     // get pointer to current audio frame in circular buffer
     *ppAfWrt = &pCb->afCb[pCb->afWrtIdx];
     
@@ -245,5 +330,8 @@ Int cbGetNextWriteAf(
         pCb->afWrtIdx = 0;
     }    
     
+    // Leave the gate
+    GateMP_leave(gateHandle, key);
+
     return ASP_DECOP_CB_SOK;
 }
index 2759e378a5b0011878ad5db6c6b4f122a3c9a4db..4e4dbf1433e028f515b011e8a01623ff506b7918 100644 (file)
@@ -40,28 +40,32 @@ All rights reserved.
 #include "paftyp.h"
 #include "aspDecOpCircBuf_common.h"
 
-#define ASP_DECOP_CB_WRITE_OVERFLOW         ( ASP_DECOP_CB_SOK-1 ) // error: write overflow
+#define ASP_DECOP_CB_WRITE_OVERFLOW         ( ASP_DECOP_CB_ERR_START-1 ) // error: write overflow
 
 // Start writes to circular buffer
 Int cbWriteStart(
-    PAF_AST_DecOpCircBuf *pCb   // decoder output circular buffer
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx                          // decoder output circular buffer index
 );
 
 // Stop writes to circular buffer
 Int cbWriteStop(
-    PAF_AST_DecOpCircBuf *pCb   // decoder output circular buffer
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx                          // decoder output circular buffer index
 );
 
 // Write audio frame to circular buffer
 Int cbWriteAf(
-    PAF_AST_DecOpCircBuf *pCb,  // decoder output circular buffer
-    PAF_AudioFrame *pAfWrt      // audio frame from which to write
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    PAF_AudioFrame *pAfWrt              // audio frame from which to write
 );
 
 // Get next audio frame to write in circular buffer
 Int cbGetNextWriteAf(
-    PAF_AST_DecOpCircBuf *pCb,  // decoder output circular buffer
-    PAF_AudioFrame **ppAfWrt    // audio frame next to be written
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    PAF_AudioFrame **ppAfWrt            // audio frame next to be written
 );
 
 #endif /* _ASP_DECOP_CB_SLAVE_H_ */
index 6d0fec4b04c128022b639e7012127b84dc503d4b..e7ab2ca2a2fc7b9d819fa27323c1e98bd76dd170 100644 (file)
@@ -89,6 +89,7 @@ ERRNO_DEFN(TaskAsdp); /* Error number macros */
 PAF_ASDT_Config gPAF_ASDT_config 
 __attribute__ ((section(".globalSectionPafAsdtConfig"))) = {
     NULL,               // acp
+    {NULL, NULL},       // decOpCircBufCtl
     &gPAF_AST_config    // ASIT/ASOT/ASDT shared configuration
 };
 
@@ -139,7 +140,8 @@ Void taskAsdpFxn(
     Int size;
     Int argIdx;
     // Decoder output circular buffer
-    PAF_AST_DecOpCircBuf *pCb;
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    //PAF_AST_DecOpCircBuf *pCb;
     PAF_AudioFrame *pAfWrt;
     Int cbErrno;    
     // Messaging
@@ -173,7 +175,8 @@ Void taskAsdpFxn(
     // Audio Framework Configuration (*pC):
     //
     pC = &gPAF_ASDT_config;
-    pAstCfg = pC->pAstCfg;
+    pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration 
+    pCbCtl = &pC->decOpCircBufCtl; // get pointer to circular buffer control
 
     // wait for initialization message from master
     do {
@@ -449,14 +452,14 @@ Void taskAsdpFxn(
                     }
 
                     // Start writes to circular buffer
-                    pCb = &pAstCfg->xDecOpCb[z];
-                    cbErrno = cbWriteStart(pCb);
+                    //pCb = &pAstCfg->xDecOpCb[z];
+                    cbErrno = cbWriteStart(pCbCtl, z);
                     if (cbErrno < 0)
                     {
                         SW_BREAKPOINT;
                     }
                     // FL: debug, log circular buffer control variables
-                    cbLog(pCb, 1, "cbWriteStart");
+                    cbLog(pCbCtl, z, 1, "cbWriteStart");
                     // Reset audio frame
                     resetAf(pP, z, sourceSelect);
                     
@@ -618,7 +621,7 @@ Void taskAsdpFxn(
                         //TRACE_TERSE0("Dec:decode done");
                         
                         // copy decoder output to decoder output circular buffers
-                        pCb = &pAstCfg->xDecOpCb[z];
+                        //pCb = &pAstCfg->xDecOpCb[z];
                         //TRACE_TERSE1("Dec:pCb=0x%04x", (IArg)pCb);
                         
                         pAfWrt = pAstCfg->xDec[z].decodeOutStruct.pAudioFrame;
@@ -631,7 +634,7 @@ Void taskAsdpFxn(
                         //    Log_info0("capAfWrite() error");
                         //}                        
 
-                        cbErrno = cbWriteAf(pCb, pAfWrt);
+                        cbErrno = cbWriteAf(pCbCtl, z, pAfWrt);
                         if (cbErrno < 0)
                         {
                             SW_BREAKPOINT;
@@ -639,7 +642,7 @@ Void taskAsdpFxn(
                         //TRACE_TERSE0("Dec:cbWriteAf() complete");
                         
                         // FL: debug, log circular buffer control variables
-                        cbLog(pCb, 1, "cbWriteAf");
+                        cbLog(pCbCtl, z, 1, "cbWriteAf");
                     }
                     
                     // write back Dec configuration
@@ -686,14 +689,14 @@ Void taskAsdpFxn(
                     }
                     
                     // Stop writes to circular buffer
-                    pCb = &pAstCfg->xDecOpCb[z];
-                    cbErrno = cbWriteStop(pCb);
+                    //pCb = &pAstCfg->xDecOpCb[z];
+                    cbErrno = cbWriteStop(pCbCtl, z);
                     if (cbErrno < 0)
                     {
                         SW_BREAKPOINT;
                     }
                     // FL: debug, log circular buffer control variables
-                    cbLog(pCb, 1, "cbWriteStop");
+                    cbLog(pCbCtl, z, 1, "cbWriteStop");
                     
                     // send dec deactivate complete message to master
                     queId = MessageQ_getReplyQueue(pAspMsg);
index da0aacef8a973d9dfe8ca009ef762fd39c9d7c5e..3fa0fca5d665429c3dfb960bd4c412416191bcb7 100644 (file)
@@ -45,6 +45,7 @@ All rights reserved.
 #include "audioStreamProc_params.h"
 #include "audioStreamProc_patchs.h"
 #include "audioStreamProc_config.h"
+#include "aspDecOpCircBuf_common.h"
 
 struct PAF_ASDT_Params;
 struct PAF_ASDT_Patchs;
@@ -107,6 +108,7 @@ typedef struct PAF_ASDT_Patchs {
 typedef struct PAF_ASDT_Config 
 {
     ACP_Handle     acp;
+    PAF_AST_DecOpCircBufCtl decOpCircBufCtl; // decoder output circular buffer control
     PAF_AST_Config *pAstCfg; // ASIT/ASOT/ASDT shared configuration
 } PAF_ASDT_Config;
 
@@ -192,5 +194,6 @@ Int resetAfSamsiz(
     Int z
 );
 
+extern PAF_ASDT_Config gPAF_ASDT_config;
 
 #endif /* _ASDP_H_ */
index ad9831761b888a2032172ec30272c3b35aabdab6..dd6b2a10b13ceb0ec17fffd6bbb65ce2430b496a 100644 (file)
@@ -46,6 +46,9 @@ All rights reserved.
 
 #include "pafhjt.h"
 #include "paf_heapMgr.h"
+#include "aspDecOpCircBuf_slave.h"
+#include "audioStreamProc_common.h"
+#include "audioStreamDecodeProc.h"
 
 const PAFHJT_t *pafhjt;
 
@@ -97,6 +100,14 @@ Void taskSysInitFxn(Void)
         return;
     }
 
+    /* Initialize decoder output circular buffer control */
+    status = cbCtlInit(&gPAF_ASDT_config.decOpCircBufCtl, gPAF_AST_config.xDecOpCb);
+    if (status < 0)
+    {
+        Log_info1("%s: unable to initialize Decoder Output Circular Buffer Control. Exiting.", (IArg)__TASK_NAME__);
+        return;
+    }
+
     /* Initialize PAF heap manager */
     Log_info0("taskSysInitFxn:pafHeapMgr_init()");
     pafHeapMgr_init((IHeap_Handle)heapMemL2Sram,
index 948c1fb9b4716d0092a1f8f27a07b1421a1dff51..e8c86a38635ff25401a670e58a04ff6f57cc7c75 100644 (file)
@@ -37,6 +37,7 @@ All rights reserved.
 #include <xdc/std.h>
 #include <ti/sysbios/hal/Cache.h>
 #include <xdc/runtime/Log.h>
+#include <ti/ipc/GateMP.h>
 
 #include "common.h"
 #include "paftyp.h"
@@ -55,21 +56,65 @@ 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 *xDecOpCb      // 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->xDecOpCb = xDecOpCb;
+    
+    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_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->xDecOpCb[cbIdx];
+    
     // set input frame length
     pCb->decOpFrameLen = decOpFrameLen;
     
@@ -125,6 +170,9 @@ Int cbInit(
     }
     else
     {
+        // Leave the gate
+        GateMP_leave(gateHandle, key);
+
         return ASP_DECOP_CB_INIT_INV_SOURCE_SEL;
     }
 
@@ -192,14 +240,30 @@ 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->xDecOpCb[cbIdx];
+    
     // Invalidate circular buffer configuration
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
@@ -212,14 +276,30 @@ 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->xDecOpCb[cbIdx];
+
     // Invalidate circular buffer configuration
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
     Cache_wait();
@@ -232,20 +312,35 @@ 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->xDecOpCb[cbIdx];
+
     // (***) FL: revisit
     // Invalidate circular buffer configuration.
     Cache_inv(pCb, sizeof(PAF_AST_DecOpCircBuf), Cache_Type_ALLD, 0);
@@ -257,6 +352,10 @@ Int cbReadAf(
         //  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,6 +367,9 @@ Int cbReadAf(
         //
         cbReadAfMute(pAfRd, pCb->strFrameLen);
         
+        // Leave the gate
+        GateMP_leave(gateHandle, key);
+
         return ASP_DECOP_CB_SOK;
     }
         
@@ -288,6 +390,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 +523,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;
 }
 
index fd297784fa941dd9f65e468be5afb60faf6e5d67..eb4e89b86d065cfaca9e28d58c7b89ac1291c184 100644 (file)
@@ -40,40 +40,45 @@ All rights reserved.
 #include "paftyp.h"
 #include "aspDecOpCircBuf_common.h"
 
-#define ASP_DECOP_CB_INIT_INV_SOURCE_SEL    ( ASP_DECOP_CB_SOK-1 )  // error: invalid source selection on init
-#define ASP_DECOP_CB_READ_UNDERFLOW         ( ASP_DECOP_CB_SOK-2 )  // error: read underflow
-#define ASP_DECOP_CB_READ_INVSTATE          ( ASP_DECOP_CB_SOK-3 )  // error: circular buffer invalid state on read
+#define ASP_DECOP_CB_INIT_INV_SOURCE_SEL    ( ASP_DECOP_CB_ERR_START-1 )  // error: invalid source selection on init
+#define ASP_DECOP_CB_READ_UNDERFLOW         ( ASP_DECOP_CB_ERR_START-2 )  // error: read underflow
+#define ASP_DECOP_CB_READ_INVSTATE          ( ASP_DECOP_CB_ERR_START-3 )  // error: circular buffer invalid state on read
 
 
 // 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_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
 );
 
 // 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
 );
 
 // 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
 );
 
 // 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
 );
 
 // Write audio frame to circular buffer
 Int cbWriteAf(
-    PAF_AST_DecOpCircBuf *pCb,  // decoder output circular buffer
-    PAF_AudioFrame *pAfWrt      // audio frame from which to write
+    PAF_AST_DecOpCircBufCtl *pCbCtl,    // decoder output circular buffer control
+    Int8 cbIdx,                         // decoder output circular buffer index
+    PAF_AudioFrame *pAfWrt              // audio frame from which to write
 );
 
 #endif /* _ASP_DECOP_CB_MASTER_H_ */
index 6fe77021fc1ad1480c67e75bc94a079f34004ba2..5209f7048bce82af4c6159d546eb3c8c0f6b2873 100644 (file)
@@ -1333,19 +1333,21 @@ PAF_ASIT_initPhaseDecOpCircBuf(
 )
 {
     PAF_AST_Config *pAstCfg;
-    Int as;                     /* Audio Stream Number (1, 2, etc.) */
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    PAF_AST_DecOpCircBuf *pCb;          /* Decoder output circular buffer */
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
     Int zMS;
-    Int z;                      /* decode counter */
-    PAF_AST_DecOpCircBuf *pCb;  /* Decoder output circular buffer */
-    Int errno;                  /* error number */
+    Int z;                              /* decode counter */
+    Int errno;                          /* error number */
     Error_Block    eb;
     Int i;
 
     // FL: (***)revisit
-
     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
     as = pAstCfg->as;
     zMS = pAstCfg->masterStr;
+
+    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
     
     /* Decode output circular buffer memory */
     if (!(pAstCfg->xDecOpCb = Memory_calloc((IHeap_Handle)HEAP_INTERNAL1_SHM, 
@@ -1398,14 +1400,14 @@ PAF_ASIT_initPhaseDecOpCircBuf(
         
         // (***) FL: revisit, here PCM is hard-coded for 256 sample dec op frame length        
         // Initialize decoder output circular buffer for PCM
-        errno = cbInit(PAF_SOURCE_PCM, 256, FRAMELENGTH, pCb, 1);
+        errno = cbInit(pCbCtl, z, PAF_SOURCE_PCM, 256, FRAMELENGTH, 1);
         if (errno)
         {
             SW_BREAKPOINT; // FL: debug
             return errno;
         }
         // FL: debug
-        cbLog(pCb, 1, "PAF_ASIT_initPhaseDecOpCircBuf:cbInit");        
+        cbLog(pCbCtl, z, 1, "PAF_ASIT_initPhaseDecOpCircBuf:cbInit");        
     }
 
     return 0;
@@ -2238,17 +2240,17 @@ PAF_ASIT_decodeInit(
 )
 {
     PAF_AST_Config *pAstCfg;
-    Int as;                     /* Audio Stream Number (1, 2, etc.) */
-    Int z;                      /* decode/encode counter */
-    Int errno;                  /* error number */
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    Int z;                              /* decode/encode counter */
+    Int errno;                          /* error number */
     Int zI, zS;
     Int zMD;
     Int zMI;
-    ASP_Msg* pAspMsg;           /* Messaging */
+    ASP_Msg* pAspMsg;                   /* Messaging */
     Int argIdx;
     Int decErrno;
     Int status;
-    PAF_AST_DecOpCircBuf *pCb;  /* Decoder output circular buffer */
     
     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
     as = pAstCfg->as;
@@ -2256,6 +2258,8 @@ PAF_ASIT_decodeInit(
     zMI = pP->zone.master;
     (void)as;  // clear compiler warning in case not used with tracing disabled
     
+    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+
     // reset frameCount
     for (z=DECODE1; z < DECODEN; z++)
     {
@@ -2439,15 +2443,14 @@ PAF_ASIT_decodeInit(
             //pC->xDec[z].decodeControl.rdSampleCount = 0;
 
             // Initialize decoder output circular buffer for selected source
-            pCb = &pAstCfg->xDecOpCb[z];
-            errno = cbInit(sourceSelect, frameLength, FRAMELENGTH, pCb, 0);
+            errno = cbInit(pCbCtl, z, sourceSelect, frameLength, FRAMELENGTH, 0);
             if (errno)
             {
                 SW_BREAKPOINT; // FL: debug
                 return errno;
             }
             // FL: debug
-            cbLog(pCb, 1, "PAF_ASIT_decodeInit:cbInit");
+            cbLog(pCbCtl, z, 1, "PAF_ASIT_decodeInit:cbInit");
             
             if (z != zMD) 
             {
index 9ff831a028aac8008d8abdabe96bc0035c7f7260..7d0b61271fe644663849a3fb7098e0d4b459cafa 100644 (file)
@@ -1629,21 +1629,22 @@ PAF_ASOT_decodeInit(
 )
 {
     PAF_AST_Config *pAstCfg;
-    Int as;                     /* Audio Stream Number (1, 2, etc.) */
-    Int z;                      /* decode/encode counter */
-    Int errno;                  /* error number */
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    Int z;                              /* decode/encode counter */
+    Int errno;                          /* error number */
     Int zO, zS;
-    PAF_AST_DecOpCircBuf *pCb; /* decoder output circular buffer */
 
 
     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
     as = pAstCfg->as;
 
+    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+
     for (z=DECODE1; z < DECODEN; z++)
     {
         // Start decoder output circular buffer reads
-        pCb = &pAstCfg->xDecOpCb[z];
-        errno = cbReadStart(pCb);
+        errno = cbReadStart(pCbCtl, z);
         if (errno)
         {
             TRACE_TERSE1("PAF_ASOT_decodeInit:cbReadStart() error=%d", errno);
@@ -1651,7 +1652,7 @@ PAF_ASOT_decodeInit(
             return errno;
         }
         // FL: debug
-        cbLog(pCb, 1, "PAF_ASOT_decodeInit:cbReadStart");
+        cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeInit:cbReadStart");
     }
     
     // TODO: move this to start of this function so that it doesn't affect IO timing
@@ -1825,14 +1826,16 @@ PAF_ASOT_decodeStream(
 )
 {
     PAF_AST_Config *pAstCfg;
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
     Int z;                              /* decode/stream counter */
-    PAF_AST_DecOpCircBuf *pCb;          /* decoder output circular buffer */
     PAF_AudioFrame *pAfRd;
     Int cbErrno;
     Int errno;
 
 
     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
+    
+    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
 
     for (z=DECODE1; z < DECODEN; z++) 
     {
@@ -1841,9 +1844,8 @@ PAF_ASOT_decodeStream(
         //
         // (***) FL: read circular buffer
         //
-        pCb = &pAstCfg->xDecOpCb[z];
         pAfRd = pAstCfg->xStr[zS].pAudioFrame;
-        cbErrno = cbReadAf(pCb, pAfRd);
+        cbErrno = cbReadAf(pCbCtl, z, pAfRd);
         if (cbErrno != 0)
         {
             TRACE_TERSE1("PAF_ASOT_decodeStream:cbReadAf() error=%d", cbErrno);
@@ -1853,7 +1855,7 @@ PAF_ASOT_decodeStream(
         //Log_info0("PAF_ASOT_decodeStream:cbReadAf() complete.");
 
         // FL: debug
-        cbLog(pCb, 1, "PAF_ASOT_decodeStream:cbReadAf");
+        cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeStream:cbReadAf");
         //if (capAfWrite(pAfRd, 0) != CAP_AF_SOK)
         //{
         //    Log_info0("capAfWrite() error");
@@ -2101,21 +2103,22 @@ PAF_ASOT_decodeComplete(
 )
 {
     PAF_AST_Config *pAstCfg;
-    Int as;                     /* Audio Stream Number (1, 2, etc.) */
-    Int z;                      /* decode/encode counter */
-    Int errno;                  /* error number */
-    PAF_AST_DecOpCircBuf *pCb; /* decoder output circular buffer */
+    PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    Int as;                             /* Audio Stream Number (1, 2, etc.) */
+    Int z;                              /* decode/encode counter */
+    Int errno;                          /* error number */
 
     
     pAstCfg = pC->pAstCfg; // get pointer to common (shared) configuration
     as = pAstCfg->as;
     (void)as;  // clear compiler warning in case not used with tracing disabled
 
+    pCbCtl = &pC->pAspmCfg->decOpCircBufCtl; // get pointer to circular buffer control
+    
     for (z=DECODE1; z < DECODEN; z++)
     {
         // Stop decoder output circular buffer reads
-        pCb = &pAstCfg->xDecOpCb[z];
-        errno = cbReadStop(pCb);
+        errno = cbReadStop(pCbCtl, z);
         if (errno)
         {
             TRACE_TERSE1("PAF_ASOT_decodeComplete:cbReadStop() error=%d", errno);
@@ -2123,7 +2126,7 @@ PAF_ASOT_decodeComplete(
             return errno;
         }
         // FL: debug
-        cbLog(pCb, 1, "PAF_ASOT_decodeComplete:cbReadStop");
+        cbLog(pCbCtl, z, 1, "PAF_ASOT_decodeComplete:cbReadStop");
     }
     
     pP->fxns->streamChainFunction(pP, pQ, pC, PAF_ASP_CHAINFRAMEFXNS_FINAL, 0, frame);
index 3d1526dbcecd9342c976d18b13880dd77a231353..3a458a5645f36de1e6dd94d56e0fc3483b879540 100644 (file)
@@ -47,7 +47,7 @@ All rights reserved.
 // Audio Stream Input/Output Task shared
 typedef struct PAF_ASPM_Config 
 {
-    PAF_AST_DecOpCircBufCtrl decOpCircBufCtrl;
+    PAF_AST_DecOpCircBufCtl decOpCircBufCtl; // decoder output circular buffer control
 } PAF_ASPM_Config;
 
 extern PAF_ASPM_Config gPAF_ASPM_config;
index d85d0a28433001e690c440cd47f500d16738089f..f5e1a7448403c1f9d5438a7210d3a2758fcd4bfe 100644 (file)
@@ -49,6 +49,9 @@ All rights reserved.
 #include "paf_heapMgr.h"
 #include "aspMsg_common.h"
 #include "aspMsg_master.h"
+#include "aspDecOpCircBuf_master.h"
+#include "audioStreamProc_master.h" // ASIT/ASOT config
+#include "audioStreamProc_common.h" // ASIT/ASOT/ASDT config
 #include "fwkSim.h"
 
 extern Void ACP_main_cus(Void);     // (*** ?) FL: revisit -- check method of patching alpha codes
@@ -116,6 +119,14 @@ Void taskSysInitFxn(Void)
         return;
     }
     
+    /* Initialize decoder output circular buffer control */
+    status = cbCtlInit(&gPAF_ASPM_config.decOpCircBufCtl, gPAF_AST_config.xDecOpCb);
+    if (status < 0)
+    {
+        Log_info0("TaskSysInit: unable to initialize Decoder Output Circular Buffer Control. Exiting.");
+        return;
+    }
+
     /* Initialize PAF heap manager */
     Log_info0("taskSysInitFxn:pafHeapMgr_init()");
     regionId = SharedRegion_getIdByName("SR_MSMC");