root / hw / lm32_juart.c @ 03a6b667
History | View | Annotate | Download (3.6 kB)
1 | 15d7dc4f | Michael Walle | /*
|
---|---|---|---|
2 | 15d7dc4f | Michael Walle | * LatticeMico32 JTAG UART model.
|
3 | 15d7dc4f | Michael Walle | *
|
4 | 15d7dc4f | Michael Walle | * Copyright (c) 2010 Michael Walle <michael@walle.cc>
|
5 | 15d7dc4f | Michael Walle | *
|
6 | 15d7dc4f | Michael Walle | * This library is free software; you can redistribute it and/or
|
7 | 15d7dc4f | Michael Walle | * modify it under the terms of the GNU Lesser General Public
|
8 | 15d7dc4f | Michael Walle | * License as published by the Free Software Foundation; either
|
9 | 15d7dc4f | Michael Walle | * version 2 of the License, or (at your option) any later version.
|
10 | 15d7dc4f | Michael Walle | *
|
11 | 15d7dc4f | Michael Walle | * This library is distributed in the hope that it will be useful,
|
12 | 15d7dc4f | Michael Walle | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 15d7dc4f | Michael Walle | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 15d7dc4f | Michael Walle | * Lesser General Public License for more details.
|
15 | 15d7dc4f | Michael Walle | *
|
16 | 15d7dc4f | Michael Walle | * You should have received a copy of the GNU Lesser General Public
|
17 | 15d7dc4f | Michael Walle | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | 15d7dc4f | Michael Walle | */
|
19 | 15d7dc4f | Michael Walle | |
20 | 15d7dc4f | Michael Walle | #include "hw.h" |
21 | 15d7dc4f | Michael Walle | #include "sysbus.h" |
22 | 15d7dc4f | Michael Walle | #include "trace.h" |
23 | 15d7dc4f | Michael Walle | #include "qemu-char.h" |
24 | 15d7dc4f | Michael Walle | |
25 | 15d7dc4f | Michael Walle | #include "lm32_juart.h" |
26 | 15d7dc4f | Michael Walle | |
27 | 15d7dc4f | Michael Walle | enum {
|
28 | 15d7dc4f | Michael Walle | LM32_JUART_MIN_SAVE_VERSION = 0,
|
29 | 15d7dc4f | Michael Walle | LM32_JUART_CURRENT_SAVE_VERSION = 0,
|
30 | 15d7dc4f | Michael Walle | LM32_JUART_MAX_SAVE_VERSION = 0,
|
31 | 15d7dc4f | Michael Walle | }; |
32 | 15d7dc4f | Michael Walle | |
33 | 15d7dc4f | Michael Walle | enum {
|
34 | 15d7dc4f | Michael Walle | JTX_FULL = (1<<8), |
35 | 15d7dc4f | Michael Walle | }; |
36 | 15d7dc4f | Michael Walle | |
37 | 15d7dc4f | Michael Walle | enum {
|
38 | 15d7dc4f | Michael Walle | JRX_FULL = (1<<8), |
39 | 15d7dc4f | Michael Walle | }; |
40 | 15d7dc4f | Michael Walle | |
41 | 15d7dc4f | Michael Walle | struct LM32JuartState {
|
42 | 15d7dc4f | Michael Walle | SysBusDevice busdev; |
43 | 15d7dc4f | Michael Walle | CharDriverState *chr; |
44 | 15d7dc4f | Michael Walle | |
45 | 15d7dc4f | Michael Walle | uint32_t jtx; |
46 | 15d7dc4f | Michael Walle | uint32_t jrx; |
47 | 15d7dc4f | Michael Walle | }; |
48 | 15d7dc4f | Michael Walle | typedef struct LM32JuartState LM32JuartState; |
49 | 15d7dc4f | Michael Walle | |
50 | 15d7dc4f | Michael Walle | uint32_t lm32_juart_get_jtx(DeviceState *d) |
51 | 15d7dc4f | Michael Walle | { |
52 | 15d7dc4f | Michael Walle | LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); |
53 | 15d7dc4f | Michael Walle | |
54 | 15d7dc4f | Michael Walle | trace_lm32_juart_get_jtx(s->jtx); |
55 | 15d7dc4f | Michael Walle | return s->jtx;
|
56 | 15d7dc4f | Michael Walle | } |
57 | 15d7dc4f | Michael Walle | |
58 | 15d7dc4f | Michael Walle | uint32_t lm32_juart_get_jrx(DeviceState *d) |
59 | 15d7dc4f | Michael Walle | { |
60 | 15d7dc4f | Michael Walle | LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); |
61 | 15d7dc4f | Michael Walle | |
62 | 15d7dc4f | Michael Walle | trace_lm32_juart_get_jrx(s->jrx); |
63 | 15d7dc4f | Michael Walle | return s->jrx;
|
64 | 15d7dc4f | Michael Walle | } |
65 | 15d7dc4f | Michael Walle | |
66 | 15d7dc4f | Michael Walle | void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx)
|
67 | 15d7dc4f | Michael Walle | { |
68 | 15d7dc4f | Michael Walle | LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); |
69 | 15d7dc4f | Michael Walle | unsigned char ch = jtx & 0xff; |
70 | 15d7dc4f | Michael Walle | |
71 | 15d7dc4f | Michael Walle | trace_lm32_juart_set_jtx(s->jtx); |
72 | 15d7dc4f | Michael Walle | |
73 | 15d7dc4f | Michael Walle | s->jtx = jtx; |
74 | 15d7dc4f | Michael Walle | if (s->chr) {
|
75 | 2cc6e0a1 | Anthony Liguori | qemu_chr_fe_write(s->chr, &ch, 1);
|
76 | 15d7dc4f | Michael Walle | } |
77 | 15d7dc4f | Michael Walle | } |
78 | 15d7dc4f | Michael Walle | |
79 | 15d7dc4f | Michael Walle | void lm32_juart_set_jrx(DeviceState *d, uint32_t jtx)
|
80 | 15d7dc4f | Michael Walle | { |
81 | 15d7dc4f | Michael Walle | LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); |
82 | 15d7dc4f | Michael Walle | |
83 | 15d7dc4f | Michael Walle | trace_lm32_juart_set_jrx(s->jrx); |
84 | 15d7dc4f | Michael Walle | s->jrx &= ~JRX_FULL; |
85 | 15d7dc4f | Michael Walle | } |
86 | 15d7dc4f | Michael Walle | |
87 | 15d7dc4f | Michael Walle | static void juart_rx(void *opaque, const uint8_t *buf, int size) |
88 | 15d7dc4f | Michael Walle | { |
89 | 15d7dc4f | Michael Walle | LM32JuartState *s = opaque; |
90 | 15d7dc4f | Michael Walle | |
91 | 15d7dc4f | Michael Walle | s->jrx = *buf | JRX_FULL; |
92 | 15d7dc4f | Michael Walle | } |
93 | 15d7dc4f | Michael Walle | |
94 | 15d7dc4f | Michael Walle | static int juart_can_rx(void *opaque) |
95 | 15d7dc4f | Michael Walle | { |
96 | 15d7dc4f | Michael Walle | LM32JuartState *s = opaque; |
97 | 15d7dc4f | Michael Walle | |
98 | 15d7dc4f | Michael Walle | return !(s->jrx & JRX_FULL);
|
99 | 15d7dc4f | Michael Walle | } |
100 | 15d7dc4f | Michael Walle | |
101 | 15d7dc4f | Michael Walle | static void juart_event(void *opaque, int event) |
102 | 15d7dc4f | Michael Walle | { |
103 | 15d7dc4f | Michael Walle | } |
104 | 15d7dc4f | Michael Walle | |
105 | 15d7dc4f | Michael Walle | static void juart_reset(DeviceState *d) |
106 | 15d7dc4f | Michael Walle | { |
107 | 15d7dc4f | Michael Walle | LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev); |
108 | 15d7dc4f | Michael Walle | |
109 | 15d7dc4f | Michael Walle | s->jtx = 0;
|
110 | 15d7dc4f | Michael Walle | s->jrx = 0;
|
111 | 15d7dc4f | Michael Walle | } |
112 | 15d7dc4f | Michael Walle | |
113 | 15d7dc4f | Michael Walle | static int lm32_juart_init(SysBusDevice *dev) |
114 | 15d7dc4f | Michael Walle | { |
115 | 15d7dc4f | Michael Walle | LM32JuartState *s = FROM_SYSBUS(typeof(*s), dev); |
116 | 15d7dc4f | Michael Walle | |
117 | 0beb4942 | Anthony Liguori | s->chr = qemu_char_get_next_serial(); |
118 | 15d7dc4f | Michael Walle | if (s->chr) {
|
119 | 15d7dc4f | Michael Walle | qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s); |
120 | 15d7dc4f | Michael Walle | } |
121 | 15d7dc4f | Michael Walle | |
122 | 15d7dc4f | Michael Walle | return 0; |
123 | 15d7dc4f | Michael Walle | } |
124 | 15d7dc4f | Michael Walle | |
125 | 15d7dc4f | Michael Walle | static const VMStateDescription vmstate_lm32_juart = { |
126 | 15d7dc4f | Michael Walle | .name = "lm32-juart",
|
127 | 15d7dc4f | Michael Walle | .version_id = 1,
|
128 | 15d7dc4f | Michael Walle | .minimum_version_id = 1,
|
129 | 15d7dc4f | Michael Walle | .minimum_version_id_old = 1,
|
130 | 15d7dc4f | Michael Walle | .fields = (VMStateField[]) { |
131 | 15d7dc4f | Michael Walle | VMSTATE_UINT32(jtx, LM32JuartState), |
132 | 15d7dc4f | Michael Walle | VMSTATE_UINT32(jrx, LM32JuartState), |
133 | 15d7dc4f | Michael Walle | VMSTATE_END_OF_LIST() |
134 | 15d7dc4f | Michael Walle | } |
135 | 15d7dc4f | Michael Walle | }; |
136 | 15d7dc4f | Michael Walle | |
137 | 999e12bb | Anthony Liguori | static void lm32_juart_class_init(ObjectClass *klass, void *data) |
138 | 999e12bb | Anthony Liguori | { |
139 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
140 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
141 | 999e12bb | Anthony Liguori | |
142 | 999e12bb | Anthony Liguori | k->init = lm32_juart_init; |
143 | 39bffca2 | Anthony Liguori | dc->reset = juart_reset; |
144 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_lm32_juart; |
145 | 999e12bb | Anthony Liguori | } |
146 | 999e12bb | Anthony Liguori | |
147 | 39bffca2 | Anthony Liguori | static TypeInfo lm32_juart_info = {
|
148 | 39bffca2 | Anthony Liguori | .name = "lm32-juart",
|
149 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
150 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(LM32JuartState),
|
151 | 39bffca2 | Anthony Liguori | .class_init = lm32_juart_class_init, |
152 | 15d7dc4f | Michael Walle | }; |
153 | 15d7dc4f | Michael Walle | |
154 | 83f7d43a | Andreas Färber | static void lm32_juart_register_types(void) |
155 | 15d7dc4f | Michael Walle | { |
156 | 39bffca2 | Anthony Liguori | type_register_static(&lm32_juart_info); |
157 | 15d7dc4f | Michael Walle | } |
158 | 15d7dc4f | Michael Walle | |
159 | 83f7d43a | Andreas Färber | type_init(lm32_juart_register_types) |