1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSBSPsARMLPC176X |
---|
5 | * |
---|
6 | * @brief Console configuration. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2008-2014 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #include <libchip/ns16550.h> |
---|
18 | |
---|
19 | #include <bsp.h> |
---|
20 | #include <bsp/io.h> |
---|
21 | #include <bsp/irq.h> |
---|
22 | #include <bsp/console-termios.h> |
---|
23 | |
---|
24 | /** |
---|
25 | * @brief Gets the uart register according to the current address. |
---|
26 | * |
---|
27 | * @param addr Register address. |
---|
28 | * @param i Index register. |
---|
29 | * @return Uart register. |
---|
30 | */ |
---|
31 | static inline uint8_t lpc176x_uart_get_register( |
---|
32 | const uintptr_t addr, |
---|
33 | const uint8_t i |
---|
34 | ) |
---|
35 | { |
---|
36 | volatile uint32_t *reg = (volatile uint32_t *) addr; |
---|
37 | |
---|
38 | return (uint8_t) reg[ i ]; |
---|
39 | } |
---|
40 | |
---|
41 | /** |
---|
42 | * @brief Sets the uart register address according to the value passed. |
---|
43 | * |
---|
44 | * @param addr Register address. |
---|
45 | * @param i Index register. |
---|
46 | * @param val Value to set. |
---|
47 | */ |
---|
48 | static inline void lpc176x_uart_set_register( |
---|
49 | const uintptr_t addr, |
---|
50 | const uint8_t i, |
---|
51 | const uint8_t val |
---|
52 | ) |
---|
53 | { |
---|
54 | volatile uint32_t *reg = (volatile uint32_t *) addr; |
---|
55 | |
---|
56 | reg[ i ] = val; |
---|
57 | } |
---|
58 | |
---|
59 | static bool lpc176x_uart1_probe(rtems_termios_device_context *ctx) |
---|
60 | { |
---|
61 | (void)ctx; |
---|
62 | |
---|
63 | lpc176x_module_enable( LPC176X_MODULE_UART_1, LPC176X_MODULE_PCLK_DEFAULT ); |
---|
64 | |
---|
65 | lpc176x_pin_select( LPC176X_PIN_UART_1_TXD, LPC176X_PIN_FUNCTION_01 ); |
---|
66 | lpc176x_pin_select( LPC176X_PIN_UART_1_RXD, LPC176X_PIN_FUNCTION_01 ); |
---|
67 | |
---|
68 | return true; |
---|
69 | } |
---|
70 | |
---|
71 | #ifdef LPC176X_CONFIG_UART_2 |
---|
72 | static bool lpc176x_uart2_probe(rtems_termios_device_context *ctx) |
---|
73 | { |
---|
74 | (void)ctx; |
---|
75 | |
---|
76 | lpc176x_module_enable( LPC176X_MODULE_UART_2, LPC176X_MODULE_PCLK_DEFAULT ); |
---|
77 | |
---|
78 | lpc176x_pin_select( LPC176X_PIN_UART_2_TXD, LPC176X_PIN_FUNCTION_01 ); |
---|
79 | lpc176x_pin_select( LPC176X_PIN_UART_2_RXD, LPC176X_PIN_FUNCTION_01 ); |
---|
80 | |
---|
81 | return true; |
---|
82 | } |
---|
83 | #endif |
---|
84 | |
---|
85 | #ifdef LPC176X_CONFIG_UART_3 |
---|
86 | static bool lpc176x_uart3_probe(rtems_termios_device_context *ctx) |
---|
87 | { |
---|
88 | (void)ctx; |
---|
89 | |
---|
90 | lpc176x_module_enable( LPC176X_MODULE_UART_3, LPC176X_MODULE_PCLK_DEFAULT ); |
---|
91 | |
---|
92 | lpc176x_pin_select( LPC176X_PIN_UART_3_TXD, LPC176X_PIN_FUNCTION_10 ); |
---|
93 | lpc176x_pin_select( LPC176X_PIN_UART_3_RXD, LPC176X_PIN_FUNCTION_10 ); |
---|
94 | |
---|
95 | return true; |
---|
96 | } |
---|
97 | #endif |
---|
98 | |
---|
99 | #ifdef LPC176X_CONFIG_CONSOLE |
---|
100 | static ns16550_context lpc176x_uart_context_0 = { |
---|
101 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"), |
---|
102 | .get_reg = lpc176x_uart_get_register, |
---|
103 | .set_reg = lpc176x_uart_set_register, |
---|
104 | .port = UART0_BASE_ADDR, |
---|
105 | .irq = LPC176X_IRQ_UART_0, |
---|
106 | .clock = LPC176X_PCLK, |
---|
107 | .initial_baud = LPC176X_UART_BAUD, |
---|
108 | .has_fractional_divider_register = true |
---|
109 | }; |
---|
110 | #endif |
---|
111 | |
---|
112 | #ifdef LPC176X_CONFIG_UART_1 |
---|
113 | static ns16550_context lpc176x_uart_context_1 = { |
---|
114 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"), |
---|
115 | .get_reg = lpc176x_uart_get_register, |
---|
116 | .set_reg = lpc176x_uart_set_register, |
---|
117 | .port = UART1_BASE_ADDR, |
---|
118 | .irq = LPC176X_IRQ_UART_1, |
---|
119 | .clock = LPC176X_PCLK, |
---|
120 | .initial_baud = LPC176X_UART_BAUD, |
---|
121 | .has_fractional_divider_register = true |
---|
122 | }; |
---|
123 | #endif |
---|
124 | |
---|
125 | #ifdef LPC176X_CONFIG_UART_2 |
---|
126 | static ns16550_context lpc176x_uart_context_2 = { |
---|
127 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"), |
---|
128 | .get_reg = lpc176x_uart_get_register, |
---|
129 | .set_reg = lpc176x_uart_set_register, |
---|
130 | .port = UART2_BASE_ADDR, |
---|
131 | .irq = LPC176X_IRQ_UART_2, |
---|
132 | .clock = LPC176X_PCLK, |
---|
133 | .initial_baud = LPC176X_UART_BAUD, |
---|
134 | .has_fractional_divider_register = true |
---|
135 | }; |
---|
136 | #endif |
---|
137 | |
---|
138 | #ifdef LPC176X_CONFIG_UART_3 |
---|
139 | static ns16550_context lpc176x_uart_context_3 = { |
---|
140 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"), |
---|
141 | .get_reg = lpc176x_uart_get_register, |
---|
142 | .set_reg = lpc176x_uart_set_register, |
---|
143 | .port = UART3_BASE_ADDR, |
---|
144 | .irq = LPC176X_IRQ_UART_3, |
---|
145 | .clock = LPC176X_PCLK, |
---|
146 | .initial_baud = LPC176X_UART_BAUD, |
---|
147 | .has_fractional_divider_register = true |
---|
148 | }; |
---|
149 | #endif |
---|
150 | |
---|
151 | const console_device console_device_table[] = { |
---|
152 | #ifdef LPC176X_CONFIG_CONSOLE |
---|
153 | { |
---|
154 | .device_file = "/dev/ttyS0", |
---|
155 | .probe = console_device_probe_default, |
---|
156 | .handler = &ns16550_handler_interrupt, |
---|
157 | .context = &lpc176x_uart_context_0.base |
---|
158 | }, |
---|
159 | #endif |
---|
160 | #ifdef LPC176X_CONFIG_UART_1 |
---|
161 | { |
---|
162 | .device_file = "/dev/ttyS1", |
---|
163 | .probe = lpc176x_uart1_probe, |
---|
164 | .handler = &ns16550_handler_interrupt, |
---|
165 | .context = &lpc176x_uart_context_1.base |
---|
166 | }, |
---|
167 | #endif |
---|
168 | #ifdef LPC176X_CONFIG_UART_2 |
---|
169 | { |
---|
170 | .device_file = "/dev/ttyS2", |
---|
171 | .probe = lpc176x_uart2_probe, |
---|
172 | .handler = &ns16550_handler_interrupt, |
---|
173 | .context = &lpc176x_uart_context_2.base |
---|
174 | }, |
---|
175 | #endif |
---|
176 | #ifdef LPC176X_CONFIG_UART_3 |
---|
177 | { |
---|
178 | .device_file = "/dev/ttyS3", |
---|
179 | .probe = lpc176x_uart3_probe, |
---|
180 | .handler = &ns16550_handler_interrupt, |
---|
181 | .context = &lpc176x_uart_context_3.base |
---|
182 | }, |
---|
183 | #endif |
---|
184 | }; |
---|
185 | |
---|
186 | const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table); |
---|