1 /**
2 * Copyright (C) 2015-2021 Texas Instruments Incorporated - http://www.ti.com/
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
34 /**
35 * \file led_test.c
36 *
37 * \brief Led diagnostic test file.
38 *
39 * Targeted Functionality: Verifies all the General purpose LEDs.
40 *
41 * Operation: This test verifies by toggling all available general
42 * purpose LEDs.
43 *
44 * Supported SoCs: AM335x, AM437x, AM571x, AM572x, K2G, AM65xx, J721E, TPR12, J7200, AM64x, AWR294X, J721S2
45 *
46 * Supported Platforms: bbbAM335x, skAM335x, icev2AM335x, iceAMIC110,
47 * evmAM437x, idkAM437x, skAM437x, evmAM571x, idkAM571x,
48 * evmAM572x, idkAM572x, evmK2G, iceK2G, am65xx_evm,
49 * am65xx_idk, j721e_evm, tpr12_evm, j7200_evm,am64x_evm, awr294x_evm, j721s2_evm
50 */
52 #include "led_test.h"
54 #if (defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_J721S2))
55 i2cIoExpPinNumber_t gUserLeds[BOARD_GPIO_LED_NUM] = { PIN_NUM_6,
56 PIN_NUM_7 };
57 #endif
59 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
60 extern GPIO_v2_Config GPIO_v2_config;
61 #endif
63 /**
64 * \brief This function is used to generate delays.
65 *
66 * \param delayValue [IN] Delay count.
67 *
68 */
69 #if (!(defined(AM65XX) || defined(SOC_J721E) || defined(SOC_TPR12) || defined(SOC_J7200) || defined(SOC_AM64X) || defined(SOC_J721S2)))
70 void BoardDiag_AppDelay(uint32_t delayVal)
71 {
72 uint32_t cnt = 0;
73 while(cnt < delayVal)
74 {
75 asm("");
76 cnt++;
77 }
78 }
79 #endif
82 #if defined(SOC_AM65XX) && defined(AM65XX_BETA_BOARD)
83 /* Function to enable IO expander based LEDs */
84 void led_write(I2C_Handle handle, uint8_t signalLevelData)
85 {
86 uint8_t tx[2];
87 I2C_Transaction i2cTransaction;
89 /* Initializes the I2C transaction structure with default values */
90 I2C_transactionInit(&i2cTransaction);
92 I2C_transactionInit(&i2cTransaction);
93 tx[0] = 0x1;
94 tx[1] = signalLevelData;
95 i2cTransaction.slaveAddress = BOARD_I2C_IOEXP_DEVICE4_ADDR;
96 i2cTransaction.writeBuf = tx;
97 i2cTransaction.writeCount = 2;
98 i2cTransaction.readCount = 0;
99 I2C_transfer(handle, &i2cTransaction);
100 }
102 /* Function to configure the IO expander pin direction */
103 void led_configure(I2C_Handle handle, uint8_t signalLevelData)
104 {
105 uint8_t tx[2];
106 I2C_Transaction i2cTransaction;
108 /* Initializes the I2C transaction structure with default values */
109 I2C_transactionInit(&i2cTransaction);
111 I2C_transactionInit(&i2cTransaction);
112 tx[0] = 0x3;
113 tx[1] = signalLevelData;
114 i2cTransaction.slaveAddress = BOARD_I2C_IOEXP_DEVICE4_ADDR;
115 i2cTransaction.writeBuf = tx;
116 i2cTransaction.writeCount = 2;
117 i2cTransaction.readCount = 0;
118 I2C_transfer(handle, &i2cTransaction);
119 }
120 #endif
122 /**
123 * \brief This is the Application callback function used while
124 * running the LED test in interrupt mode.
125 *
126 */
127 #if defined (iceK2G)
128 void AppGpioCallbackFxn(void)
129 {
130 if(gLedNum != USER_LED0)
131 {
132 GPIO_write(USER_LED0, GPIO_PIN_VAL_LOW);
133 GPIO_write(gLedNum, GPIO_PIN_VAL_HIGH);
134 }
135 }
136 #endif /* iceK2G */
138 /**
139 * \brief This test performs the LED diagnostic test by toggling
140 * all the LEDs that exists.
141 *
142 * \return int8_t
143 * 0 - in case of success
144 * -1 - in case of failure.
145 *
146 */
147 static int8_t led_run_test(void)
148 {
149 #if (defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_AM64X) || defined(SOC_J721S2))
150 Board_I2cInitCfg_t i2cCfg;
151 #endif
152 char p = 'y';
153 int i, j;
154 #if !(defined(tpr12_evm) || defined(awr294x_evm))
155 int k;
156 #endif
158 #if defined (iceK2G) /* Test is executed with GPIO interrupts enabled on iceK2G */
159 /* Setup GPIO interrupt configurations */
160 GPIO_socSetIntMux(GPIO_LED0_PORT_NUM, GPIO_LED0_PIN_NUM, NULL, GPIO_MUX_SEL);
162 /* GPIO initialization */
163 GPIO_init();
165 /* Set the callback function */
166 GPIO_setCallback(USER_LED0, AppGpioCallbackFxn);
168 /* Enable GPIO interrupt on the specific gpio pin */
169 GPIO_enableInt(USER_LED0);
170 #else
171 #if defined(SOC_AM65XX)
172 GPIO_v0_HwAttrs gpioCfg;
173 GPIO_socGetInitCfg(0, &gpioCfg);
174 gpioCfg.baseAddr = CSL_WKUP_GPIO0_BASE;
175 GPIO_socSetInitCfg(0, &gpioCfg);
176 GPIO_init();
177 #elif (defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_J721S2))
178 i2cCfg.i2cInst = BOARD_I2C_IOEXP_DEVICE2_INSTANCE;
179 i2cCfg.socDomain = BOARD_SOC_DOMAIN_MAIN;
180 i2cCfg.enableIntr = false;
181 Board_setI2cInitConfig(&i2cCfg);
183 Board_i2cIoExpInit();
184 #elif defined(SOC_AM64X)
185 i2cCfg.i2cInst = BOARD_I2C_IOEXP_DEVICE1_INSTANCE;
186 i2cCfg.socDomain = BOARD_SOC_DOMAIN_MAIN;
187 Board_setI2cInitConfig(&i2cCfg);
189 Board_i2cIoExpInit();
191 GPIO_v0_HwAttrs gpioCfg;
192 GPIO_socGetInitCfg(0, &gpioCfg);
193 gpioCfg.baseAddr = CSL_MCU_GPIO0_BASE;
194 GPIO_socSetInitCfg(0, &gpioCfg);
195 GPIO_init();
196 #else
197 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
198 GPIO_v2_updateConfig(&GPIO_v2_config);
199 #endif
200 GPIO_init();
201 #endif
203 #if defined(SOC_AM65XX) && defined(AM65XX_BETA_BOARD)
204 I2C_Params i2cParams;
205 I2C_Handle handle = NULL;
206 I2C_HwAttrs i2cCfg;
207 I2C_socGetInitCfg(0, &i2cCfg);
208 i2cCfg.baseAddr = CSL_WKUP_I2C0_CFG_BASE;
209 i2cCfg.enableIntr = 0;
210 I2C_socSetInitCfg(0, &i2cCfg);
212 I2C_init();
213 I2C_Params_init(&i2cParams);
214 handle = I2C_open(0, &i2cParams);
215 led_configure(handle, 0x9F);
217 #endif
218 #ifdef iceAMIC110
219 GPIO_write(BOARD_GPIO_LED_NUM, GPIO_PIN_VAL_HIGH);
220 #endif
221 #endif /* #if defined (iceK2G) */
223 UART_printf("\n*********************************************\n");
224 UART_printf ("* LED Test *\n");
225 UART_printf ("*********************************************\n");
227 UART_printf("\nTesting LED\n");
228 UART_printf("Blinking LEDs...\n");
230 for (i=0; i<BOARD_GPIO_LED_NUM; i++) {
231 #if (defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_J721S2))
232 Board_i2cIoExpSetPinDirection(BOARD_I2C_IOEXP_DEVICE2_ADDR,
233 THREE_PORT_IOEXP,
234 PORTNUM_2,
235 gUserLeds[i],
236 PIN_DIRECTION_OUTPUT);
238 Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE2_ADDR,
239 THREE_PORT_IOEXP,
240 PORTNUM_2,
241 gUserLeds[i],
242 GPIO_SIGNAL_LEVEL_HIGH);
243 #elif defined(SOC_AM64X)
244 Board_i2cIoExpSetPinDirection(BOARD_I2C_IOEXP_DEVICE1_ADDR,
245 THREE_PORT_IOEXP,
246 PORTNUM_2,
247 PIN_NUM_0,
248 PIN_DIRECTION_OUTPUT);
250 Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE1_ADDR,
251 THREE_PORT_IOEXP,
252 PORTNUM_2,
253 PIN_NUM_0,
254 GPIO_SIGNAL_LEVEL_LOW);
256 GPIO_write(i, GPIO_PIN_VAL_LOW);
257 #else
259 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
260 GPIO_write(GPIO_v2_config.pinConfigs[i].pinIndex, GPIO_PIN_VAL_LOW);
261 #else
262 GPIO_write(i, GPIO_PIN_VAL_LOW);
263 #endif
265 #endif
266 }
268 do {
269 #if !defined (DIAG_STRESS_TEST) && !defined(DIAG_COMPLIANCE_TEST)
270 UART_printf("Press 'y' to verify pass, 'r' to blink again,\n");
271 UART_printf("or any other character to indicate failure: ");
272 #endif
274 #if (defined(tpr12_evm) || defined(awr294x_evm))
275 for (i=0; i<NUMBER_OF_CYCLES; i++) {
276 for (j=0; j<BOARD_GPIO_LED_NUM; j++) {
277 GPIO_write(GPIO_v2_config.pinConfigs[j].pinIndex, GPIO_PIN_VAL_HIGH);
278 BOARD_delay(250000);
279 GPIO_write(GPIO_v2_config.pinConfigs[j].pinIndex, GPIO_PIN_VAL_LOW);
280 BOARD_delay(250000);
281 }
282 }
283 #else
284 for (i=0; i<NUMBER_OF_CYCLES; i++) {
285 for (j=0; j<BOARD_GPIO_LED_NUM; j++) {
286 for (k=0; k<BOARD_GPIO_LED_NUM; k++) {
287 if (j==k) {
288 #if defined (iceK2G)
289 gLedNum = k;
290 GPIO_toggle(USER_LED0);
291 #elif (defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_J721S2))
292 Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE2_ADDR,
293 THREE_PORT_IOEXP,
294 PORTNUM_2,
295 gUserLeds[k],
296 GPIO_SIGNAL_LEVEL_LOW);
297 #elif defined(SOC_AM64X)
298 if(k == 0)
299 {
300 GPIO_write(k, GPIO_PIN_VAL_HIGH);
301 }
302 else
303 {
304 Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE1_ADDR,
305 THREE_PORT_IOEXP,
306 PORTNUM_2,
307 PIN_NUM_0,
308 GPIO_SIGNAL_LEVEL_HIGH);
309 }
310 #else
311 GPIO_write(k, GPIO_PIN_VAL_HIGH);
313 #endif
314 }
315 else {
316 #if (defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_J721S2))
317 Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE2_ADDR,
318 THREE_PORT_IOEXP,
319 PORTNUM_2,
320 gUserLeds[k],
321 GPIO_SIGNAL_LEVEL_HIGH);
322 #elif defined(SOC_AM64X)
323 if(k == 0)
324 {
325 GPIO_write(k, GPIO_PIN_VAL_LOW);
326 }
327 else
328 {
329 Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE1_ADDR,
330 THREE_PORT_IOEXP,
331 PORTNUM_2,
332 PIN_NUM_0,
333 GPIO_SIGNAL_LEVEL_LOW);
334 }
335 #else
336 GPIO_write(k, GPIO_PIN_VAL_LOW);
337 #endif
338 }
339 }
340 #if (!(defined(SOC_AM65XX) || defined(SOC_J721E) || defined(SOC_TPR12) || defined(SOC_J7200) || defined(SOC_AM64X) || defined(SOC_AWR294X) || defined(SOC_J721S2)))
341 BoardDiag_AppDelay(5000000);
342 #else
343 BOARD_delay(250000);
344 #endif
345 }
346 #if defined(SOC_AM65XX) && defined(AM65XX_BETA_BOARD)
347 led_write(handle, 0x9F);
348 BOARD_delay(250000);
349 led_write(handle, 0xFF);
350 #endif
351 }
352 #endif
354 #if !defined (DIAG_STRESS_TEST) && !defined(DIAG_COMPLIANCE_TEST)
355 UART_scanFmt("%c", &p);
356 #endif
357 if (p == 'r') UART_printf("\nBlinking again\n");
358 } while (p == 'r');
360 for (i=0; i<BOARD_GPIO_LED_NUM; i++) {
361 #if (defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_J721S2))
362 /* Turn OFF the user LEDs */
363 Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE2_ADDR,
364 THREE_PORT_IOEXP,
365 PORTNUM_2,
366 gUserLeds[i],
367 GPIO_SIGNAL_LEVEL_HIGH);
368 #elif defined(SOC_AM64X)
369 /* Turn OFF the user LEDs */
370 Board_i2cIoExpPinLevelSet(BOARD_I2C_IOEXP_DEVICE1_ADDR,
371 THREE_PORT_IOEXP,
372 PORTNUM_2,
373 PIN_NUM_0,
374 GPIO_SIGNAL_LEVEL_LOW);
376 GPIO_write(i, GPIO_PIN_VAL_LOW);
377 #else
378 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
379 GPIO_write(GPIO_v2_config.pinConfigs[i].pinIndex, GPIO_PIN_VAL_LOW);
380 #else
381 GPIO_write(i, GPIO_PIN_VAL_LOW);
382 #endif
383 #endif
384 }
386 UART_printf("Received: %c\n", p);
388 #if defined(SOC_AM65XX) && defined(AM65XX_BETA_BOARD)
389 I2C_close(handle);
390 #elif (defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_AM64X) || defined(SOC_J721S2))
391 Board_i2cIoExpDeInit();
392 #endif
394 if ( (p == 'y') || (p == 'Y') ) {
395 UART_printf("\nTest PASSED!\n");
396 return 0;
397 }
398 else {
399 UART_printf("\nTest FAILED!\n");
400 return -1;
401 }
402 }
404 int8_t BoardDiag_gpioLedFunctionalTest(void)
405 {
406 int8_t ret = 0;
408 ret = led_run_test();
410 return ret;
411 }
413 #ifdef DIAG_STRESS_TEST
414 /**
415 * \brief The function performs the LED test.
416 *
417 * \return int8_t
418 * 0 - in case of success
419 * -1 - in case of failure.
420 *
421 */
422 int8_t BoardDiag_gpioLedStressTest(void)
423 {
424 int8_t ret = 0;
425 char rdBuf = 'y';
426 uint32_t iteration;
427 uint32_t passCount = 0;
428 uint32_t failCount = 0;
430 UART_printf("\n\nRunning LED Test in Stress Mode for %d Number of Times...\n", DIAG_STRESS_TEST_ITERATIONS);
431 UART_printf("Enter 'b' in Serial Console to Terminate the Test\n\n");
433 for(iteration = 1; iteration <= DIAG_STRESS_TEST_ITERATIONS; iteration++)
434 {
435 ret = BoardDiag_gpioLedFunctionalTest();
436 if (ret == 0)
437 {
438 UART_printf("\n\n\n\nIteration : %d LED Test Passed\n",iteration);
439 passCount++;
440 }
441 else
442 {
443 UART_printf("\n\n\n\n LED Test Failed at iteration - %d\n",iteration);
444 failCount++;
445 }
447 /* Check if there a input from console to break the test */
448 rdBuf = (char)BoardDiag_getUserInput(BOARD_UART_INSTANCE);
449 if((rdBuf == 'b') || (rdBuf == 'B'))
450 {
451 UART_printf("Received Test Termination... Exiting the Test\n");
452 iteration++;
453 break;
454 }
455 }
457 UART_printf("\n\nLED Stress Test Status\n");
458 UART_printf("===================================\n");
459 UART_printf("Number of Times Executed - %d\n", (iteration - 1));
460 UART_printf("Pass Count - %d\n", passCount);
461 UART_printf("Fail Count - %d\n", failCount);
463 if((iteration != 0) && (failCount == 0))
464 {
465 UART_printf("Overall Status - PASS\n\n\n" );
466 }
467 else
468 {
469 UART_printf("Overall Status - FAIL\n\n\n" );
470 ret = -1;
471 }
473 return ret;
474 }
475 #endif
477 /**
478 * \brief LED diagnostic test main function
479 *
480 * \return int - LED Diagnostic test status.
481 * 0 - in case of success
482 * -1 - in case of failure.
483 *
484 */
485 #ifndef SPI_BOOT_FRAMEWORK
486 int main(void)
487 {
488 int8_t ret = 0;
489 Board_initCfg boardCfg;
491 #if defined (iceK2G)
492 CSL_A15_INIT_copyVectorTable();
493 #endif
495 #ifdef PDK_RAW_BOOT
496 boardCfg = BOARD_INIT_MODULE_CLOCK |
497 BOARD_INIT_PINMUX_CONFIG |
498 BOARD_INIT_UART_STDIO;
499 #else
500 boardCfg = BOARD_INIT_UART_STDIO;
501 #endif /* #ifdef PDK_RAW_BOOT */
502 Board_init(boardCfg);
504 #ifdef DIAG_STRESS_TEST
505 ret = BoardDiag_gpioLedStressTest();
506 #else
507 ret = BoardDiag_gpioLedFunctionalTest();
508 #endif
509 if(ret == 0)
510 {
511 UART_printf("\nLED Test Passed\n");
512 }
513 else
514 {
515 UART_printf("\nLED Test Failed\n");
516 }
518 return ret;
519 }
521 #endif /* #ifndef SPI_BOOT_FRAMEWORK */