PASDK-538:Update DSP ASP master messaging to use SyncEvents
authorFrank Livingston <frank-livingston@ti.com>
Mon, 26 Feb 2018 22:19:02 +0000 (16:19 -0600)
committerFrank Livingston <frank-livingston@ti.com>
Mon, 26 Feb 2018 22:19:02 +0000 (16:19 -0600)
23 files changed:
pasdk/common/aspMsg_common.h
pasdk/common/ipc_common.h [new file with mode: 0644]
pasdk/paf
pasdk/test_arm/.cproject
pasdk/test_arm/framework/audioStreamDecodeProc.c
pasdk/test_arm/framework/audioStreamDecodeProc_paramsFxns.c
pasdk/test_arm/framework/systemInit.c
pasdk/test_dsp/.cproject
pasdk/test_dsp/application/app.cfg
pasdk/test_dsp/framework/as0.c
pasdk/test_dsp/framework/aspMsg_master.c
pasdk/test_dsp/framework/aspMsg_master.h
pasdk/test_dsp/framework/audioStreamInpDec.c
pasdk/test_dsp/framework/audioStreamInpProc.c
pasdk/test_dsp/framework/audioStreamInpProc.h
pasdk/test_dsp/framework/audioStreamInpProcNewIO.c
pasdk/test_dsp/framework/audioStreamInpProc_paramsFxns.c
pasdk/test_dsp/framework/audioStreamOutInit.c
pasdk/test_dsp/framework/audioStreamOutProc.c
pasdk/test_dsp/framework/audioStreamOutProc.h
pasdk/test_dsp/framework/audioStreamProc_master.c
pasdk/test_dsp/framework/audioStreamProc_master.h
pasdk/test_dsp/framework/systemInit.c

index f2d113dc6e7b8e4847a7834bb7a7e40b209caa80..55caeb362d9d51de4a43068faad4a4d2562b0310 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
-Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
 All rights reserved.
 
 * Redistribution and use in source and binary forms, with or without 
@@ -37,20 +37,16 @@ All rights reserved.
 #define _ASP_MSG_COMMON_H_
 
 #include <xdc/std.h>
-#include <ti/xdais/ialg.h>
 #include <ti/ipc/MessageQ.h>
 
-/* round up the value 'size' to the next 'align' boundary */
+// round up the value 'size' to the next 'align' boundary
 #define ROUNDUP(size, align) \
     (UInt32)(((UInt32)(size) + ((UInt32)(align) - 1)) & ~((UInt32)(align) - 1))
 
-#define MASTER_NAME                     ( "CORE0" ) // DSP is MASTER
-#define SLAVE_NAME                      ( "HOST" )  // ARM is SLAVE
+#define AspMsg_MasterMsgQueName ( "MASTER:MsgQ:01" )    // master MessageQ name
+#define AspMsg_SlaveMsgQueName  ( "%s:MsgQ:01"   )      // slave MessageQ name, %s is each slave's Proc Name
 
-#define AspMsg_MasterMsgQueName         ( "MASTER:MsgQ:01" )
-#define AspMsg_SlaveMsgQueName          ( "%s:MsgQ:01"   ) /* %s is each slave's Proc Name */
-
-#define ASP_MSG_BUF_LEN                 32   // message buffer len, do we really need 32 bytes?
+#define ASP_MSG_BUF_LEN         ( 32 )  // message buffer length in bytes
 
 // ASP (Master-To-)Slave Commands
 typedef enum ASP_Slave_Cmd {
@@ -68,7 +64,7 @@ typedef enum ASP_Slave_Cmd {
     ASP_SLAVE_NCOMMANDS                     // 11
 } ASP_Slave_Cmd;
 
-// ASP (Slave-To-)Master Commands
+// ASP (Slave-To-)Master Command Acknowledgments
 typedef enum ASP_Master_Cmd {
     ASP_MASTER_NULL = ASP_SLAVE_NCOMMANDS,  // 11
     ASP_MASTER_START_DONE,                  // 12
@@ -78,23 +74,21 @@ typedef enum ASP_Master_Cmd {
     ASP_MASTER_DEC_CONTROL_DONE,            // 16
     ASP_MASTER_DEC_ACTIVATE_DONE,           // 17
     ASP_MASTER_DEC_RESET_DONE,              // 18
-    ASP_MASTER_DEC_INFO_DONE,               // 19     // temp
-    ASP_MASTER_DEC_DECODE_DONE,             // 20     // temp
+    ASP_MASTER_DEC_INFO_DONE,               // 19
+    ASP_MASTER_DEC_DECODE_DONE,             // 20
     ASP_MASTER_DEC_DEACTIVATE_DONE          // 21
 } ASP_Master_Cmd;
 
-// ASP Message
-typedef struct ASP_Msg
+// ASP message
+typedef struct AspMsg
 {
     MessageQ_MsgHeader reserved;
     
-    UInt32  cmd;        // command
-    UInt16  procId;     // processor Id of sender
-    Uint16  expectResp; // whether response expected from receiver + align buf to 32-bit boundary
-    UInt32  messageId;  // MB bit: response bit, LS 31 bits: message Id
-    Char    buf[ASP_MSG_BUF_LEN];    // buffer for message parameters
-} ASP_Msg;
-
+    UInt16  procId;                 // processor Id of sender
+    UInt32  messageId;              // MB bit: ack bit, LS 31 bits: message Id
+    UInt32  cmd;                    // command
+    Char    buf[ASP_MSG_BUF_LEN];   // buffer for message parameters
+} AspMsg;
 
 
 #endif /* _ASP_MSG_COMMON_H_ */
diff --git a/pasdk/common/ipc_common.h b/pasdk/common/ipc_common.h
new file mode 100644 (file)
index 0000000..2f0dc06
--- /dev/null
@@ -0,0 +1,44 @@
+
+/*
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
+All rights reserved.
+
+* Redistribution and use in source and binary forms, with or without 
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of Texas Instruments Incorporated nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+#ifndef _IPC_COMMON_H_
+#define _IPC_COMMON_H_
+
+#include <xdc/std.h>
+
+#define IPC_MASTER_NAME                 ( "CORE0" ) // DSP is MASTER
+#define IPC_SLAVE_NAME                  ( "HOST" )  // ARM is SLAVE
+\
+#endif /* _ASP_MSG_COMMON_H_ */
index 6ae9257cdb624df7a5b2cd51d8ae22e32bd84658..42e6561956cfe763e1713d22ad06c7c7a449da6a 160000 (submodule)
--- a/pasdk/paf
+++ b/pasdk/paf
@@ -1 +1 @@
-Subproject commit 6ae9257cdb624df7a5b2cd51d8ae22e32bd84658
+Subproject commit 42e6561956cfe763e1713d22ad06c7c7a449da6a
index 242a25fb6a7aa25658f4d3501d55d4ee65c71ec6..2ecf259ff28a4c55df46d0f4f3f9b5e906361d7e 100644 (file)
@@ -98,7 +98,6 @@
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/paf/pa/util/da10x_misc&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/paf/pa/util/statusop_common&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/common&quot;"/>
-                                                                       <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/shared&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/test_arm/framework&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/test_arm/framework/itopo&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/test_dsp/sio&quot;"/>
index 370421c73ff3485ad84ea164ca0bf34bd0b831f5..c6bc8526428406c5d1c3f876a6043ab083c25957 100644 (file)
@@ -177,7 +177,7 @@ Void taskAsdpFxn(
     Int outIsErrno;                     // OutIS error number
     // Messaging
     PAF_InpBufConfig *pIpBufConfig;     // IB buffer configuration
-    ASP_Msg *pAspMsg;                   // Rx/Tx MessageQ message
+    AspMsg *pAspMsg;                    // Rx/Tx MessageQ message
     MessageQ_QueueId queId;             // MessageQ ID
     Int status;
     Int zI;
index ba46dc05d8f2be8598ac30bea4d77e1978dfba3c..fce8fbb57afd31c0faeea0f19c9b065e1ab0ddfa 100644 (file)
@@ -39,7 +39,6 @@ All rights reserved.
 
 #include <xdc/std.h>
  
-#include "as0.h"
 #include "audioStreamDecodeProc.h"
  
 // .............................................................................
index ac1b24abd4b5bc397df1904e0efcb355545d4ec4..a69846f47ddefcf47d948aeceaf9a041729f6a1f 100644 (file)
@@ -48,6 +48,7 @@ All rights reserved.
 #include "params.h"
 #include "pafhjt.h"
 #include "paf_heapMgr.h"
+#include "ipc_common.h"
 #include "aspMsg_common.h"
 #include "aspMsg_slave.h"
 #include "aspDecOpCircBuf_slave.h"
@@ -83,7 +84,7 @@ Void taskSysInitFxn(Void)
 
     /* Attach IPC */
     Log_info0("taskSysInitFxn:Ipc_attach()");    
-    remoteProcId = MultiProc_getId(MASTER_NAME);
+    remoteProcId = MultiProc_getId(IPC_MASTER_NAME);
     if (remoteProcId == MultiProc_INVALIDID) {
         System_abort("Improper MultiProc ID\n");
     }
index 86f93bbc903875d4617bd6aacd31ba5174411de8..edadf52d27f3da12dd88e56138023b22d9bbecc8 100644 (file)
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/test_dsp/application/itopo/evmk2g/alpha&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/test_dsp/application/itopo/evmk2g&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/common&quot;"/>
-                                                                       <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/pasdk/shared&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/dolby_ip/ddp/Dolby_Digital_Plus_Decoder_Imp/Source_Code/alpha&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/dolby_ip/mat-thd/Dolby_MAT_Decoder_Imp/Source_Code/alpha&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;${PROC_AUDIO_SDK_ROOT}/dolby_ip/oar/Source_Code&quot;"/>
index 9e145db620fd883a16ec02916a8fc1d869363d3c..43d286cfc96602bf397744b4e773bc8a434a7947 100644 (file)
@@ -77,6 +77,8 @@ var UIAEvt          = xdc.useModule('ti.uia.events.UIAEvt');
 
 var ECM             = xdc.useModule('ti.sysbios.family.c64p.EventCombiner');
 
+xdc.useModule('ti.sysbios.syncs.SyncEvent')
+
 xdc.useModule('ti.sdo.utils.MultiProc');
 
 /*
index af7f4f0c07bda14fb7278be000f1dfc447b2bc6f..421477fae02357c2c722b0ffb9c6ee7b2095b14b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
-Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
 All rights reserved.
 
 * Redistribution and use in source and binary forms, with or without 
@@ -263,44 +263,58 @@ Int
 PAF_DEC_computeFrameLength(
     Int decIdx, 
     Int frameLength, 
-    Int bufferRatio
+    Int bufferRatio,
+    AspMsgMaster_Handle hAspMsgMaster
 )
 {
     Int m, n, o, p;
     // Messaging
     Int argIdx;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
     // dec control message to slave
     argIdx = 0; //  set decIdx
     *(Int *)&decMsgBuf[argIdx] = decIdx;
     argIdx += sizeof(Int); // set decCtrlCmd
     *(IALG_Cmd *)&decMsgBuf[argIdx] = DEC_MINSAMGEN;
-    if(AspMsgSend(ASP_SLAVE_DEC_CONTROL, ASP_MASTER_DEC_CONTROL_DONE,
-                  decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
+    status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_CONTROL, decMsgBuf);
+    if (status != ASP_MSG_NO_ERR)
     {
         SW_BREAKPOINT; // temporary
-        return -1; // temporary        
-    }    
-    else 
+        return -1; // temporary
+    }
+    status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_CONTROL_DONE, decMsgBuf, TRUE);
+    if (status != ASP_MSG_NO_ERR)
+    {
+        SW_BREAKPOINT; // temporary
+        return -1; // temporary
+    }
+    else
     {
         argIdx = 0; // get decCtrlRet
         m = *(Int *)&decMsgBuf[argIdx];
-        TRACE_TERSE1("decCtrlRet (m)=%d", m);        
+        TRACE_TERSE1("decCtrlRet (m)=%d", m);
     }
-
+    
     // dec control message to slave
     argIdx = 0; // set decIdx
     *(Int *)&decMsgBuf[argIdx] = decIdx;
     argIdx += sizeof(Int); // set decCtrlCmd
     *(IALG_Cmd *)&decMsgBuf[argIdx] = DEC_MAXSAMGEN;
-    if(AspMsgSend(ASP_SLAVE_DEC_CONTROL, ASP_MASTER_DEC_CONTROL_DONE,
-                  decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
+    status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_CONTROL, decMsgBuf);
+    if (status != ASP_MSG_NO_ERR)
     {
         SW_BREAKPOINT; // temporary
-        return -1; // temporary        
-    }    
-    else 
+        return -1; // temporary
+    }
+    status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_CONTROL_DONE, decMsgBuf, TRUE);
+    if (status != ASP_MSG_NO_ERR)
+    {
+        SW_BREAKPOINT; // temporary
+        return -1; // temporary
+    }
+    else
     {
         argIdx = 0; // get decCtrlRet
         n = *(Int *)&decMsgBuf[argIdx];
index b2b515296771e8ece16b4b9b80261608e3ec9cbc..26bb029987ff24ec58469cc043273ba340e491c9 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
-Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
 All rights reserved.
 
 * Redistribution and use in source and binary forms, with or without 
@@ -33,6 +33,7 @@ All rights reserved.
 *
 */
 
+#include <string.h>
 #include <xdc/std.h>
 #include <xdc/runtime/Diags.h>
 #include <xdc/runtime/Error.h>
@@ -40,9 +41,8 @@ All rights reserved.
 #include <xdc/runtime/Log.h>
 #include <xdc/runtime/Memory.h>
 #include <xdc/runtime/System.h>
-#include <string.h>
+#include <ti/sysbios/BIOS.h>
 #include <ti/sysbios/heaps/HeapBuf.h>
-
 #include <ti/ipc/MessageQ.h>
 #include <ti/ipc/MultiProc.h>
 #include <ti/ipc/SharedRegion.h>
@@ -52,18 +52,15 @@ All rights reserved.
 #include "audioStreamProc_common.h"
 #include "common.h"
 
-#define AspMsg_MasterToSlaveMsgHeapId ( 0 )
-
-AspMsgMaster_Module gAspMsgMaster;
-AspMsgMaster_Handle hAspMsgMaster=&gAspMsgMaster;
-
-Uint32 gMessageId;
-
 /* Initialize ASP master messaging */
 Int AspMsgMaster_init(
-    AspMsgMaster_Handle hAspMsgMaster, 
-    UInt16 remoteProcId, 
-    UInt16 numMsgs
+    AspMsgMaster_Handle hAspMsgMaster,  // message master handle
+    UInt16 remoteProcId,                // remote processor Id
+    UInt16 heapId,                      // heap Id for message pool
+    UInt16 numMsgs,                     // number of messages in message pool
+    SyncEvent_Handle syncEventHandle,   // sync event handle
+    Event_Handle eventHandle,           // event handle
+    UInt eventId                        // event Id
 )
 {
     Int             status = ASP_MSG_MASTER_SOK;
@@ -74,27 +71,41 @@ Int AspMsgMaster_init(
     MessageQ_Params msgqParams;
     char            msgqName[32];
     UInt16          regionId;
-
+    UInt8           i;
 
     Log_print0(Diags_ENTRY, "AspMsgMaster_init(): -->");
     Log_info0("AspMsgMaster_init(): -->");
     
     // set default values
+    hAspMsgMaster->masterProcId = 0;
+    hAspMsgMaster->slaveProcId = 0;
     hAspMsgMaster->masterQue = NULL;
-    hAspMsgMaster->slaveQue = MessageQ_INVALIDMESSAGEQ;
-    hAspMsgMaster->heapId = AspMsg_MasterToSlaveMsgHeapId;
+    hAspMsgMaster->slaveQueId = MessageQ_INVALIDMESSAGEQ;
+    hAspMsgMaster->heapId = heapId;
+    hAspMsgMaster->numMsgs = numMsgs;
+    hAspMsgMaster->heap = NULL;
     hAspMsgMaster->msgSize = 0;
+    hAspMsgMaster->poolSize = 0;
+    hAspMsgMaster->store = NULL;            // placed in Shared Region 0
     hAspMsgMaster->messageId = 0;
+    hAspMsgMaster->saveMsgId = NULL;        // placed in Shared Region 0
+    hAspMsgMaster->saveMsgWrtIdx = 0;
+    hAspMsgMaster->saveMsgRdIdx = 0;
+    hAspMsgMaster->numSaveMsgId = 0;
+    hAspMsgMaster->syncEventHandle = NULL;
+    hAspMsgMaster->eventHandle =  NULL;
+    hAspMsgMaster->eventId = Event_Id_NONE;
     
     // set processor Ids
     hAspMsgMaster->masterProcId = MultiProc_self();
     hAspMsgMaster->slaveProcId = remoteProcId;
     
-    regionId = SharedRegion_getIdByName("SR_0"); // get IPC shared region Id
+    // get IPC shared region Id
+    regionId = SharedRegion_getIdByName("SR_0"); // message pool memory hard-coded in Shared Region 0
 
     // compute message size to fill entire cache lines
     align = SharedRegion_getCacheLineSize(regionId);
-    hAspMsgMaster->msgSize = ROUNDUP(sizeof(ASP_Msg), align);
+    hAspMsgMaster->msgSize = ROUNDUP(sizeof(AspMsg), align);
     
     // compute message pool size
     hAspMsgMaster->poolSize = hAspMsgMaster->msgSize * numMsgs;
@@ -102,6 +113,13 @@ Int AspMsgMaster_init(
     // acquire message pool memory
     srHeap = (IHeap_Handle)SharedRegion_getHeap(regionId);
     hAspMsgMaster->store = Memory_alloc(srHeap, hAspMsgMaster->poolSize, align, NULL);
+    if (hAspMsgMaster->store == NULL)
+    {
+        Log_error0("AspMsgMaster_init(): failed allocating message store");
+        status = ASP_MSG_MASTER_MSGPOOL_MALLOC_FAIL;
+        Log_print1(Diags_INFO, "AspMsgMaster_init(): <-- status=%d", (IArg)status);
+        return status;
+    }
 
     // create a heap in shared memory for message pool
     HeapBuf_Params_init(&heapParams);
@@ -115,8 +133,8 @@ Int AspMsgMaster_init(
     hAspMsgMaster->heap = HeapBuf_create(&heapParams, &eb);
     if (hAspMsgMaster->heap == NULL) 
     {
-        Log_error0("AspMsgMaster_init(): failed creating message pool");
-        status = ASP_MSG_MASTER_HEAPBUF_CREATE_FAIL;
+        Log_error0("AspMsgMaster_init(): failed creating heap for message pool");
+        status = ASP_MSG_MASTER_MSGPOOL_HEAPBUF_CREATE_FAIL;
         Log_print1(Diags_INFO, "AspMsgMaster_init(): <-- status=%d", (IArg)status);
         return status;
     }
@@ -133,6 +151,17 @@ Int AspMsgMaster_init(
 
     // create local message queue (inbound messages)
     MessageQ_Params_init(&msgqParams);
+    if (syncEventHandle != NULL)
+    {
+        // Store info related to SyncEvent (non-default) synchronizer.
+        // It is assumed the SyncEvent was created using this Event and Event Id.
+        hAspMsgMaster->syncEventHandle = syncEventHandle;
+        hAspMsgMaster->eventHandle = eventHandle;
+        hAspMsgMaster->eventId = eventId;
+        
+        // Initialize SyncEvent synchronizer for Master MessageQ creation.
+        msgqParams.synchronizer = syncEventHandle;
+    }
 
     hAspMsgMaster->masterQue = MessageQ_create(NULL, &msgqParams);
     if (hAspMsgMaster->masterQue == NULL) 
@@ -145,15 +174,11 @@ Int AspMsgMaster_init(
 
     // open the remote message queue
     System_sprintf(msgqName, AspMsg_SlaveMsgQueName, MultiProc_getName(remoteProcId));
-
     Log_info0("AspMsgMaster_init(): MessageQ_open() start");
     do {
-        status = MessageQ_open(msgqName, &hAspMsgMaster->slaveQue);
+        status = MessageQ_open(msgqName, &hAspMsgMaster->slaveQueId);
         Log_info1("MessageQ_open() status=%d", status);
-        //Task_sleep(1);
     } while (status == MessageQ_E_NOTFOUND);
-    Log_info0("AspMsgMaster_init(): MessageQ_open() finish");
-
     if (status < 0) 
     {
         Log_error0("AspMsgMaster_init(): failed opening MessageQ");
@@ -161,84 +186,212 @@ Int AspMsgMaster_init(
         Log_print1(Diags_INFO, "AspMsgMaster_init(): <-- status=%d", (IArg)status);
         return status;
     }
+    Log_info0("AspMsgMaster_init(): MessageQ_open() finish");
+
+    // allocate and initialize send message Id array
+    hAspMsgMaster->saveMsgId = Memory_alloc(srHeap, numMsgs * sizeof(UInt32), align, NULL); // send message Id array hard-coded in Shared Region 0
+    if (hAspMsgMaster->saveMsgId != NULL)
+    {
+        for (i = 0; i < hAspMsgMaster->numMsgs; i++)
+        {
+            hAspMsgMaster->saveMsgId[i] = (UInt32)(1<<31); // mark as unused
+        }
+    }
+    else
+    {
+        Log_error0("AspMsgMaster_init(): failed creating send message Id array");
+        status = ASP_MSG_MASTER_SAVEMSGID_MALLOC_FAIL;
+        Log_print1(Diags_INFO, "AspMsgMaster_init(): <-- status=%d", (IArg)status);
+        return status;
+    }
 
     Log_print0(Diags_INFO, "AspMsgMaster_init(): ASP Master messaging ready");
     Log_info0("AspMsgMaster_init(): ASP Master messaging ready");
     
     Log_print1(Diags_EXIT, "<-- AspMsgMaster_init(): %d", (IArg)status);    
-    return 0;
+    Log_info1("<-- AspMsgMaster_init(): %d", (IArg)status);
+    
+    return ASP_MSG_MASTER_SOK;
 }
 
-/************************************************************************************
- * ASP message sending function. Refer to aspMsg_master.h for detailed description.
-************************************************************************************/
-Int AspMsgSend(UInt32 sndCmd, UInt32 ackCmd, char *sndMsgBuf, char *ackMsgBuf)
+// ASP message send function
+Int AspMsgSnd(
+    AspMsgMaster_Handle hAspMsgMaster,  // message master handle
+       UInt32 sndCmd,                      // command sent from master to slave
+       char *sndMsgBuf                     // message buffer for message sent from master to slave
+)
 {
-    ASP_Msg* pAspMsg;                   /* Messaging */
+    AspMsg *pAspMsg;
     Int status;
 
     // allocate message
-    pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
-    if (pAspMsg == NULL) {
-        TRACE_TERSE0("MessageQ_alloc() failure.");
-        return (ASP_MSG_ERR_QUEUE_ALLOC);
+    pAspMsg = (AspMsg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
+    if (pAspMsg == NULL) 
+    {
+        Log_info0("AspMsgSnd(): MessageQ_alloc() failure.");
+        return ASP_MSG_ERR_QUEUE_ALLOC;
     }
 
-    // set the return address in the message header and fill in message payload
+    // set return queue in the message header and fill in message payload
     MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);
-    pAspMsg->cmd = sndCmd;
     pAspMsg->procId = hAspMsgMaster->masterProcId;
-    pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
-    pAspMsg->expectResp = TRUE;
+    pAspMsg->messageId = hAspMsgMaster->messageId;
+    pAspMsg->cmd = sndCmd;
 
     // copy the message provided by caller
-    if(sndMsgBuf != NULL) {
-        memcpy(pAspMsg->buf, sndMsgBuf, ASP_MSG_BUF_LEN*sizeof(char));
+    if (sndMsgBuf != NULL) 
+    {
+        memcpy(pAspMsg->buf, sndMsgBuf, ASP_MSG_BUF_LEN*sizeof(Char));
     }
 
     // send the message
-    TRACE_TERSE3("ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-    status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);
-    if (status != MessageQ_S_SUCCESS) {
-        TRACE_TERSE0("MessageQ_put() failure.");
+    Log_info3("AspMsgSnd(): Tx message: procId=%d, messageId=0x%04x, cmd=%d", pAspMsg->procId, pAspMsg->messageId, pAspMsg->cmd);
+    status = MessageQ_put(hAspMsgMaster->slaveQueId, (MessageQ_Msg)pAspMsg);
+    if (status != MessageQ_S_SUCCESS) 
+    {
+        Log_info0("AspMsgSnd(): MessageQ_put() failure.");
         MessageQ_free((MessageQ_Msg)pAspMsg);
-        return (ASP_MSG_ERR_QUEUE_PUT);
+        return ASP_MSG_ERR_QUEUE_PUT;
     }
 
-    // wait for complete message from slave
-    status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
-    if (status != MessageQ_S_SUCCESS) {
-        TRACE_TERSE0("MessageQ_get() failure.");
+    // Save message Id for ack message validation.
+    //  Expect ack messages in same order as sent messages.
+    //  Multiple messages can be sent between response messages.
+    hAspMsgMaster->saveMsgId[hAspMsgMaster->saveMsgWrtIdx] = hAspMsgMaster->messageId;
+    hAspMsgMaster->saveMsgWrtIdx++;
+    if (hAspMsgMaster->saveMsgWrtIdx >= hAspMsgMaster->numMsgs)
+    {
+        hAspMsgMaster->saveMsgWrtIdx = 0;
+    }
+    hAspMsgMaster->numSaveMsgId++;
+    if (hAspMsgMaster->numSaveMsgId > hAspMsgMaster->numMsgs)
+    {
+        Log_info0("AspMsgSnd(): Tx message overflow.");
         MessageQ_free((MessageQ_Msg)pAspMsg);
-        return (ASP_MSG_ERR_QUEUE_GET);
+        return ASP_MSG_ERR_SEND_OVR;
     }
 
+    // increment message Id for next message to send
+    hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31); // mask MSB, message Id is LS 31 bits
+    
+    return ASP_MSG_NO_ERR;
+} /* AspMsgSnd */
+
+// Message receive acknowledge function
+Int                                     // returned status
+AspMsgRcvAck(
+    AspMsgMaster_Handle hAspMsgMaster,  // message master handle
+       UInt32 ackCmd,                      // acknowledgment sent from slave to master
+       char *ackMsgBuf,                    // message buffer for acknowledgment message sent from slave to master
+    Bool pendOnEvent                    // whether to pend on Event synchronizer
+)
+{
+    AspMsg *pAspMsg;
+    Bool validMsg;
+    Int status;
+
+    if (hAspMsgMaster->syncEventHandle == NULL)
+    {
+        // wait for complete message from slave
+        // pend on default Semaphore synchronizer
+        // read message upon sync
+        status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);    
+        if (status != MessageQ_S_SUCCESS)
+        {
+            Log_info0("AspMsgRcvAck(): MessageQ_get() failure.");
+            if (pAspMsg != NULL)
+            {
+                MessageQ_free((MessageQ_Msg)pAspMsg);
+            }
+            return ASP_MSG_ERR_QUEUE_GET;
+        }
+    }
+    else
+    {
+        if (pendOnEvent == TRUE)
+        {
+            // wait for complete message from slave
+            // pend on non-default SyncEvent synchronizer
+            Event_pend(hAspMsgMaster->eventHandle, Event_Id_NONE, hAspMsgMaster->eventId, BIOS_WAIT_FOREVER);
+        }
+        else
+        {
+            // Sync already performed outside this function or polling
+            ;
+        }
+        
+        // Read message from MessageQ
+        status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0);
+        if (status != MessageQ_S_SUCCESS)
+        {
+            if (status == MessageQ_E_TIMEOUT)
+            {
+                Log_info0("AspMsgRcvAck(): MessageQ_get() timeout.");
+                return ASP_MSG_ERR_QUEUE_TIMEOUT;
+            }
+            else
+            {
+                Log_info0("AspMsgRcvAck(): MessageQ_get() failure.");
+                if (pAspMsg != NULL)
+                {
+                    MessageQ_free((MessageQ_Msg)pAspMsg);
+                }
+                return ASP_MSG_ERR_QUEUE_GET;
+            }
+        }
+    }
+    
     // check if returned message is valid
-    if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
-        (pAspMsg->cmd != ackCmd) ||
-        (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31)))) {
-        TRACE_TERSE3("ERROR: ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
+    validMsg = ((pAspMsg->procId == hAspMsgMaster->slaveProcId) &&  // check ack message from slave
+                (pAspMsg->messageId & (UInt32)(1<<31)) &&           // check message ack bit set by slave
+                (pAspMsg->cmd == ackCmd));                          // check command ack from slave
+    if (validMsg == FALSE)
+    {
+        Log_info3("AspMsgRcvAck(): Rx Message ACK ERROR: procId=%d, messageId=0x%04x, cmd=%d", pAspMsg->procId, pAspMsg->messageId, pAspMsg->cmd);
         MessageQ_free((MessageQ_Msg)pAspMsg);
-        return(ASP_MSG_ERR_ACKNOWLEDGE);
+        return ASP_MSG_ERR_ACKNOWLEDGE;
     }
 
-    hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
-    TRACE_TERSE3("ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
+    // Compare response message Id against message Id of least recently sent message
+    validMsg = ((pAspMsg->messageId & (UInt32)~(1<<31)) == hAspMsgMaster->saveMsgId[hAspMsgMaster->saveMsgRdIdx]);
+    if (validMsg == TRUE)
+    {
+        hAspMsgMaster->saveMsgId[hAspMsgMaster->saveMsgRdIdx] = (UInt32)(1<<31); // mark location unused
+        hAspMsgMaster->saveMsgRdIdx++;
+        if (hAspMsgMaster->saveMsgRdIdx >= hAspMsgMaster->numMsgs)
+        {
+            hAspMsgMaster->saveMsgRdIdx = 0;
+        }
+        hAspMsgMaster->numSaveMsgId--;
+        if (hAspMsgMaster->numSaveMsgId < 0)
+        {
+            Log_info0("AspMsgRcvAck(): Rx message underflow.");
+            MessageQ_free((MessageQ_Msg)pAspMsg);
+            return ASP_MSG_ERR_RECEIVE_UND;
+        }
+    }
+    else
+    {
+        TRACE_TERSE3("AspMsgRcvAck(): Rx Message ACK ERROR: procId=%d, messageId=0x%04x, cmd=%d", pAspMsg->procId, pAspMsg->messageId, pAspMsg->cmd);
+        MessageQ_free((MessageQ_Msg)pAspMsg);
+        return ASP_MSG_ERR_ACKNOWLEDGE;
+    }
 
     // get the returned message
-    if(ackMsgBuf != NULL) {
+    if (ackMsgBuf != NULL) 
+    {
         memcpy(ackMsgBuf, pAspMsg->buf, ASP_MSG_BUF_LEN*sizeof(char));
     }
 
     // free the message 
     status = MessageQ_free((MessageQ_Msg)pAspMsg);
-    if (status != MessageQ_S_SUCCESS) {
-        TRACE_TERSE0("MessageQ_free() failure.");
-        return (ASP_MSG_ERR_QUEUE_FREE);
+    if (status != MessageQ_S_SUCCESS) 
+    {
+        Log_info0("AspMsgRcvAck(): MessageQ_free() failure.");
+        return ASP_MSG_ERR_QUEUE_FREE;
     }
 
     // No error in messaging operation, even though there
-    // may be error in returned (acknowledgement) message.
-    return (ASP_MSG_NO_ERR);
-} /* AspMsgSend */
-
+    // may be error in returned (acknowledgment) message.
+    return ASP_MSG_NO_ERR;
+} /* AspMsgRcvAck */
index 46307fe8b2a887a49f161475af4cf2b1c2f69300..7fb507337104c65335db8b930d885a41f8d9370d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
-Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
+Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
 All rights reserved.
 
 * Redistribution and use in source and binary forms, with or without 
@@ -38,61 +38,96 @@ All rights reserved.
 
 #include <xdc/std.h>
 #include <ti/sysbios/heaps/HeapBuf.h>
+#include <ti/sysbios/knl/Event.h>
+#include <ti/sysbios/syncs/SyncEvent.h>
 #include <ti/ipc/MessageQ.h>
 
-#define ASP_MSG_MASTER_SOK                      (  0 )
-#define ASP_MSG_MASTER_HEAPBUF_CREATE_FAIL      ( -1 )
-#define ASP_MSG_MASTER_MSGQ_REGHEAP_FAIL        ( -2 )
-#define ASP_MSG_MASTER_MASTER_MSGQ_CREATE_FAIL  ( -3 )
-#define ASP_MSG_MASTER_SLAVE_MSGQ_OPEN_FAIL     ( -4 )
+// Error return codes
+#define ASP_MSG_MASTER_SOK                          (  0 )
+#define ASP_MSG_MASTER_MSGPOOL_MALLOC_FAIL          ( -1 )
+#define ASP_MSG_MASTER_MSGPOOL_HEAPBUF_CREATE_FAIL  ( -2 )
+#define ASP_MSG_MASTER_MSGQ_REGHEAP_FAIL            ( -3 )
+#define ASP_MSG_MASTER_MASTER_MSGQ_CREATE_FAIL      ( -4 )
+#define ASP_MSG_MASTER_SLAVE_MSGQ_OPEN_FAIL         ( -5 )
+#define ASP_MSG_MASTER_SAVEMSGID_MALLOC_FAIL        ( -6 )
 
-#define ASP_MSG_MASTER_DEF_NUMMSGS  ( 4 )
+// Error return codes for function AspMsgSend & AspMsgRcvAck
+#define ASP_MSG_NO_ERR                              (  0 )
+#define ASP_MSG_ERR_QUEUE_ALLOC                     ( -1 )
+#define ASP_MSG_ERR_QUEUE_PUT                       ( -2 )
+#define ASP_MSG_ERR_QUEUE_GET                       ( -3 )
+#define ASP_MSG_ERR_QUEUE_TIMEOUT                   ( -4 )
+#define ASP_MSG_ERR_QUEUE_FREE                      ( -5 )
+#define ASP_MSG_ERR_ACKNOWLEDGE                     ( -6 )
+#define ASP_MSG_ERR_SEND_OVR                        ( -7 )
+#define ASP_MSG_ERR_RECEIVE_UND                     ( -8 )
 
-/* Error messages for function AspMsgSend */
-#define ASP_MSG_NO_ERR                          (  0 )
-#define ASP_MSG_ERR_QUEUE_ALLOC                 ( -1 )
-#define ASP_MSG_ERR_QUEUE_PUT                   ( -2 )
-#define ASP_MSG_ERR_QUEUE_GET                   ( -3 )
-#define ASP_MSG_ERR_QUEUE_FREE                  ( -4 )
-#define ASP_MSG_ERR_ACKNOWLEDGE                 ( -5 )
+#define ASP_MSG_MASTER_DEF_NUMMSGS                  (  4 )
 
-/* module structure */
+// module structure
 typedef struct AspMsgMaster_Module
 {
     UInt16              masterProcId;       // master processor id
     UInt16              slaveProcId;        // slave processor id
     MessageQ_Handle     masterQue;          // created locally
-    MessageQ_QueueId    slaveQue;           // opened remotely
+    MessageQ_QueueId    slaveQueId;         // created remotely, opened locally
     UInt16              heapId;             // MessageQ heapId
+    UInt16              numMsgs;            // number of messages
     HeapBuf_Handle      heap;               // message heap
     Int                 msgSize;            // aligned size of message
     Int                 poolSize;           // size of message pool
     Ptr                 store;              // memory store for message pool
-    UInt32              messageId;          // MS bit: reply bit, LS 31 bits: message id
+    UInt32              messageId;          // Next send message Id. Format: Id contained in LS 31 bits, MS bit is 0.
+    UInt32              *saveMsgId;         // Send message Id array. Array member format: Id contained in LS 31 bits, MS bit is 0.
+    UInt8               saveMsgWrtIdx;      // index of next location in saveMessageId[] for write (message send)
+    UInt8               saveMsgRdIdx;       // index of next location in saveMessageId[] for read (message receive)
+    Int8                numSaveMsgId;       // number of saved message Ids
+    SyncEvent_Handle    syncEventHandle;    // sync event handle
+    Event_Handle        eventHandle;        // event handle
+    UInt                eventId;            // event Id
 } AspMsgMaster_Module;
 
-/* module handle */
+// module handle
 typedef AspMsgMaster_Module *   AspMsgMaster_Handle;
 
-/* Initialize ASP master messaging */
-Int AspMsgMaster_init(
-    AspMsgMaster_Handle hAspMsgMaster, 
-    UInt16 remoteProcId, 
-    UInt16 numMsgs
+// Initialize ASP master messaging
+Int                                     // returned status
+AspMsgMaster_init(
+    AspMsgMaster_Handle hAspMsgMaster,  // message master handle
+    UInt16 remoteProcId,                // remote processor Id
+    UInt16 heapId,                      // heap Id for message pool
+    UInt16 numMsgs,                     // number of messages in message pool
+    SyncEvent_Handle syncEventHandle,   // sync event handle
+    Event_Handle eventHandle,           // event handle
+    UInt eventId                        // event Id    
 );
 
-extern AspMsgMaster_Handle hAspMsgMaster;
+/* 
+ * ASP message send function
+ *
+ * Description: 
+ *      This function sends a message from the master to the slave processor.
+ */
+Int                                     // returned status
+AspMsgSnd(
+    AspMsgMaster_Handle hAspMsgMaster,  // message master handle
+       UInt32 sndCmd,                      // command sent from master to slave
+       char *sndMsgBuf                     // message buffer for message sent from master to slave
+);
 
-/* ASP message sending function
- * Description: This function can be used to send message from the master processor
- *              to slave processor. It uses the global handle hAspMsgMaster for
- *              message passing.
+/* 
+ * ASP message receive acknowledge function
+ *
+ * Description: 
+ *      This function receives an acknowledgment message from the slave to the master processor.
  */
-Int                    // returned error message
-AspMsgSend(
-       UInt32 sndCmd,     // command that is sent from master to slave
-       UInt32 ackCmd,     // acknowledgement that comes back from slave to master
-       char *sndMsgBuf,   // message buffer for message sent to slave
-       char *ackMsgBuf);  // message buffer for acknowledgement from slave
+Int                                     // returned status
+AspMsgRcvAck(
+    AspMsgMaster_Handle hAspMsgMaster,  // message master handle
+       UInt32 ackCmd,                      // acknowledgment sent from slave to master
+       char *ackMsgBuf,                    // message buffer for acknowledgment message sent from slave to master
+    Bool pendOnEvent                    // whether to pend on Event synchronizer
+);
+
 
 #endif /* _ASP_MSG_MASTER_H_ */
index cc48d809c1e8f7b61042b22f8e5ee4d5da1a98e7..fe2bb19b3474b7500be2444e5a237218b392a7c9 100644 (file)
@@ -83,8 +83,10 @@ static Int decDecodeFinalTest(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *
                               PAF_ASIT_Config *pAsitCfg);
 Int decCheckMajorAu(PAF_AST_Config *pAstCfg);
 
+#if 0
 Int AspMsgSnd(UInt32 sndCmd, char *sndMsgBuf);
 Int AspMsgAck(UInt32 ackCmd, char *ackMsgBuf);
+#endif
 
 extern UInt32 gCbWrtAfErrCnt;
 
@@ -167,13 +169,15 @@ Int decDecodeFsm(
         case DEC_STATE_INFO_ACK_DECODE_SND:
             //if(decMsg != DEC_MSGMSK_INFOACK) {
                 // only DEC_MSGMSK_INFOACK is expected in this state
-            if((decMsg&DEC_MSGMSK_INFOACK) != DEC_MSGMSK_INFOACK) {
-                // During debugging, it is possible that INPDATA and INFOACK
-                // come at the same time (e.g. due to breaking point).
-                decErr = DEC_ERR_WRONG_MSG;
-            }
-            else {
-                decMsg &= ~DEC_MSGMSK_INFOACK;  // clear the bit mask
+            //if((decMsg&DEC_MSGMSK_INFOACK) != DEC_MSGMSK_INFOACK) {
+            //    // During debugging, it is possible that INPDATA and INFOACK
+            //    // come at the same time (e.g. due to breaking point).
+            //    decErr = DEC_ERR_WRONG_MSG;
+            //}
+            //else {
+                
+            if (decMsg & DEC_MSGMSK_RXACK) {
+                decMsg &= ~DEC_MSGMSK_RXACK;  // clear the bit mask
 
                 // Process the INFO acknowledgment from decoder
                 decErr = decInfoAck(pP, pQ, pAsitCfg);
@@ -206,14 +210,22 @@ Int decDecodeFsm(
                     }
                 }
             }
+            
+            if (decMsg != 0) {
+                decErr = DEC_ERR_WRONG_MSG;
+            }            
         break;
 
         case DEC_STATE_DECODE_ACK:
             // Two different messages may be received: DECACK (decode acknowledgment)
             // or INPDATA (input data ready).
-            if(decMsg & DEC_MSGMSK_DECACK) {
-                decMsg &= ~DEC_MSGMSK_DECACK;
-
+            //if(decMsg & DEC_MSGMSK_DECACK) {
+            //    decMsg &= ~DEC_MSGMSK_DECACK;
+            
+            if (decMsg & DEC_MSGMSK_RXACK)
+            {
+                decMsg &= ~DEC_MSGMSK_RXACK;  // clear the bit mask
+                
                 // Process DECODE ACK from decoder
                 decErr = decDecodeAck(pP, pQ, pAsitCfg);
                 if(decErr == DEC_NO_ERR) {
@@ -239,7 +251,8 @@ Int decDecodeFsm(
                     }
                 }
             }
-            else if(decMsg & DEC_MSGMSK_INPDATA) {
+            
+            if (decMsg & DEC_MSGMSK_INPDATA) {
                 // If we're here, it means decode acknowledgment from decoder
                 // is delayed, i.e., a new frame of input data is ready before
                 // current frame decoding is finished.
@@ -250,7 +263,8 @@ Int decDecodeFsm(
 
                 TRACE_VERBOSE0("decDecodeFsm: receiving INPDATA in DEC_STATE_DECODE_ACK");
             }
-            else {
+            
+            if (decMsg != 0) {
                 decErr = DEC_ERR_WRONG_MSG;
             }
         break;
@@ -371,6 +385,7 @@ static Int decodeInit(
 {
     PAF_AST_Config *pAstCfg;
     PAF_AST_IoInp  *pInp;
+    AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
     Int as;                             /* Audio Stream Number (1, 2, etc.) */
     Int z;                              /* decode/encode counter */
@@ -379,9 +394,11 @@ static Int decodeInit(
     Int argIdx;
     Int8 tempVar8;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
-    pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
-    pInp    = pAsitCfg->pIoInp;
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
+    pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
 
     as = pAstCfg->as;
     (void)as;  // clear compiler warning in case not used with tracing disabled
@@ -420,19 +437,33 @@ static Int decodeInit(
             // send dec activate message to slave
             argIdx = 0; // set decIdx (zone index)
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE,
-                          decMsgBuf, NULL) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_ACTIVATE, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
                 SW_BREAKPOINT; // temporary
                 return ASIP_ERR_DECODE_MSG; // temporary
             }
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_ACTIVATE_DONE, NULL, TRUE);
+            if (status != ASP_MSG_NO_ERR)
+            {
+                TRACE_TERSE0("decodeInit: error in receiving DEC_ACTIVATE_DONE ack message ");
+                SW_BREAKPOINT; // temporary
+                return ASIP_ERR_DECODE_MSG; // temporary
+            }
 
             // send dec reset message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE,
-                          decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_RESET, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
+            {
+                TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
+                SW_BREAKPOINT; // temporary
+                return ASIP_ERR_DECODE_MSG; // temporary
+            }
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_RESET_DONE, decMsgBuf, TRUE);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
                 SW_BREAKPOINT; // temporary
@@ -500,13 +531,16 @@ Int decDecodeComplete( const PAF_ASIT_Params *pP,
                        PAF_ASIT_Config *pAsitCfg)
 {
     PAF_AST_Config *pAstCfg;
+    AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
     Int as;                     /* Audio Stream Number (1, 2, etc.) */
     Int z;                      /* decode/encode counter */
     Int argIdx;
     Int8 tempVar8;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
-    pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
     (void)as;  // clear compiler warning in case not used with tracing disabled
 
@@ -518,11 +552,18 @@ Int decDecodeComplete( const PAF_ASIT_Params *pP,
         {
             TRACE_VERBOSE1("decDecodeComplete: AS%d: finalizing decode", as+z);
 
-            // FL: send dec deactivate message to slave
+            // send dec deactivate message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
-                          decMsgBuf, NULL) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_DEACTIVATE, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
+            {
+                TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
+                SW_BREAKPOINT;
+                return DEC_ERR_COMPLETE_MSG;
+            }
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_DEACTIVATE_DONE, NULL, TRUE);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
                 SW_BREAKPOINT;
@@ -625,6 +666,7 @@ Int decInfoSnd(
 {
     PAF_AST_Config *pAstCfg;
     PAF_AST_IoInp  *pInp;
+    AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
     Int as;                    /* Audio Stream Number (1, 2, etc.) */
     Int z;                     /* input/decode/stream counter */
     Int errno;                 /* error number */
@@ -632,9 +674,11 @@ Int decInfoSnd(
     Int argIdx;
     Int8 tempVar8;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
-    pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
-    pInp    = pAsitCfg->pIoInp;
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
+    pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
 
     // Set decode control: sample rate, emphasis
@@ -714,7 +758,8 @@ Int decInfoSnd(
             // send info message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSnd(ASP_SLAVE_DEC_INFO, decMsgBuf) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_INFO, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
                 SW_BREAKPOINT; // temporary
@@ -735,7 +780,7 @@ Int decInfoSnd(
     } // z=DECODE1 to DECODEN
 
 //////////////////////////////////////////////////////////////////////////////
-    asitPostInfoEvent();
+    //asitPostInfoEvent(); // simulation
 //////////////////////////////////////////////////////////////////////////////
 
     return ASIP_NO_ERR;
@@ -750,6 +795,7 @@ Int decInfoAck(
 {
     PAF_AST_Config *pAstCfg;
     PAF_AST_IoInp  *pInp;
+    AspMsgMaster_Handle hAspMsgMaster;
     Int as;                    /* Audio Stream Number (1, 2, etc.) */
     Int z;                     /* input/decode/stream counter */
     Int errno;                 /* error number */
@@ -760,9 +806,11 @@ Int decInfoAck(
     Int8 tempVar8;
     Int tempVar;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
-    pAstCfg = pAsitCfg->pAstCfg;   // get pointer to common (shared) configuration
-    pInp    = pAsitCfg->pIoInp;
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
+    pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
     zMD = pAstCfg->masterDec;
     zMS = pAstCfg->masterStr;
@@ -779,15 +827,17 @@ Int decInfoAck(
                                      GATEMP_INDEX_DEC);
         if (pInp[zI].hIoPhy  && tempVar8)
         {
-            // FL: acknowledge info message from slave
-            argIdx = 0; // set decIdx
-            *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgAck(ASP_MASTER_DEC_INFO_DONE,
-                         decMsgBuf) != ASP_MSG_NO_ERR)
+            // acknowledge info message from slave
+            errno  = 0;
+            //argIdx = 0; // set decIdx
+            //*(Int32 *)&decMsgBuf[argIdx] = z;
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_INFO_DONE, decMsgBuf, FALSE);
+            if (status != ASP_MSG_NO_ERR)
             {
-                TRACE_TERSE0("decodeInfo: error in receiving DEC_INFO message ");
+                TRACE_TERSE0("decodeInfo: error in receiving DEC_INFO_DONE ack message ");
                 SW_BREAKPOINT; // temporary
-                return -1;     // temporary
+                errno = -1;    // temporary error return value
+                return errno;     // temporary
             }
             else
             {
@@ -854,14 +904,17 @@ static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
 {
     PAF_AST_Config *pAstCfg;
     PAF_AST_IoInp  *pInp;
+    AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
     Int as;                     /* Audio Stream Number (1, 2, etc.) */
     Int z;                      /* decode/stream counter */
     Int argIdx;
     Int cbErrno, errno;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
-    pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
-    pInp    = pAsitCfg->pIoInp;
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
+    pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
     (void)as; // clear compiler warning in case not used with tracing disabled
 
@@ -893,7 +946,8 @@ static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
             errno  = 0;
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSnd(ASP_SLAVE_DEC_DECODE, decMsgBuf) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_DECODE, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
                 SW_BREAKPOINT; // temporary
@@ -925,7 +979,7 @@ static Int decDecodeSnd(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
     } // z=DECODE1 to DECODEN
 
 //////////////////////////////////////////////////////////////////////////////
-    asitPostDecEvent();
+    //asitPostDecEvent(); // simulation
 //////////////////////////////////////////////////////////////////////////////
 
     return ASIP_NO_ERR;
@@ -937,15 +991,18 @@ static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
 {
     PAF_AST_Config *pAstCfg;
     PAF_AST_IoInp  *pInp;
+    AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
     Int as;                     /* Audio Stream Number (1, 2, etc.) */
     Int z;                      /* decode/stream counter */
     Int errno;                  /* error number */
     Int argIdx;
     Int cbErrno;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
-    pAstCfg = pAsitCfg->pAstCfg; // get pointer to common (shared) configuration
-    pInp    = pAsitCfg->pIoInp;
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to common (shared) configuration
+    pInp    = pAsitCfg->pIoInp;                 // get pointer to IO configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
     (void)as; // clear compiler warning in case not used with tracing disabled
 
@@ -957,16 +1014,17 @@ static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
         (void)zS; // clear compiler warning in case not used with tracing disabled
         if ( pInp[zI].hIoPhy && pAstCfg->xDec[z].decodeStatus.mode )
         {
-            // FL: send decode message to slave
+            // receive decode ack message from slave
             errno  = 0;
-            argIdx = 0; // set decIdx
-            *(Int32 *)&decMsgBuf[argIdx] = z;
-            errno = AspMsgAck(ASP_MASTER_DEC_DECODE_DONE, decMsgBuf);
-            if(errno != ASP_MSG_NO_ERR)
+            //argIdx = 0; // set decIdx
+            //*(Int32 *)&decMsgBuf[argIdx] = z;
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_DECODE_DONE, decMsgBuf, FALSE);
+            if (status != ASP_MSG_NO_ERR)
             {
-                TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
+                TRACE_TERSE0("decodeDecode: error in receiving DEC_DECODE_DONE ack message ");
                 SW_BREAKPOINT; // temporary
-                return -1;     // temporary
+                errno = -1; // temporary error return value
+                return errno;
             }
             else
             {
@@ -1004,7 +1062,7 @@ static Int decDecodeAck(const PAF_ASIT_Params *pP, const PAF_ASIT_Patchs *pQ,
 } /* decDecodeAck */
 
 
-
+#if 0
 /************************************************************************************
  * ASP message sending function. Refer to aspMsg_master.h for detailed description.
 ************************************************************************************/
@@ -1103,6 +1161,7 @@ Int AspMsgAck(UInt32 ackCmd, char *ackMsgBuf)
     // may be error in returned (acknowledgement) message.
     return (ASP_MSG_NO_ERR);
 } /* AspMsgAck */
+#endif
 
 
 #if 0
index 141e1e23dd2195211b20730de08747229e945239..48af2d0ae107d09f9149c66ae34a3ab813df0458 100644 (file)
@@ -325,15 +325,25 @@ Int getFrameLengthSourceSel(
 LINNO_DEFN(TaskAsip); /* Line number macros */
 ERRNO_DEFN(TaskAsip); /* Error number macros */
 
+// ASIT ASP messaging
+AspMsgMaster_Module gAsitAspMsgMaster;  // ASIT message master
+
 // ASIT configuration
 #pragma DATA_SECTION(gPAF_ASIT_config, ".globalSectionPafAsitConfig")
 PAF_ASIT_Config gPAF_ASIT_config = {
     NULL,               // taskHandle
     NULL,               // acp
+    &gAsitAspMsgMaster, // hAspMsgMaster
     &gPAF_ASPM_config,  // pAspmCfg, shared ASIT/ASOT configuration
-    &gPAF_AST_config    // pAstCfg, shared ASIT/ASOT/ASDT configuration
+    &gPAF_AST_config,   // pAstCfg, shared ASIT/ASOT/ASDT configuration
+    NULL,               // pIoInp, ASIT IO configuration
+    0                   // inpDec, ASIT state
 };
 
+// For writeDECCommandRestart
+volatile UInt32 gCommandOutputTask_SYNC   =0;
+volatile UInt32 gCommandOutputTask_ACK    =0;
+
 // Global debug counters */
 UInt32 gAsipRxSioReclaimCnt     =0;
 UInt32 gAsipInitCnt             =0;
@@ -352,10 +362,6 @@ UInt32 gCapIbReset_cnt          =0;
 UInt32 gCapIb_cnt               =0;
 UInt32 gCbWrtAfErrCnt           =0; // decoder output circular buffer write error count (returned from ARM to DSP)
                                    
-// For writeDECCommandRestart
-volatile UInt32 gCommandOutputTask_SYNC   =0;
-volatile UInt32 gCommandOutputTask_ACK    =0;
-
 #include "dbgDib.h" // debug
 
 extern struct {
@@ -375,15 +381,14 @@ Void taskAsipFxnInit(
     const PAF_ASIT_Patchs *pQ
 )
 {
-    PAF_ASIT_Config *pAsitCfg;      /* ASIT configuration pointer */
-    PAF_AST_Config *pAstCfg;        /* AST Common (shared) configuration pointer */
-    Int as;                         /* Audio Stream Number (1, 2, etc.) */
-    Int z;                          /* input/encode/stream/decode/output counter */
-    Int i;                          /* phase */
+    PAF_ASIT_Config *pAsitCfg;          // ASIT configuration pointer
+    PAF_AST_Config *pAstCfg;            // AST Common (shared) configuration pointer
+    AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle    
+    Int as;                             // Audio Stream Number (1, 2, etc.)
+    Int z;                              // input/encode/stream/decode/output counter
+    Int i;                              // phase
     Int zMI, zMS, zX;
     Int size;
-    // Messaging
-    ASP_Msg *pAspMsg;
     Int status;
 
     Log_info0("Enter taskAsipFxnInit()");
@@ -408,9 +413,10 @@ Void taskAsipFxnInit(
     //
     // Audio Stream Input Task Configuration (*pAsitCfg):
     //
-    pAsitCfg = &gPAF_ASIT_config;       // initialize pointer to task configuration
-    pAsitCfg->taskHandle = Task_self(); // set task handle
-    pAstCfg = pAsitCfg->pAstCfg;        // get pointer to AST common (shared) configuration
+    pAsitCfg = &gPAF_ASIT_config;               // initialize pointer to task configuration
+    pAsitCfg->taskHandle = Task_self();         // set task handle
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
 
     /* Set Audio Stream Number (1, 2, etc.) */
     as = gBetaPrimeValue + 1;
@@ -499,34 +505,18 @@ Void taskAsipFxnInit(
     Cache_wait();
 
     // send start initialization message to slave
-    pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize); /* allocate message */
-    MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
-    pAspMsg->cmd = ASP_SLAVE_START;                                                     /* fill in message payload */
-    pAspMsg->procId = hAspMsgMaster->masterProcId;
-    pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
-    pAspMsg->expectResp = TRUE;
-    TRACE_MSG3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-    status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);              /* send message */
-    if (status != MessageQ_S_SUCCESS)
+    status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_START, NULL);
+    if (status != ASP_MSG_NO_ERR)
     {
         SW_BREAKPOINT;
     }
+    
     // wait for initialization complete message from slave
     // no other thread is allowed to run until Slave finishes startup
     do {
-        status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, 0);
-    } while ((status != MessageQ_S_SUCCESS) || (pAspMsg->cmd != ASP_MASTER_START_DONE));
-    if ((pAspMsg->procId != hAspMsgMaster->slaveProcId) ||
-        (pAspMsg->cmd != ASP_MASTER_START_DONE) ||
-        (pAspMsg->messageId != (hAspMsgMaster->messageId | ((UInt32)1<<31))))
-    {
-        TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-        SW_BREAKPOINT;
-    }
-    hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
-    TRACE_MSG3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-    status = MessageQ_free((MessageQ_Msg)pAspMsg); /* free the message */
-    if (status != MessageQ_S_SUCCESS)
+        status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_START_DONE, NULL, FALSE);
+    } while (status == ASP_MSG_ERR_QUEUE_TIMEOUT);
+    if (status != ASP_MSG_NO_ERR)
     {
         SW_BREAKPOINT;
     }
@@ -669,16 +659,18 @@ Void taskAsipFxn_Not_Used(
     const PAF_ASIT_Patchs *pQ
 )
 {
-    PAF_ASIT_Config *pAsitCfg;      /* ASIT configuration pointer */
-    PAF_AST_Config *pAstCfg;        /* AST Common (shared) configuration pointer */
-    Int as;                         /* Audio Stream Number (1, 2, etc.) */
-    Int z;                          /* input/encode/stream/decode/output counter */
-    Int errno;                      /* error number */
+    PAF_ASIT_Config *pAsitCfg;          // ASIT configuration pointer
+    PAF_AST_Config *pAstCfg;            // AST Common (shared) configuration pointer
+    AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
+    Int as;                             // Audio Stream Number (1, 2, etc.)
+    Int z;                              // input/encode/stream/decode/output counter
+    Int errno;                          // error number
     Int zMD, zMI, zMS;
     Int loopCount = 0;  // used to stop trace to see startup behavior.        
     // Messaging
     Int8 tempVar8;
     char asipMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
     Log_info0("Enter taskAsipFxn()");
 
@@ -689,6 +681,7 @@ Void taskAsipFxn_Not_Used(
     //
     pAsitCfg = &gPAF_ASIT_config;       // initialize pointer to task configuration
     pAstCfg = pAsitCfg->pAstCfg;        // get pointer to AST common (shared) configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster; // get message master handle
 
     /* Set Audio Stream Number (1, 2, etc.) */
     as = pAstCfg->as;
@@ -960,11 +953,18 @@ Void taskAsipFxn_Not_Used(
 
         // send source select message to slave
         *(Int32 *)&asipMsgBuf[0] = sourceSelect;
-        if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE,
-                      asipMsgBuf, NULL) != ASP_MSG_NO_ERR)
+        status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_SOURCE_SELECT, asipMsgBuf);
+        if (status != ASP_MSG_NO_ERR)
         {
             TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
-            SW_BREAKPOINT;
+            SW_BREAKPOINT;            
+        }
+        // receive source select acknowledge message from slave
+        status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_SOURCE_SELECT_DONE, NULL, TRUE);
+        if (status != ASP_MSG_NO_ERR)
+        {
+            TRACE_VERBOSE0("TaskAsip: error in receiving SOURCE_SELECT_DONE ack message");
+            SW_BREAKPOINT;            
         }
         
         // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
@@ -995,13 +995,19 @@ Void taskAsipFxn_Not_Used(
         Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)+1);
 
         // send dec exit message to slave
-        if( AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL)
-            != ASP_MSG_NO_ERR)
+        status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_EXIT, NULL);
+        if (status != ASP_MSG_NO_ERR)
         {
             TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
             SW_BREAKPOINT;                
         }
-
+        // receive dec exit acknowledge message from slave
+        status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_EXIT_DONE, NULL, TRUE);
+        if (status != ASP_MSG_NO_ERR)
+        {
+            TRACE_VERBOSE0("TaskAsip: error in receiving DEC_EXIT_DONE ack message");
+            SW_BREAKPOINT;                
+        }
     } // End of main processing loop for (;;)
     
     //Log_info0("Exit taskAsipFxn()");
@@ -2278,7 +2284,7 @@ PAF_ASIT_decodeProcessing(
     {
         alg[z] = pAstCfg->xDec[z].decAlg[PAF_SOURCE_PCM];        
     }
-    alg[zMD] = NULL; // decAlgMaster; // FL: alg[] init is on slave
+    alg[zMD] = NULL; // decAlgMaster; // alg[] init is on slave
 
     //
     // Receive and process the data in single-frame buffers
@@ -2621,6 +2627,7 @@ PAF_ASIT_decodeInit(
 {
     PAF_AST_Config *pAstCfg;
     //PAF_AST_DecOpCircBufCtl *pCbCtl;    /* Decoder output circular buffer control */
+    AspMsgMaster_Handle hAspMsgMaster;
     Int as;                             /* Audio Stream Number (1, 2, etc.) */
     Int z;                              /* decode/encode counter */
     Int errno;                          /* error number */
@@ -2630,8 +2637,10 @@ PAF_ASIT_decodeInit(
     Int argIdx;
     Int8 tempVar8;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
     
-    pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
     zMD = pAstCfg->masterDec;
     zMI = pP->zone.master;
@@ -2672,10 +2681,17 @@ PAF_ASIT_decodeInit(
             // send dec activate message to slave
             argIdx = 0; // set decIdx (zone index)
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE, 
-                          decMsgBuf, NULL) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_ACTIVATE, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
+            {
+                TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message");
+                SW_BREAKPOINT; // temporary
+                return -1; // temporary
+            }           
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_ACTIVATE_DONE, NULL, TRUE);
+            if (status != ASP_MSG_NO_ERR)
             {
-                TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
+                TRACE_TERSE0("decodeInit: error in receiving DEC_ACTIVATE_DONE message");
                 SW_BREAKPOINT; // temporary
                 return -1; // temporary
             }           
@@ -2683,18 +2699,25 @@ PAF_ASIT_decodeInit(
             // send dec reset message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE, 
-                          decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_RESET, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
                 SW_BREAKPOINT; // temporary
                 return -1; // temporary
             }
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_RESET_DONE, decMsgBuf, TRUE);
+            if (status != ASP_MSG_NO_ERR)
+            {
+                TRACE_TERSE0("decodeInit: error in receiving DEC_RESET_DONE ack message ");
+                SW_BREAKPOINT; // temporary
+                return -1; // temporary
+            }
             else
             {
                 argIdx = 0; // get decErrno
                 errno = *(Int32 *)&decMsgBuf[argIdx];                
-            }   
+            }
 
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
@@ -2783,6 +2806,7 @@ PAF_ASIT_decodeInfo(
 )
 {
     PAF_AST_Config *pAstCfg;
+    AspMsgMaster_Handle hAspMsgMaster;
     Int as;                    /* Audio Stream Number (1, 2, etc.) */
     Int z;                     /* input/decode/stream counter */
     Int errno;                 /* error number */
@@ -2795,9 +2819,11 @@ PAF_ASIT_decodeInfo(
     Int8 tempVar8;
     Int tempVar;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
     
-    pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
     zMD = pAstCfg->masterDec;
     zMS = pAstCfg->masterStr;
@@ -2925,19 +2951,26 @@ PAF_ASIT_decodeInfo(
             // send info message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE, 
-                          decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_INFO, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
                 SW_BREAKPOINT; // temporary
                 return -1;     // temporary
             }
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_INFO_DONE, decMsgBuf, TRUE);
+            if (status != ASP_MSG_NO_ERR)
+            {
+                TRACE_TERSE0("decodeInfo: error in receiving DEC_INFO_DONE ack message");
+                SW_BREAKPOINT; // temporary
+                return -1;     // temporary
+            }
             else
             {
                 argIdx = 0; // get decErrno
                 errno = *(Int32 *)&decMsgBuf[argIdx];                
-            }             
-
+            }
+            
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();                            
@@ -3134,6 +3167,7 @@ PAF_ASIT_decodeDecode(
 )
 {
     PAF_AST_Config *pAstCfg;
+    AspMsgMaster_Handle hAspMsgMaster;
     Int as;                     /* Audio Stream Number (1, 2, etc.) */
     Int z;                      /* decode/stream counter */
     Int errno;                  /* error number */
@@ -3142,8 +3176,10 @@ PAF_ASIT_decodeDecode(
     Int cbErrno;
     Int frameLength;    
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
-    pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
     (void)as; // clear compiler warning in case not used with tracing disabled
 
@@ -3174,14 +3210,21 @@ PAF_ASIT_decodeDecode(
             // send decode message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE, 
-                          decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_DECODE, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
                 SW_BREAKPOINT; // temporary
                 return -1;     // temporary
             }
-            else 
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_DECODE_DONE, decMsgBuf, TRUE);
+            if (status != ASP_MSG_NO_ERR)
+            {
+                TRACE_TERSE0("decodeDecode: error in receiving DEC_DECODE_DONE ack message ");
+                SW_BREAKPOINT; // temporary
+                return -1;     // temporary
+            }
+            else
             {
                 argIdx = 0; // get decErrno
                 errno = *(Int32 *)&decMsgBuf[argIdx];
@@ -3192,9 +3235,9 @@ PAF_ASIT_decodeDecode(
                     gCbWrtAfErrCnt++;
                     TRACE_TERSE1("CB write error=%d", cbErrno);
                     //SW_BREAKPOINT; // temporary
-                }
-            }           
-
+                }                
+            }
+            
             // invalidate Dec configuration
             Cache_inv(&pAstCfg->xDec[z], sizeof(PAF_AST_Decode), Cache_Type_ALLD, 0);
             Cache_wait();
@@ -3362,13 +3405,16 @@ PAF_ASIT_decodeComplete(
 )
 {
     PAF_AST_Config *pAstCfg;
+    AspMsgMaster_Handle hAspMsgMaster;
     Int as;                     /* Audio Stream Number (1, 2, etc.) */
     Int z;                      /* decode/encode counter */
     Int argIdx;
     Int8 tempVar8;
     char decMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
     
-    pAstCfg = pAsitCfg->pAstCfg; // get pointer to AST common (shared) configuration
+    pAstCfg = pAsitCfg->pAstCfg;                // get pointer to AST common (shared) configuration
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get message master handle
     as = pAstCfg->as;
     (void)as;  // clear compiler warning in case not used with tracing disabled
 
@@ -3395,13 +3441,20 @@ PAF_ASIT_decodeComplete(
             // send dec deactivate message to slave
             argIdx = 0; // set decIdx
             *(Int32 *)&decMsgBuf[argIdx] = z;
-            if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
-                          decMsgBuf, NULL) != ASP_MSG_NO_ERR)
+            status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_DEACTIVATE, decMsgBuf);
+            if (status != ASP_MSG_NO_ERR)
             {
                 TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
                 SW_BREAKPOINT;
                 return -1;
             }
+            status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_DEACTIVATE_DONE, NULL, TRUE);
+            if (status != ASP_MSG_NO_ERR)
+            {
+                TRACE_TERSE0("decodeComplete: error in receiving DEC_DEACTIVATE ack message.");
+                SW_BREAKPOINT;
+                return -1;
+            }
         }
         else 
         {
index a9b791c0a7d075aa293241a4f81588cd9c092123..cff888510a22a72dda6971f39d9543109f7f7d6d 100644 (file)
@@ -41,8 +41,10 @@ All rights reserved.
 #define _ASIP_H_
  
 #include <xdc/std.h>
+#include <ti/sysbios/knl/Event.h>
 #include <ti/sysbios/knl/Task.h>
 
+#include "aspMsg_master.h"
 #include "audioStreamProc_params.h"
 #include "audioStreamProc_patchs.h"
 #include "audioStreamProc_config.h"
@@ -52,9 +54,6 @@ All rights reserved.
 #include "ioBuff.h"
 #include "ioData.h"
 
-// Global debug counter */
-extern Uint32 gTaskAsipCnt; // debug counter for ASP task
-
 struct PAF_ASIT_Params;
 struct PAF_ASIT_Patchs;
 struct PAF_ASIT_Config;
@@ -236,9 +235,10 @@ enum {
 };
 
 
-#define DEC_MSGMSK_INPDATA   0x1
-#define DEC_MSGMSK_INFOACK   0x2
-#define DEC_MSGMSK_DECACK    0x4
+#define DEC_MSGMSK_INPDATA   0x1 // Input data message
+#define DEC_MSGMSK_RXACK     0x2 // Receive acknowledge message
+#define DEC_MSGMSK_INFOACK   0x4 // temp, will be removed
+#define DEC_MSGMSK_DECACK    0x8 // temp, will be removed
 
 
 // Input I/O structure
@@ -295,15 +295,37 @@ typedef struct asipDecProc_s {
 
 // Audio Stream Input Task (ASIT) configuration
 typedef struct PAF_ASIT_Config {
-    Task_Handle taskHandle;      // ASIT handle
-    ACP_Handle acp;              // ASIT local ACP handle
-    PAF_ASPM_Config  *pAspmCfg;  // ASIT/ASOT shared configuration
-    PAF_AST_Config   *pAstCfg;   // ASIT/ASOT/ASDT shared configuration
-    PAF_AST_IoInp    *pIoInp;
-    asipDecProc_t    inpDec;
+    Task_Handle taskHandle;             // ASIT handle
+    ACP_Handle acp;                     // ASIT local ACP handle
+    AspMsgMaster_Handle hAspMsgMaster;  // ASIT message master handle
+    PAF_ASPM_Config *pAspmCfg;          // ASIT/ASOT shared configuration
+    PAF_AST_Config *pAstCfg;            // ASIT/ASOT/ASDT shared configuration
+    PAF_AST_IoInp *pIoInp;              // ASIT IO configuration
+    asipDecProc_t inpDec;
 } PAF_ASIT_Config;
 
 
+// ASIT event IDs
+#define ASIT_EVTMSK_NONE        0x0
+#define ASIT_EVTMSK_INPDATA     0x1 // Input data (Rx McASP EDMA) event
+#define ASIT_EVTMSK_RXACK       0x2 // Receive acknowledge (IPC MessageQ) message event
+#define ASIT_EVTMSK_INFOACK     0x4 // temp, will be removed
+#define ASIT_EVTMSK_DECACK      0x8 // temp, will be removed
+
+// ASIT event handle
+extern Event_Handle gAsitEvtHandle;
+
+// ASIT Sync event handle
+extern SyncEvent_Handle gAsitSyncEvtHandle;
+
+// ASIT ASP messaging
+#define ASIT_ASP_MSG_HEAP_ID        ( 0 )                           // ASIT message master heap Id
+#define ASIT_ASP_MSG_MASTER_NUMSGS  ( ASP_MSG_MASTER_DEF_NUMMSGS )  // ASIT message master number of messages
+
+// ASIT configuration
+extern PAF_ASIT_Config gPAF_ASIT_config;
+
+
 //   Purpose:   Audio Stream Input Task Function for initialization of data pointers
 //              by allocation of memory.
 Int 
@@ -331,8 +353,6 @@ PAF_ASIT_initPhaseAcpAlg(
     PAF_ASIT_Config *pAsitCfg
 );
 
-//   (***) FL: re-visit this, ASIT/ASOT currently consider common memory independently.
-//             Should simultaneously consider all algs in ASIT/ASOT.
 //   Purpose:   Audio Stream Input Task Function for allocation of common memory.
 Int
 PAF_ASIT_initPhaseCommon(
@@ -639,4 +659,5 @@ Int rxDecodeBitStream(PAF_AST_IoInp  *pInp);
 
 Int rxDecodePlayZero(PAF_AST_IoInp  *pInp);
 
+
 #endif /* _ASIP_H_ */
index 3db43196fd95135dd0c57e1df4c8330596d30a81..65278a73dbc908b13ca3812f22da83c7ebea5c7b 100644 (file)
@@ -162,18 +162,19 @@ enum {
     ASIT_DECODE_PROCESSING
 };
 
-#define ASIT_EVTMSK_NONE        0x0
-#define ASIT_EVTMSK_INPDATA     0x1
-#define ASIT_EVTMSK_INFOACK     0x2
-#define ASIT_EVTMSK_DECACK      0x4
-
+// temp for simulation
+//#define ASIT_ALL_EVENTS (  ASIT_EVTMSK_INPDATA \
+//                         + ASIT_EVTMSK_INFOACK \
+//                         + ASIT_EVTMSK_DECACK )
 #define ASIT_ALL_EVENTS (  ASIT_EVTMSK_INPDATA \
-                         + ASIT_EVTMSK_INFOACK \
-                         + ASIT_EVTMSK_DECACK )
+                         + ASIT_EVTMSK_RXACK )
 
+// temp for simulation
+//#define ASIT_DEC_EVENTS (  ASIT_EVTMSK_INPDATA \
+//                         + ASIT_EVTMSK_INFOACK \
+//                         + ASIT_EVTMSK_DECACK )
 #define ASIT_DEC_EVENTS (  ASIT_EVTMSK_INPDATA \
-                         + ASIT_EVTMSK_INFOACK \
-                         + ASIT_EVTMSK_DECACK )
+                         + ASIT_EVTMSK_RXACK )
 
 #define ASIP_DEBUG
 
@@ -183,12 +184,14 @@ int asipLoopCount1, asipLoopCount2;
 Int asipErrno;
 Int inputReadyForProcessing;
 
-// FL: debug
+// debug
 #include "evmc66x_gpio_dbg.h"
 #endif
 
-Event_Handle asitEvent;
-Int eventsOn;
+Event_Handle gAsitEvtHandle;            // ASIT event handle
+Int eventsOn;                           // flag indicating whether to process events
+
+SyncEvent_Handle gAsitSyncEvtHandle;    // ASIT Sync event handle
 
 /*
  *  ======== taskAsipFxn ========
@@ -220,18 +223,12 @@ Int inputReadyForProcessing;
     Int asitErr;
     UInt events;
 //    Int eventsOn;
-    Error_Block  eb;
+//    Error_Block  eb;
 
     Log_info0("Enter taskAsipFxn()");
 
     taskAsipFxnInit(pP, pQ);  // initialization of input task
     
-    Error_init(&eb);          // initialize error block
-
-    asitEvent = Event_create(NULL, &eb);
-    if (asitEvent == NULL) {
-        System_abort("Event create failed");
-    }
     //
     // Audio Stream Input Task Configuration (*pAsitCfg):
     //
@@ -273,7 +270,7 @@ Int inputReadyForProcessing;
         asipLoopCount1++;
 
         if(eventsOn) {
-            events = Event_pend(asitEvent, ASIT_EVTMSK_NONE, ASIT_ALL_EVENTS,
+            events = Event_pend(gAsitEvtHandle, ASIT_EVTMSK_NONE, ASIT_ALL_EVENTS,
                                 BIOS_WAIT_FOREVER);
         }
         switch (pInp->asipState)
@@ -479,13 +476,13 @@ Int asitSourceDetection(const PAF_ASIT_Params *pP,
                         PAF_ASIT_Config       *pAsitCfg)
 {
     PAF_AST_Config  *pAstCfg;
-    PAF_AST_IoInp *pInp;            /* I/O components for input */
+    PAF_AST_IoInp *pInp;                // I/O components for input
     Int zMD, mcaspErr, asitErr;
     ioDataAutoDetStat_t autoDetStatus;
 
-    pAstCfg  = pAsitCfg->pAstCfg;         // pointer to AST common (shared) configuration
+    pAstCfg  = pAsitCfg->pAstCfg;               // pointer to AST common (shared) configuration
     zMD = pAstCfg->masterDec;
-    pInp = &pAsitCfg->pIoInp[zMD];        // pointer to input I/O components
+    pInp = &pAsitCfg->pIoInp[zMD];              // pointer to input I/O components
 
     // Marks I/O PHY transfer and I/O BUFF write complete
     asitPhyTransferComplete(pInp);
@@ -665,13 +662,16 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP,
 {
     Int asitErr, decErr;
     PAF_AST_IoInp *pInp;                  // I/O components for input
+    AspMsgMaster_Handle hAspMsgMaster;    // ASIT message master handle
     asipDecProc_t *pDec;
     ioDataAutoDetStat_t autoDetStatus;
     Int zMD;
     UInt decMsg;
+    Int status;
 
-    zMD = pAsitCfg->pAstCfg->masterDec;   // pointer to AST common (shared) configuration
-    pInp = &pAsitCfg->pIoInp[zMD];        // pointer to input I/O components
+    zMD = pAsitCfg->pAstCfg->masterDec;         // pointer to AST common (shared) configuration
+    pInp = &pAsitCfg->pIoInp[zMD];              // pointer to input I/O components
+    hAspMsgMaster = pAsitCfg->hAspMsgMaster;    // get ASIT message master handle
     pDec = &pAsitCfg->inpDec;
 
     // Initialization for decode processing when this function is called the first time
@@ -775,8 +775,15 @@ Int asitDecodeProcessing(const PAF_ASIT_Params *pP,
         TRACE_VERBOSE0("TaskAsip: send DEC_EXIT message to slave decoder.");
 
         // Send dec exit message to slave decoder
-        if( AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL)
-            != ASP_MSG_NO_ERR) {
+        status = AspMsgSnd(hAspMsgMaster, ASP_SLAVE_DEC_EXIT, NULL);
+        if (status != ASP_MSG_NO_ERR)
+        {
+            TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
+            SW_BREAKPOINT;
+        }
+        status = AspMsgRcvAck(hAspMsgMaster, ASP_MASTER_DEC_EXIT_DONE, NULL, TRUE);
+        if (status != ASP_MSG_NO_ERR) 
+        {
             TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
             SW_BREAKPOINT;
         }
@@ -838,18 +845,27 @@ UInt asitEventsToDecMsg(UInt asitEvents)
 {
     UInt decMsg = 0;
 
-    if(asitEvents & ASIT_EVTMSK_INPDATA) {
+    if (asitEvents & ASIT_EVTMSK_INPDATA) {
+        // Input data event
         decMsg |= DEC_MSGMSK_INPDATA;
     }
 
-    if(asitEvents & ASIT_EVTMSK_INFOACK) {
-        decMsg |= DEC_MSGMSK_INFOACK;
-    }
+    // temp, simulation
+    //if(asitEvents & ASIT_EVTMSK_INFOACK) {
+    //    decMsg |= DEC_MSGMSK_INFOACK;
+    //}
 
-    if(asitEvents & ASIT_EVTMSK_DECACK) {
-        decMsg |= DEC_MSGMSK_DECACK;
-    }
+    // temp, simulation
+    //if(asitEvents & ASIT_EVTMSK_DECACK) {
+    //    decMsg |= DEC_MSGMSK_DECACK;
+    //}
 
+    if (asitEvents & ASIT_EVTMSK_RXACK)
+    {
+       // Receive acknowledge message event
+        decMsg |= DEC_MSGMSK_RXACK;
+    }
+    
     return decMsg;
 } /* asitEventsToDecMsg */
 
@@ -1009,7 +1025,7 @@ void asipMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
     /* post semaphore */
     if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
         //Semaphore_post(asipSemRx);
-        Event_post(asitEvent, ASIT_EVTMSK_INPDATA);
+        Event_post(gAsitEvtHandle, ASIT_EVTMSK_INPDATA);
     } else {
         ;    // intermediate packet due to buffer wrapping around
     }
@@ -1245,12 +1261,13 @@ void asitUpdateInpBufConfig(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp)
  * Decide source after SYNC is found, i.e. either bitstream preamble is detected
  * or it times out to PCM.
  ==============================================================================*/
-Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
+Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp, 
                      ioDataAutoDetStat_t *autoDetStatus)
 {
     Int sourceConfig, sourceSelect, sourceProgram;
     Int zMD;
     char asipMsgBuf[ASP_MSG_BUF_LEN];
+    Int status;
 
     // Get the configured source
     zMD = pAstCfg->masterDec;
@@ -1343,11 +1360,18 @@ Int asitDecideSource(PAF_AST_Config *pAstCfg, PAF_AST_IoInp  *pInp,
 #ifndef DEBUG_SKIP_DECODING
     // send source select message to slave
     *(Int32 *)&asipMsgBuf[0] = sourceSelect;
-    if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE,
-                  asipMsgBuf, NULL) != ASP_MSG_NO_ERR) {
+    status = AspMsgSnd(gPAF_ASIT_config.hAspMsgMaster, ASP_SLAVE_DEC_SOURCE_SELECT, asipMsgBuf);
+    if (status != ASP_MSG_NO_ERR) 
+    {
         TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
         SW_BREAKPOINT;
     }
+    status = AspMsgRcvAck(gPAF_ASIT_config.hAspMsgMaster, ASP_MASTER_DEC_SOURCE_SELECT_DONE, NULL, TRUE);
+    if (status != ASP_MSG_NO_ERR)
+    {
+        TRACE_VERBOSE0("TaskAsip: error in receiving SOURCE_SELECT ack message");
+        SW_BREAKPOINT;
+    }
 #endif
 
     pInp->sourceSelect  = sourceSelect;
@@ -1527,7 +1551,7 @@ Int asitEvtErrCheck(UInt actualEvents, UInt expectedEvents)
 
 void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr)
 {
-    UInt events;
+    //UInt events;
 
     if(asitErr == ASIT_ERR_INPBUF_UNDERFLOW) {
         TRACE_VERBOSE0("ASIT error handling: input buffer underflows. No actions needed.");
@@ -1564,12 +1588,12 @@ void asitErrorHandling(PAF_ASIT_Config *pAsitCfg, Int asitErr)
 //////////////////////////////////////////////////////////////////////////////
 void asitPostInfoEvent()
 {
-    Event_post(asitEvent, ASIT_EVTMSK_INFOACK);
+    Event_post(gAsitEvtHandle, ASIT_EVTMSK_INFOACK);
 }
 
 void asitPostDecEvent()
 {
-    Event_post(asitEvent, ASIT_EVTMSK_DECACK);
+    Event_post(gAsitEvtHandle, ASIT_EVTMSK_DECACK);
 }
 //////////////////////////////////////////////////////////////////////////////
 
index 7d991a77bd1c4232a4750dc32917d2c8bd17e4dc..145c560a228b53e3c5f72ffc308ecfb8fa1ac2ba 100644 (file)
@@ -80,7 +80,7 @@ const PAF_ASIT_Fxns PAF_ASIT_params_fxns =
     PAF_ASIT_sourceDecode,                  // sourceDecode
     PAF_DEC_deviceAllocate,                 // deviceAllocate
     PAF_DEC_deviceSelect,                   // deviceSelect
-    PAF_DEC_computeFrameLength,             // computeFrameLength
+    NULL, //PAF_DEC_computeFrameLength,             // computeFrameLength
     PAF_DEC_updateInputStatus,              // updateInputStatus
     NULL, /*headerPrint*/                   // headerPrint
     NULL, /*allocPrint*/                    // allocPrint
index 5fc2bd59a41c00be9da393d47eea1e178c48dc32..008334b83c654a432d9ddeb78c39cd0daf17d1e1 100644 (file)
@@ -176,8 +176,8 @@ Void taskAsopFxnInit(
     pAsotCfg->taskHandle = Task_self(); // set task handle
     pAstCfg = pAsotCfg->pAstCfg;        // get pointer to AST common (shared) configuration
 
-    // Create ASIT event
-    status = asotCreateEvent();
+    // Create ASOT event
+    status = astCreateEvent(&gAsotEvtHandle);
     if (status < 0)
     {
         TRACE_TERSE0("TaskAsop: unable to initialize event. Exiting.");
@@ -246,6 +246,7 @@ Void taskAsopFxnInit(
     }
 } /* taskAsopFxnInit */
 
+#if 0
 // Create ASOT event object
 static Int asotCreateEvent(void)
 {
@@ -262,6 +263,7 @@ static Int asotCreateEvent(void)
     
     return 0;
 } /* asotCreateEvent */
+#endif
 
 // Create IO Buff & Phy framework components
 static Int PAF_ASOT_ioCompCreate(
index 34e9d73e006461ea60aa396798d1b54a7f93d347..53a84537ebc73821c28e1833dbb0019f59ab57f6 100644 (file)
@@ -270,8 +270,8 @@ PAF_ASOT_Config gPAF_ASOT_config = {
     &gPAF_AST_config    // pAstCfg
 };
 
-/* ASOT event handle - to put in structure */
-Event_Handle asotEvt;
+// ASOT event handle - to put in structure
+Event_Handle gAsotEvtHandle;
 
 extern Int d10Initialized;
 
@@ -367,7 +367,7 @@ Void taskAsopFxn(
         //  Evt_Id_AsotTxMcaspEdma  : Tx McASP EDMA completion
         if (procEvents == TRUE)
         {
-            events = Event_pend(asotEvt, Event_Id_NONE, (Evt_Id_AsotWakeTimer + Evt_Id_AsotTxMcaspEdma), BIOS_WAIT_FOREVER);
+            events = Event_pend(gAsotEvtHandle, Event_Id_NONE, (Evt_Id_AsotWakeTimer + Evt_Id_AsotTxMcaspEdma), BIOS_WAIT_FOREVER);
         }
 
         asopLoopCount++;
@@ -778,7 +778,7 @@ Void taskAsopFxn(
             gCommandOutputTask_ACK = 1;
             while (gCommandOutputTask_SYNC) 
             {
-                Event_pend(asotEvt, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
+                Event_pend(gAsotEvtHandle, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
             }
             TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Re-start the process");
             pAsotCfg->state = ASOT_STATE_SEL_OUT_DEV;   // init state -- start over
@@ -806,7 +806,7 @@ Void taskAsopFxn(
 // ASOT wake timer (clock) function
 Void clkAsotFxn(Void)
 {
-    Event_post(asotEvt, Evt_Id_AsotWakeTimer);
+    Event_post(gAsotEvtHandle, Evt_Id_AsotWakeTimer);
 }
 
 void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
@@ -814,7 +814,7 @@ void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
     /* post semaphore */
     if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
         //Semaphore_post(asopSemTx);
-        Event_post(asotEvt, Evt_Id_AsotTxMcaspEdma);
+        Event_post(gAsotEvtHandle, Evt_Id_AsotTxMcaspEdma);
     } else {
         ;    // intermediate packet due to buffer wrapping around
     }
index ce37c3aaf49762e0e4521813e09500d218315378..4a909bc37a3de888a7d9a102aebf174a455f43cc 100644 (file)
@@ -60,14 +60,14 @@ All rights reserved.
 #define PAF_ASOT_FRAMELENGTH           256
 #define PAF_ASOT_MAX_FRAMELENGTH       1024
 
-/* ASOT event IDs */
+// ASOT event IDs
 #define Evt_Id_AsotWakeTimer    Event_Id_00  // ASOT Wake Timer event
 #define Evt_Id_AsotRxMsgAsit    Event_Id_01  // ASOT Rx ASIT message event
 #define Evt_Id_AsotRxMsgAsdt    Event_Id_02  // ASOT Rx ASDT message event
 #define Evt_Id_AsotTxMcaspEdma  Event_Id_03  // ASOT Tx McASP EDMA event
 
-/* ASOT event handle - to put in structure */
-extern Event_Handle asotEvt;
+// ASOT event handle - to put in structure
+extern Event_Handle gAsotEvtHandle;
 
 struct PAF_ASOT_Params;
 struct PAF_ASOT_Patchs;
index 904063335b2f6232044e243981bcaa2e6af08419..8094e17e6a5733920ed7ef4b47098ce34214bd44 100644 (file)
@@ -38,6 +38,8 @@ All rights reserved.
  */
 
 #include <xdc/std.h>
+#include <xdc/runtime/Error.h>
+#include <ti/sysbios/knl/Event.h>
 #include "audioStreamProc_common.h"
 #include "audioStreamProc_master.h"
 
@@ -47,3 +49,65 @@ PAF_ASPM_Config gPAF_ASPM_config = {
     { NULL, 0, NULL }, // gateHandle, numCb, xDecOpCb
     { NULL, NULL }, // gateHandle, xOutIsi
 };
+
+// Create AST event object
+Int astCreateEvent(
+    Event_Handle *pEventHandle
+)
+{
+    Event_Handle eventHandle;
+    Error_Block eb;
+    Int status;
+    
+    Error_init(&eb);
+    
+    // Create event,
+    // using default instance configuration parameters.
+    eventHandle = Event_create(NULL, &eb);
+    if (eventHandle == NULL)
+    {
+        status = -1;
+    }
+    else
+    {
+        status = 0;
+    }
+    
+    *pEventHandle = eventHandle;
+        
+    return status;
+}
+
+// Create AST sync event object
+Int astCreateSyncEvent(
+    Event_Handle eventHandle,
+    UInt eventId, 
+    SyncEvent_Handle *pSyncEventHandle
+)
+{
+    Error_Block eb;
+    SyncEvent_Params params;
+    SyncEvent_Handle syncEventHandle;
+    Int status;
+    Error_init(&eb);
+
+    // Create sync event
+    SyncEvent_Params_init(&params);    
+    params.event = eventHandle; // initialize synchronizer event
+    params.eventId = eventId;   // initialize synchronizer event Id
+    
+    syncEventHandle = SyncEvent_create(&params, &eb);
+    if (syncEventHandle == NULL)
+    {
+        status = -1;
+    }
+    else
+    {
+        status = 0;
+    }
+    
+    *pSyncEventHandle = syncEventHandle;
+    
+    return status;
+}
index 6f60ddd0f8e9a7c4352da641a4f7c58f2be58503..12a8647a30ba06457e7d3ba893a2e3c88630fb52 100644 (file)
@@ -41,6 +41,8 @@ All rights reserved.
 #define _ASP_MASTER_H_
  
 #include <xdc/std.h>
+#include <ti/sysbios/knl/Event.h>
+#include <ti/sysbios/syncs/SyncEvent.h>
 #include "aspDecOpCircBuf_common.h"
 #include "aspOutInitSync_common.h"
 
@@ -52,7 +54,19 @@ typedef struct PAF_ASPM_Config
     PAF_AST_OutInitSyncCtl outIsCtl;            // output init-sync control
 } PAF_ASPM_Config;
 
+// ASIT/ASOT shared configuration
 extern PAF_ASPM_Config gPAF_ASPM_config;
 
+// Create AST event object
+Int astCreateEvent(
+    Event_Handle *pEventHandle
+);
+
+// Create AST sync event object
+Int astCreateSyncEvent(
+    Event_Handle eventHandle,
+    UInt eventId, 
+    SyncEvent_Handle *pSyncEventHandle
+);
 
 #endif /* _ASP_MASTER_H_ */
index 9dfc363e4fbfe5bbca0a309e079b00616048b6ea..b4a01b15b6006d661b1f32b3d0e1cc80c2588557 100644 (file)
@@ -49,8 +49,9 @@ All rights reserved.
 #include "params.h"
 #include "pafhjt.h"
 #include "paf_heapMgr.h"
-#include "aspMsg_common.h"
-#include "aspMsg_master.h"
+#include "ipc_common.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
@@ -131,49 +132,65 @@ Void taskSysInitFxn(Void)
     //taskPriAip = Task_setPri(TaskAip, -1);
     //taskPriAsip = Task_setPri(TaskAsip, -1);
 
-    /* Attach IPC */
+    // Attach IPC
     Log_info0("taskSysInitFxn:Ipc_attach()");
-    remoteProcId = MultiProc_getId(SLAVE_NAME);
+    remoteProcId = MultiProc_getId(IPC_SLAVE_NAME);
     if (remoteProcId == MultiProc_INVALIDID) {
-        System_abort("Improper MultiProc ID\n");
+        System_abort("taskSysInitFxn(): improper MultiProc ID\n");
     }
     do {
         status = Ipc_attach(remoteProcId);
     //} while ((status < 0) && (status == Ipc_E_NOTREADY));
     } while (status != Ipc_S_SUCCESS);
 
-    /* Initialize (IPC) ASP master messaging */
-    /* Note: MessageQ_open() called in this function.
-             MessageQ_open() blocks. */
-    Log_info0("taskSysInitFxn:AspMsgMaster_init()");
-    status = AspMsgMaster_init(
-        hAspMsgMaster, 
-        remoteProcId, 
-        ASP_MSG_MASTER_DEF_NUMMSGS);
+    // Create ASIT event
+    status = astCreateEvent(&gAsitEvtHandle);
     if (status < 0)
     {
-        Log_info0("TaskSysInit: unable to initialize ASP messaging. Exiting.");
-        return;
+        System_abort("taskSysInitFxn(): unable to initialize Event. Exiting.");
     }
     
-    /* Initialize decoder output circular buffer control */
-    Log_info0("taskSysInitFxn:cbCtlInit()");
+    // Create ASIT sync event (for master IPC MessageQ)
+    status = astCreateSyncEvent(gAsitEvtHandle, ASIT_EVTMSK_RXACK, &gAsitSyncEvtHandle);
+    if (status < 0)
+    {
+        System_abort("taskSysInitFxn(): unable to initialize SyncEvent. Exiting.");
+    }
+    
+    // Initialize (IPC) ASP master messaging
+    // Note: MessageQ_open() called in this function.
+    //          MessageQ_open() blocks. 
+    //          However, no other Tasks are allowed to execute at this point.
+    Log_info0("taskSysInitFxn(): AspMsgMaster_init()");
+    status = AspMsgMaster_init(gPAF_ASIT_config.hAspMsgMaster,
+        remoteProcId,
+        ASIT_ASP_MSG_HEAP_ID, 
+        ASIT_ASP_MSG_MASTER_NUMSGS, 
+        gAsitSyncEvtHandle,
+        gAsitEvtHandle,
+        ASIT_EVTMSK_RXACK);
+    if (status < 0)
+    {
+        System_abort("taskSysInitFxn(): unable to initialize ASIT ASP messaging. Exiting.");
+    }
+    
+    // Initialize decoder output circular buffer control
+    Log_info0("taskSysInitFxn(): cbCtlInit()");
     status = cbCtlInit(&gPAF_ASPM_config.decOpCircBufCtl, asip_params.zone.decodeN, &gPAF_AST_config.xDecOpCb);
     if (status < 0)
     {
-        Log_info0("TaskSysInit: unable to initialize Decoder Output Circular Buffer Control. Exiting.");
-        return;
+        System_abort("taskSysInitFxn(): unable to initialize Decoder Output Circular Buffer Control. Exiting.");
     }
-    /* Initialize Output Processing Init-Sync control */
+    
+    // Initialize Output Processing Init-Sync control
     Log_info0("taskSysInitFxn:outIsCtlInit()");
     status = outIsCtlInit(&gPAF_ASPM_config.outIsCtl, &gPAF_AST_config.xOutIsi);
     if (status < 0)
     {
-        Log_info0("TaskSysInit: unable to initialize Output Init-Sync Control. Exiting.");
-        return;
+        System_abort("taskSysInitFxn(): unable to initialize Output Init-Sync Control. Exiting.");
     }
 
-    /* Initialize PAF heap manager */
+    // Initialize PAF heap manager
     Log_info0("taskSysInitFxn:pafHeapMgr_init()");
     regionId = SharedRegion_getIdByName("SR_MSMC");
     srHeapMsmc = (IHeap_Handle)SharedRegion_getHeap(regionId);
@@ -195,11 +212,11 @@ Void taskSysInitFxn(Void)
         PAF_HEAP_INT1_SHM, PAF_HEAP_EXT_SHM, PAF_HEAP_EXT_NONCACHED_SHM);
 #endif        
     
-    /* Initialize HJT */
+    // Initialize HJT
     pafhjt = &PAFHJT_RAM;
     
-    /* Patch sigma tables */
-    Log_info0("taskSysInitFxn:ACP_main_cus()");
+    // Patch sigma tables
+    Log_info0("taskSysInitFxn(): ACP_main_cus()");
     ACP_main_cus();
 
 #ifdef RAM_REPORT // patch RAM report functions
@@ -231,12 +248,11 @@ Void taskSysInitFxn(Void)
     GPIOClearOutput(GPIO_PORT_0, GPIO_PIN_107);
 #endif
     
-    /* This is required to use SYS alpha codes in atboot? */
+    // This is required to use SYS alpha codes in atboot?
     Log_info0("taskSysInitFxn:TaskSystemStream resume");
     gTaskInitFlag[TASK_SSP_INIT_FLAG_IDX] = 0;
     Task_setPri(TaskSystemStream, TASK_SSP_PRI);
-    // Wait until Execution of TaskSystemStream is complete
-    // once.
+    // Wait until Execution of TaskSystemStream is complete once.
     while (gTaskInitFlag[TASK_SSP_INIT_FLAG_IDX] == 0)  // System Stream initialization flag is set to 1 in TaskSystemStream
     {
         Task_sleep(SYS_INIT_SLEEP);
@@ -248,7 +264,7 @@ Void taskSysInitFxn(Void)
     Task_setPri(TaskAsop, TASK_ASOP_PRI);
 
     // Create ASIT/ASOT semaphores
-    sysCreateSemaphores();
+    //sysCreateSemaphores();
 
 #ifdef MEMSTAT_REPORT
     // Output current heap memory usage
@@ -268,5 +284,5 @@ void sysCreateSemaphores(void)
     Semaphore_Params_init(&SemParams);
 
     asipSemRx = Semaphore_create(0, &SemParams, NULL);
-    //asopSemTx = Semaphore_create(0, &SemParams, NULL);
+    asopSemTx = Semaphore_create(0, &SemParams, NULL);
 }