source: rtems/c/src/lib/libbsp/arm/tms570/console/printk-support.c @ 5ca634e9

5
Last change on this file since 5ca634e9 was 5ca634e9, checked in by Sebastian Huber <sebastian.huber@…>, on 03/09/17 at 12:23:54

bsp/tms570: Support printk() early

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

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 * @file printk-support.c
3 *
4 * @ingroup tms570
5 *
6 * @brief definitions of serial line for debugging.
7 */
8
9/*
10 * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com>
11 *
12 * Google Summer of Code 2014 at
13 * Czech Technical University in Prague
14 * Zikova 1903/4
15 * 166 36 Praha 6
16 * Czech Republic
17 *
18 * Based on LPC24xx and LPC1768 BSP
19 * by embedded brains GmbH and others
20 *
21 * The license and distribution terms for this file may be
22 * found in the file LICENSE in this distribution or at
23 * http://www.rtems.org/license/LICENSE.
24 */
25
26#include <rtems/bspIo.h>
27#include <rtems/sysinit.h>
28#include <stdint.h>
29#include <bsp/tms570-sci.h>
30#include <bsp/tms570-sci-driver.h>
31
32#define TMS570_CONSOLE (&driver_context_table[0])
33
34/**
35 * @brief Puts chars into peripheral
36 *
37 * debug functions always use serial dev 0 peripheral
38 *
39 * @retval Void
40 */
41static void tms570_debug_console_putc(char ch)
42{
43  tms570_sci_context *ctx = TMS570_CONSOLE;
44  volatile tms570_sci_t *regs = ctx->regs;
45  rtems_interrupt_level level;
46
47  rtems_interrupt_disable(level);
48  while ( ( regs->FLR & TMS570_SCI_FLR_TXRDY ) == 0) {
49    rtems_interrupt_flash(level);
50  }
51  regs->TD = ch;
52  while ( ( regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0) {
53    rtems_interrupt_flash(level);
54  }
55  rtems_interrupt_enable(level);
56}
57
58/**
59 * @brief debug console output
60 *
61 * debug functions always use serial dev 0 peripheral
62 *
63 * @retval Void
64 */
65static void tms570_debug_console_out(char c)
66{
67  if ( c == '\n' ) {
68    tms570_debug_console_putc('\r');
69  }
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);
90}
91
92/**
93 * @brief debug console input
94 *
95 * debug functions always use serial dev 0 peripheral
96 *
97 * @retval x Read char
98 * @retval -1 No input character available
99 */
100static int tms570_debug_console_in( void )
101{
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;
111  } else {
112      c = -1;
113  }
114
115  rtems_interrupt_enable(level);
116
117  return c;
118}
119
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 TracBrowser for help on using the repository browser.