PASDK-516:Add ASOT wake timer, update existing ASOT SM to use events
authorFrank Livingston <frank-livingston@ti.com>
Fri, 2 Feb 2018 17:01:00 +0000 (11:01 -0600)
committerFrank Livingston <frank-livingston@ti.com>
Fri, 2 Feb 2018 17:01:00 +0000 (11:01 -0600)
pasdk/test_dsp/application/app.cfg
pasdk/test_dsp/framework/audioStreamOutProcNewIO.c

index 1efc084bbeeb002041b009a1a2a62fa2911f085e..9e145db620fd883a16ec02916a8fc1d869363d3c 100644 (file)
@@ -386,6 +386,12 @@ ECM.eventGroupHwiNum[1] = 8; // FL: conflict w/ UART LLD, intr-callback mode
 ECM.eventGroupHwiNum[2] = 9;
 ECM.eventGroupHwiNum[3] = 10;
 
+/* Add ASOT wake timer */
+var clockParams = new Clock.Params();
+clockParams.period = 1; // one clock tick period
+clockParams.startFlag = true;
+//clockParams.arg = 0x5555; // unused, default==NULL
+Program.global.clockAsot = Clock.create("&clkAsotFxn", 1, clockParams);
 
 /* Define HWI Hook Set for PFP */
 Hwi.addHookSet({
index cdf0bb2a8499ac1a511889d6c18b3ddd39a7edcf..13276593c2736e3f72b51b904e21d4902e65285e 100644 (file)
@@ -39,6 +39,7 @@ All rights reserved.
 
 #include <xdc/runtime/Log.h>
 #include <ti/sysbios/BIOS.h>
+#include <ti/sysbios/knl/Event.h>
 #include <stdio.h>
 
 #include "mcasp_cfg.h"
@@ -57,7 +58,6 @@ extern volatile UInt32 gCommandOutputTask_SYNC;
 extern volatile UInt32 gCommandOutputTask_ACK;
 extern Int d10Initialized;
 
-
 static Int asopSelectDevices(PAF_AST_IoOut *pOut);
 static int asopIoCompsInit(PAF_AST_OutBuf * pOutBuf, PAF_AST_IoOut * pOutIo);
 static void asopIoPhyPrime(PAF_AST_IoOut *pOut);
@@ -122,6 +122,17 @@ extern Void taskAsopFxnInit(const PAF_ASOT_Params *pP, const PAF_ASOT_Patchs *pQ
 #define ASOP_DP_DECINFO2_ERR        ( -5 )  // decode encode error
 #define ASOP_DP_DECFINALTEST_ERR    ( -6 )  // decode final error
 
+// Output FSM states 
+enum 
+{ 
+    INIT_OUT_PROC_STATE,
+    INITSYNC_DEC_RESET_STATE, 
+    INITSYNC_DEC_INFO1_STATE, 
+    INITSYNC_DEC_DECODE1_STATE,
+    INITSYNC_RESYNC_STATE,
+    OUT_PROC_STATE 
+};
+
 // Global debug counters */
 extern UInt32 gAsopTxSioReclaimCnt      ;
 extern UInt32 gAsopInitOutProcCnt       ;
@@ -137,6 +148,12 @@ extern UInt32 gAsopFinalCnt             ;
 extern UInt32 gAsopOutSioUpdateCnt      ;
 extern UInt32 gAsopQuitCnt              ;
 
+#define ASOP_DEBUG
+#ifdef ASOP_DEBUG
+Int asopLoopCount;
+#endif
+
+
 /*
  *  ======== taskAsopFxn ========
  *  Audio Stream Output Processing task function
@@ -154,27 +171,25 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
     const PAF_ASOT_Patchs *pQ
 )
 {
-    PAF_ASOT_Config *pAsotCfg;      /* ASOT configuration pointer */
-    PAF_AST_Config *pAstCfg;        /* Common (shared) configuration pointer */
-    Int as;                         /* Audio Stream Number (1, 2, etc.) */
-    Int z;                          /* input/encode/stream/decode/output counter */
+    PAF_ASOT_Config *pAsotCfg;      // ASOT configuration pointer
+    PAF_AST_Config *pAstCfg;        // Common (shared) configuration pointer
+    Int as;                         // Audio Stream Number (1, 2, etc.)
+    Int z;                          // input/encode/stream/decode/output counter
     Int zMS;
     Int errno;                      // error number
     Int8 procSleep;                 // whether to sleep: 0: No, 1: Yes
     Int8 procOutDevSel;             // whether to perform output device selection: 0: No, 1:Yes
     Int outSel;                     // whether output device selected
-    enum { INIT_OUT_PROC_STATE,
-           INITSYNC_DEC_RESET_STATE, INITSYNC_DEC_INFO1_STATE, INITSYNC_DEC_DECODE1_STATE,
-           INITSYNC_RESYNC_STATE,
-           OUT_PROC_STATE } state;
     PAF_AudioFrame decResetAf;
     PAF_AudioFrame decInfo1Af;
-    Int loopCount = 0;              // used to stop trace to see startup behavior.
+#ifndef ASOP_DEBUG
+    Int asopLoopCount;              // debug, ASOT loop counter
+#endif    
 
     Log_info0("Enter taskAsopFxn()");
 
     taskAsopFxnInit(pP, pQ);    // initialization of output task
-
+    
     //
     // Audio Stream Output Task Configuration (*pAsotCfg):
     //
@@ -194,14 +209,15 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
         TRACE_VERBOSE1("TaskAsop: AS%d: running", as+z);
     }
 
-    errno = 0;                      // init error indicator -- no error
-    procSleep = 1;                  // init sleep flag -- sleep
-    procOutDevSel = 1;              // init device output selection flag -- perform output device selection
-    state = INIT_OUT_PROC_STATE;    // init state
+    errno = 0;                              // init error indicator -- no error
+    procSleep = 1;                          // init sleep flag -- sleep
+    procOutDevSel = 1;                      // init device output selection flag -- perform output device selection
+    pAsotCfg->state = INIT_OUT_PROC_STATE;  // init state
+    asopLoopCount = 0;                      // loop counter
     for (;;)
     {
-        loopCount++;
-        TRACE_GEN2("TaskAsop (begin Main loop %d) (errno 0x%x)", loopCount, errno);
+        asopLoopCount++;
+        TRACE_GEN2("TaskAsop (begin Main loop %d) (errno 0x%x)", asopLoopCount, errno);
 
         //
         // Check forward (ASIT) error here, TBD
@@ -212,13 +228,14 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
             TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Wait for the command deasserted");
             gCommandOutputTask_ACK = 1;
             while (gCommandOutputTask_SYNC) {
-                Task_sleep(1);
+                //Task_sleep(1);
+                Event_pend(asotEvt, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
             }
             TRACE_TERSE0("TaskAsop: ack for writeDECCommandRestart ... Sync-ed! Startover the process");
-            procSleep = 1;                  // init sleep flag -- sleep
-            procOutDevSel = 1;              // init device output selection flag -- perform output device selection
-            state = INIT_OUT_PROC_STATE;    // init state -- starover
-            errno = ASOP_DP_FORWARD_ERR;    // Override the error -- for flushing SIO output device
+            procSleep = 1;                          // init sleep flag -- sleep
+            procOutDevSel = 1;                      // init device output selection flag -- perform output device selection
+            pAsotCfg->state = INIT_OUT_PROC_STATE;  // init state -- start over
+            errno = ASOP_DP_FORWARD_ERR;            // Override the error -- for flushing SIO output device
         }
 
         // any error forces idling of output
@@ -232,14 +249,15 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                 }
             }
 
-            TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", loopCount);
+            TRACE_TERSE1("TaskAsop: Trace stopped at loop %d.", asopLoopCount);
             //ERRNO_RPRT(TaskAsop, errno);
         }
 
         if (procSleep == 1)
         {
             TRACE_VERBOSE1("TaskAsop: AS%d: ... sleeping ...", as+zMS);
-            Task_sleep(1);
+            //Task_sleep(1);
+            Event_pend(asotEvt, Event_Id_NONE, Evt_Id_AsotWakeTimer, BIOS_WAIT_FOREVER);
         }
 
         if (procOutDevSel == 1)
@@ -280,7 +298,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
             }
         } /* if (procOutDevSel == 1) */
 
-        switch (state)
+        switch (pAsotCfg->state)
         {
             case INIT_OUT_PROC_STATE:
                 gAsopInitOutProcCnt++;
@@ -292,13 +310,13 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                 errno = PAF_ASOT_initOutProc(pP, pAstCfg->xStr);
                 if (errno < 0)
                 {
-                    state = INIT_OUT_PROC_STATE;
+                    pAsotCfg->state = INIT_OUT_PROC_STATE;
                     procSleep = 1;
                     procOutDevSel = 1;
                 }
                 else
                 {
-                    //state = INITSYNC_DEC_RESET_STATE;
+                    //pAsotCfg->state = INITSYNC_DEC_RESET_STATE;
                     procSleep = 0;
                     procOutDevSel = 0;
                     for (z=OUTPUT1; z < OUTPUTN; z++)
@@ -309,14 +327,15 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     // Start I/O physical layer by priming McASP LLD for output
                     asopIoPhyPrime(&pAsotCfg->pIoOut[0]);
 
-                    state = OUT_PROC_STATE;
+                    pAsotCfg->state = OUT_PROC_STATE;
                 }
 
                 break;
 
             case OUT_PROC_STATE:
-                Semaphore_pend(asopSemTx, BIOS_WAIT_FOREVER);
-
+                //Semaphore_pend(asopSemTx, BIOS_WAIT_FOREVER);
+                Event_pend(asotEvt, Event_Id_NONE, Evt_Id_AsotTxMcaspEdma, BIOS_WAIT_FOREVER);
+                
                 ioPhyXferComplete(pAsotCfg->pIoOut[0].hIoPhy, FALSE);
 
                 asopDecodePcm(&pAsotCfg->pIoOut[0]);
@@ -341,7 +360,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE errno=%d", errno);
 
                     // sync error -- start over
-                    state = INIT_OUT_PROC_STATE;
+                    pAsotCfg->state = INIT_OUT_PROC_STATE;
                     procSleep = 1;
                     procOutDevSel = 1;
                 }
@@ -350,7 +369,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE not sync'd errno=%d", errno);
 
                     // sync not ready -- try again
-                    state = INITSYNC_DEC_RESET_STATE;
+                    pAsotCfg->state = INITSYNC_DEC_RESET_STATE;
                     errno=0; // FL: temp hack
                     procSleep = 1;
                     procOutDevSel = 1;
@@ -360,7 +379,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_RESET_STATE sync'd, errno=%d", errno);
 
                     // sync'd -- move on
-                    state = INITSYNC_DEC_INFO1_STATE;
+                    pAsotCfg->state = INITSYNC_DEC_INFO1_STATE;
                     procSleep = 0;
                     procOutDevSel = 0;
                 }
@@ -383,7 +402,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE errno=%d", errno);
 
                     // sync error -- start over
-                    state = INIT_OUT_PROC_STATE;
+                    pAsotCfg->state = INIT_OUT_PROC_STATE;
                     procSleep = 1;
                     procOutDevSel = 1;
                 }
@@ -392,7 +411,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE not sync'd errno=%d", errno);
 
                     // sync not ready -- try again
-                    state = INITSYNC_DEC_INFO1_STATE;
+                    pAsotCfg->state = INITSYNC_DEC_INFO1_STATE;
                     errno=0; // FL: temp hack
                     procSleep = 1;
                     procOutDevSel = 0;
@@ -402,7 +421,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_INFO1_STATE sync'd errno=%d", errno);
 
                     // sync'd -- move on
-                    state = INITSYNC_DEC_DECODE1_STATE;
+                    pAsotCfg->state = INITSYNC_DEC_DECODE1_STATE;
                     procSleep = 0;
                     procOutDevSel = 0;
                 }
@@ -425,7 +444,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE errno=%d", errno);
 
                     // sync error -- start over
-                    state = INIT_OUT_PROC_STATE;
+                    pAsotCfg->state = INIT_OUT_PROC_STATE;
                     procSleep = 1;
                     procOutDevSel = 1;
                 }
@@ -434,7 +453,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE not sync'd errno=%d", errno);
 
                     // sync not ready -- try again
-                    state = INITSYNC_DEC_DECODE1_STATE;
+                    pAsotCfg->state = INITSYNC_DEC_DECODE1_STATE;
                     errno=0; // FL: temp hack
                     procSleep = 1;
                     procOutDevSel = 0;
@@ -444,7 +463,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_DEC_DECODE1_STATE sync'd errno=%d", errno);
 
                     // sync'd -- move on
-                    state = OUT_PROC_STATE;
+                    pAsotCfg->state = OUT_PROC_STATE;
                     procSleep = 0;
                     procOutDevSel = 0;
                 }
@@ -469,7 +488,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE errno=%d", errno);
 
                     // sync error -- start over
-                    state = INIT_OUT_PROC_STATE;
+                    pAsotCfg->state = INIT_OUT_PROC_STATE;
                     procSleep = 1;
                     procOutDevSel = 1;
                 }
@@ -478,7 +497,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     Log_info1("TaskAsop: state=INITSYNC_RESYNC_STATE sync'd errno=%d", errno);
 
                     // re-sync'd -- move on
-                    state = OUT_PROC_STATE;
+                    pAsotCfg->state = OUT_PROC_STATE;
                     procSleep = 0;
                     procOutDevSel = 0;
                 }
@@ -507,14 +526,14 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     if (errno == ASOP_DP_FORWARD_ERR)
                     {
                         // forward (ASIT) error -- start over
-                        state = INIT_OUT_PROC_STATE;
+                        pAsotCfg->state = INIT_OUT_PROC_STATE;
                         procSleep = 1;
                         procOutDevSel = 1;
                     }
                     else
                     {
                         // local (ASOT) error
-                        state = INITSYNC_RESYNC_STATE;
+                        pAsotCfg->state = INITSYNC_RESYNC_STATE;
                         procSleep = 1;
                         procOutDevSel = 0; // disallow device re-select if local error during output processing
                     }
@@ -532,7 +551,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                     {
                         // skip re-sync
                         // resume output processing after new output selected
-                        state = OUT_PROC_STATE;
+                        pAsotCfg->state = OUT_PROC_STATE;
                         procSleep = 1;
                         procOutDevSel = 1;
                     }
@@ -549,7 +568,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
 
                     // no error returned if CB drained
                     // (i.e. CB drained is normal behavior)
-                    state = INIT_OUT_PROC_STATE;
+                    pAsotCfg->state = INIT_OUT_PROC_STATE;
                     procSleep = 1;
                     procOutDevSel = 1;
                 }
@@ -557,7 +576,7 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
                 break;
 #endif
             default: // unknown state
-                TRACE_TERSE2("TaskAsop: AS%d: state: unknown, 0x%x", as+zMS, state);
+                TRACE_TERSE2("TaskAsop: AS%d: state: unknown, 0x%x", as+zMS, pAsotCfg->state);
                 break;
         } // End of switch
 
@@ -567,12 +586,18 @@ Void taskAsopFxn_NewIO_Not_Used(  // not used for SIO_DEV I/O
 
 } /* taskAsopFxn */
 
+// ASOT wake timer (clock) function
+Void clkAsotFxn(Void)
+{
+    Event_post(asotEvt, Evt_Id_AsotWakeTimer);
+}
 
 void asopMcaspCallback(void* arg, MCASP_Packet *mcasp_packet)
 {
     /* post semaphore */
     if(mcasp_packet->arg == IOPHY_XFER_FINAL) {
-        Semaphore_post(asopSemTx);
+        //Semaphore_post(asopSemTx);
+        Event_post(asotEvt, Evt_Id_AsotTxMcaspEdma);
     } else {
         ;    // intermediate packet due to buffer wrapping around
     }
@@ -647,7 +672,7 @@ int asopIoCompsInit(PAF_AST_OutBuf * pOutBuf, PAF_AST_IoOut * pOutIo)
     pOutIo->phyXferSize = ioPhyParams.xferFrameSize;
 
     return 0;
-} /* asipIoCompsInit */
+} /* asopIoCompsInit */
 
 
 /*======================================================================================