diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-08-09 09:20:33 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-08-10 07:14:43 +0200 |
commit | f4424cfb499f56e46a83c3ba9b018d091b2f6088 (patch) | |
tree | 0e3e98cfcaf706b2a35ef0baf0448e0b868d766d | |
parent | posix: Add configure check for mprotect() (diff) | |
download | rtems-f4424cfb499f56e46a83c3ba9b018d091b2f6088.tar.bz2 |
bsps/sparc: Move polled APBUART functions
This reduces the link-time dependencies and avoids copy-and-paste.
-rw-r--r-- | bsps/sparc/include/bsp/apbuart.h | 10 | ||||
-rw-r--r-- | bsps/sparc/include/bsp/apbuart_termios.h | 19 | ||||
-rw-r--r-- | bsps/sparc/leon3/console/printk_support.c | 1 | ||||
-rw-r--r-- | bsps/sparc/shared/uart/apbuart_cons.c | 52 | ||||
-rw-r--r-- | bsps/sparc/shared/uart/apbuart_polled.c | 52 | ||||
-rw-r--r-- | bsps/sparc/shared/uart/apbuart_termios.c | 52 | ||||
-rw-r--r-- | c/src/lib/libbsp/sparc/leon3/Makefile.am | 5 |
7 files changed, 64 insertions, 127 deletions
diff --git a/bsps/sparc/include/bsp/apbuart.h b/bsps/sparc/include/bsp/apbuart.h index a324805d7d..870e5408d8 100644 --- a/bsps/sparc/include/bsp/apbuart.h +++ b/bsps/sparc/include/bsp/apbuart.h @@ -20,6 +20,7 @@ #define __APBUART_H__ #include <ambapp.h> +#include <grlib.h> #ifdef __cplusplus extern "C" { @@ -53,6 +54,15 @@ extern "C" { #define APBUART_STATUS_TF 0x200 #define APBUART_STATUS_RF 0x400 +void apbuart_outbyte_polled( + struct apbuart_regs *regs, + unsigned char ch, + int do_cr_on_newline, + int wait_sent +); + +int apbuart_inbyte_nonblocking(struct apbuart_regs *regs); + #ifdef __cplusplus } #endif diff --git a/bsps/sparc/include/bsp/apbuart_termios.h b/bsps/sparc/include/bsp/apbuart_termios.h index 40377c1023..58338ddb92 100644 --- a/bsps/sparc/include/bsp/apbuart_termios.h +++ b/bsps/sparc/include/bsp/apbuart_termios.h @@ -34,25 +34,6 @@ const rtems_termios_device_handler apbuart_handler_interrupt; const rtems_termios_device_handler apbuart_handler_polled; -/* - * apbuart_outbyte_polled - * - * This routine transmits a character using polling. - */ -void apbuart_outbyte_polled( - struct apbuart_regs *regs, - unsigned char ch, - int do_cr_on_newline, - int wait_sent -); - -/* - * apbuart_inbyte_nonblocking - * - * This routine polls for a character. - */ -int apbuart_inbyte_nonblocking(struct apbuart_regs *regs); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bsps/sparc/leon3/console/printk_support.c b/bsps/sparc/leon3/console/printk_support.c index f7e1fb683f..aa9441a87d 100644 --- a/bsps/sparc/leon3/console/printk_support.c +++ b/bsps/sparc/leon3/console/printk_support.c @@ -23,7 +23,6 @@ #include <assert.h> #include <stdio.h> #include <bsp/apbuart.h> -#include <bsp/apbuart_termios.h> int leon3_debug_uart_index __attribute__((weak)) = 0; struct apbuart_regs *leon3_debug_uart = NULL; diff --git a/bsps/sparc/shared/uart/apbuart_cons.c b/bsps/sparc/shared/uart/apbuart_cons.c index e406bc01b7..ac8a4369b2 100644 --- a/bsps/sparc/shared/uart/apbuart_cons.c +++ b/bsps/sparc/shared/uart/apbuart_cons.c @@ -42,12 +42,6 @@ #endif /* LEON3 Low level transmit/receive functions provided by debug-uart code */ -extern void apbuart_outbyte_polled( - struct apbuart_regs *regs, - unsigned char ch, - int do_cr_on_newline, - int wait_sent); -extern int apbuart_inbyte_nonblocking(struct apbuart_regs *regs); #ifdef LEON3 extern struct apbuart_regs *leon3_debug_uart; /* The debug UART */ #endif @@ -385,52 +379,6 @@ static int apbuart_info( } #endif -#ifndef LEON3 -/* This routine transmits a character, it will busy-wait until on character - * fits in the APBUART Transmit FIFO - */ -void apbuart_outbyte_polled( - struct apbuart_regs *regs, - unsigned char ch, - int do_cr_on_newline, - int wait_sent) -{ -send: - while ((regs->status & LEON_REG_UART_STATUS_THE) == 0) { - /* Lower bus utilization while waiting for UART */ - asm volatile ("nop"::); asm volatile ("nop"::); - asm volatile ("nop"::); asm volatile ("nop"::); - asm volatile ("nop"::); asm volatile ("nop"::); - asm volatile ("nop"::); asm volatile ("nop"::); - } - regs->data = (unsigned int) ch; - - if ((ch == '\n') && do_cr_on_newline) { - ch = '\r'; - goto send; - } - - /* Wait until the character has been sent? */ - if (wait_sent) { - while ((regs->status & LEON_REG_UART_STATUS_THE) == 0) - ; - } -} - -/* This routine polls for one character, return EOF if no character is available */ -int apbuart_inbyte_nonblocking(struct apbuart_regs *regs) -{ - if (regs->status & LEON_REG_UART_STATUS_ERR) { - regs->status = ~LEON_REG_UART_STATUS_ERR; - } - - if ((regs->status & LEON_REG_UART_STATUS_DR) == 0) - return EOF; - - return (int)regs->data; -} -#endif - static bool first_open( rtems_termios_tty *tty, rtems_termios_device_context *base, diff --git a/bsps/sparc/shared/uart/apbuart_polled.c b/bsps/sparc/shared/uart/apbuart_polled.c new file mode 100644 index 0000000000..4a4402712a --- /dev/null +++ b/bsps/sparc/shared/uart/apbuart_polled.c @@ -0,0 +1,52 @@ +/* + * COPYRIGHT (c) 2010. + * Cobham Gaisler AB. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp/apbuart.h> + +void apbuart_outbyte_polled( + struct apbuart_regs *regs, + unsigned char ch, + int do_cr_on_newline, + int wait_sent +) +{ +send: + 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"::); + __asm__ volatile ("nop"::); __asm__ volatile ("nop"::); + __asm__ volatile ("nop"::); __asm__ volatile ("nop"::); + } + + if ((ch == '\n') && do_cr_on_newline) { + regs->data = (unsigned int) '\r'; + do_cr_on_newline = 0; + goto send; + } + regs->data = (unsigned int) ch; + + /* Wait until the character has been sent? */ + if (wait_sent) { + while ((regs->status & APBUART_STATUS_TE) == 0) + ; + } +} + +int apbuart_inbyte_nonblocking(struct apbuart_regs *regs) +{ + /* Clear errors */ + if (regs->status & APBUART_STATUS_ERR) + regs->status = ~APBUART_STATUS_ERR; + + if ((regs->status & APBUART_STATUS_DR) == 0) + return -1; + else + return (int) regs->data; +} diff --git a/bsps/sparc/shared/uart/apbuart_termios.c b/bsps/sparc/shared/uart/apbuart_termios.c index 28ece27d9d..a4ecc749ce 100644 --- a/bsps/sparc/shared/uart/apbuart_termios.c +++ b/bsps/sparc/shared/uart/apbuart_termios.c @@ -242,58 +242,6 @@ static void apbuart_last_close_interrupt( rtems_interrupt_handler_remove(uart->irq, apbuart_isr, tty); } -/* - * apbuart_outbyte_polled - * - * This routine transmits a character using polling. - */ -void apbuart_outbyte_polled( - struct apbuart_regs *regs, - unsigned char ch, - int do_cr_on_newline, - int wait_sent -) -{ -send: - 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"::); - __asm__ volatile ("nop"::); __asm__ volatile ("nop"::); - __asm__ volatile ("nop"::); __asm__ volatile ("nop"::); - } - - if ((ch == '\n') && do_cr_on_newline) { - regs->data = (unsigned int) '\r'; - do_cr_on_newline = 0; - goto send; - } - regs->data = (unsigned int) ch; - - /* Wait until the character has been sent? */ - if (wait_sent) { - while ((regs->status & APBUART_STATUS_TE) == 0) - ; - } -} - -/* - * apbuart_inbyte_nonblocking - * - * This routine polls for a character. - */ -int apbuart_inbyte_nonblocking(struct apbuart_regs *regs) -{ - /* Clear errors */ - if (regs->status & APBUART_STATUS_ERR) - regs->status = ~APBUART_STATUS_ERR; - - if ((regs->status & APBUART_STATUS_DR) == 0) - return -1; - else - return (int) regs->data; -} - const rtems_termios_device_handler apbuart_handler_interrupt = { .first_open = apbuart_first_open_interrupt, .last_close = apbuart_last_close_interrupt, diff --git a/c/src/lib/libbsp/sparc/leon3/Makefile.am b/c/src/lib/libbsp/sparc/leon3/Makefile.am index 6ab5c8a8a3..9d7d59d69d 100644 --- a/c/src/lib/libbsp/sparc/leon3/Makefile.am +++ b/c/src/lib/libbsp/sparc/leon3/Makefile.am @@ -68,6 +68,8 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termio librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/leon3/console/console.c librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/cons.c librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/apbuart_cons.c +librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/apbuart_polled.c +librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/apbuart_termios.c # debugio librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/leon3/console/printk_support.c @@ -117,9 +119,6 @@ endif librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/spw/grspw_pkt.c librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/spw/grspw_router.c -# UART -librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/apbuart_termios.c - # I2CMST librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/i2c/i2cmst.c |