65caeb8faeb5ea3363852b639b4d699974cf596b
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / itopo / system.c
2 /*
3 Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without 
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 #include <xdc/std.h>
37 #include <xdc/cfg/global.h>
38 #include <xdc/runtime/Log.h>
39 #include <xdc/runtime/System.h>
40 #include <ti/sysbios/knl/Task.h>
41 #include <ti/sysbios/knl/Clock.h>
43 #include <paftyp.h>
44 #include <pafsys_a.h> 
45 #include "noasp.h"
46 #include "systemStream.h"
48 // Minimum time between invocation of system stream processing
49 #define SYSTEM_STREAM_PROC_INTERVAL ( 1000 )    // in msec.
51 const struct {
52     PAF_SST_FxnsMain *main;
53     Int count;
54     struct {
55         PAF_SST_FxnsCompute  *compute;
56         PAF_SST_FxnsTransmit *transmit;
57     } sub[5];
58 } systemStreamPrimaryFxns =
59 {
60     &systemStreamMain,
61     5,
62     {
63         { &systemStream1Compute, &systemStream1Transmit, },
64 #ifndef NOBM
65         { &systemStream2Compute, &systemStream2Transmit, },
66 #else
67         { NULL, NULL, },
68 #endif        
69 #ifndef NODEM
70         { &systemStream3Compute, &systemStream3Transmit, },
71 #else
72         { NULL, NULL, },
73 #endif        
74 #ifdef THX
75         { &systemStream4Compute, &systemStream4Transmit, },
76 #else
77         { NULL, NULL, },
78 #endif
79         { &systemStream5Compute, &systemStream5Transmit, },
80     },
81 };
83 const PAF_SST_Params systemStreamParams_PA[1] =
84 {
85     {
86         1, 0, 1, 1,                                     // streams, stream1, streamN, ss    
87         (const PAF_SST_Fxns *)&systemStreamPrimaryFxns, // fxns
88     },
89 };
91 #define systemStreamParams systemStreamParams_PA
93 // Default system status
94 PAF_SystemStatus systemStreamStatus[1] = {
95     {
96         sizeof (PAF_SystemStatus),
97         PAF_SYS_MODE_ALL,               // mode
98         0,                              // listeningMode
99         PAF_SYS_RECREATIONMODE_AUTO,    // recreationMode
100         2 + PAF_SYS_SPEAKERSIZE_SMALL,  // speakerMain
101         1 + PAF_SYS_SPEAKERSIZE_SMALL,  // speakerCntr
102         2 + PAF_SYS_SPEAKERSIZE_SMALL,  // speakerSurr
103         2 + PAF_SYS_SPEAKERSIZE_SMALL,  // speakerBack
104         1 + PAF_SYS_SPEAKERSIZE_BASS,   // speakerSubw
105         PAF_SYS_CCRTYPE_STANDARD,       // channelConfigurationRequestType
106         0, 0, 0,                        // switchImage, imageNum, imageNumMax
107         0,                              // Unused
108         0, 0,                           // cpuLoad, peakCpuLoad
109         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerWide
110         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerHead
111         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerTopfront
112         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerToprear
113         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerTopmiddle
114         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerFrontheight
115         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerRearheight
116         0,                              // unused2
117         PAF_CC_SAT_UNKNOWN, PAF_CC_SUB_ZERO, 0, 0, 0, 0, 0, 0,  // channelConfigurationRequest
118 #ifdef FULL_SPEAKER // paftyp.h
119         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerScreen
120         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerSurr1
121         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerSurr2
122         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerRearSurr1
123         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerRearSurr2
124         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerCntrSurr
125         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerLRCntr
126         0 + PAF_SYS_SPEAKERSIZE_NONE,   // speakerLRCntrSurr
127 #endif
128         0, 0,                           // asitLoad, peakAsitLoad
129         0, 0,                           // asotLoad, peakAsotLoad
130         0, 0,                           // aipLoad,  peakAipLoad
131         0, 0,                           // afpLoad,  peakAfpLoad
132         0, 0                            // ssLoad,   peakSsLoad        
133     },
134 };
136 PAF_SST_Config systemStreamConfig[1] =
138     {
139         NULL,                           // acp
140         &systemStreamStatus[0],         // pStatus
141     },
142 };
145 extern Int gSysInit;
147 // FL: debug
148 //#define MAX_CAP_CUR_TIME ( 100 )
149 //UInt32 gCurTime[MAX_CAP_CUR_TIME];
150 //Uint32 gCurTimeIdx=0;
152 /*
153  *  ======== taskSystemStreamFxn ========
154  *  IDLE function for audio stream
155  */
156 Void taskSystemStreamFxn()
158     Int32 i;
159     UInt32 elapsed, now, then=0;
160     UInt32 time, interval;
162     //System_printf("Enter idleAudioStream()\n");    
163     //Log_info0("Enter idleAudioStream()");
165     time = SYSTEM_STREAM_PROC_INTERVAL; // in msec.
167     while (1)
168     {
169         // Compute interval in system clock ticks, interval time expressed in msec.
170         // Performing calculation inside while loop allows changes in system clock tick period.
171         interval = time * USEC_PER_MSEC / Clock_tickPeriod;
173         // Compute elapsed time
174         // Note in case of wrap of 32-bit return value for now,
175         // (now-then) calculation is correct despite (now<then)
176         // due to 2s complement arithmetic.
177         now = Clock_getTicks();
178         elapsed = now - then;
179         then = now; // latch "now" as "then" for next iteration
181         // If elapsed time since last iteration is less than desired System Stream period,
182         // then sleep until interval has passed.
183         // Otherwise execute functions in System Stream.
184         if (interval > elapsed)
185         {
186             Task_sleep(interval - elapsed);
187         }
189         //if (gSysInit == 0)
190         //  return;
191     
192         // FL: debug
193         //gCurTime[gCurTimeIdx] = Clock_getTicks();
194         //gCurTimeIdx++;
195         //if (gCurTimeIdx >= MAX_CAP_CUR_TIME)
196         //{
197         //    gCurTimeIdx = 0;
198         //}
200         for (i=0; i < lengthof(systemStreamConfig); i++)
201         {
202             systemStreamParams[i].fxns->main
203                 (&systemStreamParams[i], &systemStreamConfig[i]);            
204         }
206         if (gSysInit == 0)
207         {
208             gSysInit = 1;  // Indicate system Init to resume
209         }
210     }