[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_2_eng / packages / ti / board / diag / led_industrial / src / led_industrial_test.c
1 /*
2 * Copyright (C) 2015 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 */
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
39 #include <ti/drv/i2c/I2C.h>
40 #include <ti/drv/i2c/soc/I2C_v1.h>
41 #include <ti/drv/uart/UART_stdio.h>
43 #include "board.h"
44 #include "board_cfg.h"
46 extern const I2C_Config I2C_config[];
47 void AppDelay(uint32_t delayVal);
49 void led_write(I2C_Handle h, uint8_t val)
50 {
51 uint8_t tx[2];
52 I2C_Transaction t;
54 tx[0] = 0x44;
55 tx[1] = val;
56 t.slaveAddress = BOARD_I2C_LED_ADDR;
57 t.writeBuf = tx;
58 t.writeCount = 2;
59 t.readCount = 0;
60 I2C_transfer(h, &t);
61 }
64 /*
65 * ======== test function ========
66 */
67 int industrial_led_test()
68 {
69 char p = 'r';
70 int cnt = 0;
71 int ret = 0;
72 int i;
73 I2C_Params i2cParams;
74 I2C_Handle handle = NULL;;
76 for (i=0; I2C_config[i].fxnTablePtr != NULL; i++)
77 {
78 ((I2C_HwAttrs *)I2C_config[i].hwAttrs)->enableIntr = false;
79 }
81 I2C_init();
83 I2C_Params_init(&i2cParams);
85 handle = I2C_open(BOARD_I2C_LED_INSTANCE, &i2cParams);
87 UART_printf("\n*********************************************\n");
88 UART_printf ("* Industrial LEDs Test *\n");
89 UART_printf ("*********************************************\n");
91 UART_printf("\nTesting Industrial LEDs\n");
92 UART_printf("Cycling LEDs 3 times\n");
93 cnt = 0x80;
95 do {
96 UART_printf("Press 'y' to verify pass, 'r' to cycle leds again,\n");
97 UART_printf("or any other character to indicate failure: ");
98 for (i=0; i<24; i++) {
99 if ( (cnt & 0xff) == 0) cnt = 0x80;
100 led_write(handle, cnt);
101 cnt >>= 1;
102 AppDelay(0x1FFFFFF);
103 }
104 UART_scanFmt("%c", &p);
105 if (p == 'r') UART_printf("\nCycling LEDs 3 times again\n");
106 } while (p == 'r');
108 UART_printf("Received: %c\n", p);
109 if ( (p == 'y') || (p == 'Y') ) {
110 UART_printf("\nTest PASSED!\n");
111 ret = 0;
112 }
113 else {
114 UART_printf("\nTest FAILED!\n");
115 ret = -1;
116 }
118 I2C_close(handle);
120 return ret;
121 }
123 /*
124 * ======== main ========
125 */
126 int main(void)
127 {
128 Board_initCfg boardCfg;
129 #ifdef PDK_RAW_BOOT
130 boardCfg = BOARD_INIT_PINMUX_CONFIG |
131 BOARD_INIT_UART_STDIO;
132 #else
133 boardCfg = BOARD_INIT_UART_STDIO;
134 #endif
135 Board_init(boardCfg);
136 return industrial_led_test();
137 }
139 void AppDelay(uint32_t delayVal)
140 {
141 uint32_t cnt = 0;
142 while(cnt < delayVal)
143 {
144 asm("");
145 cnt++;
146 }
147 }