1 /*
2 * audioSample_io.c
3 *
4 * This file contains the test / demo code to demonstrate the Audio component
5 * driver functionality on SYS/BIOS 6.
6 *
7 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
20 * distribution.
21 *
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 */
40 /** \file audioSample_io.c
41 *
42 * \brief sample application for profiling
43 *
44 * (C) Copyright 2017, Texas Instruments, Inc
45 */
47 /* ========================================================================== */
48 /* INCLUDE FILES */
49 /* ========================================================================== */
51 #include <xdc/std.h>
52 #include "MCASP_log.h"
53 #include "stdio.h"
54 #include "string.h"
55 #include "profiling.h"
56 #include <ti/osal/osal.h>
58 static uint64_t total_ticks=0;
59 static uint32_t start_time, end_time,ticks_per_ms,total_num_frames=0;
61 static uint32_t readTime32(void)
62 {
63 uint32_t timeVal;
65 #if defined (_TMS320C6X)
66 timeVal = TSCL;
67 #else
68 __asm__ __volatile__ ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(timeVal));
69 #endif
70 return timeVal;
71 }
72 static uint32_t time_diff(uint32_t s_time, uint32_t e_time)
73 {
74 uint32_t ticks_lapsed;
75 if(e_time > s_time) {
76 ticks_lapsed=e_time-s_time;
77 } else {
78 ticks_lapsed = (0xFFFFFFFF - s_time) + e_time;
79 }
80 return(ticks_lapsed);
81 }
83 void profiling_init()
84 {
85 uint32_t ticks_diff;
86 #if defined (_TMS320C6X) || defined(__TI_ARM_V7M4__)
87 // Do nothing for C6x and M4 cores
88 #else
89 /* PMCR
90 31......24 23......16 15....11 10.....6 5 4 3 2 1 0
91 IMP IDCODE N Res DP X D C P E
92 [31:24] IMP: Implementer code; read-only
93 [23:16] IDCODE: Identification code; read-only
94 [15:11] N: Number of event counters; read-only
95 [10:6] Reserved
96 [5] DP: Disable cycle counter in prohibited regions; r/w
97 [4] X: Export enable; r/w
98 [3] D: Clock divider - PMCCNTR counts every 64 clock cycles when enabled; r/w
99 [2] C: Clock counter reset; write-only
100 [1] P: Event counter reset; write-only
101 [0] E: Enable all counters; r/w
102 */
103 __asm__ __volatile__ ("MCR p15, 0, %0, c9, c12, 0\t\n" :: "r"(0x17));
105 /* PMCNTENSET - Count Enable Set Register */
106 __asm__ __volatile__ ("MCR p15, 0, %0, c9, c12, 1\t\n" :: "r"(0x8000000f));
108 /* PMOVSR - Overflow Flag Status Register */
109 __asm__ __volatile__ ("MCR p15, 0, %0, c9, c12, 3\t\n" :: "r"(0x8000000f));
110 #endif
112 MCASP_log("Ticks Calibration Start\n");
113 start_time=readTime32();
114 Osal_delay(1000);
115 end_time=readTime32();
116 ticks_diff=time_diff(start_time,end_time);
117 ticks_per_ms = ticks_diff/(1*1000);
119 MCASP_log("Ticks Calibration End after 1 seconds\n");
120 MCASP_log("Ticks per msec= %u, Time Diff = %u , start =%u, end=%u",ticks_per_ms,ticks_diff, start_time,end_time);
121 }
123 void profiling_start()
124 {
125 start_time=readTime32();
126 }
128 void profiling_end()
129 {
130 end_time=readTime32();
131 total_ticks+=time_diff(start_time,end_time);
132 total_num_frames++;
133 }
135 void profiling_display_results()
136 {
137 uint32_t ms_per_frame;
138 uint32_t ticks_per_frame;
140 ticks_per_frame=total_ticks/total_num_frames;
141 ms_per_frame=total_ticks/(total_num_frames*ticks_per_ms);
142 MCASP_log("\n Ticks per frame = %u ",ticks_per_frame);
143 MCASP_log("\n Time elapsed per frame = %u ms",ms_per_frame);
144 MCASP_log("\n Total Time elapsed for %d frames = %u seconds",total_num_frames,(ms_per_frame*total_num_frames)/1000);
145 }