1 | /* |
---|
2 | * Copyright (c) 2013 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 | #include <bsp/arm-pl011-regs.h> |
---|
17 | |
---|
18 | #include <libchip/sersupp.h> |
---|
19 | |
---|
20 | static volatile pl011 *pl011_get_regs(int minor) |
---|
21 | { |
---|
22 | const console_tbl *ct = Console_Port_Tbl != NULL ? |
---|
23 | Console_Port_Tbl[minor] : &Console_Configuration_Ports[minor]; |
---|
24 | |
---|
25 | return (volatile pl011 *) ct->ulCtrlPort1; |
---|
26 | } |
---|
27 | |
---|
28 | static void pl011_initialize(int minor) |
---|
29 | { |
---|
30 | volatile pl011 *regs = pl011_get_regs(minor); |
---|
31 | |
---|
32 | regs->uartlcr_h = PL011_UARTLCR_H_WLEN(PL011_UARTLCR_H_WLEN_8); |
---|
33 | regs->uartcr = PL011_UARTCR_RXE |
---|
34 | | PL011_UARTCR_TXE |
---|
35 | | PL011_UARTCR_UARTEN; |
---|
36 | } |
---|
37 | |
---|
38 | static int pl011_first_open(int major, int minor, void *arg) |
---|
39 | { |
---|
40 | rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *) arg; |
---|
41 | struct rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1; |
---|
42 | console_data *cd = &Console_Port_Data[minor]; |
---|
43 | const console_tbl *ct = Console_Port_Tbl[minor]; |
---|
44 | |
---|
45 | cd->termios_data = tty; |
---|
46 | rtems_termios_set_initial_baud(tty, (rtems_termios_baud_t) ct->pDeviceParams); |
---|
47 | |
---|
48 | return 0; |
---|
49 | } |
---|
50 | |
---|
51 | static int pl011_last_close(int major, int minor, void *arg) |
---|
52 | { |
---|
53 | return 0; |
---|
54 | } |
---|
55 | |
---|
56 | static int pl011_read_polled(int minor) |
---|
57 | { |
---|
58 | volatile pl011 *regs = pl011_get_regs(minor); |
---|
59 | |
---|
60 | if ((regs->uartfr & PL011_UARTFR_RXFE) != 0) { |
---|
61 | return -1; |
---|
62 | } else { |
---|
63 | return PL011_UARTDR_DATA_GET(regs->uartdr); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | static void pl011_write_polled(int minor, char c) |
---|
68 | { |
---|
69 | volatile pl011 *regs = pl011_get_regs(minor); |
---|
70 | |
---|
71 | while ((regs->uartfr & PL011_UARTFR_TXFF) != 0) { |
---|
72 | /* Wait */ |
---|
73 | } |
---|
74 | |
---|
75 | regs->uartdr = PL011_UARTDR_DATA(c); |
---|
76 | } |
---|
77 | |
---|
78 | static ssize_t pl011_write_support_polled( |
---|
79 | int minor, |
---|
80 | const char *s, |
---|
81 | size_t n |
---|
82 | ) |
---|
83 | { |
---|
84 | ssize_t i = 0; |
---|
85 | |
---|
86 | for (i = 0; i < n; ++i) { |
---|
87 | pl011_write_polled(minor, s[i]); |
---|
88 | } |
---|
89 | |
---|
90 | return n; |
---|
91 | } |
---|
92 | |
---|
93 | static int pl011_set_attribues(int minor, const struct termios *term) |
---|
94 | { |
---|
95 | return -1; |
---|
96 | } |
---|
97 | |
---|
98 | const console_fns arm_pl011_fns = { |
---|
99 | .deviceProbe = libchip_serial_default_probe, |
---|
100 | .deviceFirstOpen = pl011_first_open, |
---|
101 | .deviceLastClose = pl011_last_close, |
---|
102 | .deviceRead = pl011_read_polled, |
---|
103 | .deviceWrite = pl011_write_support_polled, |
---|
104 | .deviceInitialize = pl011_initialize, |
---|
105 | .deviceWritePolled = pl011_write_polled, |
---|
106 | .deviceSetAttributes = pl011_set_attribues, |
---|
107 | .deviceOutputUsesInterrupts = false |
---|
108 | }; |
---|