summaryrefslogtreecommitdiffstats
path: root/c/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-10-07 16:28:04 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-10-07 16:35:13 +0200
commit7fd5e89c96cc92254e36012eee733748d255ff29 (patch)
treee17930368a0dbdd460e99808795beaa1f815497f /c/src
parenttermios: Separate flow control from normal handler (diff)
downloadrtems-7fd5e89c96cc92254e36012eee733748d255ff29.tar.bz2
termios: Partially hide rtems_termios_tty
Move interrupt lock to device context and expose only this structure to the read, write and set attributes device handler. This makes these device handler independent of the general Termios infrastructure suitable for direct use in printk() support.
Diffstat (limited to 'c/src')
-rw-r--r--c/src/lib/libbsp/arm/tms570/console/tms570-sci.c74
-rw-r--r--c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h1
-rw-r--r--c/src/lib/libbsp/sparc/leon3/console/console.c10
-rw-r--r--c/src/lib/libbsp/sparc/shared/include/apbuart_termios.h1
-rw-r--r--c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c45
5 files changed, 76 insertions, 55 deletions
diff --git a/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
index 961754ece6..3f103004b8 100644
--- a/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
+++ b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
@@ -26,7 +26,6 @@
#include <bspopts.h>
#include <termios.h>
#include <rtems/termiostypes.h>
-#include <libchip/sersupp.h>
#include <bsp/tms570-sci.h>
#include <bsp/tms570-sci-driver.h>
#include <rtems/console.h>
@@ -43,11 +42,13 @@
*/
const tms570_sci_context driver_context_table[] = {
{
+ .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("TMS570 SCI1"),
.device_name = "/dev/console",
.regs = &TMS570_SCI,
.irq = TMS570_IRQ_SCI_LEVEL_0,
},
{
+ .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("TMS570 SCI2"),
.device_name = "/dev/ttyS1",
.regs = &TMS570_SCI2,
.irq = TMS570_IRQ_SCI2_LEVEL_0,
@@ -104,7 +105,7 @@ rtems_device_driver console_initialize(
minor,
handler,
NULL,
- (void *) ctx
+ RTEMS_DECONST(rtems_termios_device_context *, &ctx->base)
);
if ( sc != RTEMS_SUCCESSFUL ) {
bsp_fatal(BSP_FATAL_CONSOLE_NO_DEV);
@@ -196,21 +197,21 @@ static int tms570_sci_transmitted_chars(tms570_sci_context * ctx)
*
* Sets attributes of the HW peripheral (parity, baud rate, etc.)
*
- * @param[in] tty rtems_termios_tty
+ * @param[in] base context of the driver
* @param[in] t termios driver
* @retval true peripheral setting is changed
*/
static bool tms570_sci_set_attributes(
- rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
const struct termios *t
)
{
- tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
+ tms570_sci_context *ctx = (tms570_sci_context *) base;
rtems_interrupt_lock_context lock_context;
int32_t bauddiv;
int32_t baudrate;
- rtems_termios_interrupt_lock_acquire(tty, &lock_context);
+ rtems_termios_device_lock_acquire(base, &lock_context);
ctx->regs->SCIGCR1 &= ~( (1<<7) | (1<<25) | (1<<24) );
@@ -245,7 +246,7 @@ static bool tms570_sci_set_attributes(
ctx->regs->SCIGCR1 |= (1<<7) | (1<<25) | (1<<24);
- rtems_termios_interrupt_lock_release(tty, &lock_context);
+ rtems_termios_device_lock_release(base, &lock_context);
return true;
}
@@ -300,18 +301,18 @@ static void tms570_sci_interrupt_handler(void * arg)
* TMS570 does not have write data buffer asociated with SCI
* so only one character can be written.
*
- * @param[in] tty rtems_termios_tty
+ * @param[in] base context of the driver
* @param[in] buf buffer of characters pending to send
* @param[in] len size of the buffer
* @retval Void
*/
static void tms570_sci_interrupt_write(
- rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
const char *buf,
size_t len
)
{
- tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
+ tms570_sci_context *ctx = (tms570_sci_context *) base;
if ( len > 0 ) {
/* start UART TX, this will result in an interrupt when done */
@@ -334,18 +335,18 @@ static void tms570_sci_interrupt_write(
* Blocking write function. Waits until HW peripheral is ready and then writes
* character to HW peripheral. Writes all characters in the buffer.
*
- * @param[in] tty rtems_termios_tty
+ * @param[in] base context of the driver
* @param[in] buf buffer of characters pending to send
* @param[in] len size of the buffer
* @retval Void
*/
static void tms570_sci_poll_write(
- rtems_termios_tty *tty,
- const char *buf,
- size_t n
+ rtems_termios_device_context *base,
+ const char *buf,
+ size_t n
)
{
- tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
+ tms570_sci_context *ctx = (tms570_sci_context *) base;
size_t i;
/* Write */
@@ -394,13 +395,13 @@ static char TMS570_sci_read_char(
*
* check if there is recieved character to be read and reads it.
*
- * @param[in] tty rtems_termios_tty (context of the driver)
+ * @param[in] base context of the driver
* @retval -1 No character to be read
* @retval x Read character
*/
-static int tms570_sci_poll_read(rtems_termios_tty *tty)
+static int tms570_sci_poll_read(rtems_termios_device_context *base)
{
- tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
+ tms570_sci_context *ctx = (tms570_sci_context *) base;
/* Check if a character is available */
if ( TMS570_sci_can_read_char(ctx) ) {
@@ -416,20 +417,24 @@ static int tms570_sci_poll_read(rtems_termios_tty *tty)
* initialization of the HW peripheral specified in contex of the driver.
* This function is called only once when opening the driver.
*
- * @param[in] tty context of the driver
+ * @param[in] tty Termios control
+ * @param[in] ctx context of the driver
+ * @param[in] term Termios attributes
* @param[in] args
* @retval false Error occured during initialization
* @retval true Driver is open and ready
*/
static bool tms570_sci_poll_first_open(
rtems_termios_tty *tty,
+ rtems_termios_device_context *ctx,
+ struct termios *term,
rtems_libio_open_close_args_t *args
)
{
bool ok;
- rtems_termios_set_best_baud(tty, TMS570_SCI_BAUD_RATE);
- ok = tms570_sci_set_attributes(tty, rtems_termios_get_termios(tty));
+ rtems_termios_set_best_baud(term, TMS570_SCI_BAUD_RATE);
+ ok = tms570_sci_set_attributes(ctx, term);
if ( !ok ) {
return false;
}
@@ -442,21 +447,24 @@ static bool tms570_sci_poll_first_open(
* calls tms570_sci_poll_first_open function.
* install and enables interrupts.
*
- * @param[in] tty context of the driver
+ * @param[in] tty Termios control
+ * @param[in] base context of the driver
* @param[in] args
* @retval false Error occured during initialization
* @retval true Driver is open and ready
*/
static bool tms570_sci_interrupt_first_open(
rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
+ struct termios *term,
rtems_libio_open_close_args_t *args
)
{
- tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
+ tms570_sci_context *ctx = (tms570_sci_context *) base;
rtems_status_code sc;
bool ret;
- ret = tms570_sci_poll_first_open(tty,args);
+ ret = tms570_sci_poll_first_open(tty, base, term, args);
if ( ret == false ) {
return false;
}
@@ -471,20 +479,22 @@ static bool tms570_sci_interrupt_first_open(
if ( sc != RTEMS_SUCCESSFUL ) {
return false;
}
- tms570_sci_enable_interrupts(rtems_termios_get_device_context(tty));
+ tms570_sci_enable_interrupts(ctx);
return true;
}
/**
* @brief closes sci peripheral
*
- * @param[in] tty context of the driver
+ * @param[in] tty Termios control
+ * @param[in] base context of the driver
* @param[in] args
* @retval false Error occured during initialization
* @retval true Driver is open and ready
*/
static void tms570_sci_poll_last_close(
rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
rtems_libio_open_close_args_t *args
)
{
@@ -496,23 +506,25 @@ static void tms570_sci_poll_last_close(
*
* calls tms570_sci_poll_last_close and disables interrupts
*
- * @param[in] tty context of the driver
+ * @param[in] tty Termios control
+ * @param[in] base context of the driver
* @param[in] args
* @retval false Error occured during initialization
* @retval true Driver is open and ready
*/
static void tms570_sci_interrupt_last_close(
rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
rtems_libio_open_close_args_t *args
)
{
- tms570_sci_context *ctx = rtems_termios_get_device_context(tty);
+ tms570_sci_context *ctx = (tms570_sci_context *) base;
rtems_interrupt_lock_context lock_context;
/* Turn off RX interrupts */
- rtems_termios_interrupt_lock_acquire(tty, &lock_context);
+ rtems_termios_device_lock_acquire(base, &lock_context);
tms570_sci_disable_interrupts(ctx);
- rtems_termios_interrupt_lock_release(tty, &lock_context);
+ rtems_termios_device_lock_release(base, &lock_context);
/* Flush device */
while ( ( ctx->regs->SCIFLR & (1<<11) ) > 0 ) {
@@ -522,7 +534,7 @@ static void tms570_sci_interrupt_last_close(
/* uninstall ISR */
rtems_interrupt_handler_remove(ctx->irq, tms570_sci_interrupt_handler, tty);
- tms570_sci_poll_last_close(tty,args);
+ tms570_sci_poll_last_close(tty, base, args);
}
/**
diff --git a/c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h b/c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h
index 5f38908499..f32eaea875 100644
--- a/c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h
+++ b/c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h
@@ -36,6 +36,7 @@ extern "C" {
/* Low-level driver specific data structure */
typedef struct {
+ rtems_termios_device_context base;
const char *device_name;
volatile tms570_sci_t *regs;
int tx_chars_in_hw;
diff --git a/c/src/lib/libbsp/sparc/leon3/console/console.c b/c/src/lib/libbsp/sparc/leon3/console/console.c
index 513d45d256..35767ce786 100644
--- a/c/src/lib/libbsp/sparc/leon3/console/console.c
+++ b/c/src/lib/libbsp/sparc/leon3/console/console.c
@@ -36,7 +36,7 @@ int syscon_uart_index __attribute__((weak)) = 0;
static struct apbuart_context apbuarts[BSP_NUMBER_OF_TERMIOS_PORTS];
static int uarts = 0;
-static struct apbuart_context *leon3_console_get_uart(int minor)
+static rtems_termios_device_context *leon3_console_get_context(int minor)
{
struct apbuart_context *uart;
@@ -45,7 +45,9 @@ static struct apbuart_context *leon3_console_get_uart(int minor)
else
uart = &apbuarts[minor - 1];
- return uart;
+ rtems_termios_device_context_initialize(&uart->base, "APBUART");
+
+ return &uart->base;
}
/* AMBA PP find routine. Extract AMBA PnP information into data structure. */
@@ -132,7 +134,7 @@ rtems_device_driver console_initialize(
minor,
handler,
NULL,
- leon3_console_get_uart(syscon_uart_index)
+ leon3_console_get_context(syscon_uart_index)
);
if (status != RTEMS_SUCCESSFUL)
bsp_fatal(LEON3_FATAL_CONSOLE_REGISTER_DEV);
@@ -149,7 +151,7 @@ rtems_device_driver console_initialize(
minor,
handler,
NULL,
- leon3_console_get_uart(syscon_uart_index)
+ leon3_console_get_context(syscon_uart_index)
);
}
diff --git a/c/src/lib/libbsp/sparc/shared/include/apbuart_termios.h b/c/src/lib/libbsp/sparc/shared/include/apbuart_termios.h
index ba5f049e09..40377c1023 100644
--- a/c/src/lib/libbsp/sparc/shared/include/apbuart_termios.h
+++ b/c/src/lib/libbsp/sparc/shared/include/apbuart_termios.h
@@ -22,6 +22,7 @@ extern "C" {
#endif /* __cplusplus */
struct apbuart_context {
+ rtems_termios_device_context base;
struct apbuart_regs *regs;
unsigned int freq_hz;
rtems_vector_number irq;
diff --git a/c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c b/c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c
index dd3ca5db3d..05bd608711 100644
--- a/c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c
+++ b/c/src/lib/libbsp/sparc/shared/uart/apbuart_termios.c
@@ -41,12 +41,12 @@ static void apbuart_isr(void *arg)
}
static void apbuart_write_support(
- rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
const char *buf,
size_t len
)
{
- struct apbuart_context *uart = rtems_termios_get_device_context(tty);
+ struct apbuart_context *uart = (struct apbuart_context *) base;
int sending;
if (len > 0) {
@@ -69,12 +69,12 @@ static void apbuart_write_support(
}
static void apbuart_write_polled(
- rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
const char *buf,
size_t len
)
{
- struct apbuart_context *uart = rtems_termios_get_device_context(tty);
+ struct apbuart_context *uart = (struct apbuart_context *) base;
size_t nwrite = 0;
while (nwrite < len) {
@@ -83,19 +83,19 @@ static void apbuart_write_polled(
}
}
-static int apbuart_poll_read(rtems_termios_tty *tty)
+static int apbuart_poll_read(rtems_termios_device_context *base)
{
- struct apbuart_context *uart = rtems_termios_get_device_context(tty);
+ struct apbuart_context *uart = (struct apbuart_context *) base;
return apbuart_inbyte_nonblocking(uart->regs);
}
static bool apbuart_set_attributes(
- rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
const struct termios *t
)
{
- struct apbuart_context *uart = rtems_termios_get_device_context(tty);
+ struct apbuart_context *uart = (struct apbuart_context *) base;
rtems_interrupt_lock_context lock_context;
unsigned int scaler;
unsigned int ctrl;
@@ -112,7 +112,7 @@ static bool apbuart_set_attributes(
break;
}
- rtems_termios_interrupt_lock_acquire(tty, &lock_context);
+ rtems_termios_device_lock_acquire(base, &lock_context);
/* Read out current value */
ctrl = uart->regs->ctrl;
@@ -145,7 +145,7 @@ static bool apbuart_set_attributes(
/* Update new settings */
uart->regs->ctrl = ctrl;
- rtems_termios_interrupt_lock_release(tty, &lock_context);
+ rtems_termios_device_lock_release(base, &lock_context);
/* Baud rate */
baud = rtems_termios_baud_to_number(t->c_cflag);
@@ -161,23 +161,25 @@ static bool apbuart_set_attributes(
}
static void apbuart_set_best_baud(
- rtems_termios_tty *tty,
- const struct apbuart_context *uart
+ const struct apbuart_context *uart,
+ struct termios *term
)
{
uint32_t baud = (uart->freq_hz * 10) / ((uart->regs->scaler * 10 + 5) * 8);
- rtems_termios_set_best_baud(tty, baud);
+ rtems_termios_set_best_baud(term, baud);
}
static bool apbuart_first_open_polled(
rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
+ struct termios *term,
rtems_libio_open_close_args_t *args
)
{
- struct apbuart_context *uart = rtems_termios_get_device_context(tty);
+ struct apbuart_context *uart = (struct apbuart_context *) base;
- apbuart_set_best_baud(tty, uart);
+ apbuart_set_best_baud(uart, term);
/* Initialize UART on opening */
uart->regs->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
@@ -188,13 +190,15 @@ static bool apbuart_first_open_polled(
static bool apbuart_first_open_interrupt(
rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
+ struct termios *term,
rtems_libio_open_close_args_t *args
)
{
- struct apbuart_context *uart = rtems_termios_get_device_context(tty);
+ struct apbuart_context *uart = (struct apbuart_context *) base;
rtems_status_code sc;
- apbuart_set_best_baud(tty, uart);
+ apbuart_set_best_baud(uart, term);
/* Register Interrupt handler */
sc = rtems_interrupt_handler_install(uart->irq, "console",
@@ -217,16 +221,17 @@ static bool apbuart_first_open_interrupt(
static void apbuart_last_close_interrupt(
rtems_termios_tty *tty,
+ rtems_termios_device_context *base,
rtems_libio_open_close_args_t *args
)
{
- struct apbuart_context *uart = rtems_termios_get_device_context(tty);
+ struct apbuart_context *uart = (struct apbuart_context *) base;
rtems_interrupt_lock_context lock_context;
/* Turn off RX interrupts */
- rtems_termios_interrupt_lock_acquire(tty, &lock_context);
+ rtems_termios_device_lock_acquire(base, &lock_context);
uart->regs->ctrl &= ~(APBUART_CTRL_RI);
- rtems_termios_interrupt_lock_release(tty, &lock_context);
+ rtems_termios_device_lock_release(base, &lock_context);
/**** Flush device ****/
while (uart->sending) {