summaryrefslogtreecommitdiff
path: root/c/src/lib/libbsp/arm/lpc176x/console/console-config.c
blob: 246a9e65ae01a77b0514f21ba789ed4b95510b99 (plain)
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
/**
 * @file
 *
 * @ingroup lpc176x
 *
 * @brief Console configuration.
 */

/*
 * Copyright (c) 2008-2011 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Obere Lagerstr. 30
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * 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/io.h>
#include <bsp/irq.h>

/**
 * @brief Gets the uart register according to the current address.
 *
 * @param  addr Register address.
 * @param  i Index register.
 * @return  Uart register.
 */
static inline uint8_t lpc176x_uart_get_register(
  const uintptr_t addr,
  const uint8_t   i
)
{
  volatile uint32_t *reg = (volatile uint32_t *) addr;

  return (uint8_t) reg[ i ];
}

/**
 * @brief Sets the uart register address according to the value passed.
 *
 * @param  addr Register address.
 * @param  i Index register.
 * @param val Value to set.
 */
static inline void lpc176x_uart_set_register(
  const uintptr_t addr,
  const uint8_t   i,
  const uint8_t   val
)
{
  volatile uint32_t *reg = (volatile uint32_t *) addr;

  reg[ i ] = val;
}

/**
 * @brief Represents the uart configuration ports.
 */
console_tbl Console_Configuration_Ports[] = {
#ifdef LPC176X_CONFIG_CONSOLE
  {
    .sDeviceName = "/dev/ttyS0",
    .deviceType = SERIAL_NS16550_WITH_FDR,
    .pDeviceFns = &ns16550_fns,
    .deviceProbe = NULL,
    .pDeviceFlow = NULL,
    .ulMargin = 16,
    .ulHysteresis = 8,
    .pDeviceParams = (void *) LPC176X_UART_BAUD,
    .ulCtrlPort1 = UART0_BASE_ADDR,
    .ulCtrlPort2 = 0,
    .ulDataPort = UART0_BASE_ADDR,
    .getRegister = lpc176x_uart_get_register,
    .setRegister = lpc176x_uart_set_register,
    .getData = NULL,
    .setData = NULL,
    .ulClock = LPC176X_PCLK,
    .ulIntVector = LPC176X_IRQ_UART_0
  },
#endif
#ifdef LPC176X_CONFIG_UART_1
  {
    .sDeviceName = "/dev/ttyS1",
    .deviceType = SERIAL_NS16550_WITH_FDR,
    .pDeviceFns = &ns16550_fns,
    .deviceProbe = lpc176x_uart_probe_1,
    .pDeviceFlow = NULL,
    .ulMargin = 16,
    .ulHysteresis = 8,
    .pDeviceParams = (void *) LPC176X_UART_BAUD,
    .ulCtrlPort1 = UART1_BASE_ADDR,
    .ulCtrlPort2 = 0,
    .ulDataPort = UART1_BASE_ADDR,
    .getRegister = lpc176x_uart_get_register,
    .setRegister = lpc176x_uart_set_register,
    .getData = NULL,
    .setData = NULL,
    .ulClock = LPC176X_PCLK,
    .ulIntVector = LPC176X_IRQ_UART_1
  },
#endif
#ifdef LPC176X_CONFIG_UART_2
  {
    .sDeviceName = "/dev/ttyS2",
    .deviceType = SERIAL_NS16550_WITH_FDR,
    .pDeviceFns = &ns16550_fns,
    .deviceProbe = lpc176x_uart_probe_2,
    .pDeviceFlow = NULL,
    .ulMargin = 16,
    .ulHysteresis = 8,
    .pDeviceParams = (void *) LPC176X_UART_BAUD,
    .ulCtrlPort1 = UART2_BASE_ADDR,
    .ulCtrlPort2 = 0,
    .ulDataPort = UART2_BASE_ADDR,
    .getRegister = lpc176x_uart_get_register,
    .setRegister = lpc176x_uart_set_register,
    .getData = NULL,
    .setData = NULL,
    .ulClock = LPC176X_PCLK,
    .ulIntVector = LPC176X_IRQ_UART_2
  },
#endif
#ifdef LPC176X_CONFIG_UART_3
  {
    .sDeviceName = "/dev/ttyS3",
    .deviceType = SERIAL_NS16550_WITH_FDR,
    .pDeviceFns = &ns16550_fns,
    .deviceProbe = lpc176x_uart_probe_3,
    .pDeviceFlow = NULL,
    .ulMargin = 16,
    .ulHysteresis = 8,
    .pDeviceParams = (void *) LPC176X_UART_BAUD,
    .ulCtrlPort1 = UART3_BASE_ADDR,
    .ulCtrlPort2 = 0,
    .ulDataPort = UART3_BASE_ADDR,
    .getRegister = lpc176x_uart_get_register,
    .setRegister = lpc176x_uart_set_register,
    .getData = NULL,
    .setData = NULL,
    .ulClock = LPC176X_PCLK,
    .ulIntVector = LPC176X_IRQ_UART_3
  },
#endif
};

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

unsigned long Console_Configuration_Count = LPC176X_UART_COUNT;