summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/xilinx-zynq/console/zynq-uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/arm/xilinx-zynq/console/zynq-uart.c')
-rw-r--r--c/src/lib/libbsp/arm/xilinx-zynq/console/zynq-uart.c94
1 files changed, 41 insertions, 53 deletions
diff --git a/c/src/lib/libbsp/arm/xilinx-zynq/console/zynq-uart.c b/c/src/lib/libbsp/arm/xilinx-zynq/console/zynq-uart.c
index f9a1cf91d5..05c8e5424e 100644
--- a/c/src/lib/libbsp/arm/xilinx-zynq/console/zynq-uart.c
+++ b/c/src/lib/libbsp/arm/xilinx-zynq/console/zynq-uart.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2013, 2017 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
@@ -17,16 +17,6 @@
#include <bspopts.h>
-#include <libchip/sersupp.h>
-
-static volatile zynq_uart *zynq_uart_get_regs(int minor)
-{
- const console_tbl *ct = Console_Port_Tbl != NULL ?
- Console_Port_Tbl[minor] : &Console_Configuration_Ports[minor];
-
- return (volatile zynq_uart *) ct->ulCtrlPort1;
-}
-
/*
* Make weak and let the user override.
*/
@@ -112,13 +102,14 @@ static int zynq_cal_baud_rate(uint32_t baudrate,
return 0;
}
-static void zynq_uart_initialize(int minor)
+void zynq_uart_initialize(rtems_termios_device_context *base)
{
- volatile zynq_uart *regs = zynq_uart_get_regs(minor);
+ zynq_uart_context *ctx = (zynq_uart_context *) base;
+ volatile zynq_uart *regs = ctx->regs;
uint32_t brgr = 0x3e;
uint32_t bauddiv = 0x6;
- zynq_cal_baud_rate(115200, &brgr, &bauddiv, regs->mode);
+ zynq_cal_baud_rate(ZYNQ_UART_DEFAULT_BAUD, &brgr, &bauddiv, regs->mode);
regs->control &= ~(ZYNQ_UART_CONTROL_RXEN | ZYNQ_UART_CONTROL_TXEN);
regs->control = ZYNQ_UART_CONTROL_RXDIS
@@ -137,27 +128,23 @@ static void zynq_uart_initialize(int minor)
| ZYNQ_UART_CONTROL_RSTTO;
}
-static int zynq_uart_first_open(int major, int minor, void *arg)
+static bool zynq_uart_first_open(
+ rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
+ struct termios *term,
+ rtems_libio_open_close_args_t *args
+)
{
- rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *) arg;
- struct rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1;
- console_data *cd = &Console_Port_Data[minor];
- const console_tbl *ct = Console_Port_Tbl[minor];
-
- cd->termios_data = tty;
- rtems_termios_set_initial_baud(tty, (rtems_termios_baud_t) ct->pDeviceParams);
-
- return 0;
-}
+ rtems_termios_set_initial_baud(tty, ZYNQ_UART_DEFAULT_BAUD);
+ zynq_uart_initialize(base);
-static int zynq_uart_last_close(int major, int minor, void *arg)
-{
- return 0;
+ return true;
}
-static int zynq_uart_read_polled(int minor)
+int zynq_uart_read_polled(rtems_termios_device_context *base)
{
- volatile zynq_uart *regs = zynq_uart_get_regs(minor);
+ zynq_uart_context *ctx = (zynq_uart_context *) base;
+ volatile zynq_uart *regs = ctx->regs;
if ((regs->channel_sts & ZYNQ_UART_CHANNEL_STS_REMPTY) != 0) {
return -1;
@@ -166,9 +153,13 @@ static int zynq_uart_read_polled(int minor)
}
}
-static void zynq_uart_write_polled(int minor, char c)
+void zynq_uart_write_polled(
+ rtems_termios_device_context *base,
+ char c
+)
{
- volatile zynq_uart *regs = zynq_uart_get_regs(minor);
+ zynq_uart_context *ctx = (zynq_uart_context *) base;
+ volatile zynq_uart *regs = ctx->regs;
while ((regs->channel_sts & ZYNQ_UART_CHANNEL_STS_TFUL) != 0) {
/* Wait */
@@ -177,8 +168,8 @@ static void zynq_uart_write_polled(int minor, char c)
regs->tx_rx_fifo = ZYNQ_UART_TX_RX_FIFO_FIFO(c);
}
-static ssize_t zynq_uart_write_support_polled(
- int minor,
+static void zynq_uart_write_support_polled(
+ rtems_termios_device_context *base,
const char *s,
size_t n
)
@@ -186,13 +177,14 @@ static ssize_t zynq_uart_write_support_polled(
ssize_t i = 0;
for (i = 0; i < n; ++i) {
- zynq_uart_write_polled(minor, s[i]);
+ zynq_uart_write_polled(base, s[i]);
}
-
- return n;
}
-static int zynq_uart_set_attribues(int minor, const struct termios *term)
+static bool zynq_uart_set_attributes(
+ rtems_termios_device_context *context,
+ const struct termios *term
+)
{
#if 0
volatile zynq_uart *regs = zynq_uart_get_regs(minor);
@@ -209,31 +201,27 @@ static int zynq_uart_set_attribues(int minor, const struct termios *term)
regs->baud_rate_div = ZYNQ_UART_BAUD_RATE_DIV_BDIV(bauddiv);
regs->control |= ZYNQ_UART_CONTROL_RXEN | ZYNQ_UART_CONTROL_TXEN;
- return 0;
+ return true;
#else
- return -1;
+ return false;
#endif
}
-const console_fns zynq_uart_fns = {
- .deviceProbe = libchip_serial_default_probe,
- .deviceFirstOpen = zynq_uart_first_open,
- .deviceLastClose = zynq_uart_last_close,
- .deviceRead = zynq_uart_read_polled,
- .deviceWrite = zynq_uart_write_support_polled,
- .deviceInitialize = zynq_uart_initialize,
- .deviceWritePolled = zynq_uart_write_polled,
- .deviceSetAttributes = zynq_uart_set_attribues,
- .deviceOutputUsesInterrupts = false
+const rtems_termios_device_handler zynq_uart_handler = {
+ .first_open = zynq_uart_first_open,
+ .write = zynq_uart_write_support_polled,
+ .poll_read = zynq_uart_read_polled,
+ .set_attributes = zynq_uart_set_attributes,
+ .mode = TERMIOS_POLLED
};
-void zynq_uart_reset_tx_flush(int minor)
+void zynq_uart_reset_tx_flush(zynq_uart_context *ctx)
{
- volatile zynq_uart *regs = zynq_uart_get_regs(minor);
+ volatile zynq_uart *regs = ctx->regs;
int c = 4;
while (c-- > 0)
- zynq_uart_write_polled(minor, '\r');
+ zynq_uart_write_polled(&ctx->base, '\r');
while ((regs->channel_sts & ZYNQ_UART_CHANNEL_STS_TEMPTY) == 0) {
/* Wait */