source: rtems/c/src/lib/libbsp/arm/lm3s69xx/console/uart.c @ 034b041

4.115
Last change on this file since 034b041 was 034b041, checked in by Sebastian Huber <sebastian.huber@…>, on 02/07/12 at 21:13:04

Fixed bug intoduced due to API changes.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * Copyright (c) 2011 Sebastian Huber.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@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.com/license/LICENSE.
13 *
14 * $Id$
15 */
16
17#include <bspopts.h>
18#include <bsp/uart.h>
19#include <libchip/sersupp.h>
20
21static volatile lm3s69xx_uart *get_uart_regs(int minor)
22{
23  console_tbl *ct = Console_Port_Tbl [minor];
24
25  return (lm3s69xx_uart *) ct->ulCtrlPort1;
26}
27
28static void initialize(int minor)
29{
30  volatile lm3s69xx_uart *uart = get_uart_regs(minor);
31
32  uart->ctl = 0;
33  uart->lcrh = UARTLCRH_WLEN(0x3) | UARTLCRH_FEN;
34  uart->ctl = UARTCTL_RXE | UARTCTL_TXE | UARTCTL_UARTEN;
35}
36
37static int first_open(int major, int minor, void *arg)
38{
39  rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *) arg;
40  struct rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1;
41  console_data *cd = &Console_Port_Data [minor];
42
43  cd->termios_data = tty;
44  rtems_termios_set_initial_baud(tty, LM3S69XX_UART_BAUD);
45
46  return 0;
47}
48
49static int last_close(int major, int minor, void *arg)
50{
51  return 0;
52}
53
54static int read_polled(int minor)
55{
56  volatile lm3s69xx_uart *uart = get_uart_regs(minor);
57
58  if ((uart->fr & UARTFR_RXFE) != 0) {
59    return -1;
60  } else {
61    return UARTDR_DATA(uart->dr);
62  }
63}
64
65static void write_polled(int minor, char c)
66{
67  volatile lm3s69xx_uart *uart = get_uart_regs(minor);
68
69  while ((uart->fr & UARTFR_TXFF) != 0) {
70    /* Wait */
71  }
72
73  uart->dr = UARTDR_DATA(c);
74}
75
76static ssize_t write_support_polled(
77  int minor,
78  const char *s,
79  size_t n
80)
81{
82  ssize_t i = 0;
83
84  for (i = 0; i < n; ++i) {
85    write_polled(minor, s [i]);
86  }
87
88  return n;
89}
90
91static int set_attribues(int minor, const struct termios *term)
92{
93  return -1;
94}
95
96console_fns lm3s69xx_uart_fns = {
97  .deviceProbe = libchip_serial_default_probe,
98  .deviceFirstOpen = first_open,
99  .deviceLastClose = last_close,
100  .deviceRead = read_polled,
101  .deviceWrite = write_support_polled,
102  .deviceInitialize = initialize,
103  .deviceWritePolled = write_polled,
104  .deviceSetAttributes = set_attribues,
105  .deviceOutputUsesInterrupts = false
106};
Note: See TracBrowser for help on using the repository browser.