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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [AVR32_UC3/] [DRIVERS/] [GPIO/] [gpio.c] - Blame information for rev 591

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

Line No. Rev Author Line
1 589 jeremybenn
/*This file has been prepared for Doxygen automatic documentation generation.*/
2
/*! \file *********************************************************************
3
 *
4
 * \brief GPIO driver for AVR32 UC3.
5
 *
6
 * This file defines a useful set of functions for the GPIO.
7
 *
8
 * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32
9
 * - Supported devices:  All AVR32 devices with a GPIO module can be used.
10
 * - AppNote:
11
 *
12
 * \author               Atmel Corporation: http://www.atmel.com \n
13
 *                       Support and FAQ: http://support.atmel.no/
14
 *
15
 *****************************************************************************/
16
 
17
/* Copyright (c) 2007, Atmel Corporation All rights reserved.
18
 *
19
 * Redistribution and use in source and binary forms, with or without
20
 * modification, are permitted provided that the following conditions are met:
21
 *
22
 * 1. Redistributions of source code must retain the above copyright notice,
23
 * this list of conditions and the following disclaimer.
24
 *
25
 * 2. Redistributions in binary form must reproduce the above copyright notice,
26
 * this list of conditions and the following disclaimer in the documentation
27
 * and/or other materials provided with the distribution.
28
 *
29
 * 3. The name of ATMEL may not be used to endorse or promote products derived
30
 * from this software without specific prior written permission.
31
 *
32
 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
33
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
34
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
35
 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
36
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
 */
43
 
44
 
45
#include "gpio.h"
46
 
47
 
48
//! GPIO module instance.
49
#define GPIO  AVR32_GPIO
50
 
51
 
52
int gpio_enable_module(const gpio_map_t gpiomap, unsigned int size)
53
{
54
  int status = GPIO_SUCCESS;
55
  unsigned int i;
56
 
57
  for (i = 0; i < size; i++)
58
  {
59
    status |= gpio_enable_module_pin(gpiomap->pin, gpiomap->function);
60
    gpiomap++;
61
  }
62
 
63
  return status;
64
}
65
 
66
 
67
int gpio_enable_module_pin(unsigned int pin, unsigned int function)
68
{
69
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
70
 
71
  // Enable the correct function.
72
  switch (function)
73
  {
74
  case 0: // A function.
75
    gpio_port->pmr0c = 1 << (pin & 0x1F);
76
    gpio_port->pmr1c = 1 << (pin & 0x1F);
77
    break;
78
 
79
  case 1: // B function.
80
    gpio_port->pmr0s = 1 << (pin & 0x1F);
81
    gpio_port->pmr1c = 1 << (pin & 0x1F);
82
    break;
83
 
84
  case 2: // C function.
85
    gpio_port->pmr0c = 1 << (pin & 0x1F);
86
    gpio_port->pmr1s = 1 << (pin & 0x1F);
87
    break;
88
 
89
  default:
90
    return GPIO_INVALID_ARGUMENT;
91
  }
92
 
93
  // Disable GPIO control.
94
  gpio_port->gperc = 1 << (pin & 0x1F);
95
 
96
  return GPIO_SUCCESS;
97
}
98
 
99
 
100
void gpio_enable_gpio(const gpio_map_t gpiomap, unsigned int size)
101
{
102
  unsigned int i;
103
 
104
  for (i = 0; i < size; i++)
105
  {
106
    gpio_enable_gpio_pin(gpiomap->pin);
107
    gpiomap++;
108
  }
109
}
110
 
111
 
112
void gpio_enable_gpio_pin(unsigned int pin)
113
{
114
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
115
  gpio_port->oderc = 1 << (pin & 0x1F);
116
  gpio_port->gpers = 1 << (pin & 0x1F);
117
}
118
 
119
 
120
void gpio_enable_pin_open_drain(unsigned int pin)
121
{
122
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
123
  gpio_port->odmers = 1 << (pin & 0x1F);
124
}
125
 
126
 
127
void gpio_disable_pin_open_drain(unsigned int pin)
128
{
129
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
130
  gpio_port->odmerc = 1 << (pin & 0x1F);
131
}
132
 
133
 
134
void gpio_enable_pin_pull_up(unsigned int pin)
135
{
136
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
137
  gpio_port->puers = 1 << (pin & 0x1F);
138
}
139
 
140
 
141
void gpio_disable_pin_pull_up(unsigned int pin)
142
{
143
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
144
  gpio_port->puerc = 1 << (pin & 0x1F);
145
}
146
 
147
 
148
int gpio_get_pin_value(unsigned int pin)
149
{
150
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
151
  return (gpio_port->pvr >> (pin & 0x1F)) & 1;
152
}
153
 
154
 
155
int gpio_get_gpio_pin_output_value(unsigned int pin)
156
{
157
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
158
  return (gpio_port->ovr >> (pin & 0x1F)) & 1;
159
}
160
 
161
 
162
void gpio_set_gpio_pin(unsigned int pin)
163
{
164
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
165
 
166
  gpio_port->ovrs  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 1.
167
  gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
168
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
169
}
170
 
171
 
172
void gpio_clr_gpio_pin(unsigned int pin)
173
{
174
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
175
 
176
  gpio_port->ovrc  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0.
177
  gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
178
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
179
}
180
 
181
 
182
void gpio_tgl_gpio_pin(unsigned int pin)
183
{
184
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
185
 
186
  gpio_port->ovrt  = 1 << (pin & 0x1F); // Toggle the I/O line.
187
  gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
188
  gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
189
}
190
 
191
 
192
void gpio_enable_pin_glitch_filter(unsigned int pin)
193
{
194
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
195
  gpio_port->gfers = 1 << (pin & 0x1F);
196
}
197
 
198
 
199
void gpio_disable_pin_glitch_filter(unsigned int pin)
200
{
201
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
202
  gpio_port->gferc = 1 << (pin & 0x1F);
203
}
204
 
205
 
206
int gpio_enable_pin_interrupt(unsigned int pin, unsigned int mode)
207
{
208
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
209
 
210
  // Enable the glitch filter.
211
  gpio_port->gfers = 1 << (pin & 0x1F);
212
 
213
  // Configure the edge detector.
214
  switch (mode)
215
  {
216
  case GPIO_PIN_CHANGE:
217
    gpio_port->imr0c = 1 << (pin & 0x1F);
218
    gpio_port->imr1c = 1 << (pin & 0x1F);
219
    break;
220
 
221
  case GPIO_RISING_EDGE:
222
    gpio_port->imr0s = 1 << (pin & 0x1F);
223
    gpio_port->imr1c = 1 << (pin & 0x1F);
224
    break;
225
 
226
  case GPIO_FALLING_EDGE:
227
    gpio_port->imr0c = 1 << (pin & 0x1F);
228
    gpio_port->imr1s = 1 << (pin & 0x1F);
229
    break;
230
 
231
  default:
232
    return GPIO_INVALID_ARGUMENT;
233
  }
234
 
235
  // Enable interrupt.
236
  gpio_port->iers = 1 << (pin & 0x1F);
237
 
238
  return GPIO_SUCCESS;
239
}
240
 
241
 
242
void gpio_disable_pin_interrupt(unsigned int pin)
243
{
244
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
245
  gpio_port->ierc = 1 << (pin & 0x1F);
246
}
247
 
248
 
249
int gpio_get_pin_interrupt_flag(unsigned int pin)
250
{
251
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
252
  return (gpio_port->ifr >> (pin & 0x1F)) & 1;
253
}
254
 
255
 
256
void gpio_clear_pin_interrupt_flag(unsigned int pin)
257
{
258
  volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
259
  gpio_port->ifrc = 1 << (pin & 0x1F);
260
}

powered by: WebSVN 2.1.0

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