1 /**
2 * \file main_gpmc_probing_example.c
3 *
4 * \brief Probing test application main file. This application will write the data
5 * to GPMC SRAM memory using CPU multiple times to enable probing
6 *
7 */
9 /*
10 * Copyright (C) 2016 -2020 Texas Instruments Incorporated - http://www.ti.com/
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the
22 * distribution.
23 *
24 * Neither the name of Texas Instruments Incorporated nor the names of
25 * its contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 */
42 #include <stdio.h>
43 #include <string.h>
45 #ifdef USE_BIOS
46 /* XDCtools Header files */
47 #include <xdc/std.h>
48 #include <xdc/cfg/global.h>
49 #include <xdc/runtime/System.h>
50 #include <xdc/runtime/Error.h>
52 #include <ti/sysbios/knl/Task.h>
53 #include <ti/sysbios/BIOS.h>
54 #include <ti/sysbios/utils/Load.h>
55 #endif
57 /* GPMC Header files */
58 #include <ti/drv/gpmc/GPMC.h>
59 #include <ti/drv/gpmc/soc/GPMC_soc.h>
60 #include <ti/drv/gpmc/test/src/GPMC_board.h>
61 #include <ti/drv/gpmc/test/src/GPMC_log.h>
63 /* Board Header files */
64 #include <ti/board/board.h>
65 #include <ti/board/src/flash/include/board_flash.h>
67 #include <ti/drv/sciclient/sciclient.h>
68 #include <ti/osal/TimerP.h>
69 #ifdef GPMC_DMA_ENABLE
70 #include <ti/osal/CacheP.h>
71 #include <ti/drv/udma/udma.h>
72 #endif
74 /**********************************************************************
75 ************************** Macros ************************************
76 **********************************************************************/
77 #define GPMC_PROFILE /* Enable profiling */
80 /**********************************************************************
81 ************************** Global Variables **************************
82 **********************************************************************/
83 uint8_t txBuf[TEST_DATA_LEN] __attribute__((aligned(4))) __attribute__((section(".benchmark_buffer")));
84 GPMC_Transaction transaction;
87 /**********************************************************************
88 ************************** Internal functions ************************
89 **********************************************************************/
90 /*
91 * ======== GeneratePattern ========
92 */
93 static void GeneratePattern(uint8_t *txBuf, uint8_t *rxBuf, uint32_t length)
94 {
95 volatile uint32_t idx;
96 volatile uint8_t *txPtr = txBuf;
97 volatile uint8_t *rxPtr = rxBuf;
99 for(idx = 0; idx < length; idx++)
100 {
101 *txPtr++ = (uint8_t)idx;
102 *rxPtr++ = (uint8_t)0U;
103 }
104 }
106 void GPMC_initConfig()
107 {
108 GPMC_v1_HwAttrs gpmc_cfg;
110 /* Get the default GPMC init configurations */
111 GPMC_socGetInitCfg(BOARD_GPMC_INSTANCE, &gpmc_cfg);
113 /* Modify the default GPMC configurations */
115 /* Set the default GPMC init configurations */
116 GPMC_socSetInitCfg(BOARD_GPMC_INSTANCE, &gpmc_cfg);
117 }
119 uint32_t gpmc_test()
120 {
121 uint32_t testPassed = TRUE;
122 uint32_t i;
123 GPMC_Params params;
124 GPMC_Handle handle;
125 #ifdef GPMC_PROFILE
126 uint32_t testLen = TEST_DATA_LEN;
127 uint64_t startTime; /* start time stamp in usec */
128 uint64_t elapsedTime; /* elapsed time in usec */
129 float xferRate;
130 uint32_t xferRateInt;
131 #endif
133 GPMC_initConfig();
134 GPMC_Params_init(¶ms);
135 handle = GPMC_open(BOARD_GPMC_INSTANCE, ¶ms);
136 if (handle == NULL)
137 {
138 GPMC_log("\n GPMC open failed. \n");
139 testPassed = FALSE;
140 goto Err;
141 }
143 /* Generate the data */
144 GeneratePattern(txBuf, NULL, TEST_DATA_LEN);
146 /* Write data */
147 transaction.transType = GPMC_TRANSACTION_TYPE_WRITE;
148 transaction.offset = 0U;
149 transaction.count = TEST_DATA_LEN;
150 transaction.txBuf = txBuf;
151 transaction.rxBuf = NULL;
152 transaction.arg = NULL;
154 for(i=0 ; i<1000 ; i++)
155 {
156 #ifdef GPMC_PROFILE
157 /* Get start time stamp for the write performance measurement */
158 startTime = TimerP_getTimeInUsecs();
159 #endif
161 if(GPMC_transfer(handle, &transaction))
162 {
163 #ifdef GPMC_PROFILE
164 elapsedTime = TimerP_getTimeInUsecs() - startTime;
165 /* calculate the write transfer rate in MBps */
166 xferRate = (float) (((float)testLen) / elapsedTime);
167 xferRateInt = (uint32_t)xferRate;
168 GPMC_log("\n GPMC write %d bytes at transfer rate %d MBps \n", testLen, xferRateInt);
169 #endif
170 }
171 else
172 {
173 GPMC_log("\n GPMC write failed. \n");
174 break;
175 }
176 }
178 Err:
179 if (handle != NULL)
180 {
181 GPMC_close(handle);
182 }
184 return (testPassed);
185 }
187 #if defined(SOC_AM64X)
188 uint32_t GPMC_configClk(uint32_t freq)
189 {
190 GPMC_v1_HwAttrs gpmc_cfg;
191 int32_t retVal;
192 uint64_t gpmc_clk;
193 uint32_t parClk;
194 uint32_t clkID = TISCI_DEV_GPMC0_FUNC_CLK;
195 uint32_t devID = TISCI_DEV_GPMC0;
197 /* Get the default GPMC init configurations */
198 GPMC_socGetInitCfg(BOARD_GPMC_INSTANCE, &gpmc_cfg);
200 retVal = Sciclient_pmModuleClkRequest(devID,
201 clkID,
202 TISCI_MSG_VALUE_CLOCK_SW_STATE_REQ,
203 TISCI_MSG_FLAG_AOP,
204 SCICLIENT_SERVICE_WAIT_FOREVER);
205 if (retVal != CSL_PASS)
206 {
207 GPMC_log("\n Sciclient_pmModuleClkRequest failed");
208 goto clk_cfg_exit;
209 }
211 /* Set parent clock */
212 parClk = TISCI_DEV_GPMC0_FUNC_CLK_PARENT_HSDIV4_16FFT_MAIN_0_HSDIVOUT3_CLK;
213 retVal = Sciclient_pmSetModuleClkParent(devID,
214 clkID,
215 parClk,
216 SCICLIENT_SERVICE_WAIT_FOREVER);
218 if (retVal != CSL_PASS)
219 {
220 GPMC_log("\n Sciclient_pmSetModuleClkParent failed");
221 goto clk_cfg_exit;
222 }
224 gpmc_clk = (uint64_t)freq;
225 retVal = Sciclient_pmSetModuleClkFreq(devID,
226 clkID,
227 gpmc_clk,
228 TISCI_MSG_FLAG_AOP,
229 SCICLIENT_SERVICE_WAIT_FOREVER);
231 if (retVal != CSL_PASS)
232 {
233 GPMC_log("\n Sciclient_pmSetModuleClkFreq failed");
234 goto clk_cfg_exit;
235 }
237 gpmc_clk = 0;
238 retVal = Sciclient_pmGetModuleClkFreq(devID,
239 clkID,
240 &gpmc_clk,
241 SCICLIENT_SERVICE_WAIT_FOREVER);
242 if (retVal != CSL_PASS)
243 {
244 GPMC_log("\n Sciclient_pmGetModuleClkFreq failed");
245 goto clk_cfg_exit;
246 }
248 GPMC_log("\n GPMC CLK running at %d Hz. \n", freq);
250 clk_cfg_exit:
251 if (retVal == CSL_PASS)
252 {
253 return TRUE;
254 }
255 else
256 {
257 return FALSE;
258 }
259 }
260 #endif
262 uint32_t Board_initGPMC(void)
263 {
264 uint32_t retVal = TRUE;
265 Board_initCfg boardCfg;
266 Board_STATUS boardStatus;
268 boardCfg = BOARD_INIT_MODULE_CLOCK |
269 BOARD_INIT_PINMUX_CONFIG |
270 BOARD_INIT_UART_STDIO;
271 boardStatus = Board_init(boardCfg);
272 if (boardStatus != BOARD_SOK)
273 {
274 retVal = FALSE;
275 }
277 #if defined(SOC_AM64X)
278 if (retVal == TRUE)
279 {
280 retVal = GPMC_configClk(GPMC_MODULE_CLK_80MHZ);
281 }
282 #endif
283 return (retVal);
284 }
286 int main(void)
287 {
288 uint32_t testResult = FALSE;
290 if (Board_initGPMC() == FALSE)
291 {
292 return (0);
293 }
295 GPMC_init();
297 testResult = gpmc_test();
299 if (testResult)
300 {
301 GPMC_log("\n GPMC Write x100 has successfully completed! \n");
302 }
303 else
304 {
305 GPMC_log("\n Test Failed! \n");
306 }
308 while (1)
309 {
310 }
311 }