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