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 /bsps/sparc/shared/uart/apbuart_polled.c | |
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.
Diffstat (limited to '')
-rw-r--r-- | bsps/sparc/shared/uart/apbuart_polled.c | 52 |
1 files changed, 52 insertions, 0 deletions
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; +} |