source: rtems/c/src/lib/libbsp/arm/altera-cyclone-v/console/console-config.c @ aae6c21

4.115
Last change on this file since aae6c21 was aae6c21, checked in by Sebastian Huber <sebastian.huber@…>, on 04/02/15 at 06:31:09

bsp/altera-cyclone-v: Fix define usage

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <libchip/ns16550.h>
16
17#include <bsp.h>
18#include <bsp/irq.h>
19#include <bsp/alt_clock_manager.h>
20#include <bsp/console-termios.h>
21#include "socal/alt_rstmgr.h"
22#include "socal/socal.h"
23#include "socal/alt_uart.h"
24#include "socal/hps.h"
25
26#ifdef BSP_USE_UART_INTERRUPTS
27  #define DEVICE_FNS &ns16550_handler_interrupt
28#else
29  #define DEVICE_FNS &ns16550_handler_polled
30#endif
31
32static uint8_t altera_cyclone_v_uart_get_register(uintptr_t addr, uint8_t i)
33{
34  volatile uint32_t *reg = (volatile uint32_t *) addr;
35
36  return (uint8_t) reg [i];
37}
38
39static void altera_cyclone_v_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
40{
41  volatile uint32_t *reg = (volatile uint32_t *) addr;
42
43  reg [i] = val;
44}
45
46static bool altera_cyclone_v_uart_probe(
47  rtems_termios_device_context *base,
48  uint32_t uart_set_mask
49)
50{
51  ns16550_context *ctx = (ns16550_context *) base;
52  bool            ret           = true;
53  uint32_t        ucr;
54  ALT_STATUS_CODE sc;
55  void*           location = (void *) ctx->port;
56
57  /* The ALT_CLK_L4_SP is required for all SoCFPGA UARTs.
58   * Check that it's enabled. */
59  if ( alt_clk_is_enabled(ALT_CLK_L4_SP) != ALT_E_TRUE ) {
60    ret = false;
61  }
62
63  if ( ret ) {
64    sc = alt_clk_freq_get(ALT_CLK_L4_SP, &ctx->clock);
65    if ( sc != ALT_E_SUCCESS ) {
66      ret = false;
67    }
68  }
69
70  if ( ret ) {
71    // Bring UART out of reset.
72    alt_clrbits_word(ALT_RSTMGR_PERMODRST_ADDR, uart_set_mask);
73
74    // Verify the UCR (UART Component Version)
75    ucr = alt_read_word( ALT_UART_UCV_ADDR( location ) );
76    if ( ucr != ALT_UART_UCV_UART_COMPONENT_VER_RESET ) {
77      ret = false;
78    }
79  }
80
81  if ( ret ) {
82    // Write SRR::UR (Shadow Reset Register :: UART Reset)
83    alt_write_word( ALT_UART_SRR_ADDR( location ), ALT_UART_SRR_UR_SET_MSK );
84
85    // Read the MSR to work around case:119085.
86    (void)alt_read_word( ALT_UART_MSR_ADDR( location ) );
87
88    ret = ns16550_probe( base );
89  }
90
91  return ret;
92}
93
94#ifdef CYCLONE_V_CONFIG_CONSOLE
95static bool altera_cyclone_v_uart_probe_0(rtems_termios_device_context *base)
96{
97  return altera_cyclone_v_uart_probe(base, ALT_RSTMGR_PERMODRST_UART0_SET_MSK);
98}
99
100static ns16550_context altera_cyclone_v_uart_context_0 = {
101  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"),
102  .get_reg = altera_cyclone_v_uart_get_register,
103  .set_reg = altera_cyclone_v_uart_set_register,
104  .port = (uintptr_t) ALT_UART0_ADDR,
105  .irq = ALT_INT_INTERRUPT_UART0,
106  .initial_baud = CYCLONE_V_UART_BAUD
107};
108#endif
109
110#ifdef CYCLONE_V_CONFIG_UART_1
111static bool altera_cyclone_v_uart_probe_1(rtems_termios_device_context *base)
112{
113  return altera_cyclone_v_uart_probe(base, ALT_RSTMGR_PERMODRST_UART1_SET_MSK);
114}
115
116static ns16550_context altera_cyclone_v_uart_context_1 = {
117  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
118  .get_reg = altera_cyclone_v_uart_get_register,
119  .set_reg = altera_cyclone_v_uart_set_register,
120  .port = (uintptr_t) ALT_UART1_ADDR,
121  .irq = ALT_INT_INTERRUPT_UART1,
122  .initial_baud = CYCLONE_V_UART_BAUD
123};
124#endif
125
126const console_device console_device_table[] = {
127  #ifdef CYCLONE_V_CONFIG_CONSOLE
128    {
129      .device_file = "/dev/ttyS0",
130      .probe = altera_cyclone_v_uart_probe_0,
131      .handler = DEVICE_FNS,
132      .context = &altera_cyclone_v_uart_context_0.base
133    },
134  #endif
135  #ifdef CYCLONE_V_CONFIG_UART_1
136    {
137      .device_file = "/dev/ttyS1",
138      .probe = altera_cyclone_v_uart_probe_1,
139      .handler = DEVICE_FNS,
140      .context = &altera_cyclone_v_uart_context_1.base
141    },
142  #endif
143};
144
145const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);
146
147static void output_char(char c)
148{
149  rtems_termios_device_context *ctx = console_device_table[0].context;
150
151  if (c == '\n') {
152    ns16550_polled_putchar( ctx, '\r' );
153  }
154
155  ns16550_polled_putchar( ctx, c );
156}
157
158BSP_output_char_function_type BSP_output_char = output_char;
159
160BSP_polling_getchar_function_type BSP_poll_char = NULL;
Note: See TracBrowser for help on using the repository browser.