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

4.115
Last change on this file since c3803167 was 7b35a36, checked in by Martin Galvan <martin.galvan@…>, on 03/11/15 at 19:57:23

Add CAN, PWM, ADC and UART1/2/3 support to the LPC176x BSP.

This patch adds support for the following devices to the LPC176x BSP:

  • CAN
  • PWM
  • ADC

It also adds the probe routines for UART1/2/3 to the console_device_table in console-config.c, and enables UART1 in configure.ac.

  • Property mode set to 100644
File size: 4.7 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.com/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
77static bool lpc176x_uart2_probe(rtems_termios_device_context *ctx)
78{
79  (void)ctx;
80
81  lpc176x_module_enable( LPC176X_MODULE_UART_2, LPC176X_MODULE_PCLK_DEFAULT );
82
83  lpc176x_pin_select( LPC176X_PIN_UART_2_TXD, LPC176X_PIN_FUNCTION_01 );
84  lpc176x_pin_select( LPC176X_PIN_UART_2_RXD, LPC176X_PIN_FUNCTION_01 );
85
86  return true;
87}
88
89static bool lpc176x_uart3_probe(rtems_termios_device_context *ctx)
90{
91  (void)ctx;
92
93  lpc176x_module_enable( LPC176X_MODULE_UART_3, LPC176X_MODULE_PCLK_DEFAULT );
94
95  lpc176x_pin_select( LPC176X_PIN_UART_3_TXD, LPC176X_PIN_FUNCTION_10 );
96  lpc176x_pin_select( LPC176X_PIN_UART_3_RXD, LPC176X_PIN_FUNCTION_10 );
97
98  return true;
99}
100
101#ifdef LPC176X_CONFIG_CONSOLE
102static ns16550_context lpc176x_uart_context_0 = {
103  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"),
104  .get_reg = lpc176x_uart_get_register,
105  .set_reg = lpc176x_uart_set_register,
106  .port = UART0_BASE_ADDR,
107  .irq = LPC176X_IRQ_UART_0,
108  .clock = LPC176X_PCLK,
109  .initial_baud = LPC176X_UART_BAUD,
110  .has_fractional_divider_register = true
111};
112#endif
113
114#ifdef LPC176X_CONFIG_UART_1
115static ns16550_context lpc176x_uart_context_1 = {
116  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
117  .get_reg = lpc176x_uart_get_register,
118  .set_reg = lpc176x_uart_set_register,
119  .port = UART1_BASE_ADDR,
120  .irq = LPC176X_IRQ_UART_1,
121  .clock = LPC176X_PCLK,
122  .initial_baud = LPC176X_UART_BAUD,
123  .has_fractional_divider_register = true
124};
125#endif
126
127#ifdef LPC176X_CONFIG_UART_2
128static ns16550_context lpc176x_uart_context_2 = {
129  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"),
130  .get_reg = lpc176x_uart_get_register,
131  .set_reg = lpc176x_uart_set_register,
132  .port = UART2_BASE_ADDR,
133  .irq = LPC176X_IRQ_UART_2,
134  .clock = LPC176X_PCLK,
135  .initial_baud = LPC176X_UART_BAUD,
136  .has_fractional_divider_register = true
137};
138#endif
139
140#ifdef LPC176X_CONFIG_UART_3
141static ns16550_context lpc176x_uart_context_3 = {
142  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"),
143  .get_reg = lpc176x_uart_get_register,
144  .set_reg = lpc176x_uart_set_register,
145  .port = UART3_BASE_ADDR,
146  .irq = LPC176X_IRQ_UART_3,
147  .clock = LPC176X_PCLK,
148  .initial_baud = LPC176X_UART_BAUD,
149  .has_fractional_divider_register = true
150};
151#endif
152
153const console_device console_device_table[] = {
154  #ifdef LPC176X_CONFIG_CONSOLE
155    {
156      .device_file = "/dev/ttyS0",
157      .probe = console_device_probe_default,
158      .handler = &ns16550_handler_interrupt,
159      .context = &lpc176x_uart_context_0.base
160    },
161  #endif
162  #ifdef LPC176X_CONFIG_UART_1
163    {
164      .device_file = "/dev/ttyS1",
165      .probe = lpc176x_uart1_probe,
166      .handler = &ns16550_handler_interrupt,
167      .context = &lpc176x_uart_context_1.base
168    },
169  #endif
170  #ifdef LPC176X_CONFIG_UART_2
171    {
172      .device_file = "/dev/ttyS2",
173      .probe = lpc176x_uart2_probe,
174      .handler = &ns16550_handler_interrupt,
175      .context = &lpc176x_uart_context_2.base
176    },
177  #endif
178  #ifdef LPC176X_CONFIG_UART_3
179    {
180      .device_file = "/dev/ttyS3",
181      .probe = lpc176x_uart3_probe,
182      .handler = &ns16550_handler_interrupt,
183      .context = &lpc176x_uart_context_3.base
184    },
185  #endif
186};
187
188const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);
Note: See TracBrowser for help on using the repository browser.