OpenCores
URL https://opencores.org/ocsvn/aemb/aemb/trunk

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [vpio/] [vpioGpio.h] - Blame information for rev 196

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 196 sybreon
/* $Id: memtest.hh,v 1.8 2008-06-24 10:03:41 sybreon Exp $
2
**
3
** VIRTUAL PERIPHERAL I/O LIBRARY
4
** Copyright (C) 2009 Shawn Tan <shawn.tan@aeste.net>
5
**
6
** This file is part of AEMB.
7
**
8
** AEMB is free software: you can redistribute it and/or modify it
9
** under the terms of the GNU General Public License as published by
10
** the Free Software Foundation, either version 3 of the License, or
11
** (at your option) any later version.
12
**
13
** AEMB is distributed in the hope that it will be useful, but WITHOUT
14
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
** License for more details.
17
**
18
** You should have received a copy of the GNU General Public License
19
** along with AEMB.  If not, see <http://www.gnu.org/licenses/>.
20
*/
21
 
22
/*!
23
  GPIO C Interface Library.
24
  @file
25
*/
26
 
27
#ifndef VPIO_GPIO_H
28
#define VPIO_GPIO_H
29
 
30
/*!
31
   GPIO Directions.
32
*/
33
 
34
enum vpioGpioTrisType
35
  {
36
    GPIO_INPUT  = 0, ///< Define GPIO pin as an input
37
    GPIO_OUTPUT = 1 ///< Define GPIO pin as an output
38
  };
39
 
40
/*!
41
   GPIO Register Map.
42
   This structure contains the register file of a general-purpose
43
   I/O. Care should be taken when using it due to endian issues.
44
*/
45
 
46
struct vpioGpioRegs
47
{
48
  volatile int regCtrl; ///< GPIO direction register.
49
  //unsigned int /* unused */ :24;    
50
  volatile int regLine; ///< GPIO line data register.
51
  //unsigned int /* unused */ :24;    
52
};
53
 
54
typedef struct vpioGpioRegs vpioGpioRegs;
55
 
56
/*!
57
   Get a port bit.
58
 
59
   This function reads the value of a specific bit on a GPIO port. It
60
   reads the entire port line and masks out the specific bit. The
61
   result should be interpreted as zero for 0 and non-zero for 1.
62
 
63
   @param port Memory-mapped I/O port.
64
   @param bit Get port bit value.
65
   @return Value of the port bit.
66
*/
67
 
68
inline
69
int  vpioGpioGetBit(vpioGpioRegs* port, int bit)
70
{
71
  return port->regLine & (1 << bit);
72
}
73
 
74
/*!
75
   Set a port bit.
76
 
77
   This function sets a specific bit on a GPIO port to 1. It is a
78
   read-modify-write instruction that reads the port value, masks it
79
   and writes the new value to the port.
80
 
81
   @param port Memory-mapped I/O port.
82
   @param bit Set port bit to 1.
83
*/
84
 
85
inline
86
void vpioGpioSetBit(vpioGpioRegs* port, int bit)
87
{
88
  port->regLine |= (1 << bit);
89
}
90
 
91
/*!
92
   Toggle a port bit.
93
 
94
   This function toggles a specific bit on a GPIO port. It is a
95
   read-modify-write instruction that reads the port value, masks it
96
   and writes the new value to the port.
97
 
98
   @param port Memory-mapped I/O port.
99
   @param bit Toggle port bit between 0 and 1.
100
*/
101
 
102
inline
103
void vpioGpioTogBit(vpioGpioRegs* port, int bit)
104
{
105
  port->regLine ^= (1 << bit);
106
}
107
 
108
/*!
109
   Clear a port bit.
110
 
111
   This function clears a specific bit on a GPIO port to 0. It is a
112
   read-modify-write instruction that reads the port value, masks it
113
   and writes the new value to the port.
114
 
115
   @param port Memory-mapped I/O port.
116
   @param bit Clear port bit to 0.
117
 */
118
 
119
inline
120
void vpioGpioClrBit(vpioGpioRegs* port, int bit)
121
{
122
  port->regLine &= ~(1 << bit);
123
}
124
 
125
/*!
126
   Configure the entire port.
127
 
128
   This function configures the entire port, which controls the
129
   direction of specific bits of the port. It writes the entire port
130
   mask to the port control register.
131
 
132
   @see vpioGpioTrisType
133
   @param port Memory-mapped I/O port.
134
   @param mask The entire port config mask.
135
 */
136
 
137
inline
138
void vpioGpioCfgPort(vpioGpioRegs* port, int mask)
139
{
140
  port->regCtrl = mask;
141
}
142
 
143
/*!
144
   Put data on the port.
145
 
146
   This function writes onto the entire data line of the GPIO port. It
147
   writes the value directly to the port register.
148
 
149
   @param port Memory-mapped I/O port.
150
   @param data The data to write to the port.
151
 */
152
 
153
inline
154
void vpioGpioPutPort(vpioGpioRegs* port, int data)
155
{
156
  port->regLine = data;
157
}
158
 
159
/*!
160
   Get data from the port.
161
 
162
   This function reads the entire data line of the GPIO port. It reads
163
   the value directly from the port register. Any output port values
164
   will appear on the input unless something is wrong.
165
 
166
   @param port Memory-mapped I/O port.
167
   @return The contents of the entire port.
168
 */
169
 
170
inline
171
int vpioGpioGetPort(vpioGpioRegs* port)
172
{
173
  return port->regLine;
174
}
175
 
176
/*!
177
   Clear the entire port.
178
 
179
   This function clears the data pins of the entire GPIO port to 0. It
180
   writes the value directly to the port register.
181
 
182
   @param port Memory-mapped I/O port.
183
 */
184
 
185
inline
186
void vpioGpioClrPort(vpioGpioRegs* port)
187
{
188
  vpioGpioPutPort(port, 0);
189
}
190
 
191
/*!
192
   Initialise the GPIO port.
193
 
194
   This function configures the entire GPIO port as inputs and clears
195
   the whole port data register. This will restore the port to its
196
   reset condition.
197
 
198
   @param port Memory-mapped I/O port.
199
 */
200
 
201
inline
202
void vpioGpioIniPort(vpioGpioRegs* port)
203
{
204
  vpioGpioCfgPort(port, 0);
205
  vpioGpioClrPort(port);
206
}
207
 
208
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.