~ubuntu-branches/ubuntu/dapper/simulavr/dapper

« back to all changes in this revision

Viewing changes to src/ports.h

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2004-04-10 13:54:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040410135417-zywapjyz252y65se
Tags: upstream-0.1.2.1
ImportĀ upstreamĀ versionĀ 0.1.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: ports.h,v 1.5 2003/12/01 07:35:53 troth Exp $
 
3
 *
 
4
 ****************************************************************************
 
5
 *
 
6
 * simulavr - A simulator for the Atmel AVR family of microcontrollers.
 
7
 * Copyright (C) 2001, 2002, 2003  Theodore A. Roth
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
 *
 
23
 ****************************************************************************
 
24
 */
 
25
 
 
26
#ifndef SIM_PORTS_H
 
27
#define SIM_PORTS_H
 
28
 
 
29
/****************************************************************************\
 
30
 *
 
31
 * Port(VDevice) : I/O Port registers
 
32
 *
 
33
\****************************************************************************/
 
34
 
 
35
/* Global variable for accessing names of port registers (in ports.c) */
 
36
extern char *name_PIN[];
 
37
extern char *name_DDR[];
 
38
extern char *name_PORT[];
 
39
 
 
40
enum _port_constants
 
41
{
 
42
    PORT_A = 0,
 
43
    PORT_B = 1,
 
44
    PORT_C = 2,
 
45
    PORT_D = 3,
 
46
    PORT_E = 4,
 
47
    PORT_F = 5,
 
48
 
 
49
    PORT_A_BASE = 0x39,         /* Base Memory address for port */
 
50
    PORT_B_BASE = 0x36,         /* Base Memory address for port */
 
51
    PORT_C_BASE = 0x33,         /* Base Memory address for port */
 
52
    PORT_D_BASE = 0x30,         /* Base Memory address for port */
 
53
 
 
54
    /* NOTE: these are only valid addresses for the USB devices. */
 
55
    PORT_E_BASE = 0x21,         /* Base Memory address for port */
 
56
    PORT_F_BASE = 0x24,         /* Base Memory address for port */
 
57
 
 
58
    PORT_PIN = 0,               /* offset to pin io                */
 
59
    PORT_DDR = 1,               /* offset to ddr register          */
 
60
    PORT_PORT = 2,              /* offset to data register (PORTx) */
 
61
 
 
62
    PORT_SIZE = 3,              /* All ports use 3 registers: PINx, DDRx,
 
63
                                   PORTx */
 
64
 
 
65
    PORT_1_BIT = 1,             /* Some ports are 1 bits wide */
 
66
    PORT_2_BIT = 2,             /* Some ports are 2 bits wide */
 
67
    PORT_3_BIT = 3,             /* Some ports are 3 bits wide */
 
68
    PORT_4_BIT = 4,             /* Some ports are 4 bits wide */
 
69
    PORT_5_BIT = 5,             /* Some ports are 5 bits wide */
 
70
    PORT_6_BIT = 6,             /* Some ports are 6 bits wide */
 
71
    PORT_7_BIT = 7,             /* Some ports are 7 bits wide */
 
72
    PORT_8_BIT = 8,             /* Most ports are 8 bits wide */
 
73
};
 
74
 
 
75
/* Generic I/O Port */
 
76
 
 
77
typedef struct _Port Port;
 
78
 
 
79
/* Hooks for alternate functions */
 
80
typedef uint8_t (*PortFP_AltRd) (Port *p, int addr, uint8_t data);
 
81
typedef void (*PortFP_AltWr) (Port *p, int addr, uint8_t data);
 
82
 
 
83
/* Hooks for external device connections */
 
84
typedef uint8_t (*PortFP_ExtRd) (int addr);
 
85
typedef void (*PortFP_ExtWr) (int addr, uint8_t val);
 
86
 
 
87
struct _Port
 
88
{
 
89
    VDevice parent;
 
90
    uint8_t mask;               /* which bits are available */
 
91
    uint8_t port;               /* port data register */
 
92
    uint8_t ddr;                /* data direction register */
 
93
    int ext_enable;             /* allows disabling external read functions */
 
94
 
 
95
    PortFP_AltRd alt_rd;        /* port/device specific alternate function
 
96
                                   read */
 
97
    PortFP_AltWr alt_wr;        /* port/device specific alternate function
 
98
                                   write */
 
99
 
 
100
    PortFP_ExtRd ext_rd;        /* hook to read from external device via
 
101
                                   port */
 
102
    PortFP_ExtWr ext_wr;        /* hook to write to external device via
 
103
                                   port */
 
104
};
 
105
 
 
106
extern Port *port_new (char *name, int base, int pins, PortFP_AltRd alt_rd,
 
107
                       PortFP_AltWr alt_wr);
 
108
extern void port_construct (Port *p, char *name, int base, int pins,
 
109
                            PortFP_AltRd alt_rd, PortFP_AltWr alt_wr);
 
110
extern void port_destroy (void *p);
 
111
 
 
112
extern void port_add_ext_rd_wr (Port *p, PortFP_ExtRd ext_rd,
 
113
                                PortFP_ExtWr ext_wr);
 
114
 
 
115
extern void port_ext_enable (Port *p);
 
116
extern void port_ext_disable (Port *p);
 
117
 
 
118
/****************************************************************************\
 
119
 *
 
120
 * Specific I/O Ports
 
121
 *
 
122
\****************************************************************************/
 
123
 
 
124
/* Port A */
 
125
 
 
126
typedef struct _PortA PortA;
 
127
 
 
128
struct _PortA
 
129
{
 
130
    Port parent;
 
131
};
 
132
 
 
133
extern PortA *porta_new (int pins);
 
134
extern void porta_construct (PortA *p, int pins);
 
135
extern void porta_destroy (void *p);
 
136
 
 
137
/* Port B */
 
138
typedef struct _PortB PortB;
 
139
 
 
140
struct _PortB
 
141
{
 
142
    Port parent;
 
143
};
 
144
 
 
145
extern PortB *portb_new (int pins);
 
146
extern void portb_construct (PortB *p, int pins);
 
147
extern void portb_destroy (void *p);
 
148
 
 
149
/* Port C */
 
150
typedef struct _PortC PortC;
 
151
 
 
152
struct _PortC
 
153
{
 
154
    Port parent;
 
155
};
 
156
 
 
157
extern PortC *portc_new (int pins);
 
158
extern void portc_construct (PortC *p, int pins);
 
159
extern void portc_destroy (void *p);
 
160
 
 
161
/* Port D */
 
162
typedef struct _PortD PortD;
 
163
 
 
164
struct _PortD
 
165
{
 
166
    Port parent;
 
167
};
 
168
 
 
169
extern PortD *portd_new (int pins);
 
170
extern void portd_construct (PortD *p, int pins);
 
171
extern void portd_destroy (void *p);
 
172
 
 
173
/* Port E */
 
174
typedef struct _PortE PortE;
 
175
 
 
176
struct _PortE
 
177
{
 
178
    Port parent;
 
179
};
 
180
 
 
181
extern PortE *porte_new (int pins);
 
182
extern void porte_construct (PortE *p, int pins);
 
183
extern void porte_destroy (void *p);
 
184
 
 
185
/* Port F */
 
186
typedef struct _PortF PortF;
 
187
 
 
188
struct _PortF
 
189
{
 
190
    Port parent;
 
191
};
 
192
 
 
193
extern PortF *portf_new (int pins);
 
194
extern void portf_construct (PortF *p, int pins);
 
195
extern void portf_destroy (void *p);
 
196
 
 
197
#endif /* SIM_PORTS_H */