source: rtems/c/src/lib/libbsp/arm/beagle/console/console-config.c @ 1bc0ad2

5
Last change on this file since 1bc0ad2 was 1bc0ad2, checked in by Sebastian Huber <sebastian.huber@…>, on 09/08/17 at 08:38:46

Simplify and unify BSP_output_char

The BSP_output_char should output a char and not mingle with high level
processing, e.g. '\n' to '\r\n' translation. Move this translation to
rtems_putc(). Remove it from all the BSP_output_char implementations.

Close #3122.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_beagle
5 *
6 * @brief Console configuration.
7 */
8
9/*
10 * Copyright (c) 2012 Claas Ziemke. All rights reserved.
11 *
12 *  Claas Ziemke
13 *  Kernerstrasse 11
14 *  70182 Stuttgart
15 *  Germany
16 *  <claas.ziemke@gmx.net>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 *
22 * Modified by Ben Gras <beng@shrike-systems.com> to make
23 * interrupt-driven uart i/o work for beagleboards; beaglebone support added.
24 */
25
26#include <libchip/serial.h>
27#include <libchip/ns16550.h>
28
29#include <rtems/bspIo.h>
30
31#include <bsp.h>
32#include <bsp/irq.h>
33#include <bsp/uart-output-char.h>
34
35#define CONSOLE_UART_THR (*(volatile unsigned int *)BSP_CONSOLE_UART_BASE)
36#define CONSOLE_UART_RHR (*(volatile unsigned int *)BSP_CONSOLE_UART_BASE)
37#define CONSOLE_UART_LSR (*(volatile unsigned int *)(BSP_CONSOLE_UART_BASE+0x14))
38#define CONSOLE_SYSC (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + 0x54))
39#define CONSOLE_SYSS (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + 0x58))
40
41#define TX_FIFO_E (1<<5)
42#define RX_FIFO_E (1<<0)
43
44static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t i)
45{
46  uint8_t v;
47  volatile uint32_t *reg_r = (volatile uint32_t *) addr + i;
48
49  if(reg_r == (uint32_t*) BSP_CONSOLE_UART_BASE /* reading RHR */ ) {
50    /* check there should be anything in the RHR before accessing it */
51    if(!(CONSOLE_UART_LSR & 0x01)) {
52      return 0;
53    }
54  }
55
56  v = (uint8_t) *reg_r;
57
58  return v;
59}
60
61static void beagle_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
62{
63  volatile uint32_t *reg = (volatile uint32_t *) addr;
64
65  reg [i] = val;
66}
67
68console_tbl Console_Configuration_Ports [] = {
69    {
70      .sDeviceName = "/dev/ttyS0",
71      .deviceType = SERIAL_NS16550,
72#if CONSOLE_POLLED      /* option to facilitate running the tests */
73      .pDeviceFns = &ns16550_fns_polled,
74#else
75      .pDeviceFns = &ns16550_fns,
76#endif
77      .ulMargin = 16,
78      .ulHysteresis = 8,
79      .pDeviceParams = (void *) CONSOLE_BAUD,
80      .ulCtrlPort1 = BSP_CONSOLE_UART_BASE,
81      .ulDataPort = BSP_CONSOLE_UART_BASE,
82      .ulIntVector = BSP_CONSOLE_UART_IRQ,
83      .getRegister = beagle_uart_get_register,
84      .setRegister = beagle_uart_set_register,
85      .ulClock = UART_CLOCK,  /* 48MHz base clock */
86    },
87};
88
89unsigned long Console_Configuration_Count = 1;
90
91static int init_needed = 1; // don't rely on bss being 0
92
93static void beagle_console_init(void)
94{
95  if(init_needed) {
96    const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD;
97    CONSOLE_SYSC = 2;
98    while ((CONSOLE_SYSS & 1) == 0)
99      ;
100    if ((CONSOLE_LSR & (CONSOLE_LSR_THRE | CONSOLE_LSR_TEMT)) == CONSOLE_LSR_THRE) {
101      CONSOLE_LCR = 0x83;
102      CONSOLE_DLL = div;
103      CONSOLE_DLM = (div >> 8) & 0xff;
104      CONSOLE_LCR = 0x03;
105      CONSOLE_ACR = 0x00;
106    }
107
108    while ((CONSOLE_LSR & CONSOLE_LSR_TEMT) == 0)
109      ;
110
111    CONSOLE_LCR = 0x80 | 0x03;
112    CONSOLE_DLL = 0x00;
113    CONSOLE_DLM = 0x00;
114    CONSOLE_LCR = 0x03;
115    CONSOLE_MCR = 0x03;
116    CONSOLE_FCR = 0x07;
117    CONSOLE_LCR = 0x83;
118    CONSOLE_DLL = div;
119    CONSOLE_DLM = (div >> 8) & 0xff;
120    CONSOLE_LCR = 0x03;
121    CONSOLE_ACR = 0x00;
122    init_needed = 0;
123  }
124}
125
126#define CONSOLE_THR8 (*(volatile uint8_t *) (BSP_CONSOLE_UART_BASE + 0x00))
127
128static void uart_write_polled( char c )
129{
130  if(init_needed) beagle_console_init();
131
132  while( ( CONSOLE_LSR & TX_FIFO_E ) == 0 )
133    ;
134  CONSOLE_THR8 = c;
135}
136
137static void _BSP_put_char( char c ) {
138   uart_write_polled( c );
139}
140
141static int _BSP_get_char(void)
142{
143  if ((CONSOLE_LSR & CONSOLE_LSR_RDR) != 0) {
144    return CONSOLE_RBR;
145  } else {
146    return -1;
147  }
148}
149
150BSP_output_char_function_type BSP_output_char = _BSP_put_char;
151
152BSP_polling_getchar_function_type BSP_poll_char = _BSP_get_char;
Note: See TracBrowser for help on using the repository browser.