summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/beagle/console
diff options
context:
space:
mode:
authorBen Gras <beng@shrike-systems.com>2014-11-03 19:53:40 +0100
committerJoel Sherrill <joel.sherrill@oarcorp.com>2014-11-03 14:19:47 -0600
commit53dd6d6130c870d12351d8ca75e4ac9dcc834c86 (patch)
tree022804b833f8fdb47a15ab8940743f91726776b5 /c/src/lib/libbsp/arm/beagle/console
parentAdded BeagleBoard BSP (diff)
downloadrtems-53dd6d6130c870d12351d8ca75e4ac9dcc834c86.tar.bz2
BSP for several Beagle products
Specifically the beagleboard, beagleboard xM, beaglebone, beaglebone black. More info on these targets: http://www.beagleboard.org/ This commit forms a basic BSP by combining Claas's work with . new clock and irq code and definitions for beagle targets (beagleboard and beaglebones), mostly reused from the Minix codebase, thus making irqs, ticks and non-polled console mode work too . new timer code for ns timing with high timer resolution, 24MHz on the AM335X and 13MHz on the DM37XX . select the console uart based on target at configure time . removing all the lpc32xx-specific macros and code and other unused code and definitions that the beagle bsp was based on . re-using some standard functions instead of lpc32xx versions . fixed some whitespace problem in preinstall.am . fixed some compile warnings . configure MMU: set 1MB sections directly in the TTBR, just to show the difference between cacheable RAM and non-cacheable device memory and invalid ranges; this lets us turn on caches and not rely on boot loader MMU configuration. Verified to work when MMU is initially either on or off when RTEMS gets control. Thanks for testing, commentary, improvements and fixes to Chris Johns, Brandon Matthews, Matt Carberry, Romain Bornet, AZ technology and others. Signed-Off-By: Ben Gras <beng@shrike-systems.com>
Diffstat (limited to 'c/src/lib/libbsp/arm/beagle/console')
-rw-r--r--c/src/lib/libbsp/arm/beagle/console/console-config.c254
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;