summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/beagle/console/console-config.c
blob: a9349e8425d6447cda57d26b54dbb044ac21cc25 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
 * @file
 *
 * @ingroup beagle
 *
 * @brief Console configuration.
 */

/*
 * Copyright (c) 2012 Claas Ziemke. All rights reserved.
 *
 *  Claas Ziemke
 *  Kernerstrasse 11
 *  70182 Stuttgart
 *  Germany
 *  <claas.ziemke@gmx.net>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#include <libchip/serial.h>
#include <libchip/ns16550.h>

#include <bsp.h>
#include <bsp/beagle.h>
#include <bsp/irq.h>

#define UART3_THR (*(volatile unsigned int *)0x49020000)
#define UART3_RHR (*(volatile unsigned int *)0x49020000)
#define UART3_LSR (*(volatile unsigned int *)0x49020014)
#define TX_FIFO_E (1<<5)
#define RX_FIFO_E (1<<0)

static uint8_t beagle_uart_get_register(uint32_t addr, uint8_t i)
{
  volatile uint32_t *reg = (volatile uint32_t *) addr;

  return (uint8_t) reg [i];
}

static void beagle_uart_set_register(uint32_t addr, uint8_t i, uint8_t val)
{
  volatile uint32_t *reg = (volatile uint32_t *) addr;

  reg [i] = val;
}

/* FIXME: Console selection */

console_tbl Console_Configuration_Ports [] = {
  #ifdef BEAGLE_CONFIG_U5CLK
    {
      .sDeviceName = "/dev/ttyS5",
      .deviceType = SERIAL_NS16550,
      .pDeviceFns = &ns16550_fns_polled,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) 1,
      .ulCtrlPort1 = BEAGLE_BASE_UART_5,
      .ulCtrlPort2 = 0,
      .ulDataPort = BEAGLE_BASE_UART_5,
      .getRegister = beagle_uart_get_register,
      .setRegister = beagle_uart_set_register,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 16,
      .ulIntVector = BEAGLE_IRQ_UART_5
    },
  #endif
  #ifdef BEAGLE_CONFIG_U3CLK
    {
      .sDeviceName = "/dev/ttyS3",
      .deviceType = SERIAL_NS16550,
      .pDeviceFns = &ns16550_fns,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) 1,
      .ulCtrlPort1 = BEAGLE_BASE_UART_3,
      .ulCtrlPort2 = 0,
      .ulDataPort = BEAGLE_BASE_UART_3,
      .getRegister = beagle_uart_get_register,
      .setRegister = beagle_uart_set_register,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 16,
      .ulIntVector = BEAGLE_IRQ_UART_3
    },
  #endif
  #ifdef BEAGLE_CONFIG_U4CLK
    {
      .sDeviceName = "/dev/ttyS4",
      .deviceType = SERIAL_NS16550,
      .pDeviceFns = &ns16550_fns,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) 1,
      .ulCtrlPort1 = BEAGLE_BASE_UART_4,
      .ulCtrlPort2 = 0,
      .ulDataPort = BEAGLE_BASE_UART_4,
      .getRegister = beagle_uart_get_register,
      .setRegister = beagle_uart_set_register,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 16,
      .ulIntVector = BEAGLE_IRQ_UART_4
    },
  #endif
  #ifdef BEAGLE_CONFIG_U6CLK
    {
      .sDeviceName = "/dev/ttyS6",
      .deviceType = SERIAL_NS16550,
      .pDeviceFns = &ns16550_fns,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) 1,
      .ulCtrlPort1 = BEAGLE_BASE_UART_6,
      .ulCtrlPort2 = 0,
      .ulDataPort = BEAGLE_BASE_UART_6,
      .getRegister = beagle_uart_get_register,
      .setRegister = beagle_uart_set_register,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 16,
      .ulIntVector = BEAGLE_IRQ_UART_6
    },
  #endif
  #ifdef BEAGLE_UART_1_BAUD
    {
      .sDeviceName = "/dev/ttyS1",
      .deviceType = SERIAL_CUSTOM,
      .pDeviceFns = &ns16550_fns,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) BEAGLE_UART_1_BAUD,
      .ulCtrlPort1 = BEAGLE_BASE_UART_1,
      .ulCtrlPort2 = 0,
      .ulDataPort = 0,
      .getRegister = NULL,
      .setRegister = NULL,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 16,
      .ulIntVector = BEAGLE_IRQ_UART_1
    },
  #endif
  #ifdef BEAGLE_UART_2_BAUD
    {
      .sDeviceName = "/dev/ttyS2",
      .deviceType = SERIAL_CUSTOM,
      .pDeviceFns = &ns16550_fns,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) BEAGLE_UART_2_BAUD,
      .ulCtrlPort1 = BEAGLE_BASE_UART_2,
      .ulCtrlPort2 = 0,
      .ulDataPort = 0,
      .getRegister = NULL,
      .setRegister = NULL,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 16,
      .ulIntVector = BEAGLE_IRQ_UART_2
    },
  #endif
  #ifdef BEAGLE_UART_7_BAUD
    {
      .sDeviceName = "/dev/ttyS7",
      .deviceType = SERIAL_CUSTOM,
      .pDeviceFns = &ns16550_fns,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) BEAGLE_UART_7_BAUD,
      .ulCtrlPort1 = BEAGLE_BASE_UART_7,
      .ulCtrlPort2 = 0,
      .ulDataPort = 0,
      .getRegister = NULL,
      .setRegister = NULL,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 16,
      .ulIntVector = BEAGLE_IRQ_UART_7
    },
  #endif
};

#define BEAGLE_UART_COUNT \
  (sizeof(Console_Configuration_Ports) / \
  sizeof(Console_Configuration_Ports [0]))

unsigned long Console_Configuration_Count = BEAGLE_UART_COUNT;

static void uart_write_polled( char c ) {
  // wait until TX-Buffer is empty
  while( ( UART3_LSR & TX_FIFO_E ) == 0 )
  ;

  // send character
  UART3_THR = c;
  return c;
}


/*
* Write a character to the console. This is used by printk() and
* maybe other low level functions. It should not use interrupts or any
* RTEMS system calls. It needs to be very simple
*/
static void _BSP_put_char( char c ) {
   uart_write_polled( c );
   if (c == '\n') {
       uart_write_polled('\r');
   }
}

BSP_output_char_function_type BSP_output_char = _BSP_put_char;