#include #include #include #include #include /******************************************************************************/ /* Global Variables */ /******************************************************************************/ /* Default UART settings */ UartBaud baud = UART_BAUD_9600; UartWordLen wordLength = UART_WORD8; UartStopBits stopBits = UART_STOP1; UartParity parity = UART_EVEN_PARITY; UartFifoControl fifoControl = UART_FIFO_DISABLE; UartLoop loopEnable = UART_NO_LOOPBACK; /******************************************************************************/ /* Function Prototypes */ /******************************************************************************/ /* This delay routine does not conflict with DSP/BIOS. It is used in this */ /* example rather than brd_delay_msec which causes DSP/BIOS conflicts just */ /* because of this. If you are not using DSP/BIOS, you can change the code */ /* to use brd_delay_msec. */ void delay(s16); s16 initDemo(void); s16 startDemo(void); s16 changeSettings(void); /*****************************************************************************/ /* main /*****************************************************************************/ void main(void) { brd_init(100); if (initDemo() == ERROR) { printf("Error initializing UART for Demo\n"); } for (;;) { startDemo(); } return; } /*****************************************************************************/ /* uart init routine /*****************************************************************************/ s16 initDemo(void) { s16 status = OK; if(uart_init() == ERROR) { status = ERROR; } return status; } /*****************************************************************************/ /* main uart demo routine /*****************************************************************************/ s16 startDemo(void) { s16 changed, status = OK; int userInput; uart_fputs("\n\n\rTEXAS INSTRUMENTS TMS320VC5402 DSK UART DEMO....\n\r"); uart_fputs("\n\rThe current communication settings are:- \n\r"); switch (baud) { case UART_BAUD_115200: uart_fputs("\n\r\tBaud:\t\t115200"); break; case UART_BAUD_38400: uart_fputs("\n\r\tBaud:\t\t38400"); break; case UART_BAUD_9600: uart_fputs("\n\r\tBaud:\t\t9600"); break; case UART_BAUD_4800: uart_fputs("\n\r\tBaud:\t\t4800"); break; case UART_BAUD_2400: uart_fputs("\n\r\tBaud:\t\t2400"); break; case UART_BAUD_300: uart_fputs("\n\r\tBaud:\t\t300"); break; default: break; } switch (wordLength) { case UART_WORD5: uart_fputs("\n\r\tWord Length:\t5"); break; case UART_WORD6: uart_fputs("\n\r\tWord Length:\t6"); break; case UART_WORD7: uart_fputs("\n\r\tWord Length:\t7"); break; case UART_WORD8: uart_fputs("\n\r\tWord Length:\t8"); break; default: break; } switch (stopBits) { case UART_STOP1: uart_fputs("\n\r\tStop Bits:\t1"); break; case UART_STOP1_PLUS_HALF: uart_fputs("\n\r\tStop Bits:\t1.5"); break; case UART_STOP2: uart_fputs("\n\r\tStop Bits:\t2"); break; default: break; } switch (parity) { case UART_DISABLE_PARITY: uart_fputs("\n\r\tParity:\t\tNONE"); break; case UART_ODD_PARITY: uart_fputs("\n\r\tParity:\t\tODD"); break; case UART_EVEN_PARITY: uart_fputs("\n\r\tParity:\t\tEVEN"); break; default: break; } uart_fputs("\n\n\rDo you want to keep these settings? (Y/N):\n\r"); /* Poll Line Status Register (LSR) for data ready */ while((userInput = uart_fgetc()) == EOF); /* Clear upper byte */ userInput &= 0x00ff; switch (userInput) { case 'y': case 'Y': return status; break; case 'n': case 'N': status = changeSettings(); break; default: break; } changed = ERROR; while (changed != OK) { /* Poll Line Status Register (LSR) for data ready */ while((userInput = uart_fgetc()) == EOF); /* Clear upper byte */ userInput &= 0x00ff; switch (userInput) { case 'd': case 'D': changed = OK; break; default: break; } } return status; } /*****************************************************************************/ /* function to prompt user for inputs and change current uart settings /*****************************************************************************/ s16 changeSettings(void) { s16 status = OK; int userInput; /* Baud Rate */ uart_fputs("\n\n\rPlease enter your choice of Baud Rate:\n\r"); uart_fputs("\n\r1. 115200"); uart_fputs("\n\r2. 38400"); uart_fputs("\n\r3. 9600"); uart_fputs("\n\r4. 4800"); uart_fputs("\n\r5. 2400"); uart_fputs("\n\r6. 300\n\r"); /* Poll Line Status Register (LSR) for data ready */ while((userInput = uart_fgetc()) == EOF); /* Clear upper byte */ userInput &= 0x00ff; switch (userInput) { case '1': baud = UART_BAUD_115200; break; case '2': baud = UART_BAUD_38400; break; case '3': baud = UART_BAUD_9600; break; case '4': baud = UART_BAUD_4800; break; case '5': baud = UART_BAUD_2400; break; case '6': baud = UART_BAUD_300; break; default: break; } /* Word Length */ uart_fputs("\n\n\rPlease enter your choice of data word length:\n\r"); uart_fputs("\n\r1. 5"); uart_fputs("\n\r2. 6"); uart_fputs("\n\r3. 7"); uart_fputs("\n\r4. 8\n\r"); /* Poll Line Status Register (LSR) for data ready */ while((userInput = uart_fgetc()) == EOF); /* Clear upper byte */ userInput &= 0x00ff; switch (userInput) { case '1': wordLength = UART_WORD5; break; case '2': wordLength = UART_WORD6; break; case '3': wordLength = UART_WORD7; break; case '4': wordLength = UART_WORD8; break; default: break; } /* Stop Bits */ uart_fputs("\n\n\rPlease enter your choice of number of stop bits:\n\r"); uart_fputs("\n\r1. 1"); uart_fputs("\n\r2. 1.5"); uart_fputs("\n\r3. 2\n\r"); /* Poll Line Status Register (LSR) for data ready */ while((userInput = uart_fgetc()) == EOF); /* Clear upper byte */ userInput &= 0x00ff; switch (userInput) { case '1': stopBits = UART_STOP1; break; case '2': stopBits = UART_STOP1_PLUS_HALF; break; case '3': stopBits = UART_STOP2; break; default: break; } /* Parity */ uart_fputs("\n\n\rPlease enter your choice of Parity:\n\r"); uart_fputs("\n\r1. NONE"); uart_fputs("\n\r2. ODD"); uart_fputs("\n\r3. EVEN\n\r"); /* Poll Line Status Register (LSR) for data ready */ while((userInput = uart_fgetc()) == EOF); /* Clear upper byte */ userInput &= 0x00ff; switch (userInput) { case '1': parity = UART_DISABLE_PARITY; break; case '2': parity = UART_ODD_PARITY; break; case '3': parity = UART_EVEN_PARITY; break; default: break; } uart_fputs("\n\n\rThe DSK communication settings will now be changed. Change the communication settings on your host application and press 'D' when you are done ....\n\r"); /* 1000ms delay to guarantee that the above string is completely written out before settings are changed */ /* brd_delay_msec(1000); */ delay(1000); if(uart_setup(baud, wordLength, stopBits, parity, fifoControl, loopEnable) == ERROR) { status = ERROR; } return status; } void delay(s16 period) { int i, j; for(i=0; i>1; j++); } }