Changeset 5ca634e9 in rtems


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.

Location:
c/src/lib/libbsp/arm/tms570
Files:
3 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);
  • c/src/lib/libbsp/arm/tms570/console/tms570-sci.c

    rce5bcc87 r5ca634e9  
    5959};
    6060
     61void tms570_sci_initialize(tms570_sci_context *ctx)
     62{
     63  uint32_t rx_pin = 1 << 1;
     64  uint32_t tx_pin = 1 << 2;
     65
     66  /* Resec SCI peripheral */
     67  ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 0;
     68  ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 1;
     69
     70  /* Clear all interrupt sources */
     71  ctx->regs->CLEARINT = 0xffffffff;
     72
     73  /* Map all interrupts to SCI INT0 line */
     74  ctx->regs->CLEARINTLVL = 0xffffffff;
     75
     76  ctx->regs->GCR1 = TMS570_SCI_GCR1_TXENA * 0 |
     77                    TMS570_SCI_GCR1_RXENA * 0 |
     78                    TMS570_SCI_GCR1_CONT * 0 | /* continue operation when debugged */
     79                    TMS570_SCI_GCR1_LOOP_BACK * 0 |
     80                    TMS570_SCI_GCR1_POWERDOWN * 0 |
     81                    TMS570_SCI_GCR1_SLEEP * 0 |
     82                    TMS570_SCI_GCR1_SWnRST * 0 | /* reset state */
     83                    TMS570_SCI_GCR1_CLOCK * 1 | /* internal clock */
     84                    TMS570_SCI_GCR1_TIMING_MODE * 1 |
     85                    TMS570_SCI_GCR1_COMM_MODE * 0;
     86
     87  /* Setup connection of SCI peripheral Rx and Tx  pins */
     88  ctx->regs->PIO0 = rx_pin * 1 | tx_pin * 1; /* Rx and Tx pins are not GPIO */
     89  ctx->regs->PIO3 = rx_pin * 0 | tx_pin * 0; /* Default output low  */
     90  ctx->regs->PIO1 = rx_pin * 0 | tx_pin * 0; /* Input when not used by SCI */
     91  ctx->regs->PIO6 = rx_pin * 0 | tx_pin * 0; /* No open drain */
     92  ctx->regs->PIO7 = rx_pin * 0 | tx_pin * 0; /* Pull-up/down enabled */
     93  ctx->regs->PIO8 = rx_pin * 1 | tx_pin * 1; /* Select pull-up */
     94
     95  /* Bring device out of software reset */
     96  ctx->regs->GCR1 |= TMS570_SCI_GCR1_SWnRST;
     97}
     98
    6199/**
    62100 * @brief Serial drivers init function
     
    96134  ) {
    97135    tms570_sci_context *ctx = &driver_context_table[minor];
    98     uint32_t rx_pin = 1 << 1;
    99     uint32_t tx_pin = 1 << 2;
    100 
    101     /* Resec SCI peripheral */
    102     ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 0;
    103     ctx->regs->GCR0 = TMS570_SCI_GCR0_RESET * 1;
    104 
    105     /* Clear all interrupt sources */
    106     ctx->regs->CLEARINT = 0xffffffff;
    107 
    108     /* Map all interrupts to SCI INT0 line */
    109     ctx->regs->CLEARINTLVL = 0xffffffff;
    110 
    111     ctx->regs->GCR1 = TMS570_SCI_GCR1_TXENA * 0 |
    112                       TMS570_SCI_GCR1_RXENA * 0 |
    113                       TMS570_SCI_GCR1_CONT * 0 | /* continue operation when debugged */
    114                       TMS570_SCI_GCR1_LOOP_BACK * 0 |
    115                       TMS570_SCI_GCR1_POWERDOWN * 0 |
    116                       TMS570_SCI_GCR1_SLEEP * 0 |
    117                       TMS570_SCI_GCR1_SWnRST * 0 | /* reset state */
    118                       TMS570_SCI_GCR1_CLOCK * 1 | /* internal clock */
    119                       TMS570_SCI_GCR1_TIMING_MODE * 1 |
    120                       TMS570_SCI_GCR1_COMM_MODE * 0;
    121 
    122     /* Setup connection of SCI peripheral Rx and Tx  pins */
    123     ctx->regs->PIO0 = rx_pin * 1 | tx_pin * 1; /* Rx and Tx pins are not GPIO */
    124     ctx->regs->PIO3 = rx_pin * 0 | tx_pin * 0; /* Default output low  */
    125     ctx->regs->PIO1 = rx_pin * 0 | tx_pin * 0; /* Input when not used by SCI */
    126     ctx->regs->PIO6 = rx_pin * 0 | tx_pin * 0; /* No open drain */
    127     ctx->regs->PIO7 = rx_pin * 0 | tx_pin * 0; /* Pull-up/down enabled */
    128     ctx->regs->PIO8 = rx_pin * 1 | tx_pin * 1; /* Select pull-up */
    129 
    130     /* Bring device out of software reset */
    131     ctx->regs->GCR1 |= TMS570_SCI_GCR1_SWnRST;
     136
     137    tms570_sci_initialize(ctx);
    132138
    133139    /*
     
    237243 * @retval true peripheral setting is changed
    238244 */
    239 static bool tms570_sci_set_attributes(
     245bool tms570_sci_set_attributes(
    240246  rtems_termios_device_context *base,
    241247  const struct termios *t
  • c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h

    rce5bcc87 r5ca634e9  
    5050extern tms570_sci_context driver_context_table[];
    5151
     52void tms570_sci_initialize(tms570_sci_context *ctx);
     53
     54bool tms570_sci_set_attributes(
     55  rtems_termios_device_context *base,
     56  const struct termios *term
     57);
     58
    5259/** @} */
    5360
Note: See TracChangeset for help on using the changeset viewer.