829eb052707a99d1550c17ad125c45795b6391fd
1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Bob Cousins
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 /* Include Standard files */
33 #include "system-target.h"
34 #include "uart-s3c2440.h"
36 #define MAX_PRINTF_BUF 1024
38 /****************************************************************************
40 ****************************************************************************/
41 void serial_setup (void)
44 uart_init_device(DEBUG_UART_PORT
);
49 if (uart_tx_ready (DEBUG_UART_PORT
))
55 void tx_writec(unsigned char c
)
57 uart_send_byte (DEBUG_UART_PORT
, c
);
61 static int uart_push(void *user_data
, unsigned char ch
)
65 uart_send_byte(DEBUG_UART_PORT
, ch
);
67 uart_send_byte(DEBUG_UART_PORT
, '\r');
71 /****************************************************************************
72 * General purpose debug function
73 ****************************************************************************/
74 void uart_printf (const char *format
, ...)
76 static bool debug_uart_init
= false;
81 uart_init_device(DEBUG_UART_PORT
);
82 debug_uart_init
= true;
86 vuprintf(uart_push
, NULL
, format
, ap
);
90 /****************************************************************************
91 * Device level functions specific to S3C2440
92 *****************************************************************************/
100 bool uart_init_device (unsigned dev
)
102 /* set GPIOs, clock enable? etc */
108 S3C2440_GPIO_CONFIG (GPHCON
, 2, GPIO_FUNCTION
);
109 S3C2440_GPIO_CONFIG (GPHCON
, 3, GPIO_FUNCTION
);
110 S3C2440_GPIO_PULLUP (GPHUP
, 2, GPIO_PULLUP_DISABLE
);
111 S3C2440_GPIO_PULLUP (GPHUP
, 3, GPIO_PULLUP_DISABLE
);
116 S3C2440_GPIO_CONFIG (GPHCON
, 4, GPIO_FUNCTION
);
117 S3C2440_GPIO_CONFIG (GPHCON
, 5, GPIO_FUNCTION
);
118 S3C2440_GPIO_PULLUP (GPHUP
, 4, GPIO_PULLUP_DISABLE
);
119 S3C2440_GPIO_PULLUP (GPHUP
, 5, GPIO_PULLUP_DISABLE
);
124 S3C2440_GPIO_CONFIG (GPHCON
, 6, GPIO_FUNCTION
);
125 S3C2440_GPIO_CONFIG (GPHCON
, 7, GPIO_FUNCTION
);
126 S3C2440_GPIO_PULLUP (GPHUP
, 6, GPIO_PULLUP_DISABLE
);
127 S3C2440_GPIO_PULLUP (GPHUP
, 7, GPIO_PULLUP_DISABLE
);
134 /* set a default configuration */
135 uart_config (dev
, 115200, 8, UART_NO_PARITY
, UART_1_STOP_BIT
);
139 bool uart_config (unsigned dev
, unsigned speed
, unsigned num_bits
,
140 unsigned parity
, unsigned stop_bits
)
145 ULCON0
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
146 UCON0
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
147 UBRDIV0
= PCLK
/ (speed
*16);
151 ULCON1
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
152 UCON1
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
153 UBRDIV1
= PCLK
/ (speed
*16);
157 ULCON2
= (parity
<< 3) + (stop_bits
<< 2) + (num_bits
-5);
158 UCON2
= (1 << 2) + (1 << 0); /* enable TX, RX, use PCLK */
159 UBRDIV2
= PCLK
/ (speed
*16);
167 bool uart_tx_ready (unsigned dev
)
169 /* test if transmit buffer empty */
194 bool uart_send_byte (unsigned dev
, char ch
)
196 /* wait for transmit buffer empty */
197 while (!uart_tx_ready(dev
))
218 bool uart_rx_ready (unsigned dev
)
220 /* test receive buffer data ready */
245 char uart_read_byte (unsigned dev
)
247 while (!uart_rx_ready(dev
))
265 /****************************************************************************
267 *****************************************************************************/
269 bool uart_send_buf (unsigned dev
, char *buf
, unsigned len
)
274 uart_send_byte (dev
, buf
[index
]);
281 /****************************************************************************/