Revision 15d7dc4f

b/Makefile.target
249 249

  
250 250
# LM32 peripherals
251 251
obj-lm32-y += lm32_pic.o
252
obj-lm32-y += lm32_juart.o
252 253

  
253 254
obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
254 255
obj-mips-y += mips_addr.o mips_timer.o mips_int.o
b/hw/lm32_juart.c
1
/*
2
 *  LatticeMico32 JTAG UART model.
3
 *
4
 *  Copyright (c) 2010 Michael Walle <michael@walle.cc>
5
 *
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.
10
 *
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.
15
 *
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/>.
18
 */
19

  
20
#include "hw.h"
21
#include "sysbus.h"
22
#include "trace.h"
23
#include "qemu-char.h"
24

  
25
#include "lm32_juart.h"
26

  
27
enum {
28
    LM32_JUART_MIN_SAVE_VERSION = 0,
29
    LM32_JUART_CURRENT_SAVE_VERSION = 0,
30
    LM32_JUART_MAX_SAVE_VERSION = 0,
31
};
32

  
33
enum {
34
    JTX_FULL = (1<<8),
35
};
36

  
37
enum {
38
    JRX_FULL = (1<<8),
39
};
40

  
41
struct LM32JuartState {
42
    SysBusDevice busdev;
43
    CharDriverState *chr;
44

  
45
    uint32_t jtx;
46
    uint32_t jrx;
47
};
48
typedef struct LM32JuartState LM32JuartState;
49

  
50
uint32_t lm32_juart_get_jtx(DeviceState *d)
51
{
52
    LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
53

  
54
    trace_lm32_juart_get_jtx(s->jtx);
55
    return s->jtx;
56
}
57

  
58
uint32_t lm32_juart_get_jrx(DeviceState *d)
59
{
60
    LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
61

  
62
    trace_lm32_juart_get_jrx(s->jrx);
63
    return s->jrx;
64
}
65

  
66
void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx)
67
{
68
    LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
69
    unsigned char ch = jtx & 0xff;
70

  
71
    trace_lm32_juart_set_jtx(s->jtx);
72

  
73
    s->jtx = jtx;
74
    if (s->chr) {
75
        qemu_chr_write(s->chr, &ch, 1);
76
    }
77
}
78

  
79
void lm32_juart_set_jrx(DeviceState *d, uint32_t jtx)
80
{
81
    LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
82

  
83
    trace_lm32_juart_set_jrx(s->jrx);
84
    s->jrx &= ~JRX_FULL;
85
}
86

  
87
static void juart_rx(void *opaque, const uint8_t *buf, int size)
88
{
89
    LM32JuartState *s = opaque;
90

  
91
    s->jrx = *buf | JRX_FULL;
92
}
93

  
94
static int juart_can_rx(void *opaque)
95
{
96
    LM32JuartState *s = opaque;
97

  
98
    return !(s->jrx & JRX_FULL);
99
}
100

  
101
static void juart_event(void *opaque, int event)
102
{
103
}
104

  
105
static void juart_reset(DeviceState *d)
106
{
107
    LM32JuartState *s = container_of(d, LM32JuartState, busdev.qdev);
108

  
109
    s->jtx = 0;
110
    s->jrx = 0;
111
}
112

  
113
static int lm32_juart_init(SysBusDevice *dev)
114
{
115
    LM32JuartState *s = FROM_SYSBUS(typeof(*s), dev);
116

  
117
    s->chr = qdev_init_chardev(&dev->qdev);
118
    if (s->chr) {
119
        qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s);
120
    }
121

  
122
    return 0;
123
}
124

  
125
static const VMStateDescription vmstate_lm32_juart = {
126
    .name = "lm32-juart",
127
    .version_id = 1,
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()
134
    }
135
};
136

  
137
static SysBusDeviceInfo lm32_juart_info = {
138
    .init = lm32_juart_init,
139
    .qdev.name  = "lm32-juart",
140
    .qdev.size  = sizeof(LM32JuartState),
141
    .qdev.vmsd  = &vmstate_lm32_juart,
142
    .qdev.reset = juart_reset,
143
};
144

  
145
static void lm32_juart_register(void)
146
{
147
    sysbus_register_withprop(&lm32_juart_info);
148
}
149

  
150
device_init(lm32_juart_register)
b/hw/lm32_juart.h
1
#ifndef QEMU_HW_LM32_JUART_H
2
#define QEMU_HW_LM32_JUART_H
3

  
4
#include "qemu-common.h"
5

  
6
uint32_t lm32_juart_get_jtx(DeviceState *d);
7
uint32_t lm32_juart_get_jrx(DeviceState *d);
8
void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx);
9
void lm32_juart_set_jrx(DeviceState *d, uint32_t jrx);
10

  
11
#endif /* QEMU_HW_LM32_JUART_H */
b/trace-events
263 263
disable lm32_pic_set_ip(uint32_t ip) "ip 0x%08x"
264 264
disable lm32_pic_get_im(uint32_t im) "im 0x%08x"
265 265
disable lm32_pic_get_ip(uint32_t ip) "ip 0x%08x"
266

  
267
# hw/lm32_juart.c
268
disable lm32_juart_get_jtx(uint32_t value) "jtx 0x%08x"
269
disable lm32_juart_set_jtx(uint32_t value) "jtx 0x%08x"
270
disable lm32_juart_get_jrx(uint32_t value) "jrx 0x%08x"
271
disable lm32_juart_set_jrx(uint32_t value) "jrx 0x%08x"

Also available in: Unified diff