source: rtems/c/src/lib/libbsp/arm/lpc176x/console/console-config.c @ 1c0663b

4.115
Last change on this file since 1c0663b was e836c7c1, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 21, 2015 at 7:40:42 PM

lpc176x/console/console-config.c: Conditionalize code to avoid unused warnings

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc176x
5 *
6 * @brief Console configuration.
7 */
8
9/*
10 * Copyright (c) 2008-2014 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
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
23#include <libchip/ns16550.h>
24
25#include <bsp.h>
26#include <bsp/io.h>
27#include <bsp/irq.h>
28#include <bsp/console-termios.h>
29
30/**
31 * @brief Gets the uart register according to the current address.
32 *
33 * @param  addr Register address.
34 * @param  i Index register.
35 * @return  Uart register.
36 */
37static inline uint8_t lpc176x_uart_get_register(
38  const uintptr_t addr,
39  const uint8_t   i
40)
41{
42  volatile uint32_t *reg = (volatile uint32_t *) addr;
43
44  return (uint8_t) reg[ i ];
45}
46
47/**
48 * @brief Sets the uart register address according to the value passed.
49 *
50 * @param  addr Register address.
51 * @param  i Index register.
52 * @param val Value to set.
53 */
54static inline void lpc176x_uart_set_register(
55  const uintptr_t addr,
56  const uint8_t   i,
57  const uint8_t   val
58)
59{
60  volatile uint32_t *reg = (volatile uint32_t *) addr;
61
62  reg[ i ] = val;
63}
64
65static bool lpc176x_uart1_probe(rtems_termios_device_context *ctx)
66{
67  (void)ctx;
68
69  lpc176x_module_enable( LPC176X_MODULE_UART_1, LPC176X_MODULE_PCLK_DEFAULT );
70
71  lpc176x_pin_select( LPC176X_PIN_UART_1_TXD, LPC176X_PIN_FUNCTION_01 );
72  lpc176x_pin_select( LPC176X_PIN_UART_1_RXD, LPC176X_PIN_FUNCTION_01 );
73
74  return true;
75}
76
77#ifdef LPC176X_CONFIG_UART_2
78static bool lpc176x_uart2_probe(rtems_termios_device_context *ctx)
79{
80  (void)ctx;
81
82  lpc176x_module_enable( LPC176X_MODULE_UART_2, LPC176X_MODULE_PCLK_DEFAULT );
83
84  lpc176x_pin_select( LPC176X_PIN_UART_2_TXD, LPC176X_PIN_FUNCTION_01 );
85  lpc176x_pin_select( LPC176X_PIN_UART_2_RXD, LPC176X_PIN_FUNCTION_01 );
86
87  return true;
88}
89#endif
90
91#ifdef LPC176X_CONFIG_UART_3
92static bool lpc176x_uart3_probe(rtems_termios_device_context *ctx)
93{
94  (void)ctx;
95
96  lpc176x_module_enable( LPC176X_MODULE_UART_3, LPC176X_MODULE_PCLK_DEFAULT );
97
98  lpc176x_pin_select( LPC176X_PIN_UART_3_TXD, LPC176X_PIN_FUNCTION_10 );
99  lpc176x_pin_select( LPC176X_PIN_UART_3_RXD, LPC176X_PIN_FUNCTION_10 );
100
101  return true;
102}
103#endif
104
105#ifdef LPC176X_CONFIG_CONSOLE
106static ns16550_context lpc176x_uart_context_0 = {
107  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"),
108  .get_reg = lpc176x_uart_get_register,
109  .set_reg = lpc176x_uart_set_register,
110  .port = UART0_BASE_ADDR,
111  .irq = LPC176X_IRQ_UART_0,
112  .clock = LPC176X_PCLK,
113  .initial_baud = LPC176X_UART_BAUD,
114  .has_fractional_divider_register = true
115};
116#endif
117
118#ifdef LPC176X_CONFIG_UART_1
119static ns16550_context lpc176x_uart_context_1 = {
120  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
121  .get_reg = lpc176x_uart_get_register,
122  .set_reg = lpc176x_uart_set_register,
123  .port = UART1_BASE_ADDR,
124  .irq = LPC176X_IRQ_UART_1,
125  .clock = LPC176X_PCLK,
126  .initial_baud = LPC176X_UART_BAUD,
127  .has_fractional_divider_register = true
128};
129#endif
130
131#ifdef LPC176X_CONFIG_UART_2
132static ns16550_context lpc176x_uart_context_2 = {
133  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"),
134  .get_reg = lpc176x_uart_get_register,
135  .set_reg = lpc176x_uart_set_register,
136  .port = UART2_BASE_ADDR,
137  .irq = LPC176X_IRQ_UART_2,
138  .clock = LPC176X_PCLK,
139  .initial_baud = LPC176X_UART_BAUD,
140  .has_fractional_divider_register = true
141};
142#endif
143
144#ifdef LPC176X_CONFIG_UART_3
145static ns16550_context lpc176x_uart_context_3 = {
146  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"),
147  .get_reg = lpc176x_uart_get_register,
148  .set_reg = lpc176x_uart_set_register,
149  .port = UART3_BASE_ADDR,
150  .irq = LPC176X_IRQ_UART_3,
151  .clock = LPC176X_PCLK,
152  .initial_baud = LPC176X_UART_BAUD,
153  .has_fractional_divider_register = true
154};
155#endif
156
157const console_device console_device_table[] = {
158  #ifdef LPC176X_CONFIG_CONSOLE
159    {
160      .device_file = "/dev/ttyS0",
161      .probe = console_device_probe_default,
162      .handler = &ns16550_handler_interrupt,
163      .context = &lpc176x_uart_context_0.base
164    },
165  #endif
166  #ifdef LPC176X_CONFIG_UART_1
167    {
168      .device_file = "/dev/ttyS1",
169      .probe = lpc176x_uart1_probe,
170      .handler = &ns16550_handler_interrupt,
171      .context = &lpc176x_uart_context_1.base
172    },
173  #endif
174  #ifdef LPC176X_CONFIG_UART_2
175    {
176      .device_file = "/dev/ttyS2",
177      .probe = lpc176x_uart2_probe,
178      .handler = &ns16550_handler_interrupt,
179      .context = &lpc176x_uart_context_2.base
180    },
181  #endif
182  #ifdef LPC176X_CONFIG_UART_3
183    {
184      .device_file = "/dev/ttyS3",
185      .probe = lpc176x_uart3_probe,
186      .handler = &ns16550_handler_interrupt,
187      .context = &lpc176x_uart_context_3.base
188    },
189  #endif
190};
191
192const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);
Note: See TracBrowser for help on using the repository browser.