gpio.h File Reference


Detailed Description

GPIO header for AVR32 UC3.

This file contains basic GPIO driver functions.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file gpio.h.

#include <avr32/io.h>
#include "compiler.h"

Go to the source code of this file.

Data Structures

struct  gpio_map_t
 A type definition of pins and modules connectivity. More...

Defines

Interrupt Trigger Modes
#define GPIO_FALLING_EDGE   2
 Interrupt triggered upon falling edge.
#define GPIO_PIN_CHANGE   0
 Interrupt triggered upon pin change.
#define GPIO_RISING_EDGE   1
 Interrupt triggered upon rising edge.
Return Values of the GPIO API
#define GPIO_INVALID_ARGUMENT   1
 Input parameters are out of range.
#define GPIO_SUCCESS   0
 Function successfully completed.

Functions

Peripheral Bus Interface
Low-speed interface with a non-deterministic number of clock cycles per access.

This interface operates with lower clock frequencies (fPB <= fCPU), and its timing is not deterministic since it needs to access a shared bus which may be heavily loaded.

Note:
This interface is immediately available without initialization.


void gpio_clear_pin_interrupt_flag (unsigned int pin)
 Clears the interrupt flag of a pin.
void gpio_clr_gpio_open_drain_pin (unsigned int pin)
 Drives a GPIO pin to 0 using open drain.
void gpio_clr_gpio_pin (unsigned int pin)
 Drives a GPIO pin to 0.
void gpio_disable_pin_glitch_filter (unsigned int pin)
 Disables the glitch filter of a pin.
void gpio_disable_pin_interrupt (unsigned int pin)
 Disables the interrupt of a pin.
void gpio_disable_pin_pull_up (unsigned int pin)
 Disables the pull-up resistor of a pin.
void gpio_enable_gpio (const gpio_map_t gpiomap, unsigned int size)
 Enables the GPIO mode of a set of pins.
void gpio_enable_gpio_pin (unsigned int pin)
 Enables the GPIO mode of a pin.
int gpio_enable_module (const gpio_map_t gpiomap, unsigned int size)
 Enables specific module modes for a set of pins.
int gpio_enable_module_pin (unsigned int pin, unsigned int function)
 Enables a specific module mode for a pin.
void gpio_enable_pin_glitch_filter (unsigned int pin)
 Enables the glitch filter of a pin.
int gpio_enable_pin_interrupt (unsigned int pin, unsigned int mode)
 Enables the interrupt of a pin with the specified settings.
void gpio_enable_pin_pull_up (unsigned int pin)
 Enables the pull-up resistor of a pin.
int gpio_get_gpio_open_drain_pin_output_value (unsigned int pin)
 Returns the output value set for a GPIO pin using open drain.
int gpio_get_gpio_pin_output_value (unsigned int pin)
 Returns the output value set for a GPIO pin.
int gpio_get_pin_interrupt_flag (unsigned int pin)
 Gets the interrupt flag of a pin.
int gpio_get_pin_value (unsigned int pin)
 Returns the value of a pin.
void gpio_set_gpio_open_drain_pin (unsigned int pin)
 Drives a GPIO pin to 1 using open drain.
void gpio_set_gpio_pin (unsigned int pin)
 Drives a GPIO pin to 1.
void gpio_tgl_gpio_open_drain_pin (unsigned int pin)
 Toggles a GPIO pin using open drain.
void gpio_tgl_gpio_pin (unsigned int pin)
 Toggles a GPIO pin.
Peripheral Event System support
The GPIO can be programmed to output peripheral events whenever an interrupt condition is detected, such as pin value change, or only when a rising or falling edge is detected.

int gpio_configure_pin_periph_event_mode (unsigned int pin, unsigned int mode, unsigned int use_igf)
 Configure the peripheral event trigger mode of a pin.
__inline__ void gpio_disable_pin_periph_event (unsigned int pin)
 Disables the peripheral event generation of a pin.
__inline__ void gpio_enable_pin_periph_event (unsigned int pin)
 Enables the peripheral event generation of a pin.
Local Bus Interface
High-speed interface with only one clock cycle per access.

This interface operates with high clock frequency (fCPU), and its timing is deterministic since it does not need to access a shared bus which may be heavily loaded.

Warning:
To use this interface, the clock frequency of the peripheral bus on which the GPIO peripheral is connected must be set to the CPU clock frequency (fPB = fCPU).
Note:
This interface has to be initialized in order to be available.


__inline__ void gpio_local_clr_gpio_open_drain_pin (unsigned int pin)
 Drives a GPIO pin to 0 using open drain.
__inline__ void gpio_local_clr_gpio_pin (unsigned int pin)
 Drives a GPIO pin to 0.
__inline__ void gpio_local_disable_pin_output_driver (unsigned int pin)
 Disables the output driver of a pin.
__inline__ void gpio_local_enable_pin_output_driver (unsigned int pin)
 Enables the output driver of a pin.
__inline__ int gpio_local_get_pin_value (unsigned int pin)
 Returns the value of a pin.
__inline__ void gpio_local_init (void)
 Enables the local bus interface for GPIO.
__inline__ void gpio_local_init_gpio_open_drain_pin (unsigned int pin)
 Initializes the configuration of a GPIO pin so that it can be used with GPIO open-drain functions.
__inline__ void gpio_local_set_gpio_open_drain_pin (unsigned int pin)
 Drives a GPIO pin to 1 using open drain.
__inline__ void gpio_local_set_gpio_pin (unsigned int pin)
 Drives a GPIO pin to 1.
__inline__ void gpio_local_tgl_gpio_open_drain_pin (unsigned int pin)
 Toggles a GPIO pin using open drain.
__inline__ void gpio_local_tgl_gpio_pin (unsigned int pin)
 Toggles a GPIO pin.


Define Documentation

#define GPIO_FALLING_EDGE   2

Interrupt triggered upon falling edge.

Definition at line 68 of file gpio.h.

Referenced by gpio_configure_edge_detector().

#define GPIO_INVALID_ARGUMENT   1

Input parameters are out of range.

Definition at line 59 of file gpio.h.

Referenced by gpio_configure_edge_detector(), gpio_enable_module_pin(), and gpio_enable_pin_interrupt().

#define GPIO_PIN_CHANGE   0

Interrupt triggered upon pin change.

Definition at line 66 of file gpio.h.

Referenced by gpio_configure_edge_detector().

#define GPIO_RISING_EDGE   1

Interrupt triggered upon rising edge.

Definition at line 67 of file gpio.h.

Referenced by gpio_configure_edge_detector().

#define GPIO_SUCCESS   0

Function successfully completed.

Definition at line 58 of file gpio.h.

Referenced by gpio_configure_edge_detector(), gpio_enable_module(), gpio_enable_module_pin(), and gpio_enable_pin_interrupt().


Function Documentation

void gpio_clear_pin_interrupt_flag ( unsigned int  pin  ) 

Clears the interrupt flag of a pin.

Parameters:
pin The pin number.

Definition at line 425 of file gpio.c.

References GPIO.

00426 {
00427   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00428   gpio_port->ifrc = 1 << (pin & 0x1F);
00429 }

void gpio_clr_gpio_open_drain_pin ( unsigned int  pin  ) 

Drives a GPIO pin to 0 using open drain.

Parameters:
pin The pin number.

Definition at line 322 of file gpio.c.

References GPIO.

00323 {
00324   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00325 
00326   gpio_port->ovrc  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0.
00327   gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
00328   gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
00329 }

void gpio_clr_gpio_pin ( unsigned int  pin  ) 

Drives a GPIO pin to 0.

Parameters:
pin The pin number.

Definition at line 293 of file gpio.c.

References GPIO.

00294 {
00295   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00296 
00297   gpio_port->ovrc  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0.
00298   gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
00299   gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
00300 }

int gpio_configure_pin_periph_event_mode ( unsigned int  pin,
unsigned int  mode,
unsigned int  use_igf 
)

Configure the peripheral event trigger mode of a pin.

Parameters:
pin The pin number.
mode The trigger mode (GPIO_PIN_CHANGE, GPIO_RISING_EDGE or GPIO_FALLING_EDGE).
use_igf use the Input Glitch Filter (TRUE) or not (FALSE).
Returns:
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

Definition at line 438 of file gpio.c.

References GPIO, and gpio_configure_edge_detector().

00439 {
00440   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00441 
00442   if(TRUE == use_igf)
00443   {
00444     // Enable the glitch filter.
00445     gpio_port->gfers = 1 << (pin & 0x1F);
00446   }
00447   else
00448   {
00449     // Disable the glitch filter.
00450     gpio_port->gferc = 1 << (pin & 0x1F);
00451   }
00452 
00453   // Configure the edge detector.
00454   return(gpio_configure_edge_detector(pin, mode));
00455 }

void gpio_disable_pin_glitch_filter ( unsigned int  pin  ) 

Disables the glitch filter of a pin.

Parameters:
pin The pin number.

Definition at line 349 of file gpio.c.

References GPIO.

00350 {
00351   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00352   gpio_port->gferc = 1 << (pin & 0x1F);
00353 }

void gpio_disable_pin_interrupt ( unsigned int  pin  ) 

Disables the interrupt of a pin.

Parameters:
pin The pin number.

Definition at line 411 of file gpio.c.

References GPIO.

00412 {
00413   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00414   gpio_port->ierc = 1 << (pin & 0x1F);
00415 }

__inline__ void gpio_disable_pin_periph_event ( unsigned int  pin  ) 

Disables the peripheral event generation of a pin.

Parameters:
pin The pin number.

Definition at line 565 of file gpio.h.

00566 {
00567   AVR32_GPIO.port[pin >> 5].everc = 1 << (pin & 0x1F);
00568 }

void gpio_disable_pin_pull_up ( unsigned int  pin  ) 

Disables the pull-up resistor of a pin.

Parameters:
pin The pin number.

Definition at line 208 of file gpio.c.

References GPIO.

00209 {
00210   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00211   gpio_port->puerc = 1 << (pin & 0x1F);
00212 }

void gpio_enable_gpio ( const gpio_map_t  gpiomap,
unsigned int  size 
)

Enables the GPIO mode of a set of pins.

Parameters:
gpiomap The pin map.
size The number of pins in gpiomap.

Definition at line 151 of file gpio.c.

References gpio_enable_gpio_pin(), and gpio_map_t::pin.

00152 {
00153   unsigned int i;
00154 
00155   for (i = 0; i < size; i++)
00156   {
00157     gpio_enable_gpio_pin(gpiomap->pin);
00158     gpiomap++;
00159   }
00160 }

void gpio_enable_gpio_pin ( unsigned int  pin  ) 

Enables the GPIO mode of a pin.

Parameters:
pin The pin number.
Refer to the product header file `uc3x.h' (where x is the part number; e.g. x = a0512) for pin definitions. E.g., to enable the GPIO mode of PX21, AVR32_PIN_PX21 can be used. Module pins such as AVR32_PWM_3_PIN for PWM channel 3 can also be used to release module pins for GPIO.

Definition at line 163 of file gpio.c.

References GPIO.

Referenced by gpio_enable_gpio().

00164 {
00165   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00166   gpio_port->oderc = 1 << (pin & 0x1F);
00167   gpio_port->gpers = 1 << (pin & 0x1F);
00168 }

int gpio_enable_module ( const gpio_map_t  gpiomap,
unsigned int  size 
)

Enables specific module modes for a set of pins.

Parameters:
gpiomap The pin map.
size The number of pins in gpiomap.
Returns:
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

Definition at line 60 of file gpio.c.

References gpio_map_t::function, gpio_enable_module_pin(), GPIO_SUCCESS, and gpio_map_t::pin.

00061 {
00062   int status = GPIO_SUCCESS;
00063   unsigned int i;
00064 
00065   for (i = 0; i < size; i++)
00066   {
00067     status |= gpio_enable_module_pin(gpiomap->pin, gpiomap->function);
00068     gpiomap++;
00069   }
00070 
00071   return status;
00072 }

int gpio_enable_module_pin ( unsigned int  pin,
unsigned int  function 
)

Enables a specific module mode for a pin.

Parameters:
pin The pin number.
Refer to the product header file `uc3x.h' (where x is the part number; e.g. x = a0512) for module pins. E.g., to enable a PWM channel output, the pin number can be AVR32_PWM_3_PIN for PWM channel 3.
function The pin function.
Refer to the product header file `uc3x.h' (where x is the part number; e.g. x = a0512) for module pin functions. E.g., to enable a PWM channel output, the pin function can be AVR32_PWM_3_FUNCTION for PWM channel 3.
Returns:
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

Definition at line 75 of file gpio.c.

References GPIO, GPIO_INVALID_ARGUMENT, and GPIO_SUCCESS.

Referenced by gpio_enable_module().

00076 {
00077   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00078 
00079   // Enable the correct function.
00080   switch (function)
00081   {
00082   case 0: // A function.
00083     gpio_port->pmr0c = 1 << (pin & 0x1F);
00084     gpio_port->pmr1c = 1 << (pin & 0x1F);
00085 #if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
00086     gpio_port->pmr2c = 1 << (pin & 0x1F);
00087 #endif
00088     break;
00089 
00090   case 1: // B function.
00091     gpio_port->pmr0s = 1 << (pin & 0x1F);
00092     gpio_port->pmr1c = 1 << (pin & 0x1F);
00093 #if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
00094     gpio_port->pmr2c = 1 << (pin & 0x1F);
00095 #endif
00096     break;
00097 
00098   case 2: // C function.
00099     gpio_port->pmr0c = 1 << (pin & 0x1F);
00100     gpio_port->pmr1s = 1 << (pin & 0x1F);
00101 #if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
00102     gpio_port->pmr2c = 1 << (pin & 0x1F);
00103 #endif
00104     break;
00105 
00106   case 3: // D function.
00107     gpio_port->pmr0s = 1 << (pin & 0x1F);
00108     gpio_port->pmr1s = 1 << (pin & 0x1F);
00109 #if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
00110     gpio_port->pmr2c = 1 << (pin & 0x1F);
00111 #endif
00112     break;
00113 
00114 #if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
00115   case 4: // E function.
00116     gpio_port->pmr0c = 1 << (pin & 0x1F);
00117     gpio_port->pmr1c = 1 << (pin & 0x1F);
00118     gpio_port->pmr2s = 1 << (pin & 0x1F);
00119     break;
00120     
00121   case 5: // F function.
00122     gpio_port->pmr0s = 1 << (pin & 0x1F);
00123     gpio_port->pmr1c = 1 << (pin & 0x1F);
00124     gpio_port->pmr2s = 1 << (pin & 0x1F);
00125     break;
00126     
00127   case 6: // G function.
00128     gpio_port->pmr0c = 1 << (pin & 0x1F);
00129     gpio_port->pmr1s = 1 << (pin & 0x1F);
00130     gpio_port->pmr2s = 1 << (pin & 0x1F);
00131     break;
00132     
00133   case 7: // H function.
00134     gpio_port->pmr0s = 1 << (pin & 0x1F);
00135     gpio_port->pmr1s = 1 << (pin & 0x1F);
00136     gpio_port->pmr2s = 1 << (pin & 0x1F);
00137     break;
00138 #endif
00139 
00140   default:
00141     return GPIO_INVALID_ARGUMENT;
00142   }
00143 
00144   // Disable GPIO control.
00145   gpio_port->gperc = 1 << (pin & 0x1F);
00146 
00147   return GPIO_SUCCESS;
00148 }

void gpio_enable_pin_glitch_filter ( unsigned int  pin  ) 

Enables the glitch filter of a pin.

When the glitch filter is enabled, a glitch with duration of less than 1 clock cycle is automatically rejected, while a pulse with duration of 2 clock cycles or more is accepted. For pulse durations between 1 clock cycle and 2 clock cycles, the pulse may or may not be taken into account, depending on the precise timing of its occurrence. Thus for a pulse to be guaranteed visible it must exceed 2 clock cycles, whereas for a glitch to be reliably filtered out, its duration must not exceed 1 clock cycle. The filter introduces 2 clock cycles latency.

Parameters:
pin The pin number.

Definition at line 342 of file gpio.c.

References GPIO.

00343 {
00344   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00345   gpio_port->gfers = 1 << (pin & 0x1F);
00346 }

int gpio_enable_pin_interrupt ( unsigned int  pin,
unsigned int  mode 
)

Enables the interrupt of a pin with the specified settings.

Parameters:
pin The pin number.
mode The trigger mode (GPIO_PIN_CHANGE, GPIO_RISING_EDGE or GPIO_FALLING_EDGE).
Returns:
GPIO_SUCCESS or GPIO_INVALID_ARGUMENT.

Definition at line 393 of file gpio.c.

References GPIO, gpio_configure_edge_detector(), GPIO_INVALID_ARGUMENT, and GPIO_SUCCESS.

00394 {
00395   volatile avr32_gpio_port_t  *gpio_port = &GPIO.port[pin >> 5];
00396 
00397   // Enable the glitch filter.
00398   gpio_port->gfers = 1 << (pin & 0x1F);
00399 
00400   // Configure the edge detector.
00401   if(GPIO_INVALID_ARGUMENT == gpio_configure_edge_detector(pin, mode))
00402     return(GPIO_INVALID_ARGUMENT);
00403 
00404   // Enable interrupt.
00405   gpio_port->iers = 1 << (pin & 0x1F);
00406 
00407   return GPIO_SUCCESS;
00408 }

__inline__ void gpio_enable_pin_periph_event ( unsigned int  pin  ) 

Enables the peripheral event generation of a pin.

Parameters:
pin The pin number.

Definition at line 551 of file gpio.h.

00552 {
00553   AVR32_GPIO.port[pin >> 5].oderc = 1 << (pin & 0x1F); // The GPIO output driver is disabled for that pin.
00554   AVR32_GPIO.port[pin >> 5].evers = 1 << (pin & 0x1F);
00555 }

void gpio_enable_pin_pull_up ( unsigned int  pin  ) 

Enables the pull-up resistor of a pin.

Parameters:
pin The pin number.

Definition at line 198 of file gpio.c.

References GPIO.

00199 {
00200   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00201   gpio_port->puers = 1 << (pin & 0x1F);
00202 #if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
00203   gpio_port->pderc = 1 << (pin & 0x1F);
00204 #endif
00205 }

int gpio_get_gpio_open_drain_pin_output_value ( unsigned int  pin  ) 

Returns the output value set for a GPIO pin using open drain.

Parameters:
pin The pin number.
Returns:
The pin output value.
Note:
This function must be used in conjunction with gpio_set_gpio_open_drain_pin, gpio_clr_gpio_open_drain_pin and gpio_tgl_gpio_open_drain_pin.

Definition at line 276 of file gpio.c.

References GPIO.

00277 {
00278   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00279   return ((gpio_port->oder >> (pin & 0x1F)) & 1) ^ 1;
00280 }

int gpio_get_gpio_pin_output_value ( unsigned int  pin  ) 

Returns the output value set for a GPIO pin.

Parameters:
pin The pin number.
Returns:
The pin output value.
Note:
This function must be used in conjunction with gpio_set_gpio_pin, gpio_clr_gpio_pin and gpio_tgl_gpio_pin.

Definition at line 269 of file gpio.c.

References GPIO.

00270 {
00271   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00272   return (gpio_port->ovr >> (pin & 0x1F)) & 1;
00273 }

int gpio_get_pin_interrupt_flag ( unsigned int  pin  ) 

Gets the interrupt flag of a pin.

Parameters:
pin The pin number.
Returns:
The pin interrupt flag.

Definition at line 418 of file gpio.c.

References GPIO.

00419 {
00420   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00421   return (gpio_port->ifr >> (pin & 0x1F)) & 1;
00422 }

int gpio_get_pin_value ( unsigned int  pin  ) 

Returns the value of a pin.

Parameters:
pin The pin number.
Returns:
The pin value.

Definition at line 262 of file gpio.c.

References GPIO.

00263 {
00264   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00265   return (gpio_port->pvr >> (pin & 0x1F)) & 1;
00266 }

__inline__ void gpio_local_clr_gpio_open_drain_pin ( unsigned int  pin  ) 

Drives a GPIO pin to 0 using open drain.

Parameters:
pin The pin number.
Note:
gpio_local_init and gpio_local_init_gpio_open_drain_pin must have been called beforehand.

This function does not enable the GPIO mode of the pin. gpio_enable_gpio_pin can be called for this purpose.

Definition at line 503 of file gpio.h.

00504 {
00505   AVR32_GPIO_LOCAL.port[pin >> 5].oders = 1 << (pin & 0x1F);
00506 }

__inline__ void gpio_local_clr_gpio_pin ( unsigned int  pin  ) 

Drives a GPIO pin to 0.

Parameters:
pin The pin number.
Note:
gpio_local_init must have been called beforehand.

This function does not enable the GPIO mode of the pin nor its output driver. gpio_enable_gpio_pin and gpio_local_enable_pin_output_driver can be called for this purpose.

Definition at line 432 of file gpio.h.

00433 {
00434   AVR32_GPIO_LOCAL.port[pin >> 5].ovrc = 1 << (pin & 0x1F);
00435 }

__inline__ void gpio_local_disable_pin_output_driver ( unsigned int  pin  ) 

Disables the output driver of a pin.

Parameters:
pin The pin number.
Note:
gpio_local_init must have been called beforehand.

Definition at line 378 of file gpio.h.

00379 {
00380   AVR32_GPIO_LOCAL.port[pin >> 5].oderc = 1 << (pin & 0x1F);
00381 }

__inline__ void gpio_local_enable_pin_output_driver ( unsigned int  pin  ) 

Enables the output driver of a pin.

Parameters:
pin The pin number.
Note:
gpio_local_init must have been called beforehand.

This function does not enable the GPIO mode of the pin. gpio_enable_gpio_pin can be called for this purpose.

Definition at line 364 of file gpio.h.

Referenced by main().

00365 {
00366   AVR32_GPIO_LOCAL.port[pin >> 5].oders = 1 << (pin & 0x1F);
00367 }

__inline__ int gpio_local_get_pin_value ( unsigned int  pin  ) 

Returns the value of a pin.

Parameters:
pin The pin number.
Returns:
The pin value.
Note:
gpio_local_init must have been called beforehand.

Definition at line 394 of file gpio.h.

00395 {
00396   return (AVR32_GPIO_LOCAL.port[pin >> 5].pvr >> (pin & 0x1F)) & 1;
00397 }

__inline__ void gpio_local_init ( void   ) 

Enables the local bus interface for GPIO.

Note:
This function must have been called at least once before using other functions in this interface.

Definition at line 346 of file gpio.h.

Referenced by main().

00347 {
00348   Set_system_register(AVR32_CPUCR,
00349                       Get_system_register(AVR32_CPUCR) | AVR32_CPUCR_LOCEN_MASK);
00350 }

__inline__ void gpio_local_init_gpio_open_drain_pin ( unsigned int  pin  ) 

Initializes the configuration of a GPIO pin so that it can be used with GPIO open-drain functions.

Note:
This function must have been called at least once before using gpio_local_set_gpio_open_drain_pin, gpio_local_clr_gpio_open_drain_pin or gpio_local_tgl_gpio_open_drain_pin.

Definition at line 467 of file gpio.h.

00468 {
00469   AVR32_GPIO_LOCAL.port[pin >> 5].ovrc = 1 << (pin & 0x1F);
00470 }

__inline__ void gpio_local_set_gpio_open_drain_pin ( unsigned int  pin  ) 

Drives a GPIO pin to 1 using open drain.

Parameters:
pin The pin number.
Note:
gpio_local_init and gpio_local_init_gpio_open_drain_pin must have been called beforehand.

This function does not enable the GPIO mode of the pin. gpio_enable_gpio_pin can be called for this purpose.

Definition at line 485 of file gpio.h.

00486 {
00487   AVR32_GPIO_LOCAL.port[pin >> 5].oderc = 1 << (pin & 0x1F);
00488 }

__inline__ void gpio_local_set_gpio_pin ( unsigned int  pin  ) 

Drives a GPIO pin to 1.

Parameters:
pin The pin number.
Note:
gpio_local_init must have been called beforehand.

This function does not enable the GPIO mode of the pin nor its output driver. gpio_enable_gpio_pin and gpio_local_enable_pin_output_driver can be called for this purpose.

Definition at line 413 of file gpio.h.

00414 {
00415   AVR32_GPIO_LOCAL.port[pin >> 5].ovrs = 1 << (pin & 0x1F);
00416 }

__inline__ void gpio_local_tgl_gpio_open_drain_pin ( unsigned int  pin  ) 

Toggles a GPIO pin using open drain.

Parameters:
pin The pin number.
Note:
gpio_local_init and gpio_local_init_gpio_open_drain_pin must have been called beforehand.

This function does not enable the GPIO mode of the pin. gpio_enable_gpio_pin can be called for this purpose.

Definition at line 521 of file gpio.h.

00522 {
00523   AVR32_GPIO_LOCAL.port[pin >> 5].odert = 1 << (pin & 0x1F);
00524 }

__inline__ void gpio_local_tgl_gpio_pin ( unsigned int  pin  ) 

Toggles a GPIO pin.

Parameters:
pin The pin number.
Note:
gpio_local_init must have been called beforehand.

This function does not enable the GPIO mode of the pin nor its output driver. gpio_enable_gpio_pin and gpio_local_enable_pin_output_driver can be called for this purpose.

Definition at line 451 of file gpio.h.

00452 {
00453   AVR32_GPIO_LOCAL.port[pin >> 5].ovrt = 1 << (pin & 0x1F);
00454 }

void gpio_set_gpio_open_drain_pin ( unsigned int  pin  ) 

Drives a GPIO pin to 1 using open drain.

Parameters:
pin The pin number.

Definition at line 313 of file gpio.c.

References GPIO.

00314 {
00315   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00316 
00317   gpio_port->oderc = 1 << (pin & 0x1F); // The GPIO output driver is disabled for that pin.
00318   gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
00319 }

void gpio_set_gpio_pin ( unsigned int  pin  ) 

Drives a GPIO pin to 1.

Parameters:
pin The pin number.

Definition at line 283 of file gpio.c.

References GPIO.

00284 {
00285   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00286 
00287   gpio_port->ovrs  = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 1.
00288   gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
00289   gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
00290 }

void gpio_tgl_gpio_open_drain_pin ( unsigned int  pin  ) 

Toggles a GPIO pin using open drain.

Parameters:
pin The pin number.

Definition at line 332 of file gpio.c.

References GPIO.

00333 {
00334   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00335 
00336   gpio_port->ovrc  = 1 << (pin & 0x1F); // Value to be driven on the I/O line if the GPIO output driver is enabled: 0.
00337   gpio_port->odert = 1 << (pin & 0x1F); // The GPIO output driver is toggled for that pin.
00338   gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
00339 }

void gpio_tgl_gpio_pin ( unsigned int  pin  ) 

Toggles a GPIO pin.

Parameters:
pin The pin number.

Definition at line 303 of file gpio.c.

References GPIO.

00304 {
00305   volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
00306 
00307   gpio_port->ovrt  = 1 << (pin & 0x1F); // Toggle the I/O line.
00308   gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
00309   gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
00310 }


Generated on Thu Dec 17 19:58:35 2009 for AVR32 - GPIO Driver - Local Bus Interface by  doxygen 1.5.5