Cleaned up code repetitions of messaging and shared memory read/write.
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / as0.c
index 86edbd6166c4ae472f1f76dc3a7fa87f7f2c8b47..47cac9919f157244b04376ee5838e0983e4d860a 100644 (file)
@@ -275,124 +275,50 @@ PAF_DEC_computeFrameLength(
 {
     Int m, n, o, p;
     // Messaging
-    ASP_Msg *pAspMsg;
     Int argIdx;
     Int errno;                          /* error number */
-    Int status;
+    char decMsgBuf[ASP_MSG_BUF_LEN];
 
     // FL: dec control message to slave
-    pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);  /* allocate message */
-    if (pAspMsg == NULL)
-    {
-        TRACE_TERSE0("MessageQ_alloc() failure.");
-        errno = -1; // temporary
-        return errno;
-    }
-    MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
-    pAspMsg->cmd = ASP_SLAVE_DEC_CONTROL;                                              /* fill in message payload */
-    pAspMsg->procId = hAspMsgMaster->masterProcId;
-    pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
-    pAspMsg->expectResp = TRUE;
     argIdx = 0; //  set decIdx
-    *(Int *)&pAspMsg->buf[argIdx] = decIdx;
+    *(Int *)&decMsgBuf[argIdx] = decIdx;
     argIdx += sizeof(Int); // set decCtrlCmd
-    *(IALG_Cmd *)&pAspMsg->buf[argIdx] = DEC_MINSAMGEN;
-    TRACE_TERSE3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-    TRACE_TERSE1("decIdx=%d", pAspMsg->buf[0]);
-    status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);                       /* send message */
-    if (status != MessageQ_S_SUCCESS)
-    {
-        SW_BREAKPOINT;
-    }
-    // wait for dec control message from slave
-    status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
-    if (status != MessageQ_S_SUCCESS)
+    *(IALG_Cmd *)&decMsgBuf[argIdx] = DEC_MINSAMGEN;
+    if(AspMsgSend(ASP_SLAVE_DEC_CONTROL, ASP_MASTER_DEC_CONTROL_DONE,
+                  decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
     {
-        TRACE_TERSE0("decodeInit(): MessageQ_get() failure.");
         SW_BREAKPOINT;
-        return -1; // temporary
-    }
-    if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) && 
-        (pAspMsg->cmd == ASP_MASTER_DEC_CONTROL_DONE) &&
-        (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
+        return -1; // temporary        
+    }    
+    else 
     {
-        hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
-        TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-        
         argIdx = 0; // get decCtrlRet
-        m = *(Int *)&pAspMsg->buf[argIdx];
-        TRACE_TERSE1("decCtrlRet (m)=%d", m);
+        m = *(Int *)&decMsgBuf[argIdx];
+        TRACE_TERSE1("decCtrlRet (m)=%d", m);        
     }
-    else
-    {
-        TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-        SW_BREAKPOINT;
-    }
-    // free the message
-    status = MessageQ_free((MessageQ_Msg)pAspMsg);
-    if (status != MessageQ_S_SUCCESS)
-    {
-        SW_BREAKPOINT;
-    }
-    
+
 #if 0 // FL: decoder control call, slave
     m = alg->fxns->algControl(alg, DEC_MINSAMGEN, NULL);
 #endif
     
     // FL: dec control message to slave
-    pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);  /* allocate message */
-    if (pAspMsg == NULL)
-    {
-        TRACE_TERSE0("MessageQ_alloc() failure.");
-        return -1; // temporary
-    }
-    MessageQ_setReplyQueue(hAspMsgMaster->masterQue, (MessageQ_Msg)pAspMsg);            /* set the return address in the message header */
-    pAspMsg->cmd = ASP_SLAVE_DEC_CONTROL;                                              /* fill in message payload */
-    pAspMsg->procId = hAspMsgMaster->masterProcId;
-    pAspMsg->expectResp = TRUE;
-    pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
     argIdx = 0; // set decIdx
-    *(Int *)&pAspMsg->buf[argIdx] = decIdx;
+    *(Int *)&decMsgBuf[argIdx] = decIdx;
     argIdx += sizeof(Int); // set decCtrlCmd
-    *(IALG_Cmd *)&pAspMsg->buf[argIdx] = DEC_MAXSAMGEN;
-    TRACE_TERSE3("Tx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-    TRACE_TERSE1("decIdx=%d", pAspMsg->buf[0]);
-    status = MessageQ_put(hAspMsgMaster->slaveQue, (MessageQ_Msg)pAspMsg);                       /* send message */
-    if (status != MessageQ_S_SUCCESS)
-    {
-        SW_BREAKPOINT;
-    }
-    // wait for dec control message from slave
-    status = MessageQ_get(hAspMsgMaster->masterQue, (MessageQ_Msg *)&pAspMsg, MessageQ_FOREVER);
-    if (status != MessageQ_S_SUCCESS)
+    *(IALG_Cmd *)&decMsgBuf[argIdx] = DEC_MAXSAMGEN;
+    if(AspMsgSend(ASP_SLAVE_DEC_CONTROL, ASP_MASTER_DEC_CONTROL_DONE,
+                  decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
     {
-        TRACE_TERSE0("MessageQ_get() failure.");
         SW_BREAKPOINT;
-        return -1; // temporary
-    }
-    if ((pAspMsg->procId == hAspMsgMaster->slaveProcId) && 
-        (pAspMsg->cmd == ASP_MASTER_DEC_CONTROL_DONE) &&
-        (pAspMsg->messageId == (hAspMsgMaster->messageId | ((UInt32)1<<31))))
+        return -1; // temporary        
+    }    
+    else 
     {
-        hAspMsgMaster->messageId = (hAspMsgMaster->messageId + 1) & ~(1<<31);
-        TRACE_TERSE3("Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-
         argIdx = 0; // get decCtrlRet
-        n = *(Int *)&pAspMsg->buf[argIdx];
-        TRACE_TERSE1("decCtrlRet (n)=%d", n);
+        n = *(Int *)&decMsgBuf[argIdx];
+        TRACE_TERSE1("decCtrlRet (n)=%d", n);        
     }
-    else
-    {
-        TRACE_TERSE3("ERROR: Rx ASP message: procId=%d, cmd=%d, messageId=0x%04x", pAspMsg->procId, pAspMsg->cmd, pAspMsg->messageId);
-        SW_BREAKPOINT;
-    }
-    // free the message
-    status = MessageQ_free((MessageQ_Msg)pAspMsg);            
-    if (status != MessageQ_S_SUCCESS)
-    {
-        SW_BREAKPOINT;
-    }
-    
+
 #if 0 // FL: decoder control call, slave
     n = alg->fxns->algControl(alg, DEC_MAXSAMGEN, NULL);
 #endif