]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/ibl.git/blob - src/hw/uart/c66x_uart/evmc66x_uart.c
Merge branch 'boot-rel-exp'
[keystone-rtos/ibl.git] / src / hw / uart / c66x_uart / evmc66x_uart.c
1 /******************************************************************************
2  * Copyright (c) 2011 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 #include "evmc66x_uart.h"
36 static void uart_delay_cycles(uint32_t cycles)
37 {
38     while (cycles--) {
39         asm ("NOP");
40     }
41 }
43 /******************************************************************************
44  *
45  * Function:    uart_init
46  *
47  * Description: This function initializes UART peripheral for C66x
48  *
49  * Parameters: str    - string to print
50  *             length - length of the string to print
51  *
52  * Return Value: none
53  ******************************************************************************/
54 void uart_init(void)
55 {
56     uint8_t DLL_val = 0;
57     uint8_t DLH_val = 0;
59     /* Setting baud rate to 115200 */
60     DLL_val = (uint8_t )(0x00FF & BAUD_RATE_115200);
61     DLH_val = (uint8_t )(0x00FF & (BAUD_RATE_115200  >> 8));
63     /* Allows access to the divisor latches of the baud generator during a
64        read or write operation (DLL and DLH) */
66     uart_registers->LCR = 0x80;
68     /* Set the baudrate,for accessing LCR[7] should be enable */
69     uart_registers->DLL  = DLL_val;
70     uart_registers->DLH  = DLH_val;
72     /* Allows access to the receiver buffer register (RBR),
73        the transmitter holding register (THR), and the
74        interrupt enable register (IER) selected. */
75     uart_registers->LCR = 0x18;
77     /* Disable THR, RHR, Receiver line status interrupts */
78     uart_registers->IER = 0;
80     /* If autoflow control is desired,
81      * write appropriate values to the modem
82      * control register (MCR). Note that all UARTs
83      * do not support autoflow control, see
84      * the device-specific data manual for supported features.
85      *
86      * MCR
87      * ====================================================
88      * Bit  Field   Value   Description
89      * 5    AFE     0       Autoflow control is disabled
90      * 4    LOOP    0       Loop back mode is disabled.
91      * 1    RTS     0       RTS control (UARTn_RTS is disabled,
92      *                      UARTn_CTS is only enabled.)
93      * =====================================================
94      *
95      *
96      */
98     uart_registers->MCR = 0;
100     /* Choose the desired response to
101      * emulation suspend events by configuring
102      * the FREE bit and enable the UART by setting
103      * the UTRST and URRST bits in the power and
104      * emulation management register (PWREMU_MGMT).
105      *
106      *
107      * PWREMU_MGMT
108      * =================================================
109      * Bit  Field   Value   Description
110      * 14   UTRST   1       Transmitter is enabled
111      * 13   URRST   1       Receiver is enabled
112      * 0    FREE    1       Free-running mode is enabled
113      * ===================================================
114      *
115      */
116     uart_registers->PWREMU_MGMT = 0x6001;
118     /* Cleanup previous data (rx trigger is also set to 0)*/
119     uart_registers->FCR = 0xC1;
121     /* Setting the baud rate */
122     uart_registers->LCR = 0x80;
124     /* Set the baudrate,for accessing LCR[7] should be enable */
125     uart_registers->DLL  = DLL_val;
126     uart_registers->DLH  = DLH_val;
127     uart_registers->LCR  = 0x03;
129     return;
132 /******************************************************************************
133  *
134  * Function:    uart_write_byte
135  *
136  * Description: This function writes a byte of data to UART device
137  *
138  * Parameters:  byte    -  8-bit data to write to THR
139  *
140  * Return Value: none
141  ******************************************************************************/
142 static inline void uart_write_byte(uint8_t byte)
144     while (!(uart_registers->LSR & UART_LSR_THRE_MASK)) {
145         uart_delay_cycles(10000);
146     }
147     uart_registers->THR = (UART_THR_DATA_MASK & byte);
148     return;
151 /******************************************************************************
152  *
153  * Function:    uart_write_string
154  *
155  * Description: This function writes a string of data to UART device
156  *
157  * Parameters: str    - string to print
158  *             length - length of the string to print, maximum is 80
159  *
160  * Return Value: none
161  ******************************************************************************/
162 void uart_write_string(char * str, uint32_t length)
164     uint32_t i;
165     if (length==0)
166     {
167         /*Maximum length is 80 */
168         length=80;
169     }
170     for(i = 0; i < length; i++) {
171         if(str[i]=='\0') break;
172         uart_write_byte((uint8_t)str[i]);
173     }
174     uart_write_byte((uint8_t)0x0D);
175     uart_write_byte((uint8_t)0x0A);