2 * LatticeMico32 JTAG UART model.
4 * Copyright (c) 2010 Michael Walle <michael@walle.cc>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 #include "char/char.h"
25 #include "lm32_juart.h"
28 LM32_JUART_MIN_SAVE_VERSION
= 0,
29 LM32_JUART_CURRENT_SAVE_VERSION
= 0,
30 LM32_JUART_MAX_SAVE_VERSION
= 0,
41 struct LM32JuartState
{
48 typedef struct LM32JuartState LM32JuartState
;
50 uint32_t lm32_juart_get_jtx(DeviceState
*d
)
52 LM32JuartState
*s
= container_of(d
, LM32JuartState
, busdev
.qdev
);
54 trace_lm32_juart_get_jtx(s
->jtx
);
58 uint32_t lm32_juart_get_jrx(DeviceState
*d
)
60 LM32JuartState
*s
= container_of(d
, LM32JuartState
, busdev
.qdev
);
62 trace_lm32_juart_get_jrx(s
->jrx
);
66 void lm32_juart_set_jtx(DeviceState
*d
, uint32_t jtx
)
68 LM32JuartState
*s
= container_of(d
, LM32JuartState
, busdev
.qdev
);
69 unsigned char ch
= jtx
& 0xff;
71 trace_lm32_juart_set_jtx(s
->jtx
);
75 qemu_chr_fe_write(s
->chr
, &ch
, 1);
79 void lm32_juart_set_jrx(DeviceState
*d
, uint32_t jtx
)
81 LM32JuartState
*s
= container_of(d
, LM32JuartState
, busdev
.qdev
);
83 trace_lm32_juart_set_jrx(s
->jrx
);
87 static void juart_rx(void *opaque
, const uint8_t *buf
, int size
)
89 LM32JuartState
*s
= opaque
;
91 s
->jrx
= *buf
| JRX_FULL
;
94 static int juart_can_rx(void *opaque
)
96 LM32JuartState
*s
= opaque
;
98 return !(s
->jrx
& JRX_FULL
);
101 static void juart_event(void *opaque
, int event
)
105 static void juart_reset(DeviceState
*d
)
107 LM32JuartState
*s
= container_of(d
, LM32JuartState
, busdev
.qdev
);
113 static int lm32_juart_init(SysBusDevice
*dev
)
115 LM32JuartState
*s
= FROM_SYSBUS(typeof(*s
), dev
);
117 s
->chr
= qemu_char_get_next_serial();
119 qemu_chr_add_handlers(s
->chr
, juart_can_rx
, juart_rx
, juart_event
, s
);
125 static const VMStateDescription vmstate_lm32_juart
= {
126 .name
= "lm32-juart",
128 .minimum_version_id
= 1,
129 .minimum_version_id_old
= 1,
130 .fields
= (VMStateField
[]) {
131 VMSTATE_UINT32(jtx
, LM32JuartState
),
132 VMSTATE_UINT32(jrx
, LM32JuartState
),
133 VMSTATE_END_OF_LIST()
137 static void lm32_juart_class_init(ObjectClass
*klass
, void *data
)
139 DeviceClass
*dc
= DEVICE_CLASS(klass
);
140 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
142 k
->init
= lm32_juart_init
;
143 dc
->reset
= juart_reset
;
144 dc
->vmsd
= &vmstate_lm32_juart
;
147 static const TypeInfo lm32_juart_info
= {
148 .name
= "lm32-juart",
149 .parent
= TYPE_SYS_BUS_DEVICE
,
150 .instance_size
= sizeof(LM32JuartState
),
151 .class_init
= lm32_juart_class_init
,
154 static void lm32_juart_register_types(void)
156 type_register_static(&lm32_juart_info
);
159 type_init(lm32_juart_register_types
)