mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-19 18:55:04 +08:00
bsps/sparc: Move polled APBUART functions
This reduces the link-time dependencies and avoids copy-and-paste.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
52
bsps/sparc/shared/uart/apbuart_polled.c
Normal file
52
bsps/sparc/shared/uart/apbuart_polled.c
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user