From 516a60a6f8d5cdaabf4329872b8d6cef52a67542 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 30 Jun 2014 13:34:09 +0200 Subject: bsps/sparc: Reduce copy and paste --- c/src/lib/libbsp/sparc/leon3/console/console.c | 31 ++++++++++---------- .../libbsp/sparc/leon3/console/printk_support.c | 13 +++++---- c/src/lib/libbsp/sparc/leon3/include/leon.h | 33 ---------------------- c/src/lib/libbsp/sparc/shared/include/apbuart.h | 1 + c/src/lib/libbsp/sparc/shared/uart/apbuart.c | 8 +++--- 5 files changed, 28 insertions(+), 58 deletions(-) (limited to 'c') diff --git a/c/src/lib/libbsp/sparc/leon3/console/console.c b/c/src/lib/libbsp/sparc/leon3/console/console.c index 8742436622..989d1cf516 100644 --- a/c/src/lib/libbsp/sparc/leon3/console/console.c +++ b/c/src/lib/libbsp/sparc/leon3/console/console.c @@ -34,6 +34,7 @@ #include #include #include +#include int syscon_uart_index __attribute__((weak)) = 0; @@ -74,7 +75,7 @@ static void leon3_console_isr(void *arg) char data; /* Get all received characters */ - while ((status=uart->regs->status) & LEON_REG_UART_STATUS_DR) { + while ((status=uart->regs->status) & APBUART_STATUS_DR) { /* Data has arrived, get new data */ data = uart->regs->data; @@ -83,8 +84,8 @@ static void leon3_console_isr(void *arg) } if ( - (status & LEON_REG_UART_STATUS_THE) - && (uart->regs->ctrl & LEON_REG_UART_CTRL_TI) != 0 + (status & APBUART_STATUS_TE) + && (uart->regs->ctrl & APBUART_CTRL_TI) != 0 ) { /* write_interrupt will get called from this function */ rtems_termios_dequeue_characters(uart->cookie, 1); @@ -102,7 +103,7 @@ static int leon3_console_write_support(int minor, const char *buf, size_t len) if (len > 0) { /* Enable TX interrupt (interrupt is edge-triggered) */ - uart->regs->ctrl |= LEON_REG_UART_CTRL_TI; + uart->regs->ctrl |= APBUART_CTRL_TI; /* start UART TX, this will result in an interrupt when done */ uart->regs->data = *buf; @@ -110,7 +111,7 @@ static int leon3_console_write_support(int minor, const char *buf, size_t len) sending = 1; } else { /* No more to send, disable TX interrupts */ - uart->regs->ctrl &= ~LEON_REG_UART_CTRL_TI; + uart->regs->ctrl &= ~APBUART_CTRL_TI; /* Tell close that we sent everything */ sending = 0; @@ -180,26 +181,26 @@ static int leon3_console_set_attributes(int minor, const struct termios *t) switch (t->c_cflag & (PARENB|PARODD)) { case (PARENB|PARODD): /* Odd parity */ - ctrl |= LEON_REG_UART_CTRL_PE|LEON_REG_UART_CTRL_PS; + ctrl |= APBUART_CTRL_PE|APBUART_CTRL_PS; break; case PARENB: /* Even parity */ - ctrl &= ~LEON_REG_UART_CTRL_PS; - ctrl |= LEON_REG_UART_CTRL_PE; + ctrl &= ~APBUART_CTRL_PS; + ctrl |= APBUART_CTRL_PE; break; default: case 0: case PARODD: /* No Parity */ - ctrl &= ~(LEON_REG_UART_CTRL_PS|LEON_REG_UART_CTRL_PE); + ctrl &= ~(APBUART_CTRL_PS|APBUART_CTRL_PE); } if (!(t->c_cflag & CLOCAL)) { - ctrl |= LEON_REG_UART_CTRL_FL; + ctrl |= APBUART_CTRL_FL; } else { - ctrl &= ~LEON_REG_UART_CTRL_FL; + ctrl &= ~APBUART_CTRL_FL; } /* Update new settings */ @@ -339,11 +340,11 @@ static int leon3_console_first_open(int major, int minor, void *arg) uart->sending = 0; /* Enable Receiver and transmitter and Turn on RX interrupts */ - uart->regs->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE | - LEON_REG_UART_CTRL_RI; + uart->regs->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE | + APBUART_CTRL_RI; #else /* Initialize UART on opening */ - uart->regs->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE; + uart->regs->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE; #endif uart->regs->status = 0; @@ -359,7 +360,7 @@ static int leon3_console_last_close(int major, int minor, void *arg) /* Turn off RX interrupts */ rtems_termios_interrupt_lock_acquire(tty, &lock_ctx); - uart->regs->ctrl &= ~(LEON_REG_UART_CTRL_RI); + uart->regs->ctrl &= ~(APBUART_CTRL_RI); rtems_termios_interrupt_lock_release(tty, &lock_ctx); /**** Flush device ****/ diff --git a/c/src/lib/libbsp/sparc/leon3/console/printk_support.c b/c/src/lib/libbsp/sparc/leon3/console/printk_support.c index 35fb4b52e5..d12099b1a6 100644 --- a/c/src/lib/libbsp/sparc/leon3/console/printk_support.c +++ b/c/src/lib/libbsp/sparc/leon3/console/printk_support.c @@ -21,6 +21,7 @@ #include #include #include +#include int debug_uart_index __attribute__((weak)) = 0; static struct apbuart_regs *dbg_uart = NULL; @@ -69,7 +70,7 @@ void bsp_debug_uart_init(void) */ apb = (struct ambapp_apb_info *)adev->devinfo; dbg_uart = (struct apbuart_regs *)apb->start; - dbg_uart->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE; + dbg_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE; dbg_uart->status = 0; } } @@ -87,7 +88,7 @@ void apbuart_outbyte_polled( ) { send: - while ( (regs->status & LEON_REG_UART_STATUS_THE) == 0 ) { + while ( (regs->status & APBUART_STATUS_TE) == 0 ) { /* Lower bus utilization while waiting for UART */ __asm__ volatile ("nop"::); __asm__ volatile ("nop"::); __asm__ volatile ("nop"::); __asm__ volatile ("nop"::); @@ -103,7 +104,7 @@ send: /* Wait until the character has been sent? */ if (wait_sent) { - while ((regs->status & LEON_REG_UART_STATUS_THE) == 0) + while ((regs->status & APBUART_STATUS_TE) == 0) ; } } @@ -116,10 +117,10 @@ send: int apbuart_inbyte_nonblocking(struct apbuart_regs *regs) { /* Clear errors */ - if (regs->status & LEON_REG_UART_STATUS_ERR) - regs->status = ~LEON_REG_UART_STATUS_ERR; + if (regs->status & APBUART_STATUS_ERR) + regs->status = ~APBUART_STATUS_ERR; - if ((regs->status & LEON_REG_UART_STATUS_DR) == 0) + if ((regs->status & APBUART_STATUS_DR) == 0) return EOF; else return (int) regs->data; diff --git a/c/src/lib/libbsp/sparc/leon3/include/leon.h b/c/src/lib/libbsp/sparc/leon3/include/leon.h index ccf2fb7067..d7048f3c23 100644 --- a/c/src/lib/libbsp/sparc/leon3/include/leon.h +++ b/c/src/lib/libbsp/sparc/leon3/include/leon.h @@ -86,39 +86,6 @@ extern "C" { #define LEON_REG_TIMER_CONTROL_LD 0x00000004 /* 1 = load counter */ /* 0 = no function */ -/* - * The following defines the bits in the UART Control Registers. - * - */ - -#define LEON_REG_UART_CONTROL_RTD 0x000000FF /* RX/TX data */ - -/* - * The following defines the bits in the LEON UART Status Registers. - */ - -#define LEON_REG_UART_STATUS_DR 0x00000001 /* Data Ready */ -#define LEON_REG_UART_STATUS_TSE 0x00000002 /* TX Send Register Empty */ -#define LEON_REG_UART_STATUS_THE 0x00000004 /* TX Hold Register Empty */ -#define LEON_REG_UART_STATUS_BR 0x00000008 /* Break Error */ -#define LEON_REG_UART_STATUS_OE 0x00000010 /* RX Overrun Error */ -#define LEON_REG_UART_STATUS_PE 0x00000020 /* RX Parity Error */ -#define LEON_REG_UART_STATUS_FE 0x00000040 /* RX Framing Error */ -#define LEON_REG_UART_STATUS_ERR 0x00000078 /* Error Mask */ - -/* - * The following defines the bits in the LEON UART Status Registers. - */ - -#define LEON_REG_UART_CTRL_RE 0x00000001 /* Receiver enable */ -#define LEON_REG_UART_CTRL_TE 0x00000002 /* Transmitter enable */ -#define LEON_REG_UART_CTRL_RI 0x00000004 /* Receiver interrupt enable */ -#define LEON_REG_UART_CTRL_TI 0x00000008 /* Transmitter interrupt enable */ -#define LEON_REG_UART_CTRL_PS 0x00000010 /* Parity select */ -#define LEON_REG_UART_CTRL_PE 0x00000020 /* Parity enable */ -#define LEON_REG_UART_CTRL_FL 0x00000040 /* Flow control enable */ -#define LEON_REG_UART_CTRL_LB 0x00000080 /* Loop Back enable */ - /* LEON3 Interrupt Controller */ extern volatile struct irqmp_regs *LEON3_IrqCtrl_Regs; /* LEON3 GP Timer */ diff --git a/c/src/lib/libbsp/sparc/shared/include/apbuart.h b/c/src/lib/libbsp/sparc/shared/include/apbuart.h index 139d1ec4ce..2f34a11083 100644 --- a/c/src/lib/libbsp/sparc/shared/include/apbuart.h +++ b/c/src/lib/libbsp/sparc/shared/include/apbuart.h @@ -71,6 +71,7 @@ typedef struct { #define APBUART_STATUS_OV 0x10 #define APBUART_STATUS_PE 0x20 #define APBUART_STATUS_FE 0x40 +#define APBUART_STATUS_ERR 0x78 #define APBUART_STATUS_TH 0x80 #define APBUART_STATUS_RH 0x100 #define APBUART_STATUS_TF 0x200 diff --git a/c/src/lib/libbsp/sparc/shared/uart/apbuart.c b/c/src/lib/libbsp/sparc/shared/uart/apbuart.c index e64784faec..f7e9a7f58e 100644 --- a/c/src/lib/libbsp/sparc/shared/uart/apbuart.c +++ b/c/src/lib/libbsp/sparc/shared/uart/apbuart.c @@ -158,7 +158,7 @@ static void apbuart_hw_open(apbuart_priv *uart); #if 0 static int apbuart_outbyte_try(struct apbuart_regs *regs, unsigned char ch) { - if ( (READ_REG(®s->status) & LEON_REG_UART_STATUS_THE) == 0 ) + if ( (READ_REG(®s->status) & APBUART_STATUS_TE) == 0 ) return -1; /* Failed */ /* There is room in fifo, put ch in it */ @@ -171,12 +171,12 @@ static int apbuart_inbyte_try(struct apbuart_regs *regs) { unsigned int status; /* Clear errors if any */ - if ( (status=READ_REG(®s->status)) & LEON_REG_UART_STATUS_ERR) { - regs->status = status & ~LEON_REG_UART_STATUS_ERR; + if ( (status=READ_REG(®s->status)) & APBUART_STATUS_ERR) { + regs->status = status & ~APBUART_STATUS_ERR; } /* Is Data available? */ - if ( (READ_REG(®s->status) & LEON_REG_UART_STATUS_DR) == 0 ) + if ( (READ_REG(®s->status) & APBUART_STATUS_DR) == 0 ) return -1; /* No data avail */ /* Return Data */ -- cgit v1.2.3