source: rtems/c/src/lib/libbsp/arm/beagle/console/console-config.c @ 0afac6a

4.115
Last change on this file since 0afac6a was d4edbdbc, checked in by Sebastian Huber <sebastian.huber@…>, on 03/20/15 at 13:09:26

Replace www.rtems.com with www.rtems.org

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_beagle
5 *
6 * @brief Console configuration.
7 */
8
9/*
10 * Copyright (c) 2012 Claas Ziemke. All rights reserved.
11 *
12 *  Claas Ziemke
13 *  Kernerstrasse 11
14 *  70182 Stuttgart
15 *  Germany
16 *  <claas.ziemke@gmx.net>
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.org/license/LICENSE.
21 *
22 * Modified by Ben Gras <beng@shrike-systems.com> to make
23 * interrupt-driven uart i/o work for beagleboards; beaglebone support added.
24 */
25
26#include <libchip/serial.h>
27#include <libchip/ns16550.h>
28
29#include <bsp.h>
30#include <bsp/irq.h>
31#include <bsp/uart-output-char.h>
32
33#define CONSOLE_UART_THR (*(volatile unsigned int *)BSP_CONSOLE_UART_BASE)
34#define CONSOLE_UART_RHR (*(volatile unsigned int *)BSP_CONSOLE_UART_BASE)
35#define CONSOLE_UART_LSR (*(volatile unsigned int *)(BSP_CONSOLE_UART_BASE+0x14))
36#define CONSOLE_SYSC (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + 0x54))
37#define CONSOLE_SYSS (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + 0x58))
38
39#define TX_FIFO_E (1<<5)
40#define RX_FIFO_E (1<<0)
41
42static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t i)
43{
44  uint8_t v;
45  volatile uint32_t *reg_r = (volatile uint32_t *) addr + i;
46
47  if(reg_r == (uint32_t*) BSP_CONSOLE_UART_BASE /* reading RHR */ ) {
48    /* check there should be anything in the RHR before accessing it */
49    if(!(CONSOLE_UART_LSR & 0x01)) {
50      return 0;
51    }
52  }
53
54  v = (uint8_t) *reg_r;
55
56  return v;
57}
58
59static void beagle_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
60{
61  volatile uint32_t *reg = (volatile uint32_t *) addr;
62
63  reg [i] = val;
64}
65
66console_tbl Console_Configuration_Ports [] = {
67    {
68      .sDeviceName = "/dev/ttyS0",
69      .deviceType = SERIAL_NS16550,
70#if CONSOLE_POLLED      /* option to facilitate running the tests */
71      .pDeviceFns = &ns16550_fns_polled,
72#else
73      .pDeviceFns = &ns16550_fns,
74#endif
75      .ulMargin = 16,
76      .ulHysteresis = 8,
77      .pDeviceParams = (void *) CONSOLE_BAUD,
78      .ulCtrlPort1 = BSP_CONSOLE_UART_BASE,
79      .ulDataPort = BSP_CONSOLE_UART_BASE,
80      .ulIntVector = BSP_CONSOLE_UART_IRQ,
81      .getRegister = beagle_uart_get_register,
82      .setRegister = beagle_uart_set_register,
83      .ulClock = UART_CLOCK,  /* 48MHz base clock */
84    },
85};
86
87unsigned long Console_Configuration_Count = 1;
88
89static int init_needed = 1; // don't rely on bss being 0
90
91static void beagle_console_init(void)
92{
93  if(init_needed) {
94    const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD;
95    CONSOLE_SYSC = 2;
96    while ((CONSOLE_SYSS & 1) == 0)
97      ;
98    if ((CONSOLE_LSR & (CONSOLE_LSR_THRE | CONSOLE_LSR_TEMT)) == CONSOLE_LSR_THRE) {
99      CONSOLE_LCR = 0x83;
100      CONSOLE_DLL = div;
101      CONSOLE_DLM = (div >> 8) & 0xff;
102      CONSOLE_LCR = 0x03;
103      CONSOLE_ACR = 0x00;
104    }
105
106    while ((CONSOLE_LSR & CONSOLE_LSR_TEMT) == 0)
107      ;
108
109    CONSOLE_LCR = 0x80 | 0x03;
110    CONSOLE_DLL = 0x00;
111    CONSOLE_DLM = 0x00;
112    CONSOLE_LCR = 0x03;
113    CONSOLE_MCR = 0x03;
114    CONSOLE_FCR = 0x07;
115    CONSOLE_LCR = 0x83;
116    CONSOLE_DLL = div;
117    CONSOLE_DLM = (div >> 8) & 0xff;
118    CONSOLE_LCR = 0x03;
119    CONSOLE_ACR = 0x00;
120    init_needed = 0;
121  }
122}
123
124#define CONSOLE_THR8 (*(volatile uint8_t *) (BSP_CONSOLE_UART_BASE + 0x00))
125
126static void uart_write_polled( char c )
127{
128  if(init_needed) beagle_console_init();
129
130  while( ( CONSOLE_LSR & TX_FIFO_E ) == 0 )
131    ;
132  CONSOLE_THR8 = c;
133}
134
135static void _BSP_put_char( char c ) {
136   uart_write_polled( c );
137   if (c == '\n') {
138       uart_write_polled('\r');
139   }
140}
141
142static int _BSP_get_char(void)
143{
144  if ((CONSOLE_LSR & CONSOLE_LSR_RDR) != 0) {
145    return CONSOLE_RBR;
146  } else {
147    return -1;
148  }
149}
150
151BSP_output_char_function_type BSP_output_char = _BSP_put_char;
152
153BSP_polling_getchar_function_type BSP_poll_char = _BSP_get_char;
Note: See TracBrowser for help on using the repository browser.