Ignore:
Timestamp:
Mar 9, 2017, 12:23:54 PM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
dc95663e
Parents:
ce5bcc87
Message:

bsp/tms570: Support printk() early

Allow use of printk() early in the initalization and without a console
driver.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/tms570/console/printk-support.c

    rce5bcc87 r5ca634e9  
    2525
    2626#include <rtems/bspIo.h>
     27#include <rtems/sysinit.h>
    2728#include <stdint.h>
    2829#include <bsp/tms570-sci.h>
    2930#include <bsp/tms570-sci-driver.h>
    3031
     32#define TMS570_CONSOLE (&driver_context_table[0])
    3133
    3234/**
     
    3739 * @retval Void
    3840 */
    39 static void tms570_putc(char ch)
     41static void tms570_debug_console_putc(char ch)
    4042{
     43  tms570_sci_context *ctx = TMS570_CONSOLE;
     44  volatile tms570_sci_t *regs = ctx->regs;
    4145  rtems_interrupt_level level;
    4246
    4347  rtems_interrupt_disable(level);
    44   while ( ( driver_context_table[0].regs->FLR & TMS570_SCI_FLR_TXRDY ) == 0) {
     48  while ( ( regs->FLR & TMS570_SCI_FLR_TXRDY ) == 0) {
    4549    rtems_interrupt_flash(level);
    4650  }
    47   driver_context_table[0].regs->TD = ch;
     51  regs->TD = ch;
     52  while ( ( regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0) {
     53    rtems_interrupt_flash(level);
     54  }
    4855  rtems_interrupt_enable(level);
    4956}
     
    5663 * @retval Void
    5764 */
    58 static void tms570_uart_output(char c)
     65static void tms570_debug_console_out(char c)
    5966{
    6067  if ( c == '\n' ) {
    61     char r = '\r';
    62     tms570_putc(r);
     68    tms570_debug_console_putc('\r');
    6369  }
    64   tms570_putc(c);
     70
     71  tms570_debug_console_putc(c);
     72}
     73
     74static void tms570_debug_console_init(void)
     75{
     76  tms570_sci_context *ctx = TMS570_CONSOLE;
     77  struct termios term;
     78
     79  tms570_sci_initialize(ctx);
     80  memset(&term, 0, sizeof(term));
     81  term.c_cflag = B115200;
     82  tms570_sci_set_attributes(&ctx->base, &term);
     83  BSP_output_char = tms570_debug_console_out;
     84}
     85
     86static void tms570_debug_console_early_init(char c)
     87{
     88  tms570_debug_console_init();
     89  tms570_debug_console_out(c);
    6590}
    6691
     
    7398 * @retval -1 No input character available
    7499 */
    75 static int tms570_uart_input( void )
     100static int tms570_debug_console_in( void )
    76101{
    77   if ( driver_context_table[0].regs->FLR & TMS570_SCI_FLR_RXRDY ) {
    78       return driver_context_table[0].regs->RD;
     102  tms570_sci_context *ctx = TMS570_CONSOLE;
     103  volatile tms570_sci_t *regs = ctx->regs;
     104  rtems_interrupt_level level;
     105  int c;
     106
     107  rtems_interrupt_disable(level);
     108
     109  if ( regs->FLR & TMS570_SCI_FLR_RXRDY ) {
     110      c = (unsigned char) regs->RD;
    79111  } else {
    80       return -1;
     112      c = -1;
    81113  }
     114
     115  rtems_interrupt_enable(level);
     116
     117  return c;
    82118}
    83119
    84 BSP_output_char_function_type BSP_output_char = tms570_uart_output;
    85 BSP_polling_getchar_function_type BSP_poll_char = tms570_uart_input;
     120BSP_output_char_function_type BSP_output_char =
     121  tms570_debug_console_early_init;
     122
     123BSP_polling_getchar_function_type BSP_poll_char = tms570_debug_console_in;
     124
     125RTEMS_SYSINIT_ITEM(
     126  tms570_debug_console_init,
     127  RTEMS_SYSINIT_BSP_START,
     128  RTEMS_SYSINIT_ORDER_LAST
     129);
Note: See TracChangeset for help on using the changeset viewer.