[8a54204] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Console configuration. |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | /* |
---|
[6ec438e] | 8 | * Copyright (c) 2008-2014 embedded brains GmbH. All rights reserved. |
---|
[8a54204] | 9 | * |
---|
| 10 | * embedded brains GmbH |
---|
[6ec438e] | 11 | * Dornierstr. 4 |
---|
[8a54204] | 12 | * 82178 Puchheim |
---|
| 13 | * Germany |
---|
| 14 | * <rtems@embedded-brains.de> |
---|
| 15 | * |
---|
| 16 | * The license and distribution terms for this file may be |
---|
| 17 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 18 | * http://www.rtems.org/license/LICENSE. |
---|
[8a54204] | 19 | */ |
---|
| 20 | |
---|
| 21 | #include <rtems/bspIo.h> |
---|
| 22 | |
---|
| 23 | #include <libchip/ns16550.h> |
---|
| 24 | |
---|
| 25 | #include <mpc83xx/mpc83xx.h> |
---|
| 26 | |
---|
[6ec438e] | 27 | #include <bsp.h> |
---|
[8a54204] | 28 | #include <bsp/irq.h> |
---|
[6ec438e] | 29 | #include <bsp/console-termios.h> |
---|
[8a54204] | 30 | |
---|
| 31 | #ifdef BSP_USE_UART_INTERRUPTS |
---|
[6ec438e] | 32 | #define DEVICE_FNS &ns16550_handler_interrupt |
---|
[8a54204] | 33 | #else |
---|
[6ec438e] | 34 | #define DEVICE_FNS &ns16550_handler_polled |
---|
[8a54204] | 35 | #endif |
---|
| 36 | |
---|
[6ec438e] | 37 | static uint8_t gen83xx_console_get_register(uintptr_t addr, uint8_t i) |
---|
[8a54204] | 38 | { |
---|
| 39 | volatile uint8_t *reg = (volatile uint8_t *) addr; |
---|
| 40 | |
---|
| 41 | return reg [i]; |
---|
| 42 | } |
---|
| 43 | |
---|
[6ec438e] | 44 | static void gen83xx_console_set_register(uintptr_t addr, uint8_t i, uint8_t val) |
---|
[8a54204] | 45 | { |
---|
| 46 | volatile uint8_t *reg = (volatile uint8_t *) addr; |
---|
| 47 | |
---|
[6ec438e] | 48 | reg [i] = val; |
---|
[8a54204] | 49 | } |
---|
| 50 | |
---|
[6ec438e] | 51 | static ns16550_context gen83xx_uart_context_0 = { |
---|
| 52 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"), |
---|
| 53 | .get_reg = gen83xx_console_get_register, |
---|
| 54 | .set_reg = gen83xx_console_set_register, |
---|
| 55 | .port = (uintptr_t) &mpc83xx.duart[0], |
---|
[7a752161] | 56 | #if MPC83XX_CHIP_TYPE / 10 == 830 |
---|
[6ec438e] | 57 | .irq = BSP_IPIC_IRQ_UART, |
---|
[7a752161] | 58 | #else |
---|
[6ec438e] | 59 | .irq = BSP_IPIC_IRQ_UART1, |
---|
[7a752161] | 60 | #endif |
---|
[6ec438e] | 61 | .initial_baud = BSP_CONSOLE_BAUD |
---|
| 62 | }; |
---|
| 63 | |
---|
[8a54204] | 64 | #ifdef BSP_USE_UART2 |
---|
[6ec438e] | 65 | static ns16550_context gen83xx_uart_context_1 = { |
---|
| 66 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"), |
---|
| 67 | .get_reg = gen83xx_console_get_register, |
---|
| 68 | .set_reg = gen83xx_console_set_register, |
---|
| 69 | .port = (uintptr_t) &mpc83xx.duart[1], |
---|
[7a752161] | 70 | #if MPC83XX_CHIP_TYPE / 10 == 830 |
---|
[6ec438e] | 71 | .irq = BSP_IPIC_IRQ_UART, |
---|
[7a752161] | 72 | #else |
---|
[6ec438e] | 73 | .irq = BSP_IPIC_IRQ_UART2, |
---|
[7a752161] | 74 | #endif |
---|
[6ec438e] | 75 | .initial_baud = BSP_CONSOLE_BAUD |
---|
| 76 | }; |
---|
| 77 | #endif |
---|
| 78 | |
---|
| 79 | const console_device console_device_table[] = { |
---|
| 80 | { |
---|
| 81 | .device_file = "/dev/ttyS0", |
---|
| 82 | .probe = ns16550_probe, |
---|
| 83 | .handler = DEVICE_FNS, |
---|
| 84 | .context = &gen83xx_uart_context_0.base |
---|
| 85 | } |
---|
| 86 | #ifdef BSP_USE_UART2 |
---|
| 87 | , { |
---|
| 88 | .device_file = "/dev/ttyS1", |
---|
| 89 | .probe = ns16550_probe, |
---|
| 90 | .handler = DEVICE_FNS, |
---|
| 91 | .context = &gen83xx_uart_context_1.base |
---|
[8a54204] | 92 | } |
---|
| 93 | #endif |
---|
| 94 | }; |
---|
| 95 | |
---|
[6ec438e] | 96 | const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table); |
---|
| 97 | |
---|
[8a54204] | 98 | static void gen83xx_output_char(char c) |
---|
| 99 | { |
---|
[6ec438e] | 100 | rtems_termios_device_context *ctx = console_device_table[0].context; |
---|
| 101 | |
---|
| 102 | ns16550_polled_putchar(ctx, c); |
---|
[8a54204] | 103 | } |
---|
| 104 | |
---|
[6ec438e] | 105 | BSP_output_char_function_type BSP_output_char = gen83xx_output_char; |
---|
[8a54204] | 106 | |
---|
| 107 | BSP_polling_getchar_function_type BSP_poll_char = NULL; |
---|