summaryrefslogtreecommitdiffstats
path: root/bsps/arm/tms570/console/printk-support.c
blob: 9e4a6000f1145765a20f2804a338a277dba656fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
 * @file
 *
 * @ingroup RTEMSBSPsARMTMS570
 *
 * @brief definitions of serial line for debugging.
 */

/*
 * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com>
 *
 * Google Summer of Code 2014 at
 * Czech Technical University in Prague
 * Zikova 1903/4
 * 166 36 Praha 6
 * Czech Republic
 *
 * Based on LPC24xx and LPC1768 BSP
 * by embedded brains GmbH and others
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#include <rtems/bspIo.h>
#include <rtems/sysinit.h>
#include <stdint.h>
#include <string.h>
#include <bsp/tms570-sci.h>
#include <bsp/tms570-sci-driver.h>

#define TMS570_CONSOLE (&driver_context_table[0])

/**
 * @brief Puts chars into peripheral
 *
 * debug functions always use serial dev 0 peripheral
 *
 * @retval Void
 */
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 ( ( 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);
  }
  rtems_interrupt_enable(level);
}

/**
 * @brief debug console output
 *
 * debug functions always use serial dev 0 peripheral
 *
 * @retval Void
 */
static void tms570_debug_console_out(char 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);
}

/**
 * @brief debug console input
 *
 * debug functions always use serial dev 0 peripheral
 *
 * @retval x Read char
 * @retval -1 No input character available
 */
static int tms570_debug_console_in( void )
{
  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 {
      c = -1;
  }

  rtems_interrupt_enable(level);

  return c;
}

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
);