Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
usbhost_uart.c
00001 /* 00002 ************************************************************************************************************** 00003 * NXP USB Host Stack 00004 * 00005 * (c) Copyright 2008, NXP SemiConductors 00006 * (c) Copyright 2008, OnChip Technologies LLC 00007 * All Rights Reserved 00008 * 00009 * www.nxp.com 00010 * www.onchiptech.com 00011 * 00012 * File : usbhost_uart.c 00013 * Programmer(s) : Prasad.K.R.S.V 00014 * Version : 00015 * 00016 ************************************************************************************************************** 00017 */ 00018 00019 /* 00020 ************************************************************************************************************** 00021 * INCLUDE HEADER FILES 00022 ************************************************************************************************************** 00023 */ 00024 00025 #include "usbhost_uart.h" 00026 00027 /* 00028 ************************************************************************************************************** 00029 * INITIALIZE UART 00030 * 00031 * Description: This function initializes UART port, setup pin select, clock, parity, stopbits, FIFO etc 00032 * 00033 * Arguments : baud_rate UART baud rate (115200) 00034 * 00035 * Returns : None 00036 * 00037 ************************************************************************************************************** 00038 */ 00039 00040 void UART_Init(USB_INT32U baudrate) 00041 { 00042 USB_INT32U Fdiv; 00043 USB_INT32U pclkdiv, pclk; 00044 uint32_t SystemFrequency = SystemCoreClock; 00045 00046 LPC_PINCON->PINSEL0 |= 0x00000050; /* RxD0 and TxD0 */ 00047 00048 LPC_UART0->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ 00049 /* Bit 6~7 is for UART0 clock divider. */ 00050 pclkdiv = (LPC_SC->PCLKSEL0 >> 6) & 0x03; 00051 switch ( pclkdiv ) 00052 { 00053 case 0x00: 00054 default: 00055 pclk = SystemFrequency/4; 00056 break; 00057 case 0x01: 00058 pclk = SystemFrequency; 00059 break; 00060 case 0x02: 00061 pclk = SystemFrequency/2; 00062 break; 00063 case 0x03: 00064 pclk = SystemFrequency/8; 00065 break; 00066 } 00067 Fdiv = ( pclk / 16 ) / baudrate ; /*baud rate */ 00068 00069 LPC_UART0->DLM = Fdiv / 256; 00070 LPC_UART0->DLL = Fdiv % 256; 00071 LPC_UART0->LCR = 0x03; /* DLAB = 0 */ 00072 LPC_UART0->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ 00073 } 00074 00075 /* 00076 ************************************************************************************************************** 00077 * PRINT CHARECTER 00078 * 00079 * Description: This function is used to print a single charecter through UART1. 00080 * 00081 * Arguments : ch charecter to be printed 00082 * 00083 * Returns : None 00084 * 00085 ************************************************************************************************************** 00086 */ 00087 00088 void UART_PrintChar (USB_INT08U ch) 00089 { 00090 00091 while (!(LPC_UART0->LSR & 0x20)); 00092 LPC_UART0->THR = ch; 00093 } 00094 00095 /* 00096 ************************************************************************************************************** 00097 * PRINT STRING 00098 * 00099 * Description: This function is used to print a string 00100 * 00101 * Arguments : str Pointer to the string 00102 * 00103 * Returns : None 00104 * 00105 ************************************************************************************************************** 00106 */ 00107 00108 void UART_PrintStr (const USB_INT08U * str) 00109 { 00110 00111 while ((*str) != 0) { 00112 if (*str == '\n') { 00113 UART_PrintChar(*str++); 00114 UART_PrintChar('\r'); 00115 } else { 00116 UART_PrintChar(*str++); 00117 } 00118 } 00119 } 00120 00121 /* 00122 ************************************************************************************************************** 00123 * PRINT FORMATTED STRING 00124 * 00125 * Description: This function is used to print formatted string. This function takes variable length arguments 00126 * 00127 * Arguments : variable length arguments 00128 * 00129 * Returns : None 00130 * 00131 ************************************************************************************************************** 00132 */ 00133 00134 void UART_Printf (const USB_INT08U *format, ...) 00135 { 00136 static USB_INT08U buffer[40 + 1]; 00137 va_list vArgs; 00138 00139 00140 va_start(vArgs, format); 00141 vsprintf((char *)buffer, (char const *)format, vArgs); 00142 va_end(vArgs); 00143 UART_PrintStr((USB_INT08U*) buffer); 00144 }
Generated on Wed Jul 13 2022 12:29:10 by
1.7.2