[processor-sdk/performance-audio-sr.git] / psdk_cust / libarch_k2g_1_0_1_0 / examples / arm+dsp / test_lib_dsp.c
1 /******************************************************************************
2 * Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Texas Instruments Incorporated nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 *****************************************************************************/
28 #include <stdio.h>
29 #include <ti/libarch/libarch.h>
31 #define TEST_MEM_NOERR 0
32 #define TEST_MEM_ERROR 1
34 extern void test_GetSizes(size_t *smem_size_vfast, size_t *smem_size_fast,
35 size_t *smem_size_med, size_t *smem_size_slow);
36 extern int test_Init(void * svfast_buf_base, size_t svfast_buf_size,
37 void * sfast_buf_base, size_t sfast_buf_size,
38 void * smem_buf_base, size_t smem_buf_size,
39 void * sslow_buf_base, size_t sslow_buf_size);
41 /*==============================================================================
42 * This function prepares memory for the processing function
43 *============================================================================*/
44 int lib_config_memory(void *msmc_mem_base, size_t msmc_mem_size,
45 void *ddr_mem_base, size_t ddr_mem_size,
46 size_t *l1D_SRAM_size_orig, size_t *l2_SRAM_size_orig)
47 {
48 size_t smem_size_vfast, smem_size_fast, smem_size_med, smem_size_slow;
49 void *l1d_SRAM_ptr, *l2_SRAM_ptr;
50 int l1d_cfg_err, l2_cfg_err;
52 printf("DSP: Check memory requirement and configure L1D/L2 if necessary.\n");
54 /* First, verify the provided/available memory meet requirements */
55 test_GetSizes(&smem_size_vfast, &smem_size_fast, &smem_size_med, &smem_size_slow);
57 printf("Required very fast memory size is %d, fast memory size is %d, medium memory size is %d, slow memory size is %d\n",
58 smem_size_vfast, smem_size_fast, smem_size_med, smem_size_slow);
60 printf("Available very fast memory size is %d, fast memory size is %d, medium memory size is %d, slow memory size is %d\n",
61 lib_get_L1D_total_size(), lib_get_L2_total_size(), msmc_mem_size, ddr_mem_size);
63 *l1D_SRAM_size_orig = lib_get_L1D_SRAM_size(); /* get current L1D SRAM size */
64 printf("Original L1D SRAM size is %d.\n", *l1D_SRAM_size_orig);
66 *l2_SRAM_size_orig = lib_get_L2_SRAM_size(); /* get current L2 SRAM size */
67 printf("Original L2 SRAM size is %d.\n", *l2_SRAM_size_orig);
69 if( (smem_size_vfast> lib_get_L1D_total_size()) /* available L1D SRAM */
70 ||(smem_size_fast > lib_get_L2_total_size()) /* available L2 SRAM */
71 ||(smem_size_med > msmc_mem_size) /* provided MSMC memory */
72 ||(smem_size_slow > ddr_mem_size) /* provided DDR memory */
73 ) {
74 printf("No enough memory!\n");
75 return(TEST_MEM_ERROR);
76 }
78 /* Configure L1D if necessary */
79 l1d_cfg_err = LIB_CACHE_SUCCESS;
80 if(*l1D_SRAM_size_orig <= smem_size_vfast) { /* configure L1D if needs more SRAM */
81 #pragma omp parallel
82 {
83 l1d_cfg_err = lib_L1D_config_SRAM(smem_size_vfast);
84 }
85 }
87 /* Configure L2 if necessary */
88 l2_cfg_err = LIB_CACHE_SUCCESS;
89 if(*l2_SRAM_size_orig <= smem_size_fast) { /* configure L2 if needs more SRAM */
90 #pragma omp parallel
91 {
92 l2_cfg_err = lib_L2_config_SRAM(smem_size_fast);
93 }
94 }
96 if(l1d_cfg_err || l2_cfg_err) {
97 printf("Error in configuring L1D and L2!\n.");
98 return(TEST_MEM_ERROR);
99 }
101 printf("Configured L1D SRAM size is %d.\n", lib_get_L1D_SRAM_size());
102 printf("Configured L2 SRAM size is %d.\n", lib_get_L2_SRAM_size());
104 /* get L1D and L2 SRAM base address */
105 l1d_SRAM_ptr = lib_get_L1D_SRAM_base();
106 l2_SRAM_ptr = lib_get_L2_SRAM_base();
108 printf("L1D SRAM base address is 0x%x.\n", (unsigned int)l1d_SRAM_ptr);
109 printf("L2 SRAM base address is 0x%x.\n", (unsigned int) l2_SRAM_ptr);
111 /* pass allocated memories for heap initialization */
112 if(test_Init(l1d_SRAM_ptr, smem_size_vfast,
113 l2_SRAM_ptr, smem_size_fast,
114 msmc_mem_base, smem_size_med,
115 ddr_mem_base, smem_size_slow)) {
116 return(TEST_MEM_ERROR);
117 }
119 return(TEST_MEM_NOERR);
120 } /* lib_config_memory */
123 /*==============================================================================
124 * This function reconfigures L1D and L2 after processing is finished
125 *============================================================================*/
126 int lib_reconfig_memory(size_t l1D_SRAM_size_orig, size_t l2_SRAM_size_orig)
127 {
128 int l1d_cfg_err, l2_cfg_err;
130 printf("Reconfiguring L1D and L2.\n");
131 printf("L1D total size is %d.\n", lib_get_L1D_total_size());
132 printf("Original L1D SRAM size is %d.\n", l1D_SRAM_size_orig);
133 printf("Original L2 SRAM size is %d.\n", l2_SRAM_size_orig);
135 /* configure L1D back */
136 l1d_cfg_err = LIB_CACHE_SUCCESS;
137 if(l1D_SRAM_size_orig!=lib_get_L1D_SRAM_size()) {
138 #pragma omp parallel
139 {
140 l1d_cfg_err = lib_L1D_config_SRAM(l1D_SRAM_size_orig);
141 //__cache_l1d_all();
142 }
143 }
145 l2_cfg_err = LIB_CACHE_SUCCESS;
146 if(l2_SRAM_size_orig <= lib_get_L2_SRAM_size()) {
147 #pragma omp parallel
148 {
149 l2_cfg_err = lib_L2_config_SRAM(l2_SRAM_size_orig);
150 }
151 }
153 /* configure L1D and L2 back */
154 if(l1d_cfg_err || l2_cfg_err) {
155 printf("Error in reconfiguring L1D and L2!\n.");
156 return(TEST_MEM_ERROR);
157 }
159 printf("Reconfigured L1D SRAM size is %d.\n", lib_get_L1D_SRAM_size());
160 printf("Reconfigured L1D total size is %d.\n", lib_get_L1D_total_size());
161 printf("Reconfigured L2 SRAM size is %d.\n", lib_get_L2_SRAM_size());
163 return(TEST_MEM_NOERR);
164 } /* lib_reconfig_memory */
166 /*==============================================================================
167 * This function prints out the L2 SRAM start address which is passed from host
168 * through OpenCL.
169 *============================================================================*/
170 void print_l2_start(char * l2_buf)
171 {
172 printf("Function print_l2_start: L2 SRAM start address is 0x%x.\n", (unsigned int)l2_buf);
173 }
175 /* Nothing past this point */