[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_1_eng / packages / ti / board / diag / uart2usb / src / uart2usb_diag.c
1 /*
2 * Copyright (c) 2016, Texas Instruments Incorporated
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
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the 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 "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 #include <ti/drv/uart/UART_stdio.h>
34 #include <stdlib.h>
35 #include <stdint.h>
36 #include <tistdtypes.h>
38 #include "board.h"
39 #include "board_cfg.h"
41 #include <ti/drv/gpio/GPIO.h>
42 #include <ti/csl/soc.h>
43 #include <ti/drv/gpio/soc/GPIO_soc.h>
45 /* Port and pin number mask for config.
46 Bits 7-0: Pin number and Bits 15-8: Port number */
47 #define GPIO_SERIAL_CFG (0x0136)
49 /* GPIO Driver board specific pin configuration structure */
50 GPIO_PinConfig gpioPinConfigs[] = {
51 GPIO_SERIAL_CFG | GPIO_CFG_OUTPUT
52 };
54 /* GPIO Driver call back functions */
55 GPIO_CallbackFxn gpioCallbackFunctions[] = {
56 NULL
57 };
59 /* GPIO Driver configuration structure */
60 GPIO_v0_Config GPIO_v0_config = {
61 gpioPinConfigs,
62 gpioCallbackFunctions,
63 sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
64 sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
65 0,
66 };
68 extern void BOARD_delay(uint32_t usecs);
70 int uart_test()
71 {
72 char p = 'r';
74 pinMuxSetMode(125, 3);
75 GPIO_init();
77 UART_printf("\n*************************************************\n");
78 UART_printf ("* UART2USB Test *\n");
79 UART_printf ("*************************************************\n");
81 UART_printf("\nCheck the messages on UART2USB console\n");
82 BOARD_delay(250000);
83 GPIO_write(0, 1);
84 BOARD_delay(250000);
85 UART_printf("\nTesting UART print to console at 115.2k baud rate\n");
86 UART_printf("Press 'y' to verify pass: ");
88 UART_scanFmt("%c", &p);
90 GPIO_write(0, 0);
91 BOARD_delay(250000);
92 UART_printf("\nReceived: %c\n", p);
93 if ( (p == 'y') || (p == 'Y') ) {
94 UART_printf("\nTest PASSED!\n");
95 return 0;
96 }
97 else {
98 UART_printf("\nTest FAILED!\n");
99 return -1;
100 }
101 }
103 int main(void)
104 {
105 Board_initCfg boardCfg;
106 #ifdef PDK_RAW_BOOT
107 boardCfg = BOARD_INIT_PINMUX_CONFIG |
108 BOARD_INIT_UART_STDIO;
109 #else
110 boardCfg = BOARD_INIT_UART_STDIO;
111 #endif
112 Board_init(boardCfg);
113 return uart_test();
114 }