Modified messaging code after code review.
authorJianzhong Xu <a0869574@ti.com>
Fri, 23 Jun 2017 18:03:52 +0000 (14:03 -0400)
committerJianzhong Xu <a0869574@ti.com>
Fri, 23 Jun 2017 18:03:52 +0000 (14:03 -0400)
pasdk/test_dsp/framework/aspMsg_master.c
pasdk/test_dsp/framework/audioStreamInpProc.c

index 6a84fb9deeaed72dfb54013b97a4ffde5f730ea2..94744243842fef0d79ea8d988224abab2145c7ea 100644 (file)
@@ -175,18 +175,13 @@ Int AspMsgMaster_init(
 Int AspMsgSend(UInt32 sndCmd, UInt32 ackCmd, char *sndMsgBuf, char *ackMsgBuf)
 {
     ASP_Msg* pAspMsg;                   /* Messaging */
-    Int status, retVal;
-
-    // Init return vallue - no error in messaging operation, even though there
-    // may be error in returned (acknowledgement) message.
-    retVal = ASP_MSG_NO_ERR;
+    Int status;
 
     // allocate message
     pAspMsg = (ASP_Msg *)MessageQ_alloc(hAspMsgMaster->heapId, hAspMsgMaster->msgSize);
     if (pAspMsg == NULL) {
         TRACE_TERSE0("MessageQ_alloc() failure.");
-        SW_BREAKPOINT; // temporary
-        retVal = ASP_MSG_ERR_QUEUE_ALLOC;
+        return (ASP_MSG_ERR_QUEUE_ALLOC);
     }
 
     // set the return address in the message header and fill in message payload
@@ -196,24 +191,26 @@ Int AspMsgSend(UInt32 sndCmd, UInt32 ackCmd, char *sndMsgBuf, char *ackMsgBuf)
     pAspMsg->messageId = hAspMsgMaster->messageId & ~(1<<31);
     pAspMsg->expectResp = TRUE;
 
+    // copy the message provided by caller
     if(sndMsgBuf != NULL) {
-        memcpy(pAspMsg->buf, sndMsgBuf, ASP_MSG_BUF_LEN);
+        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) {
-        SW_BREAKPOINT;
-        retVal = ASP_MSG_ERR_QUEUE_PUT;
+        TRACE_TERSE0("MessageQ_put() failure.");
+        MessageQ_free((MessageQ_Msg)pAspMsg);
+        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.");
-        SW_BREAKPOINT; // temporary
-        retVal = ASP_MSG_ERR_QUEUE_GET;
+        MessageQ_free((MessageQ_Msg)pAspMsg);
+        return (ASP_MSG_ERR_QUEUE_GET);
     }
 
     // check if returned message is valid
@@ -221,24 +218,27 @@ Int AspMsgSend(UInt32 sndCmd, UInt32 ackCmd, char *sndMsgBuf, char *ackMsgBuf)
         (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);
-        SW_BREAKPOINT;
-        retVal = ASP_MSG_ERR_ACKNOWLEDGE;
+        MessageQ_free((MessageQ_Msg)pAspMsg);
+        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);
 
+    // get the returned message
     if(ackMsgBuf != NULL) {
-        memcpy(ackMsgBuf, pAspMsg->buf, ASP_MSG_BUF_LEN);
+        memcpy(ackMsgBuf, pAspMsg->buf, ASP_MSG_BUF_LEN*sizeof(char));
     }
 
-    /* free the message */
+    // free the message 
     status = MessageQ_free((MessageQ_Msg)pAspMsg);
     if (status != MessageQ_S_SUCCESS) {
-        SW_BREAKPOINT;
-        retVal = ASP_MSG_ERR_QUEUE_FREE;
+        TRACE_TERSE0("MessageQ_free() failure.");
+        return (ASP_MSG_ERR_QUEUE_FREE);
     }
 
-    return retVal;
+    // No error in messaging operation, even though there
+    // may be error in returned (acknowledgement) message.
+    return (ASP_MSG_NO_ERR);
 } /* AspMsgSend */
 
index 7645149f80e61ad8e6732759c3289ea01b28da52..4b783ce11a840f6ce0166eb25434a6b8f990c5fe 100644 (file)
@@ -839,7 +839,8 @@ Void taskAsipFxn(
         if(AspMsgSend(ASP_SLAVE_DEC_SOURCE_SELECT, ASP_MASTER_DEC_SOURCE_SELECT_DONE,
                       asipMsgBuf, NULL) != ASP_MSG_NO_ERR)
         {
-            TRACE_VERBOSE0("TaskAsip: error in sending source select message");
+            TRACE_VERBOSE0("TaskAsip: error in sending SOURCE_SELECT message");
+            SW_BREAKPOINT;
         }
         
         // set to unknown so that we can ensure, for IOS purposes, that sourceDecode = NONE
@@ -870,7 +871,12 @@ Void taskAsipFxn(
         Task_setPri(pAsitCfg->taskHandle, Task_getPri(pAsitCfg->taskHandle)+1);
 
         // FL: send dec exit message to slave
-        AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL);
+        if( AspMsgSend(ASP_SLAVE_DEC_EXIT, ASP_MASTER_DEC_EXIT_DONE, NULL, NULL)
+            != ASP_MSG_NO_ERR)
+        {
+            TRACE_VERBOSE0("TaskAsip: error in sending DEC_EXIT message");
+            SW_BREAKPOINT;                
+        }
 
     } // End of main processing loop for (;;)
     
@@ -2327,7 +2333,7 @@ PAF_ASIT_decodeInit(
             if(AspMsgSend(ASP_SLAVE_DEC_ACTIVATE, ASP_MASTER_DEC_ACTIVATE_DONE, 
                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
             {
-                TRACE_TERSE0("decodeInit: error in sending dec activate message ");
+                TRACE_TERSE0("decodeInit: error in sending DEC_ACTIVATE message ");
                 SW_BREAKPOINT; // temporary
                 return -1; // temporary
             }           
@@ -2342,7 +2348,7 @@ PAF_ASIT_decodeInit(
             if(AspMsgSend(ASP_SLAVE_DEC_RESET, ASP_MASTER_DEC_RESET_DONE, 
                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
             {
-                TRACE_TERSE0("decodeInit: error in sending dec reset message ");
+                TRACE_TERSE0("decodeInit: error in sending DEC_RESET message ");
                 SW_BREAKPOINT; // temporary
                 return -1; // temporary
             }
@@ -2641,7 +2647,7 @@ PAF_ASIT_decodeInfo(
             if(AspMsgSend(ASP_SLAVE_DEC_INFO, ASP_MASTER_DEC_INFO_DONE, 
                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
             {
-                TRACE_TERSE0("decodeInfo: error in sending dec info message ");
+                TRACE_TERSE0("decodeInfo: error in sending DEC_INFO message ");
                 SW_BREAKPOINT; // temporary
                 return -1;     // temporary
             }
@@ -2939,7 +2945,9 @@ PAF_ASIT_decodeDecode(
             if(AspMsgSend(ASP_SLAVE_DEC_DECODE, ASP_MASTER_DEC_DECODE_DONE, 
                           decMsgBuf, decMsgBuf) != ASP_MSG_NO_ERR)
             {
+                TRACE_TERSE0("decodeDecode: error in sending DEC_DECODE message ");
                 SW_BREAKPOINT; // temporary
+                return -1;     // temporary
             }
             else 
             {
@@ -3213,9 +3221,9 @@ PAF_ASIT_decodeComplete(
             if(AspMsgSend(ASP_SLAVE_DEC_DEACTIVATE, ASP_MASTER_DEC_DEACTIVATE_DONE,
                           decMsgBuf, NULL) != ASP_MSG_NO_ERR)
             {
-                TRACE_TERSE0("Decoder message failure.");
-                errno = -1; // temporary
-                return errno;
+                TRACE_TERSE0("decodeComplete: error in sending DEC_DEACTIVATE message.");
+                SW_BREAKPOINT;
+                return -1;
             }
 
 #if 0 // FL: decoder deactivate call, slave