Fix uninitialized variables, add more comments to system.c
authorFrank Livingston <frank-livingston@ti.com>
Mon, 6 Feb 2017 16:43:07 +0000 (10:43 -0600)
committerFrank Livingston <frank-livingston@ti.com>
Mon, 6 Feb 2017 16:43:07 +0000 (10:43 -0600)
pasdk/test_dsp/framework/itopo/system.c

index c0214456e9fd8d4300db058cbc6e02755e262578..451ec761b4f8106c8ba2d9132a1e5217a2c9ef11 100644 (file)
@@ -37,6 +37,7 @@ All rights reserved.
 #include <xdc/cfg/global.h>
 #include <xdc/runtime/Log.h>
 #include <xdc/runtime/System.h>
+#include <ti/sysbios/knl/Task.h>
 #include <ti/sysbios/knl/Clock.h>
 
 #include <paftyp.h>
@@ -44,7 +45,8 @@ All rights reserved.
 #include "noasp.h"
 #include "systemStream.h"
 
-#define SYSTEM_STREAM_PROC_INTERVAL 1000
+// Minimum time between invocation of system stream processing
+#define SYSTEM_STREAM_PROC_INTERVAL ( 1000 )    // in msec.
 
 const struct {
     PAF_SST_FxnsMain *main;
@@ -61,9 +63,13 @@ const struct {
         { &systemStream1Compute, &systemStream1Transmit, },
 #ifndef NOBM
         { &systemStream2Compute, &systemStream2Transmit, },
+#else
+        { NULL, NULL, },
 #endif        
 #ifndef NODEM
         { &systemStream3Compute, &systemStream3Transmit, },
+#else
+        { NULL, NULL, },
 #endif        
 #ifdef THX
         { &systemStream4Compute, &systemStream4Transmit, },
@@ -77,45 +83,67 @@ const struct {
 const PAF_SST_Params systemStreamParams_PA[1] =
 {
     {
-        1, 0, 1, 1,
-        (const PAF_SST_Fxns *)&systemStreamPrimaryFxns,
+        1, 0, 1, 1,                                     // streams, stream1, streamN, ss    
+        (const PAF_SST_Fxns *)&systemStreamPrimaryFxns, // fxns
     },
 };
 
 #define systemStreamParams systemStreamParams_PA
 
+// Default system status
 PAF_SystemStatus systemStreamStatus[1] = {
     {
         sizeof (PAF_SystemStatus),
-        PAF_SYS_MODE_ALL,
-        0,
-        PAF_SYS_RECREATIONMODE_AUTO,
-        2 + PAF_SYS_SPEAKERSIZE_SMALL,
-        1 + PAF_SYS_SPEAKERSIZE_SMALL,
-        2 + PAF_SYS_SPEAKERSIZE_SMALL,
-        2 + PAF_SYS_SPEAKERSIZE_SMALL,
-        1 + PAF_SYS_SPEAKERSIZE_BASS,
+        PAF_SYS_MODE_ALL,               // mode
+        0,                              // listeningMode
+        PAF_SYS_RECREATIONMODE_AUTO,    // recreationMode
+        2 + PAF_SYS_SPEAKERSIZE_SMALL,  // speakerMain
+        1 + PAF_SYS_SPEAKERSIZE_SMALL,  // speakerCntr
+        2 + PAF_SYS_SPEAKERSIZE_SMALL,  // speakerSurr
+        2 + PAF_SYS_SPEAKERSIZE_SMALL,  // speakerBack
+        1 + PAF_SYS_SPEAKERSIZE_BASS,   // speakerSubw
         PAF_SYS_CCRTYPE_STANDARD,       // channelConfigurationRequestType
         0, 0, 0,                        // switchImage, imageNum, imageNumMax
         0,                              // Unused
         0, 0,                           // cpuLoad, peakCpuLoad
-        0, 0, 0, 0,                     // speakerWide, speakerHead, unused[2]
-        0, 0, 0, 0,                     //unused2[4]
-        PAF_CC_SAT_UNKNOWN, PAF_CC_SUB_ZERO, 0, 0, 0, 0, 0, 0,
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerWide
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerHead
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerTopfront
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerToprear
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerTopmiddle
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerFrontheight
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerRearheight
+        0,                              // unused2
+        PAF_CC_SAT_UNKNOWN, PAF_CC_SUB_ZERO, 0, 0, 0, 0, 0, 0,  // channelConfigurationRequest
+#ifdef FULL_SPEAKER // paftyp.h
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerScreen
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerSurr1
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerSurr2
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerRearSurr1
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerRearSurr2
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerCntrSurr
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerLRCntr
+        0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerLRCntrSurr
+#endif
     },
 };
 
 PAF_SST_Config systemStreamConfig[1] =
 {
     {
-        NULL,
-        &systemStreamStatus[0],
+        NULL,                           // acp
+        &systemStreamStatus[0],         // pStatus
     },
 };
 
 
 extern Int gSysInit;
 
+// FL: debug
+//#define MAX_CAP_CUR_TIME ( 100 )
+//UInt32 gCurTime[MAX_CAP_CUR_TIME];
+//Uint32 gCurTimeIdx=0;
+
 /*
  *  ======== taskSystemStreamFxn ========
  *  IDLE function for audio stream
@@ -123,24 +151,31 @@ extern Int gSysInit;
 Void taskSystemStreamFxn()
 {
     Int32 i;
-    Uns time, interval, elapsed, now, then;
+    UInt32 elapsed, now, then=0;
+    UInt32 time, interval;
 
     //System_printf("Enter idleAudioStream()\n");    
     //Log_info0("Enter idleAudioStream()");
 
-    time = SYSTEM_STREAM_PROC_INTERVAL;
+    time = SYSTEM_STREAM_PROC_INTERVAL; // in msec.
 
     while (1)
     {
-        // Compute interval in system clock ticks,
-        // interval time expressed in msec.
+        // Compute interval in system clock ticks, interval time expressed in msec.
+        // Performing calculation inside while loop allows changes in system clock tick period.
         interval = time * USEC_PER_MSEC / Clock_tickPeriod;
 
         // Compute elapsed time
+        // Note in case of wrap of 32-bit return value for now,
+        // (now-then) calculation is correct despite (now<then)
+        // due to 2s complement arithmetic.
         now = Clock_getTicks();
         elapsed = now - then;
-        then = now;
+        then = now; // latch "now" as "then" for next iteration
 
+        // If elapsed time since last iteration is less than desired System Stream period,
+        // then sleep until interval has passed.
+        // Otherwise execute functions in System Stream.
         if (interval > elapsed)
         {
             Task_sleep(interval - elapsed);
@@ -148,14 +183,25 @@ Void taskSystemStreamFxn()
 
         //if (gSysInit == 0)
         //  return;
+    
+        // FL: debug
+        //gCurTime[gCurTimeIdx] = Clock_getTicks();
+        //gCurTimeIdx++;
+        //if (gCurTimeIdx >= MAX_CAP_CUR_TIME)
+        //{
+        //    gCurTimeIdx = 0;
+        //}
 
         for (i=0; i < lengthof(systemStreamConfig); i++)
+        {
             systemStreamParams[i].fxns->main
-                (&systemStreamParams[i], &systemStreamConfig[i]);
-
-        gSysInit = 1;  // Indicate system Init to resume
+                (&systemStreamParams[i], &systemStreamConfig[i]);            
+        }
 
+        if (gSysInit == 0)
+        {
+            gSysInit = 1;  // Indicate system Init to resume
+        }
     }
-
 }