source: rtems/bsps/arm/beagle/console/console-config.c @ d7d66d7

5
Last change on this file since d7d66d7 was d7d66d7, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/18 at 04:28:01

bsps: Move console drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

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