1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSBSPsARMLPC176X |
---|
7 | * |
---|
8 | * @brief Console configuration. |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * Copyright (C) 2008, 2014 embedded brains GmbH & Co. KG |
---|
13 | * |
---|
14 | * Redistribution and use in source and binary forms, with or without |
---|
15 | * modification, are permitted provided that the following conditions |
---|
16 | * are met: |
---|
17 | * 1. Redistributions of source code must retain the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer. |
---|
19 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer in the |
---|
21 | * documentation and/or other materials provided with the distribution. |
---|
22 | * |
---|
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
33 | * POSSIBILITY OF SUCH DAMAGE. |
---|
34 | */ |
---|
35 | |
---|
36 | #include <libchip/ns16550.h> |
---|
37 | |
---|
38 | #include <bsp.h> |
---|
39 | #include <bsp/io.h> |
---|
40 | #include <bsp/irq.h> |
---|
41 | #include <bsp/console-termios.h> |
---|
42 | |
---|
43 | /** |
---|
44 | * @brief Gets the uart register according to the current address. |
---|
45 | * |
---|
46 | * @param addr Register address. |
---|
47 | * @param i Index register. |
---|
48 | * @return Uart register. |
---|
49 | */ |
---|
50 | static inline uint8_t lpc176x_uart_get_register( |
---|
51 | const uintptr_t addr, |
---|
52 | const uint8_t i |
---|
53 | ) |
---|
54 | { |
---|
55 | volatile uint32_t *reg = (volatile uint32_t *) addr; |
---|
56 | |
---|
57 | return (uint8_t) reg[ i ]; |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * @brief Sets the uart register address according to the value passed. |
---|
62 | * |
---|
63 | * @param addr Register address. |
---|
64 | * @param i Index register. |
---|
65 | * @param val Value to set. |
---|
66 | */ |
---|
67 | static inline void lpc176x_uart_set_register( |
---|
68 | const uintptr_t addr, |
---|
69 | const uint8_t i, |
---|
70 | const uint8_t val |
---|
71 | ) |
---|
72 | { |
---|
73 | volatile uint32_t *reg = (volatile uint32_t *) addr; |
---|
74 | |
---|
75 | reg[ i ] = val; |
---|
76 | } |
---|
77 | |
---|
78 | static bool lpc176x_uart1_probe(rtems_termios_device_context *ctx) |
---|
79 | { |
---|
80 | (void)ctx; |
---|
81 | |
---|
82 | lpc176x_module_enable( LPC176X_MODULE_UART_1, LPC176X_MODULE_PCLK_DEFAULT ); |
---|
83 | |
---|
84 | lpc176x_pin_select( LPC176X_PIN_UART_1_TXD, LPC176X_PIN_FUNCTION_01 ); |
---|
85 | lpc176x_pin_select( LPC176X_PIN_UART_1_RXD, LPC176X_PIN_FUNCTION_01 ); |
---|
86 | |
---|
87 | return true; |
---|
88 | } |
---|
89 | |
---|
90 | #ifdef LPC176X_CONFIG_UART_2 |
---|
91 | static bool lpc176x_uart2_probe(rtems_termios_device_context *ctx) |
---|
92 | { |
---|
93 | (void)ctx; |
---|
94 | |
---|
95 | lpc176x_module_enable( LPC176X_MODULE_UART_2, LPC176X_MODULE_PCLK_DEFAULT ); |
---|
96 | |
---|
97 | lpc176x_pin_select( LPC176X_PIN_UART_2_TXD, LPC176X_PIN_FUNCTION_01 ); |
---|
98 | lpc176x_pin_select( LPC176X_PIN_UART_2_RXD, LPC176X_PIN_FUNCTION_01 ); |
---|
99 | |
---|
100 | return true; |
---|
101 | } |
---|
102 | #endif |
---|
103 | |
---|
104 | #ifdef LPC176X_CONFIG_UART_3 |
---|
105 | static bool lpc176x_uart3_probe(rtems_termios_device_context *ctx) |
---|
106 | { |
---|
107 | (void)ctx; |
---|
108 | |
---|
109 | lpc176x_module_enable( LPC176X_MODULE_UART_3, LPC176X_MODULE_PCLK_DEFAULT ); |
---|
110 | |
---|
111 | lpc176x_pin_select( LPC176X_PIN_UART_3_TXD, LPC176X_PIN_FUNCTION_10 ); |
---|
112 | lpc176x_pin_select( LPC176X_PIN_UART_3_RXD, LPC176X_PIN_FUNCTION_10 ); |
---|
113 | |
---|
114 | return true; |
---|
115 | } |
---|
116 | #endif |
---|
117 | |
---|
118 | #ifdef LPC176X_CONFIG_CONSOLE |
---|
119 | static ns16550_context lpc176x_uart_context_0 = { |
---|
120 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"), |
---|
121 | .get_reg = lpc176x_uart_get_register, |
---|
122 | .set_reg = lpc176x_uart_set_register, |
---|
123 | .port = UART0_BASE_ADDR, |
---|
124 | .irq = LPC176X_IRQ_UART_0, |
---|
125 | .clock = LPC176X_PCLK, |
---|
126 | .initial_baud = LPC176X_UART_BAUD, |
---|
127 | .has_fractional_divider_register = true |
---|
128 | }; |
---|
129 | #endif |
---|
130 | |
---|
131 | #ifdef LPC176X_CONFIG_UART_1 |
---|
132 | static ns16550_context lpc176x_uart_context_1 = { |
---|
133 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"), |
---|
134 | .get_reg = lpc176x_uart_get_register, |
---|
135 | .set_reg = lpc176x_uart_set_register, |
---|
136 | .port = UART1_BASE_ADDR, |
---|
137 | .irq = LPC176X_IRQ_UART_1, |
---|
138 | .clock = LPC176X_PCLK, |
---|
139 | .initial_baud = LPC176X_UART_BAUD, |
---|
140 | .has_fractional_divider_register = true |
---|
141 | }; |
---|
142 | #endif |
---|
143 | |
---|
144 | #ifdef LPC176X_CONFIG_UART_2 |
---|
145 | static ns16550_context lpc176x_uart_context_2 = { |
---|
146 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"), |
---|
147 | .get_reg = lpc176x_uart_get_register, |
---|
148 | .set_reg = lpc176x_uart_set_register, |
---|
149 | .port = UART2_BASE_ADDR, |
---|
150 | .irq = LPC176X_IRQ_UART_2, |
---|
151 | .clock = LPC176X_PCLK, |
---|
152 | .initial_baud = LPC176X_UART_BAUD, |
---|
153 | .has_fractional_divider_register = true |
---|
154 | }; |
---|
155 | #endif |
---|
156 | |
---|
157 | #ifdef LPC176X_CONFIG_UART_3 |
---|
158 | static ns16550_context lpc176x_uart_context_3 = { |
---|
159 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"), |
---|
160 | .get_reg = lpc176x_uart_get_register, |
---|
161 | .set_reg = lpc176x_uart_set_register, |
---|
162 | .port = UART3_BASE_ADDR, |
---|
163 | .irq = LPC176X_IRQ_UART_3, |
---|
164 | .clock = LPC176X_PCLK, |
---|
165 | .initial_baud = LPC176X_UART_BAUD, |
---|
166 | .has_fractional_divider_register = true |
---|
167 | }; |
---|
168 | #endif |
---|
169 | |
---|
170 | const console_device console_device_table[] = { |
---|
171 | #ifdef LPC176X_CONFIG_CONSOLE |
---|
172 | { |
---|
173 | .device_file = "/dev/ttyS0", |
---|
174 | .probe = console_device_probe_default, |
---|
175 | .handler = &ns16550_handler_interrupt, |
---|
176 | .context = &lpc176x_uart_context_0.base |
---|
177 | }, |
---|
178 | #endif |
---|
179 | #ifdef LPC176X_CONFIG_UART_1 |
---|
180 | { |
---|
181 | .device_file = "/dev/ttyS1", |
---|
182 | .probe = lpc176x_uart1_probe, |
---|
183 | .handler = &ns16550_handler_interrupt, |
---|
184 | .context = &lpc176x_uart_context_1.base |
---|
185 | }, |
---|
186 | #endif |
---|
187 | #ifdef LPC176X_CONFIG_UART_2 |
---|
188 | { |
---|
189 | .device_file = "/dev/ttyS2", |
---|
190 | .probe = lpc176x_uart2_probe, |
---|
191 | .handler = &ns16550_handler_interrupt, |
---|
192 | .context = &lpc176x_uart_context_2.base |
---|
193 | }, |
---|
194 | #endif |
---|
195 | #ifdef LPC176X_CONFIG_UART_3 |
---|
196 | { |
---|
197 | .device_file = "/dev/ttyS3", |
---|
198 | .probe = lpc176x_uart3_probe, |
---|
199 | .handler = &ns16550_handler_interrupt, |
---|
200 | .context = &lpc176x_uart_context_3.base |
---|
201 | }, |
---|
202 | #endif |
---|
203 | }; |
---|
204 | |
---|
205 | const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table); |
---|