]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - pasdk/common/components/clk.c
dd88a31277dce83535716bffdc42b4673f5a85d9
[processor-sdk/performance-audio-sr.git] / pasdk / common / components / clk.c
1 /*
2  * clk.c
3  *
4  *  Created on: Apr 2, 2017
5  *      Author: a0216546
6  */
8 #define KERNEL_BUG    0     /* Put it to 1 if you want to test for kernel bug (clock module configuration) */
10 #include <stdint.h>
12 #include <xdc/runtime/System.h>       /* for System_printf() */
14 /* BIOS Header files */
15 #include <ti/sysbios/BIOS.h>          /* mandatory - if you call APIs like BIOS_start() */
16 #include <ti/sysbios/knl/Semaphore.h> /* this looks obvious */
17 #include <ti/sysbios/knl/Task.h>
18 #include <ti/sysbios/knl/Swi.h>
19 #include <ti/sysbios/hal/Hwi.h>
21 /* Build configurations like semaphore handles, etc. */
22 #include <xdc/cfg/global.h>           /* header file for statically defined objects/handles */
24 /* Local Header files */
25 #include "clk.h"
26 #include "../pfp/pfp.h"
27 #include "../pfp_app.h"
29 /* Macros */
30 #define loop  while(1)
32 #include <xdc/runtime/Timestamp.h>    /* for benchmarking/profiling */
33 #define Timestamp_get Timestamp_get32 /* use 32-bit time stamps */
35 volatile int GET_STATS_COUNT = 3000;  /* Get stats after 3000 iterations */
37 /*----------------------------------------------------------------------------------- 
38   clkWorkDelay: Waste time based on actial work
39  *-----------------------------------------------------------------------------------*/
41 #include <math.h>
43 void clkWorkDelay(int loopcnt)
44 {
45   int k;
46   volatile double x, y, z;
48   x = 3.14/6;
49   y = 3.14/3;
50   for (k = 0; k < loopcnt; k++) {
51       z = sin(x)+cos(y);
52   }
53 } /* clkWorkDelay */
55 /*----------------------------------------------------------------------------------- 
56   clkDelay: Waste time based on time stamp
57  *-----------------------------------------------------------------------------------*/
59 void clkDelay(uint32_t pause)
60 {
61   volatile uint32_t now,then;
63   now = then = Timestamp_get();
64   while( (now-then) < pause ) {
65     now = Timestamp_get();
66   }
67 } /* clkDelay */
69 #if 0
70 /*------------------------------------------------------------ 
71   clk0Fun: Wakes up task0 which runs every 100ms
72  *------------------------------------------------------------*/
74 #if KERNEL_BUG
75 int clk0prev = 0;
76 #endif
78 void clk0Fun(void)
79 {
80   Semaphore_post(semTask0WakeUp);
82 #if KERNEL_BUG
83   if (clk0prev == GET_STATS_COUNT) {
84     clk0prev = -1;
85   }
86   else {
87     clk0prev = GET_STATS_COUNT;
88   }
89 #endif
90 } /* clk0Fun */
92 /*------------------------------------------------------------ 
93   clk1Fun: Wakes up task1 which runs every 100ms
94  *------------------------------------------------------------*/
96 #if KERNEL_BUG
97 int clk1prev = 0;
98 #endif
100 void clk1Fun(void)
102   Semaphore_post(semTask1WakeUp);
104 #if KERNEL_BUG
105   if (clk1prev == GET_STATS_COUNT) {    /* This was used for chasing SYS/BIOS Kernel bug */
106     clk1prev = -1;
107   }
108   else {
109     clk1prev = GET_STATS_COUNT;
110   }
111 #endif
113 } /* clk1Fun */
115 /*------------------------------------------------------------- 
116   task0Fun: Task0 runs every 100ms and uses 30ms of time
117  *-------------------------------------------------------------*/
119 #include <stdio.h>
121 int reset_hangover = -1;
123 //#pragma CODE_SECTION(task0Fun,".pfpsection")
125 void task0Fun(void)
127   int k;
128   pfpStats_t pfp_stats;
129   IArg swiKey, hwiKey;
130   Task_Handle myHandle;
132   /* Task initialization */
133   myHandle = Task_self();
135   reset_hangover = -1;          /* No need for stat reset */
137   /* Main loop */
138   loop {
140     pfpEnd(PFP_ID_TASK0_2,0);     /* This is OK to do since the first time it would be ignored! */
141     /* We placed the end of measurement here since we do not want to measure the printf's below
142        which are only used at the end of the test after which we would hit a break point */
144     if (GET_STATS_COUNT > 0) {
145       GET_STATS_COUNT--;
146     }
147     else {
148       hwiKey=Hwi_disable();
149       swiKey=Swi_disable();
151       for (k = 0; k <= PFP_ID_LAST; k++) {
152         pfpGetStats(k, &pfp_stats);
153         printf("ID: %02d, n=%u, C=%lld, Cmin=%u, Cmax=%u, C-avg=%g, Avg-T=%gms, Alpha=%g, C_eavg=%g, EAvg-T=%gms\n", k,
154                pfp_stats.n_count,
155                pfp_stats.c_total,
156                pfp_stats.c_min,
157                pfp_stats.c_max,
158                (double)pfp_stats.c_total/pfp_stats.n_count,
159                (double)pfp_stats.c_total/pfp_stats.n_count/CLK_CLOCKS_PER_MS,
160                pfp_stats.alpha,
161                pfp_stats.c_average,
162                pfp_stats.c_average/CLK_CLOCKS_PER_MS);
163       }
165       GET_STATS_COUNT = 3000;
166       reset_hangover = 3;     /* <----------- you may put Breakpoint here! */
167       Swi_restore(swiKey);
168       Hwi_restore(hwiKey);
169     }
171     /* This code "recovers" after the breakpoint in order to "ignore" pending interrupts */
172     if (reset_hangover > 0) {
173       reset_hangover--;
174     }
175     else if (reset_hangover == 0) {
176       reset_hangover = -1;
178       hwiKey=Hwi_disable();
179       swiKey=Swi_disable();
181       for (k = 2; k <= PFP_ID_LAST; k++) {      /* Do not reset the first two PP's */
182         pfpResetStats(k);
183       }
185       Swi_restore(swiKey);
186       Hwi_restore(hwiKey);
187     }
189     pfpBegin(PFP_ID_TASK0_2, myHandle);
191     /*-------------------------------------------------------------------------------------*/
192     Semaphore_pend(semTask0WakeUp, BIOS_WAIT_FOREVER);  /* wait for clk0Fun to wake you up */
193     /*-------------------------------------------------------------------------------------*/
195     /* Waste time for 20ms */
196     pfpBegin(PFP_ID_TASK0_1, myHandle);
197       clkWorkDelay(20*CLK_WORKCNT_PER_MS);
198     pfpEnd(PFP_ID_TASK0_1,0);
200     /* Spend another 10ms but outside of previous profile point */
201     clkWorkDelay(10*CLK_WORKCNT_PER_MS);
203   }
205   /* Never come here */
207 } /* task0Fun */
209 /*------------------------------------------------------------- 
210   task1Fun: Task1 runs every 100ms and uses 23ms of time
211  *-------------------------------------------------------------*/
213 //#pragma CODE_SECTION(task1Fun,".pfpsection")
215 void task1Fun(void)
217   Task_Handle myHandle;
219   /* Task initialization */
220   myHandle = Task_self();
222   /* Main loop */
223   loop {
225     pfpEnd(PFP_ID_TASK1_3, 0);
226     pfpBegin(PFP_ID_TASK1_3, myHandle);          /* Measure "everything else" in this task! */
228     /*-------------------------------------------------------------------------------------*/
229     Semaphore_pend(semTask1WakeUp, BIOS_WAIT_FOREVER);  /* wait for clk1Fun to wake you up */
230     /*-------------------------------------------------------------------------------------*/
232     /* Waste time for 13ms */
233     pfpBegin(PFP_ID_TASK1_1, myHandle);
234       clkWorkDelay(13*CLK_WORKCNT_PER_MS);
235     pfpEnd(PFP_ID_TASK1_1, 0);
237     pfpBegin(PFP_ID_TASK1_2, myHandle);
238       clkWorkDelay(8*CLK_WORKCNT_PER_MS);
239     pfpEnd(PFP_ID_TASK1_2, 1);      /* latch this measurement */
241     pfpBegin(PFP_ID_TASK1_2, myHandle);
242       clkWorkDelay(2*CLK_WORKCNT_PER_MS);
243     pfpEnd(PFP_ID_TASK1_2, 0);      /* Complete this measurement */
245   }
248   /* Never come here */
250 } /* task1Fun */
252 #endif
254 /* nothing past this point */