source: rtems/c/src/lib/libbsp/arm/shared/arm-pl011.c @ ca4602e

5
Last change on this file since ca4602e was 116ef2e9, checked in by Sebastian Huber <sebastian.huber@…>, on 10/13/14 at 13:19:12

bsps/arm: Convert PL011 and PL050 console drivers

Use Termios device API.

  • Property mode set to 100644
File size: 1.9 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 <bsp/arm-pl011.h>
16
17static volatile pl011 *pl011_get_regs(rtems_termios_device_context *base)
18{
19  arm_pl011_context *ctx = (arm_pl011_context *) base;
20
21  return ctx->regs;
22}
23
24
25bool arm_pl011_probe(rtems_termios_device_context *base)
26{
27  volatile pl011 *regs = pl011_get_regs(base);
28
29  regs->uartlcr_h = PL011_UARTLCR_H_WLEN(PL011_UARTLCR_H_WLEN_8);
30  regs->uartcr = PL011_UARTCR_RXE
31    | PL011_UARTCR_TXE
32    | PL011_UARTCR_UARTEN;
33
34  return true;
35}
36
37static bool pl011_first_open(
38  struct rtems_termios_tty *tty,
39  rtems_termios_device_context *base,
40  struct termios *term,
41  rtems_libio_open_close_args_t *args
42)
43{
44  arm_pl011_context *ctx = (arm_pl011_context *) base;
45
46  rtems_termios_set_initial_baud(tty, ctx->initial_baud);
47
48  return true;
49}
50
51static int pl011_read_polled(rtems_termios_device_context *base)
52{
53  volatile pl011 *regs = pl011_get_regs(base);
54
55  if ((regs->uartfr & PL011_UARTFR_RXFE) != 0) {
56    return -1;
57  } else {
58    return PL011_UARTDR_DATA_GET(regs->uartdr);
59  }
60}
61
62void arm_pl011_write_polled(rtems_termios_device_context *base, char c)
63{
64  volatile pl011 *regs = pl011_get_regs(base);
65
66  while ((regs->uartfr & PL011_UARTFR_TXFF) != 0) {
67    /* Wait */
68  }
69
70  regs->uartdr = PL011_UARTDR_DATA(c);
71}
72
73static void pl011_write_support_polled(
74  rtems_termios_device_context *base,
75  const char *s,
76  size_t n
77)
78{
79  size_t i;
80
81  for (i = 0; i < n; ++i) {
82    arm_pl011_write_polled(base, s[i]);
83  }
84}
85
86const rtems_termios_device_handler arm_pl011_fns = {
87  .first_open = pl011_first_open,
88  .poll_read = pl011_read_polled,
89  .write = pl011_write_support_polled,
90  .mode = TERMIOS_POLLED
91};
Note: See TracBrowser for help on using the repository browser.