1 |
/* |
2 |
* Copyright (C) 2006-2007 Anders Gavare. All rights reserved. |
3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
6 |
* |
7 |
* 1. Redistributions of source code must retain the above copyright |
8 |
* notice, this list of conditions and the following disclaimer. |
9 |
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
* notice, this list of conditions and the following disclaimer in the |
11 |
* documentation and/or other materials provided with the distribution. |
12 |
* 3. The name of the author may not be used to endorse or promote products |
13 |
* derived from this software without specific prior written permission. |
14 |
* |
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
26 |
* |
27 |
* |
28 |
* $Id: dev_iq80321_7seg.c,v 1.4 2007/06/15 19:11:15 debug Exp $ |
29 |
* |
30 |
* COMMENT: IQ80321 LED device |
31 |
* |
32 |
* Should work with NetBSD's iq80321_7seg.c. |
33 |
* |
34 |
* TODO: Graphical output of LED lines? |
35 |
*/ |
36 |
|
37 |
#include <stdio.h> |
38 |
#include <stdlib.h> |
39 |
#include <string.h> |
40 |
|
41 |
#include "cpu.h" |
42 |
#include "device.h" |
43 |
#include "machine.h" |
44 |
#include "memory.h" |
45 |
#include "misc.h" |
46 |
|
47 |
|
48 |
struct iq80321_7seg_data { |
49 |
uint8_t msb, lsb; |
50 |
}; |
51 |
|
52 |
|
53 |
DEVICE_ACCESS(iq80321_7seg) |
54 |
{ |
55 |
struct iq80321_7seg_data *d = extra; |
56 |
uint64_t idata = 0, odata = 0; |
57 |
|
58 |
if (writeflag == MEM_WRITE) |
59 |
idata = memory_readmax64(cpu, data, len); |
60 |
|
61 |
switch (relative_addr) { |
62 |
|
63 |
case 0: if (writeflag == MEM_READ) |
64 |
odata = d->msb; |
65 |
else { |
66 |
d->msb = idata; |
67 |
debug("[ iq80321_7seg: setting MSB to 0x%02x ]\n", |
68 |
(int)idata); |
69 |
} |
70 |
break; |
71 |
|
72 |
case 0x10000: |
73 |
if (writeflag == MEM_READ) |
74 |
odata = d->lsb; |
75 |
else { |
76 |
d->lsb = idata; |
77 |
debug("[ iq80321_7seg: setting LSB to 0x%02x ]\n", |
78 |
(int)idata); |
79 |
} |
80 |
break; |
81 |
|
82 |
default:if (writeflag == MEM_READ) { |
83 |
fatal("[ iq80321_7seg: read from 0x%x ]\n", |
84 |
(int)relative_addr); |
85 |
} else { |
86 |
fatal("[ iq80321_7seg: write to 0x%x: 0x%llx ]\n", |
87 |
(int)relative_addr, (long long)idata); |
88 |
} |
89 |
exit(1); |
90 |
} |
91 |
|
92 |
if (writeflag == MEM_READ) |
93 |
memory_writemax64(cpu, data, len, odata); |
94 |
|
95 |
return 1; |
96 |
} |
97 |
|
98 |
|
99 |
DEVINIT(iq80321_7seg) |
100 |
{ |
101 |
struct iq80321_7seg_data *d; |
102 |
|
103 |
CHECK_ALLOCATION(d = malloc(sizeof(struct iq80321_7seg_data))); |
104 |
memset(d, 0, sizeof(struct iq80321_7seg_data)); |
105 |
|
106 |
/* 0xfe840000 and 0xfe850000 */ |
107 |
memory_device_register(devinit->machine->memory, devinit->name, |
108 |
devinit->addr, 0x10004, dev_iq80321_7seg_access, d, |
109 |
DM_DEFAULT, NULL); |
110 |
|
111 |
return 1; |
112 |
} |
113 |
|
114 |
|