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

Subversion Repositories aemb

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

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 197 sybreon
typedef char gpioData;
31
 
32 196 sybreon
/*!
33
   GPIO Directions.
34
*/
35
 
36 197 sybreon
enum gpioTrisType
37 196 sybreon
  {
38
    GPIO_INPUT  = 0, ///< Define GPIO pin as an input
39
    GPIO_OUTPUT = 1 ///< Define GPIO pin as an output
40
  };
41
 
42 197 sybreon
typedef enum gpioTrisType gpioTrisType;
43
 
44 196 sybreon
/*!
45
   GPIO Register Map.
46
   This structure contains the register file of a general-purpose
47
   I/O. Care should be taken when using it due to endian issues.
48
*/
49
 
50 197 sybreon
struct gpioRegs
51 196 sybreon
{
52 197 sybreon
  volatile gpioData regCtrl; ///< GPIO direction register.
53
  unsigned int /* unused */ :24;
54
  volatile gpioData regLine; ///< GPIO line data register.
55
  unsigned int /* unused */ :24;
56 196 sybreon
};
57
 
58 197 sybreon
typedef struct gpioRegs gpioRegs;
59 196 sybreon
 
60 197 sybreon
// ==== GPIO INTERFACE ====
61
 
62
gpioData gpioGetBit(gpioRegs* port, gpioData bit);
63
void gpioSetBit(gpioRegs* port, gpioData bit);
64
void gpioTogBit(gpioRegs* port, gpioData bit);
65
void gpioClrBit(gpioRegs* port, gpioData bit);
66
 
67
//void gpioPutTris(gpioRegs* port, gpioData mask);
68
void gpioSetTris(gpioRegs* port, gpioData mask);
69
void gpioPutData(gpioRegs* port, gpioData data);
70
//gpioData gpioGetTris(gpioRegs* port);
71
gpioData gpioGetData(gpioRegs* port);
72
 
73
void gpioInit(gpioRegs* port);
74
 
75
 
76 196 sybreon
/*!
77
   Get a port bit.
78
 
79
   This function reads the value of a specific bit on a GPIO port. It
80
   reads the entire port line and masks out the specific bit. The
81 197 sybreon
   result should be gpioDataerpreted as zero for 0 and non-zero for 1.
82 196 sybreon
 
83
   @param port Memory-mapped I/O port.
84
   @param bit Get port bit value.
85
   @return Value of the port bit.
86
*/
87
 
88
inline
89 197 sybreon
gpioData  gpioGetBit(gpioRegs* port, gpioData bit)
90 196 sybreon
{
91
  return port->regLine & (1 << bit);
92
}
93
 
94
/*!
95
   Set a port bit.
96
 
97
   This function sets a specific bit on a GPIO port to 1. It is a
98
   read-modify-write instruction that reads the port value, masks it
99
   and writes the new value to the port.
100
 
101
   @param port Memory-mapped I/O port.
102
   @param bit Set port bit to 1.
103
*/
104
 
105
inline
106 197 sybreon
void gpioSetBit(gpioRegs* port, gpioData bit)
107 196 sybreon
{
108
  port->regLine |= (1 << bit);
109
}
110
 
111
/*!
112
   Toggle a port bit.
113
 
114
   This function toggles a specific bit on a GPIO port. It is a
115
   read-modify-write instruction that reads the port value, masks it
116
   and writes the new value to the port.
117
 
118
   @param port Memory-mapped I/O port.
119
   @param bit Toggle port bit between 0 and 1.
120
*/
121
 
122
inline
123 197 sybreon
void gpioTogBit(gpioRegs* port, gpioData bit)
124 196 sybreon
{
125
  port->regLine ^= (1 << bit);
126
}
127
 
128
/*!
129
   Clear a port bit.
130
 
131
   This function clears a specific bit on a GPIO port to 0. It is a
132
   read-modify-write instruction that reads the port value, masks it
133
   and writes the new value to the port.
134
 
135
   @param port Memory-mapped I/O port.
136
   @param bit Clear port bit to 0.
137
 */
138
 
139
inline
140 197 sybreon
void gpioClrBit(gpioRegs* port, gpioData bit)
141 196 sybreon
{
142
  port->regLine &= ~(1 << bit);
143
}
144
 
145
/*!
146
   Configure the entire port.
147
 
148
   This function configures the entire port, which controls the
149
   direction of specific bits of the port. It writes the entire port
150
   mask to the port control register.
151
 
152 197 sybreon
   @see gpioTrisType
153 196 sybreon
   @param port Memory-mapped I/O port.
154
   @param mask The entire port config mask.
155
 */
156
 
157
inline
158 197 sybreon
void gpioSetTris(gpioRegs* port, gpioData mask)
159 196 sybreon
{
160
  port->regCtrl = mask;
161
}
162
 
163 197 sybreon
 
164 196 sybreon
/*!
165 197 sybreon
   Configure the entire port.
166
 
167
   This function configures the entire port, which controls the
168
   direction of specific bits of the port. It writes the entire port
169
   mask to the port control register.
170
 
171
   @see gpioTrisType
172
   @param port Memory-mapped I/O port.
173
   @param mask The entire port config mask.
174
 */
175
 
176
inline
177
gpioData gpioGetTris(gpioRegs* port)
178
{
179
  //port->regCtrl = mask;
180
  return port->regCtrl;
181
}
182
 
183
/*!
184 196 sybreon
   Put data on the port.
185
 
186
   This function writes onto the entire data line of the GPIO port. It
187
   writes the value directly to the port register.
188
 
189
   @param port Memory-mapped I/O port.
190
   @param data The data to write to the port.
191
 */
192
 
193
inline
194 197 sybreon
void gpioPutData(gpioRegs* port, gpioData data)
195 196 sybreon
{
196
  port->regLine = data;
197
}
198
 
199
/*!
200
   Get data from the port.
201
 
202
   This function reads the entire data line of the GPIO port. It reads
203
   the value directly from the port register. Any output port values
204
   will appear on the input unless something is wrong.
205
 
206
   @param port Memory-mapped I/O port.
207
   @return The contents of the entire port.
208
 */
209
 
210
inline
211 197 sybreon
gpioData gpioGetData(gpioRegs* port)
212 196 sybreon
{
213
  return port->regLine;
214
}
215
 
216
/*!
217
   Initialise the GPIO port.
218
 
219
   This function configures the entire GPIO port as inputs and clears
220
   the whole port data register. This will restore the port to its
221
   reset condition.
222
 
223
   @param port Memory-mapped I/O port.
224
 */
225
 
226
inline
227 197 sybreon
void gpioInit(gpioRegs* port)
228 196 sybreon
{
229 197 sybreon
  gpioSetTris(port, 0);
230
  gpioPutData(port, 0);
231 196 sybreon
}
232
 
233
#endif

powered by: WebSVN 2.1.0

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