]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/alphaIntervalProc.c
Remove processor_audio_sdk_1_00_00_00 subfolder
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / alphaIntervalProc.c
2 /*
3 Copyright (c) 2016, 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 /*
37  *  ======== alphaIntervalProc.c ========
38  */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Log.h>
43 #include <xdc/runtime/System.h>
44 #include <ti/sysbios/knl/Clock.h>
45 #include <ti/sysbios/knl/Task.h>
46 #include <ti/sysbios/hal/Timer.h>
48 #include <acp.h>
49 #include <acp_mds.h>
51 //#include <acptype.h>
52 #include <acpbeta.h>
53 //#include <pafstd_a.h>
55 #include "logp.h"
56 #include "pafaip.h"
57 #include "paf_alg_print.h"
58 #include "paf_heapMgr.h"
60 //#include "fwkSim.h"
61 #include "fwkPort.h"
63 // Symbolic constants for translating heap Ids to handles
64 #define HEAP_INTERNAL       (HeapMem_Handle)pafHeapMgr_readHeapHandle(gPafHeapIdInt)
65 #define HEAP_INTERNAL1      (HeapMem_Handle)pafHeapMgr_readHeapHandle(gPafHeapIdInt1)
66 #define HEAP_EXTERNAL       (HeapMem_Handle)pafHeapMgr_readHeapHandle(gPafHeapIdExt)
67 #define HEAP_INTERNAL1_SHM  (HeapMem_Handle)pafHeapMgr_readHeapHandle(gPafHeapIdInt1Shm)
69 //
70 // Alpha code shortcut arrays
71 //
73 #ifndef execSTDAtBoot
74 #define execSTDAtBoot 0xc102
75 #endif
77 #ifndef execALTAtBoot
78 #define execALTAtBoot ((execSTDAtBoot) + (ACP_SERIES_ALT-ACP_SERIES_STD << 12))
79 #endif
81 #ifndef execOEMAtBoot
82 #define execOEMAtBoot ((execSTDAtBoot) + (ACP_SERIES_OEM-ACP_SERIES_STD << 12))
83 #endif
85 #ifndef execCUSAtBoot
86 #define execCUSAtBoot ((execSTDAtBoot) + (ACP_SERIES_CUS-ACP_SERIES_STD << 12))
87 #endif
89 const ACP_Unit atboot_sA[][2] = 
90 {
91     { 0xc901, execSTDAtBoot, },
92     { 0xc901, execALTAtBoot, },
93     { 0xc901, execOEMAtBoot, },
94     { 0xc901, execCUSAtBoot, },
95 };
97 #ifndef execSTDAtTime
98 #define execSTDAtTime 0xc104
99 #endif
101 #ifndef execALTAtTime
102 #define execALTAtTime ((execSTDAtTime) + (ACP_SERIES_ALT-ACP_SERIES_STD << 12))
103 #endif
105 #ifndef execOEMAtTime
106 #define execOEMAtTime ((execSTDAtTime) + (ACP_SERIES_OEM-ACP_SERIES_STD << 12))
107 #endif
109 #ifndef execCUSAtTime
110 #define execCUSAtTime ((execSTDAtTime) + (ACP_SERIES_CUS-ACP_SERIES_STD << 12))
111 #endif
113 const ACP_Unit attime_sA[][2] = 
115     { 0xc901, execSTDAtTime, },
116     { 0xc901, execALTAtTime, },
117     { 0xc901, execOEMAtTime, },
118     { 0xc901, execCUSAtTime, },
119 };
121 const PAF_AlphaIntervalProcessingStatus aipStatusInit = 
123     sizeof (PAF_AlphaIntervalProcessingStatus),
124     3,      // mode
125     0x99,   // mask
126     100,    // time
127 };
129 Int gEnableRamReport = 0;  // set this in main if RAM_REPORT is desired.
131 // Global debug counters */
132 Uint32 gTaskAipCnt=0;
134 LINNO_DEFN (alphaIntervalProcessingTask); /* Line number macros */
135 ERRNO_DEFN (alphaIntervalProcessingTask); /* Error number macros */
137 /*
138  *  ======== taskAipFxn ========
139  *  Alpha Interval Processing task function
140  */
141 Void taskAipFxn(
142     Int betaPrimeValue
145     Int mode;
146     ALG_Handle acpAlg;
147     ACP_Handle acp;
148     Int betaPrime;
149     Int betaPrimeOffset;
150     PAF_AlphaIntervalProcessingStatus aipStatus;
151     Int errno;
152     UInt32 curTime;
153     
154     //System_printf("Enter taskAipFxn()\n");
155     Log_info0("Enter taskAipFxn()");
157     //
158     // Initialize
159     //
160     aipStatus = aipStatusInit;   
162     LINNO_RPRT(alphaIntervalProcessingTask, -1);
164     // Create an ACP algorithm instance with trace enabled
165     ACP_MDS_init ();
167     if (!(acpAlg = (ALG_Handle )ACP_MDS_create (NULL)))
168     {
169         //LOG_printf(&trace, "AIP: ACP algorithm instance creation failed");
170         Log_info0("AIP: ACP algorithm instance creation failed");
171         LINNO_RPRT(alphaIntervalProcessingTask, __LINE__);
172         return;
173     }
174     
175     acpAlg->fxns->algControl (acpAlg, ACP_GETBETAPRIMEOFFSET, 
176         (IALG_Status *) &betaPrimeOffset);
177     betaPrime = betaPrimeOffset * betaPrimeValue;
179     acp = (ACP_Handle )acpAlg;
180     acp->fxns->attach(acp, ACP_SERIES_STD, STD_BETA_SYSINT+betaPrime, 
181         (IALG_Status *)&aipStatus);
182     
183     //LOG_printf(&trace, "AIP: ACP processing initialized");
184     Log_info0("AIP: ACP processing initialized");
186     if (gEnableRamReport)
187     {
188         PAF_ALG_memStatusPrint(HEAP_INTERNAL, HEAP_INTERNAL1, HEAP_EXTERNAL, HEAP_INTERNAL1_SHM);
189     }
190     
191     // Set default stream
192     if (betaPrimeValue != 0)
193     {
194         ACP_Unit stream_s[2] = { 0xcd09, 0x0400, };
196         stream_s[1] += betaPrimeValue;
197         if (errno = acp->fxns->apply (acp, stream_s, NULL)) 
198         {
199             //LOG_printf(&trace, "AIP: at boot stream error 0x%04x sending 0x%x, 0x%x",
200             //        errno, stream_s[0], stream_s[1]);
201             Log_info3("AIP: at boot stream error 0x%04x sending 0x%x, 0x%x",
202                 errno, stream_s[0], stream_s[1]);
203             LINNO_RPRT(alphaIntervalProcessingTask, __LINE__);
204             return;
205         }
206     }
208     // Process at boot interval if mode is non-zero
209     if (mode = aipStatus.mode) 
210     {
211         Int i;
212         Int mask = aipStatus.mask;
213         for (i=0; i < 4; i++)
214         {
215             if (mask & (0x01 << i)) 
216             {
217                 //LOG_printf(&trace, "AIP: at boot %d: %x, %x", i, atboot_sA[i][0], atboot_sA[i][1]);
218                 Log_info3("AIP: at boot %d: %x, %x", i, atboot_sA[i][0], atboot_sA[i][1]);
219                 if (errno = acp->fxns->sequence(acp, atboot_sA[i], NULL)) 
220                 {
221                     //LOG_printf(&trace, "AIP: at boot series %d error (0x%04x) <ignored>", i, errno);
222                     Log_info2("AIP: at boot series %d error (0x%04x) <ignored>", i, errno);
223                     ERRNO_RPRT (alphaIntervalProcessingTask, errno);
224                 }
225                 else
226                 {
227                     //LOG_printf(&trace, "AIP: at boot series %d process", i);                    
228                     Log_info1("AIP: at boot series %d process", i);                    
229                 }
230             }
231         }
232     }
233     
234     LINNO_RPRT(alphaIntervalProcessingTask, -2);
236     //
237     // Run until task is destroyed by the system 
238     //    
239     
240     while (mode = aipStatus.mode)
241     {
242         Uns time, interval, elapsed, now, then;
244         while (((mode = aipStatus.mode) > 1) && ((time = aipStatus.time) > 0))
245         {
246             // Compute interval in system clock ticks,
247             // interval time expressed in msec.
248             // Note: time can be updated via alpha commands
249             interval = time * USEC_PER_MSEC / Clock_tickPeriod; //interval = (CLK_countspms() * time) / CLK_getprd();            
250             
251             // Compute elapsed time
252             now = Clock_getTicks(); //now = TSK_time ();            
253             elapsed = now - then;
254             then = now;
255             
256             if (interval > elapsed)
257             {
258                 Task_sleep(interval - elapsed); //TSK_sleep (interval - elapsed);
259             }
261             if (mode > 2)
262             {
263                 Int i;
264                 Int mask = aipStatus.mask;
265                 for (i=0; i < 4; i++) 
266                 {
267                     if (mask & (0x10 << i))
268                     {
269                         if (errno = acp->fxns->sequence(acp, attime_sA[i], NULL))
270                         {
271                             // LOG_printf(&trace, "AIP: at time series %d error (0x%04x) <ignored>", i, errno);
272                             // Log_info2("AIP: at time series %d error (0x%04x) <ignored>", i, errno);
273                             ERRNO_RPRT (alphaIntervalProcessingTask, errno);
274                         }
275                         else
276                         {
277                             // LOG_printf(&trace, "AIP: at time series %d process", i);
278                             // Log_info1("AIP: at time series %d process", i);
279                         }
280                     }
281                 }
282             }
283             
284             gTaskAipCnt++;
285             curTime = Clock_getTicks();
286             //System_printf("System time in taskAipFxn = %lu\n", (ULong)curTime);
287             //Log_info1("System time in taskAipFxn = %u", curTime);
288         }
289     }
291     // Block until re-prioritized when mode or time is zero
292     LINNO_RPRT(alphaIntervalProcessingTask, __LINE__);
293     Task_setPri(Task_self(), -1);   //TSK_setpri( TSK_self(), -1);
294     Task_yield();                   //TSK_yield();
295     
296     //System_printf("Exit taskAipFxn()\n");
297     Log_info0("Exit taskAipFxn()");