forked from bcd/exec09
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathimux.c
126 lines (114 loc) · 2.78 KB
/
imux.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright 2009 by Brian Dominy <brian@oddchange.com>
*
* This file is part of GCC6809.
*
* GCC6809 is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GCC6809 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GCC6809; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* The interrupt multiplexer */
#include <stdlib.h>
#include "machine.h"
#include "eon.h"
#include "6809.h"
#include "imux.h"
/*
* Refresh the state of the interrupt line back to the CPU.
* src == 1 refers to IRQ, src == 2 for FIRQ.
*/
void imux_refresh (struct imux *mux)
{
if (mux->pending & mux->enabled)
{
if (mux->src == 1)
request_irq (mux->src);
else
request_firq (mux->src);
}
else
{
if (mux->src == 1)
release_irq (mux->src);
else
release_firq (mux->src);
}
}
void imux_reset (struct hw_device *dev)
{
struct imux *mux = (struct imux *)dev->priv;
mux->enabled = 0;
mux->pending = 0;
}
U8 imux_read (struct hw_device *dev, unsigned long addr)
{
struct imux *mux = (struct imux *)dev->priv;
switch (addr)
{
case IMUX_ENB:
/* Return the enable bits */
return mux->enabled & 0xFF;
case IMUX_PEND:
/* Return the pending bits */
return mux->pending & 0xFF;
}
return -1;
}
void imux_write (struct hw_device *dev, unsigned long addr, U8 val)
{
struct imux *mux = (struct imux *)dev->priv;
switch (addr)
{
case IMUX_ENB:
/* Set the interrupt enables */
mux->enabled = val;
break;
case IMUX_PEND:
/* Clear pending interrupt source */
mux->pending &= ~val;
break;
}
imux_refresh (mux);
}
/*
* Register an interrupt line with the multiplexer.
* This just tracks which ones are in use.
*/
void imux_register (struct hw_device *dev, unsigned int sig)
{
struct imux *mux = (struct imux *)dev->priv;
mux->in_use |= (1 << sig);
}
/*
* Assert an edge-triggered interrupt line.
*/
void imux_assert (struct hw_device *dev, unsigned int sig)
{
struct imux *mux = (struct imux *)dev->priv;
mux->pending |= (1 << sig);
imux_refresh (mux);
}
struct hw_class imux_class =
{
.name = "imux",
.readonly = 0,
.reset = imux_reset,
.read = imux_read,
.write = imux_write,
};
struct hw_device *imux_create (unsigned int cpu_line)
{
struct imux *imux = malloc (sizeof (struct imux));
imux->src = cpu_line;
return device_attach (&imux_class, BUS_MAP_SIZE, imux);
}