[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 |
---|
| 20 | * http://www.rtems.com/license/LICENSE. |
---|
| 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 | |
---|
| 65 | #ifdef LPC176X_CONFIG_CONSOLE |
---|
[6ec438e] | 66 | static ns16550_context lpc176x_uart_context_0 = { |
---|
| 67 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"), |
---|
| 68 | .get_reg = lpc176x_uart_get_register, |
---|
| 69 | .set_reg = lpc176x_uart_set_register, |
---|
| 70 | .port = UART0_BASE_ADDR, |
---|
| 71 | .irq = LPC176X_IRQ_UART_0, |
---|
| 72 | .clock = LPC176X_PCLK, |
---|
| 73 | .initial_baud = LPC176X_UART_BAUD, |
---|
| 74 | .has_fractional_divider_register = true |
---|
| 75 | }; |
---|
[19260fb] | 76 | #endif |
---|
[6ec438e] | 77 | |
---|
[19260fb] | 78 | #ifdef LPC176X_CONFIG_UART_1 |
---|
[6ec438e] | 79 | static ns16550_context lpc176x_uart_context_1 = { |
---|
| 80 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"), |
---|
| 81 | .get_reg = lpc176x_uart_get_register, |
---|
| 82 | .set_reg = lpc176x_uart_set_register, |
---|
| 83 | .port = UART1_BASE_ADDR, |
---|
| 84 | .irq = LPC176X_IRQ_UART_1, |
---|
| 85 | .clock = LPC176X_PCLK, |
---|
| 86 | .initial_baud = LPC176X_UART_BAUD, |
---|
| 87 | .has_fractional_divider_register = true |
---|
| 88 | }; |
---|
[19260fb] | 89 | #endif |
---|
[6ec438e] | 90 | |
---|
[19260fb] | 91 | #ifdef LPC176X_CONFIG_UART_2 |
---|
[6ec438e] | 92 | static ns16550_context lpc176x_uart_context_2 = { |
---|
| 93 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"), |
---|
| 94 | .get_reg = lpc176x_uart_get_register, |
---|
| 95 | .set_reg = lpc176x_uart_set_register, |
---|
| 96 | .port = UART2_BASE_ADDR, |
---|
| 97 | .irq = LPC176X_IRQ_UART_2, |
---|
| 98 | .clock = LPC176X_PCLK, |
---|
| 99 | .initial_baud = LPC176X_UART_BAUD, |
---|
| 100 | .has_fractional_divider_register = true |
---|
| 101 | }; |
---|
[19260fb] | 102 | #endif |
---|
[6ec438e] | 103 | |
---|
[19260fb] | 104 | #ifdef LPC176X_CONFIG_UART_3 |
---|
[6ec438e] | 105 | static ns16550_context lpc176x_uart_context_3 = { |
---|
| 106 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"), |
---|
| 107 | .get_reg = lpc176x_uart_get_register, |
---|
| 108 | .set_reg = lpc176x_uart_set_register, |
---|
| 109 | .port = UART3_BASE_ADDR, |
---|
| 110 | .irq = LPC176X_IRQ_UART_3, |
---|
| 111 | .clock = LPC176X_PCLK, |
---|
| 112 | .initial_baud = LPC176X_UART_BAUD, |
---|
| 113 | .has_fractional_divider_register = true |
---|
[19260fb] | 114 | }; |
---|
[6ec438e] | 115 | #endif |
---|
[19260fb] | 116 | |
---|
[6ec438e] | 117 | const console_device console_device_table[] = { |
---|
| 118 | #ifdef LPC176X_CONFIG_CONSOLE |
---|
| 119 | { |
---|
| 120 | .device_file = "/dev/ttyS0", |
---|
| 121 | .probe = console_device_probe_default, |
---|
| 122 | .handler = &ns16550_handler_interrupt, |
---|
| 123 | .context = &lpc176x_uart_context_0.base |
---|
| 124 | }, |
---|
| 125 | #endif |
---|
| 126 | #ifdef LPC176X_CONFIG_UART_1 |
---|
| 127 | { |
---|
| 128 | .device_file = "/dev/ttyS1", |
---|
| 129 | .probe = ns16550_probe, |
---|
| 130 | .handler = &ns16550_handler_interrupt, |
---|
| 131 | .context = &lpc176x_uart_context_1.base |
---|
| 132 | }, |
---|
| 133 | #endif |
---|
| 134 | #ifdef LPC176X_CONFIG_UART_2 |
---|
| 135 | { |
---|
| 136 | .device_file = "/dev/ttyS2", |
---|
| 137 | .probe = ns16550_probe, |
---|
| 138 | .handler = &ns16550_handler_interrupt, |
---|
| 139 | .context = &lpc176x_uart_context_2.base |
---|
| 140 | }, |
---|
| 141 | #endif |
---|
| 142 | #ifdef LPC176X_CONFIG_UART_3 |
---|
| 143 | { |
---|
| 144 | .device_file = "/dev/ttyS3", |
---|
| 145 | .probe = ns16550_probe, |
---|
| 146 | .handler = &ns16550_handler_interrupt, |
---|
| 147 | .context = &lpc176x_uart_context_3.base |
---|
| 148 | }, |
---|
| 149 | #endif |
---|
| 150 | }; |
---|
[19260fb] | 151 | |
---|
[6ec438e] | 152 | const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table); |
---|