summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/tms570/console/printk-support.c
blob: ed33d985e1c37663a56c00c04cb20b4df2c6a340 (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
/**
 * @file printk-support.c
 *
 * @ingroup tms570
 *
 * @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 <stdint.h>
#include <bsp/tms570-sci.h>
#include <bsp/tms570-sci-driver.h>


/**
 * @brief Puts chars into peripheral
 *
 * debug functions always use serial dev 0 peripheral
 *
 * @retval Void
 */
static void tms570_putc(char ch)
{
  rtems_interrupt_level level;

  rtems_interrupt_disable(level);
  while ( ( driver_context_table[0].regs->FLR & 0x100 ) == 0) {
    rtems_interrupt_flash(level);
  }
  driver_context_table[0].regs->TD = ch;
  rtems_interrupt_enable(level);
}

/**
 * @brief debug console output
 *
 * debug functions always use serial dev 0 peripheral
 *
 * @retval Void
 */
static void tms570_uart_output(char c)
{
  if ( c == '\n' ) {
    char r = '\r';
    tms570_putc(r);
  }
  tms570_putc(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_uart_input( void )
{
  if ( driver_context_table[0].regs->FLR & (1<<9) ) {
      return driver_context_table[0].regs->RD;
  } else {
      return -1;
  }
}

BSP_output_char_function_type BSP_output_char = tms570_uart_output;
BSP_polling_getchar_function_type BSP_poll_char = tms570_uart_input;