summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Hellstrom <daniel@gaisler.com>2012-04-19 15:21:21 +0200
committerGedare Bloom <gedare@rtems.org>2012-04-19 12:34:20 -0400
commit07557c86fddef855d911a8d7c879d6ede27ba527 (patch)
treeade089e64ebd8dcce9e6c52c379ba154a905b14a
parentLEON3: console, lower bus utilization waiting for UART TX ready (diff)
downloadrtems-07557c86fddef855d911a8d7c879d6ede27ba527.tar.bz2
LEON3: add console attributes such as parity and baudrate
Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
-rw-r--r--c/src/lib/libbsp/sparc/leon3/console/console.c71
1 files changed, 68 insertions, 3 deletions
diff --git a/c/src/lib/libbsp/sparc/leon3/console/console.c b/c/src/lib/libbsp/sparc/leon3/console/console.c
index fa67d370ea..45ec82eff5 100644
--- a/c/src/lib/libbsp/sparc/leon3/console/console.c
+++ b/c/src/lib/libbsp/sparc/leon3/console/console.c
@@ -13,8 +13,6 @@
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
- *
- * $Id$
*/
#include <bsp.h>
@@ -102,6 +100,73 @@ int console_pollRead(int minor)
return apbuart_inbyte_nonblocking(apbuarts[port].regs);
}
+int console_set_attributes(int minor, const struct termios *t)
+{
+ unsigned int scaler;
+ unsigned int ctrl;
+ int baud;
+ struct apbuart_priv *uart;
+
+ switch (t->c_cflag & CSIZE) {
+ default:
+ case CS5:
+ case CS6:
+ case CS7:
+ /* Hardware doesn't support other than CS8 */
+ return -1;
+ case CS8:
+ break;
+ }
+
+ if (minor == 0)
+ uart = &apbuarts[syscon_uart_index];
+ else
+ uart = &apbuarts[minor - 1];
+
+ /* Read out current value */
+ ctrl = uart->regs->ctrl;
+
+ switch (t->c_cflag & (PARENB|PARODD)) {
+ case (PARENB|PARODD):
+ /* Odd parity */
+ ctrl |= LEON_REG_UART_CTRL_PE|LEON_REG_UART_CTRL_PS;
+ break;
+
+ case PARENB:
+ /* Even parity */
+ ctrl &= ~LEON_REG_UART_CTRL_PS;
+ ctrl |= LEON_REG_UART_CTRL_PE;
+ break;
+
+ default:
+ case 0:
+ case PARODD:
+ /* No Parity */
+ ctrl &= ~(LEON_REG_UART_CTRL_PS|LEON_REG_UART_CTRL_PE);
+ }
+
+ if (!(t->c_cflag & CLOCAL)) {
+ ctrl |= LEON_REG_UART_CTRL_FL;
+ } else {
+ ctrl &= ~LEON_REG_UART_CTRL_FL;
+ }
+
+ /* Update new settings */
+ uart->regs->ctrl = ctrl;
+
+ /* Baud rate */
+ baud = rtems_termios_baud_to_number(t->c_cflag);
+ if (baud > 0) {
+ /* Calculate Baud rate generator "scaler" number */
+ scaler = (((uart->freq_hz * 10) / (baud * 8)) - 5) / 10;
+
+ /* Set new baud rate by setting scaler */
+ uart->regs->scaler = scaler;
+ }
+
+ return 0;
+}
+
/* AMBA PP find routine. Extract AMBA PnP information into data structure. */
int find_matching_apbuart(struct ambapp_dev *dev, int index, void *arg)
{
@@ -208,7 +273,7 @@ rtems_device_driver console_open(
NULL, /* lastClose */
console_pollRead, /* pollRead */
console_write_support, /* write */
- NULL, /* setAttributes */
+ console_set_attributes, /* setAttributes */
NULL, /* stopRemoteTx */
NULL, /* startRemoteTx */
0 /* outputUsesInterrupts */