[processor-sdk/performance-audio-sr.git] / processor_audio_sdk_1_00_00_00 / pasdk / test_dsp / framework / fwkSim.c
1 /*
2 * ======== fwkSim.c ========
3 */
5 #include <xdc/std.h>
6 #include <xdc/cfg/global.h>
7 #include <xdc/runtime/Error.h>
8 #include <xdc/runtime/Log.h>
9 #include <ti/sysbios/knl/Clock.h>
10 #include <ti/sysbios/knl/Semaphore.h>
11 #include <ti/sysbios/hal/Hwi.h>
12 #include <ti/sysbios/hal/Timer.h>
13 #include <ti/sysbios/family/c64p/EventCombiner.h>
14 #include <ti/csl/soc/k2g/src/cslr_soc.h>
16 #include "fwkSim.h"
18 #ifdef SIMULATE_SIO
19 #define SIM_TIMER_HWI ( 7 )
21 // Global debug counters
22 Uint32 gTimerRxCnt=0;
23 Uint32 gTimerTxCnt=0;
24 #endif // SIMULATE_SIO
26 #ifdef SIMULATE_RX_ALPHA
27 // Global debug counter
28 Uint32 gClockRxAlphaCnt=0;
29 #endif
31 #ifdef SIMULATE_SIO
32 /*
33 * ======== timerRxFxn ========
34 */
35 Void timerRxFxn(UArg a0)
36 {
37 gTimerRxCnt++;
39 /* Post semaphore indicating Rx audio frame */
40 Semaphore_post(semaphoreRxAudio);
41 }
43 /*
44 * ======== timerTxFxn ========
45 */
46 Void timerTxFxn(UArg a0)
47 {
48 gTimerTxCnt++;
50 /* Post semaphore indicating Tx audio frame */
51 Semaphore_post(semaphoreTxAudio);
52 }
54 // Simulation initialization
55 Void simInit(Void)
56 {
57 Hwi_Params hwiParams;
58 //Error_Block eb;
60 // Initialize the error block
61 //Error_init(&eb);
63 // Initialize simulation
64 // Plug the function and argument for Timer1L event and enable it
65 // Plug the function and argument for Timer2L event and enable it
66 EventCombiner_dispatchPlug(CSL_C66X_COREPAC_TIMER_1_INTL, &timerRxFxn, 0, TRUE);
67 EventCombiner_dispatchPlug(CSL_C66X_COREPAC_TIMER_2_INTL, &timerTxFxn, 0, TRUE);
69 // Initialize the Hwi parameters
70 Hwi_Params_init(&hwiParams);
71 // The eventId must be set to the combined event for Timer1L or Timer2L event.
72 // The combined event is event 1 for both. If the combined events are
73 // different, then another Hwi must be used for the other combined event.
74 hwiParams.eventId = CSL_C66X_COREPAC_EVT1;
75 // The arg must be set to hwiParams.eventId
76 hwiParams.arg = hwiParams.eventId;
77 // Enable the interrupt
78 hwiParams.enableInt = FALSE; //TRUE;
79 // Events Timer1L and Timer2L are on the same combined event so create a single Hwi.
80 // Create the Hwi on interrupt 15 then specify 'EventCombiner_dispatch'
81 // as the function.
82 //Hwi_create(SIM_TIMER_HWI, &EventCombiner_dispatch, &hwiParams, &eb);
83 Hwi_create(SIM_TIMER_HWI, &EventCombiner_dispatch, &hwiParams, NULL);
84 }
86 // Simulation start
87 Void simStart(Void)
88 {
89 UInt32 curTime;
91 // Start Rx audio clock -- Simulate Rx audio frame time */
92 //System_printf("Start Rx audio clock\n");
93 Log_info0("Start Rx audio clock");
94 Timer_start(timerRxAudio);
96 // Wait for Rx-Tx delay system ticks before starting Tx audio clock.
97 // Control phase difference between Rx and Tx audio clocks.
98 curTime = Clock_getTicks();
99 while (Clock_getTicks() <= (curTime + RX_TX_AUDIO_DELTA_TICKS))
100 {
101 ;
102 }
104 // Start Tx audio clock -- Simulate Tx audio frame time
105 //System_printf("Start Tx audio clock\n");
106 Log_info0("Start Tx audio clock");
107 Timer_start(timerTxAudio);
109 Hwi_enableInterrupt(SIM_TIMER_HWI);
110 }
112 // Simulation stop
113 Void simStop(Void)
114 {
115 Hwi_disableInterrupt(SIM_TIMER_HWI);
116 Hwi_clearInterrupt(SIM_TIMER_HWI);
117 EventCombiner_disableEvent(CSL_C66X_COREPAC_TIMER_1_INTL);
118 EventCombiner_disableEvent(CSL_C66X_COREPAC_TIMER_2_INTL);
119 }
120 #endif // SIMULATE_SIO
122 #ifdef SIMULATE_RX_ALPHA
123 /*
124 * ======== clockRxAlphaFxn ========
125 */
126 Void clockRxAlphaFxn(UArg a0)
127 {
128 gClockRxAlphaCnt++;
130 /* Post semaphore indicating Rx alpha command */
131 Semaphore_post(semaphoreRxAlpha);
132 }
133 #endif
135 // Simulate load
136 Void simLoad(
137 Uint32 loadTime // load time in system clock ticks
138 )
139 {
140 UInt32 curTime;
142 curTime = Clock_getTicks();
143 while (Clock_getTicks() <= (curTime + loadTime))
144 {
145 ;
146 }
147 }