]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/test_dsp/framework/fwkSim.c
Re-order CAR and OAR in patches since OAR overwrites audio frame bitstream metadata...
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / framework / fwkSim.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  *  ======== fwkSim.c ========
38  */
40 #include <xdc/std.h>
41 #include <xdc/cfg/global.h>
42 #include <xdc/runtime/Error.h>
43 #include <xdc/runtime/Log.h>
44 #include <ti/sysbios/knl/Clock.h>
45 #include <ti/sysbios/knl/Semaphore.h>
46 #include <ti/sysbios/hal/Hwi.h>
47 #include <ti/sysbios/hal/Timer.h>
48 #include <ti/sysbios/family/c64p/EventCombiner.h>
49 #include <ti/csl/soc/k2g/src/cslr_soc.h>
51 #include "fwkSim.h"
53 #ifdef SIMULATE_SIO
54 #define SIM_TIMER_HWI   ( 7 )
56 // Global debug counters
57 Uint32 gTimerRxCnt=0;
58 Uint32 gTimerTxCnt=0;
59 #endif // SIMULATE_SIO
61 #ifdef SIMULATE_RX_ALPHA
62 // Global debug counter
63 Uint32 gClockRxAlphaCnt=0;
64 #endif
66 #ifdef SIMULATE_SIO
67 /*
68  *  ======== timerRxFxn ========
69  */
70 Void timerRxFxn(UArg a0)
71 {
72     gTimerRxCnt++;
73     
74     /* Post semaphore indicating Rx audio frame */
75     Semaphore_post(semaphoreRxAudio); 
76 }
78 /*
79  *  ======== timerTxFxn ========
80  */
81 Void timerTxFxn(UArg a0)
82 {
83     gTimerTxCnt++;
84     
85     /* Post semaphore indicating Tx audio frame */
86     Semaphore_post(semaphoreTxAudio); 
87 }
89 // Simulation initialization
90 Void simInit(Void)
91 {
92     Hwi_Params hwiParams;
93     //Error_Block eb;
94     
95     // Initialize the error block
96     //Error_init(&eb);
97     
98     // Initialize simulation
99     // Plug the function and argument for Timer1L event and enable it
100     // Plug the function and argument for Timer2L event and enable it
101     EventCombiner_dispatchPlug(CSL_C66X_COREPAC_TIMER_1_INTL, &timerRxFxn, 0, TRUE);
102     EventCombiner_dispatchPlug(CSL_C66X_COREPAC_TIMER_2_INTL, &timerTxFxn, 0, TRUE);
103     
104     // Initialize the Hwi parameters
105     Hwi_Params_init(&hwiParams);
106     // The eventId must be set to the combined event for Timer1L or Timer2L event.
107     // The combined event is event 1 for both.  If the combined events are
108     // different, then another Hwi must be used for the other combined event.
109     hwiParams.eventId = CSL_C66X_COREPAC_EVT1;
110     // The arg must be set to hwiParams.eventId
111     hwiParams.arg = hwiParams.eventId;
112     // Enable the interrupt
113     hwiParams.enableInt = FALSE; //TRUE;
114     // Events Timer1L and Timer2L are on the same combined event so create a single Hwi.
115     // Create the Hwi on interrupt 15 then specify 'EventCombiner_dispatch'
116     // as the function.
117     //Hwi_create(SIM_TIMER_HWI, &EventCombiner_dispatch, &hwiParams, &eb);
118     Hwi_create(SIM_TIMER_HWI, &EventCombiner_dispatch, &hwiParams, NULL);
121 // Simulation start
122 Void simStart(Void)
124     UInt32 curTime;
126     // Start Rx audio clock --  Simulate Rx audio frame time */
127     //System_printf("Start Rx audio clock\n");
128     Log_info0("Start Rx audio clock");
129     Timer_start(timerRxAudio);
130     
131     // Wait for Rx-Tx delay system ticks before starting Tx audio clock.
132     // Control phase difference between Rx and Tx audio clocks.
133     curTime = Clock_getTicks();
134     while (Clock_getTicks() <= (curTime + RX_TX_AUDIO_DELTA_TICKS)) 
135     {
136         ;
137     }
139     // Start Tx audio clock -- Simulate Tx audio frame time
140     //System_printf("Start Tx audio clock\n");
141     Log_info0("Start Tx audio clock");
142     Timer_start(timerTxAudio);
143     
144     Hwi_enableInterrupt(SIM_TIMER_HWI);
147 // Simulation stop
148 Void simStop(Void)
150     Hwi_disableInterrupt(SIM_TIMER_HWI);
151     Hwi_clearInterrupt(SIM_TIMER_HWI);
152     EventCombiner_disableEvent(CSL_C66X_COREPAC_TIMER_1_INTL);
153     EventCombiner_disableEvent(CSL_C66X_COREPAC_TIMER_2_INTL);
155 #endif // SIMULATE_SIO
157 #ifdef SIMULATE_RX_ALPHA
158 /*
159  *  ======== clockRxAlphaFxn ========
160  */
161 Void clockRxAlphaFxn(UArg a0)
163     gClockRxAlphaCnt++;
164         
165     /* Post semaphore indicating Rx alpha command */
166     Semaphore_post(semaphoreRxAlpha); 
168 #endif
170 // Simulate load 
171 Void simLoad(
172     Uint32 loadTime // load time in system clock ticks
175     UInt32 curTime;
176     
177     curTime = Clock_getTicks();
178     while (Clock_getTicks() <= (curTime + loadTime)) 
179     {
180         ;
181     }