summaryrefslogtreecommitdiffstats
path: root/c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-03-09 13:23:54 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-03-09 13:23:54 +0100
commit5ca634e9c074d7a7bf1e35fbf8dec8f031535a1d (patch)
tree41627684b30e38a210a5e4303e37b62a2e6a1a72 /c
parentbsp/beagle: Fix warnings (diff)
downloadrtems-5ca634e9c074d7a7bf1e35fbf8dec8f031535a1d.tar.bz2
bsp/tms570: Support printk() early
Allow use of printk() early in the initalization and without a console driver.
Diffstat (limited to 'c')
-rw-r--r--c/src/lib/libbsp/arm/tms570/console/printk-support.c70
-rw-r--r--c/src/lib/libbsp/arm/tms570/console/tms570-sci.c76
-rw-r--r--c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h7
3 files changed, 105 insertions, 48 deletions
diff --git a/c/src/lib/libbsp/arm/tms570/console/printk-support.c b/c/src/lib/libbsp/arm/tms570/console/printk-support.c
index 77e4f1ada6..668f2d9959 100644
--- a/c/src/lib/libbsp/arm/tms570/console/printk-support.c
+++ b/c/src/lib/libbsp/arm/tms570/console/printk-support.c
@@ -24,10 +24,12 @@
*/
#include <rtems/bspIo.h>
+#include <rtems/sysinit.h>
#include <stdint.h>
#include <bsp/tms570-sci.h>
#include <bsp/tms570-sci-driver.h>
+#define TMS570_CONSOLE (&driver_context_table[0])
/**
* @brief Puts chars into peripheral
@@ -36,15 +38,20 @@
*
* @retval Void
*/
-static void tms570_putc(char ch)
+static void tms570_debug_console_putc(char ch)
{
+ tms570_sci_context *ctx = TMS570_CONSOLE;
+ volatile tms570_sci_t *regs = ctx->regs;
rtems_interrupt_level level;
rtems_interrupt_disable(level);
- while ( ( driver_context_table[0].regs->FLR & TMS570_SCI_FLR_TXRDY ) == 0) {
+ while ( ( regs->FLR & TMS570_SCI_FLR_TXRDY ) == 0) {
+ rtems_interrupt_flash(level);
+ }
+ regs->TD = ch;
+ while ( ( regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0) {
rtems_interrupt_flash(level);
}
- driver_context_table[0].regs->TD = ch;
rtems_interrupt_enable(level);
}
@@ -55,13 +62,31 @@ static void tms570_putc(char ch)
*
* @retval Void
*/
-static void tms570_uart_output(char c)
+static void tms570_debug_console_out(char c)
{
if ( c == '\n' ) {
- char r = '\r';
- tms570_putc(r);
+ tms570_debug_console_putc('\r');
}
- tms570_putc(c);
+
+ tms570_debug_console_putc(c);
+}
+
+static void tms570_debug_console_init(void)
+{
+ tms570_sci_context *ctx = TMS570_CONSOLE;
+ struct termios term;
+
+ tms570_sci_initialize(ctx);
+ memset(&term, 0, sizeof(term));
+ term.c_cflag = B115200;
+ tms570_sci_set_attributes(&ctx->base, &term);
+ BSP_output_char = tms570_debug_console_out;
+}
+
+static void tms570_debug_console_early_init(char c)
+{
+ tms570_debug_console_init();
+ tms570_debug_console_out(c);
}
/**
@@ -72,14 +97,33 @@ static void tms570_uart_output(char c)
* @retval x Read char
* @retval -1 No input character available
*/
-static int tms570_uart_input( void )
+static int tms570_debug_console_in( void )
{
- if ( driver_context_table[0].regs->FLR & TMS570_SCI_FLR_RXRDY ) {
- return driver_context_table[0].regs->RD;
+ tms570_sci_context *ctx = TMS570_CONSOLE;
+ volatile tms570_sci_t *regs = ctx->regs;
+ rtems_interrupt_level level;
+ int c;
+
+ rtems_interrupt_disable(level);
+
+ if ( regs->FLR & TMS570_SCI_FLR_RXRDY ) {
+ c = (unsigned char) regs->RD;
} else {
- return -1;
+ c = -1;
}
+
+ rtems_interrupt_enable(level);
+
+ return c;
}
-BSP_output_char_function_type BSP_output_char = tms570_uart_output;
-BSP_polling_getchar_function_type BSP_poll_char = tms570_uart_input;
+BSP_output_char_function_type BSP_output_char =
+ tms570_debug_console_early_init;
+
+BSP_polling_getchar_function_type BSP_poll_char = tms570_debug_console_in;
+
+RTEMS_SYSINIT_ITEM(
+ tms570_debug_console_init,
+ RTEMS_SYSINIT_BSP_START,
+ RTEMS_SYSINIT_ORDER_LAST
+);
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 1cd3fe1754..d72aa612c5 100644
--- a/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
+++ b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c
@@ -58,6 +58,44 @@ tms570_sci_context driver_context_table[] = {
}
};
+void tms570_sci_initialize(tms570_sci_context *ctx)
+{
+ uint32_t rx_pin = 1 << 1;
+ uint32_t tx_pin = 1 << 2;
+
+ /* Resec SCI peripheral */
+ ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 0;
+ ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 1;
+
+ /* Clear all interrupt sources */
+ ctx->regs->CLEARINT = 0xffffffff;
+
+ /* Map all interrupts to SCI INT0 line */
+ ctx->regs->CLEARINTLVL = 0xffffffff;
+
+ ctx->regs->GCR1 = TMS570_SCI_GCR1_TXENA * 0 |
+ TMS570_SCI_GCR1_RXENA * 0 |
+ TMS570_SCI_GCR1_CONT * 0 | /* continue operation when debugged */
+ TMS570_SCI_GCR1_LOOP_BACK * 0 |
+ TMS570_SCI_GCR1_POWERDOWN * 0 |
+ TMS570_SCI_GCR1_SLEEP * 0 |
+ TMS570_SCI_GCR1_SWnRST * 0 | /* reset state */
+ TMS570_SCI_GCR1_CLOCK * 1 | /* internal clock */
+ TMS570_SCI_GCR1_TIMING_MODE * 1 |
+ TMS570_SCI_GCR1_COMM_MODE * 0;
+
+ /* Setup connection of SCI peripheral Rx and Tx pins */
+ ctx->regs->PIO0 = rx_pin * 1 | tx_pin * 1; /* Rx and Tx pins are not GPIO */
+ ctx->regs->PIO3 = rx_pin * 0 | tx_pin * 0; /* Default output low */
+ ctx->regs->PIO1 = rx_pin * 0 | tx_pin * 0; /* Input when not used by SCI */
+ ctx->regs->PIO6 = rx_pin * 0 | tx_pin * 0; /* No open drain */
+ ctx->regs->PIO7 = rx_pin * 0 | tx_pin * 0; /* Pull-up/down enabled */
+ ctx->regs->PIO8 = rx_pin * 1 | tx_pin * 1; /* Select pull-up */
+
+ /* Bring device out of software reset */
+ ctx->regs->GCR1 |= TMS570_SCI_GCR1_SWnRST;
+}
+
/**
* @brief Serial drivers init function
*
@@ -95,40 +133,8 @@ rtems_device_driver console_initialize(
++minor
) {
tms570_sci_context *ctx = &driver_context_table[minor];
- uint32_t rx_pin = 1 << 1;
- uint32_t tx_pin = 1 << 2;
-
- /* Resec SCI peripheral */
- ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 0;
- ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 1;
-
- /* Clear all interrupt sources */
- ctx->regs->CLEARINT = 0xffffffff;
-
- /* Map all interrupts to SCI INT0 line */
- ctx->regs->CLEARINTLVL = 0xffffffff;
-
- ctx->regs->GCR1 = TMS570_SCI_GCR1_TXENA * 0 |
- TMS570_SCI_GCR1_RXENA * 0 |
- TMS570_SCI_GCR1_CONT * 0 | /* continue operation when debugged */
- TMS570_SCI_GCR1_LOOP_BACK * 0 |
- TMS570_SCI_GCR1_POWERDOWN * 0 |
- TMS570_SCI_GCR1_SLEEP * 0 |
- TMS570_SCI_GCR1_SWnRST * 0 | /* reset state */
- TMS570_SCI_GCR1_CLOCK * 1 | /* internal clock */
- TMS570_SCI_GCR1_TIMING_MODE * 1 |
- TMS570_SCI_GCR1_COMM_MODE * 0;
-
- /* Setup connection of SCI peripheral Rx and Tx pins */
- ctx->regs->PIO0 = rx_pin * 1 | tx_pin * 1; /* Rx and Tx pins are not GPIO */
- ctx->regs->PIO3 = rx_pin * 0 | tx_pin * 0; /* Default output low */
- ctx->regs->PIO1 = rx_pin * 0 | tx_pin * 0; /* Input when not used by SCI */
- ctx->regs->PIO6 = rx_pin * 0 | tx_pin * 0; /* No open drain */
- ctx->regs->PIO7 = rx_pin * 0 | tx_pin * 0; /* Pull-up/down enabled */
- ctx->regs->PIO8 = rx_pin * 1 | tx_pin * 1; /* Select pull-up */
-
- /* Bring device out of software reset */
- ctx->regs->GCR1 |= TMS570_SCI_GCR1_SWnRST;
+
+ tms570_sci_initialize(ctx);
/*
* Install this device in the file system and Termios. In order
@@ -236,7 +242,7 @@ static int tms570_sci_transmitted_chars(tms570_sci_context * ctx)
* @param[in] t termios driver
* @retval true peripheral setting is changed
*/
-static bool tms570_sci_set_attributes(
+bool tms570_sci_set_attributes(
rtems_termios_device_context *base,
const struct termios *t
)
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 1d9eaa74b9..61693ce0ff 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
@@ -49,6 +49,13 @@ extern const rtems_termios_device_handler tms570_sci_handler_interrupt;
extern tms570_sci_context driver_context_table[];
+void tms570_sci_initialize(tms570_sci_context *ctx);
+
+bool tms570_sci_set_attributes(
+ rtems_termios_device_context *base,
+ const struct termios *term
+);
+
/** @} */
#ifdef __cplusplus