diff options
Diffstat (limited to 'c/src/lib/libbsp/arm/beagle/console/console-config.c')
-rw-r--r-- | c/src/lib/libbsp/arm/beagle/console/console-config.c | 254 |
1 files changed, 88 insertions, 166 deletions
diff --git a/c/src/lib/libbsp/arm/beagle/console/console-config.c b/c/src/lib/libbsp/arm/beagle/console/console-config.c index a9349e8425..63c7ba7feb 100644 --- a/c/src/lib/libbsp/arm/beagle/console/console-config.c +++ b/c/src/lib/libbsp/arm/beagle/console/console-config.c @@ -1,7 +1,7 @@ /** * @file * - * @ingroup beagle + * @ingroup arm_beagle * * @brief Console configuration. */ @@ -18,209 +18,120 @@ * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rtems.com/license/LICENSE. + * + * Modified by Ben Gras <beng@shrike-systems.com> to make + * interrupt-driven uart i/o work for beagleboards; beaglebone support added. */ #include <libchip/serial.h> #include <libchip/ns16550.h> #include <bsp.h> -#include <bsp/beagle.h> #include <bsp/irq.h> +#include <bsp/uart-output-char.h> + +#define CONSOLE_UART_THR (*(volatile unsigned int *)BSP_CONSOLE_UART_BASE) +#define CONSOLE_UART_RHR (*(volatile unsigned int *)BSP_CONSOLE_UART_BASE) +#define CONSOLE_UART_LSR (*(volatile unsigned int *)(BSP_CONSOLE_UART_BASE+0x14)) +#define CONSOLE_SYSC (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + 0x54)) +#define CONSOLE_SYSS (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + 0x58)) -#define UART3_THR (*(volatile unsigned int *)0x49020000) -#define UART3_RHR (*(volatile unsigned int *)0x49020000) -#define UART3_LSR (*(volatile unsigned int *)0x49020014) #define TX_FIFO_E (1<<5) #define RX_FIFO_E (1<<0) -static uint8_t beagle_uart_get_register(uint32_t addr, uint8_t i) +static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t i) { - volatile uint32_t *reg = (volatile uint32_t *) addr; + uint8_t v; + volatile uint32_t *reg_r = (volatile uint32_t *) addr + i; + + if(reg_r == (uint32_t*) BSP_CONSOLE_UART_BASE /* reading RHR */ ) { + /* check there should be anything in the RHR before accessing it */ + if(!(CONSOLE_UART_LSR & 0x01)) { + return 0; + } + } - return (uint8_t) reg [i]; + v = (uint8_t) *reg_r; + + return v; } -static void beagle_uart_set_register(uint32_t addr, uint8_t i, uint8_t val) +static void beagle_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val) { volatile uint32_t *reg = (volatile uint32_t *) addr; reg [i] = val; } -/* FIXME: Console selection */ - console_tbl Console_Configuration_Ports [] = { - #ifdef BEAGLE_CONFIG_U5CLK { - .sDeviceName = "/dev/ttyS5", + .sDeviceName = "/dev/ttyS0", .deviceType = SERIAL_NS16550, +#if CONSOLE_POLLED /* option to facilitate running the tests */ .pDeviceFns = &ns16550_fns_polled, - .deviceProbe = NULL, - .pDeviceFlow = NULL, - .ulMargin = 16, - .ulHysteresis = 8, - .pDeviceParams = (void *) 1, - .ulCtrlPort1 = BEAGLE_BASE_UART_5, - .ulCtrlPort2 = 0, - .ulDataPort = BEAGLE_BASE_UART_5, - .getRegister = beagle_uart_get_register, - .setRegister = beagle_uart_set_register, - .getData = NULL, - .setData = NULL, - .ulClock = 16, - .ulIntVector = BEAGLE_IRQ_UART_5 - }, - #endif - #ifdef BEAGLE_CONFIG_U3CLK - { - .sDeviceName = "/dev/ttyS3", - .deviceType = SERIAL_NS16550, - .pDeviceFns = &ns16550_fns, - .deviceProbe = NULL, - .pDeviceFlow = NULL, - .ulMargin = 16, - .ulHysteresis = 8, - .pDeviceParams = (void *) 1, - .ulCtrlPort1 = BEAGLE_BASE_UART_3, - .ulCtrlPort2 = 0, - .ulDataPort = BEAGLE_BASE_UART_3, - .getRegister = beagle_uart_get_register, - .setRegister = beagle_uart_set_register, - .getData = NULL, - .setData = NULL, - .ulClock = 16, - .ulIntVector = BEAGLE_IRQ_UART_3 - }, - #endif - #ifdef BEAGLE_CONFIG_U4CLK - { - .sDeviceName = "/dev/ttyS4", - .deviceType = SERIAL_NS16550, +#else .pDeviceFns = &ns16550_fns, - .deviceProbe = NULL, - .pDeviceFlow = NULL, +#endif .ulMargin = 16, .ulHysteresis = 8, - .pDeviceParams = (void *) 1, - .ulCtrlPort1 = BEAGLE_BASE_UART_4, - .ulCtrlPort2 = 0, - .ulDataPort = BEAGLE_BASE_UART_4, + .pDeviceParams = (void *) CONSOLE_BAUD, + .ulCtrlPort1 = BSP_CONSOLE_UART_BASE, + .ulDataPort = BSP_CONSOLE_UART_BASE, + .ulIntVector = BSP_CONSOLE_UART_IRQ, .getRegister = beagle_uart_get_register, .setRegister = beagle_uart_set_register, - .getData = NULL, - .setData = NULL, - .ulClock = 16, - .ulIntVector = BEAGLE_IRQ_UART_4 + .ulClock = UART_CLOCK, /* 48MHz base clock */ }, - #endif - #ifdef BEAGLE_CONFIG_U6CLK - { - .sDeviceName = "/dev/ttyS6", - .deviceType = SERIAL_NS16550, - .pDeviceFns = &ns16550_fns, - .deviceProbe = NULL, - .pDeviceFlow = NULL, - .ulMargin = 16, - .ulHysteresis = 8, - .pDeviceParams = (void *) 1, - .ulCtrlPort1 = BEAGLE_BASE_UART_6, - .ulCtrlPort2 = 0, - .ulDataPort = BEAGLE_BASE_UART_6, - .getRegister = beagle_uart_get_register, - .setRegister = beagle_uart_set_register, - .getData = NULL, - .setData = NULL, - .ulClock = 16, - .ulIntVector = BEAGLE_IRQ_UART_6 - }, - #endif - #ifdef BEAGLE_UART_1_BAUD - { - .sDeviceName = "/dev/ttyS1", - .deviceType = SERIAL_CUSTOM, - .pDeviceFns = &ns16550_fns, - .deviceProbe = NULL, - .pDeviceFlow = NULL, - .ulMargin = 16, - .ulHysteresis = 8, - .pDeviceParams = (void *) BEAGLE_UART_1_BAUD, - .ulCtrlPort1 = BEAGLE_BASE_UART_1, - .ulCtrlPort2 = 0, - .ulDataPort = 0, - .getRegister = NULL, - .setRegister = NULL, - .getData = NULL, - .setData = NULL, - .ulClock = 16, - .ulIntVector = BEAGLE_IRQ_UART_1 - }, - #endif - #ifdef BEAGLE_UART_2_BAUD - { - .sDeviceName = "/dev/ttyS2", - .deviceType = SERIAL_CUSTOM, - .pDeviceFns = &ns16550_fns, - .deviceProbe = NULL, - .pDeviceFlow = NULL, - .ulMargin = 16, - .ulHysteresis = 8, - .pDeviceParams = (void *) BEAGLE_UART_2_BAUD, - .ulCtrlPort1 = BEAGLE_BASE_UART_2, - .ulCtrlPort2 = 0, - .ulDataPort = 0, - .getRegister = NULL, - .setRegister = NULL, - .getData = NULL, - .setData = NULL, - .ulClock = 16, - .ulIntVector = BEAGLE_IRQ_UART_2 - }, - #endif - #ifdef BEAGLE_UART_7_BAUD - { - .sDeviceName = "/dev/ttyS7", - .deviceType = SERIAL_CUSTOM, - .pDeviceFns = &ns16550_fns, - .deviceProbe = NULL, - .pDeviceFlow = NULL, - .ulMargin = 16, - .ulHysteresis = 8, - .pDeviceParams = (void *) BEAGLE_UART_7_BAUD, - .ulCtrlPort1 = BEAGLE_BASE_UART_7, - .ulCtrlPort2 = 0, - .ulDataPort = 0, - .getRegister = NULL, - .setRegister = NULL, - .getData = NULL, - .setData = NULL, - .ulClock = 16, - .ulIntVector = BEAGLE_IRQ_UART_7 - }, - #endif }; -#define BEAGLE_UART_COUNT \ - (sizeof(Console_Configuration_Ports) / \ - sizeof(Console_Configuration_Ports [0])) +unsigned long Console_Configuration_Count = 1; -unsigned long Console_Configuration_Count = BEAGLE_UART_COUNT; +static int init_needed = 1; // don't rely on bss being 0 -static void uart_write_polled( char c ) { - // wait until TX-Buffer is empty - while( ( UART3_LSR & TX_FIFO_E ) == 0 ) - ; - - // send character - UART3_THR = c; - return c; +static void beagle_console_init(void) +{ + if(init_needed) { + const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD; + CONSOLE_SYSC = 2; + while ((CONSOLE_SYSS & 1) == 0) + ; + if ((CONSOLE_LSR & (CONSOLE_LSR_THRE | CONSOLE_LSR_TEMT)) == CONSOLE_LSR_THRE) { + CONSOLE_LCR = 0x83; + CONSOLE_DLL = div; + CONSOLE_DLM = (div >> 8) & 0xff; + CONSOLE_LCR = 0x03; + CONSOLE_ACR = 0x00; + } + + while ((CONSOLE_LSR & CONSOLE_LSR_TEMT) == 0) + ; + + CONSOLE_LCR = 0x80 | 0x03; + CONSOLE_DLL = 0x00; + CONSOLE_DLM = 0x00; + CONSOLE_LCR = 0x03; + CONSOLE_MCR = 0x03; + CONSOLE_FCR = 0x07; + CONSOLE_LCR = 0x83; + CONSOLE_DLL = div; + CONSOLE_DLM = (div >> 8) & 0xff; + CONSOLE_LCR = 0x03; + CONSOLE_ACR = 0x00; + init_needed = 0; + } } +#define CONSOLE_THR8 (*(volatile uint8_t *) (BSP_CONSOLE_UART_BASE + 0x00)) + +static void uart_write_polled( char c ) +{ + if(init_needed) beagle_console_init(); + + while( ( CONSOLE_LSR & TX_FIFO_E ) == 0 ) + ; + CONSOLE_THR8 = c; +} -/* -* Write a character to the console. This is used by printk() and -* maybe other low level functions. It should not use interrupts or any -* RTEMS system calls. It needs to be very simple -*/ static void _BSP_put_char( char c ) { uart_write_polled( c ); if (c == '\n') { @@ -228,4 +139,15 @@ static void _BSP_put_char( char c ) { } } +static int _BSP_get_char(void) +{ + if ((CONSOLE_LSR & CONSOLE_LSR_RDR) != 0) { + return CONSOLE_RBR; + } else { + return -1; + } +} + BSP_output_char_function_type BSP_output_char = _BSP_put_char; + +BSP_polling_getchar_function_type BSP_poll_char = _BSP_get_char; |